当监控服务超时时,如何作为最后一步执行脚本?
我的配置如下:
check process php5-fpm with pidfile /var/run/php5-fpm.pid
start program = "/usr/sbin/service php5-fpm start"
stop program = "/usr/sbin/service php5-fpm stop"
if failed unixsocket /var/run/php5-fpm.sock then restart
if 3 restarts within 5 cycles then timeout
有一个选项可以发送超时电子邮件,如下所示
alert address@hostname only on { timeout }
但是如何在超时时执行脚本(例如发送短信)?
答案1
你可以使用以下命令执行任何处于错误状态的可执行文件:
if 3 restarts within 5 cycles then exec "/usr/sbin/apacheSmsRestart"
并且/usr/sbin/apacheSmsRestart
是 (+ chmod +x /usr/sbin/apacheSmsRestart
)
#!/bin/bash
# Trigger SMS with... literally anything. ;)
curl 'https://smsgateway.example.com/to/1337421337/text/hello+world'
# Do restart
/usr/sbin/service php5-fpm restart
# Exit with last call's exit code
exit $?