Module: check_mk
Branch: master
Commit: 50c6335a6fd6ed06896c41c8987a3b247d4fa4f4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=50c6335a6fd6ed…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jun 27 16:15:53 2013 +0200
Added livedump mail transport mechanism ; cleaned up a bit
---
doc/treasures/{README.livedump => livedump/README} | 0
doc/treasures/{ => livedump}/livedump | 0
doc/treasures/livedump/livedump-mail-fetch | 90 ++++++++++++++++++++
doc/treasures/{ => livedump}/livestatus-to-nsca.sh | 0
4 files changed, 90 insertions(+)
diff --git a/doc/treasures/README.livedump b/doc/treasures/livedump/README
similarity index 100%
rename from doc/treasures/README.livedump
rename to doc/treasures/livedump/README
diff --git a/doc/treasures/livedump b/doc/treasures/livedump/livedump
similarity index 100%
rename from doc/treasures/livedump
rename to doc/treasures/livedump/livedump
diff --git a/doc/treasures/livedump/livedump-mail-fetch
b/doc/treasures/livedump/livedump-mail-fetch
new file mode 100755
index 0000000..7078161
--- /dev/null
+++ b/doc/treasures/livedump/livedump-mail-fetch
@@ -0,0 +1,90 @@
+#!/usr/bin/python
+# Fetches mails from inbox of a pop mailbox to gather configuration
+# and state information generated by the livedump command. We use
+# the mail subject to identify the mails. Mails with a subject
+# "state" do contain the nagios checkresults in the mail body and
+# mails with subjects starting with the string "config" do contain
+# nagios configuration definitions. All chars after the config string
+# in the subject are used to identfy the sending system. This is
+# an ident of the system to support multiple sending systems.
+#
+# Configuration is written to etc/nagios/conf.d/remote-<ident>.cfg.
+# The status info is sent in nagios state result file format and
+# written to tmp/nagios/checkresults directory in a temporary file
+# which is then processed by nagios.
+
+import os
+import sys
+import poplib
+import re
+import quopri
+import tempfile
+
+omd_root = os.environ.get('OMD_ROOT')
+pop_server = "pop.1und1.de"
+pop_user = "monitor(a)grillwerkstatt.at"
+pop_pass = "LTWmonitor2013"
+
+M = poplib.POP3_SSL(pop_server)
+M.user(pop_user)
+M.pass_(pop_pass)
+
+config_ids = []
+status_ids = []
+numMessages = len(M.list()[1])
+
+status_mails = []
+config_mails = []
+
+pattern = re.compile(r"^Subject: (.*)")
+for i in range(numMessages):
+ for header_lines in M.top(i + 1, 0)[1]:
+ matches = pattern.match(header_lines)
+ if matches:
+ subject = matches.group(1).strip()
+ if subject == "status":
+ status_mails.append(i + 1)
+ elif subject.startswith("config"):
+ ident = subject[6:].strip().replace("/",
"_").replace(".", "_")
+ if not ident:
+ ident = "no-ident"
+ config_mails.append((i + 1, ident))
+
+# handle config mails. Only last available is interesting.
+# Extract mail body and use this as retrieved config.
+if config_mails:
+ mail_index, ident = config_mails[-1]
+ code, mail, num = M.retr(mail_index)
+ body_start_index = mail.index('')
+ body = quopri.decodestring('\n'.join(mail[body_start_index:]))
+
+ file("%s/etc/nagios/conf.d/remote-%s.cfg" %
+ (omd_root, ident), "w").write(body)
+
+if status_mails:
+ for index in status_mails:
+ code, mail, code = M.retr(index)
+ body_start_index = mail.index('')
+ body = quopri.decodestring('\n'.join(mail[body_start_index:]))
+
+ fd, path = tempfile.mkstemp('', 'c',
"%s/tmp/nagios/checkresults" % omd_root)
+ os.write(fd, body)
+ os.close(fd)
+ file(path + ".ok", "w")
+
+# alle mails loeschen
+try:
+ popstate, msglist, code = M.list()
+ for entry in msglist:
+ msgid, size = entry.split()
+ response = M.dele(msgid)
+ if response != "+OK":
+ raise Exception("Error from POP server: [%s]" % response)
+ break
+
+except Exception, e:
+ sys.stderr.write(msg + "Error deleting message: %s" % e)
+ sys.exit(1)
+
+# Close mailbox, commit changes
+M.quit()
diff --git a/doc/treasures/livestatus-to-nsca.sh
b/doc/treasures/livedump/livestatus-to-nsca.sh
similarity index 100%
rename from doc/treasures/livestatus-to-nsca.sh
rename to doc/treasures/livedump/livestatus-to-nsca.sh