Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
569 changes: 569 additions & 0 deletions src/cloud/cisco/webex/restapi/custom/api.pm

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions src/cloud/cisco/webex/restapi/mode/cache.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#
# Copyright 2024 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

package cloud::cisco::webex::restapi::mode::cache;

use base qw(centreon::plugins::templates::counter);

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 manage_selection {
my ($self, %options) = @_;

$options{custom}->cache_data();
$self->{output}->output_add(
severity => 'OK',
short_msg => 'Cache files created successfully'
);
}

1;

__END__

=head1 MODE

Create cache files (other modes could use it with --cache-use option).

=over 8

=back

=cut
212 changes: 212 additions & 0 deletions src/cloud/cisco/webex/restapi/mode/devicestatus.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

package cloud::cisco::webex::restapi::mode::devicestatus;

use base qw(centreon::plugins::templates::counter);

use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);

sub set_counters {
my ($self, %options) = @_;

$self->{maps_counters_type} = [
{
name => 'devices',
type => 1,
cb_prefix_output => 'prefix_output',
skipped_code => { -10 => 1 },
message_multiple => 'All devices are ok'
}
];

$self->{maps_counters}->{devices} = [
{
label => 'status',
type => 2,
unknown_default => '',
critical_default => '%{error_codes} =~ /softwareupgradekeepsfailing/i',
warning_default =>
'%{lifecycle} =~ /UPCOMING_END_OF_SUPPORT/i || %{connection_status} =~ /disconnected/i || %{error_codes} =~ /upcomingendofsupport|networkquality|currentnetworkquality|wifiradioquality/i',
set =>
{
key_values => [
{ name => 'display_name' },
{ name => 'product' },
{ name => 'ip' },
{ name => 'type' },
{ name => 'serial' },
{ name => 'error_codes' },
{ name => 'planned_maintenance' },
{ name => 'lifecycle' },
{ name => 'connection_status' },

],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub {return 0;},
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
}

sub prefix_output {
my ($self, %options) = @_;
my $pref = "device '" . $options{instance_value}->{display_name} . "'";

if (defined($options{instance_value}->{ip}) && $options{instance_value}->{ip}) {
$pref = $pref . " - $options{instance_value}->{ip}";
}

if (defined($options{instance_value}->{product}) && $options{instance_value}->{product}) {
$pref = $pref . ", $options{instance_value}->{product}";
}

if (defined($options{instance_value}->{type}) && $options{instance_value}->{type}) {
$pref = $pref . " ($options{instance_value}->{type})";
}

if (defined($options{instance_value}->{serial}) && $options{instance_value}->{serial}) {
$pref = $pref . " - $options{instance_value}->{serial}";
}

$pref = $pref . " - ";

return $pref;
}

sub custom_status_output {
my ($self, %options) = @_;

my $error = defined($self->{result_values}->{error_codes}) ? $self->{result_values}->{error_codes} : 'NA';

if (defined($self->{result_values}->{error_codes}) && $self->{result_values}->{error_codes}) {
return "Error codes: $error - Connection status: $self->{result_values}->{connection_status} - Planed maintenance: $self->{result_values}->{planned_maintenance} - Lifecycle: $self->{result_values}->{lifecycle}";
}

return "Connection status: $self->{result_values}->{connection_status} - Planed maintenance: $self->{result_values}->{planned_maintenance} - Lifecycle: $self->{result_values}->{lifecycle}";
}

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 =>
{
'device-id:s' => { name => 'device_id' },
'workspace-id:s' => { name => 'workspace_id' },
'person-id:s' => { name => 'person_id' },
'resource-type:s' => { name => 'resource_type', default => 'workspace' },
}
);

return $self;
}

sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);

if ($self->{option_results}->{resource_type} !~ /^workspace|person/) {
$self->{output}->add_option_msg(short_msg => 'Unknown resource type. Must be "workspace" or "person"');
$self->{output}->option_exit();
}

if (!defined($self->{option_results}->{device_id}) && $self->{option_results}->{resource_type} eq 'workspace'
&& (!defined($self->{option_results}->{workspace_id}) || $self->{option_results}->{workspace_id} eq '')) {
$self->{output}->add_option_msg(short_msg =>
'Need to specify --workspace-id option when using --resource-type "workspace"');
$self->{output}->option_exit();
}

if (!defined($self->{option_results}->{device_id}) && $self->{option_results}->{resource_type} eq 'person'
&& (!defined($self->{option_results}->{person_id}) || $self->{option_results}->{person_id} eq '')) {
$self->{output}->add_option_msg(short_msg =>
'Need to specify --person-id option when using --resource-type "person"');
$self->{output}->option_exit();
}
}

sub manage_selection {
my ($self, %options) = @_;

if (defined($self->{option_results}->{device_id}) && $self->{option_results}->{device_id} ne '') {
$self->{devices} = $options{custom}->get_device();
} else {
my $devices = $options{custom}->get_devices();

foreach my $device (@{$devices}) {
$self->{devices}->{$device->{id}} = $device;
}
}

if (scalar(keys %{$self->{devices}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No device found with this --device-id.");
$self->{output}->option_exit();
}
}

1;

__END__

=head1 MODE

Check device status.

=over 8

=item B<--device-id>

Filter device by device-id.

=item B<--workspace-id>

Filter devices by workspace id. Used together with --resource-type "workspace".

=item B<--person-id>

Filter devices by personal id. Used together with --resource-type "person".

=item B<--unknown-status>

Set unknown threshold for status. (Default: '')
Can used special variables like: %{error_codes}, %{connection_status}, %{planned_maintenance}, %{lifecycle}

=item B<--warning--status>

Set warning threshold for status (Default: '%{lifecycle} =~ /UPCOMING_END_OF_SUPPORT/i || %{connection_status} =~ /disconnected/i || %{error_codes} =~ /upcomingendofsupport|networkquality|currentnetworkquality|wifiradioquality/i')
Can used special variables like: %{error_codes}, %{connection_status}, %{planned_maintenance}, %{lifecycle}

=item B<--critical-status>

Set critical threshold for status (Default: '%{error_codes} =~ /softwareupgradekeepsfailing/i').
Can used special variables like: %{error_codes}, %{connection_status}, %{planned_maintenance}, %{lifecycle}

=item B<--cache-use>

Use the cache file instead of requesting the API (the cache file can be created with the cache mode).

=back

=cut
111 changes: 111 additions & 0 deletions src/cloud/cisco/webex/restapi/mode/discovery.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#
# Copyright 2024 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

package cloud::cisco::webex::restapi::mode::discovery;

use base qw(centreon::plugins::mode);

use strict;
use warnings;
use JSON::XS;

sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;

$options{options}->add_options(arguments => {
'type:s' => { name => 'type' },
'prettify' => { name => 'prettify' }
});

return $self;
}

sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);

if (defined($self->{option_results}->{type}) && $self->{option_results}->{type} !~ /^focus|huddle|meetingRoom|open|desk|other|notSet/) {
$self->{output}->add_option_msg(short_msg => 'unknown workspace type');
$self->{output}->option_exit();
}
}

sub run {
my ($self, %options) = @_;

my $disco_stats;
$disco_stats->{start_time} = time();

my $ws_locations = $options{custom}->get_workspace_locations_from_api();
foreach my $ws_location (@{$ws_locations}) {
$self->{workspace_locations}->{$ws_location->{id}} = $ws_location;
}

my $workspaces = $options{custom}->get_workspaces_from_api();

foreach my $workspace (@{$workspaces}) {
$workspace->{location_name} = $self->{workspace_locations}->{$workspace->{workspace_location_id}}->{display_name};
$workspace->{longitude} = $self->{workspace_locations}->{$workspace->{workspace_location_id}}->{longitude};
$workspace->{latitude} = $self->{workspace_locations}->{$workspace->{workspace_location_id}}->{latitude};
$workspace->{address} = $self->{workspace_locations}->{$workspace->{workspace_location_id}}->{address};
$workspace->{city} = $self->{workspace_locations}->{$workspace->{workspace_location_id}}->{city};
}

$disco_stats->{end_time} = time();
$disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time};
$disco_stats->{discovered_items} = scalar(@$workspaces);
$disco_stats->{results} = $workspaces;

my $encoded_data;
eval {
if (defined($self->{option_results}->{prettify})) {
$encoded_data = JSON::XS->new->utf8->pretty->encode($disco_stats);
} else {
$encoded_data = JSON::XS->new->utf8->encode($disco_stats);
}
};
if ($@) {
$encoded_data = '{"code":"encode_error","message":"Cannot encode discovered data into JSON format"}';
}

$self->{output}->output_add(short_msg => $encoded_data);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1);
$self->{output}->exit();
}

1;

__END__

=head1 MODE

workspace discovery.

=over 8

=item B<--type>

Choose the type of workspace to discover (can be: C<focus>, C<huddle>, C<meetingRoom>, C<open>, C<desk>, C<other>, C<notSet>).

=back

=cut
Loading