| 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::cyberoam::snmp::mode::requests; |
| 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, cb_prefix_output => 'prefix_output' } |
| 34 |
]; |
| 35 |
|
| 36 |
$self->{maps_counters}->{global} = [ |
| 37 |
{ label => 'live-users', set => { |
| 38 |
key_values => [ { name => 'live_users' } ], |
| 39 |
output_template => 'live users: %s', |
| 40 |
perfdatas => [ |
| 41 |
{ label => 'live_users', template => '%s', min => 0 } |
| 42 |
] |
| 43 |
} |
| 44 |
}, |
| 45 |
{ label => 'http-hits', set => { |
| 46 |
key_values => [ { name => 'http_hits', diff => 1 } ], |
| 47 |
output_template => 'http hits: %s', |
| 48 |
perfdatas => [ |
| 49 |
{ label => 'http_hits', template => '%s', min => 0 } |
| 50 |
] |
| 51 |
} |
| 52 |
}, |
| 53 |
{ label => 'ftp-hits', set => { |
| 54 |
key_values => [ { name => 'ftp_hits', diff => 1 } ], |
| 55 |
output_template => 'ftp hits: %s', |
| 56 |
perfdatas => [ |
| 57 |
{ label => 'ftp_hits', template => '%s', min => 0 } |
| 58 |
] |
| 59 |
} |
| 60 |
}, |
| 61 |
{ label => 'pop3-hits', set => { |
| 62 |
key_values => [ { name => 'pop3_hits', diff => 1 } ], |
| 63 |
output_template => 'pop3 hits: %s', |
| 64 |
perfdatas => [ |
| 65 |
{ label => 'pop3_hits', template => '%s', min => 0 } |
| 66 |
] |
| 67 |
} |
| 68 |
}, |
| 69 |
{ label => 'imap-hits', set => { |
| 70 |
key_values => [ { name => 'imap_hits', diff => 1 } ], |
| 71 |
output_template => 'imap hits: %s', |
| 72 |
perfdatas => [ |
| 73 |
{ label => 'imap_hits', template => '%s', min => 0 } |
| 74 |
] |
| 75 |
} |
| 76 |
}, |
| 77 |
{ label => 'smtp-hits', set => { |
| 78 |
key_values => [ { name => 'smtp_hits', diff => 1 } ], |
| 79 |
output_template => 'smtp hits: %s', |
| 80 |
perfdatas => [ |
| 81 |
{ label => 'smtp_hits', template => '%s', min => 0 } |
| 82 |
] |
| 83 |
} |
| 84 |
} |
| 85 |
]; |
| 86 |
} |
| 87 |
|
| 88 |
sub prefix_output { |
| 89 |
my ($self, %options) = @_; |
| 90 |
|
| 91 |
return 'Requests '; |
| 92 |
} |
| 93 |
|
| 94 |
sub new { |
| 95 |
my ($class, %options) = @_; |
| 96 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); |
| 97 |
bless $self, $class; |
| 98 |
|
| 99 |
$options{options}->add_options(arguments => { |
| 100 |
}); |
| 101 |
|
| 102 |
return $self; |
| 103 |
} |
| 104 |
|
| 105 |
sub add_counters { |
| 106 |
my ($self, %options) = @_; |
| 107 |
|
| 108 |
return if (!defined($options{result}->{live_users})); |
| 109 |
|
| 110 |
$self->{global} = { %{$options{result}} }; |
| 111 |
} |
| 112 |
|
| 113 |
sub manage_selection { |
| 114 |
my ($self, %options) = @_; |
| 115 |
|
| 116 |
if ($options{snmp}->is_snmpv1()) { |
| 117 |
$self->{output}->add_option_msg(short_msg => 'Need to use SNMP v2c or v3.'); |
| 118 |
$self->{output}->option_exit(); |
| 119 |
} |
| 120 |
|
| 121 |
my $mapping = { |
| 122 |
v17 => { |
| 123 |
live_users => { oid => '.1.3.6.1.4.1.21067.2.1.2.6' }, # liveUsers |
| 124 |
http_hits => { oid => '.1.3.6.1.4.1.21067.2.1.2.7' }, # httpHits |
| 125 |
ftp_hits => { oid => '.1.3.6.1.4.1.21067.2.1.2.8' }, # ftpHits |
| 126 |
pop3_hits => { oid => '.1.3.6.1.4.1.21067.2.1.2.9.1' }, # pop3Hits |
| 127 |
imap_hits => { oid => '.1.3.6.1.4.1.21067.2.1.2.9.2' }, # imapHits |
| 128 |
smtp_hits => { oid => '.1.3.6.1.4.1.21067.2.1.2.9.3' } # smtpHits |
| 129 |
}, |
| 130 |
v18 => { |
| 131 |
live_users => { oid => '.1.3.6.1.4.1.2604.5.1.2.6' }, # sfosLiveUsersCount |
| 132 |
http_hits => { oid => '.1.3.6.1.4.1.2604.5.1.2.7' }, # sfosHTTPHits |
| 133 |
ftp_hits => { oid => '.1.3.6.1.4.1.2604.5.1.2.8' }, # sfosFTPHits |
| 134 |
pop3_hits => { oid => '.1.3.6.1.4.1.2604.5.1.2.9.1' }, # sfosPOP3Hits |
| 135 |
imap_hits => { oid => '.1.3.6.1.4.1.2604.5.1.2.9.2' }, # sfosImapHits |
| 136 |
smtp_hits => { oid => '.1.3.6.1.4.1.2604.5.1.2.9.3' } # sfosSmtpHits |
| 137 |
} |
| 138 |
}; |
| 139 |
|
| 140 |
my $snmp_result = $options{snmp}->get_leef( |
| 141 |
oids => [ map($_->{oid} . '.0', values(%{$mapping->{v17}}), values(%{$mapping->{v18}})) ], |
| 142 |
nothing_quit => 1 |
| 143 |
); |
| 144 |
|
| 145 |
my $result = $options{snmp}->map_instance(mapping => $mapping->{v17}, results => $snmp_result, instance => 0); |
| 146 |
$self->add_counters(result => $result); |
| 147 |
$result = $options{snmp}->map_instance(mapping => $mapping->{v18}, results => $snmp_result, instance => 0); |
| 148 |
$self->add_counters(result => $result); |
| 149 |
|
| 150 |
$self->{cache_name} = 'cyberoam_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . |
| 151 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 152 |
} |
| 153 |
|
| 154 |
1; |
| 155 |
|
| 156 |
__END__ |
| 157 |
|
| 158 |
=head1 MODE |
| 159 |
|
| 160 |
Check request statistics. |
| 161 |
|
| 162 |
=over 8 |
| 163 |
|
| 164 |
=item B<--filter-counters> |
| 165 |
|
| 166 |
Only display some counters (regexp can be used). |
| 167 |
Example: --filter-counters='http-hits' |
| 168 |
|
| 169 |
=item B<--warning-*> B<--critical-*> |
| 170 |
|
| 171 |
Thresholds. |
| 172 |
Can be: live-users, http-hits, ftp-hits, pop3-hits, imap-hits, smtp-hits. |
| 173 |
|
| 174 |
=back |
| 175 |
|
| 176 |
=cut |