Module: check_mk
Branch: master
Commit: 05238d7848b2eed5830746a83c337a99e8a7089f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=05238d7848b2ee…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Nov 14 12:07:35 2013 +0100
Added notification script for sending SMS via
mobilant.com
in doc/treasures there is now a notify_mobilant.py. This can send
SMS via Internet/HTTP using the commercial SMS sending service
mobilant.com. You need to edit the script and enter your mobilant
key. Please refer to instructions directly in the script.
---
.werks/5 | 11 ++++++
ChangeLog | 1 +
doc/treasures/notify_mobilant.py | 72 ++++++++++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+)
diff --git a/.werks/5 b/.werks/5
new file mode 100644
index 0000000..c15d0a0
--- /dev/null
+++ b/.werks/5
@@ -0,0 +1,11 @@
+Title: Added notification script for sending SMS via
mobilant.com
+Level: 1
+Component: notifications
+Version: 1.2.3i7
+Date: 1384427169
+Class: feature
+
+in doc/treasures there is now a notify_mobilant.py. This can send
+SMS via Internet/HTTP using the commercial SMS sending service
+mobilant.com. You need to edit the script and enter your mobilant
+key. Please refer to instructions directly in the script.
diff --git a/ChangeLog b/ChangeLog
index afc0415..70621f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -42,6 +42,7 @@
* 0094 FIX: Hide SNMPv3 credentials in WATO...
Notifications:
+ * 0005 Added notification script for sending SMS via
mobilant.com...
* 0032 FIX: mail notification plugin: replace windows forbidden characters in mail
images
Reporting & Availability:
diff --git a/doc/treasures/notify_mobilant.py b/doc/treasures/notify_mobilant.py
new file mode 100755
index 0000000..8ef09a9
--- /dev/null
+++ b/doc/treasures/notify_mobilant.py
@@ -0,0 +1,72 @@
+#!/usr/bin/python
+# Send SMS via Mobilant # encoding: utf-8
+#
+# This notification script can be put below share/check_mk/notifications. It sends
+# SMS via
mobilant.com. Please add your personal configuration directly in this
+# script. The target phone number is take from the contact's pager address.
+# You can override this by specifying it as a parameter
+
+import sys, os, urllib
+
+key = "8F37ksjf8kJ8k37f729Btlllsw8" # Enter your mobilant web key here!
+
+# This does not need to be changed
+to = os.environ.get("NOTIFY_CONTACTPAGER")
+fromname = "Check_MK"
+
+
+if len(sys.argv) > 1:
+ to = sys.argv[1]
+
+if not to:
+ sys.stderr.write("NOTIFY_CONTACTPAGER is not set.\n")
+ sys.exit(1)
+
+
+max_len = 160
+message = os.environ['NOTIFY_HOSTNAME'] + " "
+
+if os.environ['NOTIFY_WHAT'] == 'SERVICE':
+ message += os.environ['NOTIFY_SERVICESTATE'][:2] + " "
+ avail_len = max_len - len(message)
+ message += os.environ['NOTIFY_SERVICEDESC'][:avail_len] + " "
+ avail_len = max_len - len(message)
+ message += os.environ['NOTIFY_SERVICEOUTPUT'][:avail_len]
+
+else:
+ message += "is " + os.environ['NOTIFY_HOSTSTATE']
+
+
+url = "http://gw.mobilant.com/?" + urllib.urlencode([
+ ( "key", key ),
+ ( "to", to ),
+ ( "message", message ),
+ ( "route", "gold" ),
+ ( "from", fromname )
+])
+
+exitcodes = {
+ "10" : u"Empfängernummer nicht korrekt, Parameter: to",
+ "20" : u"Absenderkennung nicht korrekt, Parameter: from",
+ "30" : u"Nachrichtentext nicht korrekt, Parameter: message",
+ "31" : u"Messagetyp nicht korrekt, Parameter: messagetype",
+ "40" : u"SMS Route nicht korrekt, Parameter: route",
+ "50" : u"Identifikation fehlgeschlagen, Parameter: key",
+ "60" : u"nicht genügend Guthaben",
+ "70" : u"Netz wird nicht abgedeckt, Parameter: route",
+ "71" : u"Feature nicht möglich, Parameter: route",
+ "80" : u"Übergabe an SMS-C, fehlgeschlagen",
+ "100" : u"SMS wurde angenommen und, versendet",
+}
+
+try:
+ handle = urllib.urlopen(url)
+ response = handle.read().strip()
+ if response == "100":
+ sys.stdout.write("Successfully sent SMS to %s\n" % to)
+ else:
+ sys.stderr.write("Error sending SMS to %s: %s\n" % (to,
exitcodes.get(response, "Invalid exit code %s" % response)))
+ sys.stderr.write("URL was %s\n" % url)
+except 1: # Exception, e:
+ sys.stderr.write("Error sending SMS to %s. Exception: %s%s\n" % e)
+