diff options
author | root <root@monitoring.shack> | 2012-09-13 23:39:58 +0000 |
---|---|---|
committer | root <root@monitoring.shack> | 2012-09-13 23:39:58 +0000 |
commit | db849a18e1659ff28433384d2cdca2989a6d5df0 (patch) | |
tree | d600fb3f3e5f0a54b6254c85ee8a3b836ef3d90d /Monitoring | |
parent | d5d39fc3d56b021b642ee6e1d5625524ebbc4d99 (diff) | |
parent | 88d4bdc29eb9ce5f62099f2be1488ae927aa09d5 (diff) |
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'Monitoring')
-rwxr-xr-x | Monitoring/plugins/notify_irc | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/Monitoring/plugins/notify_irc b/Monitoring/plugins/notify_irc new file mode 100755 index 00000000..e1de0866 --- /dev/null +++ b/Monitoring/plugins/notify_irc @@ -0,0 +1,87 @@ +#! /usr/bin/env python +# +# Example program using irclib.py. +# +# This program is free without restrictions; do anything you like with +# it. +# +# Joel Rosdahl <joel@rosdahl.net> + +import irclib +import sys +#irclib.DEBUG= True +class IRCCat(irclib.SimpleIRCClient): + def __init__(self, target,msg=""): + irclib.SimpleIRCClient.__init__(self) + self.target = target + self.msg = msg + + def on_welcome(self, connection, event): + if irclib.is_channel(self.target): + connection.join(self.target) + else: + self.send_it() + + def on_join(self, connection, event): + self.send_it() + + def on_disconnect(self, connection, event): + sys.exit(0) + + def send_it(self): + if self.msg: + print "writing given argv privmsg",self.msg + self.connection.privmsg(self.target, self.msg) + else: + print "writing stdin privmsg:" + while 1: + line = sys.stdin.readline() + if not line: + break + print line + self.connection.privmsg(self.target, line) + self.connection.quit("Using irclib.py") +def findGreatNick(prefix='shinken'): + import random + import re + dic="/usr/share/dict/danish" + found=False + while not found: + w = random.choice(list(open(dic))) + found = re.match(r"^[a-zA-Z_-]+$",w) + return prefix +"|"+w.strip() + +def main(): + if len(sys.argv) < 3: + print "Usage: notify_irc <server[:port]> <target> [message]" + print "\ntarget is a nickname or a channel." + sys.exit(1) + + s = sys.argv[1].split(":", 1) + server = s[0] + if len(s) == 2: + try: + port = int(s[1]) + except ValueError: + print "Error: Erroneous port." + sys.exit(1) + else: + port = 6667 + import random + nickname = findGreatNick() + print nickname + target = sys.argv[2] + msg = "" + if len(sys.argv) == 4: + msg = sys.argv[3] + c = IRCCat(target,msg) + try: + print "trying to connect to ",server,port,nickname + c.connect(server, port, nickname ) + except irclib.ServerConnectionError, x: + print x + sys.exit(1) + c.start() + +if __name__ == "__main__": + main() |