enhance apc input-lines

This commit is contained in:
garnier-quentin 2019-12-26 11:57:27 +01:00
parent 89db1f982f
commit 678404c194
1 changed files with 25 additions and 28 deletions

View File

@ -24,51 +24,43 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("Last input line fail cause is '%s'", $self->{result_values}->{last_cause});
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{last_cause} = $options{new_datas}->{$self->{instance} . '_upsAdvInputLineFailCause'};
return 0;
return sprintf("last input line fail cause is '%s'", $self->{result_values}->{last_cause});
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
];
$self->{maps_counters}->{global} = [
{ label => 'voltage', set => {
key_values => [ { name => 'upsAdvInputLineVoltage' } ],
output_template => 'Voltage: %s V',
key_values => [ { name => 'voltage' } ],
output_template => 'voltage: %s V',
perfdatas => [
{ label => 'voltage', value => 'upsAdvInputLineVoltage_absolute', template => '%s',
{ label => 'voltage', value => 'voltage_absolute', template => '%s',
unit => 'V' },
],
}
},
{ label => 'frequence', set => {
key_values => [ { name => 'upsAdvInputFrequency' } ],
output_template => 'Frequence: %s Hz',
key_values => [ { name => 'frequency' } ],
output_template => 'frequence: %s Hz',
perfdatas => [
{ label => 'frequence', value => 'upsAdvInputFrequency_absolute', template => '%s',
{ label => 'frequence', value => 'frequency_absolute', template => '%s',
unit => 'Hz' },
],
}
},
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'upsAdvInputLineFailCause' } ],
closure_custom_calc => $self->can('custom_status_calc'),
key_values => [ { name => 'last_cause' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
@ -81,7 +73,7 @@ sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '' },
@ -97,24 +89,25 @@ sub check_options {
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
my %map_status = (
my $map_status = {
1 => 'noTransfer', 2 => 'highLineVoltage', 3 => 'brownout', 4 => 'blackout',
5 => 'smallMomentarySag', 6 => 'deepMomentarySag', 7 => 'smallMomentarySpike',
8 => 'largeMomentarySpike', 9 => 'selfTest', 10 => 'rateOfVoltageChange',
);
};
my $mapping = {
upsAdvInputLineVoltage => { oid => '.1.3.6.1.4.1.318.1.1.1.3.2.1' },
upsAdvInputFrequency => { oid => '.1.3.6.1.4.1.318.1.1.1.3.2.4' },
upsAdvInputLineFailCause => { oid => '.1.3.6.1.4.1.318.1.1.1.3.2.5', map => \%map_status },
upsAdvInputLineFailCause => { oid => '.1.3.6.1.4.1.318.1.1.1.3.2.5', map => $map_status },
upsAdvConfigHighTransferVolt => { oid => '.1.3.6.1.4.1.318.1.1.1.5.2.2' },
upsAdvConfigLowTransferVolt => { oid => '.1.3.6.1.4.1.318.1.1.1.5.2.3' },
upsHighPrecInputLineVoltage => { oid => '.1.3.6.1.4.1.318.1.1.1.3.3.1' },
upsHighPrecInputFrequency => { oid => '.1.3.6.1.4.1.318.1.1.1.3.3.4' },
};
sub manage_selection {
my ($self, %options) = @_;
$self->{global} = {};
my $snmp_result = $options{snmp}->get_leef(
oids => [ map($_->{oid} . '.0', values(%$mapping)) ],
nothing_quit => 1
@ -130,9 +123,13 @@ sub manage_selection {
$self->{perfdata}->threshold_validate(label => 'critical-voltage', value => $th) if ($th ne '');
}
foreach my $name (keys %{$mapping}) {
$self->{global}->{$name} = $result->{$name};
}
$self->{global} = {
last_cause => $result->{upsAdvInputLineFailCause},
voltage => defined($result->{upsHighPrecInputLineVoltage}) && $result->{upsHighPrecInputLineVoltage} =~ /\d/ ?
$result->{upsHighPrecInputLineVoltage} * 0.1 : $result->{upsAdvInputLineVoltage},
frequency => defined($result->{upsHighPrecInputFrequency}) && $result->{upsHighPrecInputFrequency} =~ /\d/ ?
$result->{upsHighPrecInputFrequency} * 0.1 : $result->{upsAdvInputFrequency},
};
}
1;