| 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::fortinet::fortimanager::snmp::mode::devicestatus; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use Digest::MD5 qw(md5_hex); |
| 28 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 29 |
|
| 30 |
sub custom_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
return $self->{result_values}->{output_label} . ': ' . $self->{result_values}->{status}; |
| 34 |
} |
| 35 |
|
| 36 |
sub device_long_output { |
| 37 |
my ($self, %options) = @_; |
| 38 |
|
| 39 |
return "checking device '" . $options{instance_value}->{name} . "'"; |
| 40 |
} |
| 41 |
|
| 42 |
sub prefix_device_output { |
| 43 |
my ($self, %options) = @_; |
| 44 |
|
| 45 |
return "Device '" . $options{instance_value}->{name} . "' "; |
| 46 |
} |
| 47 |
|
| 48 |
sub prefix_pp_output { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
return "policy package '" . $options{instance_value}->{package_name} . "' "; |
| 52 |
} |
| 53 |
|
| 54 |
sub set_counters { |
| 55 |
my ($self, %options) = @_; |
| 56 |
|
| 57 |
$self->{maps_counters_type} = [ |
| 58 |
{ name => 'devices', type => 3, cb_prefix_output => 'prefix_device_output', cb_long_output => 'device_long_output', indent_long_output => ' ', message_multiple => 'All devices are ok', |
| 59 |
group => [ |
| 60 |
{ name => 'status', type => 0, skipped_code => { -10 => 1 } }, |
| 61 |
{ name => 'con_status', type => 0, skipped_code => { -10 => 1 } }, |
| 62 |
{ name => 'db_status', type => 0, skipped_code => { -10 => 1 } }, |
| 63 |
{ name => 'config_status', type => 0, skipped_code => { -10 => 1 } }, |
| 64 |
{ name => 'packages', display_long => 1, cb_prefix_output => 'prefix_pp_output', message_multiple => 'policy packages are ok', type => 1, skipped_code => { -10 => 1 } } |
| 65 |
] |
| 66 |
} |
| 67 |
]; |
| 68 |
|
| 69 |
$self->{maps_counters}->{status} = [ |
| 70 |
{ label => 'device-status', type => 2, set => { |
| 71 |
key_values => [ { name => 'status' }, { name => 'name' } ], |
| 72 |
output_template => 'status: %s', |
| 73 |
closure_custom_perfdata => sub { return 0; }, |
| 74 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 75 |
} |
| 76 |
} |
| 77 |
]; |
| 78 |
|
| 79 |
$self->{maps_counters}->{con_status} = [ |
| 80 |
{ label => 'device-con-status', type => 2, critical_default => '%{status} =~ /down/i', set => { |
| 81 |
key_values => [ { name => 'status' }, { name => 'name' } ], |
| 82 |
output_template => 'connection status: %s', |
| 83 |
closure_custom_perfdata => sub { return 0; }, |
| 84 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 85 |
} |
| 86 |
} |
| 87 |
]; |
| 88 |
|
| 89 |
$self->{maps_counters}->{db_status} = [ |
| 90 |
{ label => 'device-db-status', type => 2, set => { |
| 91 |
key_values => [ { name => 'status' }, { name => 'name' } ], |
| 92 |
output_template => 'db status: %s', |
| 93 |
closure_custom_perfdata => sub { return 0; }, |
| 94 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 95 |
} |
| 96 |
} |
| 97 |
]; |
| 98 |
|
| 99 |
$self->{maps_counters}->{config_status} = [ |
| 100 |
{ label => 'device-config-status', type => 2, set => { |
| 101 |
key_values => [ { name => 'status' }, { name => 'name' } ], |
| 102 |
output_template => 'configuration status: %s', |
| 103 |
closure_custom_perfdata => sub { return 0; }, |
| 104 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 105 |
} |
| 106 |
} |
| 107 |
]; |
| 108 |
|
| 109 |
$self->{maps_counters}->{packages} = [ |
| 110 |
{ label => 'device-policy-package-status', type => 2, set => { |
| 111 |
key_values => [ { name => 'status' }, { name => 'package_name' } ], |
| 112 |
output_template => 'status: %s', |
| 113 |
closure_custom_perfdata => sub { return 0; }, |
| 114 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 115 |
} |
| 116 |
} |
| 117 |
]; |
| 118 |
} |
| 119 |
|
| 120 |
sub new { |
| 121 |
my ($class, %options) = @_; |
| 122 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 123 |
bless $self, $class; |
| 124 |
|
| 125 |
$options{options}->add_options(arguments => { |
| 126 |
'filter-name:s' => { name => 'filter_name' } |
| 127 |
}); |
| 128 |
|
| 129 |
return $self; |
| 130 |
} |
| 131 |
|
| 132 |
my %map_connection_state = (0 => 'unknown', 1 => 'up', 2 => 'down'); |
| 133 |
my %map_db_state = (0 => 'unknown', 1 => 'not-modified', 2 => 'modified'); |
| 134 |
my %map_config_state = (0 => 'unknown', 1 => 'in-sync', 2 => 'out-of-sync'); |
| 135 |
my %map_device_state = ( |
| 136 |
0 => 'none', 1 => 'unknown', 2 => 'checked-in', 3 => 'in-progress', |
| 137 |
4 => 'installed', 5 => 'aborted', 6 => 'sched', 7 => 'retry', 8 => 'canceled', |
| 138 |
9 => 'pending', 10 => 'retrieved', 11 => 'changed-conf', 12 => 'sync-fail', |
| 139 |
13 => 'timeout', 14 => 'rev-reverted', 15 => 'auto-updated' |
| 140 |
); |
| 141 |
|
| 142 |
my $mapping = { |
| 143 |
connectState => { oid => '.1.3.6.1.4.1.12356.103.6.2.1.12', map => \%map_connection_state }, # fmDeviceEntConnectState |
| 144 |
dbState => { oid => '.1.3.6.1.4.1.12356.103.6.2.1.13', map => \%map_db_state }, # fmDeviceEntDbState |
| 145 |
configState => { oid => '.1.3.6.1.4.1.12356.103.6.2.1.14', map => \%map_config_state }, # fmDeviceEntConfigState |
| 146 |
state => { oid => '.1.3.6.1.4.1.12356.103.6.2.1.15', map => \%map_device_state }, # fmDeviceEntState |
| 147 |
policyPackageState => { oid => '.1.3.6.1.4.1.12356.103.6.2.1.23' } # fmDeviceEntPolicyPackageState |
| 148 |
}; |
| 149 |
my $oid_fmDeviceEntName = '.1.3.6.1.4.1.12356.103.6.2.1.2'; |
| 150 |
|
| 151 |
sub manage_selection { |
| 152 |
my ($self, %options) = @_; |
| 153 |
|
| 154 |
my $snmp_result = $options{snmp}->get_table( |
| 155 |
oid => $oid_fmDeviceEntName, |
| 156 |
nothing_quit => 1 |
| 157 |
); |
| 158 |
|
| 159 |
$self->{devices} = {}; |
| 160 |
foreach my $oid (keys %$snmp_result) { |
| 161 |
$oid =~ /^$oid_fmDeviceEntName\.(.*)$/; |
| 162 |
my $instance = $1; |
| 163 |
|
| 164 |
my $name = $snmp_result->{$oid}; |
| 165 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 166 |
$name !~ /$self->{option_results}->{filter_name}/) { |
| 167 |
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); |
| 168 |
next; |
| 169 |
} |
| 170 |
|
| 171 |
$self->{devices}->{$instance} = { |
| 172 |
name => $name, |
| 173 |
status => { name => $name }, |
| 174 |
con_status => { name => $name }, |
| 175 |
db_status => { name => $name }, |
| 176 |
config_status => { name => $name }, |
| 177 |
packages => {} |
| 178 |
}; |
| 179 |
} |
| 180 |
|
| 181 |
if (scalar(keys %{$self->{devices}}) <= 0) { |
| 182 |
$self->{output}->add_option_msg(short_msg => 'No device found.'); |
| 183 |
$self->{output}->option_exit(); |
| 184 |
} |
| 185 |
|
| 186 |
$options{snmp}->load(oids => [ |
| 187 |
map($_->{oid}, values(%$mapping)) |
| 188 |
], |
| 189 |
instances => [ map($_, keys(%{$self->{devices}})) ], |
| 190 |
instance_regexp => '^(.*)$' |
| 191 |
); |
| 192 |
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1); |
| 193 |
|
| 194 |
foreach (keys %{$self->{devices}}) { |
| 195 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); |
| 196 |
$self->{devices}->{$_}->{status}->{status} = $result->{state}; |
| 197 |
$self->{devices}->{$_}->{con_status}->{status} = $result->{connectState}; |
| 198 |
$self->{devices}->{$_}->{config_status}->{status} = $result->{configState}; |
| 199 |
$self->{devices}->{$_}->{db_status}->{status} = $result->{dbState}; |
| 200 |
if (defined($result->{policyPackageState}) && $result->{policyPackageState}) { |
| 201 |
foreach my $entry (split(/\|/, $result->{policyPackageState})) { |
| 202 |
next if ($entry !~ /\s*(.*?)\[(.*?)\]/); |
| 203 |
$self->{devices}->{$_}->{packages}->{$1} = { |
| 204 |
package_name => $1, |
| 205 |
status => $2 |
| 206 |
}; |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
1; |
| 213 |
|
| 214 |
__END__ |
| 215 |
|
| 216 |
=head1 MODE |
| 217 |
|
| 218 |
Check device status. |
| 219 |
|
| 220 |
=over 8 |
| 221 |
|
| 222 |
=item B<--filter-name> |
| 223 |
|
| 224 |
Filter by device name (can be a regexp). |
| 225 |
|
| 226 |
=item B<--warning-device-status> |
| 227 |
|
| 228 |
Set warning threshold for device status. |
| 229 |
You can use the following variables: %{status}, %{name} |
| 230 |
|
| 231 |
=item B<--critical-device-status> |
| 232 |
|
| 233 |
Set critical threshold for device status |
| 234 |
You can use the following variables: %{status}, %{name} |
| 235 |
|
| 236 |
=item B<--warning-device-con-status> |
| 237 |
|
| 238 |
Set warning threshold for device connection status. |
| 239 |
You can use the following variables: %{status}, %{name} |
| 240 |
|
| 241 |
=item B<--critical-device-con-status> |
| 242 |
|
| 243 |
Set critical threshold for device connection status (default: '%{status} =~ /down/i'). |
| 244 |
You can use the following variables: %{status}, %{name} |
| 245 |
|
| 246 |
=item B<--warning-device-db-status> |
| 247 |
|
| 248 |
Set warning threshold for device DB status. |
| 249 |
You can use the following variables: %{status}, %{name} |
| 250 |
|
| 251 |
=item B<--critical-device-db-status> |
| 252 |
|
| 253 |
Set critical threshold for device DB status. |
| 254 |
You can use the following variables: %{status}, %{name} |
| 255 |
|
| 256 |
=item B<--warning-device-config-status> |
| 257 |
|
| 258 |
Set warning threshold for device configuration status. |
| 259 |
You can use the following variables: %{status}, %{name} |
| 260 |
|
| 261 |
=item B<--critical-device-config-status> |
| 262 |
|
| 263 |
Set critical threshold for device configuration status. |
| 264 |
You can use the following variables: %{status}, %{name} |
| 265 |
|
| 266 |
=item B<--warning-device-policy-package-status> |
| 267 |
|
| 268 |
Set warning threshold for device policy package status. |
| 269 |
You can use the following variables: %{status}, %{package_name} |
| 270 |
|
| 271 |
=item B<--critical-device-policy-package-status> |
| 272 |
|
| 273 |
Set critical threshold for device policy package status. |
| 274 |
You can use the following variables: %{status}, %{package_name} |
| 275 |
|
| 276 |
=back |
| 277 |
|
| 278 |
=cut |