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 1/2] 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() From ab9bb2500a3cb2a6f8a88afddce23929634124b5 Mon Sep 17 00:00:00 2001 From: twl9 <121435187+twl9@users.noreply.github.com> Date: Sat, 16 Sep 2023 22:41:17 +0200 Subject: [PATCH 2/2] Update postfix.py --- nixstatsagent/plugins/postfix.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nixstatsagent/plugins/postfix.py b/nixstatsagent/plugins/postfix.py index 795793b..a74ff7b 100644 --- a/nixstatsagent/plugins/postfix.py +++ b/nixstatsagent/plugins/postfix.py @@ -17,6 +17,7 @@ def run(self, config): 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 + - https://serverfault.com/questions/58196/how-do-i-check-the-postfix-queue-size/577766#577766 ''' @@ -25,7 +26,9 @@ def run(self, config): 'hold', 'incoming', 'active', - 'deferred' + 'deferred', + 'bounce', + 'corrupt' ) data = {}