root/lib/Resmon/Module/DHCPLEASES.pm

Revision ee6ea773c15427802fe2e4f57bcb9adcf8a5d162, 1.5 kB (checked in by Mark Harrison <mark@omniti.com>, 5 years ago)

Detect duplicate entries in the leases file and don't count them

git-svn-id: https://labs.omniti.com/resmon/trunk@182 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 $net = $arg->{'object'};
9   my $file = "/var/db/dhcpd.leases";
10   my %ips;
11   open (IN, '<', $file);
12   my $date = `date -u +'%Y/%m/%d %H:%M:%S;'`;
13   my ($actives,$mynet,$ip,$starts,$ends)=(0,'','','','');
14   while (<IN>) {
15     if (/^lease/) {
16       my $lease=$_;
17       $mynet = ($lease =~ m/($net.\d+)/);
18       $ip = $1;
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           if (!$ips{$ip}) {
35             $actives +=1;
36             $ips{$ip} = 1;
37           }
38           ## print STDERR "ACTIVE!}", $_;
39         }else{
40           ## print STDERR "not active}", $_;
41           ## print STDERR "because today:($date)\n";
42         }
43       }
44     }elsif (/^}/) {
45       ## print STDERR "not in mynet}", $_;
46     }
47   }
48   my ($warn,$crit)=($arg->{'warn'},$arg->{'crit'});
49   if ($actives < $warn) {
50     return("OK($actives leases)");
51   }elsif ($actives < $crit) {
52     return("WARN($actives leases)");
53   }else {
54     return("BAD($actives leases)");
55   }
56 };
57 1;
Note: See TracBrowser for help on using the browser.