File: statusdat_demo.pl

package info (click to toggle)
libnagios-object-perl 0.21.20-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,032 kB
  • sloc: perl: 3,198; makefile: 9
file content (54 lines) | stat: -r-xr-xr-x 1,179 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/local/bin/perl

# $Id$
# $LastChangedDate$
# $Rev$

use lib qw(./lib ../lib);
use Nagios::StatusLog;
use Benchmark ':hireswallclock';
use Getopt::Std;
use Data::Dumper;

=head1 NAME

statusdat_demo.pl - test the StatusLog module

=head1 USAGE

perl statusdat_demo.pl -l /var/opt/nagios/status.dat

=head1 NOTES

Please send the benchmark outputs to duncs@cpan.org so I can see how the 
performance is on boxes and configs other than my own.

=cut

our $opt_l;
getopt('l:');
die "Must specify location of Nagios status log with -l option."
    if ( !$opt_l );

my $bench_begin = Benchmark->new;
my $log = Nagios::StatusLog->new( Filename => $opt_l, Version => 2.0 );

my $bench_postparse = Benchmark->new;

#print Dumper( $log );

foreach my $host ( $log->list_hosts ) {
    my $obj = $log->host($host);
    printf "Host: %s Last Update: %d\n", $obj->host_name, $obj->last_update;

}

my $prog = $log->program;
printf "Started at %d", $prog->program_start;

my $bench_postprint = Benchmark->new;

printf "\nTime to parse: %s\nTime to print: %s\n\n",
    timestr( timediff( $bench_postparse, $bench_begin ) ),
    timestr( timediff( $bench_postprint, $bench_postparse ) );