Debian Codegraph @

src/network/nokia/timos/snmp/mode/isisusage.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::nokia::timos::snmp::mode::isisusage;
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);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 my $msg = 'state : ' . $self->{result_values}->{oper_state} . ' (admin: ' . $self->{result_values}->{admin_state} . ')';
33 return $msg;
34 }
35
36 sub custom_status_calc {
37 my ($self, %options) = @_;
38
39 $self->{result_values}->{oper_state} = $options{new_datas}->{$self->{instance} . '_oper_state'};
40 $self->{result_values}->{admin_state} = $options{new_datas}->{$self->{instance} . '_admin_state'};
41 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
42 return 0;
43 }
44
45
46 sub custom_total_sessions_calc {
47 my ($self, %options) = @_;
48
49 my $total_sessions = 0;
50 foreach (keys %{$options{new_datas}}) {
51 if (/$self->{instance}_total_sessions_(\d+)/) {
52 my $new_total = $options{new_datas}->{$_};
53 next if (!defined($options{old_datas}->{$_}));
54 my $old_total = $options{old_datas}->{$_};
55
56 $total_sessions += $new_total - $old_total;
57 $total_sessions += $old_total if ($total_sessions <= 0);
58 }
59 }
60
61 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
62 $self->{result_values}->{total_sessions} = $total_sessions;
63
64 return 0;
65 }
66
67 sub set_counters {
68 my ($self, %options) = @_;
69
70 $self->{maps_counters_type} = [
71 { name => 'isis', type => 1, cb_prefix_output => 'prefix_isis_output', message_multiple => 'All IS-IS instances are ok' },
72 { name => 'int', type => 1, cb_prefix_output => 'prefix_int_output', message_multiple => 'All interfaces are ok' },
73 ];
74 $self->{maps_counters}->{int} = [
75 { label => 'status', threshold => 0, set => {
76 key_values => [ { name => 'oper_state' }, { name => 'admin_state' }, { name => 'display' } ],
77 closure_custom_calc => $self->can('custom_status_calc'),
78 closure_custom_output => $self->can('custom_status_output'),
79 closure_custom_perfdata => sub { return 0; },
80 closure_custom_threshold_check => \&catalog_status_threshold,
81 }
82 },
83 ];
84
85 $self->{maps_counters}->{isis} = [
86 { label => 'total-int-inservice', set => {
87 key_values => [ { name => 'inService' }, { name => 'display' } ],
88 output_template => 'Total Interfaces InServices : %s',
89 perfdatas => [
90 { label => 'total_int_inservice', value => 'inService', template => '%s',
91 min => 0, label_extra_instance => 1, instance_use => 'display' },
92 ],
93 }
94 },
95 { label => 'total-int-outservice', set => {
96 key_values => [ { name => 'outOfService' }, { name => 'display' } ],
97 output_template => 'Total Interfaces OutOfServices : %s',
98 perfdatas => [
99 { label => 'total_int_outservice', value => 'outOfService', template => '%s',
100 min => 0, label_extra_instance => 1, instance_use => 'display' },
101 ],
102 }
103 },
104 ];
105 }
106
107 sub prefix_isis_output {
108 my ($self, %options) = @_;
109
110 return "IS-IS instance '" . $options{instance_value}->{display} . "' ";
111 }
112
113 sub prefix_int_output {
114 my ($self, %options) = @_;
115
116 return "Interface '" . $options{instance_value}->{display} . "' ";
117 }
118
119 sub new {
120 my ($class, %options) = @_;
121 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
122 bless $self, $class;
123
124 $options{options}->add_options(arguments =>
125 {
126 "filter-name:s" => { name => 'filter_name' },
127 "warning-status:s" => { name => 'warning_status', default => '' },
128 "critical-status:s" => { name => 'critical_status', default => '%{admin_state} eq "inService" and %{oper_state} !~ /inService|transition/' },
129 });
130
131 return $self;
132 }
133
134 sub check_options {
135 my ($self, %options) = @_;
136 $self->SUPER::check_options(%options);
137
138 $self->change_macros(macros => ['warning_status', 'critical_status']);
139 }
140
141 my %map_admin_status = (1 => 'noop', 2 => 'inService', 3 => 'outOfService');
142 my %map_oper_status = (1 => 'unknown', 2 => 'inService', 3 => 'outOfService', 4 => 'transition');
143
144 my $oid_vRtrName = '.1.3.6.1.4.1.6527.3.1.2.3.1.1.4';
145 my $oid_ifName = '.1.3.6.1.2.1.31.1.1.1.1';
146 # index = vRtrID + isisInstance + ifIndex
147 my $mapping = {
148 tmnxIsisIfAdminState => { oid => '.1.3.6.1.4.1.6527.3.1.2.88.2.1.1.3', map => \%map_admin_status },
149 tmnxIsisIfOperState => { oid => '.1.3.6.1.4.1.6527.3.1.2.88.2.1.1.4', map => \%map_oper_status },
150 };
151
152 sub manage_selection {
153 my ($self, %options) = @_;
154
155 my $snmp_result = $options{snmp}->get_multiple_table(oids => [
156 { oid => $oid_vRtrName },
157 { oid => $oid_ifName },
158 { oid => $mapping->{tmnxIsisIfAdminState}->{oid} },
159 { oid => $mapping->{tmnxIsisIfOperState}->{oid} },
160 ], return_type => 1, nothing_quit => 1);
161 $self->{isis} = {};
162 $self->{int} = {};
163 foreach my $oid (keys %$snmp_result) {
164 next if ($oid !~ /^$mapping->{tmnxIsisIfOperState}->{oid}\.(\d+)\.(\d+)\.(\d+)$/);
165 my ($vrtr_id, $isis_id, $ifindex) = ($1, $2, $3);
166
167 my $vrtr_name = $snmp_result->{$oid_vRtrName . '.' . $vrtr_id};
168 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $vrtr_id . '.' . $isis_id . '.' . $ifindex);
169 my $name = $vrtr_name . '.' . $isis_id;
170 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
171 $name !~ /$self->{option_results}->{filter_name}/) {
172 $self->{output}->output_add(long_msg => "skipping '" . $name . "'.", debug => 1);
173 next;
174 }
175
176 $self->{isis}->{$vrtr_id . '.' . $isis_id} = { display => $name, inService => 0, outOfService => 0 } if (!defined($self->{isis}->{$vrtr_id . '.' . $isis_id}));
177 $self->{isis}->{$vrtr_id . '.' . $isis_id}->{$result->{tmnxIsisIfOperState}}++;
178
179 $self->{int}->{$vrtr_id . '.' . $isis_id . '.' . $ifindex} = {
180 display => $name . '.' . $snmp_result->{$oid_ifName . '.' . $ifindex},
181 admin_state => $result->{tmnxIsisIfAdminState},
182 oper_state => $result->{tmnxIsisIfOperState},
183 };
184 }
185
186 if (scalar(keys %{$self->{isis}}) <= 0) {
187 $self->{output}->add_option_msg(short_msg => "No IS-IS intance found.");
188 $self->{output}->option_exit();
189 }
190 }
191
192 1;
193
194 __END__
195
196 =head1 MODE
197
198 Check IS-IS usage.
199
200 =over 8
201
202 =item B<--warning-*>
203
204 Warning threshold.
205 Can be: 'total-int-inservice', 'total-int-outservice'.
206
207 =item B<--critical-*>
208
209 Critical threshold.
210 Can be: 'total-int-inservice', 'total-int-outservice'.
211
212 =item B<--warning-status>
213
214 Define the conditions to match for the status to be WARNING.
215 You can use the following variables: %{display}, %{oper_state}, %{admin_state}.
216
217 =item B<--critical-status>
218
219 Define the conditions to match for the status to be CRITICAL (default: '%{admin_state} eq "inService" and %{oper_state} !~ /inService|transition/').
220 You can use the following variables: %{display}, %{oper_state}, %{admin_state}.
221
222 =item B<--filter-name>
223
224 Filter by instance name (can be a regexp).
225
226 =back
227
228 =cut