Build precise queries to find exactly what you need
Press ESC to close
Join our next live webinar: “Advanced Nagios Monitoring Techniques” – Register Now
@vahidh
Favorites1
Views7464
Projects12
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;
Reviewed 12 years ago