-
Notifications
You must be signed in to change notification settings - Fork 1
/
rspamd.chart.py
76 lines (64 loc) · 2.57 KB
/
rspamd.chart.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
# Description: rspamd netdata python.d module
# Author: Keijo Korte <git@kvak.net> (@korteke)
# SPDX-License-Identifier: GPL-3.0-or-later
from bases.FrameworkServices.UrlService import UrlService
from json import loads
# Basic plugin settings for netdata.
update_every = 10
priority = 60000
retries = 10
ORDER = ['stats',
'actions'
]
CHARTS = {
'stats': {
'options': [None, 'Stats', 'stats', 'Stats', 'rspamd.stats', 'line'],
'lines': [
['spam_count', 'Spam', 'absolute'],
['ham_count', 'Ham', 'absolute'],
['scanned', 'Scanned', 'absolute'],
['learned', 'Learned', 'absolute'],
]
},
'actions': {
'options': [None, 'Actions', 'actions', 'Actions', 'rspamd.actions', 'line'],
'lines': [
['action_reject', 'Reject', 'absolute'],
['action_softreject', 'Soft reject', 'absolute'],
['action_rewritesubject', 'Rewrite subject', 'absolute'],
['action_addheader', 'Add header', 'absolute'],
['action_greylist', 'Greylist', 'absolute'],
['action_noaction', 'No Action', 'absolute'],
]
},
}
class Service(UrlService):
def __init__(self, configuration=None, name=None):
UrlService.__init__(self, configuration=configuration, name=name)
self.order = ORDER
self.definitions = CHARTS
self.url = self.configuration.get('url', 'http://localhost:11334')+'/stat'
def check(self):
self._manager = self._build_manager()
data = self._get_data()
if not data:
return None
return True
def _get_data(self):
#raw_data = self._get_raw_data()
raw_data = loads(self._get_raw_data())
if not raw_data:
return None
data = dict()
data.update({"spam_count": str(raw_data["spam_count"])})
data.update({"ham_count": str(raw_data["ham_count"])})
data.update({"scanned": str(raw_data["scanned"])})
data.update({"learned": str(raw_data["learned"])})
data.update({"action_reject": str(raw_data["actions"]["reject"])})
data.update({"action_softreject": str(raw_data["actions"]["soft reject"])})
data.update({"action_rewritesubject": str(raw_data["actions"]["rewrite subject"])})
data.update({"action_addheader": str(raw_data["actions"]["add header"])})
data.update({"action_greylist": str(raw_data["actions"]["greylist"])})
data.update({"action_noaction": str(raw_data["actions"]["no action"])})
return(data)