From 762a0d04e93d2c05b8aa5ba9b2729f43326fc453 Mon Sep 17 00:00:00 2001 From: badcrc Date: Fri, 11 Oct 2019 10:29:13 +0200 Subject: [PATCH] adding config file support --- README.md | 2 ++ graphping | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 99e4ecc..d2bfe79 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,8 @@ Usage `./graphping [ ...]` +If a config file is defined (one IP address per line) it reads it in every execution loop so you can daemonize it and just update the config file. + License ------- diff --git a/graphping b/graphping index 0776056..aab0e5c 100755 --- a/graphping +++ b/graphping @@ -84,6 +84,7 @@ class App: self.g_port = g_port self.g_prefix = g_prefix self.logfile = logfile + self.config_file = '/etc/graphping.conf' self.daemonize = True self.stop = False self.level = logging.INFO @@ -124,9 +125,10 @@ class App: return srtd[mid] def process_options(self): - self.targets = sys.argv[1:] - if not self.targets: - self.usage() + if self.config_file == None: + self.targets = sys.argv[1:] + if not self.targets: + self.usage() def usage(self): print "Usage: ping-graphite [ ...]" @@ -139,6 +141,11 @@ class App: while not self.stop: + # If the config file is defined we read the new targets from it + if self.config_file != None: + with open(self.config_file) as f: + self.targets = f.read().replace('\n', ' ').split(' ') + rtt = {} sry = {} for t in self.targets: