enh(juniper/ssg): nsrp mode - change OIDs management (#3171)

This commit is contained in:
qgarnier 2021-10-01 13:24:45 +02:00 committed by GitHub
parent 0825667706
commit 04ea20a3ce

View File

@ -25,14 +25,15 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("status: %s", return sprintf(
$self->{result_values}->{status}); "status: %s",
return $msg; $self->{result_values}->{status}
);
} }
sub custom_status_calc { sub custom_status_calc {
@ -48,42 +49,6 @@ sub custom_status_calc {
return 0; return 0;
} }
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'nsrp', type => 3, cb_prefix_output => 'prefix_nsrp_output', cb_long_output => 'nsrp_long_output', indent_long_output => ' ', message_multiple => 'All nsrp groups are ok',
group => [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'member', cb_prefix_output => 'prefix_member_output', message_multiple => 'All members are ok', type => 1, skipped_code => { -10 => 1 } },
]
}
];
$self->{maps_counters}->{global} = [
{ label => 'group-transition-change', nlabel => 'nsrp.group.transition.change.count', set => {
key_values => [ { name => 'nsrpVsdGroupCntStateChange', diff => 1 } ],
output_template => 'number of state transition events: %s',
perfdatas => [
{ value => 'nsrpVsdGroupCntStateChange', template => '%s',
min => 0, label_extra_instance => 1 },
],
}
},
];
$self->{maps_counters}->{member} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
}
},
];
}
sub prefix_nsrp_output { sub prefix_nsrp_output {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -102,82 +67,109 @@ sub prefix_member_output {
return "member '" . $options{instance_value}->{display} . "' "; return "member '" . $options{instance_value}->{display} . "' ";
} }
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'nsrp', type => 3, cb_prefix_output => 'prefix_nsrp_output', cb_long_output => 'nsrp_long_output', indent_long_output => ' ', message_multiple => 'All nsrp groups are ok',
group => [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'member', cb_prefix_output => 'prefix_member_output', message_multiple => 'All members are ok', type => 1, skipped_code => { -10 => 1 } }
]
}
];
$self->{maps_counters}->{global} = [
{ label => 'group-transition-change', nlabel => 'nsrp.group.transition.change.count', set => {
key_values => [ { name => 'cnt_state_change', diff => 1 } ],
output_template => 'number of state transition events: %s',
perfdatas => [
{ template => '%s', min => 0, label_extra_instance => 1 }
]
}
}
];
$self->{maps_counters}->{member} = [
{
label => 'status',
type => 2,
unknown_default => '%{status} =~ /undefined/i',
critical_default => '%{status} =~ /ineligible|inoperable/i',
set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
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, statefile => 1, force_new_perfdata => 1); my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'unknown-status:s' => { name => 'unknown_status', default => '%{status} =~ /undefined/i' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /ineligible|inoperable/i' },
}); });
return $self; return $self;
} }
sub check_options { my $map_status = {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
}
my %map_status = (
0 => 'undefined', 0 => 'undefined',
1 => 'init', 1 => 'init',
2 => 'master', 2 => 'master',
3 => 'primary-backup', 3 => 'primary-backup',
4 => 'backup', 4 => 'backup',
5 => 'ineligible', 5 => 'ineligible',
6 => 'inoperable', 6 => 'inoperable'
); };
my $mapping = { my $mapping = {
nsrpVsdMemberStatus => { oid => '.1.3.6.1.4.1.3224.6.2.2.1.3', map => \%map_status }, group_id => { oid => '.1.3.6.1.4.1.3224.6.2.2.1.1' }, # nsrpVsdMemberGroupId
member_id => { oid => '.1.3.6.1.4.1.3224.6.2.2.1.2' }, # nsrpVsdMemberUnitId
member_status => { oid => '.1.3.6.1.4.1.3224.6.2.2.1.3', map => $map_status } # nsrpVsdMemberStatus
}; };
my $mapping2 = { my $mapping2 = {
nsrpVsdGroupCntStateChange => { oid => '.1.3.6.1.4.1.3224.6.2.1.1.6' }, cnt_state_change => { oid => '.1.3.6.1.4.1.3224.6.2.1.1.6' } # nsrpVsdGroupCntStateChange
nsrpVsdGroupCntToInit => { oid => '.1.3.6.1.4.1.3224.6.2.1.1.7' },
nsrpVsdGroupCntToMaster => { oid => '.1.3.6.1.4.1.3224.6.2.1.1.8' },
}; };
my $oid_nsrpVsdGroupEntry = '.1.3.6.1.4.1.3224.6.2.1.1'; my $oid_member_entry = '.1.3.6.1.4.1.3224.6.2.2.1'; # nsrpVsdMemberEntry
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{nsrp} = {};
my $snmp_result = $options{snmp}->get_multiple_table( my $snmp_result = $options{snmp}->get_multiple_table(
oids => [ oids => [
{ oid => $mapping->{nsrpVsdMemberStatus}->{oid} }, { oid => $mapping2->{cnt_state_change}->{oid} },
{ oid => $oid_nsrpVsdGroupEntry, start => $mapping2->{nsrpVsdGroupCntStateChange}->{oid}, end => $mapping2->{nsrpVsdGroupCntToMaster}->{oid} }, { oid => $oid_member_entry, end => $mapping->{member_status}->{oid} }
], ],
nothing_quit => 1 nothing_quit => 1
); );
foreach my $oid (keys %{$snmp_result->{ $mapping->{nsrpVsdMemberStatus}->{oid} }}) { $self->{nsrp} = {};
$oid =~ /^$mapping->{nsrpVsdMemberStatus}->{oid}\.(\d+)\.(\d+)$/; foreach my $oid (keys %{$snmp_result->{$oid_member_entry}}) {
my ($group_id, $member_id) = ($1, $2); next if ($oid !~ /^$mapping->{member_status}->{oid}\.(.*?)$/);
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{ $mapping->{nsrpVsdMemberStatus}->{oid} }, instance => $group_id . '.' . $member_id); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_member_entry}, instance => $1);
if (!defined($self->{nsrp}->{$group_id})) { if (!defined($self->{nsrp}->{ $result->{group_id} })) {
my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_nsrpVsdGroupEntry}, instance => $group_id); my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{ $mapping2->{cnt_state_change}->{oid} }, instance => $result->{group_id});
$self->{nsrp}->{$group_id} = { $self->{nsrp}->{ $result->{group_id} } = {
display => $group_id, display => $result->{group_id},
global => { global => $result2,
%$result2
},
member => {}, member => {},
}; };
} }
$self->{nsrp}->{$group_id}->{member}->{$member_id} = { $self->{nsrp}->{ $result->{group_id} }->{member}->{ $result->{member_id} } = {
display => $member_id, display => $result->{member_id},
status => $result->{nsrpVsdMemberStatus}, status => $result->{member_status}
}; };
} }
$self->{cache_name} = "juniper_screenos_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{cache_name} = 'juniper_screenos_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
} }
@ -193,12 +185,12 @@ Check nsrp groups.
=item B<--unknown-status> =item B<--unknown-status>
Set warning threshold for status (Default: '%{status} =~ /undefined/i'). Set unknown threshold for status (Default: '%{status} =~ /undefined/i').
Can used special variables like: %{status}, %{statusLast} Can used special variables like: %{status}, %{statusLast}
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status (Default: ''). Set warning threshold for status.
Can used special variables like: %{status}, %{statusLast} Can used special variables like: %{status}, %{statusLast}
=item B<--critical-status> =item B<--critical-status>