[mythtv-users] Anybody have any alerts set up on failed recordings?
Matt Mossholder
matt at mossholder.com
Fri Mar 2 01:44:40 UTC 2012
On Thu, Mar 1, 2012 at 8:03 PM, Larry K <lunchtimelarry at gmail.com> wrote:
> On Thu, Mar 1, 2012 at 7:53 PM, Matt Emmott <memmott at gmail.com> wrote:
>
>> I have an occasionally-recurring problem where my HDHomeRun Prime, or at
>> least the Charter Tuning Adapter, loses its connection. When this happens,
>> recordings that use the cablecard (pretty much anything that isn't
>> available on QAM) fail. I came home today and had a boatload of failed
>> recordings. When this happens I have to reboot the Tuning Adapter and
>> HDHomeRun before I can tune those channels again.
>>
>> I was wondering if anybody had set up any kind of alerting, preferably
>> using email, when recordings fail. I haven't looked into it that deeply
>> yet, perhaps using procmail and the mythbackend.log, or the system events
>> feature that I admittedly haven't looked into very deeply.
>>
>> I'm open to any ideas. Thanks!
>>
>>
> I just have a simple script I run with cron to scan the log and send me an
> email. You can grep for whatever message you care about. Not very
> sophisticated, but it mostly works.
>
> #!/bin/bash
> if [ $(tac /var/log/mythtv/mythbackend.log |grep -e "Error:" | wc -l ) =
> 0 ] ; then
> exit
> else
> /usr/sbin/sendmail email_address at gmail.com < /mail_message.txt
> fi
> exit 0
>
My script is more HD-PVR-centric, but could probably be adapted to deal
with other situations. It is meant to run as a "Recording Finished" System
Event.
#!/usr/bin/env python
# zero-size-handler.py
# By Matt Mossholder
# http://www.mossholder.com
# A semi-frequent issue experienced by MythTV users is failed recordings
# resulting in a file with 0 bytes in it. This script attempts to identify
# these recordings as they occur, notify you via email, and schedule the
# program to be rerecorded at a later time.
# if any of these are not None, the given value(s) will be used to create a
# database connection
dbhost = None
dbname = None
dbuser = None
dbpass = None
# includes
from sys import exit,argv
from os import path
from subprocess import Popen,PIPE
from MythTV import MythBE,Program
from MythTV import OldRecorded, Recorded
from MythTV import MythDB, MythLog
# utility function: connect and return a MythDB object
def __db_connect():
# connect
args = []
if dbhost: args.append( ('DBHostName', dbhost) )
if dbname: args.append( ('DBName', dbname) )
if dbuser: args.append( ('DBUserName', dbuser) )
if dbpass: args.append( ('DBPassword', dbpass) )
db = MythDB(args=args)
log = MythLog(module='zero-size-handler', lstr='important')
return db
def sendMail(body):
sendmail_location = "/usr/sbin/sendmail" # sendmail location
p = Popen("%s -t" % sendmail_location, shell=True, stdin=PIPE)
p.stdin.write("From: %s\n" % "root")
p.stdin.write("To: %s\n" % "root")
p.stdin.write("Subject: Deleted & Rescheduled 0 byte recording\n")
p.stdin.write("\n") # blank line separating headers from body
p.stdin.write(body)
p.stdin.close()
status = p.wait()
if status != 0:
print "ERROR: Sendmail exit status", status
# zerosizehandler
def zerosizehandler(chanid, starttime, title, db=None):
if not db: db = __db_connect()
be = MythBE(db=db)
log = MythLog(module='zero-size-handler', lstr='general')
# get the information on the current recording
r = db.searchRecorded(chanid=chanid, starttime=starttime)
if r:
count = 0
for rec in r:
count = count+1
prog = Program.fromRecorded(rec)
if path.exists(be.getCheckfile(prog)):
if path.getsize(be.getCheckfile(prog)) == 0:
msg = 'Deleted 0 byte recording, set to allow re-recording for
chanid: %d, starttime: %s, title: %s, subtitle: %s' % ( prog.chanid,
prog.starttime.strftime("%Y%m%d%H%M%S"),prog.title, prog.subtitle )
sendMail(msg)
prog.delete(force=False,rerecord=True)
else:
msg = 'Recording is OK for chanid: %d, starttime: %s, title:
%s, subtitle: %s' % ( prog.chanid,
prog.starttime.strftime("%Y%m%d%H%M%S"), prog.title, prog.subtitle )
log(MythLog.GENERAL,msg)
else:
msg = 'Recording missing, set to allow re-recording for chanid: %d,
starttime: %s, title: %s, subtitle: %s' % ( prog.chanid,
prog.starttime.strftime("%Y%m%d%H%M%S"),prog.title, prog.subtitle )
sendMail(msg)
prog.delete(force=True,rerecord=True)
log(MythLog.GENERAL,msg)
if count == 0:
log(MythLog.GENERAL,'DB Record is missing for chanid: %s, starttime:
%s, title: %s' % ( chanid, starttime, title ) )
# main
if __name__ == '__main__':
if len(argv) == 4:
chanid = argv[1]
starttime = argv[2]
title = argv[3]
zerosizehandler(chanid, starttime, title)
else:
print "Invalid number of arguments!"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.mythtv.org/pipermail/mythtv-users/attachments/20120301/757342aa/attachment.html
More information about the mythtv-users
mailing list