search for command + exim.chart.py
paulfantom committed
Jul 7, 2016 at 12:36 UTC
b41774a194082eb532c1d6f796c6ec014f4a5c5d
2 files changed
+49
python.d/exim.chart.py
new
+41
@@ -0,0 +1,41 @@
1
+# -*- coding: utf-8 -*-
2
+# Description: exim netdata python.d module
3
+# Author: Pawel Krupa (paulfantom)
4
+
5
+from base import ExecutableService
6
+
7
+# default module values (can be overridden per job in `config`)
8
+# update_every = 2
9
+priority = 60000
10
+retries = 5
11
+
12
+# charts order (can be overridden if you want less charts, or different order)
13
+ORDER = ['qemails']
14
+
15
+CHARTS = {
16
+ 'qemails': {
17
+ 'options': [None, "Exim Queue Emails", "emails", 'queue', 'exim.queued.emails', 'line'],
18
+ 'lines': [
19
+ ['emails', None, 'absolute']
20
+ ]}
21
+}
22
+
23
+
24
+class Service(ExecutableService):
25
+ def __init__(self, configuration=None, name=None):
26
+ ExecutableService.__init__(self, configuration=configuration, name=name)
27
+ self.command = "exim -bpc"
28
+ self.order = ORDER
29
+ self.definitions = CHARTS
30
+
31
+ def _get_data(self):
32
+ """
33
+ Format data received from shell command
34
+ :return: dict
35
+ """
36
+ try:
37
+ raw = self._get_raw_data()[-1].split(' ')
38
+ return {'emails': raw[4],
39
+ 'size': raw[1]}
40
+ except (ValueError, AttributeError):
41
+ return None
python.d/python_modules/base.py
+8
@@ -606,6 +606,14 @@ class ExecutableService(SimpleService):
606
else:
607
self.error("Wrong command. Probably not on whitelist.")
608
return False
609
+ # test command and search for it in /usr/sbin or /sbin when failed
610
+ base = self.command[0]
611
+ if self._get_raw_data() is None:
612
+ for prefix in ['/sbin/', '/usr/sbin/']:
613
+ self.command[0] = prefix + base
614
+ if self._get_raw_data() is not None:
615
+ break
616
+
617
if self._get_data() is None or len(self._get_data()) == 0:
618
return False
619
return True