Using the avail.cgi script for reporting
Subhendu Ghosh
sghosh at sghosh.org
Fri Feb 21 01:25:50 CET 2003
If Chet says ok - it can be added to the plugins/contrib-reporting dir :)
-sg
On Thu, 20 Feb 2003, Jon Lyons wrote:
>
> Wow, Chet should make a website or add it to SourceForge site... :)
> Lane Williams <willipl1 at jhuapl.edu> wrote:I got a script from Chet Luther, modified it heavily and now it looks
> something like what I have below. You obviously can format the output
> however you wish. I used this just for testing the functionality so I
> suggest using your own formatting. The main line to pay attention to is
> the "my $request" variable which does a "GET". I've used this idea to
> output the data to a CSV file, and just dump it to a hash and formatted
> the output within the script.
>
> Hope this helps..... also attached the file in-case email screws up the
> formatting.
>
> #################BEGIN SCRIPT#############################
> #!/usr/local/perl/bin/perl -w
> #
> # Parse the outputs from Nagios' avail.cgi into an HTML table.
> #
>
> use Date::Manip;
> use LWP::UserAgent;
> use Time::Local;
> use Data::Dumper;
> $~ = ReportFormat;
> @stime = ("07","00",00);
> @etime = (18,30,00);
>
> $date = `date +"\%m \%d \%Y"`; #month date year
> chomp $date;
>
> ($mon,$day,$year)=split ' ', $date;
>
> #$sec1x = &UnixDate ($epoch_date1x, "%s");
> #$sec2x = &UnixDate ($epoch_date2x, "%s");
>
> use vars qw($agent);
> #use strict;
>
> my $nagios_url = "http://yoursite/nagios/cgi-bin";
>
> $agent = new LWP::UserAgent();
> $agent->agent("Mozilla/6.0");
> $agent->timeout(600);
>
> my $request = new HTTP::Request(GET =>
> "$nagios_url/avail.cgi?show_log_entries=&host=all&timeperiod=custom&smon=$mon&sday=$day&syear=$year&shour=$stime[0]&smin=$stime[1]&ssec=$stime[2]&emon=$mon&eday=$day&eyear=$year&ehour=$etime[0]&emin=$etime[1]&esec=$etime[2]&assumeinitialstates=yes&assumestateretention=yes&initialassumedstate=-1&backtrack=4&csvoutput=");
>
> $request->header('Accept' => 'text/html');
> $request->authorization_basic('username', 'password');
>
> my $response = $agent->request($request);
>
> if (!$response->is_success()) {
> exit;
> }
> (@response) = split '\n' , $response->content();
>
> foreach $line (@response){
>
> #print
> "$mon/$day/$year,$stime[0]:$stime[1],$etime[0]:$etime[1],\n$line\n";
> if ($line !~ /^HOST_NAME/){
>
> (@info) = split ',' , $line;
> @info[0] = map {uc} @info[0];
> @info[0] =~ s/"//g;
> push
> @{$sys_avail{$info[0]}},($info[7],$info[8],$info[16],$info[17]);
> ##host_name total_time_up percent_total_time_up total_time_down
> percent_total_time_down##
> }
> }
>
>
> foreach $key (sort keys %sys_avail){
>
> write;}
>
> format ReportFormat_TOP =
>
> ===========================================================
> System Availability
> for
> @ $mon, $day, $year
> @<:@< - @<:@<
> $stime[0], $stime[1], $etime[0], $etime[1]
> page@|||
> $%
> ===========================================================
> HostName Percent of Uptime Percent Down Time
> ___________________________________________________________
> .
> format ReportFormat =
>
> @<<<<<<<<<<<<<<<<< @<<<<<<< @<<<<<<<<
> $key, "@{$sys_avail{$key}}[1]","@{$sys_avail{$key}}[3]"
> .
>
> ###############################END SCRIPT#############################
>
>
>
>
>
>
> On Thu, 2003-02-20 at 11:47, bill lewis wrote:
> > I have some folks that would like reports in csv format on things that
> > nagios
> > is already keeping track of. I would like to run the avail.cgi from a
> > script
> > to generate the reports. I have tried setting the environment variables
> > suggested and cannot get past more that the first page.
> >
> > Is there a way to do this?
> >
> > thanks,
> > Bill Lewis
> >
> >
> > -----
> > William L. Lewis
> > email: william.l.lewis at usa.net
> > "They that can give up essential liberty to obtain a little temporary
> > safety
> > deserve neither liberty nor safety."
> > --Ben Franklin
> >
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: SlickEdit Inc. Develop an edge.
> > The most comprehensive and flexible code editor you can use.
> > Code faster. C/C++, C#, Java, HTML, XML, many more. FREE 30-Day Trial.
> > www.slickedit.com/sourceforge
> > _______________________________________________
> > Nagios-users mailing list
> > Nagios-users at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/nagios-users
> > ::: Please include Nagios version, plugin version (-v) and OS when
> > reporting any issue.
> > ::: Messages without supporting info will risk being sent to /dev/null
>
> #!/usr/local/perl/bin/perl -w
> #
> # Parse the outputs from Nagios' avail.cgi into an HTML table.
>
>
> use Date::Manip;
> use LWP::UserAgent;
> use Time::Local;
> use Data::Dumper;
> $~ = ReportFormat;
> @stime = ("07","00",00);
> @etime = (18,30,00);
>
> $date = `date +"\%m \%d \%Y"`; #month date year
> chomp $date;
>
> ($mon,$day,$year)=split ' ', $date;
>
> #$sec1x = &UnixDate ($epoch_date1x, "%s");
> #$sec2x = &UnixDate ($epoch_date2x, "%s");
>
> use vars qw($agent);
> #use strict;
>
> my $nagios_url = "http://yoursite/nagios/cgi-bin";
>
> $agent = new LWP::UserAgent();
> $agent->agent("Mozilla/6.0");
> $agent->timeout(600);
>
> my $request = new HTTP::Request(GET => "$nagios_url/avail.cgi?show_log_entries=&host=all&timeperiod=custom&smon=$mon&sday=$day&syear=$year&shour=$stime[0]&smin=$stime[1]&ssec=$stime[2]
> &emon=$mon&eday=$day&eyear=$year&ehour=$etime[0]&emin=$etime[1]&esec=$etime[2]&assumeinitialstates=yes&assumestateretention=yes&initialassumedstate=-1&backtrack=4&csvoutput=");
>
> $request->header('Accept' => 'text/html');
> $request->authorization_basic('username', 'password');
>
> my $response = $agent->request($request);
>
> if (!$response->is_success()) {
> exit;
> }
> (@response) = split '\n' , $response->content();
>
> foreach $line (@response){
>
> #print "$mon/$day/$year,$stime[0]:$stime[1],$etime[0]:$etime[1],\n$line\n";
> if ($line !~ /^HOST_NAME/){
>
> (@info) = split ',' , $line;
> @info[0] = map {uc} @info[0];
> @info[0] =~ s/"//g;
> push @{$sys_avail{$info[0]}}, ($info[7],$info[8],$info[16],$info[17]); ##host_name total_time_up percent_total_time_up total_time down percent_total_time_down##
> }
> }
>
>
> foreach $key (sort keys %sys_avail){
>
> write;}
>
> format ReportFormat_TOP =
>
> ===========================================================
> System Availability
> for
> @ $mon, $day, $year
> @<:@< - @<:@<
> $stime[0], $stime[1], $etime[0], $etime[1]
> page@|||
> $%
> ===========================================================
> HostName Percent of Uptime Percent Down Time
> ___________________________________________________________
> .
> format ReportFormat =
>
> @<<<<<<<<<<<<<<<<< @<<<<<<< @<<<<<<<<
> $key, "@{$sys_avail{$key}}[1]","@{$sys_avail{$key}}[3]"
> .
>
>
>
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Tax Center - forms, calculators, tips, and more
--
-------------------------------------------------------
This SF.net email is sponsored by: SlickEdit Inc. Develop an edge.
The most comprehensive and flexible code editor you can use.
Code faster. C/C++, C#, Java, HTML, XML, many more. FREE 30-Day Trial.
www.slickedit.com/sourceforge
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null
More information about the Users
mailing list