[sysadmin-bin] Added xmppsend, this script will send out nagios notifications through GTalk.



commit 296f35d38e1dd047cb4983a86f4b4aa392288d73
Author: Andrea Veri <av src gnome org>
Date:   Sat Feb 18 17:54:03 2012 +0100

    Added xmppsend, this script will send out nagios notifications through GTalk.

 xmppsend |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 72 insertions(+), 0 deletions(-)
---
diff --git a/xmppsend b/xmppsend
new file mode 100755
index 0000000..06e9285
--- /dev/null
+++ b/xmppsend
@@ -0,0 +1,72 @@
+#!/usr/bin/python -tt
+# skvidal fedoraproject org, modified by Andrea Veri <av gnome org>
+# gplv2+
+
+#nagios definition
+## 'host-notify-by-jabber' command definition
+#define command{
+#        command_name    host-notify-by-jabber
+#        command_line    /usr/local/bin/xmppsend -a config.ini "Host '$HOSTALIAS$' is $HOSTSTATE$ - Info : $HOSTOUTPUT$" $CONTACTPAGER$
+#        }
+#
+## 'notify-by-jabber' command definition
+#define command{
+#        command_name    notify-by-jabber
+#        command_line    /usr/local/bin/xmppsend -a config.ini "$NOTIFICATIONTYPE$ $HOSTNAME$ $SERVICEDESC$ $SERVICESTATE$ $SERVICEOUTPUT$ $LONGDATETIME$" $CONTACTPAGER$
+#        }
+#
+
+import warnings
+warnings.simplefilter("ignore")
+
+import xmpp
+from xmpp.protocol import Message
+
+from optparse import OptionParser
+import ConfigParser
+import sys
+import os
+
+parser = OptionParser()
+parser.add_option("-a", dest="authfile", default=None, help="file to retrieve username/password information from")
+opts, args = parser.parse_args()
+
+conf = ConfigParser.ConfigParser()
+if not opts.authfile or not os.path.exists(opts.authfile):
+   print "no config/auth file specified, can't continue"
+   sys.exit(1)
+
+conf.read(opts.authfile)
+if not conf.has_section('xmpp_nagios') or not conf.has_option('xmpp_nagios', 'username') or not conf.has_option('xmpp_nagios', 'password'):
+    print "cannot find at least one of: config section 'xmpp_nagios' or username or password"
+    sys.exit(1)
+
+username = conf.get('xmpp_nagios', 'username')
+password = conf.get('xmpp_nagios', 'password')
+
+if len(args) < 1:
+    print "xmppsend message [to whom, multiple args]"
+    sys.exit(1)
+
+msg = args[0]
+
+msg = msg.replace('\\n', '\n')
+
+# Connect to the server
+c  =  xmpp.Client('gmail.com')
+c.connect( ( 'talk.google.com', 5223 ) )
+
+# Authenticate to the server
+jid  =  xmpp.protocol.JID( username )
+c.auth( jid.getNode( ), password )
+
+if len(args) < 2:
+    r = c.getRoster()
+    for user in r.keys():
+        if user == username:
+            continue
+        c.send(Message(user, '%s' % msg))
+else:
+    for user in args[1:]:
+        c.send(Message(user, '%s' % msg))
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]