Debian Codegraph @

src/network/hirschmann/standard/snmp/mode/configuration.pm

raw
1 #
2 # Copyright 2024 Centreon (http://www.centreon.com/)
3 #
4 # Centreon is a full-fledged industry-strength solution that meets
5 # the needs in IT infrastructure and application monitoring for
6 # service performance.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 package network::hirschmann::standard::snmp::mode::configuration;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 "configuration status is '%s'",
34 $self->{result_values}->{config_status}
35 );
36 }
37
38 sub set_counters {
39 my ($self, %options) = @_;
40
41 $self->{maps_counters_type} = [
42 { name => 'global', type => 0 }
43 ];
44
45 $self->{maps_counters}->{global} = [
46 { label => 'status', type => 2, warning_default => '%{config_status} =~ /notInSync|outOfSync/', set => {
47 key_values => [ { name => 'config_status' } ],
48 closure_custom_output => $self->can('custom_status_output'),
49 closure_custom_perfdata => sub { return 0; },
50 closure_custom_threshold_check => \&catalog_status_threshold_ng
51 }
52 }
53 ];
54 }
55
56 sub new {
57 my ($class, %options) = @_;
58 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
59 bless $self, $class;
60
61 $options{options}->add_options(arguments => {
62 });
63
64 return $self;
65 }
66
67 my $map_config_status = {
68 1 => 'ok', 2 => 'notInSync'
69 };
70 my $map_nvm_state = {
71 1 => 'ok', 2 => 'outOfSync', 3 => 'busy'
72 };
73
74 my $mapping = {
75 hios => {
76 config_status => { oid => '.1.3.6.1.4.1.248.11.21.1.3.1', map => $map_config_status } # hm2FMNvmState
77 },
78 classic => {
79 config_status => { oid => '.1.3.6.1.4.1.248.14.2.4.12', map => $map_config_status } # hmConfigurationStatus
80 }
81 };
82
83 sub check_config {
84 my ($self, %options) = @_;
85
86 my $result = $options{snmp}->map_instance(mapping => $mapping->{ $options{type} }, results => $options{snmp_result}, instance => 0);
87 return 0 if (!defined($result->{config_status}));
88
89 $self->{global} = $result;
90 }
91
92 sub manage_selection {
93 my ($self, %options) = @_;
94
95 my $snmp_result = $options{snmp}->get_leef(
96 oids => [ map($_->{oid} . '.0', values(%{$mapping->{hios}}), values(%{$mapping->{classic}})), ],
97 nothing_quit => 1
98 );
99 if ($self->check_config(snmp => $options{snmp}, type => 'hios', snmp_result => $snmp_result) == 0) {
100 $self->check_config(snmp => $options{snmp}, type => 'classic', snmp_result => $snmp_result);
101 }
102 }
103
104 1;
105
106 __END__
107
108 =head1 MODE
109
110 Check configuration status.
111
112 =over 8
113
114 =item B<--warning-status>
115
116 Define the conditions to match for the status to be WARNING (default : '%{config_status} =~ /notInSync|outOfSync/').
117 You can use the following variables: %{config_status}
118
119 =item B<--critical-status>
120
121 Define the conditions to match for the status to be CRITICAL.
122 You can use the following variables: %{config_status}
123
124 =back
125
126 =cut