Merge pull request #34 from centreon/master

Merge from master
This commit is contained in:
Simon Bomm 2017-11-08 13:35:29 +01:00 committed by GitHub
commit 315b5a20af
222 changed files with 18276 additions and 3589 deletions

View File

@ -37,17 +37,18 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"config:s" => { name => 'config', },
"language:s" => { name => 'language', default => 'en' },
"dfsr" => { name => 'dfsr', },
"noeventlog" => { name => 'noeventlog', },
"timeout:s" => { name => 'timeout', default => 30 },
"config:s" => { name => 'config' },
"language:s" => { name => 'language', default => 'en' },
"dfsr" => { name => 'dfsr' },
"noeventlog" => { name => 'noeventlog' },
"nomachineaccount" => { name => 'nomachineaccount' },
"timeout:s" => { name => 'timeout', default => 30 },
});
$self->{os_is2003} = 0;
$self->{os_is2008} = 0;
$self->{os_is2012} = 0;
$self->{msg} = {global => undef, ok => undef, warning => undef, critical => undef};
$self->{msg} = { global => undef, ok => undef, warning => undef, critical => undef };
return $self;
}
@ -132,7 +133,8 @@ sub load_xml {
sub dcdiag {
my ($self, %options) = @_;
my $dcdiag_cmd = 'dcdiag /test:services /test:replications /test:advertising /test:fsmocheck /test:ridmanager /test:machineaccount';
my $dcdiag_cmd = 'dcdiag /test:services /test:replications /test:advertising /test:fsmocheck /test:ridmanager';
$dcdiag_cmd .= ' /test:machineaccount' if (!defined($self->{option_results}->{machineaccount}));
$dcdiag_cmd .= ' /test:frssysvol' if ($self->{os_is2003} == 1);
$dcdiag_cmd .= ' /test:sysvolcheck' if ($self->{os_is2008} == 1 || $self->{os_is2012} == 1);
@ -214,10 +216,14 @@ Specifies that SysVol replication uses DFS instead of FRS (Windows 2008 or later
Don't run the dc tests kccevent, frsevent and dfsrevent
=item B<--nomachineaccount>
Don't run the dc tests machineaccount
=item B<--timeout>
Set timeout time for command execution (Default: 30 sec)
=back
=cut
=cut

View File

@ -0,0 +1,143 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::activedirectory::local::mode::dfsrbacklog;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
];
$self->{maps_counters}->{global} = [
{ label => 'backlog', set => {
key_values => [ { name => 'backlog' } ],
output_template => 'Backlog File Count : %s',
perfdatas => [
{ label => 'backlog', value => 'backlog_absolute', template => '%s', min => 0 },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"sending-member:s" => { name => 'sending_member' },
"replication-group:s" => { name => 'replication_group' },
"replicated-folder:s" => { name => 'replicated_folder' },
"timeout:s" => { name => 'timeout', default => 30 },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->{option_results}->{command} = 'dfsrdiag';
$self->{option_results}->{command_options} = 'backlog ';
if (!defined($self->{option_results}->{sending_member}) || $self->{option_results}->{sending_member} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify sending-member option.");
$self->{output}->option_exit();
}
$self->{option_results}->{command_options} .= '/SendingMember:' . $self->{option_results}->{sending_member} . ' ';
if (!defined($self->{option_results}->{replication_group}) || $self->{option_results}->{replication_group} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify replication-group option.");
$self->{output}->option_exit();
}
$self->{option_results}->{command_options} .= '/RGName:' . $self->{option_results}->{replication_group} . ' ';
if (!defined($self->{option_results}->{replicated_folder}) || $self->{option_results}->{replicated_folder} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify replicated-folder option.");
$self->{output}->option_exit();
}
$self->{option_results}->{command_options} .= '/RFName:' . $self->{option_results}->{replicated_folder} . ' ';
}
sub manage_selection {
my ($self, %options) = @_;
my ($stdout) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
my $backlog = 0;
my $pattern = 'Backlog\s+File\s+Count\s*:\s+(\d+)';
$backlog = $1
if ($stdout =~ /$pattern/si);
$self->{global} = { backlog => $backlog };
}
1;
__END__
=head1 MODE
Check dfsr backlog.
=over 8
=item B<--sending-member>
Name of the member that is sending the replication data.
=item B<--replication-group>
Name for the replication group.
=item B<--replicated-folder>
Name name for the replicated folder.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--warning-backlog>
Threshold warning.
=item B<--critical-backlog>
Threshold critical.
=back
=cut

View File

@ -31,8 +31,9 @@ sub new {
$self->{version} = '0.1';
%{$self->{modes}} = (
'dcdiag' => 'apps::activedirectory::local::mode::dcdiag',
'netdom' => 'apps::activedirectory::local::mode::netdom',
'dcdiag' => 'apps::activedirectory::local::mode::dcdiag',
'dfsr-backlog' => 'apps::activedirectory::local::mode::dfsrbacklog',
'netdom' => 'apps::activedirectory::local::mode::netdom',
);
return $self;

View File

@ -28,7 +28,7 @@ use centreon::plugins::misc;
my $instance_mode;
sub custom_threshold_output {
sub custom_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
@ -67,25 +67,35 @@ sub custom_status_calc {
return 0;
}
sub custom_usage_threshold {
my ($self, %options) = @_;
if (!defined($instance_mode->{option_results}->{'critical-usage'}) || $instance_mode->{option_results}->{'critical-usage'} eq '') {
$self->{perfdata}->threshold_validate(label => 'critical-usage', value => $self->{result_values}->{watermark_absolute});
}
return $self->{perfdata}->threshold_check(value => $self->{result_values}->{usage_absolute}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All dedup status are ok' }
{ name => 'volume', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All dedup status are ok' }
];
$self->{maps_counters}->{pool} = [
$self->{maps_counters}->{volume} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_threshold_output'),
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
{ label => 'usage', set => {
key_values => [ { name => 'usage' }, { name => 'display' } ],
key_values => [ { name => 'usage' }, { name => 'watermark' }, { name => 'display' } ],
output_template => 'Use: %s %%',
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
perfdatas => [
{ label => 'used', value => 'usage_absolute', template => '%s',
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' },
@ -103,16 +113,19 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'nbdevquery' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-listdv -U -stype PureDisk' },
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'nbdevquery' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-listdp -U' },
"command2:s" => { name => 'command2', default => 'nbdevquery' },
"command2-path:s" => { name => 'command2_path' },
"command2-options:s" => { name => 'command2_options', default => '-listdv -U -stype PureDisk' },
"filter-name:s" => { name => 'filter_name' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} !~ /up/i' },
@ -129,10 +142,10 @@ sub check_options {
$self->change_macros();
}
sub prefix_pool_output {
sub prefix_volume_output {
my ($self, %options) = @_;
return "Disk pool name '" . $options{instance_value}->{display} . "' ";
return "Disk volume '" . $options{instance_value}->{display} . "' ";
}
sub change_macros {
@ -153,8 +166,36 @@ sub manage_selection {
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
$self->{pool} = {};
command_options => $self->{option_results}->{command_options});
#Disk Pool Name : NBU-MASTER-DP
#Disk Pool Id : NBU-MASTER-DP
#Disk Type : PureDisk
#Status : UP
#Flag : Patchwork
#Raw Size (GB) : 19236.97
#Usable Size (GB) : 19236.97
#High Watermark : 99
#Low Watermark : 60
#Num Volumes : 1
#Max IO Streams : -1
my $watermark = {};
while ($stdout =~ /^(Disk Pool Name.*?)(?=Disk Pool Name|\z)/msig) {
my $pool = $1;
$pool =~ /^Disk Pool Name\s*:\s*(.*?)\n/msi;
my $display = centreon::plugins::misc::trim($1);
$pool =~ /^High Watermark\s*:\s*(.*?)\n/msi;
$watermark->{$display} = centreon::plugins::misc::trim($1);
}
($stdout) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command2},
command_path => $self->{option_results}->{command2_path},
command_options => $self->{option_results}->{command2_options});
$self->{volume} = {};
#Disk Pool Name : NBU-MASTER-DP
#Disk Type : PureDisk
#Disk Volume Name : PureDiskVolume
@ -167,24 +208,26 @@ sub manage_selection {
#Flag : AdminUp
#Flag : InternalUp
while ($stdout =~ /^(Disk Pool Name.*?)(?=Disk Pool Name|\z)/msig) {
my $pool = $1;
my $volume = $1;
my ($display, $usage, $status);
$display = centreon::plugins::misc::trim($1) if ($pool =~ /^Disk Pool Name\s*:\s*(.*?)\n/msi);
$status = $1 if ($pool =~ /^Status\s*:\s*(.*?)\n/msi);
$usage = $1 if ($pool =~ /^Use%\s*:\s*(.*?)\n/msi);
my ($pool_name, $volume_name, $usage, $status);
$pool_name = centreon::plugins::misc::trim($1) if ($volume =~ /^Disk Pool Name\s*:\s*(.*?)\n/msi);
$volume_name = centreon::plugins::misc::trim($1) if ($volume =~ /^Disk Volume Name\s*:\s*(.*?)\n/msi);
$status = $1 if ($volume =~ /^Status\s*:\s*(.*?)\n/msi);
$usage = $1 if ($volume =~ /^Use%\s*:\s*(.*?)\n/msi);
my $display = $pool_name . '.' . $volume_name;
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$display !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1);
next;
}
$self->{pool}->{$display} = { display => $display, usage => $usage, status => $status };
$self->{volume}->{$display} = { display => $display, usage => $usage, status => $status, watermark => $watermark->{$pool_name} };
}
if (scalar(keys %{$self->{pool}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No pool found.");
if (scalar(keys %{$self->{volume}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No volume found.");
$self->{output}->option_exit();
}
}
@ -238,6 +281,19 @@ Command path (Default: none).
=item B<--command-options>
Command options (Default: ' -listdp -U').
=item B<--command2>
Command to get information (Default: 'nbdevquery').
Can be changed if you have output in a file.
=item B<--command2-path>
Command path (Default: none).
=item B<--command2-options>
Command options (Default: '-listdv -U -stype PureDisk').
=item B<--filter-name>

View File

@ -165,6 +165,9 @@ sub custom_frozen_calc {
$self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'};
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
$self->{result_values}->{kb} = $options{new_datas}->{$self->{instance} . '_kb'} - $options{old_datas}->{$self->{instance} . '_kb'};
$self->{result_values}->{parentid} = $options{new_datas}->{$self->{instance} . '_parentid'};
$self->{result_values}->{schedule} = $options{new_datas}->{$self->{instance} . '_schedule'};
$self->{result_values}->{jobid} = $options{new_datas}->{$self->{instance} . '_jobid'};
return 0;
}
@ -173,11 +176,23 @@ sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
{ name => 'policy', type => 2, cb_prefix_output => 'prefix_policy_output', cb_long_output => 'policy_long_output', message_multiple => 'All policies are ok',
group => [ { name => 'job', cb_prefix_output => 'prefix_job_output', skipped_code => { -11 => 1 } } ]
}
];
$self->{maps_counters}->{global} = [
{ label => 'total', set => {
key_values => [ { name => 'total' } ],
output_template => 'Total Jobs : %s',
perfdatas => [
{ label => 'total', value => 'total_absolute', template => '%s', min => 0 },
],
}
},
];
$self->{maps_counters}->{job} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' }, { name => 'type' }, { name => 'state' } ],
@ -196,7 +211,9 @@ sub set_counters {
}
},
{ label => 'frozen', threshold => 0, set => {
key_values => [ { name => 'kb', diff => 1 }, { name => 'status' }, { name => 'display' }, { name => 'elapsed' }, { name => 'type' }, { name => 'state' } ],
key_values => [ { name => 'kb', diff => 1 }, { name => 'status' },
{ name => 'display' }, { name => 'elapsed' }, { name => 'type' }, { name => 'state' },
{ name => 'parentid' }, { name => 'schedule' }, { name => 'jobid' } ],
closure_custom_calc => $self->can('custom_frozen_calc'),
closure_custom_output => $self->can('custom_frozen_output'),
closure_custom_perfdata => sub { return 0; },
@ -225,7 +242,9 @@ sub new {
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-report -most_columns' },
"filter-policy-name:s" => { name => 'filter_policy_name' },
"filter-type:s" => { name => 'filter_type' },
"filter-end-time:s" => { name => 'filter_end_time', default => 86400 },
"filter-start-time:s" => { name => 'filter_start_time' },
"ok-status:s" => { name => 'ok_status', default => '%{status} == 0' },
"warning-status:s" => { name => 'warning_status', default => '%{status} == 1' },
"critical-status:s" => { name => 'critical_status', default => '%{status} > 1' },
@ -297,7 +316,10 @@ sub manage_selection {
my ($self, %options) = @_;
$self->{cache_name} = "netbackup_" . $self->{mode} . '_' . (defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'me') . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_policy_name}) ? md5_hex($self->{option_results}->{filter_policy_name}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_start_time}) ? md5_hex($self->{option_results}->{filter_start_time}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{job_end_time}) ? md5_hex($self->{option_results}->{job_end_time}) : md5_hex('all'));
my ($stdout) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
@ -305,12 +327,14 @@ sub manage_selection {
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
$self->{global} = { total => 0 };
$self->{policy} = {};
my $current_time = time();
foreach my $line (split /\n/, $stdout) {
my @values = split /,/, $line;
my ($job_id, $job_type, $job_state, $job_status, $job_pname, $job_start_time, $job_end_time, $job_kb) =
($values[0], $values[1], $values[2], $values[3], $values[4], $values[8], $values[10], $values[14]);
my ($job_id, $job_type, $job_state, $job_status, $job_pname, $job_schedule, $job_start_time, $job_end_time, $job_kb, $job_parentid) =
($values[0], $values[1], $values[2], $values[3], $values[4], $values[5], $values[8], $values[10], $values[14], $values[33]);
$job_pname = defined($job_pname) && $job_pname ne '' ? $job_pname : 'unknown';
$job_status = defined($job_status) && $job_status =~ /[0-9]/ ? $job_status : undef;
@ -319,22 +343,33 @@ sub manage_selection {
$self->{output}->output_add(long_msg => "skipping job '" . $job_pname . "/" . $job_id . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
$job_type{$job_type} !~ /$self->{option_results}->{filter_type}/) {
$self->{output}->output_add(long_msg => "skipping job '" . $job_pname . "/" . $job_id . "': no matching filter type.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_end_time}) && $self->{option_results}->{filter_end_time} =~ /[0-9]+/ &&
defined($job_end_time) && $job_end_time =~ /[0-9]+/ && $job_end_time < $current_time - $self->{option_results}->{filter_end_time}) {
$self->{output}->output_add(long_msg => "skipping job '" . $job_pname . "/" . $job_id . "': too old.", debug => 1);
$self->{output}->output_add(long_msg => "skipping job '" . $job_pname . "/" . $job_id . "': end time too old.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_start_time}) && $self->{option_results}->{filter_start_time} =~ /[0-9]+/ &&
defined($job_start_time) && $job_start_time =~ /[0-9]+/ && $job_start_time < $current_time - $self->{option_results}->{filter_start_time}) {
$self->{output}->output_add(long_msg => "skipping job '" . $job_pname . "/" . $job_id . "': start time too old.", debug => 1);
next;
}
$self->{policy}->{$job_pname} = { job => {}, display => $job_pname } if (!defined($self->{policy}->{$job_pname}));
my $elapsed_time = $current_time - $job_start_time;
$self->{policy}->{$job_pname}->{job}->{$job_id} = { display => $job_id, elapsed => $elapsed_time,
status => $job_status, state => $job_state{$job_state}, type => $job_type{$job_type},
kb => defined($job_kb) && $job_kb =~ /[0-9]+/ ? $job_kb : undef };
}
if (scalar(keys %{$self->{policy}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No job found.");
$self->{output}->option_exit();
$self->{policy}->{$job_pname}->{job}->{$job_id} = {
display => $job_id, elapsed => $elapsed_time,
status => $job_status, state => $job_state{$job_state}, type => $job_type{$job_type},
kb => defined($job_kb) && $job_kb =~ /[0-9]+/ ? $job_kb : undef,
parentid => defined($job_parentid) ? $job_parentid : '',
jobid => $job_id,
schedule => defined($job_schedule) ? $job_schedule : '',
};
$self->{global}->{total}++;
}
}
@ -393,6 +428,14 @@ Command options (Default: '-report -most_columns').
Filter job policy name (can be a regexp).
=item B<--filter-type>
Filter job type (can be a regexp).
=item B<--filter-start-time>
Filter job with start time greater than current time less value in seconds.
=item B<--filter-end-time>
Filter job with end time greater than current time less value in seconds (Default: 86400).
@ -425,12 +468,22 @@ Can used special variables like: %{display}, %{status}, %{elapsed}, %{type}
=item B<--warning-frozen>
Set warning threshold for frozen jobs (Default: none)
Can used special variables like: %{display}, %{status}, %{elapsed}, %{type}, %{kb}
Can used special variables like:
%{display}, %{status}, %{elapsed}, %{type}, %{kb}, %{parentid}, %{schedule}, %{jobid}
=item B<--critical-frozen>
Set critical threshold for frozen jobs (Default: '%{state} =~ /active|queue/ && %{kb} == 0').
Can used special variables like: %{display}, %{status}, %{elapsed}, %{type}, %{kb}
Can used special variables like:
%{display}, %{status}, %{elapsed}, %{type}, %{kb}, %{parentid}, %{schedule}, %{jobid}
=item B<--warning-total>
Set warning threshold for total jobs.
=item B<--critical-total>
Set critical threshold for total jobs.
=back

View File

@ -0,0 +1,222 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::backup::tsm::local::custom::api;
use strict;
use warnings;
use centreon::plugins::misc;
sub new {
my ($class, %options) = @_;
my $self = {};
bless $self, $class;
if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n";
exit 3;
}
if (!defined($options{options})) {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit();
}
if (!defined($options{noptions})) {
$options{options}->add_options(arguments =>
{
"tsm-hostname:s" => { name => 'tsm_hostname' },
"tsm-username:s" => { name => 'tsm_username' },
"tsm-password:s" => { name => 'tsm_password' },
"ssh-hostname:s" => { name => 'ssh_hostname' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 45 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'dsmadmc' },
"command-path:s" => { name => 'command_path', default => '/opt/tivoli/tsm/client/ba/bin' },
"command-options:s" => { name => 'command_options', default => '' },
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'TSM CLI OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{mode} = $options{mode};
return $self;
}
sub set_options {
my ($self, %options) = @_;
$self->{option_results} = $options{option_results};
}
sub set_defaults {
my ($self, %options) = @_;
foreach (keys %{$options{default}}) {
if ($_ eq $self->{mode}) {
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
if (!defined($self->{option_results}->{$opt}[$i])) {
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
}
}
}
}
}
}
sub check_options {
my ($self, %options) = @_;
if (!defined($self->{option_results}->{tsm_hostname}) || $self->{option_results}->{tsm_hostname} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to set tsm-hostname option.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{tsm_username}) || $self->{option_results}->{tsm_username} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to set tsm-username option.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{tsm_password})) {
$self->{output}->add_option_msg(short_msg => "Need to set tsm-password option.");
$self->{output}->option_exit();
}
return 0;
}
sub tsm_build_options {
my ($self, %options) = @_;
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
if (defined($self->{option_results}->{ssh_hostname}) && $self->{option_results}->{ssh_hostname} ne '') {
$self->{option_results}->{hostname} = $self->{option_results}->{ssh_hostname};
$self->{option_results}->{remote} = 1;
}
$self->{option_results}->{command_options} =
"-comma -dataonly=yes -SERVER=\"$self->{option_results}->{tsm_hostname}\" -ID=\"$self->{option_results}->{tsm_username}\" -PASSWORD=\"$self->{option_results}->{tsm_password}\" -TAB \"$options{query}\"";
}
sub get_tsm_id {
my ($self, %options) = @_;
return $self->{option_results}->{tsm_hostname} . '_' . $self->{option_results}->{tsm_username} . '_' . $self->{option_results}->{tsm_password};
}
sub execute_command {
my ($self, %options) = @_;
$self->tsm_build_options(%options);
my ($response, $exit_code) = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options},
no_quit => 1
);
# 11 is for: ANR2034E SELECT: No match found using this criteria.
if ($exit_code != 0 && $exit_code != 11) {
$self->{output}->output_add(long_msg => $response);
$self->{output}->add_option_msg(short_msg => "Execution command issue (details).");
$self->{output}->option_exit();
}
$self->{output}->output_add(long_msg => $response, debug => 1);
return $response;
}
1;
__END__
=head1 NAME
tsm cli
=head1 SYNOPSIS
my tsm cli
=head1 TSM CLI OPTIONS
=over 8
=item B<--tsm-hostname>
TSM hostname to query (Required).
=item B<--tsm-username>
TSM username (Required).
=item B<--tsm-password>
TSM password (Required).
=item B<--ssh-hostname>
Specify SSH hostname.
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 45).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Specify command (default: 'dsmadmc').
=item B<--command-path>
Specify path (default: '/opt/tivoli/tsm/client/ba/bin')
=item B<--command-options>
Command options.
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,215 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::backup::tsm::local::mode::actlog;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
use centreon::plugins::statefile;
my $instance_mode;
sub custom_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("alarm [severity: %s] [message: %s] %s", $self->{result_values}->{severity},
$self->{result_values}->{message}, $self->{result_values}->{generation_time});
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{message} = $options{new_datas}->{$self->{instance} . '_message'};
$self->{result_values}->{severity} = $options{new_datas}->{$self->{instance} . '_severity'};
$self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'};
$self->{result_values}->{generation_time} = $options{new_datas}->{$self->{instance} . '_generation_time'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 },
group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ]
}
];
$self->{maps_counters}->{alarm} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'message' }, { name => 'severity' }, { name => 'since' }, { name => 'generation_time' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-time:s" => { name => 'filter_time', default => '1' },
"warning-status:s" => { name => 'warning_status', default => '%{severity} =~ /warning/' },
"critical-status:s" => { name => 'critical_status', default => '%{severity} =~ /error|severe/' },
"memory" => { name => 'memory' },
"timezone:s" => { name => 'timezone' },
});
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'DateTime',
error_msg => "Cannot load module 'DateTime'.");
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->check_options(%options);
}
$self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq '');
}
sub change_macros {
my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
}
}
}
sub manage_selection {
my ($self, %options) = @_;
my $response = $options{custom}->execute_command(
query => "SELECT date_time, severity, message FROM actlog WHERE date_time>current_timestamp-" . $self->{option_results}->{filter_time} . " hours"
);
$self->{alarms}->{global} = { alarm => {} };
my $last_time;
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->read(statefile => 'cache_tsm_' . $self->{mode} . '_' . $options{custom}->get_tsm_id());
$last_time = $self->{statefile_cache}->get(name => 'last_time');
}
my %map_severity = (E => 'error', W => 'warning', I => 'information', S => 'severe', K => 'kernel');
my ($i, $current_time) = (1, time());
#2017-09-19 12:08:14.000000,I,"ANR1283I File count is incorrect fo..."
while ($response =~ /^(.*?),(.*?),(.*)$/mg) {
my ($date, $severity, $message) = ($1, $2, $3);
$date =~ /^(\d+)-(\d+)-(\d+)\s+(\d+)[:\/](\d+)[:\/](\d+)/;
my $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6,
time_zone => $self->{option_results}->{timezone});
next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $dt->epoch);
my $diff_time = $current_time - $dt->epoch;
$message =~ s/^"(.*)"$/$1/;
$self->{alarms}->{global}->{alarm}->{$i} = {
message => $message,
severity => $map_severity{$severity},
since => $diff_time, generation_time => centreon::plugins::misc::change_seconds(value => $diff_time)
};
$i++;
}
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->write(data => { last_time => $current_time });
}
}
1;
__END__
=head1 MODE
Check activity logs.
=over 8
=item B<--filter-time>
Get activity log more recent than X hour(s) (default: '1').
=item B<--warning-status>
Set warning threshold for status (Default: '%{severity} =~ /warning/')
Can used special variables like: %{message}, %{severity}, %{since}
=item B<--critical-status>
Set critical threshold for status (Default: '%{severity} =~ /error|severe/').
Can used special variables like: %{message}, %{severity}, %{since}
=item B<--timezone>
Timezone of time options. Default is 'GMT'.
=item B<--memory>
Only check new alarms.
=back
=cut

View File

@ -0,0 +1,165 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::backup::tsm::local::mode::drives;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
];
$self->{maps_counters}->{global} = [
{ label => 'online', set => {
key_values => [ { name => 'online' } ],
output_template => 'online : %s',
perfdatas => [
{ label => 'online', value => 'online_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'offline', set => {
key_values => [ { name => 'offline' } ],
output_template => 'offline : %s',
perfdatas => [
{ label => 'offline', value => 'offline_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'unavailable', set => {
key_values => [ { name => 'unavailable' } ],
output_template => 'unavailable : %s',
perfdatas => [
{ label => 'unavailable', value => 'unavailable_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'empty', set => {
key_values => [ { name => 'empty' } ],
output_template => 'empty : %s',
perfdatas => [
{ label => 'empty', value => 'empty_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'loaded', set => {
key_values => [ { name => 'loaded' } ],
output_template => 'loaded : %s',
perfdatas => [
{ label => 'loaded', value => 'loaded_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'unloaded', set => {
key_values => [ { name => 'unloaded' } ],
output_template => 'unloaded : %s',
perfdatas => [
{ label => 'unloaded', value => 'unloaded_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'reserved', set => {
key_values => [ { name => 'reserved' } ],
output_template => 'reserved : %s',
perfdatas => [
{ label => 'reserved', value => 'reserved_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'unknown', set => {
key_values => [ { name => 'unknown' } ],
output_template => 'unknown : %s',
perfdatas => [
{ label => 'unknown', value => 'unknown_absolute', template => '%s', min => 0 },
],
}
},
];
}
sub prefix_global_output {
my ($self, %options) = @_;
return "Total Drives ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $response = $options{custom}->execute_command(
query => "SELECT library_name, drive_name, online, drive_state FROM drives"
);
$self->{global} = {
online => 0, offline => 0,
unavailable => 0, empty => 0, loaded => 0, unloaded => 0, reserved => 0, unknown => 0,
};
my %mapping_online = (yes => 'online', no => 'offline');
while ($response =~ /^(.*?),(.*?),(yes|no),(unavailable|empty|loaded|unloaded|reserved|unknown)$/mgi) {
my ($library, $drive, $online, $state) = ($1, $2, lc($3), lc($4));
$self->{global}->{$mapping_online{$online}}++;
$self->{global}->{$state}++;
}
}
1;
__END__
=head1 MODE
Check drives.
=over 8
=item B<--warning-*>
Set warning threshold. Can be : 'online', 'offline', 'unavailable',
'empty', 'loaded', 'unloaded', 'reserved', 'unknown'.
=item B<--critical-*>
Set critical threshold. Can be : Can be : 'online', 'offline', 'unavailable',
'empty', 'loaded', 'unloaded', 'reserved', 'unknown'.
=back
=cut

View File

@ -0,0 +1,113 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::backup::tsm::local::mode::nodes;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
];
$self->{maps_counters}->{global} = [
{ label => 'associated', set => {
key_values => [ { name => 'associated' } ],
output_template => 'Total Associated Nodes : %s',
perfdatas => [
{ label => 'associated', value => 'associated_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'non-associated', set => {
key_values => [ { name => 'non_associated' } ],
output_template => 'Total Non Associated Nodes : %s',
perfdatas => [
{ label => 'non_associated', value => 'non_associated_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'locked', set => {
key_values => [ { name => 'locked' } ],
output_template => 'Total Locked Nodes : %s',
perfdatas => [
{ label => 'locked', value => 'locked_absolute', template => '%s', min => 0 },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $response = $options{custom}->execute_command(
query => "SELECT node_name, 'non_associated' FROM nodes WHERE node_name NOT IN (SELECT node_name FROM associations) UNION SELECT node_name, 'associated' FROM nodes WHERE node_name IN (SELECT node_name FROM associations) UNION SELECT node_name, 'locked' FROM nodes WHERE locked='YES'"
);
$self->{global} = { associated => 0, non_associated => 0, locked => 0 };
while ($response =~ /^(.*?),(non_associated|associated|locked)$/mg) {
my ($node_name, $type) = ($1, $2);
$self->{global}->{$type}++;
$self->{output}->output_add(long_msg => "node '$node_name' is $type");
}
}
1;
__END__
=head1 MODE
Check node status.
=over 8
=item B<--warning-*>
Set warning threshold. Can be : 'associated', 'non-associated', 'locked'.
=item B<--critical-*>
Set critical threshold. Can be : Can be : 'associated', 'non-associated', 'locked'.
=back
=cut

View File

@ -0,0 +1,247 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::backup::tsm::local::mode::sessions;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
my $instance_mode;
sub custom_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("[client name: %s] [state: %s] [session type: %s] started since",
$self->{result_values}->{client_name}, $self->{result_values}->{state},
$self->{result_values}->{session_type}, $self->{result_values}->{generation_time});
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{session_id} = $options{new_datas}->{$self->{instance} . '_session_id'};
$self->{result_values}->{client_name} = $options{new_datas}->{$self->{instance} . '_client_name'};
$self->{result_values}->{session_type} = $options{new_datas}->{$self->{instance} . '_session_type'};
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
$self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'};
$self->{result_values}->{generation_time} = $options{new_datas}->{$self->{instance} . '_generation_time'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
{ name => 'sessions', type => 1, cb_prefix_output => 'prefix_sessions_output', message_multiple => 'All sessions are ok' },
];
$self->{maps_counters}->{global} = [
{ label => 'total', set => {
key_values => [ { name => 'total' } ],
output_template => 'Total Sessions : %s',
perfdatas => [
{ label => 'total', value => 'total_absolute', template => '%s', min => 0 },
],
}
},
];
$self->{maps_counters}->{sessions} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'session_id' }, { name => 'client_name' }, { name => 'session_type' },
{ name => 'state' }, { name => 'since' }, { name => 'generation_time' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
];
}
sub prefix_sessions_output {
my ($self, %options) = @_;
return "Session '" . $options{instance_value}->{session_id} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-clientname:s" => { name => 'filter_clientname' },
"filter-sessiontype:s" => { name => 'filter_sessiontype' },
"filter-state:s" => { name => 'filter_state' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' },
"timezone:s" => { name => 'timezone' },
});
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'DateTime',
error_msg => "Cannot load module 'DateTime'.");
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
$self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq '');
}
sub change_macros {
my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
}
}
}
sub manage_selection {
my ($self, %options) = @_;
my $response = $options{custom}->execute_command(
query => "SELECT session_id, client_name, start_time, state, session_type FROM sessions"
);
$self->{sessions} = {};
$self->{global} = { total => 0 };
while ($response =~ /^(.*?),(.*?),(.*?),(.*?),(.*?)$/mg) {
my ($session_id, $client_name, $start_time, $state, $session_type) = ($1, $2, $3, $4, $5);
$start_time =~ /^(\d+)-(\d+)-(\d+)\s+(\d+)[:\/](\d+)[:\/](\d+)/;
my $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6,
time_zone => $self->{option_results}->{timezone});
if (defined($self->{option_results}->{filter_clientname}) && $self->{option_results}->{filter_clientname} ne '' &&
$client_name !~ /$self->{option_results}->{filter_clientname}/) {
$self->{output}->output_add(long_msg => "skipping '" . $client_name . "': no matching client name filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_sessiontype}) && $self->{option_results}->{filter_sessiontype} ne '' &&
$session_type !~ /$self->{option_results}->{filter_sessiontype}/) {
$self->{output}->output_add(long_msg => "skipping '" . $session_type . "': no matching session type filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' &&
$state !~ /$self->{option_results}->{filter_state}/) {
$self->{output}->output_add(long_msg => "skipping '" . $session_type . "': no matching state filter.", debug => 1);
next;
}
my $diff_time = time() - $dt->epoch;
$self->{global}->{total}++;
$self->{sessions}->{$session_id} = {
session_id => $session_id,
client_name => $client_name,
state => $state,
session_type => $session_type,
since => $diff_time, generation_time => centreon::plugins::misc::change_seconds(value => $diff_time)
};
}
}
1;
__END__
=head1 MODE
Check sessions.
=over 8
=item B<--filter-clientname>
Filter by client name.
=item B<--filter-state>
Filter by state.
=item B<--filter-sessiontype>
Filter by session type.
=item B<--warning-status>
Set warning threshold for status (Default: '')
Can used special variables like: %{client_name}, %{state}, %{session_type}, %{since}
=item B<--critical-status>
Set critical threshold for status (Default: '').
Can used special variables like: %{client_name}, %{state}, %{session_type}, %{since}
=item B<--warning-*>
Set warning threshold. Can be : 'total'.
=item B<--critical-*>
Set critical threshold. Can be : 'total'.
=item B<--timezone>
Timezone of time options. Default is 'GMT'.
=back
=cut

View File

@ -0,0 +1,193 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::backup::tsm::local::mode::volumes;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
{ name => 'volumes', type => 1, cb_prefix_output => 'prefix_volumes_output', message_multiple => 'All volumes are ok' },
];
$self->{maps_counters}->{global} = [
{ label => 'total', set => {
key_values => [ { name => 'total' } ],
output_template => 'Volumes Total : %s',
perfdatas => [
{ label => 'total', value => 'total_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'online', set => {
key_values => [ { name => 'online' } ],
output_template => 'Online : %s',
perfdatas => [
{ label => 'online', value => 'online_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'offline', set => {
key_values => [ { name => 'offline' } ],
output_template => 'Offline : %s',
perfdatas => [
{ label => 'offline', value => 'offline_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'empty', set => {
key_values => [ { name => 'empty' } ],
output_template => 'Empty : %s',
perfdatas => [
{ label => 'empty', value => 'empty_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'pending', set => {
key_values => [ { name => 'pending' } ],
output_template => 'Pending : %s',
perfdatas => [
{ label => 'pending', value => 'pending_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'filling', set => {
key_values => [ { name => 'filling' } ],
output_template => 'Filling : %s',
perfdatas => [
{ label => 'filling', value => 'filling_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'full', set => {
key_values => [ { name => 'full' } ],
output_template => 'Full : %s',
perfdatas => [
{ label => 'full', value => 'full_absolute', template => '%s', min => 0 },
],
}
},
];
$self->{maps_counters}->{volumes} = [
{ label => 'used', set => {
key_values => [ { name => 'prct_utilized' }, { name => 'display' } ],
output_template => 'Usage : %s %%',
perfdatas => [
{ label => 'used', value => 'prct_utilized_absolute', template => '%s', min => 0, max => 100,
unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub prefix_volumes_output {
my ($self, %options) = @_;
return "Volumes '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-volume:s" => { name => 'filter_volume' },
"filter-stgpool:s" => { name => 'filter_stgpool' },
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $response = $options{custom}->execute_command(
query => "SELECT volume_name, stgpool_name, status, pct_utilized FROM volumes"
);
$self->{volumes} = {};
$self->{global} = { total => 0, online => 0, offline => 0, empty => 0, pending => 0, filling => 0, full => 0 };
while ($response =~ /^(.*?),(.*?),(.*?),(.*?)$/mg) {
my ($volume_name, $stgpool, $status, $pct_utilized) = ($1, $2, $3, $4);
if (defined($self->{option_results}->{filter_volume}) && $self->{option_results}->{filter_volume} ne '' &&
$volume_name !~ /$self->{option_results}->{filter_volume}/) {
$self->{output}->output_add(long_msg => "skipping '" . $volume_name . "': no matching volume name filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_stgpool}) && $self->{option_results}->{filter_stgpool} ne '' &&
$stgpool !~ /$self->{option_results}->{filter_stgpool}/) {
$self->{output}->output_add(long_msg => "skipping '" . $stgpool . "': no matching storage pool filter.", debug => 1);
next;
}
$self->{global}->{total}++;
$self->{global}->{lc($status)}++;
$self->{volumes}->{$volume_name} = {
display => $volume_name,
prct_utilized => $pct_utilized,
};
}
}
1;
__END__
=head1 MODE
Check volumes.
=over 8
=item B<--filter-volume>
Filter by volume name.
=item B<--filter-stgpool>
Filter by storage pool name.
=item B<--warning-*>
Set warning threshold. Can be : 'total', 'used',
'online',' offline', 'empty', 'pending', 'filling', full'.
=item B<--critical-*>
Set critical threshold. Can be : 'total', 'used',
'online', 'offline', empty', 'pending', 'filling', full'.
=back
=cut

View File

@ -0,0 +1,53 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::backup::tsm::local::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
%{$self->{modes}} = (
'actlog' => 'apps::backup::tsm::local::mode::actlog',
'drives' => 'apps::backup::tsm::local::mode::drives',
'nodes' => 'apps::backup::tsm::local::mode::nodes',
'sessions' => 'apps::backup::tsm::local::mode::sessions',
'volumes' => 'apps::backup::tsm::local::mode::volumes',
);
$self->{custom_modes}{api} = 'apps::backup::tsm::local::custom::api';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check IBM Tivoli Storage Manager (use dsmadmc).
=cut

View File

@ -0,0 +1,289 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::centreon::local::mode::brokerstats;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
use JSON;
my $instance_mode;
sub custom_threshold_output {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg;
if ($self->{result_values}->{type} eq 'input') {
$msg = sprintf("state : %s", $self->{result_values}->{state});
} else {
$msg = sprintf("state : %s [status : %s] [queue file enabled : %s]",
$self->{result_values}->{state}, $self->{result_values}->{status}, $self->{result_values}->{queue_file_enabled});
}
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{queue_file_enabled} = $options{new_datas}->{$self->{instance} . '_queue_file_enabled'};
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'endpoint', type => 1, cb_prefix_output => 'prefix_endpoint_output', message_multiple => 'Broker statistics are ok', skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{endpoint} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'queue_file_enabled' }, { name => 'state' }, { name => 'status' }, { name => 'type' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_threshold_output'),
}
},
{ label => 'speed-events', set => {
key_values => [ { name => 'speed_events' }, { name => 'display' } ],
output_template => 'Speed Events: %s/s',
perfdatas => [
{ label => 'speed_events', value => 'speed_events_absolute', template => '%s',
unit => 'events/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'queued-events', set => {
key_values => [ { name => 'queued_events' }, { name => 'display' } ],
output_template => 'Queued Events: %s',
perfdatas => [
{ label => 'queued_events', value => 'queued_events_absolute', template => '%s',
unit => 'events', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'unacknowledged-events', set => {
key_values => [ { name => 'unacknowledged_events' }, { name => 'display' } ],
output_template => 'Unacknowledged Events: %s',
perfdatas => [
{ label => 'unacknowledged_events', value => 'unacknowledged_events_absolute', template => '%s',
unit => 'events', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"broker-stats-file:s@" => { name => 'broker_stats_file' },
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"filter-name:s" => { name => 'filter_name' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{type} eq "output" and %{queue_file_enabled} =~ /yes/i' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{broker_stats_file}) || scalar(@{$self->{option_results}->{broker_stats_file}}) == 0) {
$self->{output}->add_option_msg(short_msg => "Please set broker-stats-file option.");
$self->{output}->option_exit();
}
$instance_mode = $self;
$self->change_macros();
}
sub prefix_endpoint_output {
my ($self, %options) = @_;
return "Endpoint $options{instance_value}->{type} '" . $options{instance_value}->{display} . "' ";
}
sub change_macros {
my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
}
}
}
sub manage_selection {
my ($self, %options) = @_;
$self->{endpoint} = {};
foreach my $config (@{$self->{option_results}->{broker_stats_file}}) {
my ($stdout) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => 'cat',
command_options => $config);
my $json;
eval {
$json = decode_json($stdout);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
$self->{output}->option_exit();
}
foreach my $entry (keys %$json) {
next if ($entry !~ /^endpoint/);
my $endpoint = $entry;
$endpoint =~ s/endpoint //;
my $state = $json->{$entry}->{state};
my $type = 'output';
$type = 'input' if (!defined($json->{$entry}->{status}));
$self->{endpoint}->{$endpoint} = {
display => $endpoint,
state => $state,
type => $type,
status => defined($json->{$entry}->{status}) ? $json->{$entry}->{status} : '-',
speed_events => $json->{$entry}->{event_processing_speed},
queued_events => $json->{$entry}->{queued_events},
unacknowledged_events => $json->{$entry}->{bbdo_unacknowledged_events},
queue_file_enabled => defined($json->{$entry}->{queue_file_enabled}) ? $json->{$entry}->{queue_file_enabled} : '-',
};
}
}
if (scalar(keys %{$self->{endpoint}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No endpoint found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check Centreon Broker statistics files.
=over 8
=item B<--remote>
Execute command remotely in 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--broker-stats-file>
Specify the centreon-broker json stats file (Required). Can be multiple.
=item B<--warning-*>
Threshold warning.
Can be: 'speed-events', 'queued-events', 'unacknowledged-events'.
=item B<--critical-*>
Threshold critical.
Can be: 'speed-events', 'queued-events', 'unacknowledged-events'.
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{queue_file_enabled}, %{state}, %{status}, %{type}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{type} eq "output" and %{queue_file_enabled} =~ /yes/i').
Can used special variables like: %{queue_file_enabled}, %{state}, %{status}, %{type}, %{display}
=back
=cut

View File

@ -98,20 +98,20 @@ sub run {
short_msg => "'$config': cannot parse xml");
next;
}
my %failover_finded = ();
my %file_finded = ();
my %failover_found = ();
my %file_found = ();
my $temporary;
foreach my $node ($xml->findnodes('/centreonBroker/output')) {
my %load = ();
foreach my $element ($node->getChildrenByTagName('*')) {
if ($element->nodeName eq 'failover') {
$failover_finded{$element->textContent} = 1;
$failover_found{$element->textContent} = 1;
} elsif ($element->nodeName =~ /^(name|type|path)$/) {
$load{$element->nodeName} = $element->textContent;
}
}
if (defined($load{type}) && $load{type} eq 'file') {
$file_finded{$load{name}} = {%load};
$file_found{$load{name}} = {%load};
}
}
@ -123,16 +123,16 @@ sub run {
# Check failovers
my $current_total = 0;
foreach my $failover (sort keys %failover_finded) {
next if (!defined($file_finded{$failover}));
foreach my $failover (sort keys %failover_found) {
next if (!defined($file_found{$failover}));
my ($status, $total, $size) = $self->check_directory(config => $config, path => $file_finded{$failover}->{path});
my ($status, $total, $size) = $self->check_directory(config => $config, path => $file_found{$failover}->{path});
next if (!$status);
$current_total += $total;
$total_size += $size;
my ($size_value, $size_unit) = $self->{perfdata}->change_bytes(value => $size);
$self->{output}->output_add(long_msg => sprintf("failover '%s': %d file(s) finded (%s)",
$self->{output}->output_add(long_msg => sprintf("failover '%s': %d file(s) found (%s)",
$failover, $total, $size_value . ' ' . $size_unit));
}
@ -149,7 +149,7 @@ sub run {
my ($status, $total, $size) = $self->check_directory(config => $config, path => $temporary);
if ($status) {
my ($size_value, $size_unit) = $self->{perfdata}->change_bytes(value => $size);
$self->{output}->output_add(long_msg => sprintf("temporary: %d file(s) finded (%s)",
$self->{output}->output_add(long_msg => sprintf("temporary: %d file(s) found (%s)",
$total, $size_value . ' ' . $size_unit));
if ($total > 0) {
$self->{output}->output_add(severity => 'CRITICAL',

View File

@ -31,6 +31,7 @@ sub new {
$self->{version} = '0.1';
%{$self->{modes}} = (
'broker-stats' => 'apps::centreon::local::mode::brokerstats',
'centreon-plugins-version' => 'apps::centreon::local::mode::centreonpluginsversion',
'downtime-trap' => 'apps::centreon::local::mode::downtimetrap',
'metaservice' => 'apps::centreon::local::mode::metaservice',

View File

@ -58,22 +58,22 @@ sub run {
$self->{connector} = $options{custom};
$self->{request} = [
{ mbean => "com.centreon.studio.map:name=BusinessGate,type=repo" }
{ mbean => "com.centreon.studio.map:name=statistics,type=context" }
];
my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1);
my $gates = $result->{"com.centreon.studio.map:name=BusinessGate,type=repo"}->{LoadedModelCount};
my $gates = $result->{"com.centreon.studio.map:name=statistics,type=context"}->{OpenContextCount};
my $exit = $self->{perfdata}->threshold_check(value => $gates,
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning'} ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Business gates opened : %d",
$result->{"com.centreon.studio.map:name=BusinessGate,type=repo"}->{LoadedModelCount}));
$result->{"com.centreon.studio.map:name=statistics,type=context"}->{OpenContextCount}));
$self->{output}->perfdata_add(label => 'gates',
value => $result->{"com.centreon.studio.map:name=BusinessGate,type=repo"}->{LoadedModelCount},
value => $result->{"com.centreon.studio.map:name=statistics,type=context"}->{OpenContextCount},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);

View File

@ -1,204 +0,0 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::elasticsearch::mode::cluster;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::http;
use JSON;
my $thresholds = {
cluster => [
['green', 'OK'],
['yellow', 'WARNING'],
['red', 'CRITICAL'],
],
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => 9200 },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => '/_cluster/health' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"timeout:s" => { name => 'timeout' },
"threshold-overload:s@" => { name => 'threshold_overload' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $status, $filter) = ($1, $2, $3);
if ($self->{output}->is_litteral_status(status => $status) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
$self->{output}->option_exit();
}
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub get_severity {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
if (defined($self->{overload_th}->{$options{section}})) {
foreach (@{$self->{overload_th}->{$options{section}}}) {
if ($options{value} =~ /$_->{filter}/i) {
$status = $_->{status};
return $status;
}
}
}
foreach (@{$thresholds->{$options{section}}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
}
sub run {
my ($self, %options) = @_;
my $jsoncontent = $self->{http}->request();
my $json = JSON->new;
my $webcontent;
eval {
$webcontent = $json->decode($jsoncontent);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response");
$self->{output}->option_exit();
}
my $exit = $self->get_severity(section => 'cluster', value => $webcontent->{status});
if ($webcontent->{status} eq 'green') {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("All shard are allocated for %s", $webcontent->{cluster_name}));
} elsif ($webcontent->{status} eq 'yellow') {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Primary shards are allocated but replicas not for %s", $webcontent->{cluster_name}));
} elsif ($webcontent->{status} eq 'red') {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Some or all primary shards aren't ready for %s", $webcontent->{cluster_name}));
}
$self->{output}->perfdata_add(label => 'primary_shard',
value => sprintf("%d", $webcontent->{active_primary_shards}),
min => 0,
);
$self->{output}->perfdata_add(label => 'shard',
value => sprintf("%d", $webcontent->{active_shards}),
min => 0,
);
$self->{output}->perfdata_add(label => 'unassigned_shard',
value => sprintf("%d", $webcontent->{unassigned_shards}),
min => 0,
);
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check Elasticsearch cluster health
=over 8
=item B<--hostname>
IP Addr/FQDN of the Elasticsearch host
=item B<--port>
Port used by Elasticsearch API (Default: '9200')
=item B<--proto>
Specify https if needed (Default: 'http')
=item B<--urlpath>
Set path to get Elasticsearch information (Default: '/_cluster/health')
=item B<--credentials>
Specify this option if you access webpage over basic authentification
=item B<--username>
Specify username for API authentification
=item B<--password>
Specify password for API authentification
=item B<--timeout>
Threshold for HTTP timeout (Default: 5)
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='cluster,CRITICAL,^(?!(on)$)'
=back
=cut

View File

@ -1,200 +0,0 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::elasticsearch::mode::indices;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::http;
use JSON;
use Data::Dumper;
my $thresholds = {
indices => [
['green', 'OK'],
['yellow', 'WARNING'],
['red', 'CRITICAL'],
],
};
my %map_states_indices = (
OK => 'green',
WARNING => 'yellow',
CRITICAL => 'red',
);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.1';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => 9200 },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => '/_cluster/health' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"timeout:s" => { name => 'timeout' },
"threshold-overload:s@" => { name => 'threshold_overload' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $status, $filter) = ($1, $2, $3);
if ($self->{output}->is_litteral_status(status => $status) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
$self->{output}->option_exit();
}
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
}
$self->{option_results}->{get_param} = [ 'level=indices' ];
$self->{http}->set_options(%{$self->{option_results}});
}
sub get_severity {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
if (defined($self->{overload_th}->{$options{section}})) {
foreach (@{$self->{overload_th}->{$options{section}}}) {
if ($options{value} =~ /$_->{filter}/i) {
$status = $_->{status};
return $status;
}
}
}
foreach (@{$thresholds->{$options{section}}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
}
sub run {
my ($self, %options) = @_;
my $jsoncontent = $self->{http}->request();
my $json = JSON->new;
my $webcontent;
eval {
$webcontent = $json->decode($jsoncontent);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response");
$self->{output}->option_exit();
}
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("All indices are in green state."));
my $exit = 'OK';
foreach my $indicename (sort (keys %{$webcontent->{indices}})) {
my $tmp_exit = $self->get_severity(section => 'indices', value => $webcontent->{indices}->{$indicename}->{status});
$exit = $self->{output}->get_most_critical(status => [ $tmp_exit, $exit ]);
if (!$self->{output}->is_status(value => $tmp_exit, compare => 'OK', litteral => 1)) {
$self->{output}->output_add(long_msg => sprintf("Indice %s status is in %s state",
$indicename, $webcontent->{indices}->{$indicename}->{status}));
}
}
if (!$self->{output}->is_status(value => $exit, compare => 'OK', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Some indices are in wrong state"));
}
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check Elasticsearch indices health
=over 8
=item B<--hostname>
IP Addr/FQDN of the Elasticsearch host
=item B<--port>
Port used by Elasticsearch API (Default: '9200')
=item B<--proto>
Specify https if needed (Default: 'http')
=item B<--urlpath>
Set path to get Elasticsearch information (Default: '/_cluster/health')
=item B<--credentials>
Specify this option if you access webpage over basic authentification
=item B<--username>
Specify username for API authentification
=item B<--password>
Specify password for API authentification
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='indices,CRITICAL,^(?!(on)$)'
=item B<--timeout>
Threshold for HTTP timeout (Default: 3)
=back
=cut

View File

@ -1,171 +0,0 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::elasticsearch::mode::nodescount;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::http;
use JSON;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => 9200 },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => '/_cluster/stats' },
"credentials" => { name => 'credentials' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout' },
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $jsoncontent = $self->{http}->request();
my $json = JSON->new;
my $webcontent;
eval {
$webcontent = $json->decode($jsoncontent);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response");
$self->{output}->option_exit();
}
my $exit = $self->{perfdata}->threshold_check(value => $webcontent->{nodes}->{count}->{total}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Number of nodes for cluster %s : %d",
$webcontent->{cluster_name}, $webcontent->{nodes}->{count}->{total}));
$self->{output}->perfdata_add(label => "node",
value => $webcontent->{nodes}->{count}->{total},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0,
);
$self->{output}->perfdata_add(label => "nodemasteronly",
value => $webcontent->{nodes}->{count}->{master_only},
min => 0,
);
$self->{output}->perfdata_add(label => "nodedataonly",
value => $webcontent->{nodes}->{count}->{data_only},
min => 0,
);
$self->{output}->perfdata_add(label => "nodemasterdata",
value => $webcontent->{nodes}->{count}->{master_data},
min => 0,
);
$self->{output}->perfdata_add(label => "nodeclient",
value => $webcontent->{nodes}->{count}->{client},
min => 0,
);
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check Elasticsearch number of nodes
=over 8
=item B<--hostname>
IP Addr/FQDN of the Elasticsearch host
=item B<--port>
Port used by Elasticsearch API (Default: '9200')
=item B<--proto>
Specify https if needed (Default: 'http')
=item B<--urlpath>
Set path to get Elasticsearch information (Default: '_cluster/stats')
=item B<--credentials>
Specify this option if you access webpage over basic authentification
=item B<--username>
Specify username for API authentification
=item B<--password>
Specify password for API authentification
=item B<--warning>
Threshold warning.
=item B<--critical>
Threshold critical.
=item B<--timeout>
Threshold for HTTP timeout (Default: 5)
=back
=cut

View File

@ -0,0 +1,202 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::elasticsearch::restapi::custom::api;
use strict;
use warnings;
use centreon::plugins::http;
use JSON::XS;
sub new {
my ($class, %options) = @_;
my $self = {};
bless $self, $class;
if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n";
exit 3;
}
if (!defined($options{options})) {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit();
}
if (!defined($options{noptions})) {
$options{options}->add_options(arguments =>
{
"hostname:s@" => { name => 'hostname' },
"port:s@" => { name => 'port' },
"proto:s@" => { name => 'proto' },
"username:s@" => { name => 'username' },
"password:s@" => { name => 'password' },
"proxyurl:s@" => { name => 'proxyurl' },
"timeout:s@" => { name => 'timeout' },
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{mode} = $options{mode};
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
sub set_options {
my ($self, %options) = @_;
$self->{option_results} = $options{option_results};
}
sub set_defaults {
my ($self, %options) = @_;
foreach (keys %{$options{default}}) {
if ($_ eq $self->{mode}) {
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
if (!defined($self->{option_results}->{$opt}[$i])) {
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
}
}
}
}
}
}
sub check_options {
my ($self, %options) = @_;
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? shift(@{$self->{option_results}->{hostname}}) : undef;
$self->{port} = (defined($self->{option_results}->{port})) ? shift(@{$self->{option_results}->{port}}) : 9200;
$self->{proto} = (defined($self->{option_results}->{proto})) ? shift(@{$self->{option_results}->{proto}}) : 'http';
$self->{username} = (defined($self->{option_results}->{username})) ? shift(@{$self->{option_results}->{username}}) : '';
$self->{password} = (defined($self->{option_results}->{password})) ? shift(@{$self->{option_results}->{password}}) : '';
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? shift(@{$self->{option_results}->{timeout}}) : 10;
$self->{proxyurl} = (defined($self->{option_results}->{proxyurl})) ? shift(@{$self->{option_results}->{proxyurl}}) : undef;
if (!defined($self->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Need to specify hostname option.");
$self->{output}->option_exit();
}
if (!defined($self->{hostname}) ||
scalar(@{$self->{option_results}->{hostname}}) == 0) {
return 0;
}
return 1;
}
sub build_options_for_httplib {
my ($self, %options) = @_;
$self->{option_results}->{hostname} = $self->{hostname};
$self->{option_results}->{timeout} = $self->{timeout};
$self->{option_results}->{port} = $self->{port};
$self->{option_results}->{proto} = $self->{proto};
$self->{option_results}->{proxyurl} = $self->{proxyurl};
$self->{option_results}->{credentials} = 1;
$self->{option_results}->{username} = $self->{username};
$self->{option_results}->{password} = $self->{password};
}
sub settings {
my ($self, %options) = @_;
$self->build_options_for_httplib();
$self->{http}->set_options(%{$self->{option_results}});
}
sub get {
my ($self, %options) = @_;
$self->settings();
my $response = $self->{http}->request(url_path => $options{path},
critical_status => '', warning_status => '');
my $content;
eval {
$content = JSON::XS->new->utf8->decode($response);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
$self->{output}->option_exit();
}
if (defined($content->{errmsg})) {
$self->{output}->add_option_msg(short_msg => "Cannot get data: " . $content->{errmsg});
$self->{output}->option_exit();
}
return $content;
}
1;
__END__
=head1 NAME
Elasticsearch REST API
=head1 SYNOPSIS
Elasticsearch Rest API custom mode
=head1 REST API OPTIONS
=over 8
=item B<--hostname>
Elasticsearch hostname.
=item B<--port>
Port used (Default: 9200)
=item B<--proto>
Specify https if needed (Default: 'http')
=item B<--username>
Elasticsearch username.
=item B<--password>
Elasticsearch password.
=item B<--proxyurl>
Proxy URL if any
=item B<--timeout>
Set HTTP timeout
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,203 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::elasticsearch::restapi::mode::cluster;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
my $instance_mode;
sub custom_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = "Cluster '" . $self->{result_values}->{display} . "' Status : " . $self->{result_values}->{status};
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
];
$self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
{ label => 'active-primary-shards', set => {
key_values => [ { name => 'active_primary_shards' } ],
output_template => 'Active Primary Shards : %s',
perfdatas => [
{ label => 'active_primary_shards', value => 'active_primary_shards_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'active-shards', set => {
key_values => [ { name => 'active_shards' } ],
output_template => 'Active Shards : %s',
perfdatas => [
{ label => 'active_shards', value => 'active_shards_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'unassigned-shards', set => {
key_values => [ { name => 'unassigned_shards' } ],
output_template => 'Unassigned Shards : %s',
perfdatas => [
{ label => 'unassigned_shards', value => 'unassigned_shards_absolute', template => '%s',
min => 0 },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"elastic-path:s" => { name => 'elastic_path', default => '/_cluster/health' },
"warning-status:s" => { name => 'warning_status', default => '%{status} =~ /yellow/i' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /red/i' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
}
sub change_macros {
my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
}
}
}
sub manage_selection {
my ($self, %options) = @_;
my $result = $options{custom}->get(path => $self->{option_results}->{elastic_path});
$self->{global} = {
display => $result->{cluster_name},
status => $result->{status},
active_primary_shards => $result->{active_primary_shards},
active_shards => $result->{active_shards},
unassigned_shards => $result->{unassigned_shards},
};
}
1;
__END__
=head1 MODE
Check Elasticsearch cluster.
=over 8
=item B<--elastic-path>
Set path to get Elasticsearch information (Default: '/_cluster/health')
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^status$'
=item B<--warning-*>
Threshold warning.
Can be: 'active-primary-shards', 'active-shards', 'unassigned-shards'.
=item B<--critical-*>
Threshold critical.
Can be: 'active-primary-shards', 'active-shards', 'unassigned-shards'.
=item B<--warning-status>
Set warning threshold for status (Default: '%{status} =~ /yellow/i')
Can used special variables like: %{status}.
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /red/i').
Can used special variables like: %{status}.
=back
=cut

View File

@ -0,0 +1,219 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::elasticsearch::restapi::mode::indices;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
my $instance_mode;
sub custom_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status};
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'indices', type => 1, cb_prefix_output => 'prefix_indices_output', message_multiple => 'All indices are ok' },
];
$self->{maps_counters}->{indices} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
{ label => 'active-primary-shards', set => {
key_values => [ { name => 'active_primary_shards' }, { name => 'display' } ],
output_template => 'Active Primary Shards : %s',
perfdatas => [
{ label => 'active_primary_shards', value => 'active_primary_shards_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'active-shards', set => {
key_values => [ { name => 'active_shards' }, { name => 'display' } ],
output_template => 'Active Shards : %s',
perfdatas => [
{ label => 'active_shards', value => 'active_shards_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"elastic-path:s" => { name => 'elastic_path', default => '/_cluster/health?level=indices' },
"filter-name:s" => { name => 'filter_name' },
"warning-status:s" => { name => 'warning_status', default => '%{status} =~ /yellow/i' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /red/i' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
}
sub prefix_indices_output {
my ($self, %options) = @_;
return "Indices '" . $options{instance_value}->{display} . "' ";
}
sub change_macros {
my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
}
}
}
sub manage_selection {
my ($self, %options) = @_;
$self->{indices} = {};
my $result = $options{custom}->get(path => $self->{option_results}->{elastic_path});
foreach my $indice (keys %{$result->{indices}}) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$indice !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $indice . "': no matching filter.", debug => 1);
next;
}
$self->{indices}->{$indice} = {
display => $indice,
status => $result->{indices}->{$indice}->{status},
active_primary_shards => $result->{indices}->{$indice}->{active_primary_shards},
active_shards => $result->{indices}->{$indice}->{active_shards},
};
}
if (scalar(keys %{$self->{indices}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No indices found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check Elasticsearch indices.
=over 8
=item B<--elastic-path>
Set path to get Elasticsearch information (Default: '/_cluster/health?level=indices')
=item B<--filter-name>
Filter name (can be a regexp).
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^status$'
=item B<--warning-*>
Threshold warning.
Can be: 'active-primary-shards', 'active-shards'.
=item B<--critical-*>
Threshold critical.
Can be: 'active-primary-shards', 'active-shards'.
=item B<--warning-status>
Set warning threshold for status (Default: '%{status} =~ /yellow/i')
Can used special variables like: %{display}, %{status}.
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /red/i').
Can used special variables like: %{display}, %{status}.
=back
=cut

View File

@ -0,0 +1,144 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::elasticsearch::restapi::mode::nodes;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'nodes', type => 0, cb_prefix_output => 'prefix_output' },
];
$self->{maps_counters}->{nodes} = [
{ label => 'total', set => {
key_values => [ { name => 'total' } ],
output_template => 'Total : %s',
perfdatas => [
{ label => 'total', value => 'total_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'masteronly', set => {
key_values => [ { name => 'master_only' } ],
output_template => 'Master Only : %s',
perfdatas => [
{ label => 'master_only', value => 'master_only_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'dataonly', set => {
key_values => [ { name => 'data_only' } ],
output_template => 'Data Only : %s',
perfdatas => [
{ label => 'data_only', value => 'data_only_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'masterdata', set => {
key_values => [ { name => 'master_data' } ],
output_template => 'Master Data : %s',
perfdatas => [
{ label => 'master_data', value => 'master_data_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'client', set => {
key_values => [ { name => 'client' } ],
output_template => 'Client : %s',
perfdatas => [
{ label => 'client', value => 'client_absolute', template => '%s',
min => 0 },
],
}
},
];
}
sub prefix_output {
my ($self, %options) = @_;
return "Nodes ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"elastic-path:s" => { name => 'elastic_path', default => '/_cluster/stats' },
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $result = $options{custom}->get(path => $self->{option_results}->{elastic_path});
$self->{nodes} = {
%{$result->{nodes}->{count}}
};
}
1;
__END__
=head1 MODE
Check Elasticsearch nodes.
=over 8
=item B<--elastic-path>
Set path to get Elasticsearch information (Default: '/_cluster/stats')
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^total$'
=item B<--warning-*>
Threshold warning.
Can be: 'total', 'masteronly', 'dataonly', 'masterdata', 'client'.
=item B<--critical-*>
Threshold critical.
Can be: 'total', 'masteronly', 'dataonly', 'masterdata', 'client'.
=back
=cut

View File

@ -0,0 +1,50 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::elasticsearch::restapi::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'cluster' => 'apps::elasticsearch::restapi::mode::cluster',
'indices' => 'apps::elasticsearch::restapi::mode::indices',
'nodes' => 'apps::elasticsearch::restapi::mode::nodes',
);
$self->{custom_modes}{api} = 'apps::elasticsearch::restapi::custom::api';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check elasticsearch through HTTP/REST API.
=cut

View File

@ -81,7 +81,7 @@ sub set_counters {
{ name => 'vm', type => 1, cb_prefix_output => 'prefix_vm_output', message_multiple => 'All integration services are ok' },
];
$self->{maps_counters}->{vm} = [
{ label => 'snapshot', set => {
{ label => 'status', , threshold => 0, set => {
key_values => [ { name => 'vm' }, { name => 'status' }, { name => 'vmaddition' },
{ name => 'operatingsystemshutdownenabled' }, { name => 'timesynchronizationenabled' },
{ name => 'dataexchangeenabled' }, { name => 'heartbeatenabled' }, { name => 'backupenabled' } ],
@ -287,4 +287,4 @@ Can used special variables like: %{vm}, %{vmaddition}, %{status}
=back
=cut
=cut

View File

@ -0,0 +1,217 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::inin::ig::snmp::mode::spanusage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
my $instance_mode;
sub custom_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status};
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_i3IgSpanInfoSpanState'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'span', type => 1, cb_prefix_output => 'prefix_span_output', message_multiple => 'All spans are ok' }
];
$self->{maps_counters}->{span} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'i3IgSpanInfoSpanState' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
{ label => 'active-channels', set => {
key_values => [ { name => 'i3IgSpanInfoActiveChannels' }, { name => 'display' } ],
output_template => 'Current Active Channels : %s',
perfdatas => [
{ label => 'active_channels', value => 'i3IgSpanInfoActiveChannels_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} !~ /closed|ready/i' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
}
sub prefix_span_output {
my ($self, %options) = @_;
return "Span '" . $options{instance_value}->{display} . "' ";
}
sub change_macros {
my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
}
}
}
my %map_state = (0 => 'closed', 1 => 'ready', 2 => 'alarm', 3 => 'error');
my $mapping = {
i3IgSpanInfoSpanId => { oid => '.1.3.6.1.4.1.2793.4.2.3.1.3' },
i3IgSpanInfoActiveChannels => { oid => '.1.3.6.1.4.1.2793.4.2.3.1.5' },
i3IgSpanInfoSpanState => { oid => '.1.3.6.1.4.1.2793.4.2.3.1.6', map => \%map_state },
};
my $oid_i3IgSpanInfoTableEntry = '.1.3.6.1.4.1.2793.4.2.3.1';
sub manage_selection {
my ($self, %options) = @_;
$self->{span} = {};
my $snmp_result = $options{snmp}->get_table(oid => $oid_i3IgSpanInfoTableEntry,
nothing_quit => 1);
foreach my $oid (keys %{$snmp_result}) {
next if ($oid !~ /^$mapping->{i3IgSpanInfoSpanState}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$result->{i3IgSpanInfoSpanId} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $result->{i3IgSpanInfoSpanId} . "': no matching filter.", debug => 1);
next;
}
$self->{span}->{$instance} = {
display => $result->{i3IgSpanInfoSpanId},
%$result
};
}
if (scalar(keys %{$self->{span}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No span found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check span usage.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^status$'
=item B<--filter-name>
Filter span name (can be a regexp).
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{status}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} !~ /closed|ready/i').
Can used special variables like: %{status}, %{display}
=item B<--warning-*>
Threshold warning.
Can be: 'active-channels'.
=item B<--critical-*>
Threshold critical.
Can be: 'active-channels'.
=back
=cut

View File

@ -0,0 +1,157 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::inin::ig::snmp::mode::stats;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, message_separator => ' - ' },
{ name => 'cg', type => 1, cb_prefix_output => 'prefix_cg_output', message_multiple => 'All channel groups are ok' }
];
$self->{maps_counters}->{global} = [
{ label => 'sip-active-calls', set => {
key_values => [ { name => 'SipActiveCallsCount' } ],
output_template => 'SIP Current Active Calls : %s',
perfdatas => [
{ label => 'sip_active_calls', value => 'SipActiveCallsCount_absolute', template => '%d',
min => 0 },
],
}
},
{ label => 'tdm-active-calls', set => {
key_values => [ { name => 'TdmActiveCallsCount' } ],
output_template => 'TDM Current Active Calls : %s',
perfdatas => [
{ label => 'tdm_active_calls', value => 'TdmActiveCallsCount_absolute', template => '%d',
min => 0 },
],
}
},
];
$self->{maps_counters}->{cg} = [
{ label => 'channel-group-active-calls', set => {
key_values => [ { name => 'i3IgChannelGroupActiveCallsCount' }, { name => 'display' } ],
output_template => 'Current Active Calls : %s',
perfdatas => [
{ label => 'channel_group_active_calls', value => 'i3IgChannelGroupActiveCallsCount_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
});
return $self;
}
sub prefix_cg_output {
my ($self, %options) = @_;
return "Channel group '" . $options{instance_value}->{display} . "' ";
}
my $mapping = {
i3IgChannelGroupName => { oid => '.1.3.6.1.4.1.2793.4.2.13.1.2' },
i3IgChannelGroupActiveCallsCount => { oid => '.1.3.6.1.4.1.2793.4.2.13.1.3' },
};
my $oid_i3IgInfo = '.1.3.6.1.4.1.2793.4.2';
my $oid_i3IgSipActiveCallsCount = '.1.3.6.1.4.1.2793.4.2.4';
my $oid_i3IgTdmActiveCallsCount = '.1.3.6.1.4.1.2793.4.2.7';
sub manage_selection {
my ($self, %options) = @_;
$self->{cg} = {};
my $snmp_result = $options{snmp}->get_table(oid => $oid_i3IgInfo, start => $oid_i3IgSipActiveCallsCount, end => ,
nothing_quit => 1);
foreach my $oid (keys %{$snmp_result}) {
next if ($oid !~ /^$mapping->{i3IgChannelGroupActiveCallsCount}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$result->{i3IgChannelGroupName} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $result->{i3IgSpanInfoSpanId} . "': no matching filter.", debug => 1);
next;
}
$self->{cg}->{$instance} = { display => $result->{i3IgChannelGroupName}, %$result };
}
$self->{global} = {
SipActiveCallsCount => $snmp_result->{$oid_i3IgSipActiveCallsCount . '.0'},
TdmActiveCallsCount => $snmp_result->{$oid_i3IgTdmActiveCallsCount . '.0'},
};
}
1;
__END__
=head1 MODE
Check statistics.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^sip-active-calls$'
=item B<--filter-name>
Filter channel group name (can be a regexp).
=item B<--warning-*>
Threshold warning.
Can be: 'sip-active-calls', 'tdm-active-calls',
'channel-group-active-calls'.
=item B<--critical-*>
Threshold critical.
Can be: 'sip-active-calls', 'tdm-active-calls',
'channel-group-active-calls'.
=back
=cut

View File

@ -0,0 +1,49 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::inin::ig::snmp::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_snmp);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
%{$self->{modes}} = (
'span-usage' => 'apps::inin::ig::snmp::mode::spanusage',
'stats' => 'apps::inin::ig::snmp::mode::stats',
);
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Interactive Intelligence Interaction Gateway in SNMP.
=cut

View File

@ -0,0 +1,214 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::java::awa::jmx::mode::agent;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
use DateTime;
my $instance_mode;
sub custom_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'active : ' . $self->{result_values}->{active} . ' [IpAddress: ' . $self->{result_values}->{ipaddress} . ' ]' .
'[LastCheck: ' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since}) . ']';
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'};
$self->{result_values}->{ipaddress} = $options{new_datas}->{$self->{instance} . '_ipaddress'};
$self->{result_values}->{active} = $options{new_datas}->{$self->{instance} . '_active'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'agent', type => 1, cb_prefix_output => 'prefix_agent_output', message_multiple => 'All agents are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{agent} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'active' }, { name => 'ipaddress' }, { name => 'since' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' },
"timezone:s" => { name => 'timezone' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
$self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq '');
}
sub change_macros {
my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
}
}
}
sub prefix_agent_output {
my ($self, %options) = @_;
return "Agent '" . $options{instance_value}->{display} . "' ";
}
sub manage_selection {
my ($self, %options) = @_;
$self->{app} = {};
$self->{request} = [
{ mbean => 'Automic:name=*,side=Agents,type=*',
attributes => [ { name => 'LastCheck' }, { name => 'IpAddress' },
{ name => 'Active' }, { name => 'Name' } ] },
];
my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
foreach my $mbean (keys %{$result}) {
$mbean =~ /name=(.*?)(,|$)/i;
my $name = $1;
$mbean =~ /type=(.*?)(,|$)/i;
my $display = $1 . '.' . $name;
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$display !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1);
next;
}
next if ($result->{$mbean}->{LastCheck} !~ /^\s*(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)/);
my $dt = DateTime->new(
year => $1,
month => $2,
day => $3,
hour => $4,
minute => $5,
second => $6,
time_zone => $self->{option_results}->{timezone},
);
$self->{agent}->{$display} = {
display => $display,
ipaddress => $result->{$mbean}->{IpAddress},
active => $result->{$mbean}->{Active} ? 'yes' : 'no',
since => time() - $dt->epoch,
};
}
if (scalar(keys %{$self->{agent}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No agent found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check agent status.
=over 8
=item B<--filter-name>
Filter agent name (can be a regexp).
=item B<--warning-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{since}, %{display}, %{ipaddress}, %{active}
=item B<--critical-status>
Set critical threshold for status (Default: '').
Can used special variables like: %{since}, %{display}, %{ipaddress}, %{active}
=item B<--timezone>
Timezone options (the date from the equipment overload that option). Default is 'GMT'.
=back
=cut

View File

@ -0,0 +1,138 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::java::awa::jmx::mode::listagents;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"filter-type:s" => { name => 'filter_type' },
});
$self->{agents} = {};
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{request} = [
{ mbean => 'Automic:name=*,side=Agents,type=*',
attributes => [ { name => 'IpAddress' }, { name => 'Active' }, { name => 'Name' } ] },
];
my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
foreach my $mbean (keys %{$result}) {
$mbean =~ /name=(.*?)(,|$)/i;
my $name = $1;
$mbean =~ /type=(.*?)(,|$)/i;
my $type = $1;
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$name !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
$type !~ /$self->{option_results}->{filter_type}/) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
next;
}
$self->{agents}->{$name . '.' . $type} = {
name => $name, type => $type,
ipaddress => $result->{$mbean}->{IpAddress},
active => $result->{$mbean}->{Active} ? 'yes' : 'no',
};
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $instance (sort keys %{$self->{agents}}) {
$self->{output}->output_add(long_msg => '[name = ' . $self->{agents}->{$instance}->{name} . "]" .
" [type = '" . $self->{agents}->{$instance}->{type} . "']" .
" [ipaddress = '" . $self->{agents}->{$instance}->{ipaddress} . "']" .
" [active = '" . $self->{agents}->{$instance}->{active} . "']"
);
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List agents:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name', 'type', 'ipaddress', 'active']);
}
sub disco_show {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $instance (sort keys %{$self->{agents}}) {
$self->{output}->add_disco_entry(
%{$self->{agents}->{$instance}}
);
}
}
1;
__END__
=head1 MODE
List agents.
=over 8
=item B<--filter-name>
Filter by agent name (can be a regexp).
=item B<--filter-type>
Filter by type (can be a regexp).
=back
=cut

View File

@ -0,0 +1,136 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::java::awa::jmx::mode::listqueues;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"filter-type:s" => { name => 'filter_type' },
});
$self->{queues} = {};
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{request} = [
{ mbean => 'Automic:name=*,side=Queues,type=*',
attributes => [ { name => 'Status' }, { name => 'Name' } ] },
];
my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
foreach my $mbean (keys %{$result}) {
$mbean =~ /name=(.*?)(,|$)/i;
my $name = $1;
$mbean =~ /type=(.*?)(,|$)/i;
my $type = $1;
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$name !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
$type !~ /$self->{option_results}->{filter_type}/) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
next;
}
$self->{queues}->{$name . '.' . $type} = {
name => $name, type => $type,
status => $result->{$mbean}->{Status},
};
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $instance (sort keys %{$self->{queues}}) {
$self->{output}->output_add(long_msg => '[name = ' . $self->{queues}->{$instance}->{name} . "]" .
" [type = '" . $self->{queues}->{$instance}->{type} . "']" .
" [status = '" . $self->{queues}->{$instance}->{status} . "']"
);
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List queues:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name', 'type', 'status']);
}
sub disco_show {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $instance (sort keys %{$self->{queues}}) {
$self->{output}->add_disco_entry(
%{$self->{queues}->{$instance}}
);
}
}
1;
__END__
=head1 MODE
List queues.
=over 8
=item B<--filter-name>
Filter by queue name (can be a regexp).
=item B<--filter-type>
Filter by type (can be a regexp).
=back
=cut

View File

@ -0,0 +1,141 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::java::awa::jmx::mode::listservers;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"filter-type:s" => { name => 'filter_type' },
});
$self->{servers} = {};
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{request} = [
{ mbean => 'Automic:name=*,side=Servers,type=*',
attributes => [ { name => 'NetArea' }, { name => 'IpAddress' },
{ name => 'Active' }, { name => 'Name' } ] },
];
my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
foreach my $mbean (keys %{$result}) {
$mbean =~ /name=(.*?)(,|$)/i;
my $name = $1;
$mbean =~ /type=(.*?)(,|$)/i;
my $type = $1;
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$name !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
$type !~ /$self->{option_results}->{filter_type}/) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
next;
}
$self->{servers}->{$name . '.' . $type} = {
name => $name, type => $type,
ipaddress => $result->{$mbean}->{IpAddress},
active => $result->{$mbean}->{Active} ? 'yes' : 'no',
netarea => $result->{$mbean}->{NetArea},
};
}
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $instance (sort keys %{$self->{servers}}) {
$self->{output}->output_add(long_msg => '[name = ' . $self->{servers}->{$instance}->{name} . "]" .
" [type = '" . $self->{servers}->{$instance}->{type} . "']" .
" [ipaddress = '" . $self->{servers}->{$instance}->{ipaddress} . "']" .
" [active = '" . $self->{servers}->{$instance}->{active} . "']" .
" [netarea = '" . $self->{servers}->{$instance}->{netarea} . "']"
);
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List servers:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name', 'type', 'ipaddress', 'active', 'netarea']);
}
sub disco_show {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $instance (sort keys %{$self->{servers}}) {
$self->{output}->add_disco_entry(
%{$self->{servers}->{$instance}}
);
}
}
1;
__END__
=head1 MODE
List servers.
=over 8
=item B<--filter-name>
Filter by server name (can be a regexp).
=item B<--filter-type>
Filter by type (can be a regexp).
=back
=cut

View File

@ -0,0 +1,188 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::java::awa::jmx::mode::queue;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
my $instance_mode;
sub custom_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status};
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'queue', type => 1, cb_prefix_output => 'prefix_queue_output', message_multiple => 'All queues are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{queue} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} !~ /GREEN/i' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
}
sub change_macros {
my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
}
}
}
sub prefix_queue_output {
my ($self, %options) = @_;
return "Queue '" . $options{instance_value}->{display} . "' ";
}
sub manage_selection {
my ($self, %options) = @_;
$self->{app} = {};
$self->{request} = [
{ mbean => 'Automic:name=*,side=Queues,type=*',
attributes => [ { name => 'Status' }, { name => 'Name' } ] },
];
my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
foreach my $mbean (keys %{$result}) {
$mbean =~ /name=(.*?)(,|$)/i;
my $name = $1;
$mbean =~ /type=(.*?)(,|$)/i;
my $display = $1 . '.' . $name;
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$display !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1);
next;
}
$self->{queue}->{$display} = {
display => $display,
status => $result->{$mbean}->{Status},
};
}
if (scalar(keys %{$self->{queue}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No queue found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check queue status.
=over 8
=item B<--filter-name>
Filter queue name (can be a regexp).
=item B<--warning-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{display}, %{status}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} !~ /GREEN/i').
Can used special variables like: %{display}, %{status}
=back
=cut

View File

@ -0,0 +1,192 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::java::awa::jmx::mode::server;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
my $instance_mode;
sub custom_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'active : ' . $self->{result_values}->{active} . ' [IpAddress: ' . $self->{result_values}->{ipaddress} . ' ]';
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{ipaddress} = $options{new_datas}->{$self->{instance} . '_ipaddress'};
$self->{result_values}->{active} = $options{new_datas}->{$self->{instance} . '_active'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'server', type => 1, cb_prefix_output => 'prefix_server_output', message_multiple => 'All servers are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{server} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'active' }, { name => 'ipaddress' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
}
sub change_macros {
my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
}
}
}
sub prefix_server_output {
my ($self, %options) = @_;
return "Server '" . $options{instance_value}->{display} . "' ";
}
sub manage_selection {
my ($self, %options) = @_;
$self->{app} = {};
$self->{request} = [
{ mbean => 'Automic:name=*,side=Servers,type=*',
attributes => [ { name => 'NetArea' }, { name => 'IpAddress' },
{ name => 'Active' }, { name => 'Name' } ] },
];
my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
foreach my $mbean (keys %{$result}) {
$mbean =~ /name=(.*?)(,|$)/i;
my $name = $1;
$mbean =~ /type=(.*?)(,|$)/i;
my $display = $1 . '.' . $name;
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$display !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1);
next;
}
$self->{server}->{$display} = {
display => $display,
ipaddress => $result->{$mbean}->{IpAddress},
active => $result->{$mbean}->{Active} ? 'yes' : 'no',
};
}
if (scalar(keys %{$self->{server}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No server found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check server status.
=over 8
=item B<--filter-name>
Filter server name (can be a regexp).
=item B<--warning-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{display}, %{ipaddress}, %{active}
=item B<--critical-status>
Set critical threshold for status (Default: '').
Can used special variables like: %{display}, %{ipaddress}, %{active}
=back
=cut

View File

@ -0,0 +1,54 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::java::awa::jmx::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'agent' => 'apps::java::awa::jmx::mode::agent',
'list-agents' => 'apps::java::awa::jmx::mode::listagents',
'list-queues' => 'apps::java::awa::jmx::mode::listqueues',
'list-servers' => 'apps::java::awa::jmx::mode::listservers',
'queue' => 'apps::java::awa::jmx::mode::queue',
'server' => 'apps::java::awa::jmx::mode::server',
);
$self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Automic Workload Automation (Awa) in JMX. Need Jolokia agent.
=cut

View File

@ -0,0 +1,189 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::java::hibernate::jmx::mode::stats;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'app', type => 1, cb_prefix_output => 'prefix_app_output', message_multiple => 'All hibernate applications are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{app} = [
{ label => 'connect-count', set => {
key_values => [ { name => 'connect', diff => 1 }, { name => 'display' } ],
output_template => 'Connect Count : %s',
perfdatas => [
{ label => 'connect_count', value => 'connect_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'close-count', set => {
key_values => [ { name => 'close', diff => 1 }, { name => 'display' } ],
output_template => 'Close Count : %s',
perfdatas => [
{ label => 'close_count', value => 'close_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'query-count', set => {
key_values => [ { name => 'query', diff => 1 }, { name => 'display' } ],
output_template => 'Query Count : %s',
perfdatas => [
{ label => 'query_count', value => 'query_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'insert-count', set => {
key_values => [ { name => 'insert', diff => 1 }, { name => 'display' } ],
output_template => 'Insert Count : %s',
perfdatas => [
{ label => 'insert_count', value => 'insert_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'update-count', set => {
key_values => [ { name => 'update', diff => 1 }, { name => 'display' } ],
output_template => 'Update Count : %s',
perfdatas => [
{ label => 'update_count', value => 'update_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
});
return $self;
}
sub prefix_app_output {
my ($self, %options) = @_;
return "Application '" . $options{instance_value}->{display} . "' ";
}
sub manage_selection {
my ($self, %options) = @_;
$self->{app} = {};
$self->{request} = [
{ mbean => 'Hibernate:Application=*,type=statistics',
attributes => [ { name => 'SessionCloseCount' }, { name => 'ConnectCount' },
{ name => 'EntityInsertCount' }, { name => 'CollectionUpdateCount' },
{ name => 'QueryExecutionCount' }, { name => 'StatisticsEnabled' } ] },
{ mbean => 'Hibernate:type=statistics',
attributes => [ { name => 'SessionCloseCount' }, { name => 'ConnectCount' },
{ name => 'EntityInsertCount' }, { name => 'CollectionUpdateCount' },
{ name => 'QueryExecutionCount' }, { name => 'StatisticsEnabled' } ] },
];
my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
foreach my $mbean (keys %{$result}) {
$mbean =~ /Application=(.*?),/;
my $app = defined($1) ? $1 : 'global';
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$app !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $app . "': no matching filter.", debug => 1);
next;
}
if (!$result->{$mbean}->{StatisticsEnabled}) {
$self->{output}->output_add(long_msg => "skipping '" . $app . "': statistics is disabled.", debug => 1);
next;
}
$self->{app}->{$app} = {
display => $app,
close => $result->{$mbean}->{SessionCloseCount},
connect => $result->{$mbean}->{ConnectCount},
insert => $result->{$mbean}->{EntityInsertCount},
query => $result->{$mbean}->{QueryExecutionCount},
update => $result->{$mbean}->{CollectionUpdateCount},
};
}
if (scalar(keys %{$self->{app}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No application found (or staistics is disabled).");
$self->{output}->option_exit();
}
$self->{cache_name} = "hibernate_" . $self->{mode} . '_' . md5_hex($options{custom}->{url}) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check hibernate statistics.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^connect-count$'
=item B<--filter-name>
Filter application name (can be a regexp).
=item B<--warning-*>
Threshold warning.
Can be: 'connect-count', 'query-count', 'insert-count',
'update-count' 'close-count'.
=item B<--critical-*>
Threshold critical.
Can be: 'connect-count', 'query-count', 'insert-count',
'update-count' 'close-count'.
=back
=cut

View File

@ -0,0 +1,49 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::java::hibernate::jmx::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'stats' => 'apps::java::hibernate::jmx::mode::stats',
);
$self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Hibernate in JMX. Need Jolokia agent.
=cut

View File

@ -0,0 +1,172 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::java::solr::jmx::mode::cacheusage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'solrcache', type => 1, cb_prefix_output => 'prefix_cache_output', message_multiple => 'All caches are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{solrcache} = [
{ label => 'evictions-count', set => {
key_values => [ { name => 'cumulative_evictions', diff => 1 }, { name => 'display' } ],
output_template => 'Evictions Count : %s',
perfdatas => [
{ label => 'evictions_count', value => 'cumulative_evictions_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'lookups-count', set => {
key_values => [ { name => 'cumulative_lookups', diff => 1 }, { name => 'display' } ],
output_template => 'Lookups Count : %s',
perfdatas => [
{ label => 'lookups_count', value => 'cumulative_lookups_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'inserts-count', set => {
key_values => [ { name => 'cumulative_inserts', diff => 1 }, { name => 'display' } ],
output_template => 'Inserts Count : %s',
perfdatas => [
{ label => 'inserts_count', value => 'cumulative_inserts_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'hits-count', set => {
key_values => [ { name => 'cumulative_hits', diff => 1 }, { name => 'display' } ],
output_template => 'Hits Count : %s',
perfdatas => [
{ label => 'hits_count', value => 'cumulative_hits_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
});
return $self;
}
sub prefix_cache_output {
my ($self, %options) = @_;
return "Cache '" . $options{instance_value}->{display} . "' ";
}
sub manage_selection {
my ($self, %options) = @_;
$self->{solrcache} = {};
$self->{request} = [
{ mbean => 'solr/*:id=*,type=documentCache',
attributes => [ { name => 'cumulative_evictions' }, { name => 'cumulative_lookups' },
{ name => 'cumulative_inserts' }, { name => 'cumulative_hits' } ] },
{ mbean => 'solr/*:id=*,type=filterCache',
attributes => [ { name => 'cumulative_evictions' }, { name => 'cumulative_lookups' },
{ name => 'cumulative_inserts' }, { name => 'cumulative_hits' } ] },
{ mbean => 'solr/*:id=*,type=queryResultCache',
attributes => [ { name => 'cumulative_evictions' }, { name => 'cumulative_lookups' },
{ name => 'cumulative_inserts' }, { name => 'cumulative_hits' } ] },
];
my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
foreach my $mbean (keys %{$result}) {
$mbean =~ /solr\/(.*?):.*?,type=(.*?)(?:,|$)/;
my $cache = $1 . '.' . $2;
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$cache !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $cache . "': no matching filter.", debug => 1);
next;
}
$self->{solrcache}->{$cache} = {
display => $cache,
%{$result->{$mbean}},
};
}
if (scalar(keys %{$self->{solrcache}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No cache found.");
$self->{output}->option_exit();
}
$self->{cache_name} = "solr_" . $self->{mode} . '_' . md5_hex($options{custom}->{url}) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check cache usage.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^evictions-count$'
=item B<--filter-name>
Filter cache name (can be a regexp).
=item B<--warning-*>
Threshold warning.
Can be: 'evictions-count', 'lookups-count', 'inserts-count',
'hits-count'.
=item B<--critical-*>
Threshold critical.
Can be: 'evictions-count', 'lookups-count', 'inserts-count',
'hits-count'.
=back
=cut

View File

@ -0,0 +1,170 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::java::solr::jmx::mode::requesthandlerusage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'rh', type => 1, cb_prefix_output => 'prefix_rh_output', message_multiple => 'All request handlers are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{rh} = [
{ label => '15min-rate-requests', set => {
key_values => [ { name => '15minRateRequestsPerSecond' }, { name => 'display' } ],
output_template => '15min Rate Requests : %.7f/s',
perfdatas => [
{ label => '15min_rate_requests', value => '15minRateRequestsPerSecond_absolute', template => '%.7f',
min => 0, unit => '/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'avg-requests', set => {
key_values => [ { name => 'avgRequestsPerSecond' }, { name => 'display' } ],
output_template => 'Average Requests : %.7f/s',
perfdatas => [
{ label => 'avg_requests', value => 'avgRequestsPerSecond_absolute', template => '%.7f',
min => 0, unit => '/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'avg-time', set => {
key_values => [ { name => 'avgTimePerRequest' }, { name => 'display' } ],
output_template => 'Average Time Per Request : %.3f ms',
perfdatas => [
{ label => 'avg_time', value => 'avgTimePerRequest_absolute', template => '%.3f',
min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'requests-count', set => {
key_values => [ { name => 'requests', diff => 1 }, { name => 'display' } ],
output_template => 'Requests Count : %s',
perfdatas => [
{ label => 'requests_count', value => 'requests_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name', default => '(/select|/update)$' },
});
return $self;
}
sub prefix_rh_output {
my ($self, %options) = @_;
return "Request Handler '" . $options{instance_value}->{display} . "' ";
}
sub manage_selection {
my ($self, %options) = @_;
$self->{rh} = {};
$self->{request} = [
{ mbean => 'solr/*:id=org.apache.solr.handler.component.SearchHandler,type=*',
attributes => [ { name => '15minRateRequestsPerSecond' }, { name => 'avgTimePerRequest' },
{ name => 'avgRequestsPerSecond' }, { name => 'requests' } ] },
{ mbean => 'solr/*:id=org.apache.solr.handler.UpdateRequestHandler,type=*',
attributes => [ { name => '15minRateRequestsPerSecond' }, { name => 'avgTimePerRequest' },
{ name => 'avgRequestsPerSecond' }, { name => 'requests' } ] },
];
my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
foreach my $mbean (keys %{$result}) {
$mbean =~ /solr\/(.*?):id=.*?\.(.*?)Handler,type=(.*?)(?:,|$)/;
my $rhname = $1 . '.' . $2 . '.' . $3;
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$rhname !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $rhname . "': no matching filter.", debug => 1);
next;
}
$self->{rh}->{$rhname} = {
display => $rhname,
%{$result->{$mbean}},
};
}
if (scalar(keys %{$self->{rh}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No request handler found.");
$self->{output}->option_exit();
}
$self->{cache_name} = "solr_" . $self->{mode} . '_' . md5_hex($options{custom}->{url}) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check request handler usage.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^requests-count$'
=item B<--filter-name>
Filter request handler name (can be a regexp).
Default: '(/select|/update)$'.
=item B<--warning-*>
Threshold warning.
Can be: 'requests-count', 'avg-requests', 'avg-time',
'15min-rate-requests'.
=item B<--critical-*>
Threshold critical.
Can be: 'requests-count', 'avg-requests', 'avg-time',
'15min-rate-requests'.
=back
=cut

View File

@ -0,0 +1,50 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::java::solr::jmx::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'cache-usage' => 'apps::java::solr::jmx::mode::cacheusage',
'request-handler-usage' => 'apps::java::solr::jmx::mode::requesthandlerusage',
);
$self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Solr in JMX. Need Jolokia agent.
=cut

View File

@ -0,0 +1,177 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::java::zookeeper::jmx::mode::stats;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'zk', type => 1, cb_prefix_output => 'prefix_zk_output', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{zk} = [
{ label => 'avg-request-latency', set => {
key_values => [ { name => 'AvgRequestLatency' } ],
output_template => 'Avg Request Latency : %s ms',
perfdatas => [
{ label => 'avg_request_latency', value => 'AvgRequestLatency_absolute', template => '%s',
min => 0, unit => 'ms' },
],
}
},
{ label => 'max-request-latency', set => {
key_values => [ { name => 'MaxRequestLatency' } ],
output_template => 'Max Request Latency : %s ms',
perfdatas => [
{ label => 'max_request_latency', value => 'MaxRequestLatency_absolute', template => '%s',
min => 0, unit => 'ms' },
],
}
},
{ label => 'outstanding-requests', set => {
key_values => [ { name => 'OutstandingRequests' } ],
output_template => 'Outstanding Requests : %s',
perfdatas => [
{ label => 'outstanding_requests', value => 'OutstandingRequests_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'packets-received', set => {
key_values => [ { name => 'PacketsReceived', diff => 1 } ],
output_template => 'Packets Received : %s',
perfdatas => [
{ label => 'packets_received', value => 'PacketsReceived_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'packets-sent', set => {
key_values => [ { name => 'PacketsSent', diff => 1 } ],
output_template => 'Packets Sent : %s',
perfdatas => [
{ label => 'packets_sent', value => 'PacketsSent_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'num-connections', set => {
key_values => [ { name => 'NumAliveConnections' } ],
output_template => 'Num Alive Connections : %s',
perfdatas => [
{ label => 'num_connections', value => 'NumAliveConnections_absolute', template => '%s',
min => 0 },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
return $self;
}
sub prefix_zk_output {
my ($self, %options) = @_;
return "Zookeeper '" . $options{instance_value}->{display} . "' ";
}
sub manage_selection {
my ($self, %options) = @_;
$self->{zk} = {};
$self->{request} = [
{ mbean => 'org.apache.ZooKeeperService:name0=*,name1=*,name2=Leader',
attributes => [ { name => 'AvgRequestLatency' }, { name => 'MaxRequestLatency' },
{ name => 'OutstandingRequests' }, { name => 'PacketsReceived' },
{ name => 'PacketsSent' }, { name => 'NumAliveConnections' } ] },
{ mbean => 'org.apache.ZooKeeperService:name0=*,name1=*,name2=Follower',
attributes => [ { name => 'AvgRequestLatency' }, { name => 'MaxRequestLatency' },
{ name => 'OutstandingRequests' }, { name => 'PacketsReceived' },
{ name => 'PacketsSent' }, { name => 'NumAliveConnections' } ] },
];
my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
foreach my $mbean (keys %{$result}) {
next if ($mbean !~ /name2=(.*?)(?:,|$)/);
my $type = $1;
$self->{zk}->{$type} = {
display => $type,
%{$result->{$mbean}},
};
}
if (scalar(keys %{$self->{zk}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No zookeeper found.");
$self->{output}->option_exit();
}
$self->{cache_name} = "zookeeper_" . $self->{mode} . '_' . md5_hex($options{custom}->{url}) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check hibernate statistics.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^avg-request-latency$'
=item B<--warning-*>
Threshold warning.
Can be: 'avg-request-latency', 'max-request-latency', 'outstanding-requests',
'packets-received' 'packets-sent', 'num-connections'.
=item B<--critical-*>
Threshold critical.
Can be: 'avg-request-latency', 'max-request-latency', 'outstanding-requests',
'packets-received' 'packets-sent', 'num-connections'.
=back
=cut

View File

@ -0,0 +1,49 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::java::zookeeper::jmx::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'stats' => 'apps::java::zookeeper::jmx::mode::stats',
);
$self->{custom_modes}{jolokia} = 'centreon::common::protocols::jmx::custom::jolokia';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Zookeeper in JMX. Need Jolokia agent.
=cut

View File

@ -103,7 +103,7 @@ sub run {
my $p = XML::Parser->new(NoLWP => 1);
my $xp = XML::XPath->new(parser => $p, xml => $stdout);
my $listHttpSampleNode = $xp->findnodes('/testResults/httpSample');
my $listHttpSampleNode = $xp->findnodes('/testResults/httpSample|/testResults/sample');
my $timing0 = 0;
my $timing1 = 0;

View File

@ -1,288 +0,0 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::pfsense::snmp::mode::blockedpackets;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use POSIX;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $oid_pfsenseInterfaceName = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.2';
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning-in:s" => { name => 'warning_in', },
"warning-out:s" => { name => 'warning_out', },
"critical-in:s" => { name => 'critical_in', },
"critical-out:s" => { name => 'critical_out', },
"name" => { name => 'use_name' },
"interface:s" => { name => 'interface' },
"regexp" => { name => 'use_regexp' },
"regexp-isensitive" => { name => 'use_regexpi' },
});
$self->{interface_id_selected} = [];
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning-in', value => $self->{option_results}->{warning_in})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning in threshold '" . $self->{option_results}->{warning_in} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'warning-out', value => $self->{option_results}->{warning_out})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning out threshold '" . $self->{option_results}->{warning_out} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical-in', value => $self->{option_results}->{critical_in})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical in threshold '" . $self->{option_results}->{critical_in} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical-out', value => $self->{option_results}->{critical_out})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical out threshold '" . $self->{option_results}->{critical_out} . "'.");
$self->{output}->option_exit();
}
$self->{statefile_value}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{hostname} = $self->{snmp}->get_hostname();
$self->{snmp_port} = $self->{snmp}->get_port();
if ($self->{snmp}->is_snmpv1()) {
$self->{output}->add_option_msg(short_msg => "Can't check SNMP 64 bits counters with SNMPv1.");
$self->{output}->option_exit();
}
$self->manage_selection();
my $oid_pfsenseBlockedInPackets = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.12';
my $oid_pfsenseBlockedOutPackets = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.14';
my ($result, $valueIn, $valueOut);
my $new_datas = {};
$self->{statefile_value}->read(statefile => "pfsense_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{interface}) ? md5_hex($self->{option_results}->{interface}) : md5_hex('all')));
$self->{snmp}->load(oids => [$oid_pfsenseBlockedInPackets, $oid_pfsenseBlockedOutPackets],
instances => $self->{interface_id_selected});
$result = $self->{snmp}->get_leef();
$new_datas->{last_timestamp} = time();
my $old_timestamp;
if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp})) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All interfaces are ok.');
}
foreach (sort @{$self->{interface_id_selected}}) {
my $display_value = $self->{names}->{$_};
#################
# New values
#################
$new_datas->{'in_blocked_' . $_} = $result->{$oid_pfsenseBlockedInPackets . "." . $_};
$new_datas->{'out_blocked_' . $_} = $result->{$oid_pfsenseBlockedOutPackets . "." . $_};
################
# Old values
################
my @getting = ('in_blocked', 'out_blocked');
my $old_datas = {};
$old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
foreach my $key (@getting) {
$old_datas->{$key} = $self->{statefile_value}->get(name => $key . '_' . $_);
if (!defined($old_datas->{$key}) || $new_datas->{$key . '_' . $_} < $old_datas->{$key}) {
# We set 0. Has reboot.
$old_datas->{$key} = 0;
}
}
if (!defined($old_timestamp)) {
next;
}
my $time_delta = $new_datas->{last_timestamp} - $old_timestamp;
if ($time_delta <= 0) {
# At least one second. two fast calls ;)
$time_delta = 1;
}
###########
my $in_blocked_absolute = $new_datas->{'in_blocked_' . $_} - $old_datas->{in_blocked};
my $out_blocked_absolute = $new_datas->{'out_blocked_' . $_} - $old_datas->{out_blocked};
my $in_blocked_absolute_per_sec = $in_blocked_absolute / $time_delta;
my $out_blocked_absolute_per_sec = $out_blocked_absolute / $time_delta;
###############
# Manage Output
###############
my $exit1 = $self->{perfdata}->threshold_check(value => $in_blocked_absolute_per_sec, threshold => [ { label => 'critical-in', 'exit_litteral' => 'critical' }, { label => 'warning-in', exit_litteral => 'warning' } ]);
my $exit2 = $self->{perfdata}->threshold_check(value => $out_blocked_absolute_per_sec, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]);
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
$self->{output}->output_add(long_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s [%i packets], Out Blocked : %.2f /s [%i packets]", $display_value,
$in_blocked_absolute_per_sec, $in_blocked_absolute,
$out_blocked_absolute_per_sec, $out_blocked_absolute));
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp}))) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s [%i packets], Out Blocked : %.2f /s [%i packets]", $display_value,
$in_blocked_absolute_per_sec, $in_blocked_absolute,
$out_blocked_absolute_per_sec, $out_blocked_absolute));
}
my $extra_label = '';
$extra_label = '_' . $display_value if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp}));
$self->{output}->perfdata_add(label => 'packets_blocked_in_per_sec' . $extra_label,
value => sprintf("%.2f", $in_blocked_absolute_per_sec),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-in'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-in'),
min => 0);
$self->{output}->perfdata_add(label => 'packets_blocked_out_per_sec' . $extra_label,
value => sprintf("%.2f", $out_blocked_absolute_per_sec),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-out'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out'),
min => 0);
}
$self->{statefile_value}->write(data => $new_datas);
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
}
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection {
my ($self, %options) = @_;
my $all_ids = [];
$self->{names} = {};
my $result = $self->{snmp}->get_table(oid => $oid_pfsenseInterfaceName, nothing_quit => 1);
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
next if ($key !~ /\.([0-9]+)$/);
push @{$all_ids}, $1;
$self->{names}->{$1} = $self->{output}->to_utf8($result->{$key});
}
if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})) {
# get by ID
push @{$self->{interface_id_selected}}, $self->{option_results}->{interface};
if (!defined($self->{names}->{$self->{option_results}->{interface}})) {
$self->{output}->add_option_msg(short_msg => "No interface found for id '" . $self->{option_results}->{interface} . "'.");
$self->{output}->option_exit();
}
} else {
foreach my $i (@{$all_ids}) {
my $filter_name = $self->{names}->{$i};
next if (!defined($filter_name));
if (!defined($self->{option_results}->{interface})) {
push @{$self->{interface_id_selected}}, $i;
next;
}
if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/i) {
push @{$self->{interface_id_selected}}, $i;
}
if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/) {
push @{$self->{interface_id_selected}}, $i;
}
if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{interface}) {
push @{$self->{interface_id_selected}}, $i;
}
}
if (scalar(@{$self->{interface_id_selected}}) <= 0) {
if (defined($self->{option_results}->{interface})) {
$self->{output}->add_option_msg(short_msg => "No interface found for name '" . $self->{option_results}->{interface} . "' (maybe you should reload cache file).");
} else {
$self->{output}->add_option_msg(short_msg => "No interface found (maybe you should reload cache file).");
}
$self->{output}->option_exit();
}
}
}
1;
__END__
=head1 MODE
Check pfSense blocked packets.
=over 8
=item B<--warning-in>
Threshold warning for input blocked packets.
=item B<--warning-out>
Threshold warning for output blocked packets.
=item B<--critical-in>
Threshold critical for input blocked packets.
=item B<--critical-out>
Threshold critical for output blocked packets.
=item B<--interface>
Set the interface (number expected) ex: 1, 2,... (empty means 'check all interface').
=item B<--name>
Allows to use interface name with option --interface instead of interface oid index.
=item B<--regexp>
Allows to use regexp to filter interfaces (with option --name).
=item B<--regexp-isensitive>
Allows to use regexp non case-sensitive (with --regexp).
=back
=cut

View File

@ -0,0 +1,112 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::pfsense::snmp::mode::listpfinterfaces;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
my $oid_pfInterfacesIfDescr = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.2';
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $snmp_result = $self->{snmp}->get_table(oid => $oid_pfInterfacesIfDescr, nothing_quit => 1);
$self->{pfint} = {};
foreach my $oid (keys %{$snmp_result}) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping pfInteface '" . $snmp_result->{$oid} . "'.", debug => 1);
next;
}
$self->{pfint}->{$snmp_result->{$oid}} = { name => $snmp_result->{$oid} };
}
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->manage_selection();
foreach my $name (sort keys %{$self->{pfint}}) {
$self->{output}->output_add(long_msg => "'" . $name . "'");
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List pfIntefaces:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name']);
}
sub disco_show {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->manage_selection();
foreach my $name (sort keys %{$self->{pfint}}) {
$self->{output}->add_disco_entry(name => $name);
}
}
1;
__END__
=head1 MODE
List pfInteface.
=over 8
=item B<--filter-name>
Filter by pfinterface name.
=back
=cut

View File

@ -1,130 +0,0 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::pfsense::snmp::mode::memorydroppedpackets;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use POSIX;
use centreon::plugins::statefile;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
$self->{statefile_value}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{hostname} = $self->{snmp}->get_hostname();
$self->{snmp_port} = $self->{snmp}->get_port();
my $oid_pfsenseMemDropPackets = '.1.3.6.1.4.1.12325.1.200.1.2.6.0';
my ($result, $value);
$result = $self->{snmp}->get_leef(oids => [ $oid_pfsenseMemDropPackets ], nothing_quit => 1);
$value = $result->{$oid_pfsenseMemDropPackets};
$self->{statefile_value}->read(statefile => 'pfsense_' . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode});
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
my $old_memDropPackets = $self->{statefile_value}->get(name => 'memDropPackets');
my $new_datas = {};
$new_datas->{last_timestamp} = time();
$new_datas->{memDropPackets} = $value;
$self->{statefile_value}->write(data => $new_datas);
if (!defined($old_timestamp) || !defined($old_memDropPackets)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
$old_memDropPackets = 0 if ($old_memDropPackets > $new_datas->{memDropPackets});
my $delta_time = $new_datas->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0);
my $memDropPacketsPerSec = ($new_datas->{memDropPackets} - $old_memDropPackets) / $delta_time;
my $exit_code = $self->{perfdata}->threshold_check(value => $memDropPacketsPerSec,
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->perfdata_add(label => 'dropped_packets_Per_Sec',
value => sprintf("%.2f", $memDropPacketsPerSec),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);
$self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("Dropped packets due to memory limitations : %.2f /s",
$memDropPacketsPerSec));
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check number of packets per second dropped due to memory limitations.
=over 8
=item B<--warning>
Threshold warning for dropped packets in packets per second.
=item B<--critical>
Threshold critical for dropped packets in packets per second.
=back
=cut

View File

@ -0,0 +1,167 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::pfsense::snmp::mode::packetstats;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, message_separator => ' - ' },
];
$self->{maps_counters}->{global} = [
{ label => 'match', set => {
key_values => [ { name => 'pfCounterMatch', diff => 1 } ],
per_second => 1,
output_template => 'Packets Matched Filter Rule : %.2f/s',
perfdatas => [
{ label => 'match', value => 'pfCounterMatch_per_second', template => '%.2f', unit => '/s',
min => 0 },
],
}
},
{ label => 'badoffset', set => {
key_values => [ { name => 'pfCounterBadOffset', diff => 1 } ],
per_second => 1,
output_template => 'Bad Offset Packets : %.2f/s',
perfdatas => [
{ label => 'bad_offset', value => 'pfCounterBadOffset_per_second', template => '%.2f', unit => '/s',
min => 0 },
],
}
},
{ label => 'fragment', set => {
key_values => [ { name => 'pfCounterFragment', diff => 1 } ],
per_second => 1,
output_template => 'Fragmented Packets : %.2f/s',
perfdatas => [
{ label => 'fragment', value => 'pfCounterFragment_per_second', template => '%.2f', unit => '/s',
min => 0 },
],
}
},
{ label => 'short', set => {
key_values => [ { name => 'pfCounterShort', diff => 1 } ],
per_second => 1,
output_template => 'Short Packets : %.2f/s',
perfdatas => [
{ label => 'short', value => 'pfCounterShort_per_second', template => '%.2f', unit => '/s',
min => 0 },
],
}
},
{ label => 'normalize', set => {
key_values => [ { name => 'pfCounterNormalize', diff => 1 } ],
per_second => 1,
output_template => 'Normalized Packets : %.2f/s',
perfdatas => [
{ label => 'normalize', value => 'pfCounterNormalize_per_second', template => '%.2f', unit => '/s',
min => 0 },
],
}
},
{ label => 'memdrop', set => {
key_values => [ { name => 'pfCounterMemDrop', diff => 1 } ],
per_second => 1,
output_template => 'Dropped Packets Due To Memory : %.2f/s',
perfdatas => [
{ label => 'memdrop', value => 'pfCounterMemDrop_per_second', template => '%.2f', unit => '/s',
min => 0 },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
if ($options{snmp}->is_snmpv1()) {
$self->{output}->add_option_msg(short_msg => "Can't check SNMP 64 bits counters with SNMPv1.");
$self->{output}->option_exit();
}
my %oids = (
pfCounterMatch => '.1.3.6.1.4.1.12325.1.200.1.2.1.0',
pfCounterBadOffset => '.1.3.6.1.4.1.12325.1.200.1.2.2.0',
pfCounterFragment => '.1.3.6.1.4.1.12325.1.200.1.2.3.0',
pfCounterShort => '.1.3.6.1.4.1.12325.1.200.1.2.4.0',
pfCounterNormalize => '.1.3.6.1.4.1.12325.1.200.1.2.5.0',
pfCounterMemDrop => '.1.3.6.1.4.1.12325.1.200.1.2.6.0',
);
my $snmp_result = $options{snmp}->get_leef(oids => [values %oids], nothing_quit => 1);
$self->{global} = {};
foreach (keys %oids) {
$self->{global}->{$_} = $snmp_result->{$oids{$_}};
}
$self->{cache_name} = "pfsense_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check global packet statistics.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^match$'
=item B<--warning-*>
Threshold warning.
Can be: 'match', 'badoffset', 'fragment', 'short',
'normalize', 'memdrop'.
=item B<--critical-*>
Threshold critical.
Can be: 'match', 'badoffset', 'fragment', 'short',
'normalize', 'memdrop'.
=back
=cut

View File

@ -0,0 +1,181 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::pfsense::snmp::mode::pfinterfaces;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'pfint', type => 1, cb_prefix_output => 'prefix_pfint_output', message_multiple => 'All pfInterfaes are ok' }
];
$self->{maps_counters}->{pfint} = [
{ label => 'traffic-in-pass', set => {
key_values => [ { name => 'pfInterfacesIf4BytesInPass', diff => 1 }, { name => 'display' } ],
per_second => 1, output_change_bytes => 2,
output_template => 'Traffic In Pass : %s %s/s',
perfdatas => [
{ label => 'traffic_in_pass', value => 'pfInterfacesIf4BytesInPass_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'traffic-out-pass', set => {
key_values => [ { name => 'pfInterfacesIf4BytesOutPass', diff => 1 }, { name => 'display' } ],
per_second => 1, output_change_bytes => 2,
output_template => 'Traffic Out Pass : %s %s/s',
perfdatas => [
{ label => 'traffic_out_pass', value => 'pfInterfacesIf4BytesOutPass_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'traffic-in-block', set => {
key_values => [ { name => 'pfInterfacesIf4BytesInBlock', diff => 1 }, { name => 'display' } ],
per_second => 1, output_change_bytes => 2,
output_template => 'Traffic In Block : %s %s/s',
perfdatas => [
{ label => 'traffic_in_block', value => 'pfInterfacesIf4BytesInBlock_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'traffic-out-block', set => {
key_values => [ { name => 'pfInterfacesIf4BytesOutBlock', diff => 1 }, { name => 'display' } ],
per_second => 1, output_change_bytes => 2,
output_template => 'Traffic Out Block : %s %s/s',
perfdatas => [
{ label => 'traffic_out_block', value => 'pfInterfacesIf4BytesOutBlock_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub prefix_pfint_output {
my ($self, %options) = @_;
return "pfInterface '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
});
return $self;
}
my $oid_pfInterfacesIfDescr = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.2';
my $mapping = {
pfInterfacesIf4BytesInPass => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.7' },
pfInterfacesIf4BytesInBlock => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.8' },
pfInterfacesIf4BytesOutPass => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.9' },
pfInterfacesIf4BytesOutBlock => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.10' },
};
sub manage_selection {
my ($self, %options) = @_;
if ($options{snmp}->is_snmpv1()) {
$self->{output}->add_option_msg(short_msg => "Can't check SNMP 64 bits counters with SNMPv1.");
$self->{output}->option_exit();
}
my $snmp_result = $options{snmp}->get_table(oid => $oid_pfInterfacesIfDescr, nothing_quit => 1);
$self->{pfint} = {};
foreach my $oid (keys %{$snmp_result}) {
$oid =~ /^$oid_pfInterfacesIfDescr\.(.*)$/;
my $instance = $1;
my $name = $snmp_result->{$oid};
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$name !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping pfInterface '" . $name . "'.", debug => 1);
next;
}
$self->{pfint}->{$instance} = { display => $name };
}
$options{snmp}->load(oids => [$mapping->{pfInterfacesIf4BytesInPass}->{oid}, $mapping->{pfInterfacesIf4BytesOutPass}->{oid},
$mapping->{pfInterfacesIf4BytesInBlock}->{oid}, $mapping->{pfInterfacesIf4BytesOutBlock}->{oid},
],
instances => [keys %{$self->{pfint}}], instance_regexp => '^(.*)$');
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
foreach my $instance (keys %{$self->{pfint}}) {
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
foreach (keys %$mapping) {
$self->{pfint}->{$instance}->{$_} = $result->{$_} * 8;
}
}
if (scalar(keys %{$self->{pfint}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No pfInterface found.");
$self->{output}->option_exit();
}
$self->{cache_name} = "pfsense_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check pfInterfaces.
=over 8
=item B<--warning-*>
Threshold warning.
Can be: 'traffic-in-pass', 'traffic-out-pass', 'traffic-in-block', 'traffic-out-block'.
=item B<--critical-*>
Threshold critical.
Can be: 'traffic-in-pass', 'traffic-out-pass', 'traffic-in-block', 'traffic-out-block'.
=item B<--filter-name>
Filter by interface name (can be a regexp).
=back
=cut

View File

@ -24,6 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::misc;
use POSIX;
sub new {
@ -36,7 +37,6 @@ sub new {
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
"seconds" => { name => 'seconds', },
});
return $self;
@ -78,7 +78,7 @@ sub run {
min => 0);
$self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("PfSense running since : %s",
defined($self->{option_results}->{seconds}) ? floor($valueRuntime / 100) . " seconds" : floor($valueRuntime / 86400 / 100) . " days" ));
centreon::plugins::misc::change_seconds(value => floor($valueRuntime / 100))));
} else {
$self->{output}->perfdata_add(label => 'runtime', unit => 's',
@ -87,7 +87,7 @@ sub run {
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);
$self->{output}->output_add(severity => 'critical',
short_msg => sprintf("PfSense not running."));
short_msg => 'PfSense not running');
}
$self->{output}->display();
@ -112,10 +112,6 @@ Threshold warning in seconds.
Threshold critical in seconds.
=item B<--seconds>
Display runtime in seconds.
=back
=cut

View File

@ -31,9 +31,10 @@ sub new {
$self->{version} = '0.1';
%{$self->{modes}} = (
'runtime' => 'apps::pfsense::snmp::mode::runtime',
'memory-dropped-packets' => 'apps::pfsense::snmp::mode::memorydroppedpackets',
'blocked-packets' => 'apps::pfsense::snmp::mode::blockedpackets',
'list-pfinterfaces' => 'apps::pfsense::snmp::mode::listpfinterfaces',
'packet-stats' => 'apps::pfsense::snmp::mode::packetstats',
'pfinterfaces' => 'apps::pfsense::snmp::mode::pfinterfaces',
'runtime' => 'apps::pfsense::snmp::mode::runtime',
);
return $self;

View File

@ -20,122 +20,105 @@
package apps::php::apc::web::mode::filecache;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::http;
use centreon::plugins::statefile;
use centreon::plugins::values;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
'request-rate' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'rr' },
],
output_template => 'Request Rate (global): %.2f',
perfdatas => [
{ value => 'rr_absolute', label => 'request_rate',template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
'request-rate-now' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'hits', diff => 1 }, { name => 'misses', diff => 1 },
],
closure_custom_calc => \&custom_rr_calc, per_second => 1,
output_template => 'Request Rate : %.2f', output_error_template => 'Request Rate : %s',
output_use => 'rr_now', threshold_use => 'rr_now',
perfdatas => [
{ value => 'rr_now', label => 'request_rate_now', template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
'hit-rate' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'hr' },
],
output_template => 'Hit Rate (global): %.2f',
perfdatas => [
{ value => 'hr_absolute', label => 'hit_rate',template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
'hit-rate-now' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'hits', diff => 1 },
],
closure_custom_calc => \&custom_hr_calc, per_second => 1,
output_template => 'Hit Rate : %.2f', output_error_template => 'Hit Rate : %s',
output_use => 'hr_now', threshold_use => 'hr_now',
perfdatas => [
{ value => 'hr_now', label => 'hit_rate_now', template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
'miss-rate' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'mr' },
],
output_template => 'Miss Rate (global): %.2f',
perfdatas => [
{ value => 'mr_absolute', label => 'miss_rate',template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
'miss-rate-now' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'misses', diff => 1 },
],
closure_custom_calc => \&custom_mr_calc, per_second => 1,
output_template => 'Miss Rate : %.2f', output_error_template => 'Miss Rate : %s',
output_use => 'mr_now', threshold_use => 'mr_now',
perfdatas => [
{ value => 'mr_now', label => 'miss_rate_now', template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
'hit-percent' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'hits' }, { name => 'misses' },
],
closure_custom_calc => \&custom_hit_percent_calc,
output_template => 'Hit Ratio (global) : %.2f %%', output_error_template => 'Hit Ratio (global): %s',
output_use => 'hit_ratio', threshold_use => 'hit_ratio',
perfdatas => [
{ value => 'hit_ratio', label => 'hit_ratio', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
'hit-percent-now' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'hits', diff => 1 }, { name => 'misses', diff => 1 },
],
closure_custom_calc => \&custom_hit_percent_now_calc,
output_template => 'Hit Ratio : %.2f %%', output_error_template => 'Hit Ratio : %s',
output_use => 'hit_ratio_now', threshold_use => 'hit_ratio_now',
perfdatas => [
{ value => 'hit_ratio_now', label => 'hit_ratio_now', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
};
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'fcache', type => 0, cb_prefix_output => 'prefix_output' }
];
$self->{maps_counters}->{fcache} = [
{ label => 'request-rate', set => {
key_values => [ { name => 'rr' } ],
output_template => 'Request Rate (global): %.2f',
perfdatas => [
{ value => 'rr_absolute', label => 'request_rate',template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
{ label => 'request-rate-now', set => {
key_values => [ { name => 'hits', diff => 1 }, { name => 'misses', diff => 1 } ],
closure_custom_calc => $self->can('custom_rr_calc'), per_second => 1,
output_template => 'Request Rate : %.2f', output_error_template => 'Request Rate : %s',
output_use => 'rr_now', threshold_use => 'rr_now',
perfdatas => [
{ value => 'rr_now', label => 'request_rate_now', template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
{ label => 'hit-rate', set => {
key_values => [ { name => 'hr' } ],
output_template => 'Hit Rate (global): %.2f',
perfdatas => [
{ value => 'hr_absolute', label => 'hit_rate',template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
{ label => 'hit-rate-now', set => {
key_values => [ { name => 'hits', diff => 1 } ],
closure_custom_calc => $self->can('custom_hr_calc'), per_second => 1,
output_template => 'Hit Rate : %.2f', output_error_template => 'Hit Rate : %s',
output_use => 'hr_now', threshold_use => 'hr_now',
perfdatas => [
{ value => 'hr_now', label => 'hit_rate_now', template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
{ label => 'miss-rate', set => {
key_values => [ { name => 'mr' } ],
output_template => 'Miss Rate (global): %.2f',
perfdatas => [
{ value => 'mr_absolute', label => 'miss_rate',template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
{ label => 'miss-rate-now', set => {
key_values => [ { name => 'misses', diff => 1 } ],
closure_custom_calc => $self->can('custom_mr_calc'), per_second => 1,
output_template => 'Miss Rate : %.2f', output_error_template => 'Miss Rate : %s',
output_use => 'mr_now', threshold_use => 'mr_now',
perfdatas => [
{ value => 'mr_now', label => 'miss_rate_now', template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
{ label => 'hit-percent', set => {
key_values => [ { name => 'hits' }, { name => 'misses' } ],
closure_custom_calc => $self->can('custom_hit_percent_calc'),
output_template => 'Hit Ratio (global) : %.2f %%', output_error_template => 'Hit Ratio (global): %s',
output_use => 'hit_ratio', threshold_use => 'hit_ratio',
perfdatas => [
{ value => 'hit_ratio', label => 'hit_ratio', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
{ label => 'hit-percent-now', set => {
key_values => [ { name => 'hits', diff => 1 }, { name => 'misses', diff => 1 } ],
closure_custom_calc => $self->can('custom_hit_percent_now_calc'),
output_template => 'Hit Ratio : %.2f %%', output_error_template => 'Hit Ratio : %s',
output_use => 'hit_ratio_now', threshold_use => 'hit_ratio_now',
perfdatas => [
{ value => 'hit_ratio_now', label => 'hit_ratio_now', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
];
}
sub custom_rr_calc {
my ($self, %options) = @_;
@ -205,9 +188,15 @@ sub custom_hit_percent_calc {
return 0;
}
sub prefix_output {
my ($self, %options) = @_;
return "Apc File Cache Information ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
@ -225,97 +214,32 @@ sub new {
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
foreach (keys %{$maps_counters}) {
$options{options}->add_options(arguments => {
'warning-' . $_ . ':s' => { name => 'warning-' . $_ },
'critical-' . $_ . ':s' => { name => 'critical-' . $_ },
});
my $class = $maps_counters->{$_}->{class};
$maps_counters->{$_}->{obj} = $class->new(statefile => $self->{statefile_value},
output => $self->{output}, perfdata => $self->{perfdata},
label => $_);
$maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}});
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
}
$self->SUPER::check_options(%options);
$self->{http}->set_options(%{$self->{option_results}});
$self->{statefile_value}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
$self->{webcontent} = $self->{http}->request();
$self->manage_selection();
$self->{new_datas} = {};
$self->{statefile_value}->read(statefile => "apc_" . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' . $self->{mode});
$self->{new_datas}->{last_timestamp} = time();
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->set(instance => 'fcache');
my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{fcache},
new_datas => $self->{new_datas});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $maps_counters->{$_}->{obj}->threshold_check();
push @exits, $exit2;
my $output = $maps_counters->{$_}->{obj}->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$maps_counters->{$_}->{obj}->perfdata();
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "Apc File Cache Information $short_msg"
);
} else {
$self->{output}->output_add(short_msg => "Apc File Cache Information $long_msg");
}
$self->{statefile_value}->write(data => $self->{new_datas});
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = $self->{http}->request();
$self->{fcache} = {};
$self->{fcache}->{hits} = $self->{webcontent} =~ /File Cache Information.*?Hits.*?(\d+)/msi ? $1 : undef;
$self->{fcache}->{misses} = $self->{webcontent} =~ /File Cache Information.*?Misses.*?(\d+)/msi ? $1 : undef;
$self->{fcache}->{rr} = $self->{webcontent} =~ /File Cache Information.*?Request Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{fcache}->{hr} = $self->{webcontent} =~ /File Cache Information.*?Hit Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{fcache}->{mr} = $self->{webcontent} =~ /File Cache Information.*?Miss Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{fcache}->{ir} = $self->{webcontent} =~ /File Cache Information.*?Insert Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{fcache}->{hits} = $webcontent =~ /File Cache Information.*?Hits.*?(\d+)/msi ? $1 : undef;
$self->{fcache}->{misses} = $webcontent =~ /File Cache Information.*?Misses.*?(\d+)/msi ? $1 : undef;
$self->{fcache}->{rr} = $webcontent =~ /File Cache Information.*?Request Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{fcache}->{hr} = $webcontent =~ /File Cache Information.*?Hit Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{fcache}->{mr} = $webcontent =~ /File Cache Information.*?Miss Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{fcache}->{ir} = $webcontent =~ /File Cache Information.*?Insert Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{cache_name} = "apc_" . $self->{mode} . '_' . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
@ -368,7 +292,7 @@ Threshold for HTTP timeout (Default: 30)
Threshold warning.
Can be: 'request-rate', 'request-rate-now',
'hit-rate', 'hit-rate-now', 'miss-rate', 'miss-rate-now', 'insert-rate',
'hit-rate', 'hit-rate-now', 'miss-rate', 'miss-rate-now',
'hit-percent', 'hit-percent-now'.
'*-now' are rate between two calls.
@ -376,7 +300,7 @@ Can be: 'request-rate', 'request-rate-now',
Threshold critical.
Can be: 'request-rate', 'request-rate-now',
'hit-rate', 'hit-rate-now', 'miss-rate', 'miss-rate-now', 'insert-rate',
'hit-rate', 'hit-rate-now', 'miss-rate', 'miss-rate-now',
'hit-percent', 'hit-percent-now'.
'*-now' are rate between two calls.

View File

@ -20,43 +20,45 @@
package apps::php::apc::web::mode::memory;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::http;
use centreon::plugins::values;
use centreon::plugins::misc;
my $maps_counters = {
'used' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'free' }, { name => 'used' },
],
closure_custom_calc => \&custom_used_calc,
closure_custom_output => \&custom_used_output,
threshold_use => 'used_prct',
output_error_template => 'Memory Usage: %s',
perfdatas => [
{ value => 'used', label => 'used', template => '%d',
unit => 'B', min => 0, max => 'total', threshold_total => 'total' },
],
}
},
'fragmentation' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'fragmentation' },
],
output_template => 'Memory Fragmentation: %.2f %%', output_error_template => 'Memory Fragmentation: %s',
output_use => 'fragmentation_absolute', threshold_use => 'fragmentation_absolute',
perfdatas => [
{ value => 'fragmentation_absolute', label => 'fragmentation', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
};
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'mem', type => 0, cb_prefix_output => 'prefix_output' }
];
$self->{maps_counters}->{mem} = [
{ label => 'used', set => {
key_values => [ { name => 'free' }, { name => 'free' } ],
closure_custom_calc => $self->can('custom_used_calc'),
closure_custom_output => $self->can('custom_used_output'),
threshold_use => 'used_prct',
output_error_template => 'Memory Usage: %s',
perfdatas => [
{ value => 'used', label => 'used', template => '%d',
unit => 'B', min => 0, max => 'total', threshold_total => 'total' },
],
}
},
{ label => 'fragmentation', set => {
key_values => [ { name => 'fragmentation' } ],
output_template => 'Memory Fragmentation: %.2f %%', output_error_template => 'Memory Fragmentation: %s',
output_use => 'fragmentation_absolute', threshold_use => 'fragmentation_absolute',
perfdatas => [
{ value => 'fragmentation_absolute', label => 'fragmentation', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
];
}
sub custom_used_calc {
my ($self, %options) = @_;
@ -82,6 +84,12 @@ sub custom_used_output {
$free_value . " " . $free_unit, $self->{result_values}->{free_prct});
}
sub prefix_output {
my ($self, %options) = @_;
return "Apc ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -103,106 +111,32 @@ sub new {
$self->{http} = centreon::plugins::http->new(output => $self->{output});
foreach (keys %{$maps_counters}) {
$options{options}->add_options(arguments => {
'warning-' . $_ . ':s' => { name => 'warning-' . $_ },
'critical-' . $_ . ':s' => { name => 'critical-' . $_ },
});
my $class = $maps_counters->{$_}->{class};
$maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $_);
$maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}});
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
}
$self->SUPER::check_options(%options);
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
$self->{webcontent} = $self->{http}->request();
$self->manage_selection();
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->set(instance => 'mem');
my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{mem});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $maps_counters->{$_}->{obj}->threshold_check();
push @exits, $exit2;
my $output = $maps_counters->{$_}->{obj}->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$maps_counters->{$_}->{obj}->perfdata();
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "Apc $short_msg"
);
} else {
$self->{output}->output_add(short_msg => "Apc $long_msg");
}
$self->{output}->display();
$self->{output}->exit();
}
sub in_bytes {
my ($self, %options) = @_;
my $value = $options{value};
if ($options{unit} =~ /^G/) {
$value *= 1024 * 1024 * 1024;
} elsif ($options{unit} =~ /^M/) {
$value *= 1024 * 1024;
} elsif ($options{unit} =~ /^K/) {
$value *= 1024;
}
return $value;
}
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = $self->{http}->request();
my ($free, $used);
if ($self->{webcontent} =~ /Memory Usage.*?Free:.*?([0-9\.]+)\s*(\S*)/msi) {
$free = $self->in_bytes(value => $1, unit => $2);
if ($webcontent =~ /Memory Usage.*?Free:.*?([0-9\.]+)\s*(\S*)/msi) {
$free = centreon::plugins::misc::convert_bytes(value => $1, unit => $2);
}
if ($self->{webcontent} =~ /Memory Usage.*?Used:.*?([0-9\.]+)\s*(\S*)/msi) {
$used = $self->in_bytes(value => $1, unit => $2);
if ($webcontent =~ /Memory Usage.*?Used:.*?([0-9\.]+)\s*(\S*)/msi) {
$used = centreon::plugins::misc::convert_bytes(value => $1, unit => $2);
}
$self->{mem} = {};
$self->{mem}->{free} = $free;
$self->{mem}->{used} = $used;
$self->{mem}->{fragmentation} = $self->{webcontent} =~ /Fragmentation:.*?([0-9\.]+)/msi ? $1 : undef;
$self->{mem}->{fragmentation} = $webcontent =~ /Fragmentation:.*?([0-9\.]+)/msi ? $1 : undef;
}
1;

View File

@ -20,33 +20,38 @@
package apps::php::fpm::web::mode::usage;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::http;
use centreon::plugins::values;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
fpm => {
'000_active-processes' => { set => {
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'fpm', type => 0, cb_prefix_output => 'prefix_output' }
];
$self->{maps_counters}->{fpm} = [
{ label => 'active-processes', set => {
key_values => [ { name => 'active' }, { name => 'total' } ],
closure_custom_calc => \&custom_active_calc,
closure_custom_output => \&custom_active_output,
closure_custom_calc => $self->can('custom_active_calc'),
closure_custom_output => $self->can('custom_active_output'),
threshold_use => 'active_prct',
closure_custom_perfdata => => \&custom_active_perfdata,
closure_custom_perfdata => => $self->can('custom_active_perfdata'),
}
},
'001_idle-processes' => { set => {
{ label => 'idle-processes', set => {
key_values => [ { name => 'idle' }, { name => 'total' } ],
closure_custom_calc => \&custom_idle_calc,
closure_custom_output => \&custom_idle_output,
closure_custom_calc => $self->can('custom_idle_calc'),
closure_custom_output => $self->can('custom_idle_output'),
threshold_use => 'idle_prct',
closure_custom_perfdata => => \&custom_idle_perfdata,
closure_custom_perfdata => => $self->can('custom_idle_perfdata'),
}
},
'002_listen-queue' => { set => {
},
{ label => 'listen-queue', set => {
key_values => [ { name => 'listen_queue' }, { name => 'max_listen_queue' } ],
output_template => 'Listen queue : %s',
output_use => 'listen_queue_absolute', threshold_use => 'listen_queue_absolute',
@ -56,7 +61,7 @@ my $maps_counters = {
],
}
},
'003_requests' => { set => {
{ label => 'requests', set => {
key_values => [ { name => 'request', diff => 1 } ],
per_second => 1,
output_template => 'Requests : %.2f/s',
@ -66,8 +71,8 @@ my $maps_counters = {
],
}
},
},
};
];
}
sub custom_active_calc {
my ($self, %options) = @_;
@ -123,9 +128,15 @@ sub custom_idle_perfdata {
min => 0, max => $self->{result_values}->{total});
}
sub prefix_output {
my ($self, %options) = @_;
return "php-fpm ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
@ -141,108 +152,34 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout', default => 5 },
});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
$self->{http} = centreon::plugins::http->new(output => $self->{output});
foreach my $key (('fpm')) {
foreach (keys %{$maps_counters->{$key}}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value},
output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
}
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->SUPER::check_options(%options);
foreach my $key (('fpm')) {
foreach (keys %{$maps_counters->{$key}}) {
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
$self->{statefile_value}->check_options(%options);
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
$self->{webcontent} = $self->{http}->request();
$self->manage_selection();
$self->{new_datas} = {};
$self->{statefile_value}->read(statefile => "php_fpm_" . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' . $self->{mode});
$self->{new_datas}->{last_timestamp} = time();
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters->{fpm}}) {
my $obj = $maps_counters->{fpm}->{$_}->{obj};
$obj->set(instance => 'fpm');
my ($value_check) = $obj->execute(values => $self->{fpm},
new_datas => $self->{new_datas});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$obj->perfdata();
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "php-fpm $short_msg"
);
} else {
$self->{output}->output_add(short_msg => "php-fpm $long_msg");
}
$self->{statefile_value}->write(data => $self->{new_datas});
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = $self->{http}->request();
$self->{fpm} = { request => undef, listen_queue => undef, max_listen_queue => undef,
idle => undef, active => undef, total => undef };
$self->{fpm}->{request} = $1 if ($self->{webcontent} =~ /accepted\s+conn:\s+(\d+)/msi);
$self->{fpm}->{listen_queue} = $1 if ($self->{webcontent} =~ /listen\s+queue:\s+(\d+)/msi);
$self->{fpm}->{max_listen_queue} = $1 if ($self->{webcontent} =~ /max\s+listen\s+queue:\s+(\d+)/msi);
$self->{fpm}->{idle} = $1 if ($self->{webcontent} =~ /idle\s+processes:\s+(\d+)/msi);
$self->{fpm}->{active} = $1 if ($self->{webcontent} =~ /active\s+processes:\s+(\d+)/msi);
$self->{fpm}->{total} = $1 if ($self->{webcontent} =~ /total\s+processes:\s+(\d+)/msi);
$self->{fpm}->{request} = $1 if ($webcontent =~ /accepted\s+conn:\s+(\d+)/msi);
$self->{fpm}->{listen_queue} = $1 if ($webcontent =~ /listen\s+queue:\s+(\d+)/msi);
$self->{fpm}->{max_listen_queue} = $1 if ($webcontent =~ /max\s+listen\s+queue:\s+(\d+)/msi);
$self->{fpm}->{idle} = $1 if ($webcontent =~ /idle\s+processes:\s+(\d+)/msi);
$self->{fpm}->{active} = $1 if ($webcontent =~ /active\s+processes:\s+(\d+)/msi);
$self->{fpm}->{total} = $1 if ($webcontent =~ /total\s+processes:\s+(\d+)/msi);
$self->{cache_name} = "php_fpm_" . $self->{mode} . '_' . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;

View File

@ -20,13 +20,85 @@
package apps::protocols::radius::mode::login;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Time::HiRes qw(gettimeofday tv_interval);
use Authen::Radius;
my $instance_mode;
my $radius_result_attributes = {};
sub custom_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'Radius Access Request Status: ' . $self->{result_values}->{status} .
' [error msg: ' . $self->{result_values}->{error_msg} . ']';
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{error_msg} = $options{new_datas}->{$self->{instance} . '_error_msg'};
$self->{result_values}->{attributes} = $radius_result_attributes;
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'radius', type => 0, message_separator => ' - ' },
];
$self->{maps_counters}->{radius} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'error_msg' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
{ label => 'time', set => {
key_values => [ { name => 'elapsed' } ],
output_template => 'Response time : %.3f second(s)',
perfdatas => [
{ label => 'time', value => 'elapsed_absolute', template => '%.3f',
min => 0, unit => 's' },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -36,81 +108,141 @@ sub new {
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port', default => 1812 },
"secret:s" => { name => 'secret' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"timeout:s" => { name => 'timeout', default => '30' },
"timeout:s" => { name => 'timeout', default => 5 },
"retry:s" => { name => 'retry', default => 0 },
'radius-attribute:s%' => { name => 'radius_attribute' },
'radius-dictionary:s' => { name => 'radius_dictionary' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} ne "accepted"' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->SUPER::check_options(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
my @mandatory = ('hostname', 'secret');
push @mandatory, 'username', 'password' if (!defined($self->{option_results}->{radius_attribute}));
foreach (@mandatory) {
if (!defined($self->{option_results}->{$_})) {
$self->{output}->add_option_msg(short_msg => "Please set the " . $_ . " option");
$self->{output}->option_exit();
}
}
if (defined($self->{option_results}->{radius_attribute}) &&
(!defined($self->{option_results}->{radius_dictionary}) || $self->{option_results}->{radius_dictionary} eq '')) {
$self->{output}->add_option_msg(short_msg => "Please set radius-dictionary option");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
$self->{option_results}->{retry} = 0 if (!defined($self->{option_results}->{retry}) || $self->{option_results}->{retry} !~ /^\d+$/);
if (defined($self->{option_results}->{port}) && $self->{option_results}->{port} =~ /^\d+$/) {
$self->{option_results}->{hostname} .= ':' . $self->{option_results}->{port};
}
$instance_mode = $self;
$self->change_macros();
}
if (!defined($self->{option_results}->{hostname})) {
$self->{output}->add_option_msg(short_msg => "Please set the hostname option");
$self->{output}->option_exit();
}
sub change_macros {
my ($self, %options) = @_;
if (!defined($self->{option_results}->{secret})) {
$self->{output}->add_option_msg(short_msg => "Please set the secret option");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{username})) {
$self->{output}->add_option_msg(short_msg => "Please set the username option");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{password})) {
$self->{output}->add_option_msg(short_msg => "Please set the password option");
$self->{output}->option_exit();
foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
}
}
}
sub run {
sub radius_simple_connection {
my ($self, %options) = @_;
my $timing0 = [gettimeofday];
my $radius = Authen::Radius->new(Host => $self->{option_results}->{hostname},
Secret => $self->{option_results}->{secret},
TimeOut => $self->{option_results}->{timeout},
);
$self->{timing0} = [gettimeofday];
my $retry = 0;
while ($retry <= $self->{option_results}->{retry}) {
if ($self->{radius_session}->check_pwd($self->{option_results}->{username}, $self->{option_results}->{password})) {
$self->{radius}->{status} = 'accepted';
last;
}
my $authentication = $radius->check_pwd($self->{option_results}->{username}, $self->{option_results}->{password});
if ($authentication != 1) {
$self->{output}->output_add(severity => 'CRITICAL',
short_msg => 'Authentication failed');
if ($retry + 1 > $self->{option_results}->{retry}) {
$self->{radius}->{status} = 'rejected';
$self->{radius}->{error_msg} = $self->{radius_session}->strerror();
}
$retry++;
}
}
my $timeelapsed = tv_interval ($timing0, [gettimeofday]);
sub radius_attr_connection {
my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed,
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Response time %.3f second(s)", $timeelapsed));
$self->{output}->perfdata_add(label => "time", unit => 's',
value => sprintf('%.3f', $timeelapsed),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
my $message;
eval {
local $SIG{__WARN__} = sub { $message = join(' - ', @_); };
local $SIG{__DIE__} = sub { $message = join(' - ', @_); };
$self->{output}->display();
$self->{output}->exit();
Authen::Radius->load_dictionary($self->{option_results}->{radius_dictionary});
foreach (keys %{$self->{option_results}->{radius_attribute}}) {
$self->{radius_session}->add_attributes({ Name => $_, Value => $self->{option_results}->{radius_attribute}->{$_} });
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => $message, debug => 1);
$self->{output}->add_option_msg(short_msg => "Issue with dictionary and attributes");
$self->{output}->option_exit();
}
$self->{timing0} = [gettimeofday];
my $retry = 0;
while ($retry <= $self->{option_results}->{retry}) {
my $type;
if ($self->{radius_session}->send_packet(ACCESS_REQUEST) && ($type = $self->{radius_session}->recv_packet()) == ACCESS_ACCEPT) {
$self->{radius}->{status} = 'accepted';
last;
}
if ($retry + 1 > $self->{option_results}->{retry}) {
$self->{radius}->{status} = 'unknown';
$self->{radius}->{error_msg} = $self->{radius_session}->strerror();
if (defined($type) && $type == ACCESS_REJECT) {
$self->{radius}->{status} = 'rejected';
}
}
$retry++;
}
}
sub manage_selection {
my ($self, %options) = @_;
$self->{radius} = { status => 'unknown', error_msg => 'none' };
$self->{radius_session} = Authen::Radius->new(
Host => $self->{option_results}->{hostname},
Secret => $self->{option_results}->{secret},
TimeOut => $self->{option_results}->{timeout},
);
if (defined($self->{option_results}->{radius_attribute})) {
$self->radius_attr_connection();
} else {
$self->radius_simple_connection();
}
$self->{radius}->{elapsed} = tv_interval($self->{timing0}, [gettimeofday]);
foreach my $attr ($self->{radius_session}->get_attributes()) {
$radius_result_attributes->{$attr->{Name}} = defined($attr->{Value}) ? $attr->{Value} : '';
$self->{output}->output_add(long_msg => 'Attribute Name = ' . $attr->{Name} .
', Value = ' . (defined($attr->{Value}) ? $attr->{Value} : ''), debug => 1);
}
}
1;
@ -119,7 +251,10 @@ __END__
=head1 MODE
Check Connection (also login) to a Radius Server.
Check login to a Radius Server.
Example with attributes:
centreon_plugins.pl --plugin=apps/protocols/radius/plugin.pm --mode=login --hostname=192.168.1.2 --secret=centreon --radius-attribute='User-Password=test' --radius-attribute='User-Name=user@test.com' --radius-dictionary=dictionary.txt
=over 8
@ -127,6 +262,10 @@ Check Connection (also login) to a Radius Server.
IP Addr/FQDN of the radius host
=item B<--port>
Radius port (Default: 1812)
=item B<--secret>
Secret of the radius host
@ -141,13 +280,37 @@ Specify password for authentication
=item B<--timeout>
Connection timeout in seconds (Default: 30)
Connection timeout in seconds (Default: 5)
=item B<--warning>
=item B<--timeout>
Number of retry connection (Default: 0)
=item B<--radius-attribute>
If you need to add option, please following attributes.
Option username and password should be set with that option.
Example: --radius-attribute="User-Password=test"
=item B<--radius-dictionary>
Set radius-dictionary file (mandatory with --radius-attribute).
=item B<--warning-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{status}, %{error_msg}, %{attributes}.
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} ne "accepted"').
Can used special variables like: %{status}, %{error_msg}, %{attributes}.
=item B<--warning-time>
Threshold warning in seconds
=item B<--critical>
=item B<--critical-time>
Threshold critical in seconds

View File

@ -0,0 +1,168 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::protocols::ssh::mode::login;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Time::HiRes qw(gettimeofday tv_interval);
my $instance_mode;
sub custom_status_threshold_output {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("%s", $self->{result_values}->{message});
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{message} = $options{new_datas}->{$self->{instance} . '_message'};
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, message_separator => ' - ' },
];
$self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'message' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold_output'),
}
},
{ label => 'time', set => {
key_values => [ { name => 'time_elapsed' } ],
output_template => 'Response time %.3fs',
perfdatas => [
{ label => 'time', value => 'time_elapsed_absolute', template => '%.3f', unit => 's', min => 0 },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{message} !~ /authentification succeeded/i' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
}
sub change_macros {
my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
}
}
}
sub manage_selection {
my ($self, %options) = @_;
my $timing0 = [gettimeofday];
my $result = $options{custom}->login();
my $timeelapsed = tv_interval($timing0, [gettimeofday]);
$self->{global} = { %$result, time_elapsed => $timeelapsed };
}
1;
__END__
=head1 MODE
Check SSH connection.
=over 8
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{status}, %{message}
=item B<--critical-status>
Set critical threshold for status (Default: '%{message} !~ /authentification succeeded/i'
Can used special variables like: %{status}, %{message}
=item B<--warning-time>
Threshold warning in seconds.
=item B<--critical-time>
Threshold critical in seconds.
=back
=cut

View File

@ -0,0 +1,52 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::protocols::ssh::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'login' => 'apps::protocols::ssh::mode::login',
);
$self->{custom_modes}{api} = 'centreon::common::protocols::ssh::custom::api';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check a SSH server.
Need Libssh perl:
https://github.com/garnier-quentin/perl-libssh
=cut

View File

@ -0,0 +1,255 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::tomcat::jmx::mode::connectorusage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
my $instance_mode;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'tomcatconnector', type => 1, cb_prefix_output => 'prefix_connector_output', message_multiple => 'All connectors are ok' },
];
$self->{maps_counters}->{tomcatconnector} = [
{ label => 'threads-count', set => {
key_values => [ { name => 'currentThreadCount' }, { name => 'maxThreads' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_calc_extra_options => { label_ref => 'currentThreadCount', message => 'Current Threads' },
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
}
},
{ label => 'threads-busy', set => {
key_values => [ { name => 'currentThreadsBusy' }, { name => 'maxThreads' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_calc_extra_options => { label_ref => 'currentThreadsBusy', message => 'Current Busy Threads' },
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
}
},
{ label => 'request-count', set => {
key_values => [ { name => 'requestCount', diff => 1 }, { name => 'display' } ],
output_template => 'Request Count : %s',
perfdatas => [
{ label => 'request_count', value => 'requestCount_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'traffic-in', set => {
key_values => [ { name => 'bytesReceived', diff => 1 }, { name => 'display' } ],
per_second => 1, output_change_bytes => 2,
output_template => 'Traffic In : %s %s/s',
perfdatas => [
{ label => 'traffic_in', value => 'bytesReceived_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'traffic-out', set => {
key_values => [ { name => 'bytesSent', diff => 1 }, { name => 'display' } ],
per_second => 1, output_change_bytes => 2,
output_template => 'Traffic Out : %s %s/s',
perfdatas => [
{ label => 'traffic_out', value => 'bytesSent_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub custom_usage_perfdata {
my ($self, %options) = @_;
my $use_th = 1;
$use_th = 0 if ($instance_mode->{option_results}->{units} eq '%' && $self->{result_values}->{max} <= 0);
my $extra_label = '';
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
my $value_perf = $self->{result_values}->{used};
my %total_options = ();
if ($instance_mode->{option_results}->{units} eq '%' && $self->{result_values}->{max} > 0) {
$total_options{total} = $self->{result_values}->{max};
$total_options{cast_int} = 1;
}
my $label = $self->{label};
$label =~ s/-/_/g;
$self->{output}->perfdata_add(label => $label . $extra_label,
value => $value_perf,
warning => $use_th == 1 ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef,
critical => $use_th == 1 ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options) : undef,
min => 0, max => $self->{result_values}->{max} > 0 ? $self->{result_values}->{max} : undef);
}
sub custom_usage_threshold {
my ($self, %options) = @_;
# Cannot use percent without total
return 'ok' if ($self->{result_values}->{max} <= 0 && $instance_mode->{option_results}->{units} eq '%');
my ($exit, $threshold_value);
$threshold_value = $self->{result_values}->{used};
if ($instance_mode->{option_results}->{units} eq '%') {
$threshold_value = $self->{result_values}->{prct_used};
}
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_usage_output {
my ($self, %options) = @_;
my $msg;
if ($self->{result_values}->{max} > 0) {
$msg = sprintf("%s Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$self->{result_values}->{message}, $self->{result_values}->{max},
$self->{result_values}->{used}, $self->{result_values}->{prct_used},
$self->{result_values}->{max} - $self->{result_values}->{used}, 100 - $self->{result_values}->{prct_used});
} else {
$msg = sprintf("%s : %s", $self->{result_values}->{message}, $self->{result_values}->{used});
}
return $msg;
}
sub custom_usage_calc {
my ($self, %options) = @_;
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{message} = $options{extra_options}->{message};
$self->{result_values}->{max} = $options{new_datas}->{$self->{instance} . '_maxThreads'};
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}};
if ($self->{result_values}->{max} > 0) {
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{max};
}
return 0;
}
sub prefix_connector_output {
my ($self, %options) = @_;
return "Connector '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"units:s" => { name => 'units', default => '%' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
}
sub manage_selection {
my ($self, %options) = @_;
# Tomcat: Catalina
# Jboss: jboss.web
$self->{request} = [
{ mbean => "*:name=*,type=ThreadPool", attributes => [ { name => 'currentThreadCount' }, { name => 'currentThreadsBusy' }, { name => 'maxThreads' } ] },
{ mbean => "*:name=*,type=GlobalRequestProcessor", attributes => [ { name => 'bytesReceived' }, { name => 'bytesSent' }, { name => 'requestCount' } ] }
];
my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
$self->{tomcatconnector} = {};
foreach my $key (keys %$result) {
$key =~ /name=(.*?),type=(.*)/;
my ($connector, $type) = ($1, $2);
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$connector !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $connector . "': no matching filter.", debug => 1);
next;
}
$result->{$key}->{bytesSent} *= 8 if (defined($result->{$key}->{bytesSent}));
$result->{$key}->{bytesReceived} *= 8 if (defined($result->{$key}->{bytesReceived}));
$self->{tomcatconnector}->{$connector} = { display => $connector }
if (!defined($self->{tomcatconnector}->{$connector}));
$self->{tomcatconnector}->{$connector} = { %{$self->{tomcatconnector}->{$connector}}, %{$result->{$key}} };
}
$self->{cache_name} = "tomcat_" . $self->{mode} . '_' . md5_hex($options{custom}->{url}) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check connector usage.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='threads-busy'
=item B<--filter-name>
Filter connector name (can be a regexp).
=item B<--warning-*>
Threshold warning.
Can be: 'threads-count', 'threads-busy', 'request-count', 'traffic-in', 'traffic-out'.
=item B<--critical-*>
Threshold critical.
Can be: 'threads-count', 'threads-busy', 'request-count', 'traffic-in', 'traffic-out'.
=item B<--units>
Units of thresholds (Default: '%') ('%', 'absolute').
=back
=cut

View File

@ -32,6 +32,7 @@ sub new {
$self->{version} = '0.1';
%{$self->{modes}} = (
'class-count' => 'centreon::common::jvm::mode::classcount',
'connector-usage' => 'apps::tomcat::jmx::mode::connectorusage',
'cpu-load' => 'centreon::common::jvm::mode::cpuload',
'fd-usage' => 'centreon::common::jvm::mode::fdusage',
'gc-usage' => 'centreon::common::jvm::mode::gcusage',

View File

@ -20,18 +20,121 @@
package apps::tomcat::web::mode::traffic;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::http;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
use XML::XPath;
use URI::Escape;
my $instance_mode;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'connector', type => 1, cb_prefix_output => 'prefix_connector_output', message_multiple => 'All connector traffics are ok' },
];
$self->{maps_counters}->{connector} = [
{ label => 'in', set => {
key_values => [ { name => 'in', diff => 1 }, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' },
closure_custom_output => $self->can('custom_traffic_output'),
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
},
{ label => 'out', set => {
key_values => [ { name => 'out', diff => 1 }, { name => 'display' } ],
per_second => 1,
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' },
closure_custom_output => $self->can('custom_traffic_output'),
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
}
},
];
}
sub custom_traffic_perfdata {
my ($self, %options) = @_;
my $extra_label = '';
if (!defined($options{extra_instance}) || $options{extra_instance} != 0) {
$extra_label .= '_' . $self->{result_values}->{display};
}
my ($warning, $critical);
if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1);
$critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1);
} elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') {
$warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label});
$critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label});
}
$self->{output}->perfdata_add(label => 'traffic_' . $self->{result_values}->{label} . $extra_label, unit => 'b/s',
value => sprintf("%.2f", $self->{result_values}->{traffic}),
warning => $warning,
critical => $critical,
min => 0, max => $self->{result_values}->{speed});
}
sub custom_traffic_threshold {
my ($self, %options) = @_;
my $exit = 'ok';
if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) {
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
} elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') {
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
}
return $exit;
}
sub custom_traffic_output {
my ($self, %options) = @_;
my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic}, network => 1);
my ($total_value, $total_unit);
if (defined($self->{result_values}->{speed}) && $self->{result_values}->{speed} =~ /[0-9]/) {
($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{speed}, network => 1);
}
my $msg = sprintf("Traffic %s : %s/s (%s on %s)",
ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit,
defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-',
defined($total_value) ? $total_value . $total_unit : '-');
return $msg;
}
sub custom_traffic_calc {
my ($self, %options) = @_;
$self->{result_values}->{label} = $options{extra_options}->{label_ref};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
my $diff_traffic = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{label}} - $options{old_datas}->{$self->{instance} . '_' . $self->{result_values}->{label}};
$self->{result_values}->{traffic} = $diff_traffic / $options{delta_time};
if (defined($instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}}) && $instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} =~ /[0-9]/) {
$self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic} * 100 / ($instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000);
$self->{result_values}->{speed} = $instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000;
}
return 0;
}
sub prefix_connector_output {
my ($self, %options) = @_;
return "Connector '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
@ -46,73 +149,37 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout' },
"urlpath:s" => { name => 'url_path', default => '/manager/status?XML=true' },
"name:s" => { name => 'name' },
"regexp" => { name => 'use_regexp' },
"regexp-isensitive" => { name => 'use_regexpi' },
"speed:s" => { name => 'speed' },
"warning-in:s" => { name => 'warning_in' },
"critical-in:s" => { name => 'critical_in' },
"warning-out:s" => { name => 'warning_out' },
"critical-out:s" => { name => 'critical_out' },
"filter-name:s" => { name => 'filter_name' },
"speed-in:s" => { name => 'speed_in' },
"speed-out:s" => { name => 'speed_out' },
"units-traffic:s" => { name => 'units_traffic', default => '%' },
});
$self->{result} = {};
$self->{hostname} = undef;
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
$self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning-in', value => $self->{option_results}->{warning_in})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning 'in' threshold '" . $self->{option_results}->{warning_in} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical-in', value => $self->{option_results}->{critical_in})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical 'in' threshold '" . $self->{option_results}->{critical_in} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'warning-out', value => $self->{option_results}->{warning_out})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning 'out' threshold '" . $self->{option_results}->{warning_out} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical-out', value => $self->{option_results}->{critical_out})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical 'out' threshold '" . $self->{option_results}->{critical_out} . "'.");
$self->{output}->option_exit();
}
if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '' && $self->{option_results}->{speed} !~ /^[0-9]+(\.[0-9]+){0,1}$/) {
$self->{output}->add_option_msg(short_msg => "Speed must be a positive number '" . $self->{option_results}->{speed} . "' (can be a float also).");
$self->{output}->option_exit();
}
if (defined($self->{option_results}->{units}) && $self->{option_results}->{units} eq '%' &&
(!defined($self->{option_results}->{speed}) || $self->{option_results}->{speed} eq '')) {
$self->{output}->add_option_msg(short_msg => "To use percent, you need to set --speed option.");
$self->{output}->option_exit();
}
$self->SUPER::check_options(%options);
$self->{statefile_value}->check_options(%options);
$self->{hostname} = $self->{option_results}->{hostname};
if (!defined($self->{hostname})) {
$self->{hostname} = 'me';
}
$self->{http}->set_options(%{$self->{option_results}});
$instance_mode = $self;
}
my %xpath_to_check = (
in => '/status/connector/requestInfo/@bytesReceived',
out => '/status/connector/requestInfo/@bytesSent',
in => '/status/connector/requestInfo/@bytesReceived',
out => '/status/connector/requestInfo/@bytesSent',
);
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = $self->{http}->request();
my $port = $self->{option_results}->{port};
#EXAMPLE 1:
#<status>
# <connector name="http-0">
@ -150,22 +217,29 @@ sub manage_selection {
# </workers>
#</connector>
#</status>
my $webcontent = $self->{http}->request();
#GET XML DATA
my $xpath = XML::XPath->new( xml => $webcontent );
my $xpath = XML::XPath->new(xml => $webcontent);
my %xpath_check_results;
foreach my $xpath_check ( keys %xpath_to_check ) {
my $singlepath = $xpath_to_check{$xpath_check};
$singlepath =~ s{\$port}{$port};
$self->{connector} = {};
foreach my $label (keys %xpath_to_check) {
my $singlepath = $xpath_to_check{$label};
my $nodeset = $xpath->find($singlepath);
foreach my $node ($nodeset->get_nodelist) {
foreach my $node ($nodeset->get_nodelist()) {
my $connector_name = $node->getParentNode()->getParentNode()->getAttribute("name");
$connector_name =~ s/^["'\s]+//;
$connector_name =~ s/["'\s]+$//;
$connector_name = uri_unescape($connector_name);
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$connector_name !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $connector_name . "': no matching filter.", debug => 1);
next;
}
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
&& $connector_name !~ /$self->{option_results}->{name}/i);
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
@ -173,126 +247,23 @@ sub manage_selection {
next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
&& $connector_name ne $self->{option_results}->{name});
$self->{connector}->{$connector_name} = { display => $connector_name } if (!defined($self->{connector}->{$connector_name}));
my $value = $node->string_value();
if ( $value =~ /^"?([0-9.]+)"?$/ ) {
$self->{result}->{$connector_name}{$xpath_check} = $1;
} else {
$self->{result}->{$connector_name}{$xpath_check} = "not_numeric";
};
};
if (scalar(keys %{$self->{result}}) <= 0) {
if (defined($self->{option_results}->{name})) {
$self->{output}->add_option_msg(short_msg => "No information found for name '" . $self->{option_results}->{name} . "'.");
} else {
$self->{output}->add_option_msg(short_msg => "No information found.");
}
$self->{output}->option_exit();
};
};
};
sub run {
my ($self, %options) = @_;
$self->manage_selection();
my $new_datas = {};
$self->{statefile_value}->read(statefile => 'cache_apps_tomcat_web_' . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
$new_datas->{last_timestamp} = time();
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All traffic are ok.');
}
foreach my $name (sort(keys %{$self->{result}})) {
$new_datas->{'in_' . $name} = $self->{result}->{$name}->{in} * 8;
$new_datas->{'out_' . $name} = $self->{result}->{$name}->{out} * 8;
my $old_in = $self->{statefile_value}->get(name => 'in_' . $name);
my $old_out = $self->{statefile_value}->get(name => 'out_' . $name);
if (!defined($old_timestamp) || !defined($old_in) || !defined($old_out)) {
next;
}
if ($new_datas->{'in_' . $name} < $old_in) {
# We set 0. Has reboot.
$old_in = 0;
}
if ($new_datas->{'out_' . $name} < $old_out) {
# We set 0. Has reboot.
$old_out = 0;
}
my $time_delta = $new_datas->{last_timestamp} - $old_timestamp;
if ($time_delta <= 0) {
# At least one second. two fast calls ;)
$time_delta = 1;
}
my $in_absolute_per_sec = ($new_datas->{'in_' . $name} - $old_in) / $time_delta;
my $out_absolute_per_sec = ($new_datas->{'out_' . $name} - $old_out) / $time_delta;
my ($exit, $interface_speed, $in_prct, $out_prct);
if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') {
$interface_speed = $self->{option_results}->{speed} * 1000000;
$in_prct = $in_absolute_per_sec * 100 / ($self->{option_results}->{speed} * 1000000);
$out_prct = $out_absolute_per_sec * 100 / ($self->{option_results}->{speed} * 1000000);
if ($self->{option_results}->{units} eq '%') {
my $exit1 = $self->{perfdata}->threshold_check(value => $in_prct, threshold => [ { label => 'critical-in', 'exit_litteral' => 'critical' }, { label => 'warning-in', exit_litteral => 'warning' } ]);
my $exit2 = $self->{perfdata}->threshold_check(value => $out_prct, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]);
$exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
if ($value =~ /^"?([0-9.]+)"?$/) {
$self->{connector}->{$connector_name}->{$label} = $1 * 8;
}
$in_prct = sprintf("%.2f", $in_prct);
$out_prct = sprintf("%.2f", $out_prct);
} else {
my $exit1 = $self->{perfdata}->threshold_check(value => $in_absolute_per_sec, threshold => [ { label => 'critical-in', 'exit_litteral' => 'critical' }, { label => 'warning-in', exit_litteral => 'warning' } ]);
my $exit2 = $self->{perfdata}->threshold_check(value => $out_absolute_per_sec, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]);
$exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
$in_prct = '-';
$out_prct = '-';
}
###########
# Manage Output
###########
my ($in_value, $in_unit) = $self->{perfdata}->change_bytes(value => $in_absolute_per_sec, network => 1);
my ($out_value, $out_unit) = $self->{perfdata}->change_bytes(value => $out_absolute_per_sec, network => 1);
$self->{output}->output_add(long_msg => sprintf("Connector '%s' Traffic In : %s/s (%s %%), Out : %s/s (%s %%) ", $name,
$in_value . $in_unit, $in_prct,
$out_value . $out_unit, $out_prct));
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Connector '%s' Traffic In : %s/s (%s %%), Out : %s/s (%s %%) ", $name,
$in_value . $in_unit, $in_prct,
$out_value . $out_unit, $out_prct));
}
my $extra_label = '';
$extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp}));
$self->{output}->perfdata_add(label => 'traffic_in' . $extra_label, unit => 'b/s',
value => sprintf("%.2f", $in_absolute_per_sec),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-in', total => $interface_speed),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-in', total => $interface_speed),
min => 0, max => $interface_speed);
$self->{output}->perfdata_add(label => 'traffic_out' . $extra_label, unit => 'b/s',
value => sprintf("%.2f", $out_absolute_per_sec),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-out', total => $interface_speed),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out', total => $interface_speed),
min => 0, max => $interface_speed);
}
$self->{statefile_value}->write(data => $new_datas);
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
if (scalar(keys %{$self->{connector}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No information found.");
$self->{output}->option_exit();
}
$self->{output}->display();
$self->{output}->exit();
};
$self->{cache_name} = "tomcat_web_" . $self->{mode} . '_' . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
}
1;
@ -340,37 +311,31 @@ Threshold for HTTP timeout
Path to the Tomcat Manager XML (Default: '/manager/status?XML=true')
=item B<--name>
=item B<--filter-name>
Set the filter name (empty means 'check all contexts')
Filter by context name (can be a regexp).
=item B<--regexp>
=item B<--warning-*>
Allows to use regexp to filter (with option --name).
Threshold warning.
Can be: 'in', 'out'.
=item B<--regexp-isensitive>
=item B<--critical-*>
Allows to use regexp non case-sensitive (with --regexp).
Threshold critical.
Can be: 'in', 'out'.
=item B<--warning-in>
=item B<--units-traffic>
Threshold warning in percent for 'in' traffic.
Units of thresholds for the traffic (Default: '%') ('%', 'b/s').
=item B<--critical-in>
=item B<--speed-in>
Threshold critical in percent for 'in' traffic.
Set interface speed for incoming traffic (in Mb).
=item B<--warning-out>
=item B<--speed-out>
Threshold warning in percent for 'out' traffic.
=item B<--critical-out>
Threshold critical in percent for 'out' traffic.
=item B<--speed>
Set Connector Interface speed (in Mb).
Set interface speed for outgoing traffic (in Mb).
=back

View File

@ -0,0 +1,214 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::toshiba::storemate::sql::mode::maintenanceplan;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
use centreon::plugins::statefile;
my $instance_mode;
sub custom_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf("alarm [workstation: %s] [text: %s] %s", $self->{result_values}->{workstation_id},
$self->{result_values}->{description}, $self->{result_values}->{generation_time});
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{description} = $options{new_datas}->{$self->{instance} . '_description'};
$self->{result_values}->{workstation_id} = $options{new_datas}->{$self->{instance} . '_workstation_id'};
$self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'};
$self->{result_values}->{generation_time} = $options{new_datas}->{$self->{instance} . '_generation_time'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'alarms', type => 2, message_multiple => '0 problem(s) detected', display_counter_problem => { label => 'alerts', min => 0 },
group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ]
}
];
$self->{maps_counters}->{alarm} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'description' }, { name => 'workstation_id' }, { name => 'since' }, { name => 'generation_time' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"database:s" => { name => 'database', default => 'Framework' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '1 == 1' },
"memory" => { name => 'memory' },
"timezone:s" => { name => 'timezone' },
});
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'DateTime',
error_msg => "Cannot load module 'DateTime'.");
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->check_options(%options);
}
$self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq '');
}
sub change_macros {
my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
}
}
}
sub manage_selection {
my ($self, %options) = @_;
$self->{sql} = $options{sql};
$self->{sql}->connect();
$self->{sql}->query(query => "SELECT CONVERT(varchar, LOGDATE, 120) as LOGDATE, WORKSTATION_ID, USER_ID, DESCRIPTION, DESCRIPTION_PARAMETERS
FROM " . $self->{option_results}->{database} . ".dbo.log
WHERE (TYPE <> 1) AND (DESCRIPTION_PARAMETERS LIKE N'\%FO\%') AND (TASKNAME = 'FOCleanup')");
$self->{alarms}->{global} = { alarm => {} };
my $last_time;
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->read(statefile => 'cache_toshiba_storemate_' . $self->{mode} . '_' . $self->{sql}->get_unique_id4save());
$last_time = $self->{statefile_cache}->get(name => 'last_time');
}
my ($i, $current_time) = (1, time());
while (my $row = $self->{sql}->fetchrow_hashref()) {
# date form: 2017-09-22 01:01:08.133
$row->{LOGDATE} =~ /^(\d+)-(\d+)-(\d+)\s+(\d+)[:\/](\d+)[:\/](\d+)/;
my $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6,
time_zone => $self->{option_results}->{timezone});
next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $dt->epoch);
my $diff_time = $current_time - $dt->epoch;
$self->{alarms}->{global}->{alarm}->{$i} = {
description => $row->{DESCRIPTION},
workstation_id => $row->{WORKSTATION_ID},
since => $diff_time, generation_time => centreon::plugins::misc::change_seconds(value => $diff_time)
};
$i++;
}
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->write(data => { last_time => $current_time });
}
}
1;
__END__
=head1 MODE
Check the maintenance plan error logs.
=over 8
=item B<--database>
Database name (default: 'Framework').
=item B<--warning-status>
Set warning threshold for status (Default: '')
Can used special variables like: %{description}, %{workstation_id}, %{since}
=item B<--critical-status>
Set critical threshold for status (Default: '1 == 1'. We match all errors).
Can used special variables like: %{description}, %{workstation_id}, %{since}
=item B<--timezone>
Timezone of time options. Default is 'GMT'.
=item B<--memory>
Only check new alarms.
=back
=cut

View File

@ -0,0 +1,295 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::toshiba::storemate::sql::mode::posstatus;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
{ name => 'state', type => 0, cb_prefix_output => 'prefix_state_output' },
{ name => 'merchandise', type => 0, cb_prefix_output => 'prefix_merchandise_output' },
{ name => 'transaction', type => 0, cb_prefix_output => 'prefix_transaction_output' },
];
$self->{maps_counters}->{global} = [
{ label => 'total', set => {
key_values => [ { name => 'total' } ],
output_template => 'total : %s',
perfdatas => [
{ label => 'total', value => 'total_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'online', set => {
key_values => [ { name => 'online' } ],
output_template => 'online : %s',
perfdatas => [
{ label => 'online', value => 'online_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'offline', set => {
key_values => [ { name => 'offline' } ],
output_template => 'offline : %s',
perfdatas => [
{ label => 'offline', value => 'offline_absolute', template => '%s',
min => 0 },
],
}
},
];
$self->{maps_counters}->{state} = [
{ label => 'state-unknown', set => {
key_values => [ { name => 'unknown' } ],
output_template => 'unknown : %s',
perfdatas => [
{ label => 'state_unknown', value => 'unknown_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'state-signoff', set => {
key_values => [ { name => 'signoff' } ],
output_template => 'signed off : %s',
perfdatas => [
{ label => 'state_signoff', value => 'signoff_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'state-signon', set => {
key_values => [ { name => 'signon' } ],
output_template => 'signed on : %s',
perfdatas => [
{ label => 'state_signon', value => 'signon_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'state-closed', set => {
key_values => [ { name => 'closed' } ],
output_template => 'closed : %s',
perfdatas => [
{ label => 'state_closed', value => 'closed_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'state-paused', set => {
key_values => [ { name => 'paused' } ],
output_template => 'paused : %s',
perfdatas => [
{ label => 'state_paused', value => 'paused_absolute', template => '%s',
min => 0 },
],
}
},
];
$self->{maps_counters}->{merchandise} = [
{ label => 'merchandise-rep-unknown', set => {
key_values => [ { name => 'unknown' } ],
output_template => 'unknown : %s',
perfdatas => [
{ label => 'merchandise_rep_unknown', value => 'unknown_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'merchandise-rep-ok', set => {
key_values => [ { name => 'ok' } ],
output_template => 'ok : %s',
perfdatas => [
{ label => 'merchandise_rep_ok', value => 'ok_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'merchandise-rep-suspended', set => {
key_values => [ { name => 'suspended' } ],
output_template => 'suspended : %s',
perfdatas => [
{ label => 'merchandise_rep_suspended', value => 'suspended_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'merchandise-rep-error', set => {
key_values => [ { name => 'error' } ],
output_template => 'error : %s',
perfdatas => [
{ label => 'merchandise_rep_error', value => 'error_absolute', template => '%s',
min => 0 },
],
}
},
];
$self->{maps_counters}->{transaction} = [
{ label => 'transaction-rep-unknown', set => {
key_values => [ { name => 'unknown' } ],
output_template => 'unknown : %s',
perfdatas => [
{ label => 'transaction_rep_unknown', value => 'unknown_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'transaction-rep-ok', set => {
key_values => [ { name => 'ok' } ],
output_template => 'ok : %s',
perfdatas => [
{ label => 'transaction_rep_ok', value => 'ok_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'transaction-rep-suspended', set => {
key_values => [ { name => 'suspended' } ],
output_template => 'suspended : %s',
perfdatas => [
{ label => 'transaction_rep_suspended', value => 'suspended_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'transaction-rep-error', set => {
key_values => [ { name => 'error' } ],
output_template => 'error : %s',
perfdatas => [
{ label => 'transaction_rep_error', value => 'error_absolute', template => '%s',
min => 0 },
],
}
},
];
}
sub prefix_global_output {
my ($self, %options) = @_;
return "Points of sale ";
}
sub prefix_state_output {
my ($self, %options) = @_;
return "State ";
}
sub prefix_merchandise_output {
my ($self, %options) = @_;
return "Merchandise replication ";
}
sub prefix_transaction_output {
my ($self, %options) = @_;
return "Transaction replication ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"database:s" => { name => 'database', default => 'Framework' },
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
$self->{sql} = $options{sql};
$self->{sql}->connect();
$self->{sql}->query(query => "SELECT WORKSTATION_ID, ONLINE, FO_STATE, MERCHANDISE_REPLICATION, TRANSACTION_REPLICATION
FROM " . $self->{option_results}->{database} . ".dbo.WORKSTATION_STATUS");
$self->{global} = { total => 0, online => 0, offline => 0 };
$self->{state} = { unknown => 0, signoff => 0, signon => 0, closed => 0, paused => 0 };
$self->{merchandise} = { unknown => 0, ok => 0, suspended => 0, error => 0 };
$self->{transaction} = { unknown => 0, ok => 0, suspended => 0, error => 0 };
my %map_status = (0 => 'offline', 1 => 'online');
my %map_state = (0 => 'unknown', 1 => 'signoff', 2 => 'signon', 3 => 'closed', 4 => 'paused');
my %map_merch_rep_status = (0 => 'unknown', 1 => 'ok', 2 => 'suspended', 3 => 'error');
my %map_trans_rep_status = (0 => 'unknown', 1 => 'ok', 2 => 'suspended', 3 => 'error');
while (my $row = $self->{sql}->fetchrow_hashref()) {
$self->{global}->{total}++;
$self->{global}->{$map_status{$row->{ONLINE}}}++
if (defined($map_status{$row->{ONLINE}}));
$self->{state}->{$map_state{$row->{FO_STATE}}}++
if (defined($map_state{$row->{FO_STATE}}));
$self->{merchandise}->{$map_merch_rep_status{$row->{MERCHANDISE_REPLICATION}}}++
if (defined($map_merch_rep_status{$row->{MERCHANDISE_REPLICATION}}));
$self->{transaction}->{$map_trans_rep_status{$row->{TRANSACTION_REPLICATION}}}++
if (defined($map_trans_rep_status{$row->{TRANSACTION_REPLICATION}}));
}
}
1;
__END__
=head1 MODE
Check points of sale status
=over 8
=item B<--database>
Database name (default: 'Framework').
=item B<--warning-*>
Threshold warning.
Can be: 'online, offline, state-unknown, state-signoff, state-signon, state-closed, state-paused,
merchandise-rep-unknown, merchandise-rep-ok, merchandise-rep-suspended, merchandise-rep-error,
transaction-rep-unknown, transaction-rep-ok, transaction-rep-suspended, transaction-rep-error'.
=item B<--critical-*>
Threshold critical.
Can be: 'online, offline, state-unknown, state-signoff, state-signon, state-closed, state-paused,
merchandise-rep-unknown, merchandise-rep-ok, merchandise-rep-suspended, merchandise-rep-error,
transaction-rep-unknown, transaction-rep-ok, transaction-rep-suspended, transaction-rep-error'.
=back
=cut

View File

@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::cim_card;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Card');
my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Card', dont_quit => 1);
$self->{output}->output_add(long_msg => "Checking cim cards");
$self->{components}->{cim_card} = {name => 'cards', total => 0, skip => 0};
return if ($self->check_filter(section => 'cim_card'));
return if ($self->check_filter(section => 'cim_card') || !defined($result));
foreach (@{$result}) {
my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName};
@ -57,4 +59,4 @@ sub check {
}
}
1;
1;

View File

@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::cim_computersystem;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem');
my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem', dont_quit => 1);
$self->{output}->output_add(long_msg => "Checking cim computer systems");
$self->{components}->{cim_computersystem} = {name => 'computer systems', total => 0, skip => 0};
return if ($self->check_filter(section => 'cim_computersystem'));
return if ($self->check_filter(section => 'cim_computersystem') || !defined($result));
foreach (@{$result}) {
my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName};
@ -57,4 +59,4 @@ sub check {
}
}
1;
1;

View File

@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::cim_memory;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Memory');
my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Memory', dont_quit => 1);
$self->{output}->output_add(long_msg => "Checking cim memories");
$self->{components}->{cim_memory} = {name => 'memories', total => 0, skip => 0};
return if ($self->check_filter(section => 'cim_memory'));
return if ($self->check_filter(section => 'cim_memory') || !defined($result));
foreach (@{$result}) {
my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName};
@ -57,4 +59,4 @@ sub check {
}
}
1;
1;

View File

@ -24,14 +24,16 @@ use strict;
use warnings;
use apps::vmware::wsman::mode::components::resources qw($mapping_units $mapping_sensortype);
sub load {}
sub check {
my ($self) = @_;
my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_NumericSensor');
my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_NumericSensor', dont_quit => 1);
$self->{output}->output_add(long_msg => "Checking cim numeric sensors");
$self->{components}->{cim_numericsensor} = {name => 'numeric sensors', total => 0, skip => 0};
return if ($self->check_filter(section => 'cim_numericsensor'));
return if ($self->check_filter(section => 'cim_numericsensor') || !defined($result));
foreach (@{$result}) {
my $sensor_type = defined($mapping_sensortype->{$_->{SensorType}}) ? $mapping_sensortype->{$_->{SensorType}} : 'unknown';
@ -108,4 +110,4 @@ sub check {
}
}
1;
1;

View File

@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::cim_processor;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Processor');
my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Processor', dont_quit => 1);
$self->{output}->output_add(long_msg => "Checking cim processors");
$self->{components}->{cim_processor} = {name => 'processors', total => 0, skip => 0};
return if ($self->check_filter(section => 'cim_processor'));
return if ($self->check_filter(section => 'cim_processor') || !defined($result));
foreach (@{$result}) {
my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName};
@ -59,4 +61,4 @@ sub check {
}
}
1;
1;

View File

@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::cim_recordlog;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_RecordLog');
my $result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_RecordLog', dont_quit => 1);
$self->{output}->output_add(long_msg => "Checking cim recordlog");
$self->{components}->{cim_recordlog} = {name => 'recordlog', total => 0, skip => 0};
return if ($self->check_filter(section => 'cim_recordlog'));
return if ($self->check_filter(section => 'cim_recordlog') || !defined($result));
foreach (@{$result}) {
my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName};
@ -57,4 +59,4 @@ sub check {
}
}
1;
1;

View File

@ -24,14 +24,16 @@ use strict;
use warnings;
use apps::vmware::wsman::mode::components::resources qw($mapping_EnableState);
sub load {}
sub check {
my ($self) = @_;
my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_DiscreteSensor');
my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_DiscreteSensor', dont_quit => 1);
$self->{output}->output_add(long_msg => "Checking OMC discrete sensors");
$self->{components}->{omc_discretesensor} = {name => 'omc discrete sensors', total => 0, skip => 0};
return if ($self->check_filter(section => 'omc_discretesensor'));
return if ($self->check_filter(section => 'omc_discretesensor') || !defined($result));
foreach (@{$result}) {
my $instance = $_->{Name};
@ -62,4 +64,4 @@ sub check {
}
}
1;
1;

View File

@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::omc_fan;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_Fan');
my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_Fan', dont_quit => 1);
$self->{output}->output_add(long_msg => "Checking OMC fans");
$self->{components}->{omc_fan} = {name => 'omc fans', total => 0, skip => 0};
return if ($self->check_filter(section => 'omc_fan'));
return if ($self->check_filter(section => 'omc_fan') || !defined($result));
foreach (@{$result}) {
my $instance = $_->{Name};
@ -57,4 +59,4 @@ sub check {
}
}
1;
1;

View File

@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::omc_psu;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_PowerSupply');
my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_PowerSupply', dont_quit => 1);
$self->{output}->output_add(long_msg => "Checking OMC power supplies");
$self->{components}->{omc_psu} = {name => 'omc psus', total => 0, skip => 0};
return if ($self->check_filter(section => 'omc_psu'));
return if ($self->check_filter(section => 'omc_psu') || !defined($result));
foreach (@{$result}) {
my $instance = $_->{Name};
@ -57,4 +59,4 @@ sub check {
}
}
1;
1;

View File

@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::vmware_battery;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_Battery');
my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_Battery', dont_quit => 1);
$self->{output}->output_add(long_msg => "Checking vmware batteries");
$self->{components}->{vmware_battery} = {name => 'batteries', total => 0, skip => 0};
return if ($self->check_filter(section => 'vmware_battery'));
return if ($self->check_filter(section => 'vmware_battery') || !defined($result));
foreach (@{$result}) {
my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName};
@ -57,4 +59,4 @@ sub check {
}
}
1;
1;

View File

@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::vmware_controller;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_Controller');
my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_Controller', dont_quit => 1);
$self->{output}->output_add(long_msg => "Checking vmware controller");
$self->{components}->{vmware_controller} = {name => 'controller', total => 0, skip => 0};
return if ($self->check_filter(section => 'vmware_controller'));
return if ($self->check_filter(section => 'vmware_controller') || !defined($result));
foreach (@{$result}) {
my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName};
@ -57,4 +59,4 @@ sub check {
}
}
1;
1;

View File

@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::vmware_sassataport;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_SASSATAPort');
my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_SASSATAPort', dont_quit => 1);
$self->{output}->output_add(long_msg => "Checking vmware sas/sata ports");
$self->{components}->{vmware_sassataport} = {name => 'sas/sata ports', total => 0, skip => 0};
return if ($self->check_filter(section => 'vmware_sassataport'));
return if ($self->check_filter(section => 'vmware_sassataport') || !defined($result));
foreach (@{$result}) {
my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName};
@ -57,4 +59,4 @@ sub check {
}
}
1;
1;

View File

@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::vmware_storageextent;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_StorageExtent');
my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_StorageExtent', dont_quit => 1);
$self->{output}->output_add(long_msg => "Checking vmware storage extent");
$self->{components}->{vmware_storageextent} = {name => 'storage extent', total => 0, skip => 0};
return if ($self->check_filter(section => 'vmware_storageextent'));
return if ($self->check_filter(section => 'vmware_storageextent') || !defined($result));
foreach (@{$result}) {
my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName};
@ -57,4 +59,4 @@ sub check {
}
}
1;
1;

View File

@ -23,14 +23,16 @@ package apps::vmware::wsman::mode::components::vmware_storagevolume;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_StorageVolume');
my $result = $self->{wsman}->request(uri => 'http://schemas.vmware.com/wbem/wscim/1/cim-schema/2/VMware_StorageVolume', dont_quit => 1);
$self->{output}->output_add(long_msg => "Checking vmware storage volumes");
$self->{components}->{vmware_storagevolume} = {name => 'storage volumes', total => 0, skip => 0};
return if ($self->check_filter(section => 'vmware_storagevolume'));
return if ($self->check_filter(section => 'vmware_storagevolume') || !defined($result));
foreach (@{$result}) {
my $instance = defined($_->{Name}) && $_->{Name} ne '' ? $_->{Name} : $_->{ElementName};
@ -57,4 +59,4 @@ sub check {
}
}
1;
1;

View File

@ -20,41 +20,54 @@
package apps::vmware::wsman::mode::hardware;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
use apps::vmware::wsman::mode::components::resources qw($mapping_HealthState $mapping_OperationalStatus);
my %type = ('cim_numericsensor' => 1);
my $thresholds = {
default => [
['Unknown', 'OK'],
['OK', 'OK'],
['Degraded', 'WARNING'],
['Minor failure', 'WARNING'],
['Major failure', 'CRITICAL'],
['Critical failure', 'CRITICAL'],
['Non-recoverable error', 'CRITICAL'],
['Other', 'UNKNOWN'],
['Stressed', 'WARNING'],
['Predictive Failure', 'WARNING'],
['Error', 'CRITICAL'],
['Starting', 'OK'],
['Stopping', 'WARNING'],
['In Service', 'OK'],
['No Contact', 'CRITICAL'],
['Lost Communication', 'CRITICAL'],
['Aborted', 'CRITICAL'],
['Dormant', 'OK'],
['Supporting Entity in Error', 'CRITICAL'],
['Completed', 'OK'],
['Power Mode', 'OK'],
['Relocating', 'WARNING'],
],
};
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} =
'^(omc_discretesensor|omc_fan|omc_psu|vmware_storageextent|vmware_controller|vmware_storagevolume|vmware_battery|vmware_sassataport|cim_card|cim_computersystem|cim_numericsensor|cim_memory|cim_processor|cim_recordlog)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(cim_numericsensor)$';
$self->{cb_hook1} = 'get_type';
$self->{thresholds} = {
default => [
['Unknown', 'OK'],
['OK', 'OK'],
['Degraded', 'WARNING'],
['Minor failure', 'WARNING'],
['Major failure', 'CRITICAL'],
['Critical failure', 'CRITICAL'],
['Non-recoverable error', 'CRITICAL'],
['Other', 'UNKNOWN'],
['Stressed', 'WARNING'],
['Predictive Failure', 'WARNING'],
['Error', 'CRITICAL'],
['Starting', 'OK'],
['Stopping', 'WARNING'],
['In Service', 'OK'],
['No Contact', 'CRITICAL'],
['Lost Communication', 'CRITICAL'],
['Aborted', 'CRITICAL'],
['Dormant', 'OK'],
['Supporting Entity in Error', 'CRITICAL'],
['Completed', 'OK'],
['Power Mode', 'OK'],
['Relocating', 'WARNING'],
],
};
$self->{components_path} = 'apps::vmware::wsman::mode::components';
$self->{components_module} = ['omc_discretesensor', 'omc_fan', 'omc_psu', 'vmware_storageextent', 'vmware_controller',
'vmware_storagevolume', 'vmware_battery', 'vmware_sassataport', 'cim_card',
'cim_computersystem', 'cim_numericsensor', 'cim_memory', 'cim_processor', 'cim_recordlog'];
}
sub new {
my ($class, %options) = @_;
@ -63,106 +76,29 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter:s@" => { name => 'filter' },
"component:s" => { name => 'component', default => '.*' },
"no-component:s" => { name => 'no_component' },
"threshold-overload:s@" => { name => 'threshold_overload' },
"warning:s@" => { name => 'warning' },
"critical:s@" => { name => 'critical' },
{
});
$self->{components} = {};
$self->{no_components} = undef;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{no_component})) {
if ($self->{option_results}->{no_component} ne '') {
$self->{no_components} = $self->{option_results}->{no_component};
} else {
$self->{no_components} = 'critical';
}
}
$self->{filter} = [];
foreach my $val (@{$self->{option_results}->{filter}}) {
next if (!defined($val) || $val eq '');
my @values = split (/,/, $val);
push @{$self->{filter}}, { filter => $values[0], instance => $values[1] };
}
$self->{overload_th} = {};
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
next if (!defined($val) || $val eq '');
my @values = split (/,/, $val);
if (scalar(@values) < 3) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $instance, $status, $filter);
if (scalar(@values) == 3) {
($section, $status, $filter) = @values;
$instance = '.*';
} else {
($section, $instance, $status, $filter) = @values;
}
if ($self->{output}->is_litteral_status(status => $status) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
$self->{output}->option_exit();
}
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status, instance => $instance };
}
$self->{numeric_threshold} = {};
foreach my $option (('warning', 'critical')) {
foreach my $val (@{$self->{option_results}->{$option}}) {
next if (!defined($val) || $val eq '');
if ($val !~ /^(.*?),(.*?),(.*)$/) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
$self->{output}->option_exit();
}
my ($section, $instance, $value) = ($1, $2, $3);
if (!defined($type{$section})) {
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
$self->{output}->option_exit();
}
my $position = 0;
if (defined($self->{numeric_threshold}->{$section})) {
$position = scalar(@{$self->{numeric_threshold}->{$section}});
}
if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'.");
$self->{output}->option_exit();
}
$self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section}));
push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, instance => $instance };
}
}
}
sub get_type {
my ($self, %options) = @_;
my $result = $self->{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_SMASHFirmwareIdentity');
$result = pop(@$result);
my $result = $options{wsman}->request(uri => 'http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_SMASHFirmwareIdentity', dont_quit => 1);
$result = pop(@$result) if (defined($result));
$self->{manufacturer} = 'unknown';
if (defined($result->{Manufacturer}) && $result->{Manufacturer} ne '') {
$self->{manufacturer} = $result->{Manufacturer};
}
$result = $self->{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Chassis');
$result = $options{wsman}->request(uri => 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Chassis');
$result = pop(@$result);
my $model = defined($result->{Model}) && $result->{Model} ne '' ? $result->{Model} : 'unknown';
$self->{output}->output_add(long_msg => sprintf("Manufacturer : %s, Model : %s", $self->{manufacturer}, $model));
$self->{wsman} = $options{wsman};
}
sub get_status {
@ -179,115 +115,6 @@ sub get_status {
return $status;
}
sub run {
my ($self, %options) = @_;
$self->{wsman} = $options{wsman};
$self->get_type();
my @components = ('omc_discretesensor', 'omc_fan', 'omc_psu', 'vmware_storageextent', 'vmware_controller',
'vmware_storagevolume', 'vmware_battery', 'vmware_sassataport', 'cim_card',
'cim_computersystem', 'cim_numericsensor', 'cim_memory', 'cim_processor', 'cim_recordlog');
foreach (@components) {
if (/$self->{option_results}->{component}/) {
my $mod_name = "apps::vmware::wsman::mode::components::$_";
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name,
error_msg => "Cannot load module '$mod_name'.");
my $func = $mod_name->can('check');
$func->($self);
}
}
my $total_components = 0;
my $display_by_component = '';
my $display_by_component_append = '';
foreach my $comp (sort(keys %{$self->{components}})) {
# Skipping short msg when no components
next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
$total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
$display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name};
$display_by_component_append = ', ';
}
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("All %s sensors are ok [%s].",
$total_components,
$display_by_component)
);
if (defined($self->{option_results}->{no_component}) && $total_components == 0) {
$self->{output}->output_add(severity => $self->{no_components},
short_msg => 'No sensors are checked.');
}
$self->{output}->display();
$self->{output}->exit();
}
sub check_filter {
my ($self, %options) = @_;
foreach (@{$self->{filter}}) {
if ($options{section} =~ /$_->{filter}/) {
if (!defined($options{instance}) && !defined($_->{instance})) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
return 1;
} elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) {
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
return 1;
}
}
}
return 0;
}
sub get_severity_numeric {
my ($self, %options) = @_;
my $status = 'OK'; # default
my $thresholds = { warning => undef, critical => undef };
my $checked = 0;
if (defined($self->{numeric_threshold}->{$options{section}})) {
my $exits = [];
foreach (@{$self->{numeric_threshold}->{$options{section}}}) {
if ($options{instance} =~ /$_->{instance}/) {
push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]);
$thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label});
$checked = 1;
}
}
$status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0);
}
return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked);
}
sub get_severity {
my ($self, %options) = @_;
my $status = 'UNKNOWN'; # default
if (defined($self->{overload_th}->{$options{section}})) {
foreach (@{$self->{overload_th}->{$options{section}}}) {
if ($options{value} =~ /$_->{filter}/i &&
(!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) {
$status = $_->{status};
return $status;
}
}
}
my $label = defined($options{label}) ? $options{label} : $options{section};
foreach (@{$thresholds->{$label}}) {
if ($options{value} =~ /$$_[0]/i) {
$status = $$_[1];
return $status;
}
}
return $status;
}
1;
__END__
@ -335,4 +162,4 @@ Example: --critical='cim_numericsensor,.*,40'
=back
=cut
=cut

View File

@ -32,7 +32,7 @@ sub set_counters {
$self->{maps_counters_type} = [
{ name => 'tag', type => 1, cb_prefix_output => 'prefix_tag_output', message_multiple => 'All RTT controls are ok',
skipped_code => { -2 => 1 } }
skipped_code => { -2 => 1, -3 => 1, -10 => 1 } }
];
$self->{maps_counters}->{tag} = [
{ label => 'status', threshold => 0, set => {
@ -955,4 +955,4 @@ Can be: 'CompletionTime', 'NumberOverThresholds', 'AverageDelaySD', 'AverageDela
=back
=cut

View File

@ -124,7 +124,7 @@ sub run {
threshold => [ { label => 'crit60', exit_litteral => 'critical' }, { label => 'warn60', exit_litteral => 'warning' } ]);
$exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4 ]);
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Averate session setup rate: %s, %s, %s, %s (1min, 10min, 30min, 60min)",
short_msg => sprintf("Average session setup rate: %s, %s, %s, %s (1min, 10min, 30min, 60min)",
$result->{$oid_fgSysSesRate1}, $result->{$oid_fgSysSesRate10},
$result->{$oid_fgSysSesRate30}, $result->{$oid_fgSysSesRate60}));
@ -182,4 +182,4 @@ Threshold critical of average setup rate (1min,10min,30min,60min).
=back
=cut

View File

@ -20,7 +20,7 @@
package centreon::common::jvm::mode::memorydetailed;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
@ -42,6 +42,133 @@ my %mapping_memory = (
'Tenured Gen' => 'tenured',
);
my $instance_mode;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'mem', type => 1, cb_prefix_output => 'prefix_mem_output', message_multiple => 'All memories within bounds', skipped_code => { -12 => 1 } },
];
$self->{maps_counters}->{mem} = [
{ label => 'eden', set => {
key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
}
},
{ label => 'tenured', set => {
key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
}
},
{ label => 'survivor', set => {
key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
}
},
{ label => 'permanent', set => {
key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
}
},
{ label => 'code', set => {
key_values => [ { name => 'used' }, { name => 'max' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
}
},
];
}
sub custom_usage_perfdata {
my ($self, %options) = @_;
my $use_th = 1;
$use_th = 0 if ($instance_mode->{option_results}->{units} eq '%' && $self->{result_values}->{max} <= 0);
my $value_perf = $self->{result_values}->{used};
my %total_options = ();
if ($instance_mode->{option_results}->{units} eq '%' && $self->{result_values}->{max} > 0) {
$total_options{total} = $self->{result_values}->{max};
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(label => $self->{label}, unit => 'B',
value => $value_perf,
warning => $use_th == 1 ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef,
critical => $use_th == 1 ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options) : undef,
min => 0, max => $self->{result_values}->{max} > 0 ? $self->{result_values}->{max} : undef);
}
sub custom_usage_threshold {
my ($self, %options) = @_;
# Cannot use percent without total
return 'ok' if ($self->{result_values}->{max} <= 0 && $instance_mode->{option_results}->{units} eq '%');
my ($exit, $threshold_value);
$threshold_value = $self->{result_values}->{used};
if ($instance_mode->{option_results}->{units} eq '%') {
$threshold_value = $self->{result_values}->{prct_used};
}
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_usage_output {
my ($self, %options) = @_;
my $msg;
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
if ($self->{result_values}->{max} > 0) {
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{max});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{max} - $self->{result_values}->{used});
$msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, 100 - $self->{result_values}->{prct_used});
} else {
$msg = sprintf("Used: %s", $total_used_value . " " . $total_used_unit);
}
return $msg;
}
sub custom_usage_calc {
my ($self, %options) = @_;
if ($mapping_memory{$options{new_datas}->{$self->{instance} . '_display'}} ne $self->{label}) {
return -12;
}
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{max} = $options{new_datas}->{$self->{instance} . '_max'};
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
if ($self->{result_values}->{max} > 0) {
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{max};
}
return 0;
}
sub prefix_mem_output {
my ($self, %options) = @_;
return "Memory '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -49,48 +176,29 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning-eden:s" => { name => 'warning_eden' },
"critical-eden:s" => { name => 'critical_eden' },
"warning-survivor:s" => { name => 'warning_survivor' },
"critical-survivor:s" => { name => 'critical_survivor' },
"warning-tenured:s" => { name => 'warning_tenured' },
"critical-tenured:s" => { name => 'critical_tenured' },
"warning-permanent:s" => { name => 'warning_permanent' },
"critical-permanent:s" => { name => 'critical_permanent' },
"warning-code:s" => { name => 'warning_code' },
"critical-code:s" => { name => 'critical_code' }
{
"units:s" => { name => 'units', default => '%' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $label ('warning_eden', 'critical_eden', 'warning_survivor', 'critical_survivor', 'warning_tenured', 'critical_tenured', 'warning_permanent', 'critical_permanent', 'warning_code', 'critical_code') {
if (($self->{perfdata}->threshold_validate(label => $label, value => $self->{option_results}->{$label})) == 0) {
my ($label_opt) = $label;
$label_opt =~ tr/_/-/;
$self->{output}->add_option_msg(short_msg => "Wrong " . $label_opt . " threshold '" . $self->{option_results}->{$label} . "'.");
$self->{output}->option_exit();
}
}
$self->SUPER::check_options(%options);
$instance_mode = $self;
}
sub run {
sub manage_selection {
my ($self, %options) = @_;
$self->{connector} = $options{custom};
$self->{request} = [
{ mbean => "java.lang:type=MemoryPool,name=*", attributes => [ { name => 'Usage' } ] }
];
my $result = $self->{connector}->get_attributes(request => $self->{request}, nothing_quit => 1);
$self->{output}->output_add(severity => 'OK',
short_msg => 'All memories within bounds');
my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1);
$self->{mem} = {};
foreach my $key (keys %$result) {
$key =~ /name=(.*?),type/;
my $memtype = $1;
@ -100,29 +208,12 @@ sub run {
next;
}
my $prct = $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{used} / $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{max} * 100;
$self->{output}->perfdata_add(label => $mapping_memory{$memtype}, unit => 'B',
value => $result->{"java.lang:name=" . $memtype . ",type=MemoryPool"}->{Usage}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $mapping_memory{$memtype}, total => $result->{"java.lang:name=" . $memtype . ",type=MemoryPool"}->{Usage}->{used}, cast_int => 1),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $mapping_memory{$memtype}, total => $result->{"java.lang:name=" . $memtype . ",type=MemoryPool"}->{Usage}->{used}, cast_int => 1),
min => 0, max => $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{max});
my $exit = $self->{perfdata}->threshold_check(value => $prct,
threshold => [ { label => 'critical_' . $mapping_memory{$memtype}, exit_litteral => 'critical' },
{ label => 'warning_' . $mapping_memory{$memtype}, exit_litteral => 'warning' } ]);
$self->{output}->output_add(long_msg => sprintf("%s usage %.2f%%", $memtype, $prct));
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("%s usage %.2f%% ", $memtype, $prct));
}
$self->{mem}->{$memtype} = {
display => $memtype,
used => $result->{"java.lang:name=" . $memtype . ",type=MemoryPool"}->{Usage}->{used},
max => $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{max},
};
}
$self->{output}->display();
$self->{output}->exit();
}
1;
@ -184,6 +275,10 @@ Threshold warning of NonHeap 'Code Cache' memory usage
Threshold critical of NonHeap 'Code Cache' memory usage
=item B<--units>
Units of thresholds (Default: '%') ('%', 'B').
=back
=cut

View File

@ -0,0 +1,141 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package centreon::common::powershell::windows::pendingreboot;
use strict;
use warnings;
use centreon::plugins::misc;
sub get_powershell {
my (%options) = @_;
my $no_ps = (defined($options{no_ps})) ? 1 : 0;
return '' if ($no_ps == 1);
my $ps = '
$culture = new-object "System.Globalization.CultureInfo" "en-us"
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
$ProgressPreference = "SilentlyContinue"
Try {
$ErrorActionPreference = "Stop"
$ComputerName = "$env:COMPUTERNAME"
$CompPendRen,$PendFileRename,$Pending,$SCCM = $false,$false,$false,$false
## Setting CBSRebootPend to null since not all versions of Windows has this value
$CBSRebootPend = $null
## Querying WMI for build version
$WMI_OS = Get-WmiObject -Class Win32_OperatingSystem -Property BuildNumber, CSName -ComputerName $ComputerName -ErrorAction Stop
## Making registry connection to the local/remote computer
$HKLM = [UInt32] "0x80000002"
$WMI_Reg = [WMIClass] "\\\\$ComputerName\\root\\default:StdRegProv"
## If Vista/2008 & Above query the CBS Reg Key
If ([Int32]$WMI_OS.BuildNumber -ge 6001) {
$RegSubKeysCBS = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\")
$CBSRebootPend = $RegSubKeysCBS.sNames -contains "RebootPending"
}
## Query WUAU from the registry
$RegWUAURebootReq = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\")
$WUAURebootReq = $RegWUAURebootReq.sNames -contains "RebootRequired"
## Query PendingFileRenameOperations from the registry
$RegSubKeySM = $WMI_Reg.GetMultiStringValue($HKLM,"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\","PendingFileRenameOperations")
$RegValuePFRO = $RegSubKeySM.sValue
## Query ComputerName and ActiveComputerName from the registry
$ActCompNm = $WMI_Reg.GetStringValue($HKLM,"SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName\\","ComputerName")
$CompNm = $WMI_Reg.GetStringValue($HKLM,"SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ComputerName\\","ComputerName")
If ($ActCompNm -ne $CompNm) {
$CompPendRen = $true
}
## If PendingFileRenameOperations has a value set $RegValuePFRO variable to $true
If ($RegValuePFRO) {
$PendFileRename = $true
}
## Determine SCCM 2012 Client Reboot Pending Status
## To avoid nested "if" statements and unneeded WMI calls to determine if the CCM_ClientUtilities class exist, setting EA = 0
$CCMClientSDK = $null
$CCMSplat = @{
NameSpace="ROOT\\ccm\\ClientSDK"
Class="CCM_ClientUtilities"
Name="DetermineIfRebootPending"
ComputerName=$ComputerName
ErrorAction="Stop"
}
## Try CCMClientSDK
Try {
$CCMClientSDK = Invoke-WmiMethod @CCMSplat
} Catch [System.UnauthorizedAccessException] {
$CcmStatus = Get-Service -Name CcmExec -ComputerName $ComputerName -ErrorAction SilentlyContinue
If ($CcmStatus.Status -ne "Running") {
Write-Warning "$ComputerName`: Error - CcmExec service is not running."
$CCMClientSDK = $null
}
} Catch {
$CCMClientSDK = $null
}
If ($CCMClientSDK) {
If ($CCMClientSDK.ReturnValue -ne 0) {
Write-Warning "Error: DetermineIfRebootPending returned error code $($CCMClientSDK.ReturnValue)"
}
If ($CCMClientSDK.IsHardRebootPending -or $CCMClientSDK.RebootPending) {
$SCCM = $true
}
} Else {
$SCCM = $null
}
Write-Host ("[CBServicing={0}]" -f $CBSRebootPend ) -NoNewline
Write-Host ("[WindowsUpdate={0}]" -f $WUAURebootReq ) -NoNewline
Write-Host ("[CCMClientSDK={0}]" -f $SCCM ) -NoNewline
Write-Host ("[PendComputerRename={0}]" -f $CompPendRen ) -NoNewline
Write-Host ("[PendFileRename={0}]" -f $PendFileRename ) -NoNewline
Write-Host ("[PendFileRenVal={0}]" -f $RegValuePFRO ) -NoNewline
Write-Host ("[RebootPending={0}]" -f ($CompPendRen -or $CBSRebootPend -or $WUAURebootReq -or $SCCM -or $PendFileRename) )
} Catch {
Write-Host $Error[0].Exception
exit 1
}
exit 0
';
return centreon::plugins::misc::powershell_encoded($ps);
}
1;
__END__
=head1 DESCRIPTION
Method to get pending reboot informations.
=cut

View File

@ -292,7 +292,8 @@ sub list_attributes {
$v =~ s/^\s*//;
print " = " . $v;
} else {
if (my $scal = JMX::Jmx4Perl::Util->dump_scalar($val)) {
my $scal = JMX::Jmx4Perl::Util->dump_scalar($val);
if (defined($scal)) {
print " = " . $scal . "\n";
} else {
print " = undef\n";
@ -367,4 +368,4 @@ Credentials to use for the target
B<custom>.
=cut
=cut

View File

@ -0,0 +1,201 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package centreon::common::protocols::ssh::custom::api;
use strict;
use warnings;
use Libssh::Session qw(:all);
sub new {
my ($class, %options) = @_;
my $self = {};
bless $self, $class;
if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n";
exit 3;
}
if (!defined($options{options})) {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit();
}
if (!defined($options{noptions})) {
$options{options}->add_options(arguments =>
{
"hostname:s@" => { name => 'hostname' },
"port:s@" => { name => 'port' },
"timeout:s@" => { name => 'timeout' },
"ssh-username:s@" => { name => 'ssh_username' },
"ssh-password:s@" => { name => 'ssh_password' },
"ssh-dir:s@" => { name => 'ssh_dir' },
"ssh-identity:s@" => { name => 'ssh_identity' },
"ssh-skip-serverkey-issue" => { name => 'ssh_skip_serverkey_issue' },
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'SSH OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{mode} = $options{mode};
$self->{ssh} = undef;
return $self;
}
sub set_options {
my ($self, %options) = @_;
$self->{option_results} = $options{option_results};
}
sub set_defaults {
my ($self, %options) = @_;
foreach (keys %{$options{default}}) {
if ($_ eq $self->{mode}) {
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
if (!defined($self->{option_results}->{$opt}[$i])) {
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
}
}
}
}
}
}
sub check_options {
my ($self, %options) = @_;
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? shift(@{$self->{option_results}->{hostname}}) : undef;
$self->{port} = (defined($self->{option_results}->{port})) ? shift(@{$self->{option_results}->{port}}) : 22;
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? shift(@{$self->{option_results}->{timeout}}) : 10;
$self->{ssh_username} = (defined($self->{option_results}->{ssh_username})) ? shift(@{$self->{option_results}->{ssh_username}}) : undef;
$self->{ssh_password} = (defined($self->{option_results}->{ssh_password})) ? shift(@{$self->{option_results}->{ssh_password}}) : undef;
$self->{ssh_dir} = (defined($self->{option_results}->{ssh_dir})) ? shift(@{$self->{option_results}->{ssh_dir}}) : undef;
$self->{ssh_identity} = (defined($self->{option_results}->{ssh_identity})) ? shift(@{$self->{option_results}->{ssh_identity}}) : undef;
$self->{ssh_skip_serverkey_issue} = defined($self->{option_results}->{ssh_skip_serverkey_issue}) ? 1 : 0;
if (!defined($self->{hostname}) || $self->{hostname} eq '') {
$self->{output}->add_option_msg(short_msg => "Please set option --hostname.");
$self->{output}->option_exit();
}
if (!defined($self->{hostname}) ||
scalar(@{$self->{option_results}->{hostname}}) == 0) {
return 0;
}
return 1;
}
sub login {
my ($self, %options) = @_;
my $result = { status => 0, message => 'authentification succeeded' };
$self->{ssh} = Libssh::Session->new();
foreach (['hostname', 'host'], ['port', 'port'], ['timeout', 'timeout'], ['ssh_username', 'user'],
['ssh_dir', 'sshdir'], ['ssh_identity', 'identity']) {
next if (!defined($self->{$_->[0]}) || $self->{$_->[0]} eq '');
if ($self->{ssh}->options($_->[1] => $self->{$_->[0]}) != SSH_OK) {
$result->{message} = $self->{ssh}->error();
$result->{status} = 1;
return $result;
}
}
if ($self->{ssh}->connect(SkipKeyProblem => $self->{ssh_skip_serverkey_issue}) != SSH_OK) {
$result->{message} = $self->{ssh}->error();
$result->{status} = 1;
return $result;
}
if ($self->{ssh}->auth_publickey_auto() != SSH_AUTH_SUCCESS) {
if (defined($self->{ssh_username}) && $self->{ssh_username} ne '' &&
defined($self->{ssh_password}) && $self->{ssh_password} ne '' &&
$self->{ssh}->auth_password(password => $self->{ssh_password}) == SSH_AUTH_SUCCESS) {
return $result;
}
my $msg_error = $self->{ssh}->error(GetErrorSession => 1);
$result->{message} = sprintf("auth issue: %s", defined($msg_error) && $msg_error ne '' ? $msg_error : 'pubkey issue');
$result->{status} = 1;
}
return $result;
}
1;
__END__
=head1 NAME
SSH connector library
=head1 SYNOPSIS
my ssh connector
=head1 SSH OPTIONS
=over 8
=item B<--hostname>
SSH server hostname (required).
=item B<--port>
SSH port.
=item B<--timeout>
Timeout in seconds for connection (Defaults: 10 seconds)
=item B<--ssh-username>
SSH username.
=item B<--ssh-password>
SSH password.
=item B<--ssh-dir>
Set the ssh directory.
=item B<--ssh-identity>
Set the identity file name (default: id_dsa and id_rsa are checked).
=item B<--ssh-skip-serverkey-issue>
Connection will be OK even if there is a problem (server known changed or server found other) with the ssh server.
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -393,7 +393,7 @@ sub convert_bytes {
my (%options) = @_;
my %expo = (k => 1, m => 2, g => 3, t => 4);
my $value = $options{value};
my $base = defined($options{network}) ? 1000 : 1020;
my $base = defined($options{network}) ? 1000 : 1024;
if ($options{unit} =~ /([kmgt])b/i) {
$value = $value * ($base ** $expo{lc($1)});

View File

@ -30,7 +30,7 @@ use Pod::Find qw(pod_where);
my %handlers = (DIE => {});
my $global_version = 20170613;
my $global_version = 20171013;
my $alternative_fatpacker = 0;
sub new {

View File

@ -64,11 +64,11 @@ sub init {
# $options{version} = string version
# $options{help} = string help
if (defined($options{help}) && !defined($self->{mode_name})) {
if (defined($options{help}) && !defined($self->{mode_name}) && !defined($self->{dynmode_name})) {
$self->{options}->display_help();
$self->{output}->option_exit();
}
if (defined($options{version}) && !defined($self->{mode_name})) {
if (defined($options{version}) && !defined($self->{mode_name}) && !defined($self->{dynmode_name})) {
$self->version();
}
if (defined($self->{list_mode})) {

View File

@ -66,11 +66,11 @@ sub init {
# $options{version} = string version
# $options{help} = string help
if (defined($options{help}) && !defined($self->{mode_name})) {
if (defined($options{help}) && !defined($self->{mode_name}) && !defined($self->{dynmode_name})) {
$self->{options}->display_help();
$self->{output}->option_exit();
}
if (defined($options{version}) && !defined($self->{mode_name})) {
if (defined($options{version}) && !defined($self->{mode_name}) && !defined($self->{dynmode_name})) {
$self->version();
}
if (defined($self->{list_mode})) {

View File

@ -66,11 +66,11 @@ sub init {
# $options{version} = string version
# $options{help} = string help
if (defined($options{help}) && !defined($self->{mode_name})) {
if (defined($options{help}) && !defined($self->{mode_name}) && !defined($self->{dynmode_name})) {
$self->{options}->display_help();
$self->{output}->option_exit();
}
if (defined($options{version}) && !defined($self->{mode_name})) {
if (defined($options{version}) && !defined($self->{mode_name}) && !defined($self->{dynmode_name})) {
$self->version();
}
if (defined($self->{list_mode})) {

View File

@ -570,10 +570,11 @@ sub set {
# Get last value
next if ($oid !~ /(.*)\.(\d+)([\.\s]*)$/);
my $value = $options{oids}->{$oid};
my $value = $options{oids}->{$oid}->{value};
my $type = $options{oids}->{$oid}->{type};
my ($oid, $instance) = ($1, $2);
push @$vars, [$oid, $instance, $value];
push @$vars, [$oid, $instance, $value, $type];
}
$self->{session}->set($vars);

View File

@ -263,7 +263,10 @@ sub run_instances {
$suffix_output = '' if (!defined($suffix_output));
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
$self->{output}->output_add(long_msg => ($display_status_lo == 1 ? lc($exit) . ': ' : '') . "${prefix_output}${long_msg}${suffix_output}");
# in mode grouped, we don't display 'ok'
my $debug = 0;
$debug = 1 if ($display_status_lo == 1 && $self->{output}->is_status(value => $exit, compare => 'OK', litteral => 1));
$self->{output}->output_add(long_msg => ($display_status_lo == 1 ? lc($exit) . ': ' : '') . "${prefix_output}${long_msg}${suffix_output}", debug => $debug);
if ($resume == 1) {
$self->{most_critical_instance} = $self->{output}->get_most_critical(status => [ $self->{most_critical_instance}, $exit ]);
next;
@ -403,4 +406,4 @@ Can be: 'xxx', 'xxx'.
=back
=cut
=cut

View File

@ -139,8 +139,8 @@ sub output {
if (defined($self->{closure_custom_output})) {
return $self->{closure_custom_output}->($self);
}
my $first = ${${$self->{key_values}}[0]}{name};
my ($value, $unit) = ($self->{result_values}->{$first . '_absolute'}, $self->{output_absolute_unit});
my $first = $self->{key_values}->[0]->{name};
my ($value, $unit) = (defined($first) ? $self->{result_values}->{$first . '_absolute'} : '', $self->{output_absolute_unit});
if (!defined($self->{output_use})) {
if ($self->{per_second} == 1) {

View File

@ -1,6 +1,39 @@
2017-07-XX Quentin Garnier <qgarnier@centreon.com>
2017-10-13 Quentin Garnier <qgarnier@centreon.com>
* Plugin added: Kaminario Rest API
* Plugin added: Protocol SSH
* Plugin added: Tivoli Storage Manager
* Plugin added: Toshiba Storemate
* Mode added: [windows] 'pending-reboot'
* Mode added: [storeonce] 'nas-usage'
* Mode added: [tomcat] 'connector-usage'
2017-09-13 Quentin Garnier <qgarnier@centreon.com>
* Plugin added: Zookeeper JMX
* Plugin added: Solr JMX
* Plugin added: Automic Workload Automation JMX
* Plugin added: Fujitsu Server SNMP
* Plugin added: Foxbox Notification
* Break: Netasq renamed to Stormshield
2017-08-11 Quentin Garnier <qgarnier@centreon.com>
* Plugin added: Ruckus AP SNMP
* Plugin added: Adva FSP3000 SNMP
* Plugin added: Nokia Timos SNMP
* Plugin added: Huawei SNMP
* Plugin added: Hibernate JMX
* Plugin added: Raisecom SNMP
* Break: mode change for Pfsense SNMP
* Break: mode change for HP MSL SNMP
* Break: mode change for Juniper ISG SNMP
* Break: mode change for Digi Standard (sarian now) SNMP
2017-07-13 Quentin Garnier <qgarnier@centreon.com>
* Plugin added: Supermicro SNMP
* Plugin added: QuadStor VTL Local
* Plugin added: Docker Rest API
* Mode added: [linux] directlvm-usage
* Mode added: [oracle] rollback-segment-usage
* Mode added: [oracle] event-waits-usage
2017-06-13 Quentin Garnier <qgarnier@centreon.com>
* Plugin added: HP Eva CLI

View File

@ -171,6 +171,18 @@ sub api_read_file {
return $content;
}
sub get_hostnames {
my ($self, %options) = @_;
return $self->{hostname};
}
sub get_port {
my ($self, %options) = @_;
return $self->{option_results}->{port};
}
sub cache_containers {
my ($self, %options) = @_;
@ -197,6 +209,46 @@ sub cache_containers {
return $containers;
}
sub internal_api_list_nodes {
my ($self, %options) = @_;
my $response = $self->{http}->{$options{node_name}}->request(
url_path => '/nodes',
unknown_status => '', critical_status => '', warning_status => '');
my $nodes;
eval {
$nodes = JSON::XS->new->utf8->decode($response);
};
if ($@) {
$nodes = [];
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Node '$options{node_name}': cannot decode json list nodes response: $@");
} else {
$nodes = [] if (ref($nodes) eq 'HASH'); # nodes is not in a swarm
}
return $nodes;
}
sub internal_api_info {
my ($self, %options) = @_;
my $response = $self->{http}->{$options{node_name}}->request(
url_path => '/info',
unknown_status => '', critical_status => '', warning_status => '');
my $nodes;
eval {
$nodes = JSON::XS->new->utf8->decode($response);
};
if ($@) {
$nodes = [];
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Node '$options{node_name}': cannot decode json info response: $@");
}
return $nodes;
}
sub internal_api_list_containers {
my ($self, %options) = @_;
@ -235,6 +287,44 @@ sub internal_api_get_container_stats {
return $container_stats;
}
sub api_list_containers {
my ($self, %options) = @_;
my $containers = {};
foreach my $node_name (keys %{$self->{http}}) {
my $list_containers = $self->internal_api_list_containers(node_name => $node_name);
foreach my $container (@$list_containers) {
$containers->{$container->{Id}} = {
State => $container->{State},
NodeName => $node_name,
Name => join(':', @{$container->{Names}}),
};
}
}
return $containers;
}
sub api_list_nodes {
my ($self, %options) = @_;
my $nodes = {};
foreach my $node_name (keys %{$self->{http}}) {
my $info_node = $self->internal_api_info(node_name => $node_name);
my $list_nodes = $self->internal_api_list_nodes(node_name => $node_name);
$nodes->{$node_name} = { nodes => [],
containers_running => $info_node->{ContainersRunning},
containers_stopped => $info_node->{ContainersStopped},
containers_paused => $info_node->{ContainersPaused},
};
foreach my $node (@$list_nodes) {
push @{$nodes->{$node_name}->{nodes}}, { Status => $node->{Status}->{State}, ManagerStatus => $node->{ManagerStatus}->{Reachability}, Addr => $node->{Status}->{Addr} };
}
}
return $nodes;
}
sub api_get_containers {
my ($self, %options) = @_;
@ -243,8 +333,23 @@ sub api_get_containers {
}
my $content_total = $self->cache_containers(statefile => $options{statefile});
if (defined($options{container_id}) && $options{container_id} ne '' && defined($content_total->{$options{container_id}})) {
$content_total->{$options{container_id}}->{Stats} = $self->internal_api_get_container_stats(node_name => $content_total->{$options{container_id}}->{NodeName}, container_id => $options{container_id});
if (defined($options{container_id}) && $options{container_id} ne '') {
if (defined($content_total->{$options{container_id}})) {
$content_total->{$options{container_id}}->{Stats} = $self->internal_api_get_container_stats(node_name => $content_total->{$options{container_id}}->{NodeName}, container_id => $options{container_id});
}
} elsif (defined($options{container_name}) && $options{container_name} ne '') {
my $container_id;
foreach (keys %$content_total) {
if ($content_total->{$_}->{Name} eq $options{container_name}) {
$container_id = $_;
last;
}
}
if (defined($container_id)) {
$content_total->{$container_id}->{Stats} = $self->internal_api_get_container_stats(node_name => $content_total->{$container_id}->{NodeName}, container_id => $container_id);
}
} else {
foreach my $container_id (keys %{$content_total}) {
$content_total->{$container_id}->{Stats} = $self->internal_api_get_container_stats(node_name => $content_total->{$container_id}->{NodeName}, container_id => $container_id);

View File

@ -37,11 +37,11 @@ sub custom_status_threshold {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
if (defined($instance_mode->{option_results}->{critical_container_status}) && $instance_mode->{option_results}->{critical_container_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_container_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
} elsif (defined($instance_mode->{option_results}->{warning_container_status}) && $instance_mode->{option_results}->{warning_container_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_container_status}") {
$status = 'warning';
}
};
@ -54,7 +54,7 @@ sub custom_status_threshold {
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status} . ' [error: ' . $self->{result_values}->{error} . ']';
my $msg = 'state : ' . $self->{result_values}->{state};
return $msg;
}
@ -62,55 +62,146 @@ sub custom_status_output {
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
$self->{result_values}->{error} = $options{new_datas}->{$self->{instance} . '_error'};
return 0;
}
sub custom_cpu_calc {
my ($self, %options) = @_;
my $delta_cpu_total = $options{new_datas}->{$self->{instance} . '_cpu_total_usage'} - $options{old_datas}->{$self->{instance} . '_cpu_total_usage'};
my $delta_cpu_system = $options{new_datas}->{$self->{instance} . '_cpu_system_usage'} - $options{old_datas}->{$self->{instance} . '_cpu_system_usage'};
$self->{result_values}->{prct_cpu} = (($delta_cpu_total / $delta_cpu_system) * $options{new_datas}->{$self->{instance} . '_cpu_number'}) * 100;
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
}
sub custom_memory_perfdata {
my ($self, %options) = @_;
my $extra_label = '';
if (!defined($options{extra_instance}) || $options{extra_instance} != 0) {
$extra_label .= '_' . $self->{result_values}->{display};
}
$self->{output}->perfdata_add(label => 'memory_used' . $extra_label, unit => 'B',
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total});
}
sub custom_memory_threshold {
my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_memory_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my $msg = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
return $msg;
}
sub custom_memory_calc {
my ($self, %options) = @_;
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_memory_total'};
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_memory_usage'};
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
$self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'containers', type => 1, cb_prefix_output => 'prefix_containers_output', message_multiple => 'All containers are ok', skipped_code => { -11 => 1 } },
{ name => 'containers_traffic', type => 1, cb_prefix_output => 'prefix_containers_traffic_output', message_multiple => 'All container traffics are ok', skipped_code => { -11 => 1 } },
];
$self->{maps_counters}->{output_stream} = [
$self->{maps_counters}->{containers} = [
{ label => 'container-status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'name' }, { name => 'error' } ],
key_values => [ { name => 'state' }, { name => 'name' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
{ label => 'cpu', set => {
key_values => [ { name => 'cpu_total_usage', diff => 1 }, { name => 'cpu_system_usage', diff => 1 }, { name => 'cpu_number' }, { name => 'display' } ],
output_template => 'CPU Usage : %.2f %%',
closure_custom_calc => $self->can('custom_cpu_calc'),
output_use => 'prct_cpu', threshold_use => 'prct_cpu',
perfdatas => [
{ label => 'cpu', value => 'prct_cpu', template => '%.2f',
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
],
}
},
{ label => 'memory', set => {
key_values => [ { name => 'memory_usage' }, { name => 'memory_total' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_memory_calc'),
closure_custom_output => $self->can('custom_memory_output'),
closure_custom_perfdata => $self->can('custom_memory_perfdata'),
closure_custom_threshold_check => $self->can('custom_memory_threshold'),
}
},
{ label => 'read-iops', set => {
key_values => [ { name => 'read_io', diff => 1 }, { name => 'display' } ],
per_second => 1,
output_template => 'Read IOPs : %.2f', output_error_template => "Read IOPs : %s",
perfdatas => [
{ label => 'read_iops', value => 'read_io_per_second', template => '%.2f',
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'write-iops', set => {
key_values => [ { name => 'write_io', diff => 1 }, { name => 'display' } ],
per_second => 1,
output_template => 'Write IOPs : %.2f', output_error_template => "Write IOPs : %s",
perfdatas => [
{ label => 'write_iops', value => 'write_io_per_second', template => '%.2f',
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
$self->{maps_counters}->{containers_traffic} = [
{ label => 'traffic-in', set => {
key_values => [ { name => 'traffic_in', diff => 1 }, { name => 'name' } ],
key_values => [ { name => 'traffic_in', diff => 1 }, { name => 'display' } ],
per_second => 1, output_change_bytes => 2,
output_template => 'Traffic In : %s %s/s',
perfdatas => [
{ label => 'traffic_in', value => 'traffic_in_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'name_absolute' },
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'traffic-out', set => {
key_values => [ { name => 'traffic_out', diff => 1 }, { name => 'name' } ],
key_values => [ { name => 'traffic_out', diff => 1 }, { name => 'display' } ],
per_second => 1, output_change_bytes => 2,
output_template => 'Traffic Out : %s %s/s',
perfdatas => [
{ label => 'traffic_out', value => 'traffic_out_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'name_absolute' },
],
}
},
{ label => 'dropped-in', set => {
key_values => [ { name => 'dropped_in', diff => 1 }, { name => 'name' } ],
output_template => 'Packets Dropped In : %s',
perfdatas => [
{ label => 'dropped_in', value => 'dropped_in_absolute', template => '%.2f',
min => 0, label_extra_instance => 1, instance_use => 'name_absolute' },
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
@ -126,9 +217,11 @@ sub new {
$options{options}->add_options(arguments =>
{
"container-id:s" => { name => 'container_id' },
"container-name:s" => { name => 'container_name' },
"filter-name:s" => { name => 'filter_name' },
"warning-container-status:s" => { name => 'warning_container_status' },
"critical-container-status:s" => { name => 'critical_container_status', default => '%{status} !~ /Connecting|Connected/i || %{error} !~ /none/i' },
"use-name" => { name => 'use_name' },
"warning-container-status:s" => { name => 'warning_container_status', default => '' },
"critical-container-status:s" => { name => 'critical_container_status', default => '' },
});
$self->{statefile_cache_containers} = centreon::plugins::statefile->new(%options);
@ -144,6 +237,12 @@ sub check_options {
$self->{statefile_cache_containers}->check_options(%options);
}
sub prefix_containers_traffic_output {
my ($self, %options) = @_;
return "Container '" . $options{instance_value}->{display} . "' ";
}
sub prefix_containers_output {
my ($self, %options) = @_;
@ -164,26 +263,43 @@ sub manage_selection {
my ($self, %options) = @_;
$self->{containers} = {};
my $result = $options{custom}->api_get_containers(container_id => $self->{option_results}->{container_id}, statefile => $self->{statefile_cache_containers});
use Data::Dumper;
print Data::Dumper::Dumper($result);
exit(1);
$self->{containers_traffic} = {};
my $result = $options{custom}->api_get_containers(container_id => $self->{option_results}->{container_id},
container_name => $self->{option_results}->{container_name}, statefile => $self->{statefile_cache_containers});
foreach my $entry (@{$result->{outputs}}) {
my $name = $entry->{name} . '/' . $entry->{requested_stream_id};
foreach my $container_id (keys %{$result}) {
next if (!defined($result->{$container_id}->{Stats}));
my $name = $result->{$container_id}->{Name};
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$name !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
next;
}
$self->{output_stream}->{$entry->{id}} = {
display => $name,
status => $entry->{status},
traffic_in => $entry->{stats}->{net_recv}->{bytes} * 8,
traffic_out => $entry->{stats}->{net_send}->{bytes} * 8,
dropped_in => $entry->{stats}->{net_recv}->{dropped},
my $read_io = $result->{$container_id}->{Stats}->{blkio_stats}->{io_service_bytes_recursive}->[0]->{value};
my $write_io = $result->{$container_id}->{Stats}->{blkio_stats}->{io_service_bytes_recursive}->[1]->{value};
$self->{containers}->{$container_id} = {
display => defined($self->{option_results}->{use_name}) ? $name : $container_id,
name => $name,
state => $result->{$container_id}->{State},
read_io => $read_io,
write_io => $write_io,
cpu_total_usage => $result->{$container_id}->{Stats}->{cpu_stats}->{cpu_usage}->{total_usage},
cpu_system_usage => $result->{$container_id}->{Stats}->{cpu_stats}->{system_cpu_usage},
cpu_number => scalar(@{$result->{$container_id}->{Stats}->{cpu_stats}->{cpu_usage}->{percpu_usage}}),
memory_usage => $result->{$container_id}->{Stats}->{memory_stats}->{usage},
memory_total => $result->{$container_id}->{Stats}->{memory_stats}->{limit},
};
foreach my $interface (keys %{$result->{$container_id}->{Stats}->{networks}}) {
my $name = defined($self->{option_results}->{use_name}) ? $name : $container_id;
$name .= '.' . $interface;
$self->{containers_traffic}->{$name} = {
display => $name,
traffic_in => $result->{$container_id}->{Stats}->{networks}->{$interface}->{rx_bytes} * 8,
traffic_out => $result->{$container_id}->{Stats}->{networks}->{$interface}->{tx_bytes} * 8,
};
}
}
if (scalar(keys %{$self->{containers}}) <= 0) {
@ -191,9 +307,12 @@ sub manage_selection {
$self->{output}->option_exit();
}
$self->{cache_name} = "docker_" . $self->{mode} . '_' . $options{custom}->{hostname} . '_' . $options{custom}->{port} . '_' .
my $hostnames = $options{custom}->get_hostnames();
$self->{cache_name} = "docker_" . $self->{mode} . '_' . join('_', @$hostnames) . '_' . $options{custom}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{container_id}) ? md5_hex($self->{option_results}->{container_id}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{container_name}) ? md5_hex($self->{option_results}->{container_name}) : md5_hex('all'));
}
1;
@ -210,6 +329,14 @@ Check container usage.
Exact container ID.
=item B<--container-name>
Exact container name (if multiple names: names separated by ':').
=item B<--use-name>
Use docker name for perfdata and display.
=item B<--filter-name>
Filter by container name (can be a regexp).
@ -222,24 +349,24 @@ Example: --filter-counters='^container-status$'
=item B<--warning-*>
Threshold warning.
Can be: 'traffic-in', 'traffic-out', 'dropped-in'.
Can be: 'read-iops', 'write-iops', 'traffic-in', 'traffic-out',
'cpu' (%), 'memory' (%).
=item B<--critical-*>
Threshold critical.
Can be: 'traffic-in', 'traffic-out', 'dropped-in'.
Can be: 'read-iops', 'write-iops', 'traffic-in', 'traffic-out',
'cpu' (%), 'memory' (%).
=item B<--warning-container-status>
Set warning threshold for status (Default: -)
Can used special variables like: %{id}, %{name}, %{status}.
Can used special variables like: %{name}, %{state}.
=item B<--critical-container-status>
Set critical threshold for status (Default: '%{status} !~ /Connecting|Connected/i').
Can used special variables like: %{id}, %{name}, %{status}.
Set critical threshold for status (Default: -).
Can used special variables like: %{name}, %{state}.
=back

View File

@ -0,0 +1,100 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::docker::restapi::mode::listcontainers;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{containers} = $options{custom}->api_list_containers();
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $container_id (sort keys %{$self->{containers}}) {
$self->{output}->output_add(long_msg => '[id = ' . $container_id . "] [name = '" . $self->{containers}->{$container_id}->{Name} . "']" .
" [node = '" . $self->{containers}->{$container_id}->{NodeName} . "']" .
" [state = '" . $self->{containers}->{$container_id}->{State} . "']"
);
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List containers:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['id', 'name', 'node', 'state']);
}
sub disco_show {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $container_id (sort keys %{$self->{containers}}) {
$self->{output}->add_disco_entry(name => $self->{containers}->{$container_id}->{Name},
node => $self->{containers}->{$container_id}->{NodeName},
state => $self->{containers}->{$container_id}->{State},
id => $container_id,
);
}
}
1;
__END__
=head1 MODE
List containers.
=over 8
=back
=cut

View File

@ -0,0 +1,221 @@
#
# Copyright 2017 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package cloud::docker::restapi::mode::nodestatus;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
my $instance_mode;
sub custom_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_node_status}) && $instance_mode->{option_results}->{critical_node_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_node_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_node_status}) && $instance_mode->{option_results}->{warning_node_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_node_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status} . ' [manager status: ' . $self->{result_values}->{manager_status} . ']';
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{manager_status} = $options{new_datas}->{$self->{instance} . '_manager_status'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All node informations are ok', skipped_code => { -11 => 1 } },
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All node status are ok', skipped_code => { -11 => 1 } },
];
$self->{maps_counters}->{nodes} = [
{ label => 'node-status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'manager_status' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
];
$self->{maps_counters}->{node} = [
{ label => 'containers-running', set => {
key_values => [ { name => 'containers_running' }, { name => 'display' } ],
output_template => 'Containers Running : %s',
perfdatas => [
{ label => 'containers_running', value => 'containers_running_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'containers-stopped', set => {
key_values => [ { name => 'containers_stopped' }, { name => 'display' } ],
output_template => 'Containers Stopped : %s',
perfdatas => [
{ label => 'containers_stopped', value => 'containers_stopped_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'containers-running', set => {
key_values => [ { name => 'containers_paused' }, { name => 'display' } ],
output_template => 'Containers Paused : %s',
perfdatas => [
{ label => 'containers_paused', value => 'containers_paused_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning-node-status:s" => { name => 'warning_node_status', default => '' },
"critical-node-status:s" => { name => 'critical_node_status', default => '%{status} !~ /ready/ || %{manager_status} !~ /reachable|-/' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
}
sub prefix_node_output {
my ($self, %options) = @_;
return "Node '" . $options{instance_value}->{display} . "' ";
}
sub change_macros {
my ($self, %options) = @_;
foreach (('warning_node_status', 'critical_node_status')) {
if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
}
}
}
sub manage_selection {
my ($self, %options) = @_;
$self->{node} = {};
$self->{nodes} = {};
my $result = $options{custom}->api_list_nodes();
foreach my $node_name (keys %{$result}) {
$self->{node}->{$node_name} = {
display => $node_name,
containers_running => $result->{$node_name}->{containers_running},
containers_stopped => $result->{$node_name}->{containers_stopped},
containers_paused => $result->{$node_name}->{containers_paused},
};
foreach my $entry (@{$result->{$node_name}->{nodes}}) {
my $name = $node_name . '/' . $entry->{Addr};
$self->{nodes}->{$name} = {
display => $name ,
status => $entry->{Status},
manager_status => defined($entry->{ManagerStatus}) ? $entry->{ManagerStatus} : '-',
};
}
}
if (scalar(keys %{$self->{node}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No node found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check node status.
=over 8
=item B<--warning-node-status>
Set warning threshold for status (Default: -)
Can used special variables like: %{display}, %{status}, %{manager_status}.
=item B<--critical-node-status>
Set critical threshold for status (Default: '%{status} !~ /ready/ || %{manager_status} !~ /reachable|-/').
Can used special variables like: %{display}, %{status}, %{manager_status}.
=item B<--warning-*>
Threshold warning.
Can be: 'containers-running', 'containers-paused', 'containers-stopped'.
=item B<--critical-*>
Threshold critical.
Can be: 'containers-running', 'containers-paused', 'containers-stopped'.,
=back
=cut

View File

@ -32,6 +32,7 @@ sub new {
$self->{version} = '0.3';
%{$self->{modes}} = (
'container-usage' => 'cloud::docker::restapi::mode::containerusage',
'list-containers' => 'cloud::docker::restapi::mode::listcontainers',
'node-status' => 'cloud::docker::restapi::mode::nodestatus',
);

View File

@ -0,0 +1,37 @@
# HOWTO Centos
Install dependencies:
# yum install perl-devel 'perl(ExtUtils::Embed)'
Compile the wrapper:
# gcc -o cwrapper_perl cwrapper_perl.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
Create a fatpack: https://github.com/centreon/centreon-plugins/blob/master/docs/en/user/guide.rst#can-i-have-one-standalone-perl-file-
Comment following lines in the end of fatpack file:
use strict;
use warnings;
# Not perl embedded compliant at all
#use FindBin;
#use lib "$FindBin::Bin";
# use lib '/usr/lib/nagios/plugins/';
use centreon::plugins::script;
centreon::plugins::script->new()->run();
Set setuid right:
# chown root:root cwrapper_perl
# chmod 4775 cwrapper_perl
Test it:
$ cwrapper_perl centreon_protocol_udp.pl --plugin --mode=connection --hostname=10.30.2.65 --port=161

View File

@ -0,0 +1,29 @@
#include <EXTERN.h>
#include <perl.h>
static PerlInterpreter *my_perl;
static void xs_init (pTHX);
EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
EXTERN_C void xs_init(pTHX)
{
char *file = __FILE__;
/* DynaLoader is a special case */
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
}
int main (int argc, char **argv, char **env)
{
int exitstatus = 0;
PERL_SYS_INIT3(&argc, &argv, &env);
my_perl = perl_alloc();
perl_construct(my_perl);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
perl_parse(my_perl, xs_init, argc, argv, (char **)NULL);
exitstatus = perl_run(my_perl);
perl_destruct(my_perl);
perl_free(my_perl);
PERL_SYS_TERM();
exit(exitstatus);
}

View File

@ -127,9 +127,9 @@ Threshold warning (number of long queries).
Threshold critical (number of long queries).
=item B<--critical>
=item B<--seconds>
Threshold critical (number of long queries).
Filter queries over X seconds (Default: 60).
=item B<--filter-user>

View File

@ -20,56 +20,61 @@
package database::firebird::mode::memory;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::values;
my $maps_counters = {
global => {
'000_used' => { set => {
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output' }
];
$self->{maps_counters}->{global} = [
{ label => 'used', set => {
key_values => [ { name => 'database_used' }, { name => 'database_allocated' } ],
closure_custom_calc => \&custom_unit_calc, closure_custom_calc_extra_options => { label_ref => 'database' },
closure_custom_output => \&custom_used_output,
closure_custom_calc => $self->can('custom_unit_calc'), closure_custom_calc_extra_options => { label_ref => 'database' },
closure_custom_output => $self->can('custom_used_output'),
threshold_use => 'prct',
closure_custom_perfdata => \&custom_used_perfdata,
closure_custom_perfdata => $self->can('custom_used_perfdata'),
}
},
'001_attachment' => { set => {
{ label => 'attachment', set => {
key_values => [ { name => 'attachment_used' }, { name => 'database_allocated' } ],
closure_custom_calc => \&custom_unit_calc, closure_custom_calc_extra_options => { label_ref => 'attachment' },
closure_custom_output => \&custom_unit_output,
closure_custom_calc => $self->can('custom_unit_calc'), closure_custom_calc_extra_options => { label_ref => 'attachment' },
closure_custom_output => $self->can('custom_unit_output'),
threshold_use => 'prct',
closure_custom_perfdata => \&custom_unit_perfdata,
closure_custom_perfdata => $self->can('custom_unit_perfdata'),
}
},
'002_transaction' => { set => {
{ label => 'transaction', set => {
key_values => [ { name => 'transaction_used' }, { name => 'database_allocated' } ],
closure_custom_calc => \&custom_unit_calc, closure_custom_calc_extra_options => { label_ref => 'transaction' },
closure_custom_output => \&custom_unit_output,
closure_custom_calc => $self->can('custom_unit_calc'), closure_custom_calc_extra_options => { label_ref => 'transaction' },
closure_custom_output => $self->can('custom_unit_output'),
threshold_use => 'prct',
closure_custom_perfdata => \&custom_unit_perfdata,
closure_custom_perfdata => $self->can('custom_unit_perfdata'),
}
},
'003_statement' => { set => {
{ label => 'statement', set => {
key_values => [ { name => 'statement_used' }, { name => 'database_allocated' } ],
closure_custom_calc => \&custom_unit_calc, closure_custom_calc_extra_options => { label_ref => 'statement' },
closure_custom_output => \&custom_unit_output,
closure_custom_calc => $self->can('custom_unit_calc'), closure_custom_calc_extra_options => { label_ref => 'statement' },
closure_custom_output => $self->can('custom_unit_output'),
threshold_use => 'prct',
closure_custom_perfdata => \&custom_unit_perfdata,
closure_custom_perfdata => $self->can('custom_unit_perfdata'),
}
},
'004_call' => { set => {
{ label => 'call', set => {
key_values => [ { name => 'call_used' }, { name => 'database_allocated' } ],
closure_custom_calc => \&custom_unit_calc, closure_custom_calc_extra_options => { label_ref => 'call' },
closure_custom_output => \&custom_unit_output,
closure_custom_calc => $self->can('custom_unit_calc'), closure_custom_calc_extra_options => { label_ref => 'call' },
closure_custom_output => $self->can('custom_unit_output'),
threshold_use => 'prct',
closure_custom_perfdata => \&custom_unit_perfdata,
closure_custom_perfdata => $self->can('custom_unit_perfdata'),
}
},
},
};
];
}
sub custom_used_output {
my ($self, %options) = @_;
@ -130,6 +135,12 @@ sub custom_unit_calc {
return 0;
}
sub prefix_output {
my ($self, %options) = @_;
return "Memory ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -140,101 +151,25 @@ sub new {
{
});
foreach my $key (('global')) {
foreach (keys %{$maps_counters->{$key}}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output},
perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
}
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach my $key (('global')) {
foreach (keys %{$maps_counters->{$key}}) {
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
}
sub run {
my ($self, %options) = @_;
$self->{sql} = $options{sql};
$self->manage_selection();
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters->{global}}) {
my $obj = $maps_counters->{global}->{$_}->{obj};
$obj->set(instance => 'firebird');
my ($value_check) = $obj->execute(values => $self->{firebird});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$obj->perfdata();
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "Memory $short_msg"
);
} else {
$self->{output}->output_add(short_msg => "Memory $long_msg");
}
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection {
my ($self, %options) = @_;
$self->{sql}->connect();
$self->{sql}->query(query => q{SELECT MON$STAT_GROUP as MYGROUP, MON$MEMORY_ALLOCATED AS MYTOTAL, MON$MEMORY_USED AS MYUSED FROM MON$MEMORY_USAGE});
$options{sql}->connect();
$options{sql}->query(query => q{SELECT MON$STAT_GROUP as MYGROUP, MON$MEMORY_ALLOCATED AS MYTOTAL, MON$MEMORY_USED AS MYUSED FROM MON$MEMORY_USAGE});
my %map_group = (0 => 'database', 1 => 'attachment', 2 => 'transaction', 3 => 'statement', 4 => 'call');
$self->{firebird} = {};
while ((my $row = $self->{sql}->fetchrow_hashref())) {
$self->{global} = {};
while ((my $row = $options{sql}->fetchrow_hashref())) {
if (!defined($self->{firebird}->{$map_group{$row->{MYGROUP}} . '_used'})) {
$self->{firebird}->{$map_group{$row->{MYGROUP}} . '_used'} = 0;
$self->{firebird}->{$map_group{$row->{MYGROUP}} . '_allocated'} = 0;
$self->{global}->{$map_group{$row->{MYGROUP}} . '_used'} = 0;
$self->{global}->{$map_group{$row->{MYGROUP}} . '_allocated'} = 0;
}
$self->{firebird}->{$map_group{$row->{MYGROUP}} . '_used'} += $row->{MYUSED};
$self->{firebird}->{$map_group{$row->{MYGROUP}} . '_allocated'} += $row->{MYTOTAL};
$self->{global}->{$map_group{$row->{MYGROUP}} . '_used'} += $row->{MYUSED};
$self->{global}->{$map_group{$row->{MYGROUP}} . '_allocated'} += $row->{MYTOTAL};
}
}

Some files were not shown because too many files have changed in this diff Show More