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

File mythtv-miscellaneous_status_info-example_scripts-20071005.patch, 6.0 KB (added by sphery <mtdean@…>, 12 years ago)
  • 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, $plain_text, $usage);
     15
     16# Default number of recent recordings to show
     17    $dnum_recordings = 5;
     18
     19# Provide default values for GetOptions
     20    $num_recordings = $dnum_recordings;
     21
     22# Load the cli options
     23    GetOptions('num_recordings|recordings|n=s' => \$num_recordings,
     24               'live'                          => \$live,
     25               'plain_text|plain|text'         => \$plain_text,
     26               'usage|help|h'                  => \$usage
     27              );
     28
     29# Print usage
     30    if ($usage) {
     31        print <<EOF;
     32$0 usage:
     33
     34options:
     35
     36--recordings [number of recordings]
     37
     38    Outputs information on the last [number of recordings] shows recorded by
     39    MythTV.  To output information on all recordings, specify -1.
     40
     41    default:  $dnum_recordings
     42
     43--text
     44    Output information in plain text format (i.e. for inclusion in an e-mail
     45    notification).
     46
     47--live
     48    Include information on recent LiveTV recordings.
     49
     50--help
     51
     52    Show this help text.
     53
     54EOF
     55        exit;
     56    }
     57
     58# Connect to mythbackend
     59    my $Myth = new MythTV();
     60
     61# Get the list of recordings
     62    my $count = 0;
     63    my %rows = $Myth->backend_rows('QUERY_RECORDINGS Delete');
     64    our $show;
     65    foreach my $row (@{$rows{'rows'}}) {
     66        last unless (($count < $num_recordings) || ($num_recordings < 0));
     67        $show = new MythTV::Program(@$row);
     68    # Skip LiveTV recordings?
     69        next unless (defined($live) || $show->{'recgroup'} ne 'LiveTV');
     70    # Format the starttime
     71    # Since format_name() formats for filenames, use "placeholders" for
     72    # characters that are illegal on some filesystems.
     73        my $starttime = $show->format_name('%nslash%j, %gcolon%i %A');
     74        $starttime =~ s/slash/\//;
     75        $starttime =~ s/colon/:/;
     76        if (defined($plain_text)) {
     77            text_print($starttime);
     78        }
     79        else {
     80            status_print($starttime, $count);
     81        }
     82        $count++;
     83    }
     84
     85# Print the output for use in the backend status page.
     86    sub status_print {
     87        my $starttime = shift;
     88        my $count = shift;
     89        print("Recent Recordings:<div class=\"schedule\">") if ($count == 0);
     90        print("<a href=\"#\">$starttime - $show->{'callsign'} - ");
     91        print("$show->{'title'} - $show->{'subtitle'}<br />");
     92        print("<span><strong>$show->{'title'}</strong> $starttime<br />");
     93        print("<em>$show->{'subtitle'}</em><br /><br />");
     94        print("$show->{'description'}<br /></span></a><hr />");
     95        print("</div>") if ($count == ($num_recordings - 1));
     96        print("[]:[]recording$count");
     97        print("[]:[]$starttime - $show->{'title'} - $show->{'subtitle'}\n");
     98    }
     99
     100# Print the output in plain text format
     101    sub text_print {
     102        my $starttime = shift;
     103        print("$starttime - $show->{'callsign'} - $show->{'title'} - ");
     104        print("$show->{'subtitle'}\r\n$show->{'description'}\r\n\r\n");
     105    }
  • contrib/misc_status_info/myth_sensors.sh

    Property changes on: contrib/misc_status_info/myth_recent_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.