Debian Codegraph @

src/network/digi/sarian/snmp/mode/gprs.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::digi::sarian::snmp::mode::gprs;
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 my $msg;
32
33 $msg = 'Attachement : ' . $self->{result_values}->{attachement};
34 $msg .= ', Registration : ' . $self->{result_values}->{registered};
35 return $msg;
36 }
37
38 sub custom_status_calc {
39 my ($self, %options) = @_;
40
41 $self->{result_values}->{registered} = $options{new_datas}->{$self->{instance} . '_registered'};
42 $self->{result_values}->{attachement} = $options{new_datas}->{$self->{instance} . '_attachement'};
43 return 0;
44 }
45
46 sub custom_tech_output {
47 my ($self, %options) = @_;
48 my $msg;
49
50 $msg = 'Technology : ' . $self->{result_values}->{technology};
51 return $msg;
52 }
53
54 sub custom_tech_calc {
55 my ($self, %options) = @_;
56
57 $self->{result_values}->{technology} = $options{new_datas}->{$self->{instance} . '_technology'};
58 return 0;
59 }
60
61 sub set_counters {
62 my ($self, %options) = @_;
63
64 $self->{maps_counters_type} = [
65 { name => 'gprs', type => 0 },
66 ];
67 $self->{maps_counters}->{gprs} = [
68 { label => 'signal', set => {
69 key_values => [ { name => 'signal' } ],
70 output_template => 'Signal : %d dBm',
71 perfdatas => [
72 { label => 'signal_strenght', value => 'signal', template => '%s',
73 unit => 'dBm' },
74 ],
75 }
76 },
77 { label => 'status', threshold => 0, set => {
78 key_values => [ { name => 'registered' }, { name => 'attachement' } ],
79 closure_custom_calc => $self->can('custom_status_calc'),
80 closure_custom_output => $self->can('custom_status_output'),
81 closure_custom_perfdata => sub { return 0; },
82 closure_custom_threshold_check => \&catalog_status_threshold,
83 }
84 },
85 { label => 'technology', threshold => 0, set => {
86 key_values => [ { name => 'technology' } ],
87 closure_custom_calc => $self->can('custom_tech_calc'),
88 closure_custom_output => $self->can('custom_tech_output'),
89 closure_custom_perfdata => sub { return 0; },
90 closure_custom_threshold_check => \&catalog_status_threshold,
91 }
92 },
93 ];
94 }
95
96 sub new {
97 my ($class, %options) = @_;
98 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
99 bless $self, $class;
100
101 $options{options}->add_options(arguments =>
102 {
103 "warning-status:s" => { name => 'warning_status', default => '' },
104 "critical-status:s" => { name => 'critical_status', default => '%{attachement} eq "notAttached" or %{registered} !~ /registeredHostNetwork|registeredRoaming/' },
105 "warning-technology:s" => { name => 'warning_technology', default => '' },
106 "critical-technology:s" => { name => 'critical_technology', default => '%{technology} !~ /2G|3G|4G/' },
107 });
108
109 return $self;
110 }
111
112 sub check_options {
113 my ($self, %options) = @_;
114 $self->SUPER::check_options(%options);
115
116 $self->change_macros(macros => ['warning_status', 'critical_status', 'warning_technology', 'critical_technology']);
117 }
118
119 my %map_gprs_registration = (
120 0 => 'notRegisteredNotSearching',
121 1 => 'registeredHostNetwork',
122 2 => 'notRegisteredSearching',
123 3 => 'registrationDenied',
124 4 => 'unknown',
125 5 => 'registeredRoaming',
126 6 => 'unrecognised',
127 );
128
129 my %map_gprs_attachement = (
130 0 => 'notAtached',
131 1 => 'attached',
132 );
133
134 my %map_gprs_technology = (
135 1 => 'unknown',
136 2 => 'GPRS(2G)',
137 3 => 'EDGE(2G)',
138 4 => 'UMTS(3G)',
139 5 => 'HSDPA(3G)',
140 6 => 'HSUPA(3G)',
141 7 => 'DC-HSPA+(3G)',
142 8 => 'LTE(4G)',
143 );
144
145 my $oid_gprsSignalStrength = '.1.3.6.1.4.1.16378.10000.2.1.0';
146 my $oid_gprsRegistered = '.1.3.6.1.4.1.16378.10000.2.2.0';
147 my $oid_gprsAttached = '.1.3.6.1.4.1.16378.10000.2.3.0';
148 my $oid_gprsNetworkTechnology = '.1.3.6.1.4.1.16378.10000.2.7.0';
149
150 sub manage_selection {
151 my ($self, %options) = @_;
152
153 $self->{gprs} = {};
154 $self->{results} = $options{snmp}->get_leef(oids => [ $oid_gprsSignalStrength, $oid_gprsRegistered,
155 $oid_gprsAttached, $oid_gprsNetworkTechnology ],
156 nothing_quit => 1);
157
158 $self->{gprs} = { signal => $self->{results}->{$oid_gprsSignalStrength},
159 registered => $map_gprs_registration{$self->{results}->{$oid_gprsRegistered}},
160 attachement => $map_gprs_attachement{$self->{results}->{$oid_gprsAttached}},
161 technology => $map_gprs_technology{$self->{results}->{$oid_gprsNetworkTechnology}},
162 };
163
164 }
165
166 1;
167
168 __END__
169
170 =head1 MODE
171
172 Check GPRS status.
173
174 =over 8
175
176 =item B<--filter-counters>
177
178 Only display some counters (regexp can be used).
179 Example: --filter-counters='signal|technology'
180
181 =item B<--warning-status>
182
183 Define the conditions to match for the status to be WARNING.
184 You can use the following variables: %{registered}, %{attachement}
185
186 =item B<--critical-status>
187
188 Define the conditions to match for the status to be CRITICAL (default: '%{attachement} eq "attached" and %{registered} !~ /registeredHostNetwork|registeredRoaming/'
189 You can use the following variables: %{registered}, %{attachement}
190
191 =item B<--warning-technology>
192
193 Set warning threshold for technology.
194 Use special variables %{technology}.
195
196 =item B<--critical-technology>
197
198 Set critical threshold for technology (default: '%{technology} !~ /2G|3G|4G/'
199 Use special variables %{technology}.
200
201 =item B<--warning-signal>
202
203 Warning threshold for signal strength.
204
205 =item B<--critical-signal>
206
207 Critical threshold for signal strength.
208
209 =back
210
211 =cut