init III
This commit is contained in:
209
Perl Euronext Multicast Test Tool/client.pl
Normal file
209
Perl Euronext Multicast Test Tool/client.pl
Normal file
@@ -0,0 +1,209 @@
|
||||
#!/usr/bin/perl
|
||||
#use warnings;
|
||||
use Net::hostent;
|
||||
#use strict;
|
||||
use IO::Socket;
|
||||
use Tk;
|
||||
use Tk::Font;
|
||||
use JSON;
|
||||
use threads ();
|
||||
use threads::shared ();
|
||||
|
||||
use Getopt::Long;
|
||||
|
||||
#my $peerhost = "127.0.0.1";
|
||||
#my $peerport = "59001";
|
||||
#my $timeout = "10";
|
||||
|
||||
|
||||
GetOptions(
|
||||
"h=s" => \$peerhost,
|
||||
"p=s" => \$peerport,
|
||||
"t=s" => \$timeout
|
||||
);
|
||||
|
||||
if ($peerhost== "") {&nopara};
|
||||
if ($peerport== "") {&nopara};
|
||||
if ($timeout== "") {&nopara};
|
||||
sub nopara {
|
||||
print "server [options]\n\n",
|
||||
" -h Monitoring Host/IP Address 10.10.10.10\n",
|
||||
" -p Monitoring Host Port\n",
|
||||
" -t Alarm Timeout in sec\n";
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
my @sdata0 :shared;
|
||||
my $thr0;
|
||||
my %data :shared;
|
||||
|
||||
my $st1 = "Monitoring Server OK";
|
||||
my $bg = "green";
|
||||
my $mw = MainWindow->new();
|
||||
my $menubar = $mw->Menu;
|
||||
#$mw->minsize( qw(300 300));
|
||||
$mw->title("Status Monitor v1.1");
|
||||
$mw->configure(-background=>'grey');
|
||||
$mw->fontCreate('font1', -family => 'Verdana',-size => 8);
|
||||
$mw->configure(-menu => $menubar);
|
||||
my $file = $menubar->Menubutton(-label => 'File',-underline => 0);
|
||||
my $opt = $menubar->Menubutton(-label => 'Options',-underline => 0);
|
||||
my $about = $menubar->Menubutton(-label => '?',-underline => 0);
|
||||
$file->command(-label => "Quit", -command => sub{$mw->destroy});
|
||||
$opt->command(-label => "Reconnect", -command => sub{&startthr;});
|
||||
$about->command(-label => "Info",-command => [\&about, "About"],);
|
||||
|
||||
my $JSONObject = JSON::XS->new->ascii->pretty->allow_nonref();
|
||||
|
||||
|
||||
sub about ($) {
|
||||
my ($arg) = @_;
|
||||
my $tw=$mw->Toplevel(-title => "Hilfe $arg");
|
||||
my $mes=$tw->Message(-text => "Multicast Checker Status Monitor\nby Martijn Niedlich\n",
|
||||
-width => '10c', -justify => 'center')->
|
||||
pack(-side => 'top');
|
||||
my $but=$tw->Button(-text => "Schließen",
|
||||
-command => [$tw => 'destroy'])->
|
||||
pack(-side => 'top');
|
||||
}
|
||||
|
||||
|
||||
sub TCP_CLI {
|
||||
|
||||
|
||||
my $socket = new IO::Socket::INET (
|
||||
PeerAddr => $peerhost,
|
||||
PeerPort => $peerport,
|
||||
Proto => 'tcp',
|
||||
) or die "Keinen Server gefunden unter $peerhost:$peerport\n";
|
||||
$socket->send("\n");
|
||||
#printf "[Connect to %s]\n", $socket->peerport;
|
||||
|
||||
|
||||
|
||||
while ( $socket ) {
|
||||
my $recv_data;
|
||||
$socket->send("\n");
|
||||
#%data = "";
|
||||
$socket->recv($recv_data,1024);
|
||||
#lock %data;
|
||||
# print $recv_data;
|
||||
|
||||
%data = %{$JSONObject->decode($recv_data)};
|
||||
sleep 1;
|
||||
}
|
||||
|
||||
}
|
||||
sub startthr {
|
||||
$thr0 = threads->new(\&TCP_CLI);
|
||||
#$thr0 = threads->new(\&checkdata);
|
||||
&statusbars;
|
||||
}
|
||||
&startthr;
|
||||
#my $grid;
|
||||
sub checkdata {
|
||||
my @sdata0;
|
||||
my $counter = 3;
|
||||
|
||||
|
||||
$sdata1[7] = "MC Monitoring Server Online";
|
||||
$sdata1[8] = "green";
|
||||
if ($thr0->is_joinable()) {$sdata1[7] = "MC Monitoring Server Offline"; $sdata1[8] = "red"}
|
||||
|
||||
#while( my ($k, $v) = each %data ) {
|
||||
foreach $key ( keys %data) {
|
||||
$counter++;
|
||||
my $ctime = time - $timeout;
|
||||
|
||||
@sdata0 = split(/-/, $key);
|
||||
|
||||
if ($key !=~ "/REF/" ) {
|
||||
if ($data{REF} > $data{$key}) {$sdata0[2] = "ERROR";$sdata0[3] = "red";}else{$sdata0[2] = "OK";$sdata0[3] = "green";}
|
||||
if ($data{$key} == "00") { $sdata0[4] = "NEVER"; $sdata0[3] = "blue" } else {$sdata0[4] = scalar localtime($data{$key});};
|
||||
if ($sdata1[8] eq "red") { $sdata0[3] = "yellow"};
|
||||
$servicename->configure(-text=> $data{NAME});
|
||||
$labels1[$counter]->configure(-background=> $sdata0[3]);
|
||||
$labels2[$counter]->configure(-background=> $sdata0[3]);
|
||||
$labels3[$counter]->configure(-text=> $sdata0[2],-background=> $sdata0[3]);
|
||||
$labels4[$counter]->configure(-text=> $sdata0[4],-background=> $sdata0[3]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$statusbarserverstatus->configure(-text=>$sdata1[7],-background=> $sdata1[8]);
|
||||
$statusbarserver1->configure(-background=>$sdata1[8]);
|
||||
$statusbarserver2->configure(-background=>$sdata1[8]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sub statusbars {
|
||||
$servicename=$mw->Label(-width => "52", -font => 'font1',-text => "SERVICE NAME",-relief => 'groove',-background=>"grey", -font => 'font1')->grid(-row => 0, -column => 1,-columnspan=>4,-sticky=>'ew');
|
||||
|
||||
$headbarserver=$mw->Label(-width => "10", -font => 'font1',-text => "Mon Srv",-relief => 'groove',-background=>"grey", -font => 'font1')->grid(-row => 1, -column => 1,-sticky=>'w');
|
||||
$headbarserver=$mw->Label(-width => "7", -font => 'font1',-text => "Mon Port",-relief => 'groove',-bd =>2,-background=>"grey", -font => 'font1')->grid(-row => 1, -column => 2,-sticky=>'ew');
|
||||
$headbarserver=$mw->Label(-width => "25", -font => 'font1',-text => "Status",-relief => 'groove',-bd =>2,-background=>"grey", -font => 'font1')->grid(-row => 1, -column => 3,-columnspan=>2,-sticky=>'ew');
|
||||
$sdata0[5] = $peerhost;
|
||||
$sdata0[6] = $peerport;
|
||||
|
||||
$statusbarserver1=$mw->Label(-width => "10", -font => 'font1',-text => $sdata0[5],-relief => 'groove',-background=>"grey", -font => 'font1')->grid(-row => 2, -column => 1,-sticky=>'w');
|
||||
$statusbarserver2=$mw->Label(-width => "7", -font => 'font1',-text => $sdata0[6],-relief => 'groove',-bd =>2,-background=>"grey", -font => 'font1')->grid(-row => 2, -column => 2,-sticky=>'w');
|
||||
$statusbarserverstatus=$mw->Label(-width => "25", -font => 'font1',-text => "-",-relief => 'groove',-bd =>2,-background=>"grey", -font => 'font1')->grid(-row => 2, -column => 3,-columnspan=>2,-sticky=>'ew');
|
||||
|
||||
|
||||
|
||||
|
||||
$headbardata=$mw->Label(-width => "10", -font => 'font1',-text => "MC Group",-relief => 'groove',-background=>"grey", -font => 'font1')->grid(-row => 3, -column => 1);
|
||||
$headbardata=$mw->Label(-width => "7", -font => 'font1',-text => "MC Port",-relief => 'groove',-bd =>2,-background=>"grey", -font => 'font1')->grid(-row => 3, -column => 2);
|
||||
$headbardata=$mw->Label(-width => "10", -font => 'font1',-text => "Status",-relief => 'groove',-bd =>2,-background=>"grey", -font => 'font1')->grid(-row => 3, -column => 3);
|
||||
$headbardata=$mw->Label(-width => "25", -font => 'font1',-text => "Last Data seen",-relief => 'groove',-bd => 2,-background=>"grey", -font => 'font1')->grid(-row => 3, -column => 4);
|
||||
|
||||
my $counter2 = 3;
|
||||
|
||||
foreach $key (keys %data) {
|
||||
$counter2++;
|
||||
my $ctime = time - 10;
|
||||
my @sdata1 = split(/-/, $key);
|
||||
if ($key !=~ "/REF/" and $key != "/NAME/") {
|
||||
$labels1[$counter2]=$mw->Label(-width => "10",-text => $sdata1[0],-relief => 'groove',-background=>"grey", -font => 'font1')->grid(-row => $counter2, -column => 1);
|
||||
$labels2[$counter2]=$mw->Label(-width => "7",-text => $sdata1[1],-relief => 'groove',-bd =>2,-background=>"grey", -font => 'font1')->grid(-row => $counter2, -column => 2);
|
||||
$labels3[$counter2]=$mw->Label(-width => "10",-text => "NO DATA",-relief => 'groove',-bd =>2,-background=>"grey", -font => 'font1')->grid(-row => $counter2, -column => 3);
|
||||
$labels4[$counter2]=$mw->Label(-width => "25",-text => "NO DATA",-relief => 'groove',-bd => 2,-background=>"grey", -font => 'font1')->grid(-row => $counter2, -column => 4);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#sleep 1;
|
||||
my $counter22 = 0;
|
||||
sub event {
|
||||
if (%data) {
|
||||
} else {
|
||||
$counter22++;
|
||||
if ($counter22 <= 20000)
|
||||
{
|
||||
&event;
|
||||
}
|
||||
}
|
||||
}
|
||||
&event;
|
||||
|
||||
&statusbars;
|
||||
|
||||
|
||||
$mw->repeat(500 => \&run);
|
||||
|
||||
MainLoop;
|
||||
sub run {
|
||||
&checkdata;
|
||||
$mw->update;
|
||||
|
||||
}
|
||||
|
||||
|
||||
26
Perl Euronext Multicast Test Tool/sender.pl
Normal file
26
Perl Euronext Multicast Test Tool/sender.pl
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/perl
|
||||
# server
|
||||
use strict;
|
||||
use IO::Socket::Multicast;
|
||||
use Getopt::Long;
|
||||
|
||||
my ($group,$port);
|
||||
GetOptions(
|
||||
"g=s" => \$group,
|
||||
"p=s" => \$port
|
||||
);
|
||||
|
||||
|
||||
#use constant DESTINATION => '226.1.1.2:2000';
|
||||
my $sock = IO::Socket::Multicast->new(Proto=>'udp',PeerAddr=>$group,PeerPort=>$port);
|
||||
|
||||
while (1) {
|
||||
#my $message = localtime;
|
||||
my $message = "DATA";
|
||||
#$message .= "\n" . `who`;
|
||||
#$message .= "\n";
|
||||
$sock->send($message) || die "Couldn't send: $!";
|
||||
} continue {
|
||||
sleep 1;
|
||||
}
|
||||
|
||||
190
Perl Euronext Multicast Test Tool/server2.pl
Normal file
190
Perl Euronext Multicast Test Tool/server2.pl
Normal file
@@ -0,0 +1,190 @@
|
||||
#!/usr/bin/perl
|
||||
use IO::Socket;
|
||||
use Socket;
|
||||
use Net::hostent;
|
||||
#use warnings;
|
||||
use Tk;
|
||||
#use strict;
|
||||
use IO::Socket::Multicast;
|
||||
use Getopt::Long;
|
||||
use threads ();
|
||||
use threads::shared ();
|
||||
use JSON::XS;
|
||||
use POE;
|
||||
use POE::Session;
|
||||
use POE::Loop::Select;
|
||||
use POE::Resource::Aliases;
|
||||
use POE::Resource::Events;
|
||||
use POE::Resource::Extrefs;
|
||||
use POE::Resource::FileHandles;
|
||||
use POE::Resource::SIDs;
|
||||
use POE::Resource::Sessions;
|
||||
use POE::Resource::Signals;
|
||||
use POE::Resource::Statistics;
|
||||
use POE::Component::Server::TCP;
|
||||
|
||||
my $mw = MainWindow->new();
|
||||
my $menubar = $mw->Menu;
|
||||
$mw->minsize( qw(300 300));
|
||||
$mw->title("SERVER Status Monitor v1.0");
|
||||
$mw->configure(-background=>'grey');
|
||||
$mw->fontCreate('font1', -family => 'Verdana',-size => 12);
|
||||
$mw->configure(-menu => $menubar);
|
||||
my $file = $menubar->Menubutton(-label => 'File',-underline => 0);
|
||||
my $opt = $menubar->Menubutton(-label => 'Options',-underline => 0);
|
||||
my $about = $menubar->Menubutton(-label => '?',-underline => 0);
|
||||
my $box = $mw->Listbox(-height => 15, -width => 100);
|
||||
my $scroll = $mw->Scrollbar(-command => ['yview', $box]);
|
||||
|
||||
$file->command(-label => "Quit", -command => sub{exit;});
|
||||
$opt->command(-label => "Reconnect", -command => sub{&startthr;});
|
||||
$about->command(-label => "Info",-command => [\&about, "About"],);
|
||||
|
||||
$box->configure(-yscrollcommand => ['set', $scroll]);
|
||||
#$box->pack(-side => 'left', -fill => 'both', -expand => 1);
|
||||
#$scroll->pack(-side => 'right', -fill => 'y');
|
||||
$box->grid(-row => 1, -column => 1, -sticky => "ew");
|
||||
#$scroll->grid(-row => 1, -column => 1);
|
||||
|
||||
#my $table = new Term::Menu;
|
||||
my $msg0 : shared = "NO MSG";
|
||||
my $msg;
|
||||
my %results : shared;
|
||||
my $thr0;
|
||||
my $ctime:shared;
|
||||
my $name:shared;
|
||||
my $servicename :shared =0;
|
||||
my $Port :shared =0;
|
||||
my $senddata;
|
||||
|
||||
|
||||
|
||||
GetOptions(
|
||||
"s=s" => \$servicename,
|
||||
"p=s" => \$Port,
|
||||
);
|
||||
|
||||
|
||||
|
||||
sub nopara {
|
||||
$msg1 = "server [options]\n\n";
|
||||
$msg1.= " -s Service Name for Client\n";
|
||||
$msg1.= " -p Monitoring Server Port\n";
|
||||
#print $msg1;
|
||||
return $msg1;
|
||||
#exit;
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ($Port eq "0") {print &nopara; exit;};
|
||||
if ($servicename eq "0") {print &nopara; exit;};
|
||||
|
||||
sub TCP_SRV {
|
||||
my @rip:shared;
|
||||
my @rport:shared;
|
||||
|
||||
my $coun = 0;
|
||||
POE::Component::Server::TCP->new(
|
||||
Alias => "server",
|
||||
Port => $Port,
|
||||
ClientInput => sub {
|
||||
$coun++;
|
||||
my $JSONObject = JSON::XS->new->ascii->pretty->allow_nonref();
|
||||
my ($session, $heap, $input) = @_[SESSION, HEAP, ARG0];
|
||||
#print "Session ", $session->ID(), " got input send data:\n\n";
|
||||
|
||||
$rip0 = $heap->{remote_ip};
|
||||
$rport = $heap->{remote_port};
|
||||
logevent('',$session);
|
||||
$ctime = time - 10;
|
||||
$results{REF} = ($ctime);
|
||||
$senddata=$JSONObject->encode(\%results);
|
||||
$heap->{client}->put($senddata);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
sub logevent {
|
||||
|
||||
my ($state, $session, $arg) = @_;
|
||||
my $id = $session->ID();
|
||||
my $log = scalar localtime(time).": session $id, client: $rip0, clientport: $rport";
|
||||
print $log;
|
||||
print "\n";
|
||||
#print &nrthr;
|
||||
$box->insert('end', $log);
|
||||
$box->see('end');
|
||||
|
||||
}
|
||||
|
||||
$poe_kernel->run();
|
||||
}
|
||||
|
||||
|
||||
|
||||
my $data0 :shared = 0;
|
||||
my $thr0_tid;
|
||||
my $group;
|
||||
my $port;
|
||||
my $tid;
|
||||
sub MC_RECV0 {
|
||||
my $sock = IO::Socket::Multicast->new(Proto=>'udp',LocalPort=>$port);
|
||||
$sock->mcast_add($group) || die "Couldn't set group: $!\n";
|
||||
|
||||
while (1) {
|
||||
#lock $data0;
|
||||
my $data00 = "NODATA";
|
||||
$sock->recv($data00,1024);
|
||||
#$data0 = $data00;
|
||||
$data0 = time;
|
||||
$results{$group."-".$port} = ($data0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#threads->new(\&TCP_SRV2,$msg0);
|
||||
#
|
||||
|
||||
my $counter;
|
||||
my $line;
|
||||
open CONFFILE, "<config.ini" or die("Could not open config.ini.");
|
||||
|
||||
foreach $line (<CONFFILE>) {
|
||||
chomp($line);
|
||||
$counter++;
|
||||
my @data = split(/,/, $line);
|
||||
$results{$data[0]."-".$data[1]} = "00";
|
||||
$thr0 = threads->new(\&MC_RECV0,$group=$data[0], $port=$data[1], $tid=$counter);
|
||||
|
||||
}
|
||||
|
||||
sub nrthr {
|
||||
my $count;
|
||||
my @running;
|
||||
@running = threads->list();
|
||||
$count = @running;
|
||||
$count = $count;
|
||||
print "Threads Running: ".$count."\n";
|
||||
}
|
||||
|
||||
threads->new(\&TCP_SRV);
|
||||
|
||||
foreach my $val (%results){
|
||||
$msg0 .= $val;
|
||||
print $val."\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
$mw->repeat(1000 => \&run);
|
||||
MainLoop;
|
||||
sub run {
|
||||
$mw->update;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user