Home Directory Addons Notifications * Notification Managers Disabled host and service notification parser

Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

Disabled host and service notification parser

Rating
7 votes
Favoured:
0
Hits
111856
Files:
FileDescription
host_status.awkawk script to parse out host status
service_status.awkawk script to parse out service status
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
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.
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="admin@domain.com"

if [[ -n $HOST || -n $SERVICE ]]
then
/usr/bin/printf "%b" "n$BODYn" | $MAIL "$SUBJECT" $RCPT
else
echo "Nothing is disabled..."
fi
Reviews (5)
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="sender@domain.com"
SENDMAIL_FOLDER="$WORKING_DIR/sendmail"
RCPT="reciever@domain.com"
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 =>'some@other.com, some@more.com',
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;
bychandlercord, August 5, 2011
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.