<div dir="ltr">On Mon, Sep 15, 2008 at 10:32 AM, Jorge Peņa <span dir="ltr"><<a href="mailto:cotarelo2@hotmail.com">cotarelo2@hotmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
Hello list,<br>
<br>
I have a running instalation of Nagios capable to acknowledge via web interface and SMS (I followed some tutorial for that).<br>
<br>
I guessed Nagios had implemented by default the acknowledgementent via e-mail by default just replying to the e-mail but I discovered that it doesn't work.<br>
<br>
Somebody did? how?<br>
<br>
Regards,<br><font color="#888888">
Jorge<br></font><div class="WgoR0d"><br>
</div></div></blockquote><div><br>1) install postfix<br>2) install procmail<br>3) use the following procmailrc for the nagios user:<br>LOGFILE=$HOME/.procmailrc.log<br>VERBOSE=yes<br>PATH=/usr/bin<br>:0<br>* ^Subject:[ ]*\/[^ ].*<br>
| /usr/lib/nagios/eventhandlers/processmail "${MATCH}"<br><br>4) /usr/lib/nagios/eventhandlers/processmail is at the end of this email<br>5) the program assumes notifications are formatted like mine. I put them at the end of this email too.<br>
6) when you receive an alert on your blackberry while at the bar, simply reply to the email and prepend the subject of the alert with:<br>"something ack"<br><br>I'm probably missing some things so if it doesn't work right away, post back and I'll help as much as I can. This comes with no warranty. Its poorly written perl. It probably has a huge security hole. There's probably a better way to do this. It very well may turn your servers into an Atom bomb and blow up the moon. Just warning you... :)<br>
<br>Thanks,<br>Terry<br><br><br><br>################################<br>define command{<br> command_name notify-by-email<br> command_line /usr/bin/printf "%b" "Notification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nNotification Number: $SERVICENOTIFICATIONNUMBER$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/lib/nagios/eventhandlers/notification $SERVICENOTIFICATIONNUMBER$ localhost <a href="mailto:nagios@domain.com">nagios@domain.com</a> $CONTACTEMAIL$ "** $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" service<br>
}<br><br>define command{<br> command_name notify-by-epager<br> command_line /usr/bin/printf "%b" "Service: $SERVICEDESC$\nHost: $HOSTNAME$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nNotification Number: $SERVICENOTIFICATIONNUMBER$\nInfo: $SERVICEOUTPUT$\nDate: $LONGDATETIME$" | /usr/bin/sendEmail -s localhost -f <a href="mailto:nagios@domain.com">nagios@domain.com</a> -t $CONTACTEMAIL$ -u "$NOTIFICATIONTYPE$: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$"<br>
}<br><br>define command{<br> command_name host-notify-by-email<br> command_line /usr/bin/printf "%b" "Notification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nNotification Number: $HOSTNOTIFICATIONNUMBER$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/lib/nagios/eventhandlers/notification $HOSTNOTIFICATIONNUMBER$ localhost <a href="mailto:nagios@domain.com">nagios@domain.com</a> $CONTACTEMAIL$ "Host $HOSTSTATE$ alert for $HOSTNAME$!" host<br>
}<br><br>define command{<br> command_name host-notify-by-epager<br> command_line /usr/bin/printf "%b" "Host '$HOSTALIAS$' is $HOSTSTATE$\nInfo: $HOSTOUTPUT$\nTime: $LONGDATETIME$" | /usr/bin/sendEmail -s localhost -f <a href="mailto:nagios@domain.com">nagios@domain.com</a> -t $CONTACTEMAIL$ -u "$NOTIFICATIONTYPE$ alert - Host $HOSTNAME$ is $HOSTSTATE$"<br>
}<br><br><br>########################################<br>#!/usr/bin/perl<br><br>$correctpassword = 'something';<br>$subject = "$ARGV[0]";<br>$now = `/bin/date +%s`;<br>chomp $now;<br>$commandfile = '/var/log/nagios/rw/nagios.cmd';<br>
<br>if ($subject =~ /Host/ ){<br> ($password, $what, $junk, $junk, $junk, $junk, $junk, $host) = split(/ /, $subject);<br> ($host) = ($host) =~ /(.*)\!/;<br>} else {<br> ($foo, $bar) = split(/\//, $subject);<br>
($password, $what, $junk, $junk, $junk, $junk, $junk, $host) = split(/ /, $foo);<br> ($service) = $bar =~ /^(.*) is.*$/;<br>}<br><br>$password =~ s/^\s+//;<br>$password =~ s/\s+$//;<br><br>print "$password\t$what\t$host\t$service\n";<br>
<br>unless ($password =~ /$correctpassword/i) {<br> print "exiting...wrong password\n";<br> exit 1;<br>}<br><br># ack<br>if ($subject =~ /Host/ ) {<br> $ack = "ACKNOWLEDGE_HOST_PROBLEM;$host;1;1;1;email;email;acknowledged through email";<br>
} else {<br> $ack = "ACKNOWLEDGE_SVC_PROBLEM;$host;$service;1;1;1;email;acknowledged through email";<br>}<br><br>if ($what =~ /ack/i) {<br> sub_print("$ack");<br>} else {<br> print "no valid commands...exiting\n";<br>
exit 1;<br>}<br><br><br>sub sub_print {<br> $narf=shift;<br> open(F, ">$commandfile") or die "cant";<br> print F "[$now] $narf\n";<br> close F;<br>}<br>
</div></div></div>