postfix.chart.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf-8 -*-
  2. # Description: postfix netdata python.d module
  3. # Author: Pawel Krupa (paulfantom)
  4. # SPDX-License-Identifier: GPL-3.0-or-later
  5. from bases.FrameworkServices.ExecutableService import ExecutableService
  6. POSTQUEUE_COMMAND = 'postqueue -p'
  7. ORDER = [
  8. 'qemails',
  9. 'qsize',
  10. ]
  11. CHARTS = {
  12. 'qemails': {
  13. 'options': [None, 'Postfix Queue Emails', 'emails', 'queue', 'postfix.qemails', 'line'],
  14. 'lines': [
  15. ['emails', None, 'absolute']
  16. ]
  17. },
  18. 'qsize': {
  19. 'options': [None, 'Postfix Queue Emails Size', 'KiB', 'queue', 'postfix.qsize', 'area'],
  20. 'lines': [
  21. ['size', None, 'absolute']
  22. ]
  23. }
  24. }
  25. class Service(ExecutableService):
  26. def __init__(self, configuration=None, name=None):
  27. ExecutableService.__init__(self, configuration=configuration, name=name)
  28. self.order = ORDER
  29. self.definitions = CHARTS
  30. self.command = POSTQUEUE_COMMAND
  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. if raw[0] == 'Mail' and raw[1] == 'queue':
  39. return {'emails': 0,
  40. 'size': 0}
  41. return {'emails': raw[4],
  42. 'size': raw[1]}
  43. except (ValueError, AttributeError):
  44. return None