Debian Codegraph @

src/network/sonus/sbc/snmp/mode/dspstats.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::sonus::sbc::snmp::mode::dspstats;
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_ng);
28
29 sub custom_state_output {
30 my ($self, %options) = @_;
31
32 return sprintf("state is '%s'", $self->{result_values}->{state});
33 }
34
35 sub prefix_dsp_output {
36 my ($self, %options) = @_;
37
38 return "DSP '" . $options{instance_value}->{display} . "' ";
39 }
40
41 sub set_counters {
42 my ($self, %options) = @_;
43
44 $self->{maps_counters_type} = [
45 { name => 'dsp', type => 1, cb_prefix_output => 'prefix_dsp_output', message_multiple => 'All DSP stats and states are ok' }
46 ];
47
48 $self->{maps_counters}->{dsp} = [
49 { label => 'status', type => 2, critical_default => '%{state} eq "down"', set => {
50 key_values => [ { name => 'state' }, { name => 'display' } ],
51 closure_custom_output => \&custom_state_output,
52 closure_custom_perfdata => sub { return 0; },
53 closure_custom_threshold_check => \&catalog_status_threshold_ng
54 }
55 },
56 { label => 'cpu-utilization', nlabel => 'dsp.cpu.utilization.percentage', set => {
57 key_values => [ { name => 'cpu' }, { name => 'display' } ],
58 output_template => 'CPU usage: %.2f %%',
59 perfdatas => [
60 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
61 ]
62 }
63 },
64 { label => 'channels-active', nlabel => 'dsp.channels.active.count', set => {
65 key_values => [ { name => 'channels' }, { name => 'display' } ],
66 output_template => 'active channels: %s',
67 perfdatas => [
68 { template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }
69 ]
70 }
71 }
72 ];
73 }
74
75 sub new {
76 my ($class, %options) = @_;
77 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
78 bless $self, $class;
79
80 $options{options}->add_options(arguments => {});
81
82 return $self;
83 }
84
85 my %map_status = (
86 0 => 'down',
87 1 => 'up'
88 );
89
90 my $mapping = {
91 uxDSPIsPresent => { oid => '.1.3.6.1.4.1.177.15.1.6.1.3' },
92 uxDSPCPUUsage => { oid => '.1.3.6.1.4.1.177.15.1.6.1.4' },
93 uxDSPChannelsInUse => { oid => '.1.3.6.1.4.1.177.15.1.6.1.5' },
94 uxDSPServiceStatus => { oid => '.1.3.6.1.4.1.177.15.1.6.1.6', map => \%map_status }
95 };
96 my $oid_uxDSPResourceTable = '.1.3.6.1.4.1.177.15.1.6.1';
97
98 sub manage_selection {
99 my ($self, %options) = @_;
100
101 my $snmp_result = $options{snmp}->get_table(
102 oid => $oid_uxDSPResourceTable,
103 nothing_quit => 1
104 );
105
106 foreach my $oid (keys %$snmp_result) {
107 next if($oid !~ /^$mapping->{uxDSPServiceStatus}->{oid}\.(.*)$/);
108 my $instance = $1;
109 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
110
111 next if ($result->{uxDSPIsPresent} eq '0');
112
113 $self->{dsp}->{$instance} = {
114 state => $result->{uxDSPServiceStatus},
115 cpu => $result->{uxDSPCPUUsage},
116 channels => $result->{uxDSPChannelsInUse},
117 display => $instance
118 };
119 }
120 }
121
122 1;
123
124 __END__
125
126 =head1 MODE
127
128 Check Digital Signal Processing statistics.
129
130 =over 8
131
132 =item B<--warning-*> B<--critical-*>
133
134 Thresholds. Can be: 'cpu-utilization', 'channels-active'.
135
136 =item B<--warning-status>
137
138 Define the conditions to match for the status to be WARNING.
139 You can use the following variables: %{state}, %{display}
140
141 =item B<--critical-status>
142
143 Define the conditions to match for the status to be CRITICAL (default: '%{state} eq "down"').
144 You can use the following variables: %{state}, %{display}
145
146 =back
147
148 =cut