And thank you in advance for reading and trying to solve my issue.
Problem:
It seems that the final step is never achieved.
I replied to a CRITICAL alert using email (on my smart phone), Nagios seems to know about it and processes it.
But an acknowledge icon never appears on the problem service or host.
Maybe one of you can help identify anything that's missing in the configuration or scripts.
I have done my homework and been successful in implementing Nagios 3.5.
The last piece of the puzzle is to do "auto acknowledge via email" feature.
I've followed several tips
http://www.techopsguys.com/2010/01/05/a ... l-replies/
http://www.mail-archive.com/nagios-user ... 21705.html
http://www.tek-tips.com/viewthread.cfm?qid=1641878
=========
Here is the output of the perl scrpt (i enable stdout and diagnostic)
********
Code: Select all
Subject: Re: ** PROBLEM Service Alert: prod ETS nagios/fs root is CRITICAL **
Servicedescription = fs root
Hostname = prod ETS nagios
Ack: service
Joe [1388671334] ACKNOWLEDGE_SVC_PROBLEM;prod ETS nagios;fs root;1;1;0;emailuser;acknowledged through email
SeenSubject: 1
SeenFrom: 1
Skipped: 0
AckUser: emailuser
Subject: Re: ** PROBLEM Service Alert: prod ETS nagios/fs root is CRITICAL **
Servicedescription = fs root
Hostname = prod ETS nagios
Ack: service
Joe [1388671746] ACKNOWLEDGE_SVC_PROBLEM;prod ETS nagios;fs root;1;1;0;emailuser;acknowledged through email
SeenSubject: 1
SeenFrom: 1
Skipped: 0
AckUser: emailuser
Subject: Re: ** PROBLEM Service Alert: prod ETS nagios/fs root is CRITICAL **
Servicedescription = fs root
Hostname = prod ETS nagios
Ack: service
SUBMITTING ACK by Joe [1388672724] ACKNOWLEDGE_SVC_PROBLEM;prod ETS nagios;fs root;1;1;0;emailuser;acknowledged through email
SeenSubject: 1
SeenFrom: 1
Skipped: 0
AckUser: emailuser
And the actual scripts ============
Code: Select all
#!/usr/bin/perl -w
use diagnostics -verbose;
open(STDOUT, ">>/home/nagios/script.log") or die $!;
# Nagios email ack script
#
# mdkeller - 2009/05/11
#
# Script that runs out of .procmailrc and parses email
# If it determines that it is a reply to an alert, then we
# submit an acknowledgement to Nagios. If not we then
# forward the email to the nagios admin.
use strict;
use Getopt::Std;
my $msg = "";
my $acked = 0;
my $debug = 1;
my $commandfile = "/home/nagios/nagios.cmd.test";
my $nagiosadmin = "my_name_here\@mycompany_here.com";
my $ackusername = "emailuser";
my $acksubject = "acknowledged through email";
sub usage {
print "Usage: $0 [-h] [-d]\n";
print "\t-h\t\thelp\n";
print "\t-d\t\tRun in debug mode and don't ack or email\n";
exit 1;
}
# Get the options from the command line.
my %options = ();
getopts("hd", \%options);
if($options{h}) {
usage();
}
if($options{d}) {
$debug = 1;
}
my $problem;
my $service = 0;
my $host = 0;
my $servicedescription = "";
my $hostname = "";
my $ackmesg = "";
my $skip = 0;
# Need to make sure we only check the first subject and from
my $seensubject = 0;
my $seenfrom = 0;
# To tell us if the subject matched so we can send an ACK
my $subjectmatch = 0;
# Loop through the email message
while(<STDIN>) {
# Save message for possible later use if this isn't an acknowledgement
$msg .= $_;
# Basically look for certain lines in the message. If they match we set a rule for
# if it is a host or service acknowledgement.
# For a service ack
# - We need the servicedescription and hostname
# - We also check to make sure it is WARNING or CRITICAL this means it is not a recovery
# For a host ack
# - We just need the hostname
# - We also check to make sure the State is DOWN. This means it is not a recovery
#
# Service subjects look like:
# Pager: Subject: Re: PROBLEM: idcxpr0193/NRPE CRITICAL
#
# Email: Subject: Re: ** PROBLEM Service Alert: idcxpr0193.con-way.com/IPMI is CRITICAL **
#
#if(/^Subject:\s*[Rr][Ee]:.*PROBLEM.*(CRITICAL|WARNING).*$/ && ! $seensubject ) {
if(/^Subject:\s*[Rr][Ee]:.*PROBLEM.*\/.*$/ && ! $seensubject ) {
# The string matches a rule for a service acknowledgement
$service = 1;
$subjectmatch = 1;
# Check subject for Problem status
if($debug) {
print "$_";
}
}
if(/^Subject:\s*[Rr][Ee]:.*PROBLEM.*DOWN.*$/ && ! $seensubject ) {
# The string matches a rule for a host acknowledgement
$host = 1;
$subjectmatch = 1;
# Check subject for Problem status
if($debug) {
print "$_";
}
}
elsif(/^.*Service:/) {
# The string matches a rule for a service acknowledgement
$service = 1;
$servicedescription = $_;
$servicedescription =~ s/^.*Service:\s+(.*)\s*$/$1/;
if($debug) {
#print "$_";
print "Servicedescription = $servicedescription\n";
}
}
elsif(/^.*Host:/) {
$hostname = $_;
$hostname =~ s/^.*Host:\s+(.*)\s*$/$1/;
$hostname =~ s/^(\w*)?\..*$/$1/;
if($debug) {
#print "$_";
print "Hostname = $hostname\n";
}
}
elsif(/^.*State:.*DOWN.*/) {
# This is a host down problem
#$host = 1;
}
elsif(/^.*State:.*(CRITICAL|WARNING).*/) {
# This is a service critical or warning problem
#$service = 1;
}
elsif(/^From:.*MAILER-DAEMON.*$/i && ! $seenfrom ) {
$skip = 1;
}
elsif(/^From:/ && ! $seenfrom ) {
# See if we can determine the from address so we can set it as the ackuser
# We want to shorten it so it doen't have a domain or extra crud
#
my $tmpemail = $_;
chomp($tmpemail);
if(/</) {
$tmpemail =~ s/^From:.*<(.*)\@.*>.*$/$1/;
}
elsif(/\(/) {
$tmpemail =~ s/^From:.*\((.*)\@.*\).*$/$1/;
}
else {
$tmpemail =~ s/^From:\s*(.*)\@.*$/$1/;
}
# Sadly we can't use the email right now, because Nagios needs to have
# the username configured as a contact for it to work.
#
#if( $tmpemail ne "" && length($tmpemail) < 13 ) {
# $ackusername = $tmpemail;
#}
}
elsif(/^comment:/i ) {
my $tmpcomment = $_;
chomp($tmpcomment);
$tmpcomment =~ s/^comment:\s+(.*)$/$1/i;
print $tmpcomment . "\n";
if ( $tmpcomment ne "" ) {
$acksubject = $tmpcomment;
}
}
if (/^Subject:/) {
# Make sure we only look at the first subject.
# In case this has an attachment or such.
$seensubject = 1;
}
if (/^From:/) {
# Make sure we only look at the first from.
# In case this has an attachment or such.
$seenfrom = 1;
}
}
# Determine if it is a host or service acknowledgement and build the submission
if ($service && $subjectmatch) {
# This is a service acknowledgement so build message
if ( $servicedescription eq "" ) {
# Something went wrong and no service description got through
$service = 0;
}
print "Ack: service\n";
$ackmesg = "ACKNOWLEDGE_SVC_PROBLEM;$hostname;$servicedescription;1;1;0;$ackusername;$acksubject";
}
elsif ($host && $subjectmatch) {
# This is a host acknowledgement so build message
print "Ack: host\n";
$ackmesg = "ACKNOWLEDGE_HOST_PROBLEM;$hostname;1;1;0;$ackusername;$acksubject";
}
# If we aren't supposed to skip an ack
# AND it is a service or host ack
# AND the ack message is set
# THEN submit the ACK to nagios
if ( ! $skip && ( $service || $host ) && $ackmesg ne "" && $hostname ne "" ) {
my $now = time();
if ( $debug ) {
print "SUBMITTING ACK by Joe [$now] $ackmesg\n";
}
else {
open(CMDFILE, ">> $commandfile") || die "Can't open $commandfile!\n";
print CMDFILE "[$now] $ackmesg\n";
close(CMDFILE);
}
$acked = 1;
}
# If the email was not acked then forward it to the Nagios admins
if ( ! $acked && ! $debug ) {
open(MAIL, "|/usr/sbin/sendmail -t");
print MAIL "From: $nagiosadmin\n";
print MAIL "To: $nagiosadmin\n";
print MAIL "Subject: Nagios email\n\n";
print MAIL $msg;
}
if ( $debug ) {
print "SeenSubject: $seensubject\n";
print "SeenFrom: $seenfrom\n";
print "Skipped: $skip\n";
print "AckUser: $ackusername\n";
}
And the external command content =
[1388177940] ACKNOWLEDGE_SVC_PROBLEM;prod ETS nagios;fs root;1;1;0;emailuser;acknowledged through email
[1388178286] ACKNOWLEDGE_SVC_PROBLEM;prod ETS nagios;fs root;1;1;0;emailuser;acknowledged through email
[1388639210] ACKNOWLEDGE_SVC_PROBLEM;prod ETS nagios;Current Load;1;1;0;emailuser;acknowledged through email
[1388641901] ACKNOWLEDGE_SVC_PROBLEM;prod ETS nagios;Current Load;1;1;0;emailuser;acknowledged through email
[1388663619] ACKNOWLEDGE_SVC_PROBLEM;prod ETS nagios;Current Load;1;1;0;emailuser;acknowledged through email
===========================