#!/usr/bin/perl -w
#
# nagios passive notify
#
# 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 3 of the License, or
# (at your option) any later version.
#
# This will scan status.dat using NagiosStatus.pm available on exchange and generate a notification.
# 

use strict;
use warnings;
use lib "/usr/lib64/nagios/plugins";
use NagiosStatus;

my $foo = NagiosStatus->new("/var/log/nagios/status.dat");
#$foo->debug(1);
$foo->parse_statusfile();
$foo->evaluate();
my @alerts = $foo->get_alerts(["host_name", "service_description", "current_state","passive_checks_enabled","active_checks_enabled","problem_has_been_acknowledged"]);

foreach (@alerts)
{
	print "$_->{'host_name'}" . "$_->{'service_description'} active= $_->{'active_checks_enabled'} passive= $_->{'passive_checks_enabled'}\n";
	if (( $_->{'problem_has_been_acknowledged'} == 0 ) && 
		( $_->{'active_checks_enabled'} == 0 ) && 
		( $_->{'passive_checks_enabled'} == 1 )) {
		my $cmd = "/usr/lib64/nagios/plugins/generate_nagios_notify.sh " . $_->{'host_name'} . ' ' . $_->{'service_description'} . ' ' . $_->{'current_state'} . ' "' . $_->{'service_description'} . '"';
		print "cmd was $cmd\n";
		system($cmd);
	}
}
print "Ok\n";
exit 0;
