init III
This commit is contained in:
225
Perl syslog server/syslog_tixgrid.pl
Normal file
225
Perl syslog server/syslog_tixgrid.pl
Normal file
@@ -0,0 +1,225 @@
|
||||
#!/bin/perl
|
||||
use strict;
|
||||
|
||||
use Tk;
|
||||
use Tk::TixGrid;
|
||||
|
||||
use POE qw (Loop::TkActiveState);
|
||||
use POE::Loop::TkActiveState;
|
||||
use POE::Kernel;
|
||||
use POE::Session;
|
||||
use POE::Resource::Aliases;
|
||||
use POE::Resource::Events;
|
||||
use POE::Resource::Extrefs;
|
||||
use POE::Resource::FileHandles;
|
||||
use POE::Resource::Sessions;
|
||||
use POE::Resource::SIDs;
|
||||
use POE::Resource::Signals;
|
||||
#use POE::Resource::Statistics;
|
||||
use POE::Component::Server::Syslog;
|
||||
|
||||
my @severity = qw /Emergency Alert Critical Error Warning Notice Informational Debug/;
|
||||
my @facility = qw /kernel user-level mail-system system-daemons security-auth-4 internal line-printer network-news UUCP clock-9 security-auth-10 FTP NTP log-audit log-alert clock-15 local0 local1 local2 local3 local4 local5 local6 local7/;
|
||||
my $LOGFILE = "syslog.txt";
|
||||
|
||||
POE::Session->create(
|
||||
inline_states => {
|
||||
#loop => \&loop,
|
||||
syslog => \&syslogdeamonpoe,
|
||||
gui => \&build_gui,
|
||||
_start => sub {
|
||||
$_[KERNEL]->yield($_) for qw( syslog gui);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
my $tixgrid;
|
||||
my @entbox;
|
||||
#x y x y
|
||||
@entbox=(0,1,2,1);
|
||||
my $selection=0;
|
||||
|
||||
$poe_kernel->run();
|
||||
print "Tschüss'n\n";
|
||||
exit 0;
|
||||
|
||||
sub reformattxgrid {
|
||||
#$tixgrid->formatGrid( @entbox, -bg => 'RED' , -xon => 0, -xoff => 1, -yon => 0, -yoff => 1);
|
||||
for (my $x=1;$x<=7;$x++) {
|
||||
for (my $y=1;$y<=$entbox[3]-1;$y++) {
|
||||
$tixgrid->formatBorder(1,1,$x,$y,-relief=>'groove'); #-background / -bg -borderwidth / -bd -filled -relief -selectbackground -xoff -xon -yoff -yon
|
||||
}
|
||||
}
|
||||
for (my $y=1;$y<=$entbox[3]-1;$y++) {
|
||||
#$tixgrid->formatGrid(1,$y,7,$y, -background => 'RED');
|
||||
}
|
||||
}
|
||||
sub get_cell {
|
||||
my ($x, $y)=@_;
|
||||
if ($x<=7 and $y<$entbox[3] and $x>0 and $y>0) {
|
||||
#printf "$x $y", $tixgrid->entrycget($x,$y, -text);
|
||||
}
|
||||
$selection=$y;
|
||||
print "aktuelle selection (left click) $selection\n";
|
||||
}
|
||||
sub tix_right_click {
|
||||
print "aktuelle selection (right click) $selection\n";
|
||||
}
|
||||
sub build_gui {
|
||||
#my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
|
||||
my $mbar = $poe_main_window->Menu();
|
||||
|
||||
# Menüleiste
|
||||
$poe_main_window -> configure(-menu => $mbar);
|
||||
my $help = $mbar -> cascade(-label =>"Help", -underline=>0, -tearoff => 0);
|
||||
$help -> command(-label =>"About", -command => sub {return; });
|
||||
# Menüleiste Ende
|
||||
|
||||
$tixgrid = $poe_main_window->TixGrid(-floatingrows => 1,
|
||||
-floatingcols => 0,
|
||||
-formatcmd => \&reformattxgrid,
|
||||
#-scrollbars => 'se',
|
||||
#-highlightcolor => 'RED',
|
||||
-selectbackground => 'LIGHTBLUE',
|
||||
-font => 'Arial 8',
|
||||
-width => 8,
|
||||
-height => 8,
|
||||
-borderwidth => 0,
|
||||
-relief => 'solid', # must be flat, groove, raised, ridge, solid, or sunken
|
||||
-state => 'normal', # must be normal or disabled
|
||||
-pady => 1,
|
||||
-padx => 1,
|
||||
#-leftmargin => 0,
|
||||
-browsecmd => \&get_cell,
|
||||
);
|
||||
|
||||
$tixgrid->set(0,0, -itemtype=>'text', -text=>"");
|
||||
$tixgrid->sizeColumn(0, -size=>0);
|
||||
|
||||
$tixgrid->set(1,0, -itemtype=>'text', -text=>"localtime");
|
||||
$tixgrid->sizeColumn(1, -size=>'auto');
|
||||
|
||||
$tixgrid->set(2,0, -itemtype=>'text', -text=>"sender");
|
||||
$tixgrid->sizeColumn(2, -size=>'auto');
|
||||
|
||||
$tixgrid->set(3,0, -itemtype=>'text', -text=>"origin");
|
||||
$tixgrid->sizeColumn(3, -size=>'auto');
|
||||
|
||||
$tixgrid->set(4,0, -itemtype=>'text', -text=>"facility");
|
||||
$tixgrid->sizeColumn(4, -size=>'auto');
|
||||
|
||||
$tixgrid->set(5,0, -itemtype=>'text', -text=>"severity");
|
||||
$tixgrid->sizeColumn(5, -size=>'auto');
|
||||
|
||||
$tixgrid->set(6,0, -itemtype=>'text', -text=>"time");
|
||||
$tixgrid->sizeColumn(6, -size=>'auto');
|
||||
|
||||
$tixgrid->set(7,0, -itemtype=>'text', -text=>"message");
|
||||
$tixgrid->sizeColumn(7, -size=>'auto');
|
||||
|
||||
my $srl_x = $poe_main_window -> Scrollbar(-orient=>'h',-command=>[xview => $tixgrid]);
|
||||
my $srl_y = $poe_main_window -> Scrollbar(-orient=>'v',-command=>[yview => $tixgrid]);
|
||||
$tixgrid -> configure(-yscrollcommand=>['set', $srl_y], -xscrollcommand=>['set',$srl_x]);
|
||||
|
||||
$tixgrid->grid(-row=>1, -column=>1, -sticky=>"NESW");
|
||||
$srl_y -> grid(-row=>1, -column=>2, -sticky=>"ns");
|
||||
$srl_x -> grid(-row=>2, -column=>1, -sticky=>"ew");
|
||||
|
||||
$tixgrid->bind('<ButtonRelease-3>' => [\&tix_right_click]);
|
||||
|
||||
$poe_main_window->gridColumnconfigure(1, -weight => 1);
|
||||
$poe_main_window->gridRowconfigure(1, -weight => 1);
|
||||
|
||||
#$kernel->yield("ev_loop");
|
||||
}
|
||||
sub syslogdeamonpoe {
|
||||
#my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
|
||||
POE::Component::Server::Syslog::UDP->spawn(
|
||||
#Type => 'udp',
|
||||
BindAddress => '0.0.0.0',
|
||||
BindPort => 514,
|
||||
InputState => \&input,
|
||||
);
|
||||
#$_[KERNEL]->yield("ev_loop");
|
||||
}
|
||||
sub loop {
|
||||
my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
|
||||
#$_[HEAP]->{counter}++;
|
||||
#$poe_main_window->update; # Needed on SunOS & MacOS-X
|
||||
#sleep 1;
|
||||
print "$kernel, $session, $heap\n";
|
||||
#$_[KERNEL]->yield("ev_loop");
|
||||
}
|
||||
sub input {
|
||||
#print "$_[ARG0]\n";
|
||||
my $sever = $_[10]->{severity};
|
||||
my $facil = $_[10]->{facility};
|
||||
my $message = $_[10]->{msg};
|
||||
my $sender = $_[10]->{host};
|
||||
my $stime = $_[10]->{time};
|
||||
|
||||
($sender) = $sender =~ /([^.]*)\./;
|
||||
|
||||
#von reihe 1 bis ende eine zeile nach unten verschieben
|
||||
$tixgrid->moveRow(1,$entbox[3],1);
|
||||
@entbox=(0, 1, $entbox[2], $entbox[3]+1);
|
||||
|
||||
#my $hostname;
|
||||
my $origin;
|
||||
#my $otime;
|
||||
|
||||
|
||||
|
||||
if ($message =~ /Address=/) {
|
||||
#$hostname = "";
|
||||
if ($message =~ /Address=([^\s]*) (.*:[0-9]{1,2}) ([^\s]*) (.*)/) {
|
||||
($origin, $stime, undef, $message) = $message =~ /Address=([^\s]*) (.*:[0-9]{1,2}) ([^\s]*) (.*)/;
|
||||
$message =~ s/$origin//;
|
||||
$message .= " # fwd. by $sender";
|
||||
}
|
||||
else {
|
||||
($origin, $message) = $message =~ /Address=([^\s]*) (.*)/i;
|
||||
$message =~ s/Address=$origin//;
|
||||
$message .= " # fwd. by $sender";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$origin=$sender;
|
||||
if ($message =~ /[a-z]{3} [0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}/i) {
|
||||
($stime) = $message =~ /([a-z]{3} [0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3})/i;
|
||||
$message =~ s/$stime//;
|
||||
}
|
||||
elsif ($message =~ /[a-z]{3} [0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/i) {
|
||||
($stime) = $message =~ /([a-z]{3} [0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2})/i;
|
||||
$message =~ s/$stime//;
|
||||
}
|
||||
}
|
||||
$message =~ s/\s{2,}/ /;
|
||||
|
||||
$tixgrid->selectionClear(0,0,'max','max');
|
||||
$selection++;
|
||||
print "setze selection (new msg) $selection\n";
|
||||
$tixgrid->selectionSet(0,$selection,7,$selection);
|
||||
|
||||
|
||||
my $localt=localtime;
|
||||
|
||||
$tixgrid->set(1,1, -itemtype=>'text', -text=>"$localt"); # ok
|
||||
#$tg->bind('<ButtonRelease-3>' => [\&test, 1, 1]);
|
||||
|
||||
|
||||
$tixgrid->set(2,1, -itemtype=>'text', -text=>"$sender"); # sender
|
||||
$tixgrid->set(3,1, -itemtype=>'text', -text=>"$origin"); # origin
|
||||
|
||||
$tixgrid->set(4,1, -itemtype=>'text', -text=>"$facility[$facil]"); # ok
|
||||
$tixgrid->set(5,1, -itemtype=>'text', -text=>"$severity[$sever]"); # ok
|
||||
|
||||
$tixgrid->set(6,1, -itemtype=>'text', -text=>"$stime"); # ok
|
||||
$tixgrid->set(7,1, -itemtype=>'text', -text=>"$message"); # message
|
||||
|
||||
#print "$localt|$sender|$origin|$facility[$facil]|$severity[$sever]|$stime|$message\n";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user