EanderAlx.org

Linux, Virtualization and whatever I find interesting ...

User Tools


Site Tools


linux:vdr_konflikt_mail

Send Mail when VDR timer-conflict occurs script-based

  • Send Mail when VDR timer-conflict occurs.

Context

Problems:

  • I'm using my vdr without a client and without OSD.
  • I doesn't find a pleasant possibility to send a mail when a conflict occurs.
  • By using epgsearch, a conflict could arise without noticing.
  • A existing Perl script wasn't possible to use for me because I have installed postfix and mailx not sendmail.

Prerequisite

  • All logs produced by vdr are collected by syslog-ng into a single file so that can be analysed.

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

  • Every 30min, or something like that, vdr checks for timer-conflicts (It's a German System)
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:

  • mailx only works without additional options when postfix is configured properly
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
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
linux/vdr_konflikt_mail.txt · Last modified: 23.03.2013 18:44 by eanderalx