From: Andrew Ruthven Date: Thu, 6 Dec 2018 22:27:30 +0000 (+1300) Subject: Add a new option --highlight which uses asterisks to highlight warnings. X-Git-Tag: 1.0.0~46 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f342393e93e83525ac95810962b9ffa35b0a124a;p=mythtv-status.git Add a new option --highlight which uses asterisks to highlight warnings. --- diff --git a/bin/mythtv-status b/bin/mythtv-status index 5b2ac7c..8798b14 100755 --- a/bin/mythtv-status +++ b/bin/mythtv-status @@ -53,6 +53,7 @@ if (eval("{ local \$SIG{__DIE__}; require Config::Auto; }")) { $c->{'host'} ||= "localhost"; $c->{'port'} ||= "6544"; $c->{'colour'} ||= 0; +$c->{'highlight'} ||= -1; $c->{'episode'} ||= 0; $c->{'description'} ||= 0; $c->{'encoder_details'} ||= 0; @@ -117,6 +118,7 @@ GetOptions( 'e|episode!' => \$c->{'episode'}, 'encoder-details!' => \$c->{'encoder_details'}, 'h|host=s' => \$c->{'host'}, + 'highlight!' => \$c->{'highlight'}, 'p|port=i' => \$c->{'port'}, 'v|version' => \&print_version, 'email=s@' => \@{ $c->{'email'} }, @@ -158,25 +160,37 @@ $0 = "mythtv-status - parent"; # Get the email address into a format we can use. @{ $c->{'email'} } = split(',', join(',', @{ $c->{'email'} })); -# Default to not showing some blocks if we're sending email, but let the -# user override us. +# Default settings for emails but let the user override us. if (scalar(@{ $c->{'email'} }) > 0) { + # Disable these blocks for my $block ('Encoders', 'Recording Now', 'Next Recording In') { if (! defined $c->{'display'}{$block}) { $c->{'display'}{$block} = 0; } } + + # Enable highlight + if ($c->{'highlight'} == -1) { + $c->{'highlight'} = 1; + } } -# Possibly use some colour, but not in emails. +# Possibly use some colour or highlighting, but not no colour in emails. my $safe = ''; -my $warning = ''; -my $normal = ''; +my $warn = ''; +my $warn_to_normal = ''; +my $safe_to_normal = ''; if ($c->{'colour'} && scalar(@{ $c->{'email'} }) == 0) { - $safe = "\033[0;32m"; - $warning = "\033[1;31m"; - $normal = "\033[0m"; + $safe = "\033[0;32m"; + $warn = "\033[1;31m"; + $safe_to_normal = "\033[0m"; + $warn_to_normal = "\033[0m"; +} + +if ($c->{'highlight'} > 0) { + $warn .= '*'; + $warn_to_normal = "*$warn_to_normal"; } # Is a warning present? @@ -259,13 +273,13 @@ my @blocks = ( 'attrs' => [ qw/hostname id state connected/ ], 'template' => "__hostname__ (__id__) - __state____connected__", 'rewrite' => { - '/connected/' => { '1' => '', '0' => "${warning}(Disconnected)${normal}" }, + '/connected/' => { '1' => '', '0' => "${warn}(Disconnected)${warn_to_normal}" }, '/state/' => { - '^0$' => "${safe}Idle${normal}", - '^1$' => "${warning}Watching LiveTV${normal}", - '^2$' => "${warning}Watching Pre-recorded${normal}", - '^3$' => "${warning}Watching Recording${normal}", - '^4$' => "${warning}Recording${normal}", + '^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}", }, }, 'filter' => { @@ -282,16 +296,16 @@ my @blocks = ( 'attrs' => [ qw/hostname id state connected/ ], 'template' => "__hostname__ (__id__) - __state____connected__", 'rewrite' => { - '/connected/' => { '1' => '', '0' => "${warning}(Disconnected)${normal}" }, + '/connected/' => { '1' => '', '0' => "${warn}(Disconnected)${warn_to_normal}" }, '/state/' => { - '^-1$' => "${warning}Error${normal}", - '^0$' => "${safe}Idle${normal}", - '^1$' => "${warning}Watching LiveTV${normal}", - '^2$' => "${warning}Watching Pre-recorded${normal}", - '^3$' => "${warning}Watching DVD${normal}", - '^4$' => "${warning}Watching Video${normal}", - '^5$' => "${warning}Watching Recording${normal}", - '^6$' => "${warning}Recording${normal}", + '^-1$' => "${warn}Error${warn_to_normal}", + '^0$' => "${safe}Idle${safe_to_normal}", + '^1$' => "${warn}Watching LiveTV${warn_to_normal}", + '^2$' => "${warn}Watching Pre-recorded${warn_to_normal}", + '^3$' => "${warn}Watching DVD${warn_to_normal}", + '^4$' => "${warn}Watching Video${warn_to_normal}", + '^5$' => "${warn}Watching Recording${warn_to_normal}", + '^6$' => "${warn}Recording${warn_to_normal}", }, }, 'filter' => { @@ -310,17 +324,17 @@ my @blocks = ( 'attrs' => [ qw/hostname id state devlabel connected/ ], 'template' => "__hostname__ (__id____devtype__) - __state____connected__", 'rewrite' => { - '/connected/' => { '1' => '', '0' => "${warning}(Disconnected)${normal}" }, + '/connected/' => { '1' => '', '0' => "${warn}(Disconnected)${warn_to_normal}" }, '/state/' => { - '^-1$' => "${warning}Error${normal}", - '^0$' => "${safe}Idle${normal}", - '^1$' => "${warning}Watching LiveTV${normal}", - '^2$' => "${warning}Watching Pre-recorded${normal}", - '^3$' => "${warning}Watching DVD${normal}", - '^4$' => "${warning}Watching Blu-ray${normal}", - '^5$' => "${warning}Watching Video${normal}", - '^6$' => "${warning}Watching Recording${normal}", - '^7$' => "${warning}Recording${normal}", + '^-1$' => "${warn}Error${warn_to_normal}", + '^0$' => "${safe}Idle${safe_to_normal}", + '^1$' => "${warn}Watching LiveTV${warn_to_normal}", + '^2$' => "${warn}Watching Pre-recorded${warn_to_normal}", + '^3$' => "${warn}Watching DVD${warn_to_normal}", + '^4$' => "${warn}Watching Blu-ray${warn_to_normal}", + '^5$' => "${warn}Watching Video${warn_to_normal}", + '^6$' => "${warn}Watching Recording${warn_to_normal}", + '^7$' => "${warn}Recording${warn_to_normal}", }, }, 'filter' => { @@ -518,7 +532,7 @@ my @blocks = ( if ($seconds <= $c->{'recording_in_warn'}) { $warn_present ||= 1; - $str = "$warning$str$normal"; + $str = "$warn$str$warn_to_normal"; } return $str; @@ -556,18 +570,18 @@ my @blocks = ( '&guideDays' => sub { if ($_[0] <= $c->{'guide_days_warn'}) { $warn_present ||= 1; - return "$warning$_[0]$normal"; + return "$warn$_[0]$warn_to_normal"; } else { - return "$safe$_[0]$normal"; + return "$safe$_[0]$safe_to_normal"; } }, '/guideThru/' => { 'T\d+:\d+:\d+' => ' ' }, '&guideThru' => sub { if ($_[1]->{'guideDays'} <= $c->{'guide_days_warn'}) { $warn_present ||= 1; - return "$warning$_[0]$normal"; + return "$warn$_[0]$warn_to_normal"; } else { - return "$safe$_[0]$normal"; + return "$safe$_[0]$safe_to_normal"; } }, }, @@ -578,7 +592,7 @@ my @blocks = ( 'format' => 'one line', 'type' => 'xpath', 'xpath' => '//Status/MachineInfo/Guide[@status=""]', - 'template' => "${warning}No guide data!${normal}", + 'template' => "${warn}No guide data!${warn_to_normal}", }, ); @@ -1134,9 +1148,9 @@ sub calc_disk_space_percentage { if ($percent >= $c->{'disk_space_warn'}) { $exit_value ||= 1; push @alerts, "DISK SPACE"; - return "$warning$percent\%$normal"; + return "$warn$percent\%$warn_to_normal"; } else { - return "$safe$percent\%$normal"; + return "$safe$percent\%$safe_to_normal"; } } @@ -1413,6 +1427,8 @@ the email. To turn the additional blocks on you can use B<--encoders>, B<--recording-now> and/or B<--next-recording>. +By default highlight is turned on, to disable it use B<--nohighlight>. + =item B<--email-only-on-alert> Only send an email out (if --email is present) if there is an alert @@ -1441,6 +1457,11 @@ this level. Default is 2 days. The host to check, defaults to localhost. +=item B<--highlight> + +Surround any items that are considered a warning with asterisks. This helps +to highlight an issue if colour mode is disabled. + =item B<--nostatus>, B<--noencoders>, B<--norecording-now>, B<--noscheduled-recordings>, B<--noschedule-conflicts>, B<--nonext-recording>, B<--nototal-disk-space>, B<--nodisk-space>, B<--noguide-data>, B<--noauto-expire> Suppress displaying blocks of the output if they would normally be displayed.