Nagios statistics access
Williams, P. Lane
Lane.Williams at jhuapl.edu
Mon Oct 11 14:28:21 CEST 2004
Here is a perl script that I modified to fit my needs. It dumps the total
availability for services for one work week...during working hours.....your
site will probably be different.
#!/usr/bin/perl
use LWP::UserAgent;
use Time::Local;
use Data::Dumper;
use Date::Manip qw (ParseDate DateCalc UnixDate);
@work_week = ("monday","tuesday","wednesday","thursday","friday");
@stime = ("07","30",00);
@etime = (18,00,00);
$username = @ARGV[0];
$password = @ARGV[1];
print "Days Used:";
foreach $nday (@work_week){
@date = &UnixDate("last $nday","\%m \%d \%Y \%A"),"\n";
foreach $date (@date){
($mon,$day,$year,$tday) = split ' ', $date;
$tday .= "service";
#PUT code HERE and push data in hashes for later processing
print "$mon-$day-$year, ";
use vars qw($local/perl/agent);
my $nagios_url = " <http://nagios-server/nagios/cgi-bin>
http://nagios-server/nagios/cgi-bin";
$agent = new LWP::UserAgent();
$agent->agent("Mozilla/6.0");
$agent->timeout(600);
#service request happens here........
my $srequest = new HTTP::Request(GET =>
"$nagios_url/avail.cgi?show_log_entries=&host=all&service=all&timeperiod=cus
tom&smon=$mon&sday=$day&syear=$year&shour=$stime[0]&smin=$stime[1]&ssec=0&em
on=$mon&eday=$day&eyear=$year&ehour=$etime[0]&emin=$etime[1]&esec=0&assumein
itialstates=yes&assumestateretention=yes&initialassumedstate=0&backtrack=10&
csvoutput= HTTP/1.1");
$srequest->header('Accept' => 'text/html');
$srequest->authorization_basic($username, $password);
my $sresponse = $agent->request($srequest);
if (!$sresponse->is_success()) {
exit;
}
(@sresponse) = split '\n' , $sresponse->content();
#pass all service requested data into 5 hashes for each work day of work
week
foreach $line (@sresponse){
if ($line !~ /^HOST_NAME/){
(@info) = split ',' , $line;
@info[0] = map {uc} @info[0];
$info[0] =~ s/"//g;
$info[1] =~ s/"//g;
push
@{$$tday{$info[0]}{$info[1]}},($info[10],($info[19]+$info[28]+$info[37]));
}
}
}
}print "\n";
foreach $server (keys %Mondayservice){
foreach $service (keys %{$Mondayservice{$server}}){
push
@{$stotal{$server}{$service}},(("@{$Mondayservice{$server}{$service}}[0]"+"@
{$Tuesdayservice{$server}{$service}}[0]"+"@{$Wednesdayservice{$server}{$serv
ice}}[0]"+"@{$Thursdayservice{$server}{$service}}[0]"+"@{$Fridayservice{$ser
ver}{$service}}[0]")/"5",
("@{$Mondayservice{$server}{$service}}[1]"+"@{$Tuesdayservice{$server}{$serv
ice}}[1]"+"@{$Wednesdayservice{$server}{$service}}[1]"+"@{$Thursdayservice{$
server}{$service}}[1]"+"@{$Fridayservice{$server}{$service}}[1]")/"5");
}
}
foreach $host (sort keys %stotal){
#print "$host,";
foreach $service (sort keys %{$stotal{$host}}){
print
"$host,$service,$stotal{$host}{$service}[0],$stotal{$host}{$service}[1]\n";
}print "\n";
}
-----Original Message-----
From: nagios-users-admin at lists.sourceforge.net
[mailto:nagios-users-admin at lists.sourceforge.net] On Behalf Of Casey Allen
Shobe
Sent: Monday, October 11, 2004 7:47 AM
To: Nagios
Subject: [Nagios-users] Nagios statistics access
The company I'm working for is creating a reporting system where they want
to show availability of services based on Nagios data.
In the Nagios CGI, I can click "View Availability Report For This Service",
and see the percentages I want to use. How can I access these from the
command-line where the nagios server is running?
Thanks,
--
Casey Allen Shobe | http://casey.allen.shobe.info
cshobe at osss.net | ICQ: 1494523 | AIM: SomeLinuxGuy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20041011/c2fca846/attachment.html>
More information about the Users
mailing list