| 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 database::sap::hana::mode::connectedusers; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub set_counters { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
$self->{maps_counters_type} = [ |
| 32 |
{ name => 'host', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All connected users are ok' }, |
| 33 |
]; |
| 34 |
$self->{maps_counters}->{host} = [ |
| 35 |
{ label => 'users', nlabel => 'users.count', set => { |
| 36 |
key_values => [ { name => 'total' }, { name => 'display' } ], |
| 37 |
output_template => 'Connected Users : %s', |
| 38 |
perfdatas => [ |
| 39 |
{ label => 'users', value => 'total', template => '%s', min => 0, |
| 40 |
label_extra_instance => 1, instance_use => 'display' }, |
| 41 |
], |
| 42 |
} |
| 43 |
}, |
| 44 |
]; |
| 45 |
} |
| 46 |
|
| 47 |
sub prefix_output { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
return "Host '" . $options{instance_value}->{display} . "' "; |
| 51 |
} |
| 52 |
|
| 53 |
sub new { |
| 54 |
my ($class, %options) = @_; |
| 55 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 56 |
bless $self, $class; |
| 57 |
|
| 58 |
$options{options}->add_options(arguments => |
| 59 |
{ |
| 60 |
"filter-username:s" => { name => 'filter_username' }, |
| 61 |
}); |
| 62 |
|
| 63 |
return $self; |
| 64 |
} |
| 65 |
|
| 66 |
sub manage_selection { |
| 67 |
my ($self, %options) = @_; |
| 68 |
$options{sql}->connect(); |
| 69 |
|
| 70 |
my $query = q{ |
| 71 |
SELECT * FROM SYS.M_CONNECTIONS WHERE CONNECTION_TYPE IN ('Remote') |
| 72 |
}; |
| 73 |
$options{sql}->query(query => $query); |
| 74 |
|
| 75 |
$self->{host} = {}; |
| 76 |
while ((my $row = $options{sql}->fetchrow_hashref())) { |
| 77 |
my $name = $row->{HOST} . ':' . $row->{PORT}; |
| 78 |
|
| 79 |
$self->{host}->{$name} = { total => 0, display => $name } if (!defined($self->{host}->{$name})); |
| 80 |
|
| 81 |
if (defined($self->{option_results}->{filter_username}) && $self->{option_results}->{filter_username} ne '' && |
| 82 |
$row->{USER_NAME} !~ /$self->{option_results}->{filter_username}/) { |
| 83 |
$self->{output}->output_add(long_msg => "skipping '" . $name . '/' . $row->{USER_NAME} . "': no matching filter.", debug => 1); |
| 84 |
next; |
| 85 |
} |
| 86 |
|
| 87 |
$self->{host}->{$name}->{total}++; |
| 88 |
} |
| 89 |
|
| 90 |
if (scalar(keys %{$self->{host}}) <= 0) { |
| 91 |
$self->{output}->add_option_msg(short_msg => "No host found."); |
| 92 |
$self->{output}->option_exit(); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
1; |
| 97 |
|
| 98 |
__END__ |
| 99 |
|
| 100 |
=head1 MODE |
| 101 |
|
| 102 |
Check connected users. |
| 103 |
|
| 104 |
=over 8 |
| 105 |
|
| 106 |
=item B<--filter-username> |
| 107 |
|
| 108 |
Filter connected username. (can be a regex) |
| 109 |
|
| 110 |
=item B<--warning-*> |
| 111 |
|
| 112 |
Warning threshold. |
| 113 |
Can be: 'users'. |
| 114 |
|
| 115 |
=item B<--critical-*> |
| 116 |
|
| 117 |
Critical threshold. |
| 118 |
Can be: 'users'. |
| 119 |
|
| 120 |
=back |
| 121 |
|
| 122 |
=cut |