one job config
paulfantom committed
Jun 18, 2016 at 13:46 UTC
ad64156eb471a0e1d5dc17638c014b02ea487485
1 file changed
+30
-15
plugins.d/python.d.plugin
+30
-15
@@ -45,7 +45,6 @@ class PythonCharts(object):
45
46
# good economy and prosperity:
47
self.jobs = self._create_jobs(configured_modules)
48
- debug(self.jobs)
48
49
50
def _create_jobs(self,modules):
@@ -70,7 +69,9 @@ class PythonCharts(object):
69
return None
70
else:
71
# set execution_name (needed to plot run time graphs)
73
- job.execution_name = module.__name__ + "_" + name
72
+ job.execution_name = module.__name__
73
+ if name is not None:
74
+ job.execution_name += "_" + name
75
jobs.append(job)
76
77
return [j for j in jobs if j is not None]
@@ -145,13 +146,25 @@ class PythonCharts(object):
146
except (KeyError,ValueError):
147
# if above failed, get defaults from global dict
148
defaults[key] = BASE_CONFIG[key]
148
-
149
- # assign variables needed by supervisor to every job configuration
149
+
150
+ # check if there are dict in config dict
151
+ many_jobs = False
152
for name in config:
151
- for key in BASE_CONFIG:
152
- if key not in config[name]:
153
- config[name][key] = defaults[key]
153
+ if type(config[name]) is dict:
154
+ many_jobs = True
155
+ break
156
157
+ # assign variables needed by supervisor to every job configuration
158
+ if many_jobs:
159
+ for name in config:
160
+ for key in defaults:
161
+ if key not in config[name]:
162
+ config[name][key] = defaults[key]
163
+ # if only one job is needed, values doesn't have to be in dict (in YAML)
164
+ else:
165
+ config = {None: config.copy()}
166
+ config[None].update(defaults)
167
+
168
# return dictionary of jobs where every job has BASE_CONFIG variables
169
return config
170
@@ -190,6 +203,7 @@ class PythonCharts(object):
203
self._stop(job, "no check")
204
except (UnboundLocalError, Exception) as e:
205
self._stop(job, "misbehaving. Reason: " + str(e))
206
+ print("CHECK OK")
207
208
def create(self):
209
# try to execute create() on every job
@@ -213,6 +227,7 @@ class PythonCharts(object):
227
self._stop(job, "no create")
228
except (UnboundLocalError, Exception) as e:
229
self._stop(job, "misbehaving. Reason: " + str(e))
230
+ print("CREATE OK")
231
232
def _update_job(self, job):
233
# try to execute update() on every job and draw run time graph
@@ -341,7 +356,7 @@ def run():
356
try:
357
conf = read_config(configfile)
358
try:
344
- if str(conf['enable']) == "no":
359
+ if str(conf['enable']) is False:
360
debug("disabled in configuration file")
361
sys.stdout.write("DISABLE\n")
362
sys.exit(1)
@@ -349,24 +364,24 @@ def run():
364
pass
365
try:
366
modules_conf = conf['plugins_config_dir']
352
- except (KeyError):
367
+ except KeyError:
368
modules_conf = config_dir + "python.d/" # default configuration directory
369
try:
370
modules_dir = conf['plugins_dir']
356
- except (KeyError):
371
+ except KeyError:
372
modules_dir = main_dir.replace("plugins.d", "python.d")
373
try:
359
- interval = int(conf['interval'])
360
- except (KeyError, TypeError):
374
+ interval = conf['interval']
375
+ except KeyError:
376
pass # use default interval from NETDATA_UPDATE_EVERY
377
try:
363
- DEBUG_FLAG = bool(conf['debug'])
364
- except (KeyError, TypeError):
378
+ DEBUG_FLAG = conf['debug']
379
+ except KeyError:
380
pass
381
for k, v in conf.items():
382
if k in ("plugins_config_dir", "plugins_dir", "interval", "debug"):
383
continue
369
- if v == 'no':
384
+ if v is False:
385
disabled.append(k)
386
except FileNotFoundError:
387
modules_conf = config_dir