| 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::antivirus::kaspersky::snmp::mode::protection; |
| 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 sprintf("Protection status is '%s'", $self->{result_values}->{status}); |
| 33 |
} |
| 34 |
|
| 35 |
sub custom_status_calc { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_protectionStatus'}; |
| 39 |
return 0; |
| 40 |
} |
| 41 |
|
| 42 |
sub set_counters { |
| 43 |
my ($self, %options) = @_; |
| 44 |
|
| 45 |
$self->{maps_counters_type} = [ |
| 46 |
{ name => 'global', type => 0, message_separator => ' - ' }, |
| 47 |
]; |
| 48 |
|
| 49 |
$self->{maps_counters}->{global} = [ |
| 50 |
{ |
| 51 |
label => 'status', |
| 52 |
type => 2, |
| 53 |
warning_default => '%{status} =~ /Warning/i', |
| 54 |
critical_default => '%{status} =~ /Critical/i', |
| 55 |
set => { |
| 56 |
key_values => [ { name => 'protectionStatus' } ], |
| 57 |
closure_custom_calc => $self->can('custom_status_calc'), |
| 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 |
{ label => 'no-antivirus', nlabel => 'protection.hosts.antivirus.notrunning.count', set => { |
| 64 |
key_values => [ { name => 'hostsAntivirusNotRunning' } ], |
| 65 |
output_template => '%d host(s) without running antivirus', |
| 66 |
perfdatas => [ |
| 67 |
{ label => 'no_antivirus', template => '%d', min => 0 } |
| 68 |
] |
| 69 |
} |
| 70 |
}, |
| 71 |
{ label => 'no-real-time', nlabel => 'protection.hosts.realtime.notrunning.count', set => { |
| 72 |
key_values => [ { name => 'hostsRealtimeNotRunning' } ], |
| 73 |
output_template => '%d hosts(s) without running real time protection', |
| 74 |
perfdatas => [ |
| 75 |
{ label => 'no_real_time', template => '%d', min => 0 } |
| 76 |
] |
| 77 |
} |
| 78 |
}, |
| 79 |
{ label => 'not-acceptable-level', nlabel => 'protection.hosts.realtime.unacceptable.level.count', set => { |
| 80 |
key_values => [ { name => 'hostsRealtimeLevelChanged' } ], |
| 81 |
output_template => '%d host(s) with not acceptable level of real time protection', |
| 82 |
perfdatas => [ |
| 83 |
{ label => 'not_acceptable_level', value => 'hostsRealtimeLevelChanged', template => '%d', min => 0 } |
| 84 |
] |
| 85 |
} |
| 86 |
}, |
| 87 |
{ label => 'not-cured-objects', nlabel => 'protection.hosts.uncured.objects.count', set => { |
| 88 |
key_values => [ { name => 'hostsNotCuredObject' } ], |
| 89 |
output_template => '%d host(s) with not cured objects', |
| 90 |
perfdatas => [ |
| 91 |
{ label => 'not_cured_objects', value => 'hostsNotCuredObject', template => '%d', min => 0 } |
| 92 |
] |
| 93 |
} |
| 94 |
}, |
| 95 |
{ label => 'too-many-threats', nlabel => 'protection.hosts.toomanythreats.count', set => { |
| 96 |
key_values => [ { name => 'hostsTooManyThreats' } ], |
| 97 |
output_template => '%d host(s) with too many threats', |
| 98 |
perfdatas => [ |
| 99 |
{ label => 'too_many_threats', template => '%d', min => 0 } |
| 100 |
] |
| 101 |
} |
| 102 |
} |
| 103 |
]; |
| 104 |
} |
| 105 |
|
| 106 |
sub new { |
| 107 |
my ($class, %options) = @_; |
| 108 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 109 |
bless $self, $class; |
| 110 |
|
| 111 |
$options{options}->add_options(arguments => { |
| 112 |
}); |
| 113 |
|
| 114 |
return $self; |
| 115 |
} |
| 116 |
|
| 117 |
my %map_status = ( |
| 118 |
0 => 'OK', |
| 119 |
1 => 'Info', |
| 120 |
2 => 'Warning', |
| 121 |
3 => 'Critical' |
| 122 |
); |
| 123 |
|
| 124 |
my $oid_protectionStatus = '.1.3.6.1.4.1.23668.1093.1.3.1'; |
| 125 |
my $oid_hostsAntivirusNotRunning = '.1.3.6.1.4.1.23668.1093.1.3.3'; |
| 126 |
my $oid_hostsRealtimeNotRunning = '.1.3.6.1.4.1.23668.1093.1.3.4'; |
| 127 |
my $oid_hostsRealtimeLevelChanged = '.1.3.6.1.4.1.23668.1093.1.3.5'; |
| 128 |
my $oid_hostsNotCuredObject = '.1.3.6.1.4.1.23668.1093.1.3.6'; |
| 129 |
my $oid_hostsTooManyThreats = '.1.3.6.1.4.1.23668.1093.1.3.7'; |
| 130 |
|
| 131 |
sub manage_selection { |
| 132 |
my ($self, %options) = @_; |
| 133 |
|
| 134 |
my $snmp_result = $options{snmp}->get_leef( |
| 135 |
oids => [ |
| 136 |
$oid_protectionStatus, $oid_hostsAntivirusNotRunning, |
| 137 |
$oid_hostsRealtimeNotRunning, $oid_hostsRealtimeLevelChanged, |
| 138 |
$oid_hostsNotCuredObject, $oid_hostsTooManyThreats |
| 139 |
], |
| 140 |
nothing_quit => 1 |
| 141 |
); |
| 142 |
|
| 143 |
$self->{global} = { |
| 144 |
protectionStatus => $map_status{$snmp_result->{$oid_protectionStatus}}, |
| 145 |
hostsAntivirusNotRunning => $snmp_result->{$oid_hostsAntivirusNotRunning}, |
| 146 |
hostsRealtimeNotRunning => $snmp_result->{$oid_hostsRealtimeNotRunning}, |
| 147 |
hostsRealtimeLevelChanged => $snmp_result->{$oid_hostsRealtimeLevelChanged}, |
| 148 |
hostsNotCuredObject => $snmp_result->{$oid_hostsNotCuredObject}, |
| 149 |
hostsTooManyThreats => $snmp_result->{$oid_hostsTooManyThreats} |
| 150 |
}; |
| 151 |
} |
| 152 |
|
| 153 |
1; |
| 154 |
|
| 155 |
__END__ |
| 156 |
|
| 157 |
=head1 MODE |
| 158 |
|
| 159 |
Check protection status. |
| 160 |
|
| 161 |
=over 8 |
| 162 |
|
| 163 |
=item B<--warning-status> |
| 164 |
|
| 165 |
Define the conditions to match for the status to be WARNING. (default: '%{status} =~ /Warning/i'). |
| 166 |
Can use special variables like: %{status} |
| 167 |
|
| 168 |
=item B<--critical-status> |
| 169 |
|
| 170 |
Define the conditions to match for the status to be CRITICAL. (default: '%{status} =~ /Critical/i'). |
| 171 |
Can use special variables like: %{status} |
| 172 |
|
| 173 |
=item B<--warning-*> |
| 174 |
|
| 175 |
Warning threshold. |
| 176 |
Can be: 'no-antivirus', 'no-real-time', 'not-acceptable-level', |
| 177 |
'not-cured-objects', 'too-many-threats'. |
| 178 |
|
| 179 |
=item B<--critical-*> |
| 180 |
|
| 181 |
Critical threshold. |
| 182 |
Can be: 'no-antivirus', 'no-real-time', 'not-acceptable-level', |
| 183 |
'not-cured-objects', 'too-many-threats'. |
| 184 |
|
| 185 |
=back |
| 186 |
|
| 187 |
=cut |