forked from Poil/Collectd-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailqueues.py
67 lines (44 loc) · 1.52 KB
/
mailqueues.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
#--------------------------------------
# Auteur : Frederick Lemasson
# Date : 16/11/2014
# Version : 0.1
#--------------------------------------
import os
import collectd
VERBOSE_LOGGING = False
def configure_callback(conf):
"""Received configuration information"""
global VERBOSE_LOGGING
if conf.key == 'Verbose':
VERBOSE_LOGGING = bool(conf.values[0])
else:
collectd.warning('mailqueues plugin: Unknown config key: %s.' % conf.key)
def fetch_stats():
queueCount={}
for queue in ['maildrop','incoming','active','deferred','hold']:
queueCount[queue]=0
for root, dirs, files in os.walk("/var/spool/postfix/"+queue):
queueCount[queue] += len(files)
for queue in queueCount:
#print("Mails in "+str(queue)+" : "+str(queueCount[queue]))
dispatch_stat(key=queue, value=queueCount[queue])
def dispatch_stat(key, value, type='gauge'):
"""Read a key from info response data and dispatch a value"""
value = int(value)
log_verbose('Sending value[%s]: %s=%s' % (type, key, value))
val = collectd.Values(plugin='mailqueues')
#val.plugin_instance = pinstance
val.type = type
val.type_instance = key
val.values = [value]
val.dispatch()
def read_callback():
log_verbose('Read callback called')
stats = fetch_stats()
def log_verbose(msg):
if not VERBOSE_LOGGING:
return
collectd.info('PostfixQueuesMailsCount plugin [verbose]: %s' % msg)
collectd.register_config(configure_callback)
collectd.register_read(read_callback)