Module: check_mk
Branch: master
Commit: 27a6d76b3fed76399eaf8a0d402ff6161bf27ace
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=27a6d76b3fed76…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Thu Jan 31 14:33:35 2013 +0100
opcmsg notification plugin
---
notifications/opcmsg | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 68 insertions(+), 0 deletions(-)
diff --git a/notifications/opcmsg b/notifications/opcmsg
new file mode 100755
index 0000000..8d953cf
--- /dev/null
+++ b/notifications/opcmsg
@@ -0,0 +1,68 @@
+#!/usr/bin/python
+# Create message for HPOpenView
+# This plugin forwards the notification to the
+# local HPOpenView instance
+
+import os, sys, re
+
+def substitute_context(template, context):
+ # First replace all known variables
+ for varname, value in context.items():
+ template = template.replace('$'+varname+'$', value)
+
+ # Remove the rest of the variables and make them empty
+ template = re.sub("\$[A-Z]+\$", "", template)
+ return template
+
+def main():
+ try:
+ opcmsg_bin = "/opt/OV/bin/opcmsg"
+
+ # gather all options from env
+ context = dict([
+ (var[7:], value.decode("utf-8"))
+ for (var, value)
+ in os.environ.items()
+ if var.startswith("NOTIFY_")])
+
+
+ # Severity and message text
+ if context["WHAT"] == "HOST":
+ msg_t = context["HOSTOUTPUT"]
+ severity = context["HOSTSTATEID"] == "0" and
"ok" or "critical"
+ else:
+ msg_t = context["SERVICEOUTPUT"]
+ state_map = { "0": "normal", "1":
"warning", "2": "critical", "3":
"warning" }
+ try:
+ severity = state_map[context["SERVICESTATEID"]]
+ except:
+ severity = "normal"
+
+ # application
+ application = "RWWS4.0"
+
+ # object
+ # Wichtig: " escapen
+ the_object = context["HOSTNAME"]
+ if context["WHAT"] == "SERVICE":
+ the_object += ":" + context["SERVICEDESC"]
+
+ # msg_grp
+ msg_grp = os.getenv("NOTIFY_PARAMETER_1")
+
+ # node
+ node = context['MONITORING_HOST']
+
+ # Assemble the command
+ command = "%s severity=%s application=%s object=\"%s\"
msg_grp=\"%s\" msg_t=\"%s\" node=%s" % (
+ opcmsg_bin, severity, application, the_object, msg_grp, msg_t, node)
+
+ # Execute the command
+ print "executing command" , command
+ file("/tmp/opc","w").write(command)
+ # return os.system(command)
+ except Exception, e:
+ sys.stdout.write("ERROR %r" % e)
+ sys.exit(1)
+
+main()