| 1 |
# |
| 2 |
# Copyright 2022 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::fortinet::fortimail::snmp::mode::queues; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub prefix_queue_output { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
return "Queue '" . $options{instance_value}->{display} . "' "; |
| 32 |
} |
| 33 |
|
| 34 |
sub set_counters { |
| 35 |
my ($self, %options) = @_; |
| 36 |
|
| 37 |
$self->{maps_counters_type} = [ |
| 38 |
{ name => 'queue', type => 1, cb_prefix_output => 'prefix_queue_output', message_multiple => 'All queues are ok' } |
| 39 |
]; |
| 40 |
|
| 41 |
$self->{maps_counters}->{queue} = [ |
| 42 |
{ label => 'count', nlabel => 'queue.mails.count', set => { |
| 43 |
key_values => [ { name => 'count' }, { name => 'display' } ], |
| 44 |
output_template => 'mails: %s', |
| 45 |
perfdatas => [ |
| 46 |
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 47 |
] |
| 48 |
} |
| 49 |
}, |
| 50 |
{ label => 'size', nlabel => 'queue.mails.size.count', set => { |
| 51 |
key_values => [ { name => 'size' }, { name => 'display' } ], |
| 52 |
output_template => 'size: %s %s', |
| 53 |
output_change_bytes => 1, |
| 54 |
perfdatas => [ |
| 55 |
{ template => '%d', unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 56 |
] |
| 57 |
} |
| 58 |
} |
| 59 |
]; |
| 60 |
} |
| 61 |
|
| 62 |
sub new { |
| 63 |
my ($class, %options) = @_; |
| 64 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 65 |
bless $self, $class; |
| 66 |
|
| 67 |
$options{options}->add_options(arguments => { |
| 68 |
'filter-name:s' => { name => 'filter_name' } |
| 69 |
}); |
| 70 |
|
| 71 |
return $self; |
| 72 |
} |
| 73 |
|
| 74 |
my $mapping = { |
| 75 |
fmlMailQueueMailCount => { oid => '.1.3.6.1.4.1.12356.105.1.103.2.1.3' }, |
| 76 |
fmlMailQueueMailSize => { oid => '.1.3.6.1.4.1.12356.105.1.103.2.1.4' } |
| 77 |
}; |
| 78 |
my $oid_fmlMailQueueEntry = '.1.3.6.1.4.1.12356.105.1.103.2.1'; |
| 79 |
my $oid_fmlMailQueueName = '.1.3.6.1.4.1.12356.105.1.103.2.1.2'; |
| 80 |
|
| 81 |
sub manage_selection { |
| 82 |
my ($self, %options) = @_; |
| 83 |
|
| 84 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 85 |
oids => [ |
| 86 |
{ oid => $oid_fmlMailQueueName }, |
| 87 |
{ oid => $oid_fmlMailQueueEntry } |
| 88 |
], |
| 89 |
nothing_quit => 1 |
| 90 |
); |
| 91 |
|
| 92 |
$self->{queue} = {}; |
| 93 |
foreach my $oid (keys %{$snmp_result->{$oid_fmlMailQueueName}}) { |
| 94 |
next if ($oid !~ /^$oid_fmlMailQueueName\.(.*)/); |
| 95 |
my $instance = $1; |
| 96 |
|
| 97 |
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 98 |
$snmp_result->{$oid_fmlMailQueueName}->{$oid} !~ /$self->{option_results}->{filter_name}/); |
| 99 |
|
| 100 |
my $result = $options{snmp}->map_instance( |
| 101 |
mapping => $mapping, |
| 102 |
results => $snmp_result->{$oid_fmlMailQueueEntry}, |
| 103 |
instance => $instance |
| 104 |
); |
| 105 |
|
| 106 |
$self->{queue}->{$instance} = { |
| 107 |
display => $snmp_result->{$oid_fmlMailQueueName}->{$oid}, |
| 108 |
count => $result->{'fmlMailQueueMailCount'}, |
| 109 |
size => $result->{'fmlMailQueueMailSize'} * 1024 |
| 110 |
}; |
| 111 |
} |
| 112 |
|
| 113 |
if (scalar(keys %{$self->{queue}}) <= 0) { |
| 114 |
$self->{output}->add_option_msg(short_msg => "No queue found."); |
| 115 |
$self->{output}->option_exit(); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
1; |
| 120 |
|
| 121 |
__END__ |
| 122 |
|
| 123 |
=head1 MODE |
| 124 |
|
| 125 |
Check queue statistics. |
| 126 |
|
| 127 |
=over 8 |
| 128 |
|
| 129 |
=item B<--filter-name> |
| 130 |
|
| 131 |
Filter queue name (can be a regexp). |
| 132 |
|
| 133 |
=item B<--warning-*> B<--critical-*> |
| 134 |
|
| 135 |
Thresholds. |
| 136 |
Can be: 'count', 'size'. |
| 137 |
|
| 138 |
=back |
| 139 |
|
| 140 |
=cut |