This commit is contained in:
garnier-quentin 2020-09-17 15:51:27 +02:00
parent 0255b2b54c
commit 4f25b35c7f
2 changed files with 44 additions and 35 deletions

View File

@ -30,57 +30,53 @@ sub set_counters {
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, { name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'oline', type => 1, cb_prefix_output => 'prefix_oline_output', message_multiple => 'All output lines are ok', skipped_code => { -10 => 1 } }, { name => 'oline', type => 1, cb_prefix_output => 'prefix_oline_output', message_multiple => 'All output lines are ok', skipped_code => { -10 => 1 } }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'stdev-3phases', nlabel => 'output.3phases.stdev.gauge', set => { { label => 'stdev-3phases', nlabel => 'output.3phases.stdev.gauge', set => {
key_values => [ { name => 'stdev' } ], key_values => [ { name => 'stdev' } ],
output_template => 'Load Standard Deviation : %.2f', output_template => 'Load standard deviation: %.2f',
perfdatas => [ perfdatas => [
{ label => 'stdev', value => 'stdev', template => '%.2f' }, { label => 'stdev', template => '%.2f' }
], ]
} }
}, }
]; ];
$self->{maps_counters}->{oline} = [ $self->{maps_counters}->{oline} = [
{ label => 'load', nlabel => 'line.output.load.percentage', set => { { label => 'load', nlabel => 'line.output.load.percentage', set => {
key_values => [ { name => 'upsOutputPercentLoad' } ], key_values => [ { name => 'upsOutputPercentLoad' } ],
output_template => 'Load : %.2f %%', output_template => 'load: %.2f %%',
perfdatas => [ perfdatas => [
{ value => 'upsOutputPercentLoad', template => '%.2f', { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
min => 0, max => 100, unit => '%', label_extra_instance => 1 }, ]
],
} }
}, },
{ label => 'current', nlabel => 'line.output.current.ampere', set => { { label => 'current', nlabel => 'line.output.current.ampere', set => {
key_values => [ { name => 'upsOutputCurrent' } ], key_values => [ { name => 'upsOutputCurrent' } ],
output_template => 'Current : %.2f A', output_template => 'current: %.2f A',
perfdatas => [ perfdatas => [
{ value => 'upsOutputCurrent', template => '%.2f', { template => '%.2f', min => 0, unit => 'A', label_extra_instance => 1 }
min => 0, unit => 'A', label_extra_instance => 1 }, ]
],
} }
}, },
{ label => 'voltage', nlabel => 'line.output.voltage.volt', set => { { label => 'voltage', nlabel => 'line.output.voltage.volt', set => {
key_values => [ { name => 'upsOutputVoltage' } ], key_values => [ { name => 'upsOutputVoltage' } ],
output_template => 'Voltage : %.2f V', output_template => 'voltage: %.2f V',
perfdatas => [ perfdatas => [
{ value => 'upsOutputVoltage', template => '%.2f', { template => '%.2f', unit => 'V', label_extra_instance => 1 }
unit => 'V', label_extra_instance => 1 }, ]
],
} }
}, },
{ label => 'power', nlabel => 'line.output.power.watt', set => { { label => 'power', nlabel => 'line.output.power.watt', set => {
key_values => [ { name => 'upsOutputPower' } ], key_values => [ { name => 'upsOutputPower' } ],
output_template => 'Power : %.2f W', output_template => 'power: %.2f W',
perfdatas => [ perfdatas => [
{ value => 'upsOutputPower', template => '%.2f', { template => '%.2f', unit => 'W', label_extra_instance => 1 }
unit => 'W', label_extra_instance => 1 }, ]
],
} }
}, }
]; ];
} }
@ -90,6 +86,7 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'ignore-zero-counters' => { name => 'ignore_zero_counters' }
}); });
return $self; return $self;
@ -98,7 +95,7 @@ sub new {
sub prefix_oline_output { sub prefix_oline_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Output Line '" . $options{instance_value}->{display} . "' "; return "Output line '" . $options{instance_value}->{display} . "' ";
} }
sub stdev { sub stdev {
@ -126,7 +123,7 @@ my $mapping = {
upsOutputVoltage => { oid => '.1.3.6.1.2.1.33.1.4.4.1.2' }, # in Volt 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 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 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' }, upsOutputPercentLoad => { 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_upsOutputEntry = '.1.3.6.1.2.1.33.1.4.4.1';
@ -138,16 +135,24 @@ sub manage_selection {
oid => $oid_upsOutputEntry, oid => $oid_upsOutputEntry,
nothing_quit => 1 nothing_quit => 1
); );
foreach my $oid (keys %{$snmp_result}) { foreach my $oid (keys %$snmp_result) {
$oid =~ /^$oid_upsOutputEntry\.\d+\.(.*)$/; $oid =~ /^$oid_upsOutputEntry\.\d+\.(.*)$/;
my $instance = $1; my $instance = $1;
next if (defined($self->{oline}->{$instance})); next if (defined($self->{oline}->{$instance}));
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
if (defined($self->{option_results}->{ignore_zero_counters})) {
foreach (keys %$result) {
delete $result->{$_} if ($result->{$_} == 0);
}
}
$result->{upsOutputCurrent} *= 0.1 if (defined($result->{upsOutputCurrent})); $result->{upsOutputCurrent} *= 0.1 if (defined($result->{upsOutputCurrent}));
$self->{oline}->{$instance} = { display => $instance, %$result };
if (scalar(keys %$result) > 0) {
$self->{oline}->{$instance} = { display => $instance, %$result };
}
} }
if (scalar(keys %{$self->{oline}}) > 1) { if (scalar(keys %{$self->{oline}}) > 1) {
$self->stdev(); $self->stdev();
} }
@ -163,6 +168,10 @@ Check Output lines metrics (load, voltage, current and true power).
=over 8 =over 8
=item B<--ignore-zero-counters>
Ignore counters equals to 0.
=item B<--warning-*> =item B<--warning-*>
Threshold warning. Threshold warning.

View File

@ -30,13 +30,13 @@ sub new {
bless $self, $class; bless $self, $class;
$self->{version} = '0.1'; $self->{version} = '0.1';
%{$self->{modes}} = ( $self->{modes} = {
'alarms' => 'hardware::ups::standard::rfc1628::snmp::mode::alarms', 'alarms' => 'hardware::ups::standard::rfc1628::snmp::mode::alarms',
'battery-status' => 'hardware::ups::standard::rfc1628::snmp::mode::batterystatus', 'battery-status' => 'hardware::ups::standard::rfc1628::snmp::mode::batterystatus',
'input-lines' => 'hardware::ups::standard::rfc1628::snmp::mode::inputlines', 'input-lines' => 'hardware::ups::standard::rfc1628::snmp::mode::inputlines',
'output-lines' => 'hardware::ups::standard::rfc1628::snmp::mode::outputlines', 'output-lines' => 'hardware::ups::standard::rfc1628::snmp::mode::outputlines',
'output-source' => 'hardware::ups::standard::rfc1628::snmp::mode::outputsource', 'output-source' => 'hardware::ups::standard::rfc1628::snmp::mode::outputsource'
); };
return $self; return $self;
} }