From 169496092fd6552bbfe3d10dfd81afc33538b238 Mon Sep 17 00:00:00 2001 From: twl9 <121435187+twl9@users.noreply.github.com> Date: Sat, 16 Sep 2023 22:01:52 +0200 Subject: [PATCH] Create postfix.py --- nixstatsagent/plugins/postfix.py | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 nixstatsagent/plugins/postfix.py diff --git a/nixstatsagent/plugins/postfix.py b/nixstatsagent/plugins/postfix.py new file mode 100644 index 0000000..795793b --- /dev/null +++ b/nixstatsagent/plugins/postfix.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import os +import plugins + +class Plugin(plugins.BasePlugin): + __name__ = 'postfix' + + def run(self, config): + ''' + postfix mail queue monitoring. Needs sudo access. + Add the following section to /etc/nixstats.ini + + [postfix] + enabled=yes + + Inspiration: + - https://github.com/NIXStats/nixstatsagent/blob/master/nixstatsagent/plugins/exim.py + - https://serverfault.com/questions/697670/how-to-monitor-the-postfix-mail-queue-using-monit/1097886#1097886 + + ''' + + metrics = ( + 'maildrop', + 'hold', + 'incoming', + 'active', + 'deferred' + ) + + data = {} + + for metric in metrics: + data[metric] = int(os.popen('sudo find /var/spool/postfix/' + metric + ' -type f | wc -l').read()) + + return data + +if __name__ == '__main__': + Plugin().execute()