From 780e067604f24b0c097450dda529b7582bcb104c Mon Sep 17 00:00:00 2001 From: Andreas Bachlechner <62039342+bachandi@users.noreply.github.com> Date: Thu, 24 Feb 2022 10:08:44 +0100 Subject: [PATCH] Add ignore_error_output option to nut.pm This option, when enabled, suppresses error output from upsc. --- lib/nut.pm | 14 ++++++++++++-- man/man5/monitorix.conf.5 | 7 +++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/nut.pm b/lib/nut.pm index 2d7a57c..e34f397 100644 --- a/lib/nut.pm +++ b/lib/nut.pm @@ -148,6 +148,7 @@ sub nut_update { my $rrdata = "N"; my $use_nan_for_missing_data = lc($nut->{use_nan_for_missing_data} || "") eq "y" ? 1 : 0; + my $ignore_error_output = lc($nut->{ignore_error_output} || "") eq "y" ? 1 : 0; my $e = 0; foreach my $ups (my @nl = split(',', $nut->{list})) { @@ -176,7 +177,11 @@ sub nut_update { my $val05 = $default_value; my $data; - if(open(PIPE, "upsc $ups |")) { + my $upsc_cmd = "upsc $ups"; + if ($ignore_error_output) { + $upsc_cmd .= " 2>/dev/null"; + } + if(open(PIPE, "$upsc_cmd |")) { while() { $data .= $_; } close(PIPE); } @@ -304,6 +309,7 @@ sub nut_cgi { } my $gap_on_all_nan = lc($nut->{gap_on_all_nan} || "") eq "y" ? 1 : 0; + my $ignore_error_output = lc($nut->{ignore_error_output} || "") eq "y" ? 1 : 0; # text mode # @@ -394,7 +400,11 @@ sub nut_cgi { foreach my $ups (my @nl = split(',', $nut->{list})) { my $data; - if(open(PIPE, "upsc $ups |")) { + my $upsc_cmd = "upsc $ups"; + if ($ignore_error_output) { + $upsc_cmd .= " 2>/dev/null"; + } + if(open(PIPE, "$upsc_cmd |")) { while() { $data .= $_; } close(PIPE); } diff --git a/man/man5/monitorix.conf.5 b/man/man5/monitorix.conf.5 index 269bb86..9dec156 100644 --- a/man/man5/monitorix.conf.5 +++ b/man/man5/monitorix.conf.5 @@ -4213,6 +4213,13 @@ This option, when enabled via \fIy\fP, combined with the \fIshow_gaps\fP option .P Default value: \fIn\fP .RE +.P +.BI ignore_error_output +.RS +This option, when enabled via \fIy\fP, suppresses error output from upsc. +.P +Default value: \fIn\fP +.RE .SS Wowza Media Server (wowza.pm) This graph is able to monitor an unlimited number of Wowza servers. .P