add(plugin): as400 connector (#3202)

This commit is contained in:
qgarnier 2021-10-20 10:17:41 +02:00 committed by GitHub
parent 510047b2b4
commit 222f436315
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 1939 additions and 0 deletions

View File

@ -0,0 +1,249 @@
#
# Copyright 2021 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 os::as400::connector::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 => {
'connector-api-username:s' => { name => 'connector_api_username' },
'connector-api-password:s' => { name => 'connector_api_password' },
'connector-hostname:s' => { name => 'connector_hostname' },
'connector-port:s' => { name => 'connector_port' },
'connector-proto:s' => { name => 'connector_proto' },
'connector-timeout:s' => { name => 'connector_timeout' },
'unknown-http-status:s' => { name => 'unknown_http_status' },
'warning-http-status:s' => { name => 'warning_http_status' },
'critical-http-status:s' => { name => 'critical_http_status' },
'as400-hostname:s' => { name => 'as400_hostname' },
'as400-username:s' => { name => 'as400_username' },
'as400-password:s' => { name => 'as400_password' }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{http} = centreon::plugins::http->new(%options);
return $self;
}
sub set_options {
my ($self, %options) = @_;
$self->{option_results} = $options{option_results};
}
sub set_defaults {}
sub check_options {
my ($self, %options) = @_;
$self->{connector_hostname} = (defined($self->{option_results}->{connector_hostname})) ? $self->{option_results}->{connector_hostname} : '127.0.0.1';
$self->{connector_port} = (defined($self->{option_results}->{connector_port})) ? $self->{option_results}->{connector_port} : 8091;
$self->{connector_proto} = (defined($self->{option_results}->{connector_proto})) ? $self->{option_results}->{connector_proto} : 'http';
$self->{connector_timeout} = (defined($self->{option_results}->{connector_timeout})) ? $self->{option_results}->{connector_timeout} : 50;
$self->{connector_api_username} = (defined($self->{option_results}->{connector_api_username})) ? $self->{option_results}->{connector_api_username} : '';
$self->{connector_api_password} = (defined($self->{option_results}->{connector_api_password})) ? $self->{option_results}->{connector_api_password} : '';
$self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '%{http_code} < 200 or %{http_code} >= 300';
$self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_http_status} : '';
$self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_http_status} : '';
$self->{as400_hostname} = (defined($self->{option_results}->{as400_hostname})) ? $self->{option_results}->{as400_hostname} : '';
$self->{as400_username} = (defined($self->{option_results}->{as400_username})) ? $self->{option_results}->{as400_username} : '';
$self->{as400_password} = (defined($self->{option_results}->{as400_password})) ? $self->{option_results}->{as400_password} : '';
if ($self->{connector_hostname} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --connector-hostname option.");
$self->{output}->option_exit();
}
if ($self->{connector_api_username} ne '' && $self->{connector_api_password} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --connector-api-password option.");
$self->{output}->option_exit();
}
if ($self->{as400_hostname} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --as400-hostname option.");
$self->{output}->option_exit();
}
if ($self->{as400_username} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --as400-username option.");
$self->{output}->option_exit();
}
if ($self->{as400_password} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --as400-password option.");
$self->{output}->option_exit();
}
return 0;
}
sub build_options_for_httplib {
my ($self, %options) = @_;
$self->{option_results}->{hostname} = $self->{connector_hostname};
$self->{option_results}->{timeout} = $self->{connector_timeout};
$self->{option_results}->{port} = $self->{connector_port};
$self->{option_results}->{proto} = $self->{connector_proto};
$self->{option_results}->{timeout} = $self->{connector_timeout};
if ($self->{connector_api_username} ne '') {
$self->{option_results}->{credentials} = 1;
$self->{option_results}->{basic} = 1;
$self->{option_results}->{username} = $self->{connector_api_username};
$self->{option_results}->{password} = $self->{connector_api_password};
}
}
sub settings {
my ($self, %options) = @_;
return if (defined($self->{settings_done}));
$self->build_options_for_httplib();
$self->{http}->add_header(key => 'Content-Type', value => 'application/json');
$self->{http}->add_header(key => 'Accept', value => 'application/json');
$self->{http}->set_options(%{$self->{option_results}});
$self->{settings_done} = 1;
}
sub get_hostname {
my ($self, %options) = @_;
return $self->{as400_hostname};
}
sub request_api {
my ($self, %options) = @_;
my $post = {
host => $self->{as400_hostname},
login => $self->{as400_username},
password => $self->{as400_password},
command => $options{command}
};
$post->{args} = $options{args} if (defined($options{args}));
my $encoded;
eval {
$encoded = encode_json($post);
};
$self->settings();
my $content = $self->{http}->request(
method => 'POST',
query_form_post => $encoded,
url_path => '/',
unknown_status => $self->{unknown_http_status},
warning_status => $self->{warning_http_status},
critical_status => $self->{critical_http_status}
);
if (!defined($content) || $content eq '') {
$self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']");
$self->{output}->option_exit();
}
my $decoded;
eval {
$decoded = JSON::XS->new->decode($self->{output}->decode($content));
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)");
$self->{output}->option_exit();
}
if (defined($decoded->{code}) && $decoded->{code} != 0) {
$self->{output}->add_option_msg(short_msg => $decoded->{message});
$self->{output}->option_exit();
}
return $decoded;
}
1;
__END__
=head1 NAME
Centreon AS400 connector Rest API
=head1 REST API OPTIONS
Centreon AS400 connector Rest API
=over 8
=item B<--connector-hostname>
Centreon connector hostname (Default: 127.0.0.1)
=item B<--connector-port>
Port used (Default: 8091)
=item B<--connector-proto>
Specify https if needed (Default: 'http')
=item B<--connector-username>
API username.
=item B<--connector-password>
API password.
=item B<--connector-timeout>
Set timeout in seconds (Default: 50)
=item B<--as400-hostname>
AS/400 hostname (Required)
=item B<--as400-username>
AS/400 username (Required)
=item B<--as400-password>
AS/400 password (Required)
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,133 @@
#
# Copyright 2021 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 os::as400::connector::mode::command;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
"command '%s' status: %s",
$self->{result_values}->{command_name},
$self->{result_values}->{status}
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', cb_prefix_output => 'prefix_global_output', type => 0, skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
{
label => 'status',
type => 2,
critical_default => '%{status} =~ /failed/i',
set => {
key_values => [ { name => 'status' }, { name => 'command_name' } ],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'command-name:s' => { name => 'command_name' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{command_name}) || $self->{option_results}->{command_name} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --command-name option');
$self->{output}->option_exit();
}
}
sub manage_selection {
my ($self, %options) = @_;
my $infos = $options{custom}->request_api(command => 'executeCommand', args => { cmdName => $self->{option_results}->{command_name} });
$self->{global} = {
status => $infos->{result}->[0]->{status},
command_name => $self->{option_results}->{command_name}
};
if (defined($infos->{result}->[0]->{output}) && $infos->{result}->[0]->{output} ne '') {
$self->{output}->output_add(
long_msg => sprintf(
'command output: %s',
$infos->{result}->[0]->{output}
)
);
}
}
1;
__END__
=head1 MODE
Execute command and check result.
=over 8
=item B<--command-name>
Specify the command to execute (Required).
=item B<--unknown-status>
Set unknown threshold for status.
Can used special variables like: %{status}, %{name}
=item B<--warning--status>
Set warning threshold for status.
Can used special variables like: %{status}, %{name}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /failed/i').
Can used special variables like: %{status}, %{name}
=back
=cut

View File

@ -0,0 +1,264 @@
#
# Copyright 2021 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 os::as400::connector::mode::disks;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
'status: %s',
$self->{result_values}->{status}
);
}
sub custom_space_usage_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space});
return sprintf(
'space usage 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_space},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space}
);
}
sub prefix_disk_output {
my ($self, %options) = @_;
return "Disk '" . $options{instance_value}->{name} . "' ";
}
sub prefix_global_output {
my ($self, %options) = @_;
return 'Disks ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', cb_prefix_output => 'prefix_global_output', type => 0, skipped_code => { -10 => 1 } },
{ name => 'disks', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All disks are ok' }
];
$self->{maps_counters}->{global} = [
{ label => 'disks-total', nlabel => 'disks.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => 'total: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
},
{ label => 'disks-active', nlabel => 'disks.active.count', set => {
key_values => [ { name => 'active' }, { name => 'total' } ],
output_template => 'active: %s',
perfdatas => [
{ template => '%s', min => 0, max => 'total' }
]
}
},
{ label => 'disks-errors', nlabel => 'disks.errors.count', set => {
key_values => [ { name => 'errors' }, { name => 'total' } ],
output_template => 'errors: %s',
perfdatas => [
{ template => '%s', min => 0, max => 'total' }
]
}
},
{ label => 'disks-gap-repartition', nlabel => 'disks.gap.repartition.percentage', set => {
key_values => [ { name => 'gap' } ],
output_template => 'gap repartition between min/max: %.2f %%',
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%' }
]
}
},
];
$self->{maps_counters}->{disks} = [
{
label => 'status',
type => 2,
unknown_default => '%{status} =~ /unknown/i',
warning_default => '%{status} =~ /noReady|busy|hwFailureOk|hwFailurePerf|Protected|rebuilding/i',
critical_default => '%{status} =~ /^(noAccess|otherDiskSubFailed|failed|notOperational|noUnitControl)$/i',
set => {
key_values => [ { name => 'status' }, { name => 'name' } ],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'space-usage', nlabel => 'disk.space.usage.bytes', set => {
key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' } ],
closure_custom_output => $self->can('custom_space_usage_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 }
]
}
},
{ label => 'space-usage-free', nlabel => 'disk.space.free.bytes', display_ok => 0, set => {
key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' } ],
closure_custom_output => $self->can('custom_space_usage_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 }
]
}
},
{ label => 'space-usage-prct', nlabel => 'disk.space.usage.percentage', display_ok => 0, set => {
key_values => [ { name => 'prct_used_space' }, { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_free_space' }, { name => 'total_space' } ],
closure_custom_output => $self->can('custom_space_usage_output'),
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
]
}
},
{ label => 'reserved', nlabel => 'disk.space.reserved.bytes', set => {
key_values => [ { name => 'reserved_space' }, { name => 'total_space' } ],
output_template => 'reserved: %s %s',
output_change_bytes => 1,
perfdatas => [
{ template => '%s', unit => 'B', min => 0, max => 'total_space', label_extra_instance => 1 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'disk-name:s' => { name => 'disk_name' },
'filter-disk-name:s' => { name => 'filter_disk_name' }
});
return $self;
}
my $map_disk_status = {
0 => 'noUnitControl', 1 => 'active', 2 => 'failed',
3 => 'otherDiskSubFailed', 4 => 'hwFailurePerf', 5 => 'hwFailureOk',
6 => 'rebuilding', 7 => 'noReady', 8 => 'writeProtected', 9 => 'busy',
10 => 'notOperational', 11 => 'unknownStatus', 12 => 'noAccess',
13 => 'rwProtected'
};
sub manage_selection {
my ($self, %options) = @_;
my %cmd = (command => 'listDisks');
if (defined($self->{option_results}->{disk_name}) && $self->{option_results}->{disk_name} ne '') {
$cmd{args} = { diskName => $self->{option_results}->{disk_name} };
}
my $disks = $options{custom}->request_api(%cmd);
$self->{global} = { total => 0, active => 0, errors => 0 };
$self->{disks} = {};
my ($max, $min) = (0, 100);
foreach my $disk (@{$disks->{result}}) {
if (defined($self->{option_results}->{filter_disk_name}) && $self->{option_results}->{filter_disk_name} ne '' &&
$disk->{name} !~ /$self->{option_results}->{filter_disk_name}/) {
$self->{output}->output_add(long_msg => "skipping disk '" . $disk->{name} . "': no matching filter.", debug => 1);
next;
}
$self->{disks}->{ $disk->{name} } = {
name => $disk->{name},
status => $map_disk_status->{ $disk->{status} },
used_space => $disk->{totalSpace} - $disk->{freeSpace} - $disk->{reservedSpace},
total_space => $disk->{totalSpace},
reserved_space => $disk->{reservedSpace}
};
$self->{disks}->{ $disk->{name} }->{free_space} = $disk->{totalSpace} - $self->{disks}->{ $disk->{name} }->{used_space};
$self->{disks}->{ $disk->{name} }->{prct_used_space} = $self->{disks}->{ $disk->{name} }->{used_space} * 100 / $disk->{totalSpace};
$self->{disks}->{ $disk->{name} }->{prct_free_space} = 100 - $self->{disks}->{ $disk->{name} }->{prct_used_space};
$max = $self->{disks}->{ $disk->{name} }->{prct_used_space} if ($self->{disks}->{ $disk->{name} }->{prct_used_space} > $max);
$min = $self->{disks}->{ $disk->{name} }->{prct_used_space} if ($self->{disks}->{ $disk->{name} }->{prct_used_space} < $min);
if ($self->{disks}->{ $disk->{name} }->{status} eq 'active') {
$self->{global}->{active}++;
} else {
$self->{global}->{errors}++;
}
$self->{global}->{total}++;
}
if ($self->{global}->{total} > 1) {
$self->{global}->{gap} = $max - $min;
};
}
1;
__END__
=head1 MODE
Check disks.
=over 8
=item B<--disk-name>
Check exact disk.
=item B<--filter-disk-name>
Filter disks by name (can be a regexp).
=item B<--unknown-status>
Set unknown threshold for status (Default: '%{status} =~ /unknown/i').
Can used special variables like: %{status}, %{name}
=item B<--warning--status>
Set warning threshold for status (Default: '%{status} =~ /noReady|busy|hwFailureOk|hwFailurePerf|Protected|rebuilding/i').
Can used special variables like: %{status}, %{name}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /^(noAccess|otherDiskSubFailed|failed|notOperational|noUnitControl)$/i').
Can used special variables like: %{status}, %{name}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'space-usage', 'space-usage-free', 'space-usage-prct', 'reserved',
'disks-total', 'disks-active', 'disks-errors', 'disks-gap-repartition'.
=back
=cut

View File

@ -0,0 +1,229 @@
#
# Copyright 2021 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 os::as400::connector::mode::jobqueues;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
'status: %s',
$self->{result_values}->{status}
);
}
sub custom_jobs_active_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
instances => [$self->{result_values}->{library}, $self->{result_values}->{name}],
value => $self->{result_values}->{activeJob},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0
);
}
sub custom_jobs_scheduled_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
instances => [$self->{result_values}->{library}, $self->{result_values}->{name}],
value => $self->{result_values}->{scheduledJobOnQueue},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0
);
}
sub custom_jobs_held_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
instances => [$self->{result_values}->{library}, $self->{result_values}->{name}],
value => $self->{result_values}->{heldJobOnQueue},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0
);
}
sub prefix_jobq_output {
my ($self, %options) = @_;
return sprintf(
"Job queue '%s' [library: %s] ",
$options{instance_value}->{name},
$options{instance_value}->{library}
);
}
sub prefix_global_output {
my ($self, %options) = @_;
return 'Job queues ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', cb_prefix_output => 'prefix_global_output', type => 0, skipped_code => { -10 => 1 } },
{ name => 'jobq', type => 1, cb_prefix_output => 'prefix_jobq_output', message_multiple => 'All job queues are ok' }
];
$self->{maps_counters}->{global} = [
{ label => 'jobqueues-total', nlabel => 'jobqueues.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => 'total: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{jobq} = [
{
label => 'status',
type => 2,
critical_default => '%{status} =~ /HELD/i',
set => {
key_values => [ { name => 'status' }, { name => 'name' }, { name => 'library' } ],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'jobqueue-jobs-active', nlabel => 'jobqueue.jobs.active.count', set => {
key_values => [ { name => 'activeJob' }, { name => 'name' }, { name => 'library' } ],
output_template => 'active jobs: %s',
closure_custom_perfdata => $self->can('custom_jobs_active_perfdata')
}
},
{ label => 'jobqueue-jobs-scheduled', nlabel => 'jobqueue.jobs.scheduled.count', set => {
key_values => [ { name => 'scheduledJobOnQueue' }, { name => 'name' }, { name => 'library' } ],
output_template => 'scheduled jobs: %s',
closure_custom_perfdata => $self->can('custom_jobs_scheduled_perfdata')
}
},
{ label => 'jobqueue-jobs-held', nlabel => 'jobqueue.jobs.held.count', set => {
key_values => [ { name => 'heldJobOnQueue' }, { name => 'name' }, { name => 'library' } ],
output_template => 'held jobs: %s',
closure_custom_perfdata => $self->can('custom_jobs_held_perfdata')
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'jobq:s@' => { name => 'jobq' }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my %cmd = (command => 'getJobQueues', args => { queues => [] });
if (defined($self->{option_results}->{jobq})) {
foreach (@{$self->{option_results}->{jobq}}) {
my ($library, $name) = split(/:/);
if (defined($library) && $library ne '' && defined($name) && $name ne '') {
push @{$cmd{args}->{queues}}, { name => $name, library => $library };
}
}
}
if (scalar(@{$cmd{args}->{queues}}) == 0) {
$self->{output}->add_option_msg(short_msg => 'Need to specify --jobq option');
$self->{output}->option_exit();
}
my $entries = $options{custom}->request_api(%cmd);
$self->{global} = { total => 0 };
$self->{jobq} = {};
foreach my $entry (@{$entries->{result}}) {
$self->{jobq}->{ $entry->{name} . ':' . $entry->{library} } = {
name => $entry->{name},
library => $entry->{library},
status => $entry->{status},
activeJob => $entry->{activeJob},
scheduledJobOnQueue => $entry->{scheduledJobOnQueue},
heldJobOnQueue => $entry->{heldJobOnQueue}
};
$self->{global}->{total}++;
}
}
1;
__END__
=head1 MODE
Check job queues.
=over 8
=item B<--jobq>
JOBQ selection. Eg: --jobq="QBASE:QGPL" --jobq="QBASE:QPGMR"
=item B<--unknown-status>
Set unknown threshold for status.
Can used special variables like: %{status}, %{name}, %{library}
=item B<--warning--status>
Set warning threshold for status.
Can used special variables like: %{status}, %{name}, %{library}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /HELD/i').
Can used special variables like: %{status}, %{name}, %{library}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'jobqueues-total', 'jobqueue-jobs-active',
'jobqueue-jobs-scheduled', 'jobqueue-jobs-held'.
=back
=cut

View File

@ -0,0 +1,123 @@
#
# Copyright 2021 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 os::as400::connector::mode::jobs;
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, skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
{ label => 'jobs-total', nlabel => 'jobs.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => 'number of jobs: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'filter-subsystem:s' => { name => 'filter_subsystem' },
'display-jobs' => { name => 'display_jobs' }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $jobs = $options{custom}->request_api(command => 'listJobs');
$self->{global} = { total => 0 };
foreach my $entry (@{$jobs->{result}}) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$entry->{name} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping job '" . $entry->{name} . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_subsystem}) && $self->{option_results}->{filter_subsystem} ne '' &&
$entry->{subSystem} !~ /$self->{option_results}->{filter_subsystem}/) {
$self->{output}->output_add(long_msg => "skipping job '" . $entry->{name} . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{display_jobs})) {
$self->{output}->output_add(
long_msg => sprintf(
'job %s [subsystem: %s] [active status: %s]',
$entry->{name},
$entry->{subSystem},
$entry->{activeStatus}
)
);
}
$self->{global}->{total}++;
}
}
1;
__END__
=head1 MODE
Check active jobs.
=over 8
=item B<--filter-name>
Filter jobs by name (can be a regexp).
=item B<--filter-subsystem>
Filter jobs by subsystem (can be a regexp).
=item B<--display-jobs>
Display jobs in verbose output.
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'jobs-total'.
=back
=cut

View File

@ -0,0 +1,110 @@
#
# Copyright 2021 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 os::as400::connector::mode::listdisks;
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;
$options{options}->add_options(arguments => {
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
return $options{custom}->request_api(command => 'listDisks');
}
my $map_disk_status = {
0 => 'noUnitControl', 1 => 'active', 2 => 'failed',
3 => 'otherDiskSubFailed', 4 => 'hwFailurePerf', 5 => 'hwFailureOk',
6 => 'rebuilding', 7 => 'noReady', 8 => 'writeProtected', 9 => 'busy',
10 => 'notOperational', 11 => 'unknownStatus', 12 => 'noAccess',
13 => 'rwProtected'
};
sub run {
my ($self, %options) = @_;
my $results = $self->manage_selection(%options);
foreach my $entry (@{$results->{result}}) {
$self->{output}->output_add(
long_msg => sprintf(
"[name: %s][status: %s]",
$entry->{name},
$map_disk_status->{ $entry->{status} }
)
);
}
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List disks:'
);
$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', 'status']);
}
sub disco_show {
my ($self, %options) = @_;
my $results = $self->manage_selection(%options);
foreach my $entry (@{$results->{result}}) {
$self->{output}->add_disco_entry(
name => $entry->{name},
status => $map_disk_status->{ $entry->{status} }
);
}
}
1;
__END__
=head1 MODE
List disks.
=over 8
=back
=cut

View File

@ -0,0 +1,112 @@
#
# Copyright 2021 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 os::as400::connector::mode::listsubsystems;
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;
$options{options}->add_options(arguments => {
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
return $options{custom}->request_api(command => 'listSubsystems');
}
my $map_subsys_status = {
'*ACTIVE' => 'active',
'*ENDING' => 'ending',
'*INACTIVE' => 'inactive',
'*RESTRICTED' => 'restricted',
'*STARTING' => 'starting'
};
sub run {
my ($self, %options) = @_;
my $results = $self->manage_selection(%options);
foreach my $entry (@{$results->{result}}) {
$self->{output}->output_add(
long_msg => sprintf(
"[name: %s][library: %s][status: %s]",
$entry->{name},
$entry->{library},
$map_subsys_status->{ $entry->{status} }
)
);
}
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List subsystems:'
);
$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', 'library', 'status']);
}
sub disco_show {
my ($self, %options) = @_;
my $results = $self->manage_selection(%options);
foreach my $entry (@{$results->{result}}) {
$self->{output}->add_disco_entry(
name => $entry->{name},
library => $entry->{library},
status => $map_subsys_status->{ $entry->{status} }
);
}
}
1;
__END__
=head1 MODE
List subsystems.
=over 8
=back
=cut

View File

@ -0,0 +1,166 @@
#
# Copyright 2021 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 os::as400::connector::mode::messagequeue;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub custom_jobs_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
instances => $self->{result_values}->{mq_path},
value => $self->{result_values}->{total},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
{ label => 'messages', nlabel => 'mq.messages.count', set => {
key_values => [ { name => 'total' }, { name => 'mq_path' } ],
output_template => 'number of messages: %s',
closure_custom_perfdata => $self->can('custom_jobs_perfdata')
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'message-queue-path:s' => { name => 'message_queue_path' },
'memory' => { name => 'memory' },
'filter-message-id:s' => { name => 'filter_message_id' },
'min-severity:s' => { name => 'min_severity' },
'max-severity:s' => { name => 'max_severity' },
'display-messages' => { name => 'display_messages' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{message_queue_path}) || $self->{option_results}->{message_queue_path} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify --message-queue-path option.');
$self->{output}->option_exit();
}
}
sub manage_selection {
my ($self, %options) = @_;
my %cmd = (command => 'getErrorMessageQueue', args => { messageQueuePath => $self->{option_results}->{message_queue_path} });
$cmd{args}->{messageIdfilterPattern} = $self->{option_results}->{filter_message_id}
if (defined($self->{option_results}->{filter_message_id}) && $self->{option_results}->{filter_message_id} ne '');
$cmd{args}->{minSeverityLevel} = $self->{option_results}->{min_severity}
if (defined($self->{option_results}->{min_severity}) && $self->{option_results}->{min_severity} ne '');
$cmd{args}->{maxSeverityLevel} = $self->{option_results}->{max_severity}
if (defined($self->{option_results}->{max_severity}) && $self->{option_results}->{max_severity} ne '');
$cmd{command} = 'getNewMessageInMessageQueue'
if (defined($self->{option_results}->{memory}));
$self->{global} = { total => 0, mq_path => $self->{option_results}->{message_queue_path} };
my $messages = $options{custom}->request_api(%cmd);
if (defined($self->{option_results}->{memory}) && defined($messages->{message})) {
$self->{output}->output_add(short_msg => $messages->{message});
$self->{output}->display();
$self->{output}->exit();
}
foreach my $entry (@{$messages->{result}}) {
if (defined($self->{option_results}->{display_messages})) {
$entry->{text} =~ s/\|/ /g;
$self->{output}->output_add(
long_msg => sprintf(
'message [id: %s] [severity: %s] [date: %s] [user: %s]: %s',
$entry->{id},
$entry->{severity},
scalar(localtime($entry->{date} / 1000)),
defined($entry->{user}) ? $entry->{user} : '-',
$entry->{text}
)
);
}
$self->{global}->{total}++;
}
}
1;
__END__
=head1 MODE
Check message queue.
=over 8
=item B<--message-queue-path>
Specify the message queue (Required. Eg: --message-queue-path='/QSYS.LIB/QSYSOPR.MSGQ').
=item B<--memory>
Check only new messages.
=item B<--filter-message-id>
Filter messages by id (can be a regexp).
=item B<--min-severity>
Filter messages with severity greater than or equal to X.
=item B<--max-severity>
Filter messages with severity less than to X.
=item B<--display-messages>
Display messages in verbose output.
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'total'.
=back
=cut

View File

@ -0,0 +1,105 @@
#
# Copyright 2021 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 os::as400::connector::mode::pagefaults;
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, skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
{ label => 'pagefaults-database', nlabel => 'pagefaults.database.ratio.percentage', set => {
key_values => [ { name => 'db_ratio' } ],
output_template => 'database page faults: %.2f %%',
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%' }
]
}
},
{ label => 'pagefaults-nondatabase', nlabel => 'pagefaults.nondatabase.ratio.percentage', set => {
key_values => [ { name => 'non_db_ratio' } ],
output_template => 'nondatabase page faults: %.2f %%',
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $pools = $options{custom}->request_api(command => 'pageFault');
my ($db_page_fault, $db_page, $non_db_page_fault, $non_db_page) = (0, 0, 0, 0);
foreach my $entry (@{$pools->{result}}) {
$db_page_fault += $entry->{dbPageFault};
$db_page += $entry->{dbPage};
$non_db_page_fault += $entry->{nonDbPageFault};
$non_db_page += $entry->{nonDbPage};
}
$self->{global} = { non_db_ratio => 0, db_ratio => 0 };
if ($non_db_page > 0) {
$self->{global}->{non_db_ratio} = $non_db_page_fault * 100 / $non_db_page;
}
if ($db_page > 0) {
$self->{global}->{db_ratio} = $db_page_fault * 100 / $db_page;
}
}
1;
__END__
=head1 MODE
Check page faults.
=over 8
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'pagefaults-database', 'pagefaults-nondatabase'.
=back
=cut

View File

@ -0,0 +1,212 @@
#
# Copyright 2021 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 os::as400::connector::mode::subsystems;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
'status: %s',
$self->{result_values}->{status}
);
}
sub custom_jobs_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
nlabel => $self->{nlabel},
instances => [$self->{result_values}->{name}, $self->{result_values}->{library}],
value => $self->{result_values}->{jobs_active},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel})
);
}
sub prefix_subsys_output {
my ($self, %options) = @_;
return sprintf(
"Subsystem '%s' [library: %s] ",
$options{instance_value}->{name},
$options{instance_value}->{library}
);
}
sub prefix_global_output {
my ($self, %options) = @_;
return 'Subsystems ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', cb_prefix_output => 'prefix_global_output', type => 0, skipped_code => { -10 => 1 } },
{ name => 'subsys', type => 1, cb_prefix_output => 'prefix_subsys_output', message_multiple => 'All subsystems are ok' }
];
$self->{maps_counters}->{global} = [
{ label => 'subsystems-total', nlabel => 'subsystems.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => 'total: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
foreach ('active', 'ending', 'inactive', 'restricted', 'starting') {
push @{$self->{maps_counters}->{global}},
{ label => 'subsystems-' . $_, nlabel => 'subsystems.' . $_ . '.count', set => {
key_values => [ { name => $_ }, { name => 'total' } ],
output_template => $_ . ': %s',
perfdatas => [
{ template => '%s', min => 0, max => 'total' }
]
}
};
}
$self->{maps_counters}->{subsys} = [
{
label => 'status',
type => 2,
warning_default => '%{status} =~ /ending|restricted|starting/i',
set => {
key_values => [ { name => 'status' }, { name => 'name' }, { name => 'library' } ],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'jobs-active', nlabel => 'subsystem.jobs.active.count', set => {
key_values => [ { name => 'jobs_active' }, { name => 'name' }, { name => 'library' } ],
output_template => 'current active jobs: %s',
closure_custom_perfdata => $self->can('custom_jobs_perfdata')
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-subsystem-name:s' => { name => 'filter_subsystem_name' },
'filter-subsystem-library:s' => { name => 'filter_subsystem_library' }
});
return $self;
}
my $map_subsys_status = {
'*ACTIVE' => 'active',
'*ENDING' => 'ending',
'*INACTIVE' => 'inactive',
'*RESTRICTED' => 'restricted',
'*STARTING' => 'starting'
};
sub manage_selection {
my ($self, %options) = @_;
my $subsys = $options{custom}->request_api(command => 'listSubsystems');
$self->{global} = { total => 0, active => 0, ending => 0, inactive => 0, restricted => 0, starting => 0 };
$self->{subsys} = {};
foreach my $entry (@{$subsys->{result}}) {
if (defined($self->{option_results}->{filter_subsystem_name}) && $self->{option_results}->{filter_subsystem_name} ne '' &&
$entry->{name} !~ /$self->{option_results}->{filter_subsystem_name}/) {
$self->{output}->output_add(long_msg => "skipping subsystem '" . $entry->{name} . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_subsystem_library}) && $self->{option_results}->{filter_subsystem_library} ne '' &&
$entry->{library} !~ /$self->{option_results}->{filter_subsystem_library}/) {
$self->{output}->output_add(long_msg => "skipping subsystem '" . $entry->{name} . "': no matching filter.", debug => 1);
next;
}
$self->{subsys}->{ $entry->{name} . ':' . $entry->{library} } = {
name => $entry->{name},
library => $entry->{library},
status => $map_subsys_status->{ $entry->{status} },
jobs_active => $entry->{currentActiveJobs}
};
$self->{global}->{ $map_subsys_status->{ $entry->{status} } }++;
$self->{global}->{total}++;
}
}
1;
__END__
=head1 MODE
Check subsystems.
=over 8
=item B<--filter-subsystem-name>
Filter subsystems by name (can be a regexp).
=item B<--filter-subsystem-library>
Filter subsystems by library (can be a regexp).
=item B<--unknown-status>
Set unknown threshold for status.
Can used special variables like: %{status}, %{name}, %{library}
=item B<--warning--status>
Set warning threshold for status (Default: '%{status} =~ /ending|restricted|starting/i').
Can used special variables like: %{status}, %{name}, %{library}
=item B<--critical-status>
Set critical threshold for status.
Can used special variables like: %{status}, %{name}, %{library}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'subsystems-total', 'subsystems-active', 'subsystems-ending',
'subsystems-inactive', 'subsystems-restricted', 'subsystems-starting',
'jobs-active'.
=back
=cut

View File

@ -0,0 +1,178 @@
#
# Copyright 2021 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 os::as400::connector::mode::system;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub system_long_output {
my ($self, %options) = @_;
return 'checking system';
}
sub prefix_jobs_output {
my ($self, %options) = @_;
return 'jobs ';
}
sub prefix_bjobs_output {
my ($self, %options) = @_;
return 'batch jobs ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'system', type => 3, cb_long_output => 'system_long_output', indent_long_output => ' ',
group => [
{ name => 'cpu', type => 0, display_short => 0, skipped_code => { -10 => 1 } },
{ name => 'asp1', type => 0, display_short => 0, skipped_code => { -10 => 1 } },
{ name => 'jobs', type => 0, display_short => 0, cb_prefix_output => 'prefix_jobs_output', skipped_code => { -10 => 1 } },
{ name => 'bjobs', type => 0, display_short => 0, cb_prefix_output => 'prefix_bjobs_output', skipped_code => { -10 => 1 } }
]
}
];
$self->{maps_counters}->{cpu} = [
{ label => 'processing-units-usage', nlabel => 'system.processing.units.usage.percentage', set => {
key_values => [ { name => 'units_used' } ],
output_template => 'processing units used: %.2f %%',
perfdatas => [
{ template => '%.2f', min => 0, unit => '%' }
]
}
}
];
$self->{maps_counters}->{asp1} = [
{ label => 'storage-pool-space-usage', nlabel => 'system.storage.pool.space.usage.percentage', set => {
key_values => [ { name => 'space_used' } ],
output_template => 'storage pool space used: %.2f %%',
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%' }
]
}
}
];
$self->{maps_counters}->{jobs} = [
{ label => 'jobs-total', nlabel => 'system.jobs.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => 'total: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
},
{ label => 'jobs-active', nlabel => 'system.jobs.active.count', set => {
key_values => [ { name => 'active' } ],
output_template => 'active: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{bjobs} = [
{ label => 'batch-jobs-running', nlabel => 'system.batch_jobs.running.count', set => {
key_values => [ { name => 'running' } ],
output_template => 'running: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
},
{ label => 'batch-jobs-waiting-message', nlabel => 'system.batch_jobs.waiting_message.count', set => {
key_values => [ { name => 'wfm' } ],
output_template => 'waiting for message: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $infos = $options{custom}->request_api(command => 'getSystem');
$self->{output}->output_add(short_msg => 'System usage is ok');
$self->{system} = {
global => {
cpu => { units_used => $infos->{result}->[0]->{percentProcessingUnitUsed} },
asp1 => { space_used => $infos->{result}->[0]->{percentSystemASPUsed} },
jobs => {
total => $infos->{result}->[0]->{jobInSystem}, # Returns the total number of user jobs and system jobs that are currently in the system
active => $infos->{result}->[0]->{activeJobInSystem}
},
bjobs => {
running => $infos->{result}->[0]->{batchJobRunning},
wfm => $infos->{result}->[0]->{batchJobWaitingForMessage}
}
}
};
}
1;
__END__
=head1 MODE
Check system usage.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='processing-units'
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'processing-units-usage' (%), 'storage-pool-space-usage' (%),
=back
=cut

View File

@ -0,0 +1,58 @@
#
# Copyright 2021 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 os::as400::connector::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} = {
'command' => 'os::as400::connector::mode::command',
'disks' => 'os::as400::connector::mode::disks',
'jobs' => 'os::as400::connector::mode::jobs',
'job-queues' => 'os::as400::connector::mode::jobqueues',
'list-disks' => 'os::as400::connector::mode::listdisks',
'list-subsystems' => 'os::as400::connector::mode::listsubsystems',
'message-queue' => 'os::as400::connector::mode::messagequeue',
'page-faults' => 'os::as400::connector::mode::pagefaults',
'system' => 'os::as400::connector::mode::system',
'subsystems' => 'os::as400::connector::mode::subsystems'
};
$self->{custom_modes}->{api} = 'os::as400::connector::custom::api';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check AS/400 (Systemi) with centreon-as400 connector.
=cut