我想检查一个远程肥皂服务器,通过发送一些xml和greping一个字符串?如果成功,我想输出一个xml文件,以便我可以使用pingdom来检查服务的正常运行时间。
答案 0 :(得分:1)
以下是我用来执行此操作的脚本。将其添加到cron,每六十秒运行一次,将结果输出到Web根目录并使用ping自定义检查或其他监视工具:
#!/bin/bash
# result file
file="/var/www/vhostwebroot/out.xml"
# remove the file if exists (from previous runs)
if [ -e $file ];then
rm $file
fi
# set start time
start=$(date +%s%3N)
# soap_text.xml is the soap call you want to post to the remote server
test=$(curl --silent -d @soap_test.xml -H "Content-Type: application/soap+xml" -H 'SOAPAction: ""' https://www.soap-server-to-check/service-endpoint | grep -o 'string you want to check for')
# set end time
end=$(date +%s%3N)
# calculate elapsed time
el=$(($end-$start))
# if the string exists, output an xml file
if [ "$test" = 'string you want to check for' ]
then
# output the appropriately formatted file for pingdom to check
echo "<pingdom_http_custom_check>
<status>OK</status>
<response_time>$el</response_time>
</pingdom_http_custom_check>" > $file
else
# if the check fails, output a failure doc
echo "<pingdom_http_custom_check>
<status>DOWN</status>
<response_time>$el</response_time>
</pingdom_http_custom_check>" > $file
fi