diff --git a/bundles/postfix/files/postfix-telegraf-queue b/bundles/postfix/files/postfix-telegraf-queue new file mode 100644 index 0000000..7fc24a8 --- /dev/null +++ b/bundles/postfix/files/postfix-telegraf-queue @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + + +from json import loads +from subprocess import check_output + + +queue_counts = {} + +queue_json = check_output(['sudo', '/usr/sbin/postqueue', '-j']) +for line in queue_json.splitlines(): + j = loads(line.decode('UTF-8')) + queue_counts.setdefault(j['queue_name'], 0) + queue_counts[j['queue_name']] += 1 + +for queue in ('incoming', 'active', 'deferred', 'corrupt', 'hold'): + print('postfix_queue,status={} count={}i'.format(queue, queue_counts.get(queue, 0))) diff --git a/bundles/postfix/items.py b/bundles/postfix/items.py index 3a7ff0b..0b328e1 100644 --- a/bundles/postfix/items.py +++ b/bundles/postfix/items.py @@ -54,6 +54,9 @@ files = { 'svc_systemd:postfix:restart', }, }, + '/usr/local/bin/postfix-telegraf-queue': { + 'mode': '0755', + }, '/usr/local/share/icinga/plugins/check_postfix_queue': { 'mode': '0755', }, diff --git a/bundles/postfix/metadata.py b/bundles/postfix/metadata.py index f53e46e..9d72683 100644 --- a/bundles/postfix/metadata.py +++ b/bundles/postfix/metadata.py @@ -53,10 +53,18 @@ else: if node.has_bundle('telegraf'): defaults['telegraf'] = { 'input_plugins': { - 'builtin': { - 'postfix': [{}], + 'exec': { + 'postfix': { + 'commands': ['postfix-telegraf-queue'], + 'interval': '15s', + 'data_format': 'influx', + 'timeout': '5s', + }, }, }, + 'sudo_commands': { + '/usr/sbin/postqueue -j', + }, }