Table of Contents

Send Mail when VDR timer-conflict occurs script-based

Context

Problems:

Prerequisite

Syslog-ng.conf (part of it):

Click to display ⇲

Click to hide ⇱

#vdr log##########################################################################
filter f_vdr {
  program(".*vdr.*");
  };
destination d_vdr {
  file("/data/syslog/vdr/$YEAR-$MONTH/vdr.log.$DAY"
  owner(root) group(root) perm(0644) dir_perm(0755) create_dirs(yes));
  };
destination d_vdr02 {
  file("/data/syslog/vdr/$YEAR-$MONTH/$FACILITY/vdr.log.$DAY"
  owner(root) group(root) perm(0644) dir_perm(0755) create_dirs(yes));
  };
log {
  source(s_all);
  filter(f_vdr);
  destination(d_vdr);
  destination(d_vdr02);
  };

Monitoring the log

Apr  2 17:20:00 vdr: [6734] EPGSearch: timer conflict check started
Apr  2 17:20:00 vdr: [6718] info: 1 Timer-Konflikt(e)! Erster am 02.04 20:38. Anzeigen?
Apr  2 17:20:08 vdr: [6734] EPGSearch: timer conflict check finished

Analysing the log isn't complicated:

vdr_timer_konflikte.sh
#!/bin/bash
#########################
##vdr Timer-conflicts and send mail
##30.03.2010
#########################
LOGDATE=`date '+%Y-%m'`
DAY=`date '+%d'`
LOGFILE="/syslog/vdr/$LOGDATE/vdr.log.$DAY"
LOCKFILE="/tmp/timer_konflikt_$DAY.lock"
ACTFILE="/tmp/timer_konflikt.log"
DATE=`date '+%A %d. %b %Y %H:%M:%S'`
MAILTO="user@example.com"
SUBJECT="ALERT vdr Timer-conflict($DATE)"
###############################################################
/usr/bin/find /tmp/ -name *timer_konflikt* -mtime +1 -exec rm -f {} \;
GREP=`/bin/grep "Timer-Konflikt" $LOGFILE`
# wenn grep was gefunden rückgabe = 0
if [ $? == 0 ];then
	GREP=`/bin/grep "Timer-Konflikt" $LOGFILE | tail -1 | cut -d : -f 5-6`
        #GREP=`/bin/grep "Timer-Konflikt" $LOGFILE | tail -1 | cut -c 40-120`
	# check mail already send
	touch $ACTFILE	
	touch $LOCKFILE
	echo $GREP > $ACTFILE
 
	/usr/bin/diff $ACTFILE $LOCKFILE > /dev/null
	if [ $? != 0 ];then
		echo $GREP > $LOCKFILE
		TEXT="A Conflict in a Timer occured in the logfile.\nPleas check.\n\n"
		TEXT="$TEXT$GREP"
		TEXT="$TEXT\n\nhttp://vdr.example.org"
    TEXT="$TEXT\nhttp://vdr.example.lan\n"
		TEXT="$TEXT \n\n\n\nYour faithful employee,\n\nyour vdr!"
		echo -e $TEXT | /usr/bin/mailx -s "$SUBJECT" $MAILTO
fi
rm -f $ACTFILE