====== Client side connection test ====== ^ Author | [[ hlang@mweb.com | Hermann Lang ]] | ^ Compatibility | Xymon 4.2 | ^ Requirements | Perl, Linux | ^ Download | None | ^ Last Update | 2017-10-10 | ===== Description ===== This program tests network connections from the XYmon client to remote servers. {{:monitors:xymon-remoteconns.jpg?400|}} ===== Installation ===== === Client side === Add the script /etc/xymon-client/ext/xymon-remoteconns.pl and make it executable. Add the clients configuration file /etc/xymon-client/client.d/xymon-remoteconns.cfg Restart the xymon client === Server side === ===== Source ===== ==== xymon-remoteconns.cfg ==== [remote-conns] ENVFILE /etc/xymon-client/xymonclient.cfg CMD $XYMONCLIENTHOME/ext/xymon-remoteconns.pl INTERVAL 5m ==== xymon-remoteconns.pl ==== #!/usr/bin/perl -w # This program tests network connections from the xymon client to a remote servers. # Update the array @servers with the list of remote servers and ports to test. The format # for an entry is the "server:port". Example: # @servers = qw(192.168.0.1:80 192.168.0.1:8080 192.168.10.5:21); # Author : H. Lang # Date : 2017/10/10 #---------------------------------------------------------------------------------------- use strict; use IO::Socket::INET; #---------------------------------------------------------------------------------------- my $XYTEST = "remote-conns"; my @servers = qw(192.168.0.1:80 192.168.0.1:8080 192.168.10.5:21); my $server_status = ""; my $server; my $debug = "no"; #my $debug = "yes"; #---------------------------------------------------------------------------------------- my %colours = ( green => 0, yellow => 1, red => 2 ); my $colour = 'green'; use constant ERRTABLECELL => q{style="color:white;background-color:red"}; use constant WARNTABLECELL => q{style="color:white;background-color:yellow"}; #---------------------------------------------------------------------------------------- sub setcolour { my ($current, $new) = @_; return ($colours{$new} > $colours{$current}) ? $new : $current; } #---------------------------------------------------------------------------------------- sub connect_test { my ($input) = @_; my ($server,$port) = (split(/:/,$input)); my $status = "green"; if ( my $socket = new IO::Socket::INET ( PeerHost => "$server", PeerPort => "$port", Proto => 'tcp', Timeout => '5') ) { shutdown($socket, 1); $socket->close(); }else{ $status = "red"; } return ($status); } #---------------------------------------------------------------------------------------- # MAIN #---------------------------------------------------------------------------------------- my $date = localtime(); my $message = "Outbound Connection Tests
\n"; # You cannot use styles because it affect the whole xymon page. $message .= "\n\n"; $message .= "\n\n"; foreach $server (@servers) { ($server_status) = connect_test($server); if ($server_status eq 'red') { $colour = setcolour($colour,'red'); $message .= "\n"; }else{ $message .= "\n"; } } $message .= "
DestinationStatus
$serverConnection down!
$serverConnection up
\n"; if ($debug eq "no") { exec "$ENV{XYMON}", "$ENV{XYMSRV}", "status $ENV{MACHINE}.$XYTEST $colour $date\n$message\n\n"; } else { print "Colour : $colour\n"; print "Date : $date\n"; print "status $ENV{MACHINE}.$XYTEST $colour $date\n$message\n\n"; }
===== Known Bugs and Issues ===== ===== To Do ===== ===== Credits ===== ===== Changelog ===== * **2017-10-10** * Initial release