Module: check_mk
Branch: master
Commit: 6bd851e88861bce26b503813baf08248927c6f23
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6bd851e88861bc…
Author: Bastian Kuhn <bk(a)mathias-kettner.de>
Date: Tue Sep 18 17:02:25 2012 +0200
Added SNMP and MAIL script for mkeventd
---
doc/treasures/mail_mkevent.py | 39 +++++++++++++++++++++++++++++++++++++++
doc/treasures/snmptd_mkevent.py | 23 +++++++++++++++++++++++
2 files changed, 62 insertions(+), 0 deletions(-)
diff --git a/doc/treasures/mail_mkevent.py b/doc/treasures/mail_mkevent.py
new file mode 100755
index 0000000..58269d2
--- /dev/null
+++ b/doc/treasures/mail_mkevent.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+#
+#This script sends all mails from given mailbox
+#to the mkeventd pipe of given OMD Installation
+#
+# Bastian Kuhn, bk(a)mathias-kettner.de
+import poplib
+import time
+
+pop3_server = "localhost"
+mail_user = "USER"
+mail_pass = "mail"
+site_name = "SITE"
+deamon_path = "/omd/sites/%s/tmp/run/mkeventd/events" % site_name
+
+
+M = poplib.POP3(pop3_server)
+M.user(mail_user)
+M.pass_(mail_pass)
+numMessages = len(M.list()[1])
+for i in range(numMessages):
+ host = "not_found"
+ msg = ""
+ found_host = False
+ for line in M.retr(i+1)[1]:
+ if found_host == False and line.split()[0] == "From:":
+ host = line.split()[1].split('@')[1]
+ host = host.replace('>','')
+ found_host = True
+ msg += line
+ out = open(deamon_path, "w")
+ timestamp = time.strftime("%b %d %H:%M:%S", time.localtime(time.time()))
+ out.write("<5>%s %s mail: %s" % (timestamp, host, msg))
+ out.close()
+ M.dele(i+1)
+M.quit()
+
+
diff --git a/doc/treasures/snmptd_mkevent.py b/doc/treasures/snmptd_mkevent.py
new file mode 100755
index 0000000..69c0c4d
--- /dev/null
+++ b/doc/treasures/snmptd_mkevent.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+#
+#This script is called by snmptrapd and sends
+#all traps to the mkeventd
+#
+# Bastian Kuhn, bk(a)mathias-kettner.de
+import time
+import sys
+
+site_name = "SITE"
+deamon_path = "/omd/sites/%s/tmp/run/mkeventd/events" % site_name
+
+data = []
+for line in sys.stdin:
+ data.append(line.strip())
+msg = " ".join(data[2:])
+host, ip = data[:2]
+out = open(deamon_path, "w")
+timestamp = time.strftime("%b %d %H:%M:%S", time.localtime(time.time()))
+out.write("<5>%s %s trap: %s" % (timestamp, host, msg))
+out.close()
+~