1 #!/usr/bin/python 2 # Usage: check_nick server nick hostname 3 # Example: check_nick irc.freenode.net ubotu irc/bot/ubotu 4 # 5 # Placed in the public domain 6 7 import irclib, os, sys 8 9 server, nick, host = sys.argv[1:] 10 11 def whois(c, e): 12 c.whois([nick]) 13 14 def on_whois(c, e): 15 args = e.arguments()
1 #!/usr/bin/python
2 # Usage: check_nick server nick hostname
3 # Example: check_nick irc.freenode.net ubotu irc/bot/ubotu
4 #
5 # Placed in the public domain
6
7 import irclib, os, sys
8
9 server, nick, host = sys.argv[1:]
10
11 def whois(c, e):
12 c.whois([nick])
13
14 def on_whois(c, e):
15 args = e.arguments()
16 if args[0] == nick and args[2] == host:
17 print "%s was found on %s" % (nick, host)
18 sys.exit(0)
19 else:
20 print "%s was taken over: %s" % (nick,str(args))
21 sys.exit(1)
22
23 def on_nosuchnick(c, e):
24 print "%s is missing" % nick
25 sys.exit(2)
26
27 def abort():
28 print "Can't connect to %s" % server
29 sys.exit(3)
30
31 c = irclib.SimpleIRCClient()
32 c.connect(server, 6667, 'nagios_%s' % os.getpid())
33 c.ircobj.add_global_handler("endofmotd", whois, 0)
34 c.ircobj.add_global_handler("whoisuser", on_whois, 0)
35 c.ircobj.add_global_handler("nosuchnick", on_nosuchnick, 0)
36 c.ircobj.execute_delayed(30, abort)
37 c.start()
Show all