<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>
<META content="MSHTML 6.00.2800.1459" name=GENERATOR></HEAD>
<BODY>
<DIV>
<P><SPAN class=566082312-11102004><FONT size=2>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.</FONT></SPAN></P>
<P><FONT face="AR Sans Serif" size=2>#!/usr/bin/perl </FONT></P>
<P><FONT face="AR Sans Serif" size=2>use LWP::UserAgent;</FONT></P>
<P><FONT face="AR Sans Serif" size=2>use Time::Local;</FONT></P>
<P><FONT face="AR Sans Serif" size=2>use Data::Dumper;</FONT></P>
<P><FONT face="AR Sans Serif" size=2>use Date::Manip qw (ParseDate DateCalc
UnixDate);</FONT></P>
<P><FONT face="AR Sans Serif" size=2>@work_week =
("monday","tuesday","wednesday","thursday","friday");</FONT></P>
<P><FONT face="AR Sans Serif" size=2>@stime = ("07","30",00);</FONT></P>
<P><FONT face="AR Sans Serif" size=2>@etime = (18,00,00);</FONT></P>
<P><FONT face="AR Sans Serif" size=2>$username = @ARGV[0];</FONT></P>
<P><FONT face="AR Sans Serif" size=2>$password = @ARGV[1];</FONT></P>
<P><FONT face="AR Sans Serif" size=2></FONT> </P>
<P><FONT face="AR Sans Serif" size=2>print "Days Used:";</FONT></P>
<P><FONT face="AR Sans Serif" size=2>foreach $nday (@work_week){</FONT></P>
<P><FONT face="AR Sans Serif" size=2>@date = &UnixDate("last $nday","\%m \%d
\%Y \%A"),"\n";</FONT></P>
<P><FONT face="AR Sans Serif" size=2>foreach $date (@date){</FONT></P>
<P><FONT face="AR Sans Serif" size=2>($mon,$day,$year,$tday) = split ' ',
$date;</FONT></P>
<P><FONT face="AR Sans Serif" size=2>$tday .= "service";</FONT></P>
<P><FONT face="AR Sans Serif" size=2>#PUT code HERE and push data in hashes for
later processing</FONT></P>
<P><FONT face="AR Sans Serif" size=2>print "$mon-$day-$year, ";</FONT></P>
<P><FONT face="AR Sans Serif" size=2>use vars qw($local/perl/agent);</FONT></P>
<P><FONT face="AR Sans Serif" size=2>my $nagios_url = "</FONT><A
href="http://nagios-server/nagios/cgi-bin"><U><FONT face="AR Sans Serif"
size=2>http://<SPAN
class=566082312-11102004>nagios-server</SPAN>/nagios/cgi-bin</FONT></U></A><FONT
face="AR Sans Serif" size=2>";</FONT></P>
<P><FONT face="AR Sans Serif" size=2>$agent = new LWP::UserAgent();</FONT></P>
<P><FONT face="AR Sans Serif" size=2>$agent->agent("Mozilla/6.0");</FONT></P>
<P><FONT face="AR Sans Serif" size=2>$agent->timeout(600);</FONT></P>
<P><FONT face="AR Sans Serif" size=2>#service request happens here........
</FONT></P>
<P><FONT face="AR Sans Serif" size=2>my $srequest = new HTTP::Request(GET =>
"$nagios_url/avail.cgi?show_log_entries=&host=all&service=all&timeperiod=custom&smon=$mon&sday=$day&syear=$year&shour=$stime[0]&smin=$stime[1]&ssec=0&emon=$mon&eday=$day&eyear=$year&ehour=$etime[0]&emin=$etime[1]&esec=0&assumeinitialstates=yes&assumestateretention=yes&initialassumedstate=0&backtrack=10&csvoutput=
HTTP/1.1");</FONT></P>
<P><FONT face="AR Sans Serif" size=2>$srequest->header('Accept' =>
'text/html');</FONT></P>
<P><FONT face="AR Sans Serif"
size=2>$srequest->authorization_basic($username, $password);</FONT></P>
<P><FONT face="AR Sans Serif" size=2>my $sresponse =
$agent->request($srequest);</FONT></P>
<P><FONT face="AR Sans Serif" size=2>if (!$sresponse->is_success())
{</FONT></P>
<P><FONT face="AR Sans Serif" size=2>exit;</FONT></P>
<P><FONT face="AR Sans Serif" size=2>}</FONT></P>
<P><FONT face="AR Sans Serif" size=2>(@sresponse) = split '\n' ,
$sresponse->content();</FONT></P>
<P><FONT face="AR Sans Serif" size=2>#pass all service requested data into 5
hashes for each work day of work week </FONT></P>
<P><FONT face="AR Sans Serif" size=2>foreach $line (@sresponse){ </FONT></P>
<P><FONT face="AR Sans Serif" size=2>if ($line !~ /^HOST_NAME/){</FONT></P>
<P><FONT face="AR Sans Serif" size=2>(@info) = split ',' , $line;</FONT></P>
<P><FONT face="AR Sans Serif" size=2>@info[0] = map {uc} @info[0];</FONT></P>
<P><FONT face="AR Sans Serif" size=2>$info[0] =~ s/"//g;</FONT></P>
<P><FONT face="AR Sans Serif" size=2>$info[1] =~ s/"//g;</FONT></P>
<P><FONT face="AR Sans Serif" size=2>push
@{$$tday{$info[0]}{$info[1]}},($info[10],($info[19]+$info[28]+$info[37]));</FONT></P>
<P><FONT face="AR Sans Serif" size=2>}</FONT></P>
<P><FONT face="AR Sans Serif" size=2>}</FONT></P>
<P><FONT face="AR Sans Serif" size=2></FONT></P>
<P><FONT face="AR Sans Serif" size=2>} </FONT></P>
<P><FONT face="AR Sans Serif" size=2>}print "\n";</FONT></P>
<P><FONT face="AR Sans Serif" size=2>foreach $server (keys
%Mondayservice){</FONT></P>
<P><FONT face="AR Sans Serif" size=2>foreach $service (keys
%{$Mondayservice{$server}}){</FONT></P>
<P><FONT face="AR Sans Serif" size=2>push
@{$stotal{$server}{$service}},(("@{$Mondayservice{$server}{$service}}[0]"+"@{$Tuesdayservice{$server}{$service}}[0]"+"@{$Wednesdayservice{$server}{$service}}[0]"+"@{$Thursdayservice{$server}{$service}}[0]"+"@{$Fridayservice{$server}{$service}}[0]")/"5",</FONT></P>
<P><FONT face="AR Sans Serif"
size=2>("@{$Mondayservice{$server}{$service}}[1]"+"@{$Tuesdayservice{$server}{$service}}[1]"+"@{$Wednesdayservice{$server}{$service}}[1]"+"@{$Thursdayservice{$server}{$service}}[1]"+"@{$Fridayservice{$server}{$service}}[1]")/"5");</FONT></P>
<P><FONT face="AR Sans Serif" size=2>}</FONT></P>
<P><FONT face="AR Sans Serif" size=2>} </FONT></P>
<P><FONT face="AR Sans Serif" size=2></FONT></P>
<P><FONT face="AR Sans Serif" size=2>foreach $host (sort keys
%stotal){</FONT></P>
<P><FONT face="AR Sans Serif" size=2>#print "$host,";</FONT></P>
<P><FONT face="AR Sans Serif" size=2>foreach $service (sort keys
%{$stotal{$host}}){</FONT></P>
<P><FONT face="AR Sans Serif" size=2>print
"$host,$service,$stotal{$host}{$service}[0],$stotal{$host}{$service}[1]\n";</FONT></P>
<P><FONT face="AR Sans Serif" size=2>}print "\n";</FONT></P>
<P><FONT face="AR Sans Serif" size=2>}</FONT></P></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV></DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT
face=Tahoma size=2>-----Original Message-----<BR><B>From:</B>
nagios-users-admin@lists.sourceforge.net
[mailto:nagios-users-admin@lists.sourceforge.net] <B>On Behalf Of </B>Casey
Allen Shobe<BR><B>Sent:</B> Monday, October 11, 2004 7:47 AM<BR><B>To:</B>
Nagios<BR><B>Subject:</B> [Nagios-users] Nagios statistics
access<BR><BR></FONT></DIV><!-- Converted from text/enriched format -->
<DIV>The company I'm working for is creating a reporting system where they
want to show availability of services based on Nagios data. </DIV><BR>
<DIV>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? </DIV><BR>
<DIV>Thanks, </DIV><BR>
<DIV><FONT face=Helvetica>-- </DIV>
<DIV>Casey Allen Shobe | http://casey.allen.shobe.info </DIV>
<DIV>cshobe@osss.net | ICQ: 1494523 | AIM: SomeLinuxGuy</FONT>
</DIV></BLOCKQUOTE></BODY></HTML>