<commit_before>package Resmon::Module::DHCPLEASES;
use Resmon::ExtComm qw/cache_command/;
use vars qw/@ISA/;
@ISA = qw/Resmon::Module/;

sub handler {
  my $arg = shift;
  my $net = $arg->{'object'};
  my $file = "/var/db/dhcpd.leases";
  my %ips;
  open (IN, '<', $file);
  my $date = `date -u +'%Y/%m/%d %H:%M:%S;'`;
  my ($actives,$mynet,$ip,$starts,$ends)=(0,'','','','');
  while (<IN>) {
    if (/^lease/) {
      my $lease=$_;
      $mynet = ($lease =~ m/($net.\d+)/);
      $ip = $1;
      ($starts,$ends)=('','');
      ## print STDERR "mynet:($mynet,$net)\n";
    }
    if ($mynet) {
      ## print STDERR "in mynet:";
      if(/starts/) {
        s/\s+starts\s+\d\s+//;
        $starts = $_;
        ## print STDERR "starts:($starts)\n";
      }elsif (/ends/) {
        s/\s+ends\s+\d\s+//;
        $ends = $_;
        ## print STDERR "ends:($ends)\n";
      }elsif (/^}/) {
        if (($starts le $date ) && ($ends ge $date)){
          if (!$ips{$ip}) {
            $actives +=1;
            $ips{$ip} = 1;
          }
          ## print STDERR "ACTIVE!}", $_;
        }else{
          ## print STDERR "not active}", $_;
          ## print STDERR "because today:($date)\n";
        }
      }
    }elsif (/^}/) {
      ## print STDERR "not in mynet}", $_;
    }
  }
  my ($warn,$crit)=($arg->{'warn'},$arg->{'crit'});
  if ($actives < $warn) {
    return("OK($actives leases)");
  }elsif ($actives < $crit) {
    return("WARN($actives leases)");
  }else {
    return("BAD($actives leases)");
  }
};
1;<commit_msg>Fix invalid warning status on dhcpleases check<commit_after>package Resmon::Module::DHCPLEASES;
use Resmon::ExtComm qw/cache_command/;
use vars qw/@ISA/;
@ISA = qw/Resmon::Module/;

sub handler {
  my $arg = shift;
  my $net = $arg->{'object'};
  my $file = "/var/db/dhcpd.leases";
  my %ips;
  open (IN, '<', $file);
  my $date = `date -u +'%Y/%m/%d %H:%M:%S;'`;
  my ($actives,$mynet,$ip,$starts,$ends)=(0,'','','','');
  while (<IN>) {
    if (/^lease/) {
      my $lease=$_;
      $mynet = ($lease =~ m/($net.\d+)/);
      $ip = $1;
      ($starts,$ends)=('','');
      ## print STDERR "mynet:($mynet,$net)\n";
    }
    if ($mynet) {
      ## print STDERR "in mynet:";
      if(/starts/) {
        s/\s+starts\s+\d\s+//;
        $starts = $_;
        ## print STDERR "starts:($starts)\n";
      }elsif (/ends/) {
        s/\s+ends\s+\d\s+//;
        $ends = $_;
        ## print STDERR "ends:($ends)\n";
      }elsif (/^}/) {
        if (($starts le $date ) && ($ends ge $date)){
          if (!$ips{$ip}) {
            $actives +=1;
            $ips{$ip} = 1;
          }
          ## print STDERR "ACTIVE!}", $_;
        }else{
          ## print STDERR "not active}", $_;
          ## print STDERR "because today:($date)\n";
        }
      }
    }elsif (/^}/) {
      ## print STDERR "not in mynet}", $_;
    }
  }
  my ($warn,$crit)=($arg->{'warn'},$arg->{'crit'});
  if ($actives < $warn) {
    return("OK($actives leases)");
  }elsif ($actives < $crit) {
    return("WARNING($actives leases)");
  }else {
    return("BAD($actives leases)");
  }
};
1;
{'fraction_non_alphanumeric': 0.2551813471502591, 'fraction_numerical': 0.003238341968911917, 'mean_word_length': 2.1488277268093783, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6695664', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1228, 'n_words': 237}