]> arthur.barton.de Git - netdata.git/blob - python.d/postfix.chart.py
ab-debian 0.20170327.01-0ab1, upstream v1.6.0-42-gaa6b96fc
[netdata.git] / python.d / postfix.chart.py
1 # -*- coding: utf-8 -*-
2 # Description: postfix 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 = 60
11
12 # charts order (can be overridden if you want less charts, or different order)
13 ORDER = ['qemails', 'qsize']
14
15 CHARTS = {
16     'qemails': {
17         'options': [None, "Postfix Queue Emails", "emails", 'queue', 'postfix.qemails', 'line'],
18         'lines': [
19             ['emails', None, 'absolute']
20         ]},
21     'qsize': {
22         'options': [None, "Postfix Queue Emails Size", "emails size in KB", 'queue', 'postfix.qsize', 'area'],
23         'lines': [
24             ["size", None, 'absolute']
25         ]}
26 }
27
28
29 class Service(ExecutableService):
30     def __init__(self, configuration=None, name=None):
31         ExecutableService.__init__(self, configuration=configuration, name=name)
32         self.command = "postqueue -p"
33         self.order = ORDER
34         self.definitions = CHARTS
35
36     def _get_data(self):
37         """
38         Format data received from shell command
39         :return: dict
40         """
41         try:
42             raw = self._get_raw_data()[-1].split(' ')
43             if raw[0] == 'Mail' and raw[1] == 'queue':
44                 return {'emails': 0,
45                         'size': 0}
46
47             return {'emails': raw[4],
48                     'size': raw[1]}
49         except (ValueError, AttributeError):
50             return None