| 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 apps::proxmox::mg::restapi::mode::mail; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub mails_long_output { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
return 'checking mail statistics'; |
| 32 |
} |
| 33 |
|
| 34 |
sub prefix_mail_output { |
| 35 |
my ($self, %options) = @_; |
| 36 |
|
| 37 |
return 'number of mails '; |
| 38 |
} |
| 39 |
|
| 40 |
sub prefix_virus_output { |
| 41 |
my ($self, %options) = @_; |
| 42 |
|
| 43 |
return 'number of virus mails '; |
| 44 |
} |
| 45 |
|
| 46 |
sub prefix_spam_output { |
| 47 |
my ($self, %options) = @_; |
| 48 |
|
| 49 |
return 'number of spam mails '; |
| 50 |
} |
| 51 |
|
| 52 |
sub prefix_traffic_output { |
| 53 |
my ($self, %options) = @_; |
| 54 |
|
| 55 |
return 'traffic '; |
| 56 |
} |
| 57 |
|
| 58 |
sub set_counters { |
| 59 |
my ($self, %options) = @_; |
| 60 |
|
| 61 |
$self->{maps_counters_type} = [ |
| 62 |
{ name => 'mails', type => 3, cb_long_output => 'mails_long_output', indent_long_output => ' ', |
| 63 |
group => [ |
| 64 |
{ name => 'mail', type => 0, display_short => 0, cb_prefix_output => 'prefix_mail_output', skipped_code => { -10 => 1 } }, |
| 65 |
{ name => 'traffic', type => 0, display_short => 0, cb_prefix_output => 'prefix_traffic_output', skipped_code => { -10 => 1 } }, |
| 66 |
{ name => 'spam', type => 0, display_short => 0, cb_prefix_output => 'prefix_spam_output', skipped_code => { -10 => 1 } }, |
| 67 |
{ name => 'virus', type => 0, display_short => 0, cb_prefix_output => 'prefix_virus_output', skipped_code => { -10 => 1 } } |
| 68 |
] |
| 69 |
} |
| 70 |
]; |
| 71 |
|
| 72 |
$self->{maps_counters}->{mail} = [ |
| 73 |
{ label => 'mails-incoming', nlabel => 'mails.incoming.count', set => { |
| 74 |
key_values => [ { name => 'mail_in' } ], |
| 75 |
output_template => 'incoming: %s', |
| 76 |
perfdatas => [ |
| 77 |
{ template => '%s', min => 0 } |
| 78 |
] |
| 79 |
} |
| 80 |
}, |
| 81 |
{ label => 'mails-outgoing', nlabel => 'mails.outgoing.count', set => { |
| 82 |
key_values => [ { name => 'mail_out' } ], |
| 83 |
output_template => 'outgoing: %s', |
| 84 |
perfdatas => [ |
| 85 |
{ template => '%s', min => 0 } |
| 86 |
] |
| 87 |
} |
| 88 |
} |
| 89 |
]; |
| 90 |
|
| 91 |
$self->{maps_counters}->{traffic} = [ |
| 92 |
{ label => 'traffic-in', nlabel => 'mails.traffic.in.bytespersecond', set => { |
| 93 |
key_values => [ { name => 'bytes_in_psec' } ], |
| 94 |
output_template => 'in: %.2f %s/s', |
| 95 |
output_change_bytes => 1, |
| 96 |
perfdatas => [ |
| 97 |
{ template => '%.2f', unit => 'B/s', min => 0 } |
| 98 |
] |
| 99 |
} |
| 100 |
}, |
| 101 |
{ label => 'traffic-out', nlabel => 'mails.traffic.out.bytespersecond', set => { |
| 102 |
key_values => [ { name => 'bytes_out_psec' } ], |
| 103 |
output_template => 'out: %.2f %s/s', |
| 104 |
output_change_bytes => 1, |
| 105 |
perfdatas => [ |
| 106 |
{ template => '%.2f', unit => 'B/s', min => 0 } |
| 107 |
] |
| 108 |
} |
| 109 |
} |
| 110 |
]; |
| 111 |
|
| 112 |
$self->{maps_counters}->{spam} = [ |
| 113 |
{ label => 'spam-incoming', nlabel => 'mails.spam.incoming.count', set => { |
| 114 |
key_values => [ { name => 'spam_in' } ], |
| 115 |
output_template => 'incoming: %s', |
| 116 |
perfdatas => [ |
| 117 |
{ template => '%s', min => 0 } |
| 118 |
] |
| 119 |
} |
| 120 |
}, |
| 121 |
{ label => 'spam-outgoing', nlabel => 'mails.spam.outgoing.count', set => { |
| 122 |
key_values => [ { name => 'spam_out' } ], |
| 123 |
output_template => 'outgoing: %s', |
| 124 |
perfdatas => [ |
| 125 |
{ template => '%s', min => 0 } |
| 126 |
] |
| 127 |
} |
| 128 |
} |
| 129 |
]; |
| 130 |
|
| 131 |
$self->{maps_counters}->{virus} = [ |
| 132 |
{ label => 'virus-incoming', nlabel => 'mails.virus.incoming.count', set => { |
| 133 |
key_values => [ { name => 'virus_in' } ], |
| 134 |
output_template => 'incoming: %s', |
| 135 |
perfdatas => [ |
| 136 |
{ template => '%s', min => 0 } |
| 137 |
] |
| 138 |
} |
| 139 |
}, |
| 140 |
{ label => 'virus-outgoing', nlabel => 'mails.virus.outgoing.count', set => { |
| 141 |
key_values => [ { name => 'virus_out' } ], |
| 142 |
output_template => 'outgoing: %s', |
| 143 |
perfdatas => [ |
| 144 |
{ template => '%s', min => 0 } |
| 145 |
] |
| 146 |
} |
| 147 |
} |
| 148 |
]; |
| 149 |
} |
| 150 |
|
| 151 |
sub new { |
| 152 |
my ($class, %options) = @_; |
| 153 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 154 |
bless $self, $class; |
| 155 |
|
| 156 |
$options{options}->add_options(arguments => { |
| 157 |
'hours:s' => { name => 'hours', default => 12 }, |
| 158 |
'timespan:s' => { name => 'timespan', default => 1800 } |
| 159 |
}); |
| 160 |
|
| 161 |
return $self; |
| 162 |
} |
| 163 |
|
| 164 |
sub manage_selection { |
| 165 |
my ($self, %options) = @_; |
| 166 |
|
| 167 |
my $datas = $options{custom}->request( |
| 168 |
endpoint => '/statistics/recent', |
| 169 |
get_param => [ |
| 170 |
'hours=' . $self->{option_results}->{hours}, |
| 171 |
'timespan=' . $self->{option_results}->{timespan} |
| 172 |
] |
| 173 |
); |
| 174 |
|
| 175 |
my $result = { mail_in => 0, mail_out => 0, virus_in => 0, virus_out => 0, spam_in => 0, spam_out => 0, bytes_in => 0, bytes_out => 0 }; |
| 176 |
foreach (@{$datas->{data}}) { |
| 177 |
$result->{mail_in} += $_->{count_in}; |
| 178 |
$result->{mail_out} += $_->{count_out}; |
| 179 |
$result->{spam_in} += $_->{spam_in}; |
| 180 |
$result->{spam_out} += $_->{spam_out}; |
| 181 |
$result->{virus_in} += $_->{virus_in}; |
| 182 |
$result->{virus_out} += $_->{virus_out}; |
| 183 |
$result->{bytes_in} += $_->{bytes_in}; |
| 184 |
$result->{bytes_out} += $_->{bytes_out}; |
| 185 |
} |
| 186 |
|
| 187 |
$self->{output}->output_add(short_msg => 'Mail statistics are ok'); |
| 188 |
|
| 189 |
$self->{mails} = { |
| 190 |
global => { |
| 191 |
mail => { |
| 192 |
mail_in => $result->{mail_in}, |
| 193 |
mail_out => $result->{mail_out} |
| 194 |
}, |
| 195 |
spam => { |
| 196 |
spam_in => $result->{spam_in}, |
| 197 |
spam_out => $result->{spam_out} |
| 198 |
}, |
| 199 |
traffic => { |
| 200 |
bytes_in_psec => $result->{bytes_in} / ($self->{option_results}->{hours} * 3600), |
| 201 |
bytes_out_psec => $result->{bytes_out} / ($self->{option_results}->{hours} * 3600) |
| 202 |
}, |
| 203 |
virus => { |
| 204 |
virus_in => $result->{virus_in}, |
| 205 |
virus_out => $result->{virus_out} |
| 206 |
} |
| 207 |
} |
| 208 |
}; |
| 209 |
} |
| 210 |
|
| 211 |
1; |
| 212 |
|
| 213 |
__END__ |
| 214 |
|
| 215 |
=head1 MODE |
| 216 |
|
| 217 |
Check mail statistics. |
| 218 |
|
| 219 |
=over 8 |
| 220 |
|
| 221 |
=item B<--hours> |
| 222 |
|
| 223 |
How many hours of statistics you want (default: 12) |
| 224 |
|
| 225 |
=item B<--timespan> |
| 226 |
|
| 227 |
Timespan for datapoints in hours timeframe (default: 1800) |
| 228 |
|
| 229 |
=item B<--warning-*> B<--critical-*> |
| 230 |
|
| 231 |
Thresholds. |
| 232 |
Can be: 'virus-incoming', 'virus-outgoing', 'traffic-in', 'traffic-out', |
| 233 |
'mails-incoming', 'mails-outgoing', 'spam-incoming', 'spam-outgoing'. |
| 234 |
|
| 235 |
=back |
| 236 |
|
| 237 |
=cut |