こんにちは! JQです。
前回は『OSS編~Sensuを試してみる②~』と題して、Monitoring FrameworkのSensuで監視設定を試してみました。
今回は『OSS編~Sensuを試してみる③~』と題して、Monitoring FrameworkのSensuでメール通知を試してみたいと思います。
handler設定
1.準備
先ずはメールコマンドを利用して通知をしてみたいと思います。
メールコマンドをインストールをしておきます。
1 |
$ sudo yum -y install mailx |
2.メール通知の設定
次にメール通知をするHandlerを設定します。
1 2 3 4 5 6 7 8 9 |
$ sudo vim /etc/sensu/conf.d/handler_email.json { "handlers": { "email": { "type": "pipe", "command": "mail -s 'sensu alert' -r from@address to@address" } } } |
3.チェックプロセスにメールのHandlerを設定します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$ sudo vim /etc/sensu/conf.d/checks/cron_process.json { "checks": { "cron_process": { "command": "check-procs.rb -p cron -C 1", "handlers": [ "default", "email" ], "subscribers": [ "cron" ], "interval": 30, "notification": "Cron is not running", "occurrences": 5 } } } |
sensu-serverとsensu-clientを再起動します。
1 2 |
$ sudo /etc/rc.d/init.d/sensu-server restart $ sudo /etc/rc.d/init.d/sensu-client restart |
3.確認
それでは確認してみましょう!
cronを停止してみます。
1 |
$ sudo /etc/rc.d/init.d/crond stop |
次のようなメールが来れば成功です。
1 2 3 |
{"client":{"name":"ip-xx-xxx-xx-xxx.ec2.internal","address":"xx-xxx-xx-xxx","subscriptions":["cron","all"],"timestamp":1402290132},"check":{"command":"check-procs.rb -p cron -C 1","handlers":["default","email"],"subscribers":["cron"],"interval":30,"notification":"Cron is not running","occurrences":5,"name":"cron_process","issued":1402290132,"executed":1402290132,"output":"CheckProcs CRITICAL: Found 0 matching processes; cmd /cron/\n","status":2,"duration":0.22,"history":["2","2","0","2","2","2","2","2","2","2","0","2","0","2","2","2","2","2","0","0","2"]},"occurrences":1,"action":"create"} {"client":{"name":"ip-xx-xxx-xx-xxx.ec2.internal","address":"xx-xxx-xx-xxx","subscriptions":["cron","all"],"timestamp":1402290132},"check":{"command":"check-procs.rb -p cron -C 1","handlers":["default","email"],"subscribers":["cron"],"interval":30,"notification":"Cron is not running","occurrences":5,"name":"cron_process","issued":1402290132,"executed":1402290132,"output":"CheckProcs CRITICAL: Found 0 matching processes; cmd /cron/\n","status":2,"duration":0.22,"history":["2","2","0","2","2","2","2","2","2","2","0","2","0","2","2","2","2","2","0","0","2"]},"occurrences":1,"action":"create"} |
cronを起動してみます。
1 |
$ sudo /etc/rc.d/init.d/crond stop |
次のようなメールが来れば成功です。
1 2 3 |
{"client":{"name":"ip-xx-xxx-xx-xxx.ec2.internal","address":"xx-xxx-xx-xxx","subscriptions":["cron","all"],"timestamp":1402290152},"check":{"command":"check-procs.rb -p cron -C 1","handlers":["default","email"],"subscribers":["cron"],"interval":30,"notification":"Cron is not running","occurrences":5,"name":"cron_process","issued":1402290162,"executed":1402290162,"output":"CheckProcs CRITICAL: Found 0 matching processes; cmd /cron/\n","status":2,"duration":0.222,"history":["2","0","2","2","2","2","2","2","2","0","2","0","2","2","2","2","2","0","0","2","2"]},"occurrences":2,"action":"create"} {"client":{"name":"ip-xx-xxx-xx-xxx.ec2.internal","address":"xx.xxx.xx.xxx","subscriptions":["cron","all"],"timestamp":1402290192},"check":{"command":"check-procs.rb -p cron -C 1","handlers":["default","email"],"subscribers":["cron"],"interval":30,"notification":"Cron is not running","occurrences":5,"name":"cron_process","issued":1402290192,"executed":1402290192,"output":"CheckProcs OK: Found 1 matching processes; cmd /cron/\n","status":0,"duration":0.22,"history":["0","2","2","2","2","2","2","2","0","2","0","2","2","2","2","2","0","0","2","2","0"]},"occurrences":2,"action":"resolve"} |
いかがでしたでしょうか?
次回もお楽しみに!!!