| 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; |
|---|