Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / other / dspam_activity @ 2aea630c

Historique | Voir | Annoter | Télécharger (7,84 ko)

1
#!/bin/sh
2
# -*- sh -*-
3

    
4
: << =cut
5

    
6
=head1 NAME
7

    
8
dspam_activity - Plugin to monitor DSPAM message handling activities.
9

    
10
=head1 APPLICABLE SYSTEMS
11

    
12
Any system running a recent (3.8.0 or higher) DSPAM install.
13

    
14
=head1 CONFIGURATION
15

    
16
The plugin uses the contents of the SystemLog or UserLog produced by DSPAM.
17

    
18
The following environment variables are used by this plugin:
19

    
20
 logfile - Where to find the system.log that is written by dspam
21
          (default: /var/spool/dspam/system.log)
22

    
23
=head2 CONFIGURATION EXAMPLES
24

    
25
 [dspam_activity]
26
  env.logfile /opt/dspam/var/spool/dspam/system.log
27
  # or when monitoring only a single user in stead of all users:
28
  env.logfile /var/spool/dspam/data/example.org/username/username.log
29

    
30
=head1 USAGE
31

    
32
Link this plugin to /etc/munin/plugins/ and restart the munin-node.
33

    
34
You'll need to enable system logging in dspam.conf, set 'SystemLog on'
35
in the DSPAM configuration file.
36

    
37
=head1 INTERPRETATION
38

    
39
The graph shows the messages that DSPAM has processed over the monitored
40
period, and what kind of action was taken on it. Possible activities are:
41

    
42
 Received messages can be classified as:
43
 - Innocent (I)
44
 - Spam (S)
45
 - Auto-whitelist (W)
46
 - Virus (V)
47
 - Blocklist (O)
48
 - Blacklist (RBL) (A)
49
 Other actions:
50
 - Retrained as spam (M)
51
 - Retrained as innocent (F)
52
 - Inoculation (N)
53
 - Corpusfed (C)
54

    
55
Please see DSPAM documentation for more information on used terminology. The
56
single character in parentheses is the DSPAM internal name for the classifications.
57

    
58
=head1 AUTHOR
59

    
60
Copyright 2010-2011 Tom Hendrikx <tom@whyscream.net>
61

    
62
=head1 LICENSE
63

    
64
GPLv2
65

    
66
This program is free software; you can redistribute it and/or modify
67
it under the terms of the GNU General Public License as published by
68
the Free Software Foundation; version 2 dated June, 1991.
69

    
70
This program is distributed in the hope that it will be useful, but
71
WITHOUT ANY WARRANTY; without even the implied warranty of
72
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
73
General Public License for more details.
74

    
75
You should have received a copy of the GNU General Public License
76
along with this program; if not, write to the Free Software
77
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
78
02110-1301 USA.
79

    
80
=head1 BUGS
81

    
82
None known. Please report to author when you think you found something.
83

    
84
=head2 TODO LIST
85

    
86
=head1 VERSION
87

    
88
$Id: dspam_activity 139 2011-08-04 20:03:22Z tomhendr $
89

    
90
=head1 MAGIC MARKERS
91

    
92
 #%# family=auto
93
 #%# capabilities=autoconf
94

    
95
=cut
96

    
97
# defaults for configurable settings
98
: ${logfile:=/var/spool/dspam/system.log}
99
: ${statefile:=$MUNIN_STATEFILE}
100

    
101
# include munin plugin helper
102
. $MUNIN_LIBDIR/plugins/plugin.sh
103

    
104
##########################
105
# Some generic functions #
106
##########################
107

    
108
#
109
# debug $message
110
#	Prints debugging output when munin-run is called with --pidebug argument (i.e. when MUNIN_DEBUG is set)
111
#
112
debug() {
113
	if [ -n "$MUNIN_DEBUG" ]; then
114
		echo "# DEBUG: $@"
115
	fi
116
}
117

    
118
#
119
# get_activity_description $activity $type
120
#	Return textual descriptions for the various activities
121
#
122
get_activity_description() {
123
	local activity=$1
124
	local type=$2
125

    
126
	# defaults
127
	local short="Unknown ($activity)"
128
	local long="Unknown ($activity)"
129

    
130
	# Possible activities: I S W V O A M F N C
131
	case $activity in
132
		I) short=Innocent long="Messages received and classified as innocent" ;;
133
		S) short=Spam long="Messages received and classified as spam" ;;
134
		W) short=Auto-whitelisted long="Messages received and auto-whitelisted" ;;
135
		V) short=Virus long="Messages received and classified as virus by Clamav" ;;
136
		O) short=Blocklisted long="Messages received but not classified because the sender domain is on to the user blocklist" ;;
137
		A) short="Blacklisted (RBL)" long="Message received and classified as spam because the sender ip is listed on the RBL" ;;
138
		M) short="Retrained as spam" long="Messages classified as innocent, but retrained by user as spam" ;;
139
		F) short="Retrained as innocent" long="Messages classified as spam, but retrained by the user as innocent" ;;
140
		N) short=Inoculation long="Messages trained as spam trough inoculation" ;;
141
		C) short=Corpusfed long="Messages fed from a corpus" ;;
142
	esac
143

    
144
	[ "$type" = "short" ] && echo $short && return
145
	[ "$type" = "long" ] && echo $long && return
146
}
147

    
148
########################################
149
# Functions that generate munin output #
150
########################################
151

    
152
#
153
# print_autoconf
154
#	Output for 'munin-node-configure autoconf' functionality
155
#
156
print_autoconf() {
157
	if [ ! -r $logfile ]; then
158
		echo "no (logfile $logfile does not exist or not readable)"
159
	else
160
		echo yes
161
	fi
162
}
163

    
164
#
165
# print_config
166
#	Output for 'munin-run <plugin> config' command.
167
#
168
print_config() {
169
	debug printing config
170

    
171
	echo "graph_title DSPAM activity"
172
	echo graph_category dspam
173
	echo graph_args --base 1000
174
	echo graph_vlabel Messages / \${graph_period}
175
	echo graph_period minute
176

    
177
	for activity in I S W V O A M F N C; do
178
		local label=$(get_activity_description $activity short)
179
		local info=$(get_activity_description $activity long)
180
		echo $activity.label $label
181
		echo $activity.info $info
182
		echo $activity.draw AREASTACK
183
		echo $activity.type DERIVE
184
		echo $activity.min 0
185
	done
186

    
187
	debug finished printing config
188
}
189

    
190
#
191
# print_fetch
192
#	Output for 'munin-run <plugin> fetch' command: the actual data to graph.
193
#
194
print_fetch() {
195
	debug printing fetch
196

    
197
	local old_ts
198
	[ -r $statefile ] && old_ts=$(cat $statefile)
199
	if [ -n "$old_ts" ]; then
200
		debug read timestamp $old_ts from statefile
201

    
202
		# sample from system.log:
203
		# 1285144434<tab>M<tab>"Dr.Abdul Qahaar" <dr.abdulqahaar@sify.com><tab>2,4c99980137698241679684 \
204
		#  <tab>Business Proposal / Partnership Investment<tab>1.256280<tab>username@example.org<tab>Retrained<tab><421586.75972.qm@web120402.mail.ne1.yahoo.com>
205

    
206
		if [ -r $logfile ]; then
207

    
208
			# Possible activities: I S W V O A M F N C
209
			local aI=0 aS=0 aW=0 aV=0 aO=0 aA=0 aM=0 aF=0 aN=0 aC=0
210

    
211
			local skipped=0 processed=0
212
			local old_IFS=$IFS
213
			IFS="	" # tab-separator in $logfile
214
			while read ts activity from signature subject x recipient info msgid; do
215
				if ! [ $ts -gt 0 2> /dev/null ]; then
216
					debug skipped entry with non-numeric timestamp: $ts
217
				elif [ $ts -gt $old_ts ]; then
218
					debug processing entry with timestamp $ts, activity=$activity, subject=$subject, msgid=$msgid
219
					case $activity in
220
						I) aI=$((aI + 1)) ;;
221
						S) aS=$((aS + 1)) ;;
222
						W) aW=$((aW + 1)) ;;
223
						V) aV=$((aV + 1)) ;;
224
						O) aO=$((aO + 1)) ;;
225
						A) aA=$((aA + 1)) ;;
226
						M) aM=$((aM + 1)) ;;
227
						F) aF=$((aF + 1)) ;;
228
						N) aN=$((aN + 1)) ;;
229
						C) aC=$((aC + 1)) ;;
230
						*) debug unknown activity $activity found, subject=$subject, msgid=$msgid ;;
231
					esac
232

    
233
					processed=$((processed + 1))
234
				else
235
					skipped=$((skipped + 1))
236
				fi
237
			done < $logfile
238
			IFS=$old_IFS
239
			debug skipped $skipped lines in logfile because timestamp was too old
240
			debug processed $processed lines in logfile
241

    
242
			# show results
243
			echo I.value $aI
244
			echo S.value $aS
245
			echo W.value $aW
246
			echo V.value $aV
247
			echo O.value $aO
248
			echo A.value $aA
249
			echo M.value $aM
250
			echo F.value $aF
251
			echo N.value $aN
252
			echo C.value $aC
253
		else
254
			debug logfile not available $logfile
255
			exit 66 # EX_NOINPUT
256
		fi
257
	else
258
		debug could not read timestamp from statefile
259
		# no exit here, we need the next operation to write a timestamp in the statefile
260
	fi
261

    
262
	# update statefile with current timestamp
263
	local new_ts=$(date +%s)
264
	echo $new_ts > $statefile
265
	debug timestamp in statefile updated to $new_ts, old was $old_ts
266

    
267
	debug finished printing fetch
268
}
269

    
270

    
271
#####################
272
# Main process loop #
273
#####################
274

    
275
# show env settings
276
debug dspam_activity plugin started, pid=$$
277
debug settings:
278
debug - logfile is set to: $logfile
279
debug - statefile is set to: $statefile
280

    
281
command=$1
282
[ -n "$command" ] || command="fetch"
283
debug - command is set to: $command
284

    
285
debug settings completed, starting process
286

    
287
case $command in
288
	autoconf)
289
		print_autoconf
290
		;;
291
	config)
292
		print_config
293
		;;
294
	fetch)
295
		print_fetch
296
		;;
297
esac
298

    
299
debug exiting
300
exit 0 # EX_OK