diff --git a/Makefile b/Makefile index a64871608b60d53bd81d13ad5dac0bc2d6e32c50..fb9946512b1608870324cad00f78a1f8a0fce7dc 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ LIBEXECDIR = /usr/local/nagios/libexec/ SCRIPTS = check_cups check_glsa check_saned check_lpd check_hddtemp \ check_link_status check_true check_lysrdiff check_syslog \ - check_ping check_enodia_monitored check_hostextinfo + check_ping check_enodia_monitored check_hostextinfo \ + check_hydra all:; diff --git a/check_hydra b/check_hydra new file mode 100755 index 0000000000000000000000000000000000000000..ff232a6b51b10581f7c3923d6ee06cf4d09c229a --- /dev/null +++ b/check_hydra @@ -0,0 +1,68 @@ +#!/usr/bin/env python + +import sys +import socket + +import pcl_expect +import pcl_expect.telnet + +def debug(s): + print s + +#pcl_expect.debug = debug + +def critical(msg): + print "CRITICAL - %s" % msg + sys.exit(2) + +def warning(msg): + print "WARNING - %s" % msg + sys.exit(1) + +def ok(msg): + print "OK - %s" % msg + sys.exit(0) + +def check_hydra(hydra, hostname): + try: + t = pcl_expect.telnet.Telnet(hydra, 'telnet') + except socket.gaierror, err: + critical("looking up %s: %s" % (hydra, err[1])) + except socket.error, err: + critical("connecting to %s: %s" % (hydra, err[1])) + + t.send(hostname + '\n') + + x = pcl_expect.Controller() + while x.loop(): + if x.re(t, "%s\r?\n" % hostname): + break + elif x.timeout(): + critical("no echo of hostname while talking to %s" % hydra) + + x = pcl_expect.Controller() + while x.loop(): + if x.re(t, "Attached to port [0-9]*\r?\n"): + break + elif x.re(t, "busy, do you wish to wait.*: "): + # FIXME: Only warn after an hour. + warning("port busy") + elif x.re(t, "Rotaries Defined:"): + critical("unexpected output from hydra: %s" % repr(t.consumed)) + elif x.eof(t): + critical("unexpected EOF from telnet") + elif x.timeout(): + critical("unexpected timeout while talking to the hydra") + + t.send("\025") # Ctrl-U. + t.send("\n") + + x = pcl_expect.Controller() + while x.loop(): + if x.re(t, "%s .*login: " % hostname): + ok(repr(t.consumed.strip())) + elif x.timeout(): + critical("timeout while waiting for login prompt") + +if __name__ == '__main__': + check_hydra(sys.argv[1], sys.argv[2])