Monday, March 25, 2013

Nagios Apache Audit

Nagios Web Interface shows a lot of info about the hosts and services, but it 's not easy audit the change that were made to it such as who made a change?

The following script grab the apache log for all the changes that were made in nagios for that particular day.

(You can download the script here: nagios_apache_audit.pl)



#!/usr/bin/perl

@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
@weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
$year = 1900 + $yearOffset;
#$theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year";
#print $theTime;

my $today="$dayOfMonth/$months[$month]/$year";

#print $today . "\n";

open FILE, "/var/log/httpd/access_log" or die "cannot open apache log $!";

my @lines=<FILE>;

print "\n<BR>---------------------------------------------------\n<BR>";
print "The following changes were made to nagios:\n<BR>";
print "---------------------------------------------------\n\n<BR><BR>";



foreach $line (@lines)
{
if($line=~m/$today/ && $line=~m/POST/ && $line=~m/cmd.cgi\?cmd_typ=/)
{
print $line . "<BR>";
}
}