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: