(plugin) hardware::ups::standard::rfc1628::snmp - perfdata v2 + threshold options (#4232)

This commit is contained in:
qgarnier 2023-03-06 09:13:18 +00:00 committed by David Boucher
parent 8fcabfc2c2
commit 85ecbf69e3
6 changed files with 126 additions and 102 deletions

View File

@ -20,47 +20,52 @@
package hardware::ups::standard::rfc1628::snmp::mode::alarms; package hardware::ups::standard::rfc1628::snmp::mode::alarms;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; 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 { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {});
{
});
return $self; return $self;
} }
sub check_options { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub run { my $oid_upsAlarmsPresent = '.1.3.6.1.2.1.33.1.6.1.0';
my ($self, %options) = @_; my $snmp_result = $options{snmp}->get_leef(
$self->{snmp} = $options{snmp}; oids => [ $oid_upsAlarmsPresent ],
nothing_quit => 1
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);
$self->{output}->output_add(severity => 'ok', $self->{global} = {
short_msg => 'No alarms'); current_alarms => $snmp_result->{$oid_upsAlarmsPresent}
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();
} }
1; 1;
@ -69,12 +74,15 @@ __END__
=head1 MODE =head1 MODE
Check if Alarms present. Check current alarms.
Need an example to do the display from 'upsAlarmTable'. If you have ;)
https://forge.centreon.com/issues/5377
=over 8 =over 8
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'alarms-current'.
=back =back
=cut =cut

View File

@ -67,7 +67,7 @@ sub set_counters {
key_values => [ { name => 'charge_remain' }, { name => 'minute_remain' } ], key_values => [ { name => 'charge_remain' }, { name => 'minute_remain' } ],
closure_custom_output => $self->can('custom_load_output'), closure_custom_output => $self->can('custom_load_output'),
perfdatas => [ 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' } ], key_values => [ { name => 'minute_remain' } ],
output_template => 'minutes remaining: %s', output_template => 'minutes remaining: %s',
perfdatas => [ 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 } ], key_values => [ { name => 'current', no_value => 0 } ],
output_template => 'current: %s A', output_template => 'current: %s A',
perfdatas => [ 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 } ], key_values => [ { name => 'voltage', no_value => 0 } ],
output_template => 'voltage: %s V', output_template => 'voltage: %s V',
perfdatas => [ 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 } ], key_values => [ { name => 'temperature', no_value => 0 } ],
output_template => 'temperature: %s C', output_template => 'temperature: %s C',
perfdatas => [ perfdatas => [
{ label => 'temp', template => '%s', unit => 'C' } { template => '%s', unit => 'C' }
] ]
} }
} }
@ -108,7 +108,7 @@ sub set_counters {
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {

View File

@ -25,6 +25,12 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
sub prefix_line_output {
my ($self, %options) = @_;
return "Input Line '" . $options{instance_value}->{display} . "' ";
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -33,59 +39,47 @@ sub set_counters {
]; ];
$self->{maps_counters}->{line} = [ $self->{maps_counters}->{line} = [
{ label => 'frequence', set => { { label => 'frequence', nlabel => 'line.input.frequence.hertz', set => {
key_values => [ { name => 'upsInputFrequency' }, { name => 'display' } ], key_values => [ { name => 'upsInputFrequency' }, { name => 'display' } ],
output_template => 'Frequence : %.2f Hz', output_template => 'Frequence : %.2f Hz',
perfdatas => [ perfdatas => [
{ label => 'frequence', value => 'upsInputFrequency', template => '%s', { template => '%s', unit => 'Hz', label_extra_instance => 1, instance_use => 'display' }
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' } ], key_values => [ { name => 'upsInputVoltage' }, { name => 'display' } ],
output_template => 'Voltage : %.2f V', output_template => 'Voltage : %.2f V',
perfdatas => [ perfdatas => [
{ label => 'voltage', value => 'upsInputVoltage', template => '%s', { template => '%s', unit => 'V', label_extra_instance => 1, instance_use => 'display' }
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' } ], key_values => [ { name => 'upsInputCurrent' }, { name => 'display' } ],
output_template => 'Current : %.2f A', output_template => 'Current : %.2f A',
perfdatas => [ perfdatas => [
{ label => 'current', value => 'upsInputCurrent', template => '%s', { template => '%s', unit => 'A', label_extra_instance => 1, instance_use => 'display' }
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' } ], key_values => [ { name => 'upsInputTruePower' }, { name => 'display' } ],
output_template => 'Power : %.2f W', output_template => 'Power : %.2f W',
perfdatas => [ perfdatas => [
{ label => 'power', value => 'upsInputTruePower', template => '%s', { template => '%s', unit => 'W', label_extra_instance => 1, instance_use => 'display' }
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 { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {});
{
});
return $self; return $self;
} }
@ -102,14 +96,14 @@ sub manage_selection {
my $oid_upsInputEntry = '.1.3.6.1.2.1.33.1.3.3.1'; 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); my $results = $options{snmp}->get_table(oid => $oid_upsInputEntry, nothing_quit => 1);
$self->{line} = {}; $self->{line} = {};
foreach my $oid (keys %{$results}) { foreach my $oid (keys %{$results}) {
next if ($oid !~ /^(.*)\.(.*?)\.(.*?)$/); next if ($oid !~ /^(.*)\.(.*?)\.(.*?)$/);
my ($base, $instance) = ($1 . '.' . $2, $3); my ($base, $instance) = ($1 . '.' . $2, $3);
next if (!defined($oids->{$base})); next if (!defined($oids->{$base}));
next if ($results->{$oid} !~ /\d/ || $results->{$oid} == 0); next if ($results->{$oid} !~ /\d/ || $results->{$oid} == 0);
$self->{line}->{$instance} = { display => $instance } if (!defined($self->{line}->{$instance})); $self->{line}->{$instance} = { display => $instance } if (!defined($self->{line}->{$instance}));
$self->{line}->{$instance}->{$oids->{$base}->{name}} = $results->{$oid} * $oids->{$base}->{factor}; $self->{line}->{$instance}->{$oids->{$base}->{name}} = $results->{$oid} * $oids->{$base}->{factor};
} }
@ -121,7 +115,7 @@ __END__
=head1 MODE =head1 MODE
Check Input lines metrics (frequence, voltage, current and true power). Check input lines metrics (frequence, voltage, current and true power).
=over 8 =over 8
@ -130,14 +124,9 @@ Check Input lines metrics (frequence, voltage, current and true power).
Only display some counters (regexp can be used). Only display some counters (regexp can be used).
Example: --filter-counters='^power$' Example: --filter-counters='^power$'
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold warning. Thresholds.
Can be: 'frequence', 'voltage', 'current', 'power'.
=item B<--critical-*>
Threshold critical.
Can be: 'frequence', 'voltage', 'current', 'power'. Can be: 'frequence', 'voltage', 'current', 'power'.
=back =back

View File

@ -82,7 +82,7 @@ sub set_counters {
sub new { sub new {
my ($class, %options) = @_; 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; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {

View File

@ -20,52 +20,65 @@
package hardware::ups::standard::rfc1628::snmp::mode::outputsource; package hardware::ups::standard::rfc1628::snmp::mode::outputsource;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
my %outputsource_status = ( sub custom_status_output {
1 => ['other', 'UNKNOWN'], my ($self, %options) = @_;
2 => ['none', 'CRITICAL'],
3 => ['normal', 'OK'], return sprintf("Output source status is '%s'", $self->{result_values}->{status});
4 => ['bypass', 'WARNING'], }
5 => ['battery', 'WARNING'],
6 => ['booster', 'WARNING'], sub set_counters {
7 => ['reducer', 'WARNING'], 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 { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {});
{
});
return $self; return $self;
} }
sub check_options { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub run { my $map_status = {
my ($self, %options) = @_; 1 => 'other', 2 => 'none',
$self->{snmp} = $options{snmp}; 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 $oid_upsOutputSource = '.1.3.6.1.2.1.33.1.4.1.0';
my $snmp_result = $options{snmp}->get_leef(oids => [$oid_upsOutputSource], nothing_quit => 1);
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]));
$self->{output}->display(); $self->{global} = { status => $map_status->{ $snmp_result->{$oid_upsOutputSource} } };
$self->{output}->exit();
} }
1; 1;
@ -78,6 +91,21 @@ Check output source status.
=over 8 =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 =back
=cut =cut

View File

@ -29,7 +29,6 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$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',