Debian Codegraph @

src/network/sophos/es/snmp/mode/message.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::sophos::es::snmp::mode::message;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28
29 sub set_counters {
30 my ($self, %options) = @_;
31
32 $self->{maps_counters_type} = [
33 { name => 'global', type => 0 },
34 { name => 'sea_msg', type => 1, cb_prefix_output => 'prefix_seamsg_output', message_multiple => 'All messages are ok' },
35 ];
36
37 $self->{maps_counters}->{global} = [
38 { label => 'queue', set => {
39 key_values => [ { name => 'queue' } ],
40 output_template => 'Current Queue : %s',
41 perfdatas => [
42 { label => 'queue', template => '%s', min => 0 }
43 ]
44 }
45 },
46 { label => 'total-msg-in', set => {
47 key_values => [ { name => 'total_in', per_second => 1 } ],
48 output_template => 'Total Message In : %.2f/s',
49 perfdatas => [
50 { label => 'total_msg_in', template => '%.2f', unit => '/s', min => 0 }
51 ]
52 }
53 },
54 { label => 'total-msg-out', set => {
55 key_values => [ { name => 'total_out', per_second => 1 } ],
56 output_template => 'Total Message Out : %.2f/s',
57 perfdatas => [
58 { label => 'total_msg_out', template => '%.2f', unit => '/s', min => 0 }
59 ]
60 }
61 }
62 ];
63
64 $self->{maps_counters}->{sea_msg} = [
65 { label => 'msg-in', set => {
66 key_values => [ { name => 'in', per_second => 1 }, { name => 'display' } ],
67 output_template => 'In : %.2f/s',
68 perfdatas => [
69 { label => 'msg_in', template => '%.2f', unit => '/s', min => 0, label_extra_instance => 1, instance_use => 'display' }
70 ]
71 }
72 },
73 { label => 'msg-out', set => {
74 key_values => [ { name => 'out', per_second => 1 }, { name => 'display' } ],
75 output_template => 'Out : %.2f/s',
76 perfdatas => [
77 { label => 'msg_out', template => '%.2f', unit => '/s', min => 0, label_extra_instance => 1, instance_use => 'display' }
78 ]
79 }
80 }
81 ];
82 }
83
84 sub prefix_seamsg_output {
85 my ($self, %options) = @_;
86
87 return "Message '" . $options{instance_value}->{display} . "' ";
88 }
89
90 sub new {
91 my ($class, %options) = @_;
92 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
93 bless $self, $class;
94
95 $options{options}->add_options(arguments => {
96 'filter-type:s' => { name => 'filter_type' },
97 });
98
99 return $self;
100 }
101
102 my $mapping = {
103 counterType => { oid => '.1.3.6.1.4.1.2604.1.1.1.4.1.2' },
104 counterInbound => { oid => '.1.3.6.1.4.1.2604.1.1.1.4.1.3' },
105 counterOutbound => { oid => '.1.3.6.1.4.1.2604.1.1.1.4.1.4' },
106 };
107
108 my $oid_sophosStatisticsEmail = '.1.3.6.1.4.1.2604.1.1.1';
109 my $oid_seaStatisticsQueuedMessages = '.1.3.6.1.4.1.2604.1.1.1.5';
110
111 sub manage_selection {
112 my ($self, %options) = @_;
113
114 my $results = $options{snmp}->get_table(oid => $oid_sophosStatisticsEmail, nothing_quit => 1);
115
116 $self->{cache_name} = "sophos_es_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
117 (defined($self->{option_results}->{filter_type}) ? md5_hex($self->{option_results}->{filter_type}) : md5_hex('all')) . '_' .
118 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
119
120 $self->{global} = { total_in => 0, total_out => 0 };
121 $self->{global}->{queue} = defined($results->{$oid_seaStatisticsQueuedMessages}) ? $results->{$oid_seaStatisticsQueuedMessages} : undef;
122
123 $self->{sea_msg} = {};
124 foreach my $oid (keys %$results) {
125 next if ($oid !~ /^$mapping->{counterType}->{oid}\.(.*)$/);
126 my $instance = $1;
127
128 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance);
129 if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
130 $result->{counterType} !~ /$self->{option_results}->{filter_type}/i) {
131 $self->{output}->output_add(long_msg => "skipping '" . $result->{counterType} . "': no matching filter.", debug => 1);
132 next;
133 }
134
135 $self->{sea_msg}->{lc($result->{counterType})} = {
136 display => lc($result->{counterType}),
137 in => $result->{counterInbound},
138 out => $result->{counterOutbound}
139 };
140
141 $self->{global}->{total_in} += $result->{counterInbound};
142 $self->{global}->{total_out} += $result->{counterOutbound};
143 }
144 }
145
146 1;
147
148 __END__
149
150 =head1 MODE
151
152 Check message statistics.
153
154 =over 8
155
156 =item B<--filter-type>
157
158 Filter message type (can be a regexp).
159
160 =item B<--filter-counters>
161
162 Only display some counters (regexp can be used).
163 Example: --filter-counters='queue'
164
165 =item B<--warning-*> B<--critical-*>
166
167 Thresholds.
168 Can be: queue, total-msg-in, total-msg-out, msg-in, msg-out.
169
170 =back
171
172 =cut