<div class="gmail_quote">On Thu, Mar 1, 2012 at 8:03 PM, Larry K <span dir="ltr">&lt;<a href="mailto:lunchtimelarry@gmail.com">lunchtimelarry@gmail.com</a>&gt;</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">&lt;<a href="mailto:memmott@gmail.com" target="_blank">memmott@gmail.com</a>&gt;</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&#39;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&#39;t looked into it that deeply yet, perhaps using procmail and the mythbackend.log, or the system events feature that I admittedly haven&#39;t looked into very deeply.<br>


<br>I&#39;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 &quot;Error:&quot;  | 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> &lt; /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 &quot;Recording Finished&quot; 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( (&#39;DBHostName&#39;, dbhost) )</div><div>  if dbname: args.append( (&#39;DBName&#39;, dbname) )</div><div>  if dbuser: args.append( (&#39;DBUserName&#39;, dbuser) )</div>
<div>  if dbpass: args.append( (&#39;DBPassword&#39;, dbpass) )</div><div>  db = MythDB(args=args) </div><div>  log = MythLog(module=&#39;zero-size-handler&#39;, lstr=&#39;important&#39;)</div><div>  return db</div><div><br>
</div><div>def sendMail(body):</div><div>    sendmail_location = &quot;/usr/sbin/sendmail&quot; # sendmail location</div><div>    p = Popen(&quot;%s -t&quot; % sendmail_location, shell=True, stdin=PIPE)</div><div>    p.stdin.write(&quot;From: %s\n&quot; % &quot;root&quot;)</div>
<div>    p.stdin.write(&quot;To: %s\n&quot; % &quot;root&quot;)</div><div>    p.stdin.write(&quot;Subject: Deleted &amp; Rescheduled 0 byte recording\n&quot;)</div><div>    p.stdin.write(&quot;\n&quot;) # 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 &quot;ERROR: Sendmail exit status&quot;, 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=&#39;zero-size-handler&#39;, lstr=&#39;general&#39;)</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 = &#39;Deleted 0 byte recording, set to allow re-recording for chanid: %d,  starttime: %s,  title: %s,  subtitle: %s&#39; % ( prog.chanid, prog.starttime.strftime(&quot;%Y%m%d%H%M%S&quot;),prog.title, prog.subtitle )</div>
<div>          sendMail(msg)</div><div>          prog.delete(force=False,rerecord=True)</div><div>        else:</div><div>          msg = &#39;Recording is OK for chanid: %d,  starttime: %s,  title: %s,  subtitle: %s&#39; % ( prog.chanid, prog.starttime.strftime(&quot;%Y%m%d%H%M%S&quot;), prog.title, prog.subtitle )</div>
<div>        log(MythLog.GENERAL,msg)</div><div>      else:</div><div>        msg = &#39;Recording missing, set to allow re-recording for chanid: %d,  starttime: %s,  title: %s,  subtitle: %s&#39; % ( prog.chanid, prog.starttime.strftime(&quot;%Y%m%d%H%M%S&quot;),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,&#39;DB Record is missing for chanid: %s,  starttime: %s,  title: %s&#39; % ( chanid, starttime, title ) )</div>
<div><br></div><div># main</div><div>if __name__ == &#39;__main__&#39;:</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 &quot;Invalid number of arguments!&quot;</div><div><br></div></div>