Debian Codegraph @

src/network/citrix/sdx/snmp/mode/hardware.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::citrix::sdx::snmp::mode::hardware;
22
23 use base qw(centreon::plugins::templates::hardware);
24
25 sub set_system {
26 my ($self, %options) = @_;
27
28 $self->{cb_hook2} = 'snmp_execute';
29
30 $self->{thresholds} = {
31 default => [
32 ['OK', 'OK'],
33 ['ERROR', 'CRITICAL']
34 ]
35 };
36
37 $self->{components_path} = 'network::citrix::sdx::snmp::mode::components';
38 $self->{components_module} = ['hardware', 'software'];
39 }
40
41 sub new {
42 my ($class, %options) = @_;
43 my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1);
44 bless $self, $class;
45
46 $options{options}->add_options(arguments => {});
47
48 return $self;
49 }
50
51 sub snmp_execute {
52 my ($self, %options) = @_;
53
54 $self->{snmp} = $options{snmp};
55 $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
56 }
57
58 1;
59
60 =head1 MODE
61
62 Check hardware.
63
64 =over 8
65
66 =item B<--component>
67
68 Which component to check (default: '.*').
69 Can be: 'hardware', 'software'.
70
71 =item B<--filter>
72
73 Exclude some parts (comma separated list)
74 You can also exclude items from specific instances: --filter=hardware,name
75
76 =item B<--no-component>
77
78 Define the expected status if no components are found (default: critical).
79
80
81 =item B<--threshold-overload>
82
83 Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp).
84 Example: --threshold-overload='hardware,WARNING,ERROR'
85
86 =back
87
88 =cut
89
90 package network::citrix::sdx::snmp::mode::components::hardware;
91
92 use strict;
93 use warnings;
94
95 my $mapping_hw = {
96 hardwareResourceName => { oid => '.1.3.6.1.4.1.5951.6.2.1000.1.1.1' },
97 hardwareResourceStatus => { oid => '.1.3.6.1.4.1.5951.6.2.1000.1.1.7' },
98 };
99
100 sub load {
101 my ($self) = @_;
102
103 push @{$self->{request}}, { oid => $mapping_hw->{hardwareResourceName}->{oid} },
104 { oid => $mapping_hw->{hardwareResourceStatus}->{oid} };
105 }
106
107 sub check {
108 my ($self) = @_;
109
110 $self->{output}->output_add(long_msg => "Checking hardware");
111 $self->{components}->{hardware} = {name => 'hardware', total => 0, skip => 0};
112 return if ($self->check_filter(section => 'hardware'));
113
114 my $datas = { %{$self->{results}->{ $mapping_hw->{hardwareResourceStatus}->{oid} }}, %{$self->{results}->{ $mapping_hw->{hardwareResourceName}->{oid} }} };
115 foreach ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping_hw->{hardwareResourceStatus}->{oid} }})) {
116 /^$mapping_hw->{hardwareResourceStatus}->{oid}\.(.*)$/;
117 my $instance = $1;
118 my $result = $self->{snmp}->map_instance(mapping => $mapping_hw, results => $datas, instance => $instance);
119
120 next if ($self->check_filter(section => 'hardware', instance => $result->{hardwareResourceName}));
121
122 $self->{components}->{hardware}->{total}++;
123 $self->{output}->output_add(long_msg => sprintf("hardware '%s' status is '%s' [instance = %s]",
124 $result->{hardwareResourceName}, $result->{hardwareResourceStatus}, $result->{hardwareResourceName}));
125 my $exit = $self->get_severity(label => 'default', section => 'hardware', value => $result->{hardwareResourceStatus});
126 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
127 $self->{output}->output_add(severity => $exit,
128 short_msg => sprintf("Hardware '%s' status is '%s'", $result->{hardwareResourceName}, $result->{hardwareResourceStatus}));
129 }
130 }
131 }
132
133 1;
134
135 package network::citrix::sdx::snmp::mode::components::software;
136
137 use strict;
138 use warnings;
139
140 my $mapping_soft = {
141 softwareResourceName => { oid => '.1.3.6.1.4.1.5951.6.2.1000.2.1.1' },
142 softwareResourceStatus => { oid => '.1.3.6.1.4.1.5951.6.2.1000.2.1.7' },
143 };
144
145 sub load {
146 my ($self) = @_;
147
148 push @{$self->{request}}, { oid => $mapping_soft->{softwareResourceName}->{oid} },
149 { oid => $mapping_soft->{softwareResourceStatus}->{oid} };
150 }
151
152 sub check {
153 my ($self) = @_;
154
155 $self->{output}->output_add(long_msg => "Checking software");
156 $self->{components}->{software} = {name => 'software', total => 0, skip => 0};
157 return if ($self->check_filter(section => 'software'));
158
159 my $datas = { %{$self->{results}->{ $mapping_soft->{softwareResourceStatus}->{oid} }}, %{$self->{results}->{ $mapping_soft->{softwareResourceName}->{oid} }} };
160 foreach ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping_soft->{softwareResourceStatus}->{oid} }})) {
161 /^$mapping_soft->{softwareResourceStatus}->{oid}\.(.*)$/;
162 my $instance = $1;
163 my $result = $self->{snmp}->map_instance(mapping => $mapping_soft, results => $datas, instance => $instance);
164
165 next if ($self->check_filter(section => 'software', instance => $result->{softwareResourceName}));
166
167 $self->{components}->{software}->{total}++;
168 $self->{output}->output_add(long_msg => sprintf("software '%s' status is '%s' [instance = %s]",
169 $result->{softwareResourceName}, $result->{softwareResourceStatus}, $result->{softwareResourceName}));
170 my $exit = $self->get_severity(label => 'default', section => 'software', value => $result->{softwareResourceStatus});
171 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
172 $self->{output}->output_add(severity => $exit,
173 short_msg => sprintf("Software '%s' status is '%s'", $result->{softwareResourceName}, $result->{softwareResourceStatus}));
174 }
175 }
176 }
177
178 1;