add cisco vcs

This commit is contained in:
Colin Gagnaire 2019-01-09 18:28:49 +01:00
parent 992a214df4
commit c07b2e9e78
5 changed files with 1124 additions and 0 deletions

View File

@ -0,0 +1,241 @@
#
# Copyright 2019 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 network::cisco::vcs::restapi::custom::xmlapi;
use strict;
use warnings;
use centreon::plugins::http;
use XML::Simple;
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' },
"url-path:s" => { name => 'url_path' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout' },
"ssl-opt:s@" => { name => 'ssl_opt' },
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'XMLAPI 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})) ? $self->{option_results}->{hostname} : undef;
$self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443;
$self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https';
$self->{username} = (defined($self->{option_results}->{username})) ? $self->{option_results}->{username} : undef;
$self->{password} = (defined($self->{option_results}->{password})) ? $self->{option_results}->{password} : undef;
$self->{url_path} = (defined($self->{option_results}->{url_path})) ? $self->{option_results}->{url_path} : '/getxml?location=';
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10;
$self->{proxyurl} = (defined($self->{option_results}->{proxyurl})) ? $self->{option_results}->{proxyurl} : undef;
$self->{ssl_opt} = (defined($self->{option_results}->{ssl_opt})) ? $self->{option_results}->{ssl_opt} : undef;
if (!defined($self->{option_results}->{hostname}) || $self->{option_results}->{hostname} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --hostname option.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{username}) || $self->{option_results}->{username} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --username option.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{password}) || $self->{option_results}->{password} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --password option.");
$self->{output}->option_exit();
}
return 0;
}
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}->{username} = $self->{username};
$self->{option_results}->{password} = $self->{password};
$self->{option_results}->{credentials} = 1;
$self->{option_results}->{basic} = 1;
$self->{option_results}->{proxyurl} = $self->{proxyurl};
$self->{option_results}->{warning_status} = '';
$self->{option_results}->{critical_status} = '';
}
sub settings {
my ($self, %options) = @_;
$self->build_options_for_httplib();
$self->{http}->set_options(%{$self->{option_results}});
}
sub get_connection_info {
my ($self, %options) = @_;
return $self->{hostname} . ":" . $self->{port};
}
sub get_hostname {
my ($self, %options) = @_;
return $self->{hostname};
}
sub get_port {
my ($self, %options) = @_;
return $self->{port};
}
sub get_endpoint {
my ($self, %options) = @_;
$self->settings;
my $content = $self->{http}->request(url_path => $self->{url_path} . $options{method});
my $xml_result;
eval {
$xml_result = XMLin($content, ForceArray => ['Call', 'Zone'], KeyAttr => []);
};
if ($@) {
$self->{output}->output_add(long_msg => $content, debug => 1);
$self->{output}->add_option_msg(short_msg => "Cannot decode xml response: $@");
$self->{output}->option_exit();
}
if (defined($xml_result->{XPathError})) {
$self->{output}->output_add(long_msg => $content, debug => 1);
$self->{output}->add_option_msg(short_msg => "Api return error: " . $xml_result->{XPathError}->{Reason});
$self->{output}->option_exit();
}
return $xml_result;
}
1;
__END__
=head1 NAME
Cisco VCS XML API
=head1 SYNOPSIS
Cisco VCS XML API
=head1 XMLAPI OPTIONS
=over 8
=item B<--hostname>
API hostname.
=item B<--url-path>
API url path (Default: '/getxml?location=')
=item B<--port>
API port (Default: 443)
=item B<--proto>
Specify https if needed (Default: 'https')
=item B<--username>
Set API username
=item B<--password>
Set API password
=item B<--proxyurl>
Proxy URL if any
=item B<--timeout>
Set HTTP timeout
=item B<--ssl-opt>
Set SSL options if needed (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,252 @@
#
# Copyright 2019 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 network::cisco::vcs::restapi::mode::calls;
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 = sprintf("state is '%s' [Duration: %s s]",
$self->{result_values}->{state}, $self->{result_values}->{duration});
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{serial_number} = $options{new_datas}->{$self->{instance} . '_SerialNumber'};
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_State'};
$self->{result_values}->{duration} = $options{new_datas}->{$self->{instance} . '_Duration'};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } },
{ name => 'calls', type => 1, cb_prefix_output => 'prefix_call_output', message_multiple => 'All calls are ok' },
];
$self->{maps_counters}->{global} = [
{ label => 'traversal', set => {
key_values => [ { name => 'Traversal' } ],
output_template => 'Traversal: %d',
perfdatas => [
{ label => 'traversal', value => 'Traversal_absolute', template => '%d',
min => 0, unit => 'calls' },
],
}
},
{ label => 'non-traversal', set => {
key_values => [ { name => 'NonTraversal' } ],
output_template => 'Non Traversal: %d',
perfdatas => [
{ label => 'non_traversal', value => 'NonTraversal_absolute', template => '%d',
min => 0, unit => 'calls' },
],
}
},
{ label => 'collaboration-edge', set => {
key_values => [ { name => 'CollaborationEdge' } ],
output_template => 'Collaboration Edge: %d',
perfdatas => [
{ label => 'collaboration_edge', value => 'CollaborationEdge_absolute', template => '%d',
min => 0, unit => 'calls' },
],
}
},
{ label => 'cloud', set => {
key_values => [ { name => 'Cloud' } ],
output_template => 'Cloud: %d',
perfdatas => [
{ label => 'cloud', value => 'Cloud_absolute', template => '%d',
min => 0, unit => 'calls' },
],
}
},
{ label => 'microsoft-content', set => {
key_values => [ { name => 'MicrosoftContent' } ],
output_template => 'Microsoft Content: %d',
perfdatas => [
{ label => 'microsoft_content', value => 'MicrosoftContent_absolute', template => '%d',
min => 0, unit => 'calls' },
],
}
},
{ label => 'microsoft-imp', set => {
key_values => [ { name => 'MicrosoftIMP' } ],
output_template => 'Microsoft IMP: %d',
perfdatas => [
{ label => 'microsoft_imp', value => 'MicrosoftIMP_absolute', template => '%d',
min => 0, unit => 'calls' },
],
}
},
];
$self->{maps_counters}->{calls} = [
{ label => 'state', set => {
key_values => [ { name => 'State' }, { name => 'Duration' }, { name => 'SerialNumber' } ],
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_global_output {
my ($self, %options) = @_;
return "Number of Calls ";
}
sub prefix_call_output {
my ($self, %options) = @_;
return "Call '" . $options{instance_value}->{SerialNumber} . "' ";
}
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' },
"critical-status:s" => { name => 'critical_status', default => '%{state} ne "Connected"' },
});
return $self;
}
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 check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
}
sub manage_selection {
my ($self, %options) = @_;
my $usages = $options{custom}->get_endpoint(method => '/Status/ResourceUsage/Calls');
$self->{global}->{Traversal} = $usages->{ResourceUsage}->{Calls}->{Traversal}->{Current}->{content};
$self->{global}->{NonTraversal} = $usages->{ResourceUsage}->{Calls}->{NonTraversal}->{Current}->{content};
$self->{global}->{CollaborationEdge} = $usages->{ResourceUsage}->{Calls}->{CollaborationEdge}->{Current}->{content};
$self->{global}->{Cloud} = $usages->{ResourceUsage}->{Calls}->{Cloud}->{Current}->{content};
$self->{global}->{MicrosoftContent} = $usages->{ResourceUsage}->{Calls}->{MicrosoftContent}->{Current}->{content};
$self->{global}->{MicrosoftIMP} = $usages->{ResourceUsage}->{Calls}->{MicrosoftIMP}->{Current}->{content};
my $results = $options{custom}->get_endpoint(method => '/Status/Calls');
$self->{calls} = {};
foreach my $call (@{$results->{Calls}->{Call}}) {
next if (!defined($call->{SerialNumber}));
$self->{calls}->{$call->{SerialNumber}->{content}} = {
SerialNumber => $call->{SerialNumber}->{content},
Duration => $call->{Duration}->{content},
State => $call->{State}->{content},
};
}
}
1;
__END__
=head1 MODE
Check calls count and state.
=over 8
=item B<--warning-*>
Threshold warning.
Can be: 'traversal', 'non-traversal', 'collaboration-edge',
'cloud', 'microsoft-content', 'microsoft-imp'.
=item B<--critical-*>
Threshold critical.
Can be: 'traversal', 'non-traversal', 'collaboration-edge',
'cloud', 'microsoft-content', 'microsoft-imp'.
=item B<--warning-status>
Set warning threshold for status. (Default: '').
Can use special variables like: %{state}, %{serial_number}, %{duration}.
=item B<--critical-status>
Set critical threshold for status. (Default: '%{state} ne "Connected"').
Can use special variables like: %{state}, %{serial_number}, %{duration}.
=back
=cut

View File

@ -0,0 +1,316 @@
#
# Copyright 2019 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 network::cisco::vcs::restapi::mode::httpproxystats;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
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("Status is '%s'", $self->{result_values}->{status});
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$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 },
{ name => 'connections', type => 0, cb_prefix_output => 'prefix_connections_output' },
{ name => 'requests', type => 0, cb_prefix_output => 'prefix_requests_output' },
{ name => 'responses', type => 0, cb_prefix_output => 'prefix_responses_output' },
];
$self->{maps_counters}->{global} = [
{ label => 'status', set => {
key_values => [ { name => 'Status' } ],
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}->{connections} = [
{ label => 'client-connections', set => {
key_values => [ { name => 'TotalClientConnection', diff => 1 } ],
output_template => 'Client: %.2f/s',
per_second => 1,
perfdatas => [
{ label => 'client_connections', value => 'TotalClientConnection_per_second', template => '%.2f',
min => 0, unit => 'connections/s' },
],
}
},
{ label => 'server-connections', set => {
key_values => [ { name => 'TotalServerConnection', diff => 1 } ],
output_template => 'Server: %.2f/s',
per_second => 1,
perfdatas => [
{ label => 'server_connections', value => 'TotalServerConnection_per_second', template => '%.2f',
min => 0, unit => 'connections/s' },
],
}
},
];
$self->{maps_counters}->{requests} = [
{ label => 'completed-requests', set => {
key_values => [ { name => 'CompletedRequests', diff => 1 } ],
output_template => 'Completed: %.2f/s',
per_second => 1,
perfdatas => [
{ label => 'completed_requests', value => 'CompletedRequests_per_second', template => '%.2f',
min => 0, unit => 'requests/s' },
],
}
},
{ label => 'get-requests', set => {
key_values => [ { name => 'GetRequests', diff => 1 } ],
output_template => 'Get: %.2f/s',
per_second => 1,
perfdatas => [
{ label => 'get_requests', value => 'GetRequests_per_second', template => '%.2f',
min => 0, unit => 'requests/s' },
],
}
},
{ label => 'post-requests', set => {
key_values => [ { name => 'PostRequests', diff => 1 } ],
output_template => 'Post: %.2f/s',
per_second => 1,
perfdatas => [
{ label => 'post_requests', value => 'PostRequests_per_second', template => '%.2f',
min => 0, unit => 'requests/s' },
],
}
},
];
$self->{maps_counters}->{responses} = [
{ label => 'responses-1xx', set => {
key_values => [ { name => 'Response1XXCount', diff => 1 } ],
output_template => '1XX: %.2f/s',
per_second => 1,
perfdatas => [
{ label => 'responses_1xx', value => 'Response1XXCount_per_second', template => '%.2f',
min => 0, unit => 'responses/s' },
],
}
},
{ label => 'responses-2xx', set => {
key_values => [ { name => 'Response2XXCount', diff => 1 } ],
output_template => '2XX: %.2f/s',
per_second => 1,
perfdatas => [
{ label => 'responses_2xx', value => 'Response2XXCount_per_second', template => '%.2f',
min => 0, unit => 'responses/s' },
],
}
},
{ label => 'responses-3xx', set => {
key_values => [ { name => 'Response3XXCount', diff => 1 } ],
output_template => '3XX: %.2f/s',
per_second => 1,
perfdatas => [
{ label => 'responses_3xx', value => 'Response3XXCount_per_second', template => '%.2f',
min => 0, unit => 'responses/s' },
],
}
},
{ label => 'responses-4xx', set => {
key_values => [ { name => 'Response4XXCount', diff => 1 } ],
output_template => '4XX: %.2f/s',
per_second => 1,
perfdatas => [
{ label => 'responses_4xx', value => 'Response4XXCount_per_second', template => '%.2f',
min => 0, unit => 'responses/s' },
],
}
},
{ label => 'responses-5xx', set => {
key_values => [ { name => 'Response5XXCount', diff => 1 } ],
output_template => '5XX: %.2f/s',
per_second => 1,
perfdatas => [
{ label => 'responses_5xx', value => 'Response5XXCount_per_second', template => '%.2f',
min => 0, unit => 'responses/s' },
],
}
},
];
}
sub prefix_connections_output {
my ($self, %options) = @_;
return "Connections ";
}
sub prefix_requests_output {
my ($self, %options) = @_;
return "Resquests ";
}
sub prefix_responses_output {
my ($self, %options) = @_;
return "Responses ";
}
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-counters:s" => { name => 'filter_counters' },
"warning-status:s" => { name => 'warning_status' },
"critical-status:s" => { name => 'critical_status', default => '%{status} ne "Active"' },
});
return $self;
}
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 check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
}
sub manage_selection {
my ($self, %options) = @_;
my $results = $options{custom}->get_endpoint(method => '/Status/HTTPProxy');
$self->{global} = {};
$self->{connections} = {};
$self->{requests} = {};
$self->{responses} = {};
$self->{global}->{Status} = $results->{HTTPProxy}->{Status}->{content};
$self->{connections}->{TotalClientConnection} = $results->{HTTPProxy}->{Stats}->{TotalClientConnection}->{content};
$self->{connections}->{TotalServerConnection} = $results->{HTTPProxy}->{Stats}->{TotalServerConnection}->{content};
$self->{requests}->{CompletedRequests} = $results->{HTTPProxy}->{Stats}->{CompletedRequests}->{content};
$self->{requests}->{GetRequests} = $results->{HTTPProxy}->{Stats}->{GetRequests}->{content};
$self->{requests}->{PostRequests} = $results->{HTTPProxy}->{Stats}->{PostRequests}->{content};
$self->{responses}->{Response1XXCount} = $results->{HTTPProxy}->{Stats}->{Response1XXCount}->{content};
$self->{responses}->{Response2XXCount} = $results->{HTTPProxy}->{Stats}->{Response2XXCount}->{content};
$self->{responses}->{Response3XXCount} = $results->{HTTPProxy}->{Stats}->{Response3XXCount}->{content};
$self->{responses}->{Response4XXCount} = $results->{HTTPProxy}->{Stats}->{Response4XXCount}->{content};
$self->{responses}->{Response5XXCount} = $results->{HTTPProxy}->{Stats}->{Response5XXCount}->{content};
$self->{cache_name} = "cisco_vcs_" . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check HTTP proxy status and statistics.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
(Example: --filter-counters='responses')
=item B<--warning-*>
Threshold warning (/s).
Can be: 'client-connections', 'server-connections', 'completed-requests',
'get-requests', 'post-requests', 'responses-1xx', 'responses-2xx',
'responses-3xx', 'responses-4xx', 'responses-5xx'.
=item B<--critical-*>
Threshold critical (/s).
Can be: 'client-connections', 'server-connections', 'completed-requests',
'get-requests', 'post-requests', 'responses-1xx', 'responses-2xx',
'responses-3xx', 'responses-4xx', 'responses-5xx'.
=item B<--warning-status>
Set warning threshold for status. (Default: '').
Can use special variables like: %{status}.
=item B<--critical-status>
Set critical threshold for status. (Default: '%{status} ne "Active"').
Can use special variables like: %{status}.
=back
=cut

View File

@ -0,0 +1,265 @@
#
# Copyright 2019 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 network::cisco::vcs::restapi::mode::zones;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
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("Status is '%s' [Type: %s]",
$self->{result_values}->{status}, $self->{result_values}->{type});
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_Name'};
$self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_Type'};
$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},
{ name => 'searches', type => 0, cb_prefix_output => 'prefix_searches_output' },
{ name => 'zones', type => 1, cb_prefix_output => 'prefix_zones_output', message_multiple => 'All zones are ok' },
];
$self->{maps_counters}->{global} = [
{ label => 'zones-count', set => {
key_values => [ { name => 'count' } ],
output_template => 'Number of zones: %d',
perfdatas => [
{ label => 'zones_count', value => 'count_absolute', template => '%d',
min => 0 },
],
}
},
];
$self->{maps_counters}->{searches} = [
{ label => 'searches-total', set => {
key_values => [ { name => 'Total', diff => 1 } ],
output_template => 'Total: %.2f/s',
per_second => 1,
perfdatas => [
{ label => 'searches_total', value => 'Total_per_second', template => '%.2f',
min => 0, unit => 'searches/s' },
],
}
},
{ label => 'searches-dropped', set => {
key_values => [ { name => 'Dropped', diff => 1 } ],
output_template => 'Dropped: %.2f/s',
per_second => 1,
perfdatas => [
{ label => 'searches_dropped', value => 'Dropped_per_second', template => '%.2f',
min => 0, unit => 'searches/s' },
],
}
},
{ label => 'searches-max-sub-search-exceeded', set => {
key_values => [ { name => 'MaxSubSearchExceeded', diff => 1 } ],
output_template => 'Max Sub Search Exceeded: %.2f/s',
per_second => 1,
perfdatas => [
{ label => 'searches_max_sub_search_exceeded', value => 'MaxSubSearchExceeded_per_second', template => '%.2f',
min => 0, unit => 'searches/s' },
],
}
},
{ label => 'searches-max-targets-exceeded', set => {
key_values => [ { name => 'MaxTargetsExceeded', diff => 1 } ],
output_template => 'Max Targets Exceeded: %.2f/s',
per_second => 1,
perfdatas => [
{ label => 'searches_max_targets_exceeded', value => 'MaxTargetsExceeded_per_second', template => '%.2f',
min => 0, unit => 'searches/s' },
],
}
},
];
$self->{maps_counters}->{zones} = [
{ label => 'status', set => {
key_values => [ { name => 'Status' }, { name => 'Type' }, { 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 => 'calls-count', set => {
key_values => [ { name => 'Calls' }, { name => 'Name' } ],
output_template => 'Number of Calls: %d',
perfdatas => [
{ label => 'calls_count', value => 'Calls_absolute', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'Name_absolute' },
],
}
},
];
}
sub prefix_searches_output {
my ($self, %options) = @_;
return "Searches ";
}
sub prefix_zones_output {
my ($self, %options) = @_;
return "Zone '" . $options{instance_value}->{Name} . "' ";
}
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-counters:s" => { name => 'filter_counters' },
"warning-status:s" => { name => 'warning_status' },
"critical-status:s" => { name => 'critical_status', default => '%{status} ne "Active"' },
});
return $self;
}
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 check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
$self->change_macros();
}
sub manage_selection {
my ($self, %options) = @_;
my $results = $options{custom}->get_endpoint(method => '/Status/Zones');
$self->{global}->{count} = 0;
$self->{searches} = {};
$self->{zones} = {};
$self->{searches}->{Total} = $results->{Zones}->{Searches}->{Total}->{content};
$self->{searches}->{Dropped} = $results->{Zones}->{Searches}->{Dropped}->{content};
$self->{searches}->{MaxSubSearchExceeded} = $results->{Zones}->{Searches}->{MaxSubSearchExceeded}->{content};
$self->{searches}->{MaxTargetsExceeded} = $results->{Zones}->{Searches}->{MaxTargetsExceeded}->{content};
foreach my $zone (@{$results->{Zones}->{Zone}}) {
next if (!defined($zone->{Name}));
$self->{zones}->{$zone->{Name}->{content}} = {
Type => $zone->{Type}->{content},
Name => $zone->{Name}->{content},
Calls => (defined($zone->{Calls})) ? scalar(@{$zone->{Calls}->{Call}}) : 0,
Status => $zone->{Status}->{content},
};
$self->{global}->{count}++;
}
$self->{cache_name} = "cisco_vcs_" . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check zones count and state.
=over 8
=item B<--warning-*>
Threshold warning.
Can be: 'zones-count', 'calls-count', 'searches-total' (/s), 'searches-dropped' (/s),
'searches-max-sub-search-exceeded' (/s), 'searches-max-targets-exceeded' (/s).
=item B<--critical-*>
Threshold critical.
Can be: 'zones-count', 'calls-count', 'searches-total' (/s), 'searches-dropped' (/s),
'searches-max-sub-search-exceeded' (/s), 'searches-max-targets-exceeded' (/s).
=item B<--warning-status>
Set warning threshold for status. (Default: '').
Can use special variables like: %{status}, %{type}, %{name}.
=item B<--critical-status>
Set critical threshold for status. (Default: '%{status} ne "Active"').
Can use special variables like: %{status}, %{type}, %{name}.
=back
=cut

View File

@ -0,0 +1,50 @@
#
# Copyright 2019 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 network::cisco::vcs::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}} = (
'calls' => 'network::cisco::vcs::restapi::mode::calls',
'http-proxy-stats' => 'network::cisco::vcs::restapi::mode::httpproxystats',
'zones' => 'network::cisco::vcs::restapi::mode::zones',
);
$self->{custom_modes}{xmlapi} = 'network::cisco::vcs::restapi::custom::xmlapi';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Cisco VCS (TelePresence Video Communication Server) API.
=cut