From 12e2057505e20c5c80dc95479c66507ed7e8c855 Mon Sep 17 00:00:00 2001 From: Yoav Date: Sat, 8 Feb 2014 07:54:29 +0100 Subject: [PATCH] added update_hostname * gets the hostname from the the munin connection hello string * does not override displayname if provided --- m2g-poller.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/m2g-poller.py b/m2g-poller.py index e22938a..fe7ac8b 100755 --- a/m2g-poller.py +++ b/m2g-poller.py @@ -12,6 +12,7 @@ import time LOGGING_FORMAT = "%(asctime)s:%(levelname)s:%(message)s" RE_LEFTRIGHT = re.compile(r"^(?P\S+)\s+(?P\S+)$") +RE_MUNIN_NODE_NAME = re.compile(r"^# munin node at\s+(?P\S+)$") ## TODO: Catch keyboard interrupt properly and die when requested @@ -33,6 +34,7 @@ class Munin(): def go(self): """Bootstrap method to start processing hosts's Munin stats.""" self.connect() + self.update_hostname() self.process_host_stats() while True and self.args.interval != 0: @@ -40,6 +42,18 @@ class Munin(): self.connect() self.process_host_stats() + def update_hostname(self): + """Updating hostname from connection hello string.""" + if self.args.displayname: + return + try: + node_name = RE_MUNIN_NODE_NAME.search(self.hello_string).group(1) + self.displayname = node_name + except AttributeError: + logging.info("Unable to obtain munin node name from: %s", + self.hello_string) + return + def connect(self): """Initial connection to Munin host.""" try: