(plugin) hardware::ups::standard::rfc1628::snmp - mode alarms add test-status + mode output-lines add frequency (#4556)

This commit is contained in:
qgarnier 2023-07-21 15:18:55 +02:00 committed by GitHub
parent f99ad76662
commit e557d62e6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 141 additions and 29 deletions

View File

@ -194,4 +194,4 @@ Default: ^(?!(UtilityPowerRestored|NoticeCondition|ReturnFromLowBattery|AlarmEnt
=back
=cut

View File

@ -24,12 +24,24 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
use centreon::plugins::misc;
sub custom_test_status_output {
my ($self, %options) = @_;
return sprintf(
'test status: %s [detail: %s]',
$self->{result_values}->{status},
$self->{result_values}->{detail}
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 }
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
@ -40,6 +52,18 @@ sub set_counters {
{ template => '%s', min => 0 }
]
}
},
{
label => 'test-status',
type => 2,
warning_default => '%{status} =~ /doneWarning|aborted/',
critical_default => '%{status} =~ /doneError/',
set => {
key_values => [ { name => 'status' }, { name => 'detail' } ],
closure_custom_output => $self->can('custom_test_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
]
}
@ -49,23 +73,84 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {});
$options{options}->add_options(arguments => {
'display-alarms' => { name => 'display_alarms' }
});
return $self;
}
my $map_test = {
1 => 'donePass', 2 => 'doneWarning', 3 => 'doneError',
4 => 'aborted', 5 => 'inProgress', 6 => 'noTestsInitiated'
};
my $map_alarm_desc = {
'.1.3.6.1.2.1.33.1.6.3.1' => 'batteryBad',
'.1.3.6.1.2.1.33.1.6.3.2' => 'onBattery',
'.1.3.6.1.2.1.33.1.6.3.3' => 'lowBattery',
'.1.3.6.1.2.1.33.1.6.3.4' => 'depletedBattery',
'.1.3.6.1.2.1.33.1.6.3.5' => 'tempBad',
'.1.3.6.1.2.1.33.1.6.3.6' => 'inputBad',
'.1.3.6.1.2.1.33.1.6.3.7' => 'outputBad',
'.1.3.6.1.2.1.33.1.6.3.8' => 'outputOverload',
'.1.3.6.1.2.1.33.1.6.3.9' => 'onBypass',
'.1.3.6.1.2.1.33.1.6.3.10' => 'bypassBad',
'.1.3.6.1.2.1.33.1.6.3.11' => 'outputOffAsRequested',
'.1.3.6.1.2.1.33.1.6.3.12' => 'upsOffAsRequested',
'.1.3.6.1.2.1.33.1.6.3.13' => 'chargerFailed',
'.1.3.6.1.2.1.33.1.6.3.14' => 'upsOutputOff',
'.1.3.6.1.2.1.33.1.6.3.15' => 'upsSystemOff',
'.1.3.6.1.2.1.33.1.6.3.16' => 'fanFailure',
'.1.3.6.1.2.1.33.1.6.3.17' => 'fuseFailure',
'.1.3.6.1.2.1.33.1.6.3.18' => 'generalFault',
'.1.3.6.1.2.1.33.1.6.3.19' => 'diagnosticTestFailed',
'.1.3.6.1.2.1.33.1.6.3.20' => 'communicationsLost',
'.1.3.6.1.2.1.33.1.6.3.21' => 'awaitingPower',
'.1.3.6.1.2.1.33.1.6.3.22' => 'shutdownPending',
'.1.3.6.1.2.1.33.1.6.3.23' => 'shutdownImminent',
'.1.3.6.1.2.1.33.1.6.3.24' => 'testInProgress'
};
sub manage_selection {
my ($self, %options) = @_;
my $oid_upsAlarmsPresent = '.1.3.6.1.2.1.33.1.6.1.0';
my $oid_upsTestResultsSummary = '.1.3.6.1.2.1.33.1.7.3.0';
my $oid_upsTestResultsDetail = '.1.3.6.1.2.1.33.1.7.4.0';
my $snmp_result = $options{snmp}->get_leef(
oids => [ $oid_upsAlarmsPresent ],
oids => [ $oid_upsAlarmsPresent, $oid_upsTestResultsSummary, $oid_upsTestResultsDetail ],
nothing_quit => 1
);
$self->{global} = {
current_alarms => $snmp_result->{$oid_upsAlarmsPresent}
};
if (defined($snmp_result->{$oid_upsTestResultsSummary}) && defined($map_test->{ $snmp_result->{$oid_upsTestResultsSummary} })) {
$self->{global}->{status} = $map_test->{ $snmp_result->{$oid_upsTestResultsSummary} };
$self->{global}->{detail} = defined($snmp_result->{$oid_upsTestResultsDetail}) && $snmp_result->{$oid_upsTestResultsDetail} ne '' ?
$snmp_result->{$oid_upsTestResultsDetail} : '-';
}
if ($snmp_result->{$oid_upsAlarmsPresent} > 0) {
my $oid_upsAlarmEntry = '.1.3.6.1.2.1.33.1.6.2.1';
my $oid_upsAlarmDescr = '.1.3.6.1.2.1.33.1.6.2.1.2';
my $oid_upsAlarmTime = '.1.3.6.1.2.1.33.1.6.2.1.3';
$snmp_result = $options{snmp}->get_table(oid => $oid_upsAlarmEntry);
foreach my $oid (keys %$snmp_result) {
next if ($oid !~ /^$oid_upsAlarmDescr\.(.*)$/);
if (defined($self->{option_results}->{display_alarms})) {
$self->{output}->output_add(
long_msg => sprintf(
'alarm [since: %s]: %s',
centreon::plugins::misc::change_seconds(value => $snmp_result->{$oid_upsAlarmTime . '.' . $1}),
$map_alarm_desc->{ $snmp_result->{$oid_upsAlarmDescr . '.' . $1} }
)
);
}
}
}
}
1;
@ -78,6 +163,25 @@ Check current alarms.
=over 8
=item B<--display-alarms>
Display alarms in verbose output.
=item B<--unknown-test-status>
Define the conditions to match for the status to be UNKNOWN.
You can use the following variables: %{status}, %{detail}
=item B<--warning-test-status>
Define the conditions to match for the status to be WARNING (default: '%{status} =~ /doneWarning|aborted/').
You can use the following variables: %{status}, %{detail}
=item B<--critical-test-status>
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /doneError/').
You can use the following variables: %{status}, %{detail}
=item B<--warning-*> B<--critical-*>
Thresholds.

View File

@ -41,12 +41,20 @@ sub set_counters {
{ label => 'stdev', template => '%.2f' }
]
}
},
{ label => 'frequence', nlabel => 'lines.output.frequence.hertz', set => {
key_values => [ { name => 'frequency' } ],
output_template => 'frequence: %.2f Hz',
perfdatas => [
{ template => '%.2f', unit => 'Hz' }
]
}
}
];
$self->{maps_counters}->{oline} = [
{ label => 'load', nlabel => 'line.output.load.percentage', set => {
key_values => [ { name => 'upsOutputPercentLoad' } ],
key_values => [ { name => 'outputPercentLoad' } ],
output_template => 'load: %.2f %%',
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
@ -54,7 +62,7 @@ sub set_counters {
}
},
{ label => 'current', nlabel => 'line.output.current.ampere', set => {
key_values => [ { name => 'upsOutputCurrent' } ],
key_values => [ { name => 'outputCurrent' } ],
output_template => 'current: %.2f A',
perfdatas => [
{ template => '%.2f', min => 0, unit => 'A', label_extra_instance => 1 }
@ -62,7 +70,7 @@ sub set_counters {
}
},
{ label => 'voltage', nlabel => 'line.output.voltage.volt', set => {
key_values => [ { name => 'upsOutputVoltage' } ],
key_values => [ { name => 'outputVoltage' } ],
output_template => 'voltage: %.2f V',
perfdatas => [
{ template => '%.2f', unit => 'V', label_extra_instance => 1 }
@ -70,7 +78,7 @@ sub set_counters {
}
},
{ label => 'power', nlabel => 'line.output.power.watt', set => {
key_values => [ { name => 'upsOutputPower' } ],
key_values => [ { name => 'outputPower' } ],
output_template => 'power: %.2f W',
perfdatas => [
{ template => '%.2f', unit => 'W', label_extra_instance => 1 }
@ -105,38 +113,41 @@ sub stdev {
my $total = 0;
my $num_present = scalar(keys %{$self->{oline}});
foreach my $instance (keys %{$self->{oline}}) {
next if (!defined($self->{oline}->{$instance}->{upsOutputPercentLoad}));
$total += $self->{oline}->{$instance}->{upsOutputPercentLoad};
next if (!defined($self->{oline}->{$instance}->{outputPercentLoad}));
$total += $self->{oline}->{$instance}->{outputPercentLoad};
}
my $mean = $total / $num_present;
$total = 0;
foreach my $instance (keys %{$self->{oline}}) {
next if (!defined($self->{oline}->{$instance}->{upsOutputPercentLoad}));
$total += ($mean - $self->{oline}->{$instance}->{upsOutputPercentLoad}) ** 2;
next if (!defined($self->{oline}->{$instance}->{outputPercentLoad}));
$total += ($mean - $self->{oline}->{$instance}->{outputPercentLoad}) ** 2;
}
my $stdev = sqrt($total / $num_present);
$self->{global} = { stdev => $stdev };
$self->{global}->{stdev} = $stdev;
}
my $mapping = {
upsOutputVoltage => { oid => '.1.3.6.1.2.1.33.1.4.4.1.2' }, # in Volt
upsOutputCurrent => { oid => '.1.3.6.1.2.1.33.1.4.4.1.3' }, # in dA
upsOutputPower => { oid => '.1.3.6.1.2.1.33.1.4.4.1.4' }, # in Watt
upsOutputPercentLoad => { oid => '.1.3.6.1.2.1.33.1.4.4.1.5' }
outputVoltage => { oid => '.1.3.6.1.2.1.33.1.4.4.1.2' }, # in Volt
outputCurrent => { oid => '.1.3.6.1.2.1.33.1.4.4.1.3' }, # in dA
outputPower => { oid => '.1.3.6.1.2.1.33.1.4.4.1.4' }, # in Watt
outputPercentLoad => { oid => '.1.3.6.1.2.1.33.1.4.4.1.5' }
};
my $oid_upsOutputEntry = '.1.3.6.1.2.1.33.1.4.4.1';
my $oid_outputFrequency = '.1.3.6.1.2.1.33.1.4.2.0'; # upsOutputFrequency
my $oid_outputEntry = '.1.3.6.1.2.1.33.1.4.4.1';
my $oid_output = '.1.3.6.1.2.1.33.1.4'; # upsOutput
sub manage_selection {
my ($self, %options) = @_;
$self->{oline} = {};
my $snmp_result = $options{snmp}->get_table(
oid => $oid_upsOutputEntry,
oid => $oid_output,
nothing_quit => 1
);
foreach my $oid (keys %$snmp_result) {
$oid =~ /^$oid_upsOutputEntry\.\d+\.(.*)$/;
next if ($oid !~ /^$oid_outputEntry\.\d+\.(.*)$/);
my $instance = $1;
next if (defined($self->{oline}->{$instance}));
@ -146,13 +157,15 @@ sub manage_selection {
delete $result->{$_} if ($result->{$_} == 0);
}
}
$result->{upsOutputCurrent} *= 0.1 if (defined($result->{upsOutputCurrent}));
$result->{outputCurrent} *= 0.1 if (defined($result->{outputCurrent}));
if (scalar(keys %$result) > 0) {
$self->{oline}->{$instance} = { display => $instance, %$result };
}
}
$self->{global} = {};
$self->{global}->{frequency} = $snmp_result->{$oid_outputFrequency} * 0.1 if (defined($snmp_result->{$oid_outputFrequency}));
if (scalar(keys %{$self->{oline}}) > 1) {
$self->stdev();
}
@ -172,15 +185,10 @@ Check Output lines metrics (load, voltage, current and true power).
Ignore counters equals to 0.
=item B<--warning-*>
=item B<--warning-*> B<--critical-*>
Warning threshold.
Can be: 'load', 'voltage', 'current', 'power'.
=item B<--critical-*>
Critical threshold.
Can be: 'load', 'voltage', 'current', 'power'.
Threshold.
Can be: 'frequency', 'load', 'voltage', 'current', 'power'.
=item B<--warning-stdev-3phases>