]> git.etc.gen.nz Git - spong.git/commitdiff
plugin to monitor the GNU Gatekeeper (http://www.gnugk.org/)
authorJan Willamowius <jan@willamowius.de>
Tue, 13 Sep 2005 13:14:34 +0000 (13:14 +0000)
committerJan Willamowius <jan@willamowius.de>
Tue, 13 Sep 2005 13:14:34 +0000 (13:14 +0000)
src/lib/Spong/Network/plugins/check_gnugk [new file with mode: 0755]

diff --git a/src/lib/Spong/Network/plugins/check_gnugk b/src/lib/Spong/Network/plugins/check_gnugk
new file mode 100755 (executable)
index 0000000..7e6af77
--- /dev/null
@@ -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
+