Debian Codegraph @

src/hardware/server/cisco/ucs/snmp/mode/mgmtentities.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 hardware::server::cisco::ucs::snmp::mode::mgmtentities;
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 'status: %s [role: %s][services status: %s]',
34 $self->{result_values}->{status},
35 $self->{result_values}->{role},
36 $self->{result_values}->{services_status}
37 );
38 }
39
40 sub prefix_mgmt_output {
41 my ($self, %options) = @_;
42
43 return sprintf(
44 "Management entity '%s' ",
45 $options{instance_value}->{dn}
46 );
47 }
48
49 sub prefix_global_output {
50 my ($self, %options) = @_;
51
52 return 'Management entities ';
53 }
54
55 sub set_counters {
56 my ($self, %options) = @_;
57
58 $self->{maps_counters_type} = [
59 { name => 'global', cb_prefix_output => 'prefix_global_output', type => 0 },
60 { name => 'mgmt', type => 1, cb_prefix_output => 'prefix_mgmt_output', message_multiple => 'All management entities are ok' }
61 ];
62
63 $self->{maps_counters}->{global} = [
64 { label => 'total', nlabel => 'management_entities.total.count', display_ok => 0, set => {
65 key_values => [ { name => 'total' } ],
66 output_template => 'total: %s',
67 perfdatas => [
68 { template => '%s', min => 0 }
69 ]
70 }
71 }
72 ];
73
74 $self->{maps_counters}->{mgmt} = [
75 {
76 label => 'status', type => 2,
77 unknown_default => '%{role} =~ /unknown/ or %{status} eq "unknown" or %{services_status} eq "unknown"',
78 critical_default => '%{role} =~ /electionFailed|inapplicable/ or %{status} eq "down" or %{services_status} eq "down"',
79 set => {
80 key_values => [
81 { name => 'dn' }, { name => 'role' },
82 { name => 'services_status' }, { name => 'status' },
83 ],
84 closure_custom_output => $self->can('custom_status_output'),
85 closure_custom_perfdata => sub { return 0; },
86 closure_custom_threshold_check => \&catalog_status_threshold_ng
87 }
88 }
89 ];
90 }
91
92 sub new {
93 my ($class, %options) = @_;
94 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
95 bless $self, $class;
96
97 $options{options}->add_options(arguments => {
98 });
99
100 return $self;
101 }
102
103 my $map_role = {
104 0 => 'unknown', 1 => 'primary',
105 2 => 'subordinate', 3 => 'inapplicable',
106 4 => 'electionInProgress', 5 => 'electionFailed'
107 };
108 my $map_state = {
109 0 => 'unknown', 1 => 'up', 2 => 'down'
110 };
111 my $map_services_state = {
112 0 => 'unknown', 1 => 'up', 2 => 'unresponsive', 3 => 'down', 4 => 'switchoverInProgress'
113 };
114
115 my $mapping = {
116 dn => { oid => '.1.3.6.1.4.1.9.9.719.1.31.8.1.2' }, # cucsMgmtEntityDn
117 role => { oid => '.1.3.6.1.4.1.9.9.719.1.31.8.1.14', map => $map_role }, # cucsMgmtEntityLeadership
118 services_status => { oid => '.1.3.6.1.4.1.9.9.719.1.31.8.1.15', map => $map_services_state }, # cucsMgmtEntityMgmtServicesState
119 status => { oid => '.1.3.6.1.4.1.9.9.719.1.31.8.1.17', map => $map_state } # cucsMgmtEntityState
120 };
121
122 sub manage_selection {
123 my ($self, %options) = @_;
124
125 my $snmp_result = $options{snmp}->get_multiple_table(
126 oids => [ map({ oid => $_->{oid} }, values(%$mapping)) ],
127 return_type => 1,
128 nothing_quit => 1
129 );
130
131 $self->{global} = { total => 0, online => 0, offline => 0 };
132 $self->{mgmt} = {};
133 foreach my $oid (keys %$snmp_result) {
134 next if ($oid !~ /^$mapping->{dn}->{oid}\.(.*)$/);
135 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1);
136 $self->{mgmt}->{ $result->{dn} } = $result;
137 $self->{global}->{total}++;
138 }
139 }
140
141 1;
142
143 __END__
144
145 =head1 MODE
146
147 Check management entities.
148
149 =over 8
150
151 =item B<--unknown-status>
152
153 Define the conditions to match for the status to be UNKNOWN (default: '%{role} =~ /unknown/ or %{status} eq "unknown" or %{services_status} eq "unknown"')
154 You can use the following variables: %{dn}, %{role}, %{services_status}, %{status}
155
156 =item B<--warning-status>
157
158 Define the conditions to match for the status to be WARNING.
159 You can use the following variables: %{dn}, %{role}, %{services_status}, %{status}
160
161 =item B<--critical-status>
162
163 Define the conditions to match for the status to be CRITICAL (default: '%{role} =~ /electionFailed|inapplicable/ or %{status} eq "down" or %{services_status} eq "down"').
164 You can use the following variables: %{dn}, %{role}, %{services_status}, %{status}
165
166 =item B<--warning-*> B<--critical-*>
167
168 Thresholds.
169 Can be: 'total'.
170
171 =back
172
173 =cut