Add commvault (#2309)

This commit is contained in:
qgarnier 2020-10-30 11:12:49 +01:00 committed by GitHub
parent ceeb21d3b1
commit e4f3cbaa4e
5 changed files with 1076 additions and 0 deletions

View File

@ -0,0 +1,337 @@
#
# Copyright 2020 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.
# Authors : Roman Morandell - ivertix
#
package apps::backup::commvault::commserve::restapi::custom::api;
use strict;
use warnings;
use centreon::plugins::http;
use centreon::plugins::statefile;
use JSON::XS;
use Digest::MD5 qw(md5_hex);
use MIME::Base64;
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' },
'url-path:s' => { name => 'url_path' },
'api-username:s' => { name => 'api_username' },
'api-password:s' => { name => 'api_password' },
'user-domain:s' => { name => 'user_domain' },
'timeout:s' => { name => 'timeout' }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{http} = centreon::plugins::http->new(%options);
$self->{cache} = centreon::plugins::statefile->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->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
$self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https';
$self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443;
$self->{url_path} = (defined($self->{option_results}->{url_path})) ? $self->{option_results}->{url_path} : '/webconsole/api';
$self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : '';
$self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : '';
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30;
$self->{user_domain} = (defined($self->{option_results}->{user_domain})) ? $self->{option_results}->{user_domain} : '';
if ($self->{hostname} eq '') {
$self->{output}->add_option_msg(short_msg => 'Need to specify hostname option.');
$self->{output}->option_exit();
}
if ($self->{api_username} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --api-username option.");
$self->{output}->option_exit();
}
if ($self->{api_password} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --api-password option.");
$self->{output}->option_exit();
}
$self->{cache}->check_options(option_results => $self->{option_results});
return 0;
}
sub get_connection_infos {
my ($self, %options) = @_;
return $self->{hostname} . '_' . $self->{http}->get_port();
}
sub get_hostname {
my ($self, %options) = @_;
return $self->{hostname};
}
sub get_port {
my ($self, %options) = @_;
return $self->{port};
}
sub json_decode {
my ($self, %options) = @_;
$options{content} =~ s/\r//mg;
my $decoded;
eval {
$decoded = JSON::XS->new->utf8->decode($options{content});
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
$self->{output}->option_exit();
}
return $decoded;
}
sub build_options_for_httplib {
my ($self, %options) = @_;
$self->{option_results}->{hostname} = $self->{hostname};
$self->{option_results}->{port} = $self->{port};
$self->{option_results}->{proto} = $self->{proto};
}
sub settings {
my ($self, %options) = @_;
$self->build_options_for_httplib();
$self->{http}->add_header(key => 'Accept', value => 'application/json');
$self->{http}->add_header(key => 'Content-Type', value => 'application/json');
$self->{http}->set_options(%{$self->{option_results}});
}
sub clean_token {
my ($self, %options) = @_;
my $datas = {};
$options{statefile}->write(data => $datas);
$self->{access_token} = undef;
$self->{http}->add_header(key => 'Authorization', value => undef);
}
sub get_auth_token {
my ($self, %options) = @_;
my $has_cache_file = $options{statefile}->read(statefile => 'commvault_commserve_' . md5_hex($self->{option_results}->{hostname}) . '_' . md5_hex($self->{option_results}->{api_username}));
my $access_token = $options{statefile}->get(name => 'access_token');
# Token expires every 15 minutes
if ($has_cache_file == 0 || !defined($access_token)) {
my $json_request = {
username => $self->{api_username},
password => MIME::Base64::encode_base64($self->{api_password}, '')
};
$json_request->{domain} = $self->{user_domain} if ($self->{user_domain} ne '');
my $encoded;
eval {
$encoded = encode_json($json_request);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => 'cannot encode json request');
$self->{output}->option_exit();
}
my ($content) = $self->{http}->request(
method => 'POST',
url_path => $self->{url_path} . '/Login',
query_form_post => $encoded,
warning_status => '', unknown_status => '', critical_status => ''
);
if ($self->{http}->get_code() != 200) {
$self->{output}->add_option_msg(short_msg => "Authentication error [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']");
$self->{output}->option_exit();
}
my $decoded = $self->json_decode(content => $content);
if (!defined($decoded->{token})) {
$self->{output}->add_option_msg(short_msg => "Cannot get token");
$self->{output}->option_exit();
}
$access_token = $decoded->{token};
my $datas = {
access_token => $access_token
};
$options{statefile}->write(data => $datas);
}
$self->{access_token} = $access_token;
$self->{http}->add_header(key => 'Authtoken', value => $self->{access_token});
}
sub request_internal {
my ($self, %options) = @_;
$self->settings();
if (!defined($self->{access_token})) {
$self->get_auth_token(statefile => $self->{cache});
}
my $content = $self->{http}->request(
method => 'GET',
url_path => $self->{url_path} . $options{endpoint},
get_param => $options{get_param},
warning_status => '',
unknown_status => '',
critical_status => ''
);
# Maybe there is an issue with the token. So we retry.
if ($self->{http}->get_code() < 200 || $self->{http}->get_code() >= 300) {
$self->clean_token(statefile => $self->{cache});
$self->get_auth_token(statefile => $self->{cache});
$content = $self->{http}->request(
url_path => $self->{url_path} . $options{endpoint},
get_param => $options{get_param},
warning_status => '',
unknown_status => '',
critical_status => ''
);
}
my $decoded = $self->json_decode(content => $content);
if (!defined($decoded)) {
$self->{output}->add_option_msg(short_msg => 'Error while retrieving data (add --debug option for detailed message)');
$self->{output}->option_exit();
}
if ($self->{http}->get_code() < 200 || $self->{http}->get_code() >= 300) {
$self->{output}->add_option_msg(short_msg => 'api request error');
$self->{output}->option_exit();
}
return $decoded;
}
sub request {
my ($self, %options) = @_;
return $self->request_internal(
endpoint => $options{endpoint}
);
}
sub request_paging {
my ($self, %options) = @_;
my ($page_num, $page_count) = (1, 200);
my $alerts = [];
while (1) {
my $results = $self->request_internal(
endpoint => $options{endpoint},
get_param => ['pageNo=' . $page_num, 'pageCount=' . $page_count]
);
push @$alerts, @{$results->{feedsList}};
last if ($results->{totalNoOfAlerts} < ($page_num * $page_count));
$page_num++;
}
return $alerts;
}
1;
__END__
=head1 NAME
Commvault API
=head1 SYNOPSIS
Commvault api
=head1 REST API OPTIONS
=over 8
=item B<--hostname>
API hostname.
=item B<--url-path>
API url path (Default: '/webconsole/api')
=item B<--port>
API port (Default: 443)
=item B<--proto>
Specify https if needed (Default: 'https')
=item B<--api-username>
Set API username
=item B<--api-password>
Set API password
=item B<--timeout>
Set HTTP timeout
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,227 @@
#
# Copyright 2018 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::commvault::commserve::restapi::mode::alerts;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use POSIX;
use centreon::plugins::misc;
use centreon::plugins::statefile;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
'alert [severity: %s] [status: %s] [name: %s] [type: %s] %s',
$self->{result_values}->{severity},
$self->{result_values}->{status},
$self->{result_values}->{name},
$self->{result_values}->{type},
$self->{result_values}->{generation_time}
);
}
sub prefix_global_output {
my ($self, %options) = @_;
return 'Alerts ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', },
{ name => 'alarms', type => 2, message_multiple => '0 alert(s) detected', display_counter_problem => { nlabel => 'alerts.problems.current.count', min => 0 },
group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ]
}
];
$self->{maps_counters}->{global} = [
{ label => 'alerts-total', nlabel => 'alerts.total.count', display_ok => 0, set => {
key_values => [ { name => 'total' } ],
output_template => 'total: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
foreach (('critical', 'warning', 'info')) {
push @{$self->{maps_counters}->{global}},
{ label => 'alerts-' . $_, nlabel => 'alerts.' . $_ . '.count', display_ok => 0, set => {
key_values => [ { name => $_ }, { name => 'total' } ],
output_template => $_ . ': %s',
perfdatas => [
{ template => '%s', min => 0, max => 'total' }
]
}
};
}
$self->{maps_counters}->{alarm} = [
{
label => 'status',
type => 2,
warning_default => '%{severity} =~ /warning/',
critical_default => '%{severity} =~ /critical/',
set => {
key_values => [
{ name => 'name' }, { name => 'type' },
{ name => 'severity' }, { name => 'status' },
{ name => 'since' }, { name => 'generation_time' }
],
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 => {
'filter-alert-name:s' => { name => 'filter_alert_name' },
'filter-alert-type:s' => { name => 'filter_alert_type' },
'memory' => { name => 'memory' }
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->check_options(%options);
}
}
my $map_severity = {
0 => 'autoPick', 1 => 'critical',
2 => 'warning', 3 => 'info'
};
my $map_status = {
4 => 'read', 8 => 'unread'
};
sub manage_selection {
my ($self, %options) = @_;
my $alarms = $options{custom}->request_paging(
endpoint => '/Alert'
);
my $last_time;
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->read(
statefile => 'commvault_commserve_' . $options{custom}->get_connection_infos() . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_alert_name}) ? md5_hex($self->{option_results}->{filter_alert_name}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_alert_type}) ? md5_hex($self->{option_results}->{filter_alert_type}) : md5_hex('all'))
);
$last_time = $self->{statefile_cache}->get(name => 'last_time');
}
$self->{global} = { total => 0, critical => 0, warning => 0, info => 0 };
$self->{alarms} = { global => { alarm => {} } };
my ($i, $current_time) = (1, time());
foreach my $alarm (@$alarms) {
my $create_time = $alarm->{detectedTime}->{time};
next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $create_time);
if (defined($self->{option_results}->{filter_alert_name}) && $self->{option_results}->{filter_alert_name} ne '' &&
$alarm->{alertName} !~ /$self->{option_results}->{filter_alert_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $alarm->{alertName} . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_alert_type}) && $self->{option_results}->{filter_alert_type} ne '' &&
$alarm->{alertType} !~ /$self->{option_results}->{filter_alert_type}/) {
$self->{output}->output_add(long_msg => "skipping '" . $alarm->{alertName} . "': no matching filter.", debug => 1);
next;
}
my $diff_time = $current_time - $create_time;
$self->{alarms}->{global}->{alarm}->{$i} = {
name => $alarm->{alertName},
type => $alarm->{alertType},
severity => $map_severity->{ $alarm->{severity} },
status => $map_status->{ $alarm->{status} },
since => $diff_time,
generation_time => centreon::plugins::misc::change_seconds(value => $diff_time)
};
$self->{global}->{total}++;
$self->{global}->{ $map_severity->{ $alarm->{severity} } }++
if (defined($self->{global}->{ $map_severity->{ $alarm->{severity} } }));
$i++;
}
if (defined($self->{option_results}->{memory})) {
$self->{statefile_cache}->write(data => { last_time => $current_time });
}
}
1;
__END__
=head1 MODE
Check alerts.
=over 8
=item B<--filter-alert-name>
Filter alerts by name (can be a regexp).
=item B<--filter-alert-type>
Filter alerts by type (can be a regexp).
=item B<--warning-status>
Set warning threshold for status (Default: '%{severity} =~ /warning/')
Can used special variables like: %{severity}, %{status}, %{type}, %{name}, %{since}
=item B<--critical-status>
Set critical threshold for status (Default: '%{severity} =~ /critical/').
Can used special variables like: %{severity}, %{status}, %{type}, %{name}, %{since}
=item B<--memory>
Only check new alerts.
=back
=cut

View File

@ -0,0 +1,266 @@
#
# Copyright 2020 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::commvault::commserve::restapi::mode::jobs;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::misc;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
return 'status: ' . $self->{result_values}->{status};
}
sub custom_long_output {
my ($self, %options) = @_;
return 'started since: ' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{elapsed});
}
sub prefix_job_output {
my ($self, %options) = @_;
return "Job '" . $options{instance_value}->{display} . "' [type: " . $options{instance_value}->{type} . "] " ;
}
sub policy_long_output {
my ($self, %options) = @_;
return "Checking policy '" . $options{instance_value}->{display} . "'";
}
sub prefix_policy_output {
my ($self, %options) = @_;
return "Policy '" . $options{instance_value}->{display} . "' ";
}
sub custom_long_calc {
my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{elapsed} = $options{new_datas}->{$self->{instance} . '_elapsed'};
$self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'};
return -11 if ($self->{result_values}->{status} !~ /running|queued|waiting/i);
return 0;
}
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',
display_counter_problem => { nlabel => 'jobs.problems.current.count', min => 0 },
message_multiple => 'All policies are ok',
group => [ { name => 'job', cb_prefix_output => 'prefix_job_output', skipped_code => { -11 => 1 } } ]
}
];
$self->{maps_counters}->{global} = [
{ label => 'jobs-total', nlabel => 'jobs.total.count', set => {
key_values => [ { name => 'total' } ],
output_template => 'Total jobs: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{job} = [
{
label => 'status',
type => 2,
warning_default => '%{status} =~ /abnormal/i',
critical_default => '%{status} =~ /errors|failed/i',
set => {
key_values => [ { name => 'status' }, { name => 'display' }, { name => 'type' } ],
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 => \&catalog_status_threshold_ng
}
},
{ label => 'long', type => 2, set => {
key_values => [
{ name => 'status' }, { name => 'display' }, { name => 'elapsed' }, { name => 'type' }
],
closure_custom_calc => $self->can('custom_long_calc'),
closure_custom_output => $self->can('custom_long_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, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-policy-name:s' => { name => 'filter_policy_name' },
'filter-type:s' => { name => 'filter_type' },
'filter-client-group:s' => { name => 'filter_client_group' },
'filter-client-name:s' => { name => 'filter_client_name' }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
$self->{cache_name} = 'commvault_commserve_' . $options{custom}->get_connection_infos() . '_' . $self->{mode} . '_' .
(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_type}) ? md5_hex($self->{option_results}->{filter_type}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_client_group}) ? md5_hex($self->{option_results}->{filter_client_group}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_client_name}) ? md5_hex($self->{option_results}->{filter_client_name}) : md5_hex('all'));
my $last_timestamp = $self->read_statefile_key(key => 'last_timestamp');
$last_timestamp = time() - 300 if (!defined($last_timestamp));
# Also we get Pending/Waiting/Running jobs with that
my $results = $options{custom}->request(
endpoint => '/Job?completedJobLookupTime=' . (time() - $last_timestamp)
);
$self->{global} = { total => 0 };
$self->{policy} = {};
my $jobs_checked = {};
my $current_time = time();
foreach (@{$results->{jobs}}) {
my $job = $_->{jobSummary};
next if (defined($jobs_checked->{ $job->{jobId} }));
$jobs_checked->{ $job->{jobId} } = 1;
my $policy_name = defined($job->{storagePolicy}->{storagePolicyName}) && $job->{storagePolicy}->{storagePolicyName} ne '' ? $job->{storagePolicy}->{storagePolicyName} : 'unknown';
# when the job is running, end_time = 0
if (defined($self->{option_results}->{filter_policy_name}) && $self->{option_results}->{filter_policy_name} ne '' &&
$policy_name !~ /$self->{option_results}->{filter_policy_name}/) {
$self->{output}->output_add(long_msg => "skipping job '" . $policy_name . "/" . $job->{jobId} . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
$job->{jobType} !~ /$self->{option_results}->{filter_type}/) {
$self->{output}->output_add(long_msg => "skipping job '" . $policy_name . "/" . $job->{jobId} . "': no matching filter type.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_client_name}) && $self->{option_results}->{filter_client_name} ne '' &&
$job->{destClientName} !~ /$self->{option_results}->{filter_client_name}/) {
$self->{output}->output_add(long_msg => "skipping job '" . $policy_name . "/" . $job->{jobId} . "': no matching filter type.", debug => 1);
next;
}
if (defined($job->{clientGroups}) && defined($self->{option_results}->{filter_client_name}) && $self->{option_results}->{filter_client_name} ne '') {
my $matched = 0;
foreach (@$job->{clientGroups}) {
if ($_->{clientGroupName} =~ /$self->{option_results}->{filter_client_group}/) {
$matched = 1;
last;
}
}
if ($matched == 0) {
$self->{output}->output_add(long_msg => "skipping job '" . $policy_name . "/" . $job->{jobId} . "': no matching filter type.", debug => 1);
next;
}
}
$self->{policy}->{$policy_name} = { job => {}, display => $policy_name } if (!defined($self->{policy}->{$policy_name}));
my $elapsed_time = $current_time - $job->{jobStartTime};
$self->{policy}->{$policy_name}->{job}->{ $job->{jobId} } = {
display => $job->{jobId},
elapsed => $elapsed_time,
status => $job->{status},
type => $job->{jobType}
};
$self->{global}->{total}++;
}
}
1;
__END__
=head1 MODE
Check jobs.
=over 8
=item B<--filter-policy-name>
Filter jobs by policy name (can be a regexp).
=item B<--filter-type>
Filter jobs by type (can be a regexp).
=item B<--filter-client-name>
Filter jobs by client name (can be a regexp).
=item B<--filter-client-group>
Filter jobs by client groups (can be a regexp).
=item B<--warning-status>
Set warning threshold for status (Default: '%{status} =~ /abnormal/i')
Can used special variables like: %{display}, %{status}, %{type}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /errors|failed/i').
Can used special variables like: %{display}, %{status}, %{type}
=item B<--warning-long>
Set warning threshold for long jobs.
Can used special variables like: %{display}, %{status}, %{elapsed}, %{type}
=item B<--critical-long>
Set critical threshold for long jobs.
Can used special variables like: %{display}, %{status}, %{elapsed}, %{type}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'jobs-total'.
=back
=cut

View File

@ -0,0 +1,188 @@
#
# Copyright 2020 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::commvault::commserve::restapi::mode::storagepools;
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 'status: ' . $self->{result_values}->{status};
}
sub custom_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_sp_output {
my ($self, %options) = @_;
return "Storage pool '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'sp', type => 1, cb_prefix_output => 'prefix_sp_output', message_multiple => 'All storage pools are ok', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{sp} = [
{ label => 'status', type => 2, critical_default => '%{status} !~ /online/i', set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'usage', nlabel => 'storagepool.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_usage_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total_space',
unit => 'B', cast_int => 1, label_extra_instance => 1 }
]
}
},
{ label => 'usage-free', nlabel => 'storagepool.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_usage_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 }
]
}
},
{ label => 'usage-prct', nlabel => 'storagepool.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_usage_output'),
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%', 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 => {
'filter-name:s' => { name => 'filter_name' }
});
return $self;
}
my $map_status_code = {
0 => 'online', 1 => 'offline'
};
sub manage_selection {
my ($self, %options) = @_;
my $results = $options{custom}->request(
endpoint => '/StoragePool'
);
$self->{sp} = {};
foreach (@{$results->{storagePoolList}}) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$_->{storagePoolEntity}->{storagePoolName} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping storage resource '" . $_->{storagePoolEntity}->{storagePoolName} . "': no matching filter.", debug => 1);
next;
}
my ($total, $free) = ($_->{totalCapacity} * 1024 * 1024, $_->{totalFreeSpace} * 1024 * 1024);
$self->{sp}->{ $_->{storagePoolEntity}->{storagePoolName} } = {
display => $_->{storagePoolEntity}->{storagePoolName},
status => defined($map_status_code->{ $_->{statusCode} }) ? $map_status_code->{ $_->{statusCode} } : lc($_->{status}),
total_space => $total,
used_space => $total - $free,
free_space => $free,
prct_used_space => 100 - ($free * 100 / $total),
prct_free_space => $free * 100 / $total
};
}
if (scalar(keys %{$self->{sp}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No storage pool found");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check storage pools.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^usage$'
=item B<--filter-name>
Filter storage pools by name (can be a regexp).
=item B<--unknown-status>
Set warning threshold for status.
Can used special variables like: %{status}, %{display}
=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} !~ /online/i').
Can used special variables like: %{status}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%).
=back
=cut

View File

@ -0,0 +1,58 @@
#
# Copyright 2020 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.
# Authors : Roman Morandell - ivertix
#
package apps::backup::commvault::commserve::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} = '1.0';
$self->{modes} = {
'alerts' => 'apps::backup::commvault::commserve::restapi::mode::alerts',
'jobs' => 'apps::backup::commvault::commserve::restapi::mode::jobs',
#'media-agents' => 'apps::backup::commvault::commserve::restapi::mode::mediaagents',
'storage-pools' => 'apps::backup::commvault::commserve::restapi::mode::storagepools'
};
$self->{custom_modes}->{api} = 'apps::backup::commvault::commserve::restapi::custom::api';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Commvault Commserve using Rest API.
=over 8
=back
=cut