<div class="gmail_quote">On Thu, Mar 1, 2012 at 8:03 PM, Larry K <span dir="ltr"><<a href="mailto:lunchtimelarry@gmail.com">lunchtimelarry@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><div>On Thu, Mar 1, 2012 at 7:53 PM, Matt Emmott <span dir="ltr"><<a href="mailto:memmott@gmail.com" target="_blank">memmott@gmail.com</a>></span> wrote:</div></div></div><div class="gmail_quote">
<div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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.<br>
<br>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.<br>
<br>I'm open to any ideas. Thanks!<br>
<br></blockquote><div><br></div></div></div><div>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.<div>
<br></div><div><div>#!/bin/bash</div><div>if [ $(tac /var/log/mythtv/mythbackend.log |grep -e "Error:" | wc -l ) = 0 ] ; then</div><div>exit</div><div>else</div><div>/usr/sbin/sendmail <a href="mailto:email_address@gmail.com" target="_blank">email_address@gmail.com</a> < /mail_message.txt</div>
<div>fi</div><div>exit 0</div></div></div></div></blockquote><div><br></div><div>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.</div>
<div><br></div><div> #!/usr/bin/env python</div><div><br></div><div># zero-size-handler.py</div><div># By Matt Mossholder</div><div># <a href="http://www.mossholder.com">http://www.mossholder.com</a></div><div><br>
</div><div># A semi-frequent issue experienced by MythTV users is failed recordings</div><div># resulting in a file with 0 bytes in it. This script attempts to identify</div><div># these recordings as they occur, notify you via email, and schedule the</div>
<div># program to be rerecorded at a later time.</div><div><br></div><div># if any of these are not None, the given value(s) will be used to create a</div><div># database connection</div><div>dbhost = None</div><div>dbname = None</div>
<div>dbuser = None</div><div>dbpass = None</div><div><br></div><div># includes</div><div>from sys import exit,argv</div><div>from os import path</div><div>from subprocess import Popen,PIPE</div><div>from MythTV import MythBE,Program</div>
<div>from MythTV import OldRecorded, Recorded</div><div>from MythTV import MythDB, MythLog</div><div><br></div><div><br></div><div># utility function: connect and return a MythDB object</div><div>def __db_connect():</div>
<div><br></div><div> # connect</div><div> args = []</div><div> if dbhost: args.append( ('DBHostName', dbhost) )</div><div> if dbname: args.append( ('DBName', dbname) )</div><div> if dbuser: args.append( ('DBUserName', dbuser) )</div>
<div> if dbpass: args.append( ('DBPassword', dbpass) )</div><div> db = MythDB(args=args) </div><div> log = MythLog(module='zero-size-handler', lstr='important')</div><div> return db</div><div><br>
</div><div>def sendMail(body):</div><div> sendmail_location = "/usr/sbin/sendmail" # sendmail location</div><div> p = Popen("%s -t" % sendmail_location, shell=True, stdin=PIPE)</div><div> p.stdin.write("From: %s\n" % "root")</div>
<div> p.stdin.write("To: %s\n" % "root")</div><div> p.stdin.write("Subject: Deleted & Rescheduled 0 byte recording\n")</div><div> p.stdin.write("\n") # blank line separating headers from body</div>
<div> p.stdin.write(body)</div><div> p.stdin.close() </div><div> status = p.wait()</div><div> if status != 0:</div><div> print "ERROR: Sendmail exit status", status</div><div><br></div><div># zerosizehandler</div>
<div>def zerosizehandler(chanid, starttime, title, db=None):</div><div><br></div><div> if not db: db = __db_connect()</div><div> be = MythBE(db=db)</div><div> log = MythLog(module='zero-size-handler', lstr='general')</div>
<div><br></div><div> # get the information on the current recording</div><div> r = db.searchRecorded(chanid=chanid, starttime=starttime)</div><div> if r:</div><div> count = 0</div><div> for rec in r:</div><div> count = count+1</div>
<div> prog = Program.fromRecorded(rec)</div><div> if path.exists(be.getCheckfile(prog)):</div><div> if path.getsize(be.getCheckfile(prog)) == 0:</div><div> 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 )</div>
<div> sendMail(msg)</div><div> prog.delete(force=False,rerecord=True)</div><div> else:</div><div> 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 )</div>
<div> log(MythLog.GENERAL,msg)</div><div> else:</div><div> 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 )</div>
<div> sendMail(msg)</div><div> prog.delete(force=True,rerecord=True)</div><div> log(MythLog.GENERAL,msg)</div><div> if count == 0:</div><div> log(MythLog.GENERAL,'DB Record is missing for chanid: %s, starttime: %s, title: %s' % ( chanid, starttime, title ) )</div>
<div><br></div><div># main</div><div>if __name__ == '__main__':</div><div><br></div><div> if len(argv) == 4:</div><div> chanid = argv[1]</div><div> starttime = argv[2]</div><div> title = argv[3]</div><div>
zerosizehandler(chanid, starttime, title)</div><div> else:</div><div> print "Invalid number of arguments!"</div><div><br></div></div>