Debian Codegraph @

src/network/nokia/timos/snmp/mode/sasalarm.pm

raw
1 #
2 # Copyright 2023 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::nokia::timos::snmp::mode::sasalarm;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
29
30 sub prefix_output {
31 my ($self, %options) = @_;
32
33 return "Alarm input '" . $options{instance_value}->{display} . "' ";
34 }
35
36 sub custom_status_output {
37 my ($self, %options) = @_;
38
39 my $msg = 'Alarm input status : ' . $self->{result_values}->{alarm_input_status}
40 . ' (Alarm input admin state: ' . $self->{result_values}->{alarm_input_admin_state}
41 . ' (Alarm output severity: ' . $self->{result_values}->{alarm_output_severity}
42 . ')';
43 return $msg;
44 }
45
46 sub custom_status_calc {
47 my ($self, %options) = @_;
48
49 $self->{result_values}->{alarm_output_severity} = $options{new_datas}->{$self->{instance} . '_alarm_output_severity'};
50 $self->{result_values}->{alarm_input_status} = $options{new_datas}->{$self->{instance} . '_alarm_input_status'};
51 $self->{result_values}->{alarm_input_admin_state} = $options{new_datas}->{$self->{instance} . '_alarm_input_admin_state'};
52 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
53 return 0;
54 }
55
56 sub set_counters {
57 my ($self, %options) = @_;
58
59 $self->{maps_counters_type} = [
60 {
61 name => 'sas_alarm_input',
62 type => 1,
63 cb_prefix_output => 'prefix_output',
64 message_multiple => 'All sas alarm inputs are ok'
65 }
66 ];
67
68 $self->{maps_counters}->{sas_alarm_input} = [
69 { label => 'status', threshold => 0, set => {
70 key_values =>
71 [
72 { name => 'alarm_output_severity' },
73 { name => 'alarm_input_status' },
74 { name => 'alarm_input_admin_state' },
75 { name => 'display' }
76 ],
77 closure_custom_calc =>
78 $self->can('custom_status_calc'),
79 closure_custom_output =>
80 $self->can('custom_status_output'),
81 closure_custom_perfdata =>
82 sub {return 0;},
83 closure_custom_threshold_check =>
84 \&catalog_status_threshold,
85 }
86 },
87 ]
88 }
89
90 sub new {
91 my ($class, %options) = @_;
92 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
93 bless $self, $class;
94
95 $options{options}->add_options(arguments =>
96 {
97 "filter-name:s" =>
98 { name => 'filter_name' },
99 "warning-status:s" =>
100 { name =>
101 'warning_status',
102 default =>
103 '%{alarm_input_admin_state} eq "up" and %{alarm_input_status} eq "alarm" and %{alarm_output_severity} =~ /minor/' },
104 "critical-status:s" =>
105 { name =>
106 'critical_status',
107 default =>
108 '%{alarm_input_admin_state} eq "up" and %{alarm_input_status} eq "alarm" and %{alarm_output_severity} =~ /major|critical/' },
109 });
110
111 return $self;
112 }
113
114 sub check_options {
115 my ($self, %options) = @_;
116 $self->SUPER::check_options(%options);
117
118 $self->change_macros(macros => [ 'warning_status', 'critical_status' ]);
119 }
120
121 my %alarm_output_severity = (1 => 'none', 2 => 'minor', 3 => 'major', 4 => 'critical');
122 my %alarm_input_status = (1 => 'noAlarm', 2 => 'alarm');
123 my %alarm_input_admin_state = (1 => 'up', 2 => 'down');
124
125 my $mapping = {
126 tmnxSasAlarmOutputSeverity => { oid => '.1.3.6.1.4.1.6527.6.2.2.2.9.1.1.5', map => \%alarm_output_severity },
127 tmnxSasAlarmInputDescription => { oid => '.1.3.6.1.4.1.6527.6.2.2.2.9.1.1.2' },
128 tmnxSasAlarmInputStatus => { oid => '.1.3.6.1.4.1.6527.6.2.2.2.9.1.1.6', map => \%alarm_input_status },
129 tmnxSasAlarmInputAdminState => { oid => '.1.3.6.1.4.1.6527.6.2.2.2.9.1.1.3', map => \%alarm_input_admin_state },
130 };
131
132 sub manage_selection {
133 my ($self, %options) = @_;
134
135 my $snmp_result = $options{snmp}->get_multiple_table(oids => [
136 { oid => $mapping->{tmnxSasAlarmInputDescription}->{oid} },
137 { oid => $mapping->{tmnxSasAlarmInputStatus}->{oid} },
138 { oid => $mapping->{tmnxSasAlarmInputAdminState}->{oid} },
139 { oid => $mapping->{tmnxSasAlarmOutputSeverity}->{oid} }
140 ],
141 return_type => 1,
142 nothing_quit => 1
143 );
144
145 $self->{sas_alarm_input} = {};
146 foreach my $oid (keys %{$snmp_result}) {
147 next if ($oid !~ /^$mapping->{tmnxSasAlarmOutputSeverity}->{oid}\.(.*)$/);
148 my $instance = $1;
149 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
150
151 if (!defined($result->{tmnxSasAlarmInputDescription}) || $result->{tmnxSasAlarmInputDescription} eq '') {
152 $result->{tmnxSasAlarmInputDescription} = "AlarmInput-Instance-$instance";
153 }
154 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
155 $result->{tmnxSasAlarmInputDescription} !~ /$self->{option_results}->{filter_name}/) {
156 $self->{output}->output_add(long_msg =>
157 "skipping Input '" . $result->{tmnxSasAlarmInputDescription} . "'.",
158 debug =>
159 1);
160 next;
161 }
162
163 $self->{sas_alarm_input}->{$instance} = {
164 display => $result->{tmnxSasAlarmInputDescription},
165 alarm_output_severity => $result->{tmnxSasAlarmOutputSeverity},
166 alarm_input_status => $result->{tmnxSasAlarmInputStatus},
167 alarm_input_admin_state => $result->{tmnxSasAlarmInputAdminState}
168 };
169
170 $self->{cache_name} = "nokia_timos_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
171 (defined($self->{option_results}->{filter_counters}) ?
172 md5_hex($self->{option_results}->{filter_counters}) :
173 md5_hex('all')) . '_' .
174 (defined($self->{option_results}->{filter_name}) ?
175 md5_hex($self->{option_results}->{filter_name}) :
176 md5_hex('all'));
177 }
178 }
179
180 1;
181
182 __END__
183
184 =head1 MODE
185
186 Check SAS alarm input usage.
187
188
189 =over 8
190
191 =item B<--warning-status>
192
193 Set warning threshold for status. (Default: '%{alarm_input_admin_state} eq "up" and %{alarm_input_status} eq "alarm" and %{alarm_output_severity} =~ /minor/')
194 You can use the following variables: %{alarm_input_admin_state}, %{alarm_input_status}, %{alarm_output_severity}
195
196 =item B<--critical-status>
197
198 Set critical threshold for status (Default: '%{alarm_input_admin_state} eq "up" and %{alarm_input_status} eq "alarm" and %{alarm_output_severity} =~ /major|critical/').
199 You can use the following variables: %{ipv4_oper_state}, %{admin_state}, %{display}
200
201 =item B<--filter-name>
202
203 Filter alarm input (tmnxSasAlarmInputDescription) (can be a regexp).
204
205 =back
206
207 =cut