Debian Codegraph @

src/network/cisco/callmanager/snmp/mode/voicemailusage.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::voicemailusage;
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_voicemail_output {
36 my ($self, %options) = @_;
37
38 return "Voicemail '" . $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 => 'voicemail', type => 1, cb_prefix_output => 'prefix_voicemail_output', message_multiple => 'All voicemails are ok' }
53 ];
54
55 $self->{maps_counters}->{voicemail} = [
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'],
67 ['total-unregistered', 'unregistered: %s', 'unregistered'],
68 ['total-rejected', 'rejected: %s', 'rejected'],
69 ['total-unknown', 'unknown: %s', 'unknown'],
70 ['total-partiallyregistered', 'partially registered: %s', 'partiallyregistered']
71 );
72
73 $self->{maps_counters}->{global} = [];
74 foreach (@map) {
75 push @{$self->{maps_counters}->{global}}, {
76 label => $_->[0], nlabel => 'voicemail.devices.total.' . $_->[2] . '.count', set => {
77 key_values => [ { name => $_->[2] } ],
78 output_template => $_->[1],
79 perfdatas => [
80 { value => $_->[2] , template => '%s', min => 0 }
81 ]
82 }
83 };
84 }
85 }
86
87 sub new {
88 my ($class, %options) = @_;
89 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
90 bless $self, $class;
91
92 $self->{version} = '1.0';
93 $options{options}->add_options(arguments => {
94 });
95
96 return $self;
97 }
98
99 my %mapping_status = (
100 1 => 'unknown', 2 => 'registered', 3 => 'unregistered',
101 4 => 'rejected', 5 => 'partiallyregistered'
102 );
103
104 my $mapping = {
105 display => { oid => '.1.3.6.1.4.1.9.9.156.1.12.1.1.2' }, # ccmVMailDevName
106 description => { oid => '.1.3.6.1.4.1.9.9.156.1.12.1.1.4' }, # ccmVMailDevDescription
107 status => { oid => '.1.3.6.1.4.1.9.9.156.1.12.1.1.5', map => \%mapping_status } # ccmVMailDevStatus
108 };
109 my $oid_ccmVoicemailEntry = '.1.3.6.1.4.1.9.9.156.1.12.1.1';
110
111 sub manage_selection {
112 my ($self, %options) = @_;
113
114 my $snmp_result = $options{snmp}->get_table(
115 oid => $oid_ccmVoicemailEntry,
116 start => $mapping->{display}->{oid},
117 end => $mapping->{status}->{oid},
118 nothing_quit => 1
119 );
120
121 $self->{phone} = {};
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->{phone}->{$instance} = $result;
129 $self->{global}->{ $result->{status} }++;
130 }
131 }
132
133 1;
134
135 __END__
136
137 =head1 MODE
138
139 Check voicemail 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.
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-*> B<--critical-*>
159
160 Thresholds.
161 Can be: 'total-registered', 'total-unregistered', 'total-rejected',
162 'total-unknown', 'total-partiallyregistered'.
163
164 =back
165
166 =cut