207 lines
7.6 KiB
Perl
207 lines
7.6 KiB
Perl
#!/bin/perl
|
|
use Net::Syslogd;
|
|
use Thread;
|
|
use Tk;
|
|
use strict;
|
|
|
|
my $LOGFILE :shared;
|
|
$LOGFILE = "syslog.txt";
|
|
|
|
|
|
# Main Window
|
|
my $mw = new MainWindow;
|
|
my $mbar = $mw -> Menu();
|
|
my $i;
|
|
|
|
my $stlab = $mw -> Label(-height=>1, -text=>"received");
|
|
my $iplab = $mw -> Label(-height=>1, -text=>"IP");
|
|
my $falab = $mw -> Label(-height=>1, -text=>"facility");
|
|
my $selab = $mw -> Label(-height=>1, -text=>"severity");
|
|
my $tilab = $mw -> Label(-height=>1, -text=>"time");
|
|
my $holab = $mw -> Label(-height=>1, -text=>"hostname");
|
|
my $melab = $mw -> Label(-height=>1, -text=>"message");
|
|
|
|
my $sttxt;# = $mw -> Text(-width=>21, -wrap=>"none");
|
|
my $iptxt;# = $mw -> Text(-width=>16, -wrap=>"none");
|
|
my $fatxt;# = $mw -> Text(-width=>8, -wrap=>"none");
|
|
my $setxt;# = $mw -> Text(-width=>15, -wrap=>"none");
|
|
my $titxt;# = $mw -> Text(-width=>15, -wrap=>"none");
|
|
my $hotxt;# = $mw -> Text(-width=>15, -wrap=>"none");
|
|
my $metxt;# = $meframe -> Text(-width=>15, -wrap=>"none");#-width=>10, -height=>10, -wrap=>"none");
|
|
|
|
# Frame für Messagetext und Scrollbalken
|
|
my $meframe = $mw->Frame();
|
|
|
|
# Vertikaler Scrollbalken für Textfelder
|
|
my $srl_y = $meframe -> Scrollbar();
|
|
|
|
# Definition der Textfelder
|
|
my $textboxes = [ $sttxt = $mw -> Text(-width=>21, -wrap=>"none"),
|
|
$metxt = $meframe -> Text(-width=>15, -wrap=>"none"),
|
|
$iptxt = $mw -> Text(-width=>16, -wrap=>"none"),
|
|
$fatxt = $mw -> Text(-width=>8, -wrap=>"none"),
|
|
$setxt = $mw -> Text(-width=>15, -wrap=>"none"),
|
|
$titxt = $mw -> Text(-width=>15, -wrap=>"none"),
|
|
$hotxt = $mw -> Text(-width=>15, -wrap=>"none"),
|
|
];
|
|
|
|
# This method is called when one Listbox is scrolled with the keyboard
|
|
# It makes the Scrollbar reflect the change, and scrolls the other lists
|
|
sub scroll_textboxes {
|
|
my ($sb, $scrolled, $lbs, @args) = @_;
|
|
$sb->set(@args); # tell the Scrollbar what to display
|
|
my ($top, $bottom) = $scrolled->yview( );
|
|
foreach my $list (@$lbs) {
|
|
$list->yviewMoveto($top); # adjust each lb
|
|
}
|
|
}
|
|
|
|
# Configure each Listbox to call &scroll_textboxes
|
|
foreach my $list (@$textboxes) {
|
|
$list->configure(-yscrollcommand => [ \&scroll_textboxes, $srl_y,
|
|
$list, $textboxes ]);
|
|
}
|
|
|
|
# Configure the Scrollbar to scroll each Listbox
|
|
$srl_y->configure(-command => sub { foreach my $list (@$textboxes) {
|
|
$list->yview(@_);
|
|
}});
|
|
# Vertikaler Scrollbalken für Textfelder Ende
|
|
|
|
|
|
# Horizontaler Scrollbalken für Messages Textbox
|
|
my $srl_x = $meframe -> Scrollbar(-orient=>'h',-command=>[xview => $metxt]);
|
|
$metxt -> configure(-yscrollcommand=>['set', $srl_y], -xscrollcommand=>['set',$srl_x]);
|
|
# Horizontaler Scrollbalken für Messages Textbox Ende
|
|
|
|
# Menüleiste
|
|
$mw -> configure(-menu => $mbar);
|
|
my $help = $mbar -> cascade(-label =>"Help", -underline=>0, -tearoff => 0);
|
|
$help -> command(-label =>"About", -command => sub {return; });
|
|
# Menüleiste Ende
|
|
|
|
$stlab -> grid (-row=>5, -column=>1);
|
|
$iplab -> grid (-row=>5, -column=>2);
|
|
$falab -> grid (-row=>5, -column=>3);
|
|
$selab -> grid (-row=>5, -column=>4);
|
|
$tilab -> grid (-row=>5, -column=>5);
|
|
$holab -> grid (-row=>5, -column=>6);
|
|
$melab -> grid (-row=>5, -column=>7);
|
|
|
|
$sttxt -> grid(-row=>10,-column=>1, -sticky=>"NSEW");
|
|
$iptxt -> grid(-row=>10,-column=>2, -sticky=>"NSEW");
|
|
$fatxt -> grid(-row=>10,-column=>3, -sticky=>"NSEW");
|
|
$setxt -> grid(-row=>10,-column=>4, -sticky=>"NSEW");
|
|
$titxt -> grid(-row=>10,-column=>5, -sticky=>"NSEW");
|
|
$hotxt -> grid(-row=>10,-column=>6, -sticky=>"NSEW");
|
|
$metxt -> grid(-row=>1,-column=>1, -sticky=>"NSEW");
|
|
$meframe -> grid(-row=>10,-column=>7, -sticky=>"NSEW");
|
|
|
|
|
|
#$mw->gridColumnconfigure(0, -weight => 1);
|
|
$mw->gridColumnconfigure(1, -weight => 0);
|
|
$mw->gridColumnconfigure(2, -weight => 0);
|
|
$mw->gridColumnconfigure(3, -weight => 0);
|
|
$mw->gridColumnconfigure(4, -weight => 0);
|
|
$mw->gridColumnconfigure(5, -weight => 0);
|
|
$mw->gridColumnconfigure(6, -weight => 0);
|
|
$mw->gridColumnconfigure(7, -weight => 1);
|
|
$meframe->gridColumnconfigure(1, -weight => 1);
|
|
|
|
$mw->gridRowconfigure(10, -weight => 1);
|
|
$meframe->gridRowconfigure(1, -weight => 1);
|
|
|
|
$srl_y -> grid(-row=>1,-column=>2,-sticky=>"ns");
|
|
$srl_x -> grid(-row=>2,-column=>1,-sticky=>"ew");
|
|
|
|
|
|
my $thr = new Thread \&syslogd;
|
|
|
|
|
|
MainLoop;
|
|
|
|
sub syslogd {
|
|
my $syslogd = Net::Syslogd->new() or die "Error creating Syslogd listener: ", Net::Syslogd->error;
|
|
|
|
# Logfile einlesen
|
|
open SYSLOG, "<$LOGFILE";
|
|
foreach (<SYSLOG>) {
|
|
chomp;
|
|
my $la; my $b; my $c; my $d; my $e; my $f; my $g;
|
|
($a,$b,$c,$d,$e,$f,$g) = split/\|/,$_;
|
|
|
|
$sttxt->insert("1.0", "$a\n");
|
|
$iptxt->insert("1.0", "$b\n");
|
|
$fatxt->insert("1.0", "$c\n");
|
|
$setxt->insert("1.0", "$d\n");
|
|
$titxt->insert("1.0", "$e\n");
|
|
$hotxt->insert("1.0", "$f\n");
|
|
$metxt->insert("1.0", "$g\n");
|
|
}
|
|
close SYSLOG;
|
|
|
|
while (1) {
|
|
my $message = $syslogd->get_message();
|
|
|
|
if (!defined($message)) {
|
|
printf "$0: %s\n", Net::Syslogd->error;
|
|
exit 1;
|
|
} elsif ($message == 0) {
|
|
next;
|
|
}
|
|
|
|
if (!defined($message->process_message())) {
|
|
printf "$0: %s\n", Net::Syslogd->error;
|
|
} else {
|
|
my $peeraddr = $message->peeraddr;
|
|
my $port = $message->peerport;
|
|
my $facility = $message->facility;
|
|
my $severity = $message->severity;
|
|
my $time = $message->time;
|
|
my $hostname = $message->hostname;
|
|
my $message = $message->message;
|
|
my $localt = localtime;
|
|
|
|
($localt) = $localt =~ /.{3} (.*)/;
|
|
|
|
chomp($peeraddr); chomp($port); chomp($facility); chomp($severity); chomp($time); chomp($hostname); chomp($message);
|
|
|
|
#printf "A:%s F:%s S:%s T:%s H:%s M:%s\n", $peeraddr, $facility, $severity, $time, $hostname, $message;
|
|
|
|
my $sender = $peeraddr;
|
|
|
|
$time = "" if ($time == "0");
|
|
$hostname = "" if ($hostname == "0");
|
|
|
|
if ($message =~ /^Address=/) {
|
|
$hostname = "";
|
|
if ($message =~ /^Address=([^\s]*) (.*:[0-9]{1,2}) ([^\s]*) (.*)/) {
|
|
($peeraddr, $time, undef, $message) = $message =~ /^Address=([^\s]*) (.*:[0-9]{1,2}) ([^\s]*) (.*)/;
|
|
$message =~ s/$peeraddr//;
|
|
$message .= " # fwd. by $sender";
|
|
}
|
|
else {
|
|
($peeraddr, $message) = $message =~ /^Address=([^\s]*) (.*)/;
|
|
$message =~ s/^Address=$peeraddr//;
|
|
$message .= " # fwd. by $sender";
|
|
}
|
|
}
|
|
$message =~ s/\s{2,}/ /;
|
|
|
|
# Logfile schreiben
|
|
my $log = sprintf "%s|%s|%s|%s|%s|%s|%s\n", $localt, $peeraddr, $facility, $severity, $time, $hostname, $message;
|
|
open SYSLOG, ">>$LOGFILE";
|
|
printf SYSLOG "$log";
|
|
close SYSLOG;
|
|
|
|
$sttxt->insert("1.0", "$localt\n");
|
|
$iptxt->insert("1.0", "$peeraddr\n");
|
|
$fatxt->insert("1.0", "$facility\n");
|
|
$setxt->insert("1.0", "$severity\n");
|
|
$titxt->insert("1.0", "$time\n");
|
|
$hotxt->insert("1.0", "$hostname\n");
|
|
$metxt->insert("1.0", "$message\n");
|
|
#$txt -> configure(-state=>"disabled");
|
|
}
|
|
}
|
|
} |