This is one of the cases where the passive check of the Nagios monitoring system comes in handy as we need to be informed immediately when the Keepalived changes state. So you will need an NSCA system implemented with your Nagios configuration.
Studying the Keepalived configuration we found that the authors have implemented the option to run a script that when the state of the VRRP changes. The script I’m referring to is run under the “notify” option.
Here is what I’m talking about (from the Keepalived configuration):
# for ANY state transition.# "notify" script is called AFTER the# notify_* script(s) and is executed# with 3 arguments provided by keepalived# (ie don't include parameters in the notify line).# arguments# $1 = "GROUP"|"INSTANCE"# $2 = name of group or instance# $3 = target state of transition# ("MASTER"|"BACKUP"|"FAULT")notify /path/notify.sh
My idea is to create a small script that will be added to the configuration of the VRRP instance and which will provide all the info to the NSCA client. This script will pass the status information to the Nagios installation via the NSCA daemon installed on the Nagios server.
The notify.sh script should look like this:
#!/bin/shHOST="localhost"KEEPHOST="127.0.0.1"SERVICE="Keepalived service status"#read the last stateLASTCHECKF="/tmp/keep_nsca_hist.tmp"LASTCHECK="echo $LASTCHECKF"echo -e "$HOSTt$SERVICEt1tKeepalived $1 - $2 is transitioning from the $LASTCHECK to the $3 state" | /opt/nagios/bin/send_nsca -H $KEEPHOST -c /etc/nagios/send_nsca.cfg#store the new state to the temp fileecho "$3"> $LASTCHECKFexit 0
I did not have the time to test the script nor to implement further checks. This article is only with an informational scope. So happy testing!
If you found this info useful, please leave a comment 🙂 .
Copyright (c) 2011 Mihai Radoveanu. All Rights Reserved.Note: Copying this article to your website is strictly NOT allowed.