Debian Codegraph @

src/network/cisco/callmanager/snmp/mode/mediadeviceusage.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::cisco::callmanager::snmp::mode::mediadeviceusage;
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_status_output {
30 my ($self, %options) = @_;
31
32 return 'status: ' . $self->{result_values}->{status};
33 }
34
35 sub prefix_md_output {
36 my ($self, %options) = @_;
37
38 return "Media device '" . $options{instance_value}->{display} . "' ";
39 }
40
41 sub prefix_global_output {
42 my ($self, %options) = @_;
43
44 return 'Total ';
45 }
46
47 sub set_counters {
48 my ($self, %options) = @_;
49
50 $self->{maps_counters_type} = [
51 { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
52 { name => 'md', type => 1, cb_prefix_output => 'prefix_md_output', message_multiple => 'All media devices are ok' }
53 ];
54
55 $self->{maps_counters}->{md} = [
56 { label => 'status', type => 2, critical_default => '%{status} !~ /^registered/', set => {
57 key_values => [ { name => 'status' }, { name => 'display' } ],
58 closure_custom_output => $self->can('custom_status_output'),
59 closure_custom_perfdata => sub { return 0; },
60 closure_custom_threshold_check => \&catalog_status_threshold_ng
61 }
62 }
63 ];
64
65 my @map = (
66 ['total-registered', 'registered: %s', 'registered', 'media_devices.registered.count'],
67 ['total-unregistered', 'unregistered: %s', 'unregistered', 'media_devices.unregistered.count'],
68 ['total-rejected', 'rejected: %s', 'rejected', 'media_devices.rejected.count'],
69 ['total-unknown', 'unknown: %s', 'unknown', 'media_devices.unknown.count'],
70 ['total-partiallyregistered', 'partially registered: %s', 'partiallyregistered', 'media_devices.partially_registered.count']
71 );
72
73 $self->{maps_counters}->{global} = [];
74 foreach (@map) {
75 my $label = $_->[0];
76 $label =~ tr/-/_/;
77 push @{$self->{maps_counters}->{global}}, {
78 label => $_->[0], nlabel => $_->[3], set => {
79 key_values => [ { name => $_->[2] } ],
80 output_template => $_->[1],
81 perfdatas => [
82 { label => $label, value => $_->[2] , template => '%s', min => 0 }
83 ]
84 }
85 };
86 }
87 }
88
89 sub new {
90 my ($class, %options) = @_;
91 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
92 bless $self, $class;
93
94 $options{options}->add_options(arguments => {
95 });
96
97 return $self;
98 }
99
100 my %mapping_status = (
101 1 => 'unknown', 2 => 'registered', 3 => 'unregistered',
102 4 => 'rejected', 5 => 'partiallyregistered'
103 );
104
105 my $mapping = {
106 display => { oid => '.1.3.6.1.4.1.9.9.156.1.6.1.1.2' }, # ccmMediaDeviceName
107 status => { oid => '.1.3.6.1.4.1.9.9.156.1.6.1.1.5', map => \%mapping_status } # ccmMediaDeviceStatus
108 };
109 my $oid_ccmMediaDeviceEntry = '.1.3.6.1.4.1.9.9.156.1.6.1.1';
110
111 sub manage_selection {
112 my ($self, %options) = @_;
113
114 my $snmp_result = $options{snmp}->get_table(
115 oid => $oid_ccmMediaDeviceEntry,
116 start => $mapping->{display}->{oid},
117 end => $mapping->{status}->{oid},
118 nothing_quit => 1
119 );
120
121 $self->{md} = {};
122 $self->{global} = { unknown => 0, registered => 0, unregistered => 0, rejected => 0, partiallyregistered => 0 };
123 foreach my $oid (keys %$snmp_result) {
124 next if ($oid !~ /^$mapping->{status}->{oid}\.(.*)/);
125 my $instance = $1;
126 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
127
128 $self->{md}->{$instance} = { %$result };
129 $self->{global}->{ $result->{status} }++;
130 }
131 }
132
133 1;
134
135 __END__
136
137 =head1 MODE
138
139 Check media device usage.
140
141 =over 8
142
143 =item B<--filter-counters>
144
145 Only display some counters (regexp can be used).
146 Example: --filter-counters='status'
147
148 =item B<--warning-status>
149
150 Define the conditions to match for the status to be WARNING (default: '').
151 You can use the following variables: %{status}, %{display}
152
153 =item B<--critical-status>
154
155 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /^registered/').
156 You can use the following variables: %{status}, %{display}
157
158 =item B<--warning-*>
159
160 Warning threshold.
161
162 =item B<--critical-*>
163
164 Critical threshold.
165
166 Can be: 'total-registered', 'total-unregistered', 'total-rejected',
167 'total-unknown', 'total-partiallyregistered'.
168
169 =back
170
171 =cut