]> git.etc.gen.nz Git - mythtv-status.git/commitdiff
Allow warn status only for encoders for errors - enable with --no-encoder-warn-non...
authorAndrew Ruthven <andrew@etc.gen.nz>
Sat, 8 Dec 2018 13:25:03 +0000 (02:25 +1300)
committerAndrew Ruthven <andrew@etc.gen.nz>
Sat, 8 Dec 2018 13:25:03 +0000 (02:25 +1300)
bin/mythtv-status

index 3a1ed8633822f86e0c7bffec4e191a7c5e58d5b1..6374d388b568ac4b58cd64555d563227bf9d7234 100755 (executable)
@@ -58,6 +58,7 @@ $c->{'episode'} ||= 0;
 $c->{'description'} ||= 0;
 $c->{'encoder_details'}     ||= 0;
 $c->{'encoder_skip_idle'}   //= 1;
+$c->{'encoder_warn_non_idle'} //= 1;
 $c->{'email_only_on_alert'} ||= 0;
 my $help = 0;
 my $verbose = 0;
@@ -129,6 +130,7 @@ GetOptions(
   'auto-expire-count=i'   => \$c->{'auto_expire_count'},
   'recording-in-warn=i'   => \$c->{'recording_in_warn'},
   'encoder-skip-idle!'    => \$c->{'encoder_skip_idle'},
+  'encoder-warn-non-idle!' => \$c->{'encoder_warn_non_idle'},
   'oneliner-bullets!'     => \$c->{'oneliner_bullets'},
 
   'status!'               => \$c->{'display'}{'Status'},
@@ -272,20 +274,56 @@ my @blocks = (
     'xpath' => "//Status/Encoders/Encoder",
     'protocol_version' => [ "<= 43" ],
     'attrs' => [ qw/hostname id state connected/ ],
-    'template' => "__hostname__ (__id__) - __state____connected__",
+    'template' => "__hostname__ (__id__) - __state_colour____state____state_normal____connected__",
     'rewrite' => {
       '/connected/' => { '1' => '', '0' => "${warn}(Disconnected)${warn_to_normal}" },
       '/state/' => {
-        '^0$' => "${safe}Idle${safe_to_normal}",
-        '^1$' => "${warn}Watching LiveTV${warn_to_normal}",
-        '^2$' => "${warn}Watching Pre-recorded${warn_to_normal}",
-        '^3$' => "${warn}Watching Recording${warn_to_normal}",
-        '^4$' => "${warn}Recording${warn_to_normal}",
+        '^0$' => "Idle",
+        '^1$' => "Watching LiveTV",
+        '^2$' => "Watching Pre-recorded",
+        '^3$' => "Watching Recording",
+        '^4$' => "Recording",
       },
     },
     'filter' => {
       'state' => sub { return $c->{'encoder_skip_idle'} && $_[0] == 0 },
     },
+    'subs' => {
+      'state_colour' => sub {
+        if ($c->{'encoder_warn_non_idle'}) {
+            if ($_[0]->{'state'} eq '0') {
+                return $safe;
+            } else {
+                return $warn;
+            }
+        } else {
+            if ($_[0]->{'state'} eq '0') {
+                return $safe;
+            } elsif ($_[0]->{'state'} eq '-1') {
+                return $warn;
+            } else {
+                return '';
+            }
+        }
+      },
+      'state_normal' => sub {
+        if ($c->{'encoder_warn_non_idle'}) {
+            if ($_[0]->{'state'} eq '0') {
+                return $safe_to_normal;
+            } else {
+                return $warn_to_normal;
+            }
+        } else {
+            if ($_[0]->{'state'} eq '0') {
+                return $safe_to_normal;
+            } elsif ($_[0]->{'state'} eq '-1') {
+                return $warn_to_normal;
+            } else {
+                return '';
+            }
+        }
+      },
+    },
   },
 
   # Info about the encoders after TV OSD Declutter (Changeset 20037).
@@ -295,7 +333,7 @@ my @blocks = (
     'xpath' => "//Status/Encoders/Encoder",
     'protocol_version' => [ ">= 44", "< 58" ],
     'attrs' => [ qw/hostname id state connected/ ],
-    'template' => "__hostname__ (__id__) - __state____connected__",
+    'template' => "__hostname__ (__id__) - __state_colour____state____state_normal____connected__",
     'rewrite' => {
       '/connected/' => { '1' => '', '0' => "${warn}(Disconnected)${warn_to_normal}" },
       '/state/' => {
@@ -312,6 +350,42 @@ my @blocks = (
     'filter' => {
       'state' => sub { return $c->{'encoder_skip_idle'} && $_[0] == 0 },
     },
+    'subs' => {
+      'state_colour' => sub {
+        if ($c->{'encoder_warn_non_idle'}) {
+            if ($_[0]->{'state'} eq '0') {
+                return $safe;
+            } else {
+                return $warn;
+            }
+        } else {
+            if ($_[0]->{'state'} eq '0') {
+                return $safe;
+            } elsif ($_[0]->{'state'} eq '-1') {
+                return $warn;
+            } else {
+                return '';
+            }
+        }
+      },
+      'state_normal' => sub {
+        if ($c->{'encoder_warn_non_idle'}) {
+            if ($_[0]->{'state'} eq '0') {
+                return $safe_to_normal;
+            } else {
+                return $warn_to_normal;
+            }
+        } else {
+            if ($_[0]->{'state'} eq '0') {
+                return $safe_to_normal;
+            } elsif ($_[0]->{'state'} eq '-1') {
+                return $warn_to_normal;
+            } else {
+                return '';
+            }
+        }
+      },
+    },
   },
 
   # Info about the encoders after adding Blu-ray (Changeset 25058).
@@ -323,7 +397,7 @@ my @blocks = (
     'xpath' => "//Status/Encoders/Encoder",
     'protocol_version' => [ ">= 58" ],
     'attrs' => [ qw/hostname id state devlabel connected/ ],
-    'template' => "__hostname__ (__id____devtype__) - __state____connected__",
+    'template' => "__hostname__ (__id____devtype__) - __state_colour____state____state_normal____connected__",
     'rewrite' => {
       '/connected/' => { '1' => '', '0' => "${warn}(Disconnected)${warn_to_normal}" },
       '/state/' => {
@@ -346,6 +420,41 @@ my @blocks = (
         if    ($_[0]->{'devlabel'} =~ /\[ (.+) :/)   { ", $1" }
         else { '' }
       },
+      'state_colour' => sub {
+        if ($c->{'encoder_warn_non_idle'}) {
+          warn "non idle";
+            if ($_[0]->{'state'} eq '0') {
+                return $safe;
+            } else {
+                return $warn;
+            }
+        } else {
+            if ($_[0]->{'state'} eq '0') {
+                return $safe;
+            } elsif ($_[0]->{'state'} eq '-1') {
+                return $warn;
+            } else {
+                return '';
+            }
+        }
+      },
+      'state_normal' => sub {
+        if ($c->{'encoder_warn_non_idle'}) {
+            if ($_[0]->{'state'} eq '0') {
+                return $safe_to_normal;
+            } else {
+                return $warn_to_normal;
+            }
+        } else {
+            if ($_[0]->{'state'} eq '0') {
+                return $safe_to_normal;
+            } elsif ($_[0]->{'state'} eq '-1') {
+                return $warn_to_normal;
+            } else {
+                return '';
+            }
+        }
+      },
     },
   },
 
@@ -1416,6 +1525,12 @@ Display the input ID and channel name against the recording details.
 
 Suppress displaying idle encoders in the Encoders block.
 
+=item B<--encoder-warn-non-idle>
+
+Display warnings if an encoder is not idle. This is the default, it allows
+you to know if an encoder or the MythTV system is busy. To disable, use
+B<--no-encoder-warn-non-idle>.
+
 =item B<-e, --episode>
 
 Display the episode (subtitle) for the scheduled recordings.