#!/usr/bin/perl -w
use strict;
##########################################################################
# $Id: dhcpd,v 1.3 2002/10/12 02:08:18 kirk Exp $
##########################################################################

########################################################
# This was written and is maintained by:
#    Kirk Bauer <kirk@kaybee.org>
#
# Please send all comments, suggestions, bug reports,
#    etc, to kirk@kaybee.org.
########################################################

my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'};

my %data;

# This filter is very basic... much more could be done with it

while (my $line = <STDIN>) {
   chomp $line;
   $line =~ s/^\s+//;
   $line =~ s/\s+$//;
   next unless $line;
   if (
      # All of these entries are generated at startup :(
      ($line =~ /^Internet Software Consortium DHCP Server/) or
      ($line =~ /^Copyright/) or
      ($line =~ /^All rights reserved/) or
      ($line =~ /^Please contribute if you find this software useful/) or
      ($line =~ /^For info, please visit/) or
      # Other lines to ignore
      ($line =~ /^already acking lease/) or
      ($line =~ /^dhcpd shutdown succeeded/) or
      ($line =~ /^dhcpd startup succeeded/) or
      ($line =~ /^Sending on/) or
      ($line =~ /^DHCPACK/) or
      ($line =~ /^DHCPNAK/) or
      ($line =~ /^DHCPINFORM/) or
      ($line =~ /^DHCPDISCOVER/) or
      ($line =~ /^DHCPREQUEST/)
      ) {
      # Ignore these lines
   } elsif ($line =~ s/Listening on\s+//) {
      $data{'DHCP Server Listening On'}{$line}++;
   } elsif ($line =~ s/^DHCPOFFER on ([\d\.]+) to ([a-f\d:]+) via (\S+)\s*$/$1 -> $2 ($3)/) {
      if ($Detail >= 5) {
         $data{'Addresses Leased'}{$line}++;
      }
   } else {
      $data{'Unknown Entries'}{$line}++;
   }
}

if (keys %data) {
   foreach my $type (keys %data) {
      print "$type:\n";
      foreach my $entry (keys %{$data{$type}}) {
         print "   $entry: $data{$type}{$entry} Time(s)\n";
      }
      print "\n";
   }
}

