Ticket #4049: mythtv-miscellaneous_status_info-example_scripts-20071008.patch

File mythtv-miscellaneous_status_info-example_scripts-20071008.patch, 20.8 KB (added by sphery <mtdean@…>, 17 years ago)

Updates myth_recent_recordings.pl and adds myth_upcoming_recordings.pl

  • contrib/misc_status_info/myth_recent_recordings.pl

     
     1#!/usr/bin/perl -w
     2#
     3# Outputs information about the most-recently-recorded shows.
     4#
     5# Automatically detects database settings.
     6#
     7
     8# Includes
     9    use DBI;
     10    use Getopt::Long;
     11    use MythTV;
     12
     13# Some variables we'll use here
     14    our ($num_recordings, $live, $heading, $plain_text, $text_format, $usage);
     15    our ($dnum_recordings, $dheading, $dtext_format);
     16    our ($status_text_format, $status_value_format);
     17    our ($dstatus_text_format, $dstatus_value_format);
     18
     19# Default number of recent recordings to show
     20    $dnum_recordings = 5;
     21# Default status output heading
     22    $dheading='Recent Recordings:\n';
     23# Default format of plain-text output
     24    $dtext_format='%n/%j, %g:%i %A - %cc\n%T - %S\n%R\n\n';
     25# Default format of status output display text
     26    $dstatus_text_format= '<a href="#">%n/%j, %g:%i %A -  %cc - %T - %S<br />'.
     27                          '<span><strong>%T</strong> %n/%j, %g:%i %A<br />'.
     28                          '<em>%S</em><br /><br />%R<br /></span></a><hr />';
     29# Default format of status output value
     30    $dstatus_value_format = '%n/%j, %g:%i %A - %T - %S';
     31
     32# Provide default values for GetOptions
     33    $num_recordings = $dnum_recordings;
     34    $text_format = $dtext_format;
     35    $heading = $dheading;
     36    $status_text_format = $dstatus_text_format;
     37    $status_value_format = $dstatus_value_format;
     38
     39# Load the cli options
     40    GetOptions('num_recordings|recordings=s' => \$num_recordings,
     41               'live'                        => \$live,
     42               'heading=s'                   => \$heading,
     43               'plain_text'                  => \$plain_text,
     44               'text_format=s'               => \$text_format,
     45               'status_text_format=s'        => \$status_text_format,
     46               'status_value_format=s'       => \$status_value_format,
     47               'usage|help'                  => \$usage
     48              );
     49
     50# Print usage
     51    if ($usage) {
     52        print <<EOF;
     53$0 usage:
     54
     55options:
     56
     57--recordings [number of recordings]
     58
     59    Outputs information on the last [number of recordings] shows recorded by
     60    MythTV.  To output information on all recordings, specify -1.
     61
     62    default:  $dnum_recordings
     63
     64--live
     65    Include information on recent LiveTV recordings.
     66
     67--heading [heading]
     68    Output the [heading] before printing information about recordings.
     69
     70    default:  \'$dheading\'
     71
     72--plain_text
     73    Output information in plain text format (i.e. for inclusion in an e-mail
     74    notification).
     75
     76--text_format [format]
     77    Use the provided [format] to display information on the recordings.  The
     78    format should use the same format specifiers used by mythrename.pl, but
     79    may also use \\r and/or \\n for line breaks.  This option is ignored
     80    if --plain_text is not used.
     81
     82    default:  \'$dtext_format\'
     83
     84--help
     85
     86    Show this help text.
     87
     88EOF
     89        exit;
     90    }
     91
     92# Fix the heading.
     93    if (defined($plain_text)) {
     94        $heading =~ s/\\r/\r/g;
     95        $heading =~ s/\\n/\n/g;
     96    }
     97    else {
     98    # Remove line break format specifiers from heading for status output
     99        $heading =~ s/(\\r|\\n)//g;
     100    }
     101
     102# Connect to mythbackend
     103    my $Myth = new MythTV();
     104
     105# Get the list of recordings
     106    my $count = 0;
     107    my %rows = $Myth->backend_rows('QUERY_RECORDINGS Delete');
     108    our $show;
     109    foreach my $row (@{$rows{'rows'}}) {
     110        last unless (($count < $num_recordings) || ($num_recordings < 0));
     111        $show = new MythTV::Program(@$row);
     112    # Skip LiveTV recordings?
     113        next unless (defined($live) || $show->{'recgroup'} ne 'LiveTV');
     114    # Print the recording information in the desired format
     115        if (defined($plain_text)) {
     116            text_print($count);
     117        }
     118        else {
     119            status_print($count);
     120        }
     121        $count++;
     122    }
     123
     124# Print the output for use in the backend status page.
     125    sub status_print {
     126        my $count = shift;
     127        my $text = $show->format_name($status_text_format, ' ', ' ', 1, 0 ,1);
     128        my $value = $show->format_name($status_value_format, ' ', ' ',
     129                                       1, 0 ,1);
     130        print("$heading<div class=\"schedule\">") if ($count == 0);
     131        print("$text");
     132        print("</div>") if ($count == ($num_recordings - 1));
     133        print("[]:[]recording$count");
     134        print("[]:[]$value\n");
     135    }
     136
     137# Print the output in plain text format
     138    sub text_print {
     139        my $count = shift;
     140        my $text = $show->format_name($text_format, ' ', ' ', 1, 0 ,1);
     141        $text =~ s/\\r/\r/g;
     142        $text =~ s/\\n/\n/g;
     143        print("$heading") if ($count == 0);
     144        print("$text");
     145    }
  • contrib/misc_status_info/myth_upcoming_recordings.pl

    Property changes on: contrib/misc_status_info/myth_recent_recordings.pl
    ___________________________________________________________________
    Name: svn:executable
       + *
    
     
     1#!/usr/bin/perl -w
     2#
     3# Provides notification of upcoming recordings.
     4#
     5# Automatically detects database settings.
     6#
     7
     8# Includes
     9    use DBI;
     10    use Getopt::Long;
     11    use MythTV;
     12
     13# Some variables we'll use here
     14    our ($num_recordings, $heading, $plain_text, $text_format, $usage);
     15    our ($hours, $minutes, $seconds, $no_conflicts_message);
     16    our ($scheduled, $duplicates, $deactivated, $conflicts);
     17    our ($dnum_recordings, $dheading, $dtext_format);
     18    our ($dhours, $dminutes, $dseconds, $dno_conflicts_message);
     19    our ($dscheduled, $dduplicates, $ddeactivated, $dconflicts);
     20    our ($status_text_format, $status_value_format);
     21    our ($dstatus_text_format, $dstatus_value_format);
     22
     23# Default number of recent recordings to show
     24    $dnum_recordings = 5;
     25# Default period in which to show recordings
     26    $dhours          = -1;
     27    $dminutes        = -1;
     28    $dseconds        = -1;
     29# Default recording status types to show
     30    $dscheduled      = 1;
     31    $dduplicates     = 0;
     32    $ddeactivated    = 0;
     33    $dconflicts      = 1;
     34# Default status output heading
     35    $dheading='Upcoming Recordings:\n';
     36# Default format of plain-text output
     37    $dtext_format='%rs\n%n/%j, %g:%i %A - %cc\n%T - %S\n%R\n\n';
     38# Default "no conflicts" message
     39    $dno_conflicts_message='No conflicts.\n';
     40# Default format of status output display text
     41    $dstatus_text_format= '<a href="#">%rs - %n/%j, %g:%i %A -  %cc - '.
     42                          '%T - %S<br />'.
     43                          '<span><strong>%T</strong> %n/%j, %g:%i %A<br />'.
     44                          '<em>%S</em><br /><br />%R<br /></span></a><hr />';
     45# Default format of status output value
     46    $dstatus_value_format = '%n/%j, %g:%i %A - %T - %S';
     47
     48# Provide default values for GetOptions
     49    $num_recordings       = $dnum_recordings;
     50    $hours                = $dhours;
     51    $minutes              = $dminutes;
     52    $seconds              = $dseconds;
     53    $scheduled            = $dscheduled;
     54    $duplicates           = $dduplicates;
     55    $deactivated          = $ddeactivated;
     56    $conflicts            = $dconflicts;
     57    $heading              = $dheading;
     58    $text_format          = $dtext_format;
     59    $no_conflicts_message = $dno_conflicts_message;
     60    $status_text_format   = $dstatus_text_format;
     61    $status_value_format  = $dstatus_value_format;
     62
     63# Load the cli options
     64    GetOptions('num_recordings|recordings=s'         => \$num_recordings,
     65               'hours|o=i'                           => \$hours,
     66               'minutes=i'                           => \$minutes,
     67               'seconds|n=i'                         => \$seconds,
     68               'show_scheduled|_show_scheduled|scheduled|_scheduled|e!'
     69                                                     => \$scheduled,
     70               'show_duplicates|_show_duplicates|duplicates|_duplicates|p!'
     71                                                     => \$duplicates,
     72               'show_deactivated|_show_deactivated|deactivated|_deactivated|v!'
     73                                                     => \$deactivated,
     74               'show_conflicts|_show_conflicts|conflicts|_conflicts!'
     75                                                     => \$conflicts,
     76               'heading=s'                           => \$heading,
     77               'plain_text'                          => \$plain_text,
     78               'text_format=s'                       => \$text_format,
     79               'no_conflicts_message=s'              => \$no_conflicts_message,
     80               'status_text_format=s'                => \$status_text_format,
     81               'status_value_format=s'               => \$status_value_format,
     82               'usage|help'                          => \$usage
     83              );
     84
     85# Print usage
     86    if ($usage) {
     87    # Make default "--show_*" options readable
     88        $dscheduled   = ($dscheduled   ? '--show_scheduled' :
     89                                         '--no_show_scheduled');
     90        $dduplicates  = ($dduplicates  ? '--show_duplicates' :
     91                                         '--no_show_duplicates');
     92        $ddeactivated = ($ddeactivated ? '--show_deactivated' :
     93                                         '--no_show_deactivated');
     94        $dconflicts   = ($dconflicts   ? '--show_conflicts' :
     95                                         '--no_show_conflicts');
     96        print <<EOF;
     97$0 usage:
     98
     99options:
     100
     101--recordings [number of recordings]
     102
     103    Outputs information on the next [number of recordings] shows to be recorded
     104    by MythTV and that match the criteria specified for --scheduled,
     105    --duplicates, --deactivated, and --conflicts.  To output information on all
     106    matching recordings, specify -1.
     107
     108    default:  $dnum_recordings
     109
     110--hours [number of hours]
     111
     112    Outputs information on recordings starting in the next [number of hours]
     113    and that match the criteria specified for --scheduled, --duplicates,
     114    --deactivated, and --conflicts.  This option may be specified in
     115    conjunction with --minutes and --seconds.  To output information on all
     116    matching recordings regardless of start time, specify -1 for --hours,
     117    --minutes, and --seconds.
     118
     119    default:  $dhours
     120
     121--minutes [number of minutes]
     122
     123    Outputs information on recordings starting in the next [number of minutes]
     124    and that match the criteria specified for --scheduled, --duplicates,
     125    --deactivated, and --conflicts.  This option may be specified in
     126    conjunction with --hours and --seconds.  To output information on all
     127    matching recordings regardless of start time, specify -1 for --hours,
     128    --minutes, and --seconds.
     129
     130    default:  $dminutes
     131
     132--seconds [number of seconds]
     133
     134    Outputs information on recordings starting in the next [number of seconds]
     135    and that match the criteria specified for --scheduled, --duplicates,
     136    --deactivated, and --conflicts.  This option may be specified in
     137    conjunction with --hours and --minutes.  To output information on all
     138    matching recordings regardless of start time, specify -1 for --hours,
     139    --minutes, and --seconds.
     140
     141    default:  $dseconds
     142
     143--show_scheduled|--no_show_scheduled
     144
     145    Outputs information about scheduled recordings.  Scheduled recordings are
     146    those that MythTV plans to actually record.
     147
     148    default:  $dscheduled
     149
     150--show_duplicates|--no_show_duplicates
     151
     152    Outputs information about duplicate recordings.  Duplicate recordings are
     153    those that will not be recorded because of the specified duplicate matching
     154    policy for the rule.
     155
     156    default:  $dduplicates
     157
     158--show_deactivated|--no_show_deactivated
     159
     160    Outputs information about deactivated recordings.  Deactivated recordings
     161    are those that MythTV will not record because the schedule is inactive,
     162    because the showing was set to never record, because the show is being
     163    recorded in an earlier or later showing, because there are too many
     164    recordings or not enough disk space to allow the recording, or because
     165    the show you\'ve specified for recording is not listed in the timeslot
     166    specified.
     167
     168    default:  $ddeactivated
     169
     170--show_conflicts|--no_show_conflicts
     171
     172    Outputs information about conflicts (those shows that MythTV cannot record
     173    because of other higher-priority scheduled recordings).
     174
     175    default:  $dconflicts
     176
     177--heading [heading]
     178    Output the [heading] before printing information about recordings.
     179
     180    default:  \'$dheading\'
     181
     182--plain_text
     183    Output information in plain text format (i.e. for inclusion in an e-mail
     184    notification).
     185
     186--text_format [format]
     187    Use the provided [format] to display information on the recordings.  The
     188    format should use the same format specifiers used by mythrename.pl, but
     189    may also use \\r and/or \\n for line breaks and %rs for recording status.
     190    This option is ignored if --plain_text is not used.
     191
     192    default:  \'$dtext_format\'
     193
     194--no_conflicts_message [message]
     195    Use the provided [message] to specify there are no conflicts.  This option
     196    is used when only information about conflicts is requested and there are
     197    no conflicts.  I.e. it is only used with the combination of show_*
     198    options --show_conflicts, --no_show_scheduled, --no_show_deactivated,
     199    and --no_show_duplicates .
     200
     201    default:  \'$dno_conflicts_message\'
     202
     203--help
     204
     205    Show this help text.
     206
     207EOF
     208        exit;
     209    }
     210
     211# Determine the period of interest
     212    my $now = time();
     213    my $start_before = $now;
     214    $start_before = $start_before + ($hours * 3600) if ($hours > 0);
     215    $start_before = $start_before + ($minutes * 60) if ($minutes > 0);
     216    $start_before = $start_before + $seconds if ($seconds > 0);
     217    $start_before = 0 if (!($start_before > $now));
     218
     219# Fix the heading.
     220    if (defined($plain_text)) {
     221        $heading =~ s/\\r/\r/g;
     222        $heading =~ s/\\n/\n/g;
     223    }
     224    else {
     225    # Remove line break format specifiers from heading for status output
     226        $heading =~ s/(\\r|\\n)//g;
     227    }
     228
     229# Connect to mythbackend
     230    my $Myth = new MythTV();
     231
     232# Get the list of recordings
     233    my $count = 0;
     234    my %rows = $Myth->backend_rows('QUERY_GETALLPENDING', 2);
     235    my $has_conflicts = $rows{'offset'}[0];
     236    if ((!$has_conflicts) &&
     237        (($conflicts) &&
     238         (!(($scheduled) || ($duplicates) || ($deactivated))))) {
     239        $no_conflicts_message =~ s/\\r/\r/g;
     240        $no_conflicts_message =~ s/\\n/\n/g;
     241        print "$no_conflicts_message";
     242        exit 0;
     243    }
     244    my $num_scheduled = $rows{'offset'}[1];
     245    our $show;
     246    foreach my $row (@{$rows{'rows'}}) {
     247        last unless (($count < $num_recordings) || ($num_recordings < 0));
     248        $show = new MythTV::Program(@$row);
     249        last if (($start_before) && ($show->{'recstartts'} > $start_before));
     250        next if ((!$scheduled) && (is_scheduled($show->{'recstatus'})));
     251        next if ((!$duplicates) && (is_duplicate($show->{'recstatus'})));
     252        next if ((!$deactivated) && (is_deactivated($show->{'recstatus'})));
     253        next if ((!$conflicts) && (is_conflict($show->{'recstatus'})));
     254
     255    # Print the recording information in the desired format
     256        if (defined($plain_text)) {
     257            text_print($count);
     258        }
     259        else {
     260            status_print($count);
     261        }
     262        $count++;
     263    }
     264
     265# Returns true if the show is scheduled to record
     266    sub is_scheduled {
     267        my $recstatus = (shift() or 0);
     268        return (($MythTV::recstatus_willrecord == $recstatus) ||
     269                ($MythTV::recstatus_recorded == $recstatus) ||
     270                ($MythTV::recstatus_recording == $recstatus));
     271    }
     272
     273# Returns true if the show is a duplicate
     274    sub is_duplicate {
     275        my $recstatus = (shift() or 0);
     276        return (($MythTV::recstatus_repeat == $recstatus) ||
     277                ($MythTV::recstatus_previousrecording == $recstatus) ||
     278                ($MythTV::recstatus_currentrecording == $recstatus));
     279    }
     280
     281# Returns true if the recording is deactivated
     282    sub is_deactivated {
     283        my $recstatus = (shift() or 0);
     284        return (($MythTV::recstatus_inactive == $recstatus) ||
     285                ($MythTV::recstatus_toomanyrecordings == $recstatus) ||
     286                ($MythTV::recstatus_cancelled == $recstatus) ||
     287                ($MythTV::recstatus_deleted == $recstatus) ||
     288                ($MythTV::recstatus_aborted == $recstatus) ||
     289                ($MythTV::recstatus_notlisted == $recstatus) ||
     290                ($MythTV::recstatus_dontrecord == $recstatus) ||
     291                ($MythTV::recstatus_lowdiskspace == $recstatus) ||
     292                ($MythTV::recstatus_tunerbusy == $recstatus) ||
     293                ($MythTV::recstatus_neverrecord == $recstatus) ||
     294                ($MythTV::recstatus_earliershowing == $recstatus) ||
     295                ($MythTV::recstatus_latershowing == $recstatus));
     296    }
     297
     298# Returns true if the show cannot be recorded due to a conflict
     299    sub is_conflict {
     300        my $recstatus = (shift() or 0);
     301        return ($MythTV::recstatus_conflict == $recstatus);
     302    }
     303
     304# Print the output for use in the backend status page.
     305    sub status_print {
     306        my $count = shift;
     307        my $text = $show->format_name($status_text_format, ' ', ' ', 1, 0 ,1);
     308        $text =~ s/%rs/$MythTV::RecStatus_Types{$show->{'recstatus'}}/g;
     309        my $value = $show->format_name($status_value_format, ' ', ' ',
     310                                       1, 0 ,1);
     311        $value =~ s/%rs/$MythTV::RecStatus_Types{$show->{'recstatus'}}/g;
     312        print("$heading<div class=\"schedule\">") if ($count == 0);
     313        print("$text");
     314        print("</div>") if ($count == ($num_recordings - 1));
     315        print("[]:[]recording$count");
     316        print("[]:[]$value\n");
     317    }
     318
     319# Print the output in plain text format
     320    sub text_print {
     321        my $count = shift;
     322        my $text = $show->format_name($text_format, ' ', ' ', 1, 0 ,1);
     323        $text =~ s/%rs/$MythTV::RecStatus_Types{$show->{'recstatus'}}/g;
     324        $text =~ s/\\r/\r/g;
     325        $text =~ s/\\n/\n/g;
     326        print("$heading") if ($count == 0);
     327        print("$text");
     328    }
     329
  • contrib/misc_status_info/myth_sensors.sh

    Property changes on: contrib/misc_status_info/myth_upcoming_recordings.pl
    ___________________________________________________________________
    Name: svn:executable
       + *
    
     
     1#!/bin/bash
     2#
     3# sensors.sh
     4# Retrieves sensors output and formats it for inclusion in the MythTV backend
     5# status page.
     6
     7# The following line outputs information to include the CPU temperature
     8# information in the backend status page.  Though the sensors output includes
     9# the °C unit marker, it is stripped out of the data before being placed in the
     10# output page, so the display value includes a proper HTML entity.
     11
     12#sensors | awk '/CPU Temp/ { printf "Current CPU Temperature: %s &#8451;.[]:[]temperature-CPU[]:[]%s\n", $3, $3 };'
     13
     14# The following lines output CPU and Motherboard temperature and CPU and Case
     15# fan speed information.  Modify the patterns (i.e. /CPU Temp/) to match the
     16# sensors output lines containing the data you want to grab (i.e. /Core0
     17# Temp/).  Continue adding lines to the awk program as desired to incude
     18# additional information.
     19
     20sensors | awk '
     21/CPU Temp/ {
     22  printf "Current CPU Temperature: %s &#8451;.[]:[]temperature-CPU[]:[]%s\n", \
     23         $3, $3
     24};
     25/M\/B Temp/ {
     26  printf \
     27  "Current Motherboard Temperature: %s &#8451;.[]:[]temperature-MB[]:[]%s\n", \
     28    $3, $3
     29};
     30/CPU Fan/ {
     31  printf "Current CPU Fan Speed: %s.[]:[]fan-CPU[]:[]%s\n", $3, $3
     32};
     33/Case Fan/ {
     34  printf "Current Case Fan Speed: %s.[]:[]fan-case[]:[]%s\n", $3, $3
     35};
     36' | sort
     37
     38# With appropriate authentication in place (i.e. using SSH Certificate
     39# Authentication), you may also retrieve sensors data from remote system (i.e.
     40# slave backends, remote frontends, etc.).  Do so with commands of the format
     41# below (provide an appropriate hostname in place of "slave" (3 places) and
     42# replace the awk script with one providing the desired information as shown
     43# above):
     44
     45#ssh -q slave sensors | awk '/CPU Temp/ { printf "Current CPU Temperature (slave): %s &#8451;.[]:[]temperature-CPU-slave[]:[]%s\n", $3, $3 };'
     46
     47# Alternatively, this information could be retrieved from an appropriate
     48# monitoring program (monit, mrtg) or by using SNMP, depending on the system
     49# and network configuration.