postfix.chart.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # -*- coding: utf-8 -*-
  2. # Description: postfix netdata python.d module
  3. # Author: Pawel Krupa (paulfantom)
  4. from bases.FrameworkServices.ExecutableService import ExecutableService
  5. # default module values (can be overridden per job in `config`)
  6. # update_every = 2
  7. priority = 60000
  8. retries = 60
  9. # charts order (can be overridden if you want less charts, or different order)
  10. ORDER = ['qemails', 'qsize']
  11. CHARTS = {
  12. 'qemails': {
  13. 'options': [None, "Postfix Queue Emails", "emails", 'queue', 'postfix.qemails', 'line'],
  14. 'lines': [
  15. ['emails', None, 'absolute']
  16. ]},
  17. 'qsize': {
  18. 'options': [None, "Postfix Queue Emails Size", "emails size in KB", 'queue', 'postfix.qsize', 'area'],
  19. 'lines': [
  20. ["size", None, 'absolute']
  21. ]}
  22. }
  23. class Service(ExecutableService):
  24. def __init__(self, configuration=None, name=None):
  25. ExecutableService.__init__(self, configuration=configuration, name=name)
  26. self.command = "postqueue -p"
  27. self.order = ORDER
  28. self.definitions = CHARTS
  29. def _get_data(self):
  30. """
  31. Format data received from shell command
  32. :return: dict
  33. """
  34. try:
  35. raw = self._get_raw_data()[-1].split(' ')
  36. if raw[0] == 'Mail' and raw[1] == 'queue':
  37. return {'emails': 0,
  38. 'size': 0}
  39. return {'emails': raw[4],
  40. 'size': raw[1]}
  41. except (ValueError, AttributeError):
  42. return None