Log Entries

<%perl> my $odd = 0; foreach my $class (sort keys %log_sort){ next unless grep(/^$class$/,@classes); foreach my $l (sort {$b->{timestamp} <=> $a->{timestamp} } @{$log_sort{$class}} ) { my $uri = $r->uri; my $time = localtime($l->{timestamp}); my $entry = $l->{entry}; my $logfile = defined $l->{logfile} ? 1 : 0; # Make each nocdp log entry into links to device_search if ($class =~ /(nocdp|timeout)/){ my @ret; foreach my $nocdp (split / /, $entry){ push (@ret, "$nocdp"); } $entry = join(' ',@ret); } elsif ($class =~ /(nosnmp)/){ my @ret; foreach my $nosnmp (split / /, $entry){ push (@ret, "$nosnmp"); } $entry = join(' ',@ret); } my $details = $logfiles->{$l->{id}}; $odd++; % if ($details){ % } % } %}
Class Entry View Log Time Stamp
<% $l->{class} %> <% $entry %> X <% $time |h %>
 
<%$details |h%>

Entry Types to Show

% foreach my $c (keys %$db_classes){ <%$c%>:>   %}
Number of Entries per category:
<%args> @classes => qw/arp discover mac netbios/ $number => 1 @log => () <%shared> my $logfiles = {}; <%init> # Check for stuffing of non-numerics $number = 5 unless $number =~ /^\d+$/; my $db_classes = sql_column('log',['distinct(class)','true']); my $log = []; # Get the log entries we want foreach my $class (@classes){ # Check for non existant next unless defined $db_classes->{$class}; my $logs = sql_rows('log', ['id','extract(epoch from creation) as timestamp','class','entry','logfile'], {'class' => $class},undef, "order by timestamp desc limit $number"); push (@$log,@$logs); } # Get the Log Files if requested foreach my $l (@log){ my $db_entry = sql_hash('log',['id','logfile'],{'id'=>$l}); unless (defined $db_entry){ $logfiles->{$l} = 'Not found in Database'; next; } my $file = $db_entry->{logfile}; # Uncompressed Log Files if (-r $file){ $logfiles->{$l} = ''; my $ok = open (LOG, "<$file"); unless ($ok){ $logfiles->{$l} = "Couldn't open $file. $!\n"; next; } while (){ $logfiles->{$l} .= $_; } close LOG; # Gzipped Log Files } elsif (-r "$file.gz"){ eval { use Compress::Zlib; }; if ($@){ $logfiles->{$l} = 'Log File is Gzipped. Please install Perl module Compress::Zlib'; next; } my $gz = gzopen("$file.gz", "rb"); unless (defined $gz){ $logfiles->{$l} = "Problem with gzcat. $gzerrno\n"; next; } my $buffer; $logfiles->{$l} .= $buffer while $gz->gzread($buffer) > 0; $gz->gzclose(); # Unknown / Permission files. } else { my $t1 = -r $file; $t1 = $!; my $t2 = -r "$file.gz"; $t2 = $!; $logfiles->{$l} = "I can't read/find $file ($t1) or $file.gz ($t2).\n"; } } # Split them up by class into separate arrays stored in this hash my %log_sort; foreach my $l (@$log){ my $class = $l->{class}; push (@{$log_sort{$class}},$l); } %# %# title() %# <%method title> - Log \ %# $Id: log.html,v 1.11 2007/12/18 01:26:04 maxbaker Exp $ %# vim:syntax=mason