SourceForge.net Logo

F.14. syslog:/etc/log.d/scripts/services/dnsmasq

#!/usr/bin/perl
# GPL $Id: dnsmasq,v 1.2 2005/03/20 22:59:30 cvonk Exp $
# script for SISO logwatch for service dnsmasq
# 

$Show          = $ENV{'dnsmasq_show'}           || 1;
$ShowUnmatched = $ENV{'dnsmasq_show_unmatched'} || 0;

while (defined($ThisLine = <STDIN>)) {

    if ( ($Type,$Interface,$IP,$MAC,$Details) = 
	 ($ThisLine =~ /DHCP(.*?)\((.*?)\) (.*?) (.*?) (.*?)$/i ) ) {
	$HOSTAPD->{$Interface}->{$MAC}->{$Type}->{$IP . " " . $Details}++;

    } elsif ( ($Type,$Interface,$IP,$MAC) = 
	 ($ThisLine =~ /DHCP(.*?)\((.*?)\) (.*?) (.*?)$/i ) ) {
	$HOSTAPD->{$Interface}->{$MAC}->{$Type}->{$Details}++;

    } elsif ( ($Type,$Interface,$MAC) = 
	 ($ThisLine =~ /DHCP(.*?)\((.*?)\) (.*?)$/i ) ) {
	$HOSTAPD->{$Interface}->{$MAC}->{$Type}->{$Details}++;

    } else {
	# Report any unmatched entries...
	push @OtherList,$ThisLine;
    }
}

if ($Show) {
    if (keys %{$HOSTAPD}) {
	foreach	$Interface (sort {$a cmp $b} keys %{$HOSTAPD}) {
	    print "\nInterface " . $Interface . "\n";
	    foreach $MAC (sort {$a cmp $b} keys %{$HOSTAPD->{$Interface}}) {
		print "\t" . $MAC . "\n";
		foreach $Type (sort {$a cmp $b} keys %{$HOSTAPD->{$Interface}->{$MAC}}) {
		    foreach $Details (sort {$a cmp $b} keys %{$HOSTAPD->{$Interface}->{$MAC}->{$Type}}) {
			print "\t\t" . $Type . 
			    substr( "          ", length($Type), 10 ) . 
			    $Details;
			$count = $HOSTAPD->{$Interface}->{$MAC}->{$Type}->{$Details};
			if ( $count > 1 ) {
			    if ( length($Details) ) { 
				print " ";
			    }
			    print "(" . $count . " times)";
			} 
			print "\n";
		    }
		}
	    }
	}
    }
}

if (($#OtherList >= 0) and ($ShowUnmatched)) {
   print "\n**Unmatched Entries**\n";
   print @OtherList;
}

exit(0);
# 

Example F.14. syslog:/etc/log.d/scripts/services/dnsmasq