(plugin) hardware::ups::standard::rfc1628::snmp - perfdata v2 + threshold options (#4232)
This commit is contained in:
parent
8fcabfc2c2
commit
85ecbf69e3
|
@ -20,47 +20,52 @@
|
|||
|
||||
package hardware::ups::standard::rfc1628::snmp::mode::alarms;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
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 }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'alarms-current', nlabel => 'alarms.current.count', set => {
|
||||
key_values => [ { name => 'current_alarms' } ],
|
||||
output_template => 'current alarms: %s',
|
||||
perfdatas => [
|
||||
{ template => '%s', min => 0 }
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
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 => {});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{snmp} = $options{snmp};
|
||||
|
||||
my $oid_upsAlarmsPresent = '.1.3.6.1.2.1.33.1.6.1.0';
|
||||
my $result = $self->{snmp}->get_leef(oids => [ $oid_upsAlarmsPresent ], nothing_quit => 1);
|
||||
my $oid_upsAlarmsPresent = '.1.3.6.1.2.1.33.1.6.1.0';
|
||||
my $snmp_result = $options{snmp}->get_leef(
|
||||
oids => [ $oid_upsAlarmsPresent ],
|
||||
nothing_quit => 1
|
||||
);
|
||||
|
||||
$self->{output}->output_add(severity => 'ok',
|
||||
short_msg => 'No alarms');
|
||||
if ($result->{$oid_upsAlarmsPresent} > 0) {
|
||||
$self->{output}->output_add(severity => 'critical',
|
||||
short_msg => sprintf('%d Alarms (check your equipment to have more informations)', $result->{$oid_upsAlarmsPresent}));
|
||||
}
|
||||
$self->{output}->perfdata_add(label => 'alarms',
|
||||
value => $result->{$oid_upsAlarmsPresent},
|
||||
min => 0);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{global} = {
|
||||
current_alarms => $snmp_result->{$oid_upsAlarmsPresent}
|
||||
};
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -69,12 +74,15 @@ __END__
|
|||
|
||||
=head1 MODE
|
||||
|
||||
Check if Alarms present.
|
||||
Need an example to do the display from 'upsAlarmTable'. If you have ;)
|
||||
https://forge.centreon.com/issues/5377
|
||||
Check current alarms.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
Thresholds.
|
||||
Can be: 'alarms-current'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -67,7 +67,7 @@ sub set_counters {
|
|||
key_values => [ { name => 'charge_remain' }, { name => 'minute_remain' } ],
|
||||
closure_custom_output => $self->can('custom_load_output'),
|
||||
perfdatas => [
|
||||
{ label => 'load', template => '%s', min => 0, max => 100, unit => '%' }
|
||||
{ template => '%s', min => 0, max => 100, unit => '%' }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -75,7 +75,7 @@ sub set_counters {
|
|||
key_values => [ { name => 'minute_remain' } ],
|
||||
output_template => 'minutes remaining: %s',
|
||||
perfdatas => [
|
||||
{ label => 'charge_remaining', template => '%s', min => 0, unit => 'minutes' }
|
||||
{ template => '%s', min => 0, unit => 'minutes' }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -83,7 +83,7 @@ sub set_counters {
|
|||
key_values => [ { name => 'current', no_value => 0 } ],
|
||||
output_template => 'current: %s A',
|
||||
perfdatas => [
|
||||
{ label => 'current', template => '%s', min => 0, unit => 'A' }
|
||||
{ template => '%s', min => 0, unit => 'A' }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -91,7 +91,7 @@ sub set_counters {
|
|||
key_values => [ { name => 'voltage', no_value => 0 } ],
|
||||
output_template => 'voltage: %s V',
|
||||
perfdatas => [
|
||||
{ label => 'voltage', template => '%s', unit => 'V' }
|
||||
{ template => '%s', unit => 'V' }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
@ -99,7 +99,7 @@ sub set_counters {
|
|||
key_values => [ { name => 'temperature', no_value => 0 } ],
|
||||
output_template => 'temperature: %s C',
|
||||
perfdatas => [
|
||||
{ label => 'temp', template => '%s', unit => 'C' }
|
||||
{ template => '%s', unit => 'C' }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ sub set_counters {
|
|||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
|
|
|
@ -25,6 +25,12 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub prefix_line_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Input Line '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -33,59 +39,47 @@ sub set_counters {
|
|||
];
|
||||
|
||||
$self->{maps_counters}->{line} = [
|
||||
{ label => 'frequence', set => {
|
||||
{ label => 'frequence', nlabel => 'line.input.frequence.hertz', set => {
|
||||
key_values => [ { name => 'upsInputFrequency' }, { name => 'display' } ],
|
||||
output_template => 'Frequence : %.2f Hz',
|
||||
perfdatas => [
|
||||
{ label => 'frequence', value => 'upsInputFrequency', template => '%s',
|
||||
unit => 'Hz', label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ template => '%s', unit => 'Hz', label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'voltage', set => {
|
||||
{ label => 'voltage', nlabel => 'line.input.voltage.volt', set => {
|
||||
key_values => [ { name => 'upsInputVoltage' }, { name => 'display' } ],
|
||||
output_template => 'Voltage : %.2f V',
|
||||
perfdatas => [
|
||||
{ label => 'voltage', value => 'upsInputVoltage', template => '%s',
|
||||
unit => 'V', label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ template => '%s', unit => 'V', label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'current', set => {
|
||||
{ label => 'current', nlabel => 'line.input.current.ampere', set => {
|
||||
key_values => [ { name => 'upsInputCurrent' }, { name => 'display' } ],
|
||||
output_template => 'Current : %.2f A',
|
||||
perfdatas => [
|
||||
{ label => 'current', value => 'upsInputCurrent', template => '%s',
|
||||
unit => 'A', label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ template => '%s', unit => 'A', label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'power', set => {
|
||||
{ label => 'power', nlabel => 'line.input.power.watt', set => {
|
||||
key_values => [ { name => 'upsInputTruePower' }, { name => 'display' } ],
|
||||
output_template => 'Power : %.2f W',
|
||||
perfdatas => [
|
||||
{ label => 'power', value => 'upsInputTruePower', template => '%s',
|
||||
unit => 'W', label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ template => '%s', unit => 'W', label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_line_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Input Line '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
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 => {});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
@ -102,14 +96,14 @@ sub manage_selection {
|
|||
|
||||
my $oid_upsInputEntry = '.1.3.6.1.2.1.33.1.3.3.1';
|
||||
my $results = $options{snmp}->get_table(oid => $oid_upsInputEntry, nothing_quit => 1);
|
||||
|
||||
|
||||
$self->{line} = {};
|
||||
foreach my $oid (keys %{$results}) {
|
||||
next if ($oid !~ /^(.*)\.(.*?)\.(.*?)$/);
|
||||
my ($base, $instance) = ($1 . '.' . $2, $3);
|
||||
next if (!defined($oids->{$base}));
|
||||
next if ($results->{$oid} !~ /\d/ || $results->{$oid} == 0);
|
||||
|
||||
|
||||
$self->{line}->{$instance} = { display => $instance } if (!defined($self->{line}->{$instance}));
|
||||
$self->{line}->{$instance}->{$oids->{$base}->{name}} = $results->{$oid} * $oids->{$base}->{factor};
|
||||
}
|
||||
|
@ -121,7 +115,7 @@ __END__
|
|||
|
||||
=head1 MODE
|
||||
|
||||
Check Input lines metrics (frequence, voltage, current and true power).
|
||||
Check input lines metrics (frequence, voltage, current and true power).
|
||||
|
||||
=over 8
|
||||
|
||||
|
@ -130,14 +124,9 @@ Check Input lines metrics (frequence, voltage, current and true power).
|
|||
Only display some counters (regexp can be used).
|
||||
Example: --filter-counters='^power$'
|
||||
|
||||
=item B<--warning-*>
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'frequence', 'voltage', 'current', 'power'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Thresholds.
|
||||
Can be: 'frequence', 'voltage', 'current', 'power'.
|
||||
|
||||
=back
|
||||
|
|
|
@ -82,7 +82,7 @@ sub set_counters {
|
|||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
|
|
|
@ -20,52 +20,65 @@
|
|||
|
||||
package hardware::ups::standard::rfc1628::snmp::mode::outputsource;
|
||||
|
||||
use base qw(centreon::plugins::mode);
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||
|
||||
my %outputsource_status = (
|
||||
1 => ['other', 'UNKNOWN'],
|
||||
2 => ['none', 'CRITICAL'],
|
||||
3 => ['normal', 'OK'],
|
||||
4 => ['bypass', 'WARNING'],
|
||||
5 => ['battery', 'WARNING'],
|
||||
6 => ['booster', 'WARNING'],
|
||||
7 => ['reducer', 'WARNING'],
|
||||
);
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf("Output source 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 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{
|
||||
label => 'source-status',
|
||||
type => 2,
|
||||
unknown_default => '%{status} =~ /other/',
|
||||
warning_default => '%{status} =~ /bypass|battery|booster|reducer/',
|
||||
critical_default => '%{status} =~ /none/',
|
||||
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
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
});
|
||||
$options{options}->add_options(arguments => {});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
$self->{snmp} = $options{snmp};
|
||||
|
||||
my $map_status = {
|
||||
1 => 'other', 2 => 'none',
|
||||
3 => 'normal', 4 => 'bypass', 5 => 'battery',
|
||||
6 => 'booster', 7 => 'reducer'
|
||||
};
|
||||
|
||||
my $oid_upsOutputSource = '.1.3.6.1.2.1.33.1.4.1.0';
|
||||
|
||||
my $result = $self->{snmp}->get_leef(oids => [$oid_upsOutputSource], nothing_quit => 1);
|
||||
my $status = $result->{'.1.3.6.1.2.1.33.1.4.1.0'};
|
||||
|
||||
$self->{output}->output_add(severity => ${$outputsource_status{$status}}[1],
|
||||
short_msg => sprintf("Output source status is %s", ${$outputsource_status{$status}}[0]));
|
||||
my $snmp_result = $options{snmp}->get_leef(oids => [$oid_upsOutputSource], nothing_quit => 1);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
$self->{global} = { status => $map_status->{ $snmp_result->{$oid_upsOutputSource} } };
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -78,6 +91,21 @@ Check output source status.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--unknown-source-status>
|
||||
|
||||
Set unknown threshold for status (Default: '%{status} =~ /other/')
|
||||
Can used special variables like: %{status}
|
||||
|
||||
=item B<--warning-source-status>
|
||||
|
||||
Set warning threshold for status (Default: '%{status} =~ /bypass|battery|booster|reducer/')
|
||||
Can used special variables like: %{status}
|
||||
|
||||
=item B<--critical-source-status>
|
||||
|
||||
Set critical threshold for status (Default: '%{status} =~ /none/')
|
||||
Can used special variables like: %{status}
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -29,7 +29,6 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '0.1';
|
||||
$self->{modes} = {
|
||||
'alarms' => 'hardware::ups::standard::rfc1628::snmp::mode::alarms',
|
||||
'battery-status' => 'hardware::ups::standard::rfc1628::snmp::mode::batterystatus',
|
||||
|
|
Loading…
Reference in New Issue