I have a VM running Ubuntu 8.04 that we use as our Nagios server. I have been trying to set it up so that I can reply to the alert emails I receive and acknowledge problems. I am using the directions from this page.
Here is the code from that page.
This works for services but not for hosts. In the syslog, I get this: "nagios: EXTERNAL COMMAND: ACKNOWLEDGE_HOST_PROBLEM;;1;1;1;email;email;acknowledged through email"
It seems that the $host variable is not working for host problems. When I reply to the Nagios email, the subject would be "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" for host alerts, and "** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$ **" for services.
If it helps, this is from the procmail.log.
Anybody have any ideas as to why it won't work for host alerts?
Thanks
Here is the code from that page.
Code:
#!/usr/bin/perl
$correctpassword = 'whatever'; # more of a sanity check than a password and can be anything
$subject = "$ARGV[0]";
$now = `/bin/date +%s`;
chomp $now;
$commandfile = '/usr/local/nagios/var/rw/nagios.cmd';
if ($subject =~ /Host/ ){ # this parses the subject of your email
($password, $what, $junk, $junk, $junk, $junk, $junk, $host) = split(/ /, $subject);
($host) = ($host) =~ /(.*)\!/;
} else {
($foo, $bar) = split(/\//, $subject);
($password, $what, $junk, $junk, $junk, $junk, $junk, $host) = split(/\ /, $foo);
($service) = $bar =~ /^(.*) is.*$/;
}
$password =~ s/^\s+//;
$password =~ s/\s+$//;
print "$password\t$what\t$host\t$service\n";
unless ($password =~ /$correctpassword/i) {
print "exiting...wrong password\n";
exit 1;
}
# ack - this is where the acknowledgement happens
# you could get creative with this and pass all kinds of things via email
# a list of external commands here: [URL unfurl="true"]http://www.nagios.org/development/apis/externalcommands/[/URL]
if ($subject =~ /Host/ ) {
$ack =
"ACKNOWLEDGE_HOST_PROBLEM;$host;1;1;1;email;email;acknowledged through email";
} else {
$ack = "ACKNOWLEDGE_SVC_PROBLEM;$host;$service;1;1;1;email;acknowledged through email";
}
if ($what =~ /ack/i) {
sub_print("$ack");
} else {
print "no valid commands...exiting\n";
exit 1;
}
sub sub_print {
$narf=shift;
open(F, ">$commandfile") or die "cant";
print F "[$now] $narf\n";
close F;
}
This works for services but not for hosts. In the syslog, I get this: "nagios: EXTERNAL COMMAND: ACKNOWLEDGE_HOST_PROBLEM;;1;1;1;email;email;acknowledged through email"
It seems that the $host variable is not working for host problems. When I reply to the Nagios email, the subject would be "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" for host alerts, and "** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$ **" for services.
If it helps, this is from the procmail.log.
Code:
procmail: [17841] Mon Mar 28 11:36:42 2011
procmail: Assigning "PATH=/usr/bin"
procmail: Assigning "MATCH="
procmail: Matched ""PASSWORD" ack RE: ** PROBLEM Host Alert: "HOSTNAME" is DOWN **"
procmail: Match on "^Subject:[ ]*\/[^ ].*"
procmail: Executing "/usr/lib/nagios/eventhandlers/processmail,"PASSWORD" ack RE: ** PROBLEM Host Alert: "HOSTNAME" is DOWN **"
procmail: Assigning "LASTFOLDER=/usr/lib/nagios/eventhandlers/processmail "PASSWORD" ack RE: ** PROBLEM Host Alert: "HOSTNAME" is DOWN **"
procmail: Notified comsat: "nagios@:/usr/lib/nagios/eventhandlers/processmail "PASSWORD" ack RE: ** PROBLEM Host Alert: "HOSTNAME" is DOWN **"
From ME@MYEMAIL.COM Mon Mar 28 11:36:42 2011
Subject: "PASSWORD" ack RE: ** PROBLEM Host Alert: "HOSTNAME" is DOWN **
Folder: /usr/lib/nagios/eventhandlers/processmail "PASSWORD" ack RE: ** PRO 1685
Thanks