Debian Codegraph @

src/storage/bdt/multistak/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 storage::bdt::multistak::snmp::mode::hardware;
22
23 use base qw(centreon::plugins::templates::hardware);
24
25 use strict;
26 use warnings;
27
28 sub set_system {
29 my ($self, %options) = @_;
30
31 $self->{cb_hook1} = 'get_system_information';
32 $self->{cb_hook2} = 'snmp_execute';
33
34 $self->{thresholds} = {
35 health => [
36 ['ok', 'OK'],
37 ['unknown', 'UNKNOWN'],
38 ['warning', 'WARNING'],
39 ['critical', 'CRITICAL']
40 ],
41 status => [
42 ['OK', 'OK'],
43 ['N/A', 'OK'],
44 ['.*', 'CRITICAL']
45 ]
46 };
47
48 $self->{components_path} = 'storage::bdt::multistak::snmp::mode::components';
49 $self->{components_module} = ['device', 'module'];
50 }
51
52 sub new {
53 my ($class, %options) = @_;
54 my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, force_new_perfdata => 1);
55 bless $self, $class;
56
57 $options{options}->add_options(arguments => {});
58
59 return $self;
60 }
61
62 sub get_system_information {
63 my ($self, %options) = @_;
64
65 my $oid_vendor = '.1.3.6.1.4.1.20884.1.1.0'; # bdtDeviceDatVendor
66 my $oid_product_id = '.1.3.6.1.4.1.20884.1.2.0'; # bdtDeviceDatVendor
67 my $oid_serial = '.1.3.6.1.4.1.20884.1.3.0'; # bdtDeviceDatSerialNum
68 my $oid_revision = '.1.3.6.1.4.1.20884.1.4.0'; # bdtDeviceDatSWRevision
69 my $result = $options{snmp}->get_leef(
70 oids => [
71 $oid_vendor, $oid_product_id,
72 $oid_serial, $oid_revision
73 ]
74 );
75
76 my $vendor = defined($result->{$oid_vendor}) ? centreon::plugins::misc::trim($result->{$oid_vendor}) : 'unknown';
77 my $product_id = defined($result->{$oid_product_id}) ? centreon::plugins::misc::trim($result->{$oid_product_id}) : 'unknown';
78 my $serial = defined($result->{$oid_serial}) ? centreon::plugins::misc::trim($result->{$oid_serial}) : 'unknown';
79 my $revision = defined($result->{$oid_revision}) ? centreon::plugins::misc::trim($result->{$oid_revision}) : 'unknown';
80 $self->{output}->output_add(
81 long_msg => sprintf(
82 'vendor: %s, product: %s, serial: %s, revision: %s',
83 $vendor, $product_id, $serial, $revision
84 )
85 );
86 }
87
88 sub snmp_execute {
89 my ($self, %options) = @_;
90
91 $self->{snmp} = $options{snmp};
92 $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request});
93 }
94
95 1;
96
97 __END__
98
99 =head1 MODE
100
101 Check hardware.
102
103 =over 8
104
105 =item B<--component>
106
107 Which component to check (default: '.*').
108 Can be: 'module', 'device'.
109
110 =item B<--filter>
111
112 Exclude the items given as a comma-separated list (example: --filter=disk --filter=psu).
113 You can also exclude items from specific instances: --filter=module,1
114
115 =item B<--no-component>
116
117 Define the expected status if no components are found (default: critical).
118
119 =item B<--threshold-overload>
120
121 Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,[instance,]status,regexp).
122 Example: --threshold-overload='module,WARNING,N/A'
123
124 =back
125
126 =cut