From: Jan Willamowius Date: Tue, 13 Sep 2005 13:14:34 +0000 (+0000) Subject: plugin to monitor the GNU Gatekeeper (http://www.gnugk.org/) X-Git-Tag: spong-2_8_0-beta1~25 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da862269908a2320701bfb47d8baf85a8172f715;p=spong.git plugin to monitor the GNU Gatekeeper (http://www.gnugk.org/) --- diff --git a/src/lib/Spong/Network/plugins/check_gnugk b/src/lib/Spong/Network/plugins/check_gnugk new file mode 100755 index 0000000..7e6af77 --- /dev/null +++ b/src/lib/Spong/Network/plugins/check_gnugk @@ -0,0 +1,52 @@ +# plugin to monitor the GNU Gatekeeper (http://www.gnugk.org/) +# $Id: check_gnugk,v 1.1 2005/09/13 13:14:34 willamowius Exp $ +# Author: Jan Willamowius, jan@willamowius.de, http://www.willamowius.de + +# Register the routine with the plugins registry +$PLUGINS{'gnugk'} = \&check_gnugk; + +eval "require Net::Telnet;"; + +sub check_gnugk { + my ($host) = @_; + # Find the list of ports to check + my @ports = $HOSTS{$host}->{'gnugk_ports'} || + $HOSTS_DEFAULTS{'gnugk_ports'} || + (7000); + # Append mandatory ports from the 'ALL' host + @ports = ( @ports, @{$HOSTS_ALL{'gnugk_ports'}} ); + my ($color, $summary, $message) = ("green", "", ""); + + foreach $port (@ports) { + my $con = new Net::Telnet; + $con->errmode('return'); + my $ok = $con->open(Host=> $host, Port => $port); + if (! $ok) { + $color = "red"; + $message .= "$host:$port -\n" . $con->errmsg() . "\n"; + next; + } + + $con->waitfor("/;/"); + my @data = $con->cmd(String => "Statistics", Prompt => "/;/", Timeout => 3); + if (@data) { + $message .= "$host:$port -\n@data\n"; + } else { + $color = "yellow" unless $color eq "red"; + $message .= "$host:$port -\n Timed out reading data\n"; + } + $con->close(); + } + + if ($color eq "green") { + $summary = "GnuGk OK"; + } else { + $summary = "GnuGk Not OK"; + } + + &debug("gnugk - $host - $color, $summary"); + return( $color, $summary, $message); +} + +1; # Leave me here +