clean(phoenixtec/snmp): remove useless mode (#3037)

This commit is contained in:
qgarnier 2021-08-11 14:32:33 +02:00 committed by GitHub
parent d861ebe669
commit a306311c20
5 changed files with 96 additions and 268 deletions

View File

@ -24,63 +24,66 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("battery status is '%s'", $self->{result_values}->{status});
return $msg;
return sprintf("battery status is '%s'", $self->{result_values}->{status});
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, set => {
{
label => 'status',
type => 2,
unknown_default => '%{status} =~ /unknown/i',
warning_default => '%{status} =~ /low/i',
set => {
key_values => [ { name => 'status' } ],
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,
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'charge-remaining', , nlabel => 'battery.charge.remaining.percent', set => {
key_values => [ { name => 'upsSmartBatteryCapacity' } ],
output_template => 'remaining capacity: %s %%',
perfdatas => [
{ value => 'upsSmartBatteryCapacity', template => '%s', min => 0, max => 100, unit => '%' },
],
{ template => '%s', min => 0, max => 100, unit => '%' }
]
}
},
{ label => 'charge-remaining-minutes', nlabel => 'battery.charge.remaining.minutes', display_ok => 0, set => {
key_values => [ { name => 'upsSmartBatteryRunTimeRemaining' } ],
output_template => 'remaining time: %s minutes',
perfdatas => [
{ value => 'upsSmartBatteryRunTimeRemaining', template => '%s', min => 0, unit => 'm' },
],
{ template => '%s', min => 0, unit => 'm' }
]
}
},
{ label => 'voltage', nlabel => 'battery.voltage.volt', display_ok => 0, set => {
key_values => [ { name => 'upsSmartBatteryVoltage', no_value => 0 } ],
output_template => 'voltage: %s V',
perfdatas => [
{ value => 'upsSmartBatteryVoltage', template => '%s', unit => 'V' },
],
{ template => '%s', unit => 'V' }
]
}
},
{ label => 'temperature', nlabel => 'battery.temperature.celsius', display_ok => 0, set => {
key_values => [ { name => 'upsSmartBatteryTemperature', no_value => 0 } ],
output_template => 'temperature: %s C',
perfdatas => [
{ value => 'upsSmartBatteryTemperature', template => '%s', unit => 'C' },
],
{ template => '%s', unit => 'C' }
]
}
},
}
];
}
@ -90,21 +93,11 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' },
'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /low/i' },
'critical-status:s' => { name => 'critical_status', default => '' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
}
my $map_battery_status = {
1 => 'unknown', 2 => 'normal', 3 => 'low'
};
@ -114,12 +107,12 @@ my $mapping = {
upsSmartBatteryVoltage => { oid => '.1.3.6.1.4.1.935.1.1.1.2.2.2' }, # in dV
upsSmartBatteryTemperature => { oid => '.1.3.6.1.4.1.935.1.1.1.2.2.3' }, # in tenth of celsius
upsSmartBatteryRunTimeRemaining => { oid => '.1.3.6.1.4.1.935.1.1.1.2.2.4' }, # in seconds
upsSmartBatteryCapacity => { oid => '.1.3.6.1.4.1.935.1.1.1.2.2.1' },
upsSmartBatteryCapacity => { oid => '.1.3.6.1.4.1.935.1.1.1.2.2.1' }
};
sub manage_selection {
my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_leef(
oids => [ map($_->{oid} . '.0', values(%$mapping)) ],
nothing_quit => 1

View File

@ -1,157 +0,0 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package hardware::ups::hp::snmp::mode::environment;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
{ label => 'internal-temperature', nlabel => 'environment.internal.temperature.celsius', set => {
key_values => [ { name => 'internal_temperature' } ],
output_template => 'internal temperature: %.2f C',
perfdatas => [
{ value => 'internal_temperature', template => '%.2f',
min => 0, unit => 'C' },
],
}
},
{ label => 'internal-humidity', nlabel => 'environment.internal.humidity.percentage', set => {
key_values => [ { name => 'internal_humidity' } ],
output_template => 'internal humidity: %.2f %%',
perfdatas => [
{ value => 'internal_humidity', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
{ label => 'remote-temperature', nlabel => 'environment.remote.temperature.celsius', set => {
key_values => [ { name => 'remote_temperature' } ],
output_template => 'remote temperature: %.2f C',
perfdatas => [
{ value => 'remote_temperature', template => '%.2f',
min => 0, unit => 'C' },
],
}
},
{ label => 'remote-humidity', nlabel => 'environment.remote.humidity.percentage', set => {
key_values => [ { name => 'remote_humidity' } ],
output_template => 'remote humidity: %.2f %%',
perfdatas => [
{ value => 'remote_humidity', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $oids = {
upsEnvAmbientTemp => '.1.3.6.1.4.1.232.165.3.6.1.0',
upsEnvAmbientLowerLimit => '.1.3.6.1.4.1.232.165.3.6.2.0',
upsEnvAmbientUpperLimit => '.1.3.6.1.4.1.232.165.3.6.3.0',
upsEnvAmbientHumidity => '.1.3.6.1.4.1.232.165.3.6.4.0',
upsEnvRemoteTemp => '.1.3.6.1.4.1.232.165.3.6.5.0',
upsEnvRemoteHumidity => '.1.3.6.1.4.1.232.165.3.6.6.0',
upsEnvRemoteTempLowerLimit => '.1.3.6.1.4.1.232.165.3.6.9.0',
upsEnvRemoteTempUpperLimit => '.1.3.6.1.4.1.232.165.3.6.10.0',
upsEnvRemoteHumidityLowerLimit => '.1.3.6.1.4.1.232.165.3.6.11.0',
upsEnvRemoteHumidityUpperLimit => '.1.3.6.1.4.1.232.165.3.6.12.0',
};
my $snmp_result = $options{snmp}->get_leef(
oids => [ values %$oids ],
nothing_quit => 1
);
$self->{global} = {
internal_temperature => defined($snmp_result->{$oids->{upsEnvAmbientTemp}}) && $snmp_result->{$oids->{upsEnvAmbientTemp}} ne '' && $snmp_result->{$oids->{upsEnvAmbientTemp}} != 0 ?
$snmp_result->{$oids->{upsEnvAmbientTemp}} : undef,
internal_humidity => defined($snmp_result->{$oids->{upsEnvAmbientHumidity}}) && $snmp_result->{$oids->{upsEnvAmbientHumidity}} ne '' && $snmp_result->{$oids->{upsEnvAmbientHumidity}} != 0 ?
$snmp_result->{$oids->{upsEnvAmbientHumidity}} : undef,
remote_temperature => defined($snmp_result->{$oids->{upsEnvRemoteTemp}}) && $snmp_result->{$oids->{upsEnvRemoteTemp}} ne '' && $snmp_result->{$oids->{upsEnvRemoteTemp}} != 0 ?
$snmp_result->{$oids->{upsEnvRemoteTemp}} : undef,
remote_humidity => defined($snmp_result->{$oids->{upsEnvRemoteHumidity}}) && $snmp_result->{$oids->{upsEnvRemoteHumidity}} ne '' && $snmp_result->{$oids->{upsEnvRemoteHumidity}} != 0 ?
$snmp_result->{$oids->{upsEnvRemoteHumidity}} : undef,
};
if (!defined($self->{option_results}->{'critical-environment-internal-temperature-celsius'}) || $self->{option_results}->{'critical-environment-internal-temperature-celsius'} eq '') {
my $crit_val = '';
$crit_val = $snmp_result->{$oids->{upsEnvAmbientLowerLimit}} . ':'
if (defined($snmp_result->{$oids->{upsEnvAmbientLowerLimit}}) &&
$snmp_result->{$oids->{upsEnvAmbientLowerLimit}} ne '' && $snmp_result->{$oids->{upsEnvAmbientLowerLimit}} != 0);
$crit_val .= $snmp_result->{$oids->{upsEnvAmbientUpperLimit}}
if (defined($snmp_result->{$oids->{upsEnvAmbientUpperLimit}}) &&
$snmp_result->{$oids->{upsEnvAmbientUpperLimit}} ne '' && $snmp_result->{$oids->{upsEnvAmbientUpperLimit}} != 0);
$self->{perfdata}->threshold_validate(label => 'critical-environment-internal-temperature-celsius', value => $crit_val);
}
if (!defined($self->{option_results}->{'critical-environment-remote-temperature-celsius'}) || $self->{option_results}->{'critical-environment-remote-temperature-celsius'} eq '') {
my $crit_val = '';
$crit_val = $snmp_result->{$oids->{upsEnvRemoteTempLowerLimit}} . ':'
if (defined($snmp_result->{$oids->{upsEnvRemoteTempLowerLimit}}) &&
$snmp_result->{$oids->{upsEnvRemoteTempLowerLimit}} ne '' && $snmp_result->{$oids->{upsEnvRemoteTempLowerLimit}} != 0);
$crit_val .= $snmp_result->{$oids->{upsEnvRemoteTempUpperLimit}}
if (defined($snmp_result->{$oids->{upsEnvRemoteTempUpperLimit}}) &&
$snmp_result->{$oids->{upsEnvRemoteTempUpperLimit}} ne '' && $snmp_result->{$oids->{upsEnvRemoteTempUpperLimit}} != 0);
$self->{perfdata}->threshold_validate(label => 'critical-environment-remote-temperature-celsius', value => $crit_val);
}
}
1;
__END__
=head1 MODE
Check environment.
=over 8
=item B<--warning-*> B<--critical-*>
Can be: 'internal-temperature', 'internal-humidity',
'remote-temperature', 'remote-humidity'.
=back
=cut

View File

@ -25,9 +25,15 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub prefix_global_output {
my ($self, %options) = @_;
return 'Input lines ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } },
];
@ -37,34 +43,26 @@ sub set_counters {
key_values => [ { name => 'upsSmartInputFrequency', no_value => 0 } ],
output_template => 'frequence: %.2f Hz',
perfdatas => [
{ value => 'upsSmartInputFrequency', template => '%.2f',
unit => 'Hz' },
],
{ template => '%.2f', unit => 'Hz' }
]
}
},
{ label => 'voltage', nlabel => 'lines.input.voltage.volt', set => {
key_values => [ { name => 'upsSmartInputLineVoltage', no_value => 0 } ],
output_template => 'voltage: %s V',
perfdatas => [
{ value => 'upsSmartInputLineVoltage', template => '%s',
unit => 'V' },
],
{ template => '%s', unit => 'V' }
]
}
},
}
];
}
sub prefix_global_output {
my ($self, %options) = @_;
return 'Input lines ';
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
@ -73,13 +71,13 @@ sub new {
my $mapping = {
upsSmartInputLineVoltage => { oid => '.1.3.6.1.4.1.935.1.1.1.3.2.1' }, # in dV
upsSmartInputFrequency => { oid => '.1.3.6.1.4.1.935.1.1.1.3.2.4' }, # in tenth of Hz
upsSmartInputFrequency => { oid => '.1.3.6.1.4.1.935.1.1.1.3.2.4' } # in tenth of Hz
};
sub manage_selection {
my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_leef(
my $snmp_result = $options{snmp}->get_leef(
oids => [ map($_->{oid} . '.0', values(%$mapping)) ],
nothing_quit => 1
);

View File

@ -24,103 +24,97 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf("status is '%s'", $self->{result_values}->{status});
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' } ],
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,
}
},
{ label => 'load', nlabel => 'lines.output.load.percentage', set => {
key_values => [ { name => 'upsSmartOutputLoad', no_value => -1 } ],
output_template => 'load: %.2f %%',
perfdatas => [
{ value => 'upsSmartOutputLoad', template => '%.2f', min => 0, max => 100 },
],
}
},
{ label => 'frequence', nlabel => 'lines.output.frequence.hertz', set => {
key_values => [ { name => 'upsSmartOutputFrequency', no_value => 0 } ],
output_template => 'frequence: %.2f Hz',
perfdatas => [
{ value => 'upsSmartOutputFrequency', template => '%.2f', unit => 'Hz' },
],
}
},
{ label => 'voltage', nlabel => 'lines.output.voltage.volt', set => {
key_values => [ { name => 'upsSmartOutputVoltage', no_value => 0 } ],
output_template => 'voltage: %s V',
perfdatas => [
{ value => 'upsSmartOutputVoltage', template => '%s',
unit => 'V' },
],
}
},
];
}
sub prefix_global_output {
my ($self, %options) = @_;
return 'Output lines ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
{
label => 'status',
type => 2,
unknown_default => '%{status} =~ /unknown/i',
warning_default => '%{status} =~ /rebooting|onBypass/i',
critical_default => '%{status} =~ /onBattery/i',
set => {
key_values => [ { name => 'status' } ],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'load', nlabel => 'lines.output.load.percentage', set => {
key_values => [ { name => 'upsSmartOutputLoad', no_value => -1 } ],
output_template => 'load: %.2f %%',
perfdatas => [
{ template => '%.2f', min => 0, max => 100 }
]
}
},
{ label => 'frequence', nlabel => 'lines.output.frequence.hertz', set => {
key_values => [ { name => 'upsSmartOutputFrequency', no_value => 0 } ],
output_template => 'frequence: %.2f Hz',
perfdatas => [
{ template => '%.2f', unit => 'Hz' }
]
}
},
{ label => 'voltage', nlabel => 'lines.output.voltage.volt', set => {
key_values => [ { name => 'upsSmartOutputVoltage', no_value => 0 } ],
output_template => 'voltage: %s V',
perfdatas => [
{ template => '%s', unit => 'V' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /unknown/i' },
'warning-status:s' => { name => 'warning_status', default => '%{status} =~ /rebooting|onBypass/i' },
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /onBattery/i' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
}
my $map_status = {
1 => 'unknown', 2 => 'onLine',
3 => 'onBattery', 4 => 'onBoost',
5 => 'sleeping', 6 => 'onBypass',
7 => 'rebooting', 8 => 'standBy',
9 => 'onBuck',
9 => 'onBuck'
};
my $mapping = {
upsBaseOutputStatus => { oid => '.1.3.6.1.4.1.935.1.1.1.4.1.1', map => $map_status },
upsSmartOutputVoltage => { oid => '.1.3.6.1.4.1.935.1.1.1.4.2.1' }, # in dV
upsSmartOutputFrequency => { oid => '.1.3.6.1.4.1.935.1.1.1.4.2.2' }, # in tenth of Hz
upsSmartOutputLoad => { oid => '.1.3.6.1.4.1.935.1.1.1.4.2.3' }, # in %
upsSmartOutputLoad => { oid => '.1.3.6.1.4.1.935.1.1.1.4.2.3' } # in %
};
sub manage_selection {
my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_leef(
oids => [ map($_->{oid} . '.0', values(%$mapping)) ],
nothing_quit => 1

View File

@ -28,13 +28,13 @@ sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
$self->{modes} = {
'battery-status' => 'centreon::common::xppc::snmp::mode::batterystatus',
'input-lines' => 'centreon::common::xppc::snmp::mode::inputlines',
'output-lines' => 'centreon::common::xppc::snmp::mode::outputlines',
);
'output-lines' => 'centreon::common::xppc::snmp::mode::outputlines'
};
return $self;
}