Build precise queries to find exactly what you need
Press ESC to close
Your review has been submitted and is pending approval.
I kept disabling checks and then would get caught up in something else and forgot what I disabled. I created these scripts to remind me what is disabled so I can go back, fix the problem if needed, and re-enable the notifications.
Current Version
Last Release Date
June 8, 2009
Owner
Nagios Exchange
To use these, you need to cat the status.log and pipe it into the script:
'cat status.log | host_status.awk'
I run a bash script on a cron to call these two scripts and send the output via email:
#!/bin/sh # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either Version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # This script was designed to run the two awk scripts host_status.awk and service_status.awk # and send an email if anything is returned. # DATE=`date +%c` HOST=`/bin/cat /usr/local/nagios/var/status.log | /usr/local/nagios/var/host_status.awk` SERVICE=`/bin/cat /usr/local/nagios/var/status.log | /usr/local/nagios/var/service_status.awk` MAIL="/bin/mail -s" SUBJECT="Disabled Nagios notifications *** $DATE" BODY="$HOST $SERVICE" RCPT="[email protected]"
if [[ -n $HOST || -n $SERVICE ]] then /usr/bin/printf "%b" "n$BODYn" | $MAIL "$SUBJECT" $RCPT else echo "Nothing is disabled..." fi
Hi, Can you please advise on how to run this on Ubuntu? When I run it as documented I get no result. This is also after confirming the location of awk is not in /bin/awk but in /usr/bin/awk (which was updated in the script). It seems that the version of nagios I have also has a status.dat file, with no status.log file. Maybe I'm missing something here, but it seems different when installed on Ubuntu (or Debian).
I will re-release this script with all of its requirements: This script will convert output to html email and provide a html link to enable service/host #!/bin/bash DATE=$(date +%c) NAGIOS_STATUS="/var/nagios/status.dat" WORKING_DIR="/usr/local/bin" SUBJECT="Disabled Nagios notifications *** $DATE" from="[email protected]" SENDMAIL_FOLDER="$WORKING_DIR/sendmail" RCPT="[email protected]" BODY="$HOST $SERVICE" userpass="nagiosadmin:password" nagios_server="nagios.server.yourdomain.com" function host_status() { awk -v user=$userpass -v server=$nagios_server 'BEGIN { header=0; FS="="; } /^[[:space:]]*info {[[:space:]]*$/ { codeblock="info"; } /^[[:space:]]*program {[[:space:]]*$/ { codeblock="program"; } /^[[:space:]]*hoststatus {[[:space:]]*$/ { codeblock="host"; host_name=""; notifications_enabled=""; } /^[[:space:]]*service {[[:space:]]*$/ { codeblock="service"; } /^[[:space:]]*host_name=/ { host_name=$2; } /^[[:space:]]*notifications_enabled=/ { notifications_enabled=$2; } /^[[:space:]]*}[[:space:]]*$/ { if (codeblock=="host" && notifications_enabled=="0") { if (header==0) { print "The following hosts have notifications disabled:"; header=1; } print ""host_name"ENABLE NOTIFICATION"; } } ' } function service_status() { awk -v user=$userpass -v server=$nagios_server 'BEGIN { header=0; FS="="; } /^[[:space:]]*info {[[:space:]]*$/ { codeblock="info"; } /^[[:space:]]*program {[[:space:]]*$/ { codeblock="program"; } /^[[:space:]]*hoststatus {[[:space:]]*$/ { codeblock="host"; } /^[[:space:]]*servicestatus {[[:space:]]*$/ { codeblock="service"; host_name=""; service_description=""; notifications_enabled=""; } /^[[:space:]]*host_name=/ { host_name=$2; } /^[[:space:]]*service_description=/ { service_description=$2; } /^[[:space:]]*notifications_enabled=/ { notifications_enabled=$2; } /^[[:space:]]*}[[:space:]]*$/ { if (codeblock=="service" && notifications_enabled=="0") { if (header==0) { print "The following services have notifications turned off"; header=1; } print ""service_description " on " host_name"ENABLE SERVICE NOTIFICATION"; } } ' } HOST=$(/bin/cat $NAGIOS_STATUS| host_status) SERVICE=$(/bin/cat $NAGIOS_STATUS |service_status) if [[ -n $HOST || -n $SERVICE ]]; then cd $SENDMAIL_FOLDER;./sendmail.pl "$WORKING_DIR" "$from" "$RCPT" "$SUBJECT:" "$SERVICE$HOST" else echo "Nothing is disabled..." fi ---------------------- sendmail.pl --------------------- #!/usr/bin/perl use MIME::Lite; use Net::SMTP; $spath=$ARGV[0]; $from=$ARGV[1]; $to=$ARGV[2]; $subject=$ARGV[3]; $body=$ARGV[4]; $msg = MIME::Lite->new( From =>$from, To =>$to, ##Cc =>'[email protected], [email protected]', Subject =>$subject, Type =>'multipart/mixed' ); $msg->attach( Type =>'text/html; charset="iso-8859-1"', Data =>$body ); $mail_host="localhost"; MIME::Lite->send('smtp', $mail_host, Timeout=>60); $msg->send;
Awesome, great for a busy admin. I put together a awk a to check if nofitications are disabled globally. BEGIN { header=0; FS="="; } /^[[:space:]]*info {[[:space:]]*$/ { codeblock="info"; } /^[[:space:]]*programstatus {[[:space:]]*$/ { codeblock="program"; notifications_enabled=""; } /^[[:space:]]*hoststatus {[[:space:]]*$/ { codeblock="host"; } /^[[:space:]]*servicestatus {[[:space:]]*$/ { codeblock="service"; } /^[[:space:]]*enable_notifications=/ { notifications_enabled=$2; } /^[[:space:]]*}[[:space:]]*$/ { if (codeblock=="program" && notifications_enabled=="0") { if (header==0) { print " ****************** Notifications have been disabled globally!!!!!!! "; header=1; } print host_name; } } Figure that might be useful to someone
I have the same exact problem, so this really helped. Had to adjust it a bit, maybe to fit the recent version? Also, tweaked a bit to have line breaks between hosts/services.. Here are my cents: host_status.awk: 1c1 #!/bin/awk -f 30c30 /^[[:space:]]*host {[[:space:]]*$/ { 36c36 /^[[:space:]]*service {[[:space:]]*$/ { service_status.awk: 1c1 #!/bin/awk -f 30c30 /^[[:space:]]*host {[[:space:]]*$/ { 34c34 /^[[:space:]]*service {[[:space:]]*$/ { 36d35
Thanks for contributing to Nagios exchange. Its a good and handy tool for nagios Admin. 100% recommended.
You must be logged in to submit a review.
To:
From: