| 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::wallix::bastion::snmp::mode::system; |
| 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_services_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf('services status: %s', $self->{result_values}->{status}); |
| 33 |
} |
| 34 |
|
| 35 |
sub system_long_output { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
return 'checking system'; |
| 39 |
} |
| 40 |
|
| 41 |
sub prefix_sessions_output { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
return 'sessions '; |
| 45 |
} |
| 46 |
|
| 47 |
sub set_counters { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
$self->{maps_counters_type} = [ |
| 51 |
{ name => 'system', type => 3, cb_long_output => 'system_long_output', indent_long_output => ' ', |
| 52 |
group => [ |
| 53 |
{ name => 'services_status', type => 0, display_short => 0, skipped_code => { -10 => 1 } }, |
| 54 |
{ name => 'sessions', type => 0, cb_prefix_output => 'prefix_sessions_output', message_separator => ' ', display_short => 0, skipped_code => { -10 => 1 } }, |
| 55 |
{ name => 'requests', type => 0, display_short => 0, skipped_code => { -10 => 1 } } |
| 56 |
] |
| 57 |
} |
| 58 |
]; |
| 59 |
|
| 60 |
$self->{maps_counters}->{services_status} = [ |
| 61 |
{ label => 'services-status', type => 2, critical_default => '%{status} eq "unreachable"', set => { |
| 62 |
key_values => [ { name => 'status' }, ], |
| 63 |
closure_custom_output => $self->can('custom_services_status_output'), |
| 64 |
closure_custom_perfdata => sub { return 0; }, |
| 65 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 66 |
} |
| 67 |
} |
| 68 |
]; |
| 69 |
|
| 70 |
$self->{maps_counters}->{sessions} = [ |
| 71 |
{ label => 'sessions-total', nlabel => 'sessions.total.count', set => { |
| 72 |
key_values => [ { name => 'total' } ], |
| 73 |
output_template => 'total: %s', |
| 74 |
perfdatas => [ { template => '%s', min => 0 } ] |
| 75 |
} |
| 76 |
}, |
| 77 |
{ label => 'sessions-primary', nlabel => 'sessions.primary.count', set => { |
| 78 |
key_values => [ { name => 'primary' } ], |
| 79 |
output_template => 'primary: %s', |
| 80 |
perfdatas => [ { template => '%s', min => 0 } ] |
| 81 |
} |
| 82 |
}, |
| 83 |
{ label => 'sessions-secondary', nlabel => 'sessions.secondary.count', set => { |
| 84 |
key_values => [ { name => 'secondary' } ], |
| 85 |
output_template => 'secondary: %s', |
| 86 |
perfdatas => [ { template => '%s', min => 0 } ] |
| 87 |
} |
| 88 |
}, |
| 89 |
{ label => 'sessions-ghost', nlabel => 'sessions.ghost.count', set => { |
| 90 |
key_values => [ { name => 'ghost' } ], |
| 91 |
output_template => 'ghost: %s', |
| 92 |
perfdatas => [ { template => '%s', min => 0 } ] |
| 93 |
} |
| 94 |
} |
| 95 |
]; |
| 96 |
|
| 97 |
$self->{maps_counters}->{requests} = [ |
| 98 |
{ label => 'requests-pending', nlabel => 'requests.pending.count', set => { |
| 99 |
key_values => [ { name => 'pending' } ], |
| 100 |
output_template => 'requests pending: %s', |
| 101 |
perfdatas => [ { template => '%s', min => 0 } ] |
| 102 |
} |
| 103 |
} |
| 104 |
]; |
| 105 |
} |
| 106 |
|
| 107 |
sub new { |
| 108 |
my ($class, %options) = @_; |
| 109 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 110 |
bless $self, $class; |
| 111 |
|
| 112 |
$options{options}->add_options(arguments => {}); |
| 113 |
|
| 114 |
return $self; |
| 115 |
} |
| 116 |
|
| 117 |
sub manage_selection { |
| 118 |
my ($self, %options) = @_; |
| 119 |
|
| 120 |
my $mapping_status = { |
| 121 |
1 => 'running', 2 => 'unreachable' |
| 122 |
}; |
| 123 |
my $mapping = { |
| 124 |
total_session => { oid => '.1.3.6.1.4.1.30373.1.1.1' }, # totalSessionCount |
| 125 |
primary_session => { oid => '.1.3.6.1.4.1.30373.1.1.2' }, # primarySessionCount |
| 126 |
secondary_session => { oid => '.1.3.6.1.4.1.30373.1.1.3' }, # secondarySessionCount |
| 127 |
ghost_session => { oid => '.1.3.6.1.4.1.30373.1.1.4' }, # ghostSessionCount |
| 128 |
requests_pending => { oid => '.1.3.6.1.4.1.30373.1.1.7' }, # pendingApprovalCount |
| 129 |
services_status => { oid => '.1.3.6.1.4.1.30373.1.2.3', map => $mapping_status } # bastionStatus |
| 130 |
}; |
| 131 |
|
| 132 |
my $snmp_result = $options{snmp}->get_leef( |
| 133 |
oids => [ map($_->{oid} . '.0', values(%$mapping)) ], |
| 134 |
nothing_quit => 1 |
| 135 |
); |
| 136 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0); |
| 137 |
|
| 138 |
$self->{output}->output_add(short_msg => 'system is ok'); |
| 139 |
|
| 140 |
$self->{system} = { |
| 141 |
global => { |
| 142 |
services_status => { status => $result->{services_status} }, |
| 143 |
sessions => { |
| 144 |
total => $result->{total_session}, |
| 145 |
primary => $result->{primary_session}, |
| 146 |
secondary => $result->{secondary_session}, |
| 147 |
ghost => $result->{ghost_session} |
| 148 |
}, |
| 149 |
requests => { pending => $result->{requests_pending} } |
| 150 |
} |
| 151 |
}; |
| 152 |
} |
| 153 |
|
| 154 |
1; |
| 155 |
|
| 156 |
__END__ |
| 157 |
|
| 158 |
=head1 MODE |
| 159 |
|
| 160 |
Check system usage. |
| 161 |
|
| 162 |
=over 8 |
| 163 |
|
| 164 |
=item B<--filter-counters> |
| 165 |
|
| 166 |
Only display some counters (regexp can be used). |
| 167 |
Example: --filter-counters='status' |
| 168 |
|
| 169 |
=item B<--warning-services-status> |
| 170 |
|
| 171 |
Define the conditions to match for the status to be WARNING. |
| 172 |
You can use the following variables: %{status} |
| 173 |
|
| 174 |
=item B<--critical-services-status> |
| 175 |
|
| 176 |
Define the conditions to match for the status to be CRITICAL (default: ''). |
| 177 |
You can use the following variables: %{status} |
| 178 |
|
| 179 |
=item B<--warning-*> B<--critical-*> |
| 180 |
|
| 181 |
Thresholds. |
| 182 |
Can be: 'requests-pending', 'sessions-total', 'sessions-primary', |
| 183 |
'sessions-secondary', 'sessions-ghost'. |
| 184 |
|
| 185 |
=back |
| 186 |
|
| 187 |
=cut |