#!/bin/sh -e
#
# start the RRD feeders
#
# $Cambridge: hermes/src/stats/scripts/rrdrun,v 1.23 2004/11/30 13:45:16 fanf2 Exp $

PATH=$PATH:/opt/stats/bin:/opt/stats/scripts

SOCK=/data/stats/ppsw/log_sock

cd /data/stats/ppsw/graphs

# rrdmk balance.rrd ppsw0 ppsw1 ppsw2 ppsw3 ppsw4 ppsw5 ppsw6 ppsw7 ppsw8 ppsw9
loguse -crp loguse.balance.pid -s $SOCK					|
	rrdfeed balance.rrd						\
		ppsw0 '^\w{3} [ 123][0-9] [0-9:]{8} ppsw-0-intramail '	\
		ppsw1 '^\w{3} [ 123][0-9] [0-9:]{8} ppsw-1-intramail '	\
		ppsw2 '^\w{3} [ 123][0-9] [0-9:]{8} ppsw-2-intramail '	\
		ppsw3 '^\w{3} [ 123][0-9] [0-9:]{8} ppsw-3-intramail '	\
		ppsw4 '^\w{3} [ 123][0-9] [0-9:]{8} ppsw-4-intramail '	\
		ppsw5 '^\w{3} [ 123][0-9] [0-9:]{8} ppsw-5-intramail '	\
		ppsw6 '^\w{3} [ 123][0-9] [0-9:]{8} ppsw-6-intramail '	\
		ppsw7 '^\w{3} [ 123][0-9] [0-9:]{8} ppsw-7-intramail '	\
		ppsw8 '^\w{3} [ 123][0-9] [0-9:]{8} ppsw-8-intramail '	\
		ppsw9 '^\w{3} [ 123][0-9] [0-9:]{8} ppsw-9-intramail '	&

# rrdmk -gauge balexim.rrd ppsw0 ppsw1 ppsw2 ppsw3 ppsw4 ppsw5 ppsw6 ppsw7 ppsw8 ppsw9
loguse -crp loguse.balexim.pid -s $SOCK					|
	rrdfeed -s balexim.rrd						\
		ppsw0 ' ppsw-0-intramail countprocs: exim [^ ]* ([0-9]*)' \
		ppsw1 ' ppsw-1-intramail countprocs: exim [^ ]* ([0-9]*)' \
		ppsw2 ' ppsw-2-intramail countprocs: exim [^ ]* ([0-9]*)' \
		ppsw3 ' ppsw-3-intramail countprocs: exim [^ ]* ([0-9]*)' \
		ppsw4 ' ppsw-4-intramail countprocs: exim [^ ]* ([0-9]*)' \
		ppsw5 ' ppsw-5-intramail countprocs: exim [^ ]* ([0-9]*)' \
		ppsw6 ' ppsw-6-intramail countprocs: exim [^ ]* ([0-9]*)' \
		ppsw7 ' ppsw-7-intramail countprocs: exim [^ ]* ([0-9]*)' \
		ppsw8 ' ppsw-8-intramail countprocs: exim [^ ]* ([0-9]*)' \
		ppsw9 ' ppsw-9-intramail countprocs: exim [^ ]* ([0-9]*)' &

# rrdmk -gauge balproxy.rrd ppsw0 ppsw1 ppsw2 ppsw3 ppsw4 ppsw5 ppsw6 ppsw7 ppsw8 ppsw9
loguse -crp loguse.balproxy.pid -s $SOCK				|
	rrdfeed -s balproxy.rrd						\
		ppsw0 ' ppsw-0-intramail countprocs: proxy [^ ]* ([0-9]*)' \
		ppsw1 ' ppsw-1-intramail countprocs: proxy [^ ]* ([0-9]*)' \
		ppsw2 ' ppsw-2-intramail countprocs: proxy [^ ]* ([0-9]*)' \
		ppsw3 ' ppsw-3-intramail countprocs: proxy [^ ]* ([0-9]*)' \
		ppsw4 ' ppsw-4-intramail countprocs: proxy [^ ]* ([0-9]*)' \
		ppsw5 ' ppsw-5-intramail countprocs: proxy [^ ]* ([0-9]*)' \
		ppsw6 ' ppsw-6-intramail countprocs: proxy [^ ]* ([0-9]*)' \
		ppsw7 ' ppsw-7-intramail countprocs: proxy [^ ]* ([0-9]*)' \
		ppsw8 ' ppsw-8-intramail countprocs: proxy [^ ]* ([0-9]*)' \
		ppsw9 ' ppsw-9-intramail countprocs: proxy [^ ]* ([0-9]*)' &

# rrdmk connrefuse.rrd HighLoad HighCount
loguse -crp loguse.connrefuse.pid -s $SOCK				|
	rrdfeed connrefuse.rrd						\
		HighLoad ': not in reserve list and load average ='	\
		HighCount ': not in reserve list: connected='		&

# rrdmk connrefuse2.rrd TooMany
loguse -crp loguse.connrefuse2.pid -s $SOCK				|
	rrdfeed connrefuse2.rrd						\
		TooMany   'too many connections from that IP address'	&

# rrdmk dnsbl.rrd Spamhaus RBLplus
loguse -crp loguse.dnsbl.pid -s $SOCK					|
	rrdfeed dnsbl.rrd						\
		Spamhaus 'is listed at sbl-xbl'				\
		RBLplus 'is listed at rbl-plus'				&

# rrdmk dnsbl2.rrd HeloNS FromNS FromMX
loguse -crp loguse.dnsbl2.pid -s $SOCK					|
	rrdfeed dnsbl2.rrd						\
		HeloNS 'The name servers for the host name'		\
		FromNS 'The name servers for the domain'		\
		FromMX 'The mail servers for the domain'		&

# rrdmk -gauge delay.rrd Delay
loguse -crp loguse.delay.pid -s $SOCK					|
	rrdfeed -t delay.rrd						\
		Delay ' QT=([0-9wdhms]+) '				&

# rrdmk forwarded.rrd Forwarded FwdVol
CYRUS='cyrus-[0-9]+[.]csi[.]private[.]cam[.]ac[.]uk'
loguse -crp loguse.forwarded.pid -s $SOCK				|
	rrdfeed -s forwarded.rrd					\
		Forwarded " <= .* H=$CYRUS "				\
		FwdVol    " <= .* H=$CYRUS .* S=([0-9]+) "		&

# rrdmk fromhermes.rrd Hermes1 Hermes2
loguse -crp loguse.fromhermes.pid -s $SOCK				|
	rrdfeed -s fromhermes.rrd					\
		Hermes1 ' <= .* H=hermes-1[.]csi[.]cam[.]ac[.]uk '	\
		Hermes2 ' <= .* H=hermes-2[.]csi[.]cam[.]ac[.]uk '	&

# rrdmk -gauge inqueue.rrd InQueueSz
loguse -crp loguse.inqueue.pid -s $SOCK					|
	rrdfeed -a inqueue.rrd						\
		InQueueSz 'New Batch: Found (\d+) messages waiting'	&

# rrdmk lmtp0.rrd cyrus1 cyrus2 cyrus3 cyrus4 cyrus5 cyrus6 cyrus7 cyrus8 cyrus9 cyrus10
loguse -crp loguse.lmtp0.pid -s $SOCK					|
	rrdfeed lmtp0.rrd						\
		cyrus1 ' => .* H=cyrus-1-intramail.csi.cam.ac.uk '	\
		cyrus2 ' => .* H=cyrus-2-intramail.csi.cam.ac.uk '	\
		cyrus3 ' => .* H=cyrus-3-intramail.csi.cam.ac.uk '	\
		cyrus4 ' => .* H=cyrus-4-intramail.csi.cam.ac.uk '	\
		cyrus5 ' => .* H=cyrus-5-intramail.csi.cam.ac.uk '	\
		cyrus6 ' => .* H=cyrus-6-intramail.csi.cam.ac.uk '	\
		cyrus7 ' => .* H=cyrus-7-intramail.csi.cam.ac.uk '	\
		cyrus8 ' => .* H=cyrus-8-intramail.csi.cam.ac.uk '	\
		cyrus9 ' => .* H=cyrus-9-intramail.csi.cam.ac.uk '	\
		cyrus10 ' => .* H=cyrus-10-intramail.csi.cam.ac.uk '	&

# rrdmk lmtp1.rrd cyrus11 cyrus12 cyrus13 cyrus14 cyrus15 cyrus16 cyrus17 cyrus18 cyrus19 cyrus20
loguse -crp loguse.lmtp1.pid -s $SOCK					|
	rrdfeed lmtp1.rrd						\
		cyrus11 ' => .* H=cyrus-11-intramail.csi.cam.ac.uk '	\
		cyrus12 ' => .* H=cyrus-12-intramail.csi.cam.ac.uk '	\
		cyrus13 ' => .* H=cyrus-13-intramail.csi.cam.ac.uk '	\
		cyrus14 ' => .* H=cyrus-14-intramail.csi.cam.ac.uk '	\
		cyrus15 ' => .* H=cyrus-15-intramail.csi.cam.ac.uk '	\
		cyrus16 ' => .* H=cyrus-16-intramail.csi.cam.ac.uk '	\
		cyrus17 ' => .* H=cyrus-17-intramail.csi.cam.ac.uk '	\
		cyrus18 ' => .* H=cyrus-18-intramail.csi.cam.ac.uk '	\
		cyrus19 ' => .* H=cyrus-19-intramail.csi.cam.ac.uk '	\
		cyrus20 ' => .* H=cyrus-20-intramail.csi.cam.ac.uk '	&

# rrdmk -gauge load.rrd ppsw0 ppsw1 ppsw2 ppsw3 ppsw4 ppsw5 ppsw6 ppsw7 ppsw8 ppsw9
loguse -crp loguse.load.pid -s $SOCK					|
	rrdfeed -a load.rrd						\
		ppsw0 ' ppsw-0-intramail countprocs: load average: ([0-9.]*), ' \
		ppsw1 ' ppsw-1-intramail countprocs: load average: ([0-9.]*), ' \
		ppsw2 ' ppsw-2-intramail countprocs: load average: ([0-9.]*), ' \
		ppsw3 ' ppsw-3-intramail countprocs: load average: ([0-9.]*), ' \
		ppsw4 ' ppsw-4-intramail countprocs: load average: ([0-9.]*), ' \
		ppsw5 ' ppsw-5-intramail countprocs: load average: ([0-9.]*), ' \
		ppsw6 ' ppsw-6-intramail countprocs: load average: ([0-9.]*), ' \
		ppsw7 ' ppsw-7-intramail countprocs: load average: ([0-9.]*), ' \
		ppsw8 ' ppsw-8-intramail countprocs: load average: ([0-9.]*), ' \
		ppsw9 ' ppsw-9-intramail countprocs: load average: ([0-9.]*), ' &

# rrdmk -gauge processes.rrd exim_in exim_out proxy_imap proxy_imaps proxy_pop proxy_pops
loguse -crp loguse.processes.pid -s $SOCK				|
	rrdfeed -s processes.rrd					\
		exim_in     ' countprocs: exim incoming: ([0-9]*)'	\
		exim_out    ' countprocs: exim delivering: ([0-9]*)'	\
		proxy_imap  ' countprocs: proxy imap: ([0-9]*)'		\
		proxy_imaps ' countprocs: proxy imaps: ([0-9]*)'	\
		proxy_pop   ' countprocs: proxy pop: ([0-9]*)'		\
		proxy_pops  ' countprocs: proxy pops: ([0-9]*)'		&

# rrdmk protocol.rrd Relay Unauth Hello Sync
loguse -crp loguse.protocol.pid -s $SOCK				|
	rrdfeed protocol.rrd						\
		Relay 'Relaying is not permitted'			\
		Unauth 'No SMTP service for unauthorized users'		\
		Hello 'Please use your name when saying HELO'		\
		Sync 'SMTP protocol violation: synchronization error'	&

# rrdmk reject.rrd Temp All
loguse -crp loguse.reject.pid -s $SOCK					|
	rrdfeed reject.rrd						\
		Temp 'temporarily rejected RCPT'			\
		All 'rejected RCPT'					&

# rrdmk roles.rrd Vppsw ppsw MX Hermes25 Hermes465 Hermes587
loguse -crp loguse.roles.pid -s $SOCK					|
	rrdfeed roles.rrd						\
		Vppsw ' <= .* I=[[]131[.]111[.]8[.]129[]]'		\
		ppsw   ' <= .* I=[[]131[.]111[.]8[.]13'			\
		MX      ' <= .* I=[[]131[.]111[.]8[.]14'		\
		Hermes25 ' <= .* I=[[]131[.]111[.]8[.]15.[]]:25 '	\
		Hermes465 ' <= .* I=[[]131[.]111[.]8[.]15.[]]:465 '	\
		Hermes587 ' <= .* I=[[]131[.]111[.]8[.]15.[]]:587 '	&

# rrdmk smtptype.rrd smtp smtps esmtp esmtpa esmtps esmtpsa
loguse -crp loguse.smtptype.pid -s $SOCK					|
	rrdfeed smtptype.rrd						\
		smtp	' P=smtp '					\
		smtps	' P=smtps '					\
		esmtp	' P=esmtp '					\
		esmtpa	' P=esmtpa '					\
		esmtps	' P=esmtps '					\
		esmtpsa	' P=esmtpsa '					&

# rrdmk sender.rrd Temp Perm
loguse -crp loguse.sender.pid -s $SOCK					|
	rrdfeed sender.rrd						\
		Temp 'temporarily rejected RCPT .* Could not complete sender verify'	\
		Perm 'rejected RCPT .* Sender verify failed'				&

# rrdmk spam.rrd Spam
loguse -crp loguse.spam.pid -s $SOCK					|
	rrdfeed spam.rrd						\
		Spam 'SpamAssassin [(]score=([56789]|[1-9][0-9]+)[.][0-9]+' &

# rrdmk spam2.rrd LoSpam HiSpam
loguse -crp loguse.spam2.pid -s $SOCK					|
	rrdfeed spam2.rrd						\
		LoSpam 'SpamAssassin [(]score=[56789][.][0-9]+'		\
		HiSpam 'SpamAssassin [(]score=[1-9][0-9]+[.][0-9]+'	&

# rrdmk traffic.rrd MsgIn MsgOut XRcpt Bounce
loguse -crp loguse.traffic.pid -s $SOCK					|
	rrdfeed traffic.rrd						\
		MsgIn ' <= '						\
		MsgOut ' => '						\
		XRcpt ' -> '						\
		Bounce ' [*][*] '					&

# rrdmk virus.rrd ClamAV McAfee
loguse -crp loguse.virus.pid -s $SOCK					|
	rrdfeed virus.rrd						\
		ClamAV ' FOUND  '					\
		McAfee ' !!!  '						&

# rrdmk volume.rrd VolIn VolOut
loguse -crp loguse.volume.pid -s $SOCK					|
	rrdfeed -s volume.rrd						\
		VolIn ' <= .* S=([0-9]+) '				\
		VolOut ' => .* S=([0-9]+) '				&

exit
