root/lib/Resmon/Module/DHCPLEASES.pm

Revision cab0e0f3daabfa75635eddb0146bda858df7e2ad, 1.5 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

fix them up to be number-consistent

git-svn-id: https://labs.omniti.com/resmon/trunk@114 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100755
Line 
1 package Resmon::Module::DHCPLEASES;
2 use Resmon::ExtComm qw/cache_command/;
3 use vars qw/@ISA/;
4 @ISA = qw/Resmon::Module/;
5
6 sub handler {
7   my $arg = shift;
8   my $os = $arg->fresh_status();
9   return $os if $os;
10   my $net = $arg->{'object'};
11   my $file = "/var/db/dhcpd.leases";
12   open (IN, '<', $file);
13   my $date = `date +'%Y/%m/%e %H:%M:%S;'`;
14   my ($actives,$mynet,$starts,$ends)=(0,'','');
15   while (<IN>) {
16     if (/^lease/) {
17       my $lease=$_;
18       $mynet = ($lease =~ m/$net/);
19       ($starts,$ends)=('','');
20       ## print STDERR "mynet:($mynet,$net)\n";
21     }
22     if ($mynet) {
23       ## print STDERR "in mynet:";
24       if(/starts/) {
25         s/\s+starts\s+\d\s+//;
26         $starts = $_;
27         ## print STDERR "starts:($starts)\n";
28       }elsif (/ends/) {
29         s/\s+ends\s+\d\s+//;
30         $ends = $_;
31         ## print STDERR "ends:($ends)\n";
32       }elsif (/^}/) {
33         if (($starts le $date ) && ($ends ge $date)){
34           $actives =+1;
35           print STDERR "ACTIVE!}", $_;
36         }else{
37           ## print STDERR "not active}", $_;
38           ## print STDERR "because today:($date)\n";
39         }
40       }
41     }elsif (/^}/) {
42       ## print STDERR "not in mynet}", $_;
43     }
44   }
45   my ($warn,$crit)=($arg->{'warn'},$arg->{'crit'});
46   if ($actives < $warn) {
47     return($arg->set_status("OK($actives leases)"));
48   }elsif ($actives < $crit) {
49     return($arg->set_status("WARN($actives leases)"));
50   }else {
51     return($arg->set_status("BAD($actives leases)"));
52   }
53 };
54 1;
Note: See TracBrowser for help on using the browser.