diff --git a/src/network/backbox/restapi/custom/api.pm b/src/network/backbox/restapi/custom/api.pm index 9ba302c6a2..088aed5fdc 100644 --- a/src/network/backbox/restapi/custom/api.pm +++ b/src/network/backbox/restapi/custom/api.pm @@ -149,10 +149,11 @@ sub request { $self->settings(); my $content = $self->{http}->request( - method => 'GET', + method => $options{method}, url_path => $endpoint, get_param => $options{get_param}, header => [ + 'Accept: application/json', 'AUTH: ' . $self->{api_token} ], warning_status => '', @@ -163,9 +164,11 @@ sub request { # Maybe there is an issue with the token. So we retry. if ($self->{http}->get_code() < 200 || $self->{http}->get_code() >= 300) { $content = $self->{http}->request( + method => $options{method}, url_path => $endpoint, get_param => $options{get_param}, header => [ + 'Accept: application/json', 'AUTH: ' . $self->{api_token} ], unknown_status => $self->{unknown_http_status}, @@ -179,7 +182,6 @@ sub request { $self->{output}->add_option_msg(short_msg => 'Error while retrieving data (add --debug option for detailed message)'); $self->{output}->option_exit(); } - return $decoded; } @@ -190,7 +192,8 @@ sub get_backup_jobs_status { if (!centreon::plugins::misc::is_empty($options{filter_type})) { $endpoint .= '/' . $options{filter_type}; } - return $self->request(endpoint => $endpoint); + return $self->request(method => 'GET', + endpoint => $endpoint); } sub get_config_status { @@ -200,7 +203,8 @@ sub get_config_status { if (!centreon::plugins::misc::is_empty($options{filter_type})) { $endpoint .= '/' . $options{filter_type}; } - return $self->request(endpoint => $endpoint); + return $self->request(method => 'GET', + endpoint => $endpoint); } sub get_intelli_check_status { @@ -213,7 +217,49 @@ sub get_intelli_check_status { if (!centreon::plugins::misc::is_empty($options{report_id})) { $endpoint .= '/' . $options{report_id}; } - return $self->request(endpoint => $endpoint); + return $self->request(method => 'GET', + endpoint => $endpoint); +} + +sub get_devices { + my ($self, %options) = @_; + + my $json_decode = 1; + if (defined($options{json_decode})) { + $json_decode = $options{json_decode}; + } + return $self->request(method => 'GET', + endpoint => 'devices'); +} + +sub get_device_id_from_name { + my ($self, %options) = @_; + + my $devices = $self->get_devices(); + for my $device (@$devices) { + if ($device->{deviceName} eq $options{device_name}) { + return $device->{deviceId}; + } + } +} + +sub get_devices_backups_status { + my ($self, %options) = @_; + + return $self->request(method => 'POST', + endpoint => 'devices/dynamic'); +} + +sub get_device_backup_status { + my ($self, %options) = @_; + + my $backups = $self->get_devices_backups_status(); + + for my $backup (@$backups) { + if ($backup->{deviceId} == $options{device_id}) { + return $backup; + } + } } 1; diff --git a/src/network/backbox/restapi/mode/backup.pm b/src/network/backbox/restapi/mode/backup.pm index be13d97da9..591bf481c9 100644 --- a/src/network/backbox/restapi/mode/backup.pm +++ b/src/network/backbox/restapi/mode/backup.pm @@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub prefix_backup_output { my ($self, %options) = @_; diff --git a/src/network/backbox/restapi/mode/configstatus.pm b/src/network/backbox/restapi/mode/configstatus.pm index 0cd5a39753..97583fb855 100644 --- a/src/network/backbox/restapi/mode/configstatus.pm +++ b/src/network/backbox/restapi/mode/configstatus.pm @@ -24,7 +24,6 @@ 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) = @_; diff --git a/src/network/backbox/restapi/mode/devicebackup.pm b/src/network/backbox/restapi/mode/devicebackup.pm new file mode 100644 index 0000000000..c30cdfe89c --- /dev/null +++ b/src/network/backbox/restapi/mode/devicebackup.pm @@ -0,0 +1,143 @@ +# +# 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 network::backbox::restapi::mode::devicebackup; + +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) = @_; + + my $msg = sprintf("Device [id: %s] [name: %s] [status: %s] [status reason: %s]", + $self->{result_values}->{device_id}, + $self->{result_values}->{device_name}, + $self->{result_values}->{status}, + $self->{result_values}->{status_reason}); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'backup', type => 0 }, + ]; + + $self->{maps_counters}->{backup} = [ + { label => 'status', + type => 2, + warning_default => '%{status} =~ /SUSPECT/i', + critical_default => '%{status} =~ /FAILURE/i', + set => { + key_values => [ { name => 'device_id' }, + { name => 'device_name' }, + { name => 'status' }, + { name => 'status_reason' } + ], + 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 => { + 'device-id:s' => { name => 'device_id' }, + 'device-name:s' => { name => 'device_name' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (centreon::plugins::misc::is_empty($self->{option_results}->{device_id}) && centreon::plugins::misc::is_empty($self->{option_results}->{device_name})) { + $self->{output}->add_option_msg(short_msg => "Need to specify --device-id or --device-name option."); + $self->{output}->option_exit(); + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my $device_id = $self->{option_results}->{device_id}; + my $device_name = $self->{option_results}->{device_name} || ''; + if (centreon::plugins::misc::is_empty($device_id)) { + $device_id = $options{custom}->get_device_id_from_name(device_name => $device_name); + } + + my $backup = $options{custom}->get_device_backup_status(device_id => $device_id); + if (centreon::plugins::misc::is_empty($backup)) { + $self->{output}->add_option_msg(short_msg => "No backup found for device id '" . $device_id . "'."); + $self->{output}->option_exit(); + } + + $self->{backup} = { device_id => $device_id, + device_name => $device_name, + status => $backup->{historyStatus}, + status_reason => $backup->{statusReason} + }; +} + +1; + +__END__ + +=head1 MODE + +Check a device backup on BackBox. + +=over 8 + +=item B<--device-id> + +ID of the device (if you prefer to use the ID instead of the name). +ID or name is mandatory. + +=item B<--device-name> + +Name of the device (if you prefer to use the name instead of the ID). +ID or name is mandatory. If you specify both, the ID will be used. + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /SUSPECT/i'). +You can use the following variables: %{status}, %{status_reason}, %{device_name}, %{device_id}. + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /FAILURE/i'). +You can use the following variables: %{status}, %{status_reason}, %{device_name}, %{device_id}. + +=back + +=cut diff --git a/src/network/backbox/restapi/mode/intellicheck.pm b/src/network/backbox/restapi/mode/intellicheck.pm index 779218cc64..f90e6d7daf 100644 --- a/src/network/backbox/restapi/mode/intellicheck.pm +++ b/src/network/backbox/restapi/mode/intellicheck.pm @@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); sub prefix_intellicheck_output { my ($self, %options) = @_; diff --git a/src/network/backbox/restapi/mode/listdevices.pm b/src/network/backbox/restapi/mode/listdevices.pm new file mode 100644 index 0000000000..df0679860b --- /dev/null +++ b/src/network/backbox/restapi/mode/listdevices.pm @@ -0,0 +1,121 @@ +# +# 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 network::backbox::restapi::mode::listdevices; + +use strict; +use warnings; + +use base qw(centreon::plugins::mode); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + + my $jsondevices = $options{custom}->get_devices(); + + $self->{devices} = []; + + for my $jsondevice (@{$jsondevices}) { + my $device = { + id => $jsondevice->{deviceId}, + name => $jsondevice->{deviceName}, + description => defined($jsondevice->{description}) ? $jsondevice->{description} : '', + site => defined($jsondevice->{siteName}) ? $jsondevice->{siteName} : '', + group => defined($jsondevice->{groupName}) ? $jsondevice->{groupName} : '', + vendor => defined($jsondevice->{vendorName}) ? $jsondevice->{vendorName} : '', + product => defined($jsondevice->{productName}) ? $jsondevice->{productName} : '', + product_type => defined($jsondevice->{productTypeName}) ? $jsondevice->{productTypeName} : '', + version => defined($jsondevice->{versionName}) ? $jsondevice->{versionName} : '' + }; + push @{$self->{devices}}, $device; + $self->{output}->output_add( + long_msg => sprintf( + "[id: %s][name: %s][description: %s][site: %s][group: %s][vendor: %s][product: %s][product_type: %s][version: %s]", + $device->{id}, + $device->{name}, + $device->{description}, + $device->{site}, + $device->{group}, + $device->{vendor}, + $device->{product}, + $device->{product_type}, + $device->{version} + ) + ); + } + + if (!defined($options{disco_show})) { + $self->{output}->output_add(severity => 'OK', short_msg => 'Devices:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + } +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => [ 'id', 'name', 'description', 'site', 'group', 'vendor', 'product', 'product_type', 'version' ]); +} + +sub disco_show { + my ($self, %options) = @_; + + $options{disco_show} = 1; + $self->run(%options); + + for my $device (@{$self->{devices}}) { + $self->{output}->add_disco_entry( + id => $device->{id}, + name => $device->{name}, + description => $device->{description}, + site => $device->{site}, + group => $device->{group}, + vendor => $device->{vendor}, + product => $device->{product}, + product_type => $device->{product_type}, + version => $device->{version} + ); + } +} + +1; + +__END__ + +=head1 MODE + +List devices using the Backbox REST API. + +=back + +=cut + diff --git a/src/network/backbox/restapi/plugin.pm b/src/network/backbox/restapi/plugin.pm index f88a79e0ae..edf447917b 100644 --- a/src/network/backbox/restapi/plugin.pm +++ b/src/network/backbox/restapi/plugin.pm @@ -31,9 +31,11 @@ sub new { $self->{version} = '1.0'; $self->{modes} = { - 'backup' => 'network::backbox::restapi::mode::backup', - 'configstatus' => 'network::backbox::restapi::mode::configstatus', - 'intellicheck' => 'network::backbox::restapi::mode::intellicheck' + 'backup' => 'network::backbox::restapi::mode::backup', + 'device-backup' => 'network::backbox::restapi::mode::devicebackup', + 'configstatus' => 'network::backbox::restapi::mode::configstatus', + 'intellicheck' => 'network::backbox::restapi::mode::intellicheck', + 'list-devices' => 'network::backbox::restapi::mode::listdevices' }; $self->{custom_modes}->{api} = 'network::backbox::restapi::custom::api'; diff --git a/tests/network/backbox/restapi/backbox.json b/tests/network/backbox/restapi/backbox.json index 1e2761852e..0167e93d4d 100644 --- a/tests/network/backbox/restapi/backbox.json +++ b/tests/network/backbox/restapi/backbox.json @@ -94,6 +94,64 @@ } ], "responseMode": null + }, + { + "uuid": "7d03fa0c-863e-4364-84be-a4c77a75d392", + "type": "http", + "documentation": "", + "method": "post", + "endpoint": "rest/data/token/api/devices/dynamic", + "responses": [ + { + "uuid": "173704ee-4bd7-408d-8fcb-e05dd319bf77", + "body": "[\n {\n \"id\": 16949,\n \"historyStatus\": \"FAILURE\",\n \"statusReason\": \"The failed expected result was found: (No route to host)\",\n \"lastBackupDate\": 1733990419000,\n \"fileSize\": 0,\n \"fileName\": null,\n \"isDiffer\": 0,\n \"backupDuration\": \"\",\n \"optionId\": -9000314,\n \"baseline\": false,\n \"lastBackupDateForUI\": \"2024-12-12T08:00+0000\",\n \"deviceId\": 1,\n \"intelliChecksStatus\": \"0\",\n \"sameBackupPointer\": 0,\n \"inMaintenance\": false,\n \"restorable\": false,\n \"comparable\": false,\n \"retention\": null,\n \"siteId\": 0,\n \"siteName\": \"Global\",\n \"agentDownloadStatus\": -1,\n \"uploadedToRemote\": false,\n \"actionInitiator\": \"Schedule\",\n \"comment\": null,\n \"executiontype\": \"BACKUP\"\n },\n {\n \"id\": 16951,\n \"historyStatus\": \"FAILURE\",\n \"statusReason\": \"No backup data\",\n \"lastBackupDate\": 1733990403000,\n \"fileSize\": 0,\n \"fileName\": null,\n \"isDiffer\": 0,\n \"backupDuration\": \"\",\n \"optionId\": -9000143,\n \"baseline\": false,\n \"lastBackupDateForUI\": \"2024-12-12T08:00+0000\",\n \"deviceId\": 2,\n \"intelliChecksStatus\": \"\",\n \"sameBackupPointer\": 0,\n \"inMaintenance\": false,\n \"restorable\": false,\n \"comparable\": false,\n \"retention\": null,\n \"siteId\": 0,\n \"siteName\": \"Global\",\n \"agentDownloadStatus\": -1,\n \"uploadedToRemote\": false,\n \"actionInitiator\": \"Schedule\",\n \"comment\": null,\n \"executiontype\": \"BACKUP\"\n },\n {\n \"id\": 16953,\n \"historyStatus\": \"SUSPECT\",\n \"statusReason\": \"Unknown status\",\n \"lastBackupDate\": 1733990403000,\n \"fileSize\": 0,\n \"fileName\": null,\n \"isDiffer\": 0,\n \"backupDuration\": \"472\",\n \"optionId\": -275,\n \"baseline\": false,\n \"lastBackupDateForUI\": \"2024-12-12T08:00+0000\",\n \"deviceId\": 3,\n \"intelliChecksStatus\": \"0\",\n \"sameBackupPointer\": 0,\n \"inMaintenance\": false,\n \"restorable\": false,\n \"comparable\": false,\n \"retention\": null,\n \"siteId\": 0,\n \"siteName\": \"Global\",\n \"agentDownloadStatus\": -1,\n \"uploadedToRemote\": false,\n \"actionInitiator\": \"Schedule\",\n \"comment\": null,\n \"executiontype\": \"BACKUP\"\n },\n {\n \"id\": 16952,\n \"historyStatus\": \"SUCCESS\",\n \"statusReason\": \"\",\n \"lastBackupDate\": 1733990403000,\n \"fileSize\": 0,\n \"fileName\": null,\n \"isDiffer\": 0,\n \"backupDuration\": \"537\",\n \"optionId\": -509,\n \"baseline\": false,\n \"lastBackupDateForUI\": \"2024-12-12T08:00+0000\",\n \"deviceId\": 4,\n \"intelliChecksStatus\": \"\",\n \"sameBackupPointer\": 0,\n \"inMaintenance\": false,\n \"restorable\": false,\n \"comparable\": false,\n \"retention\": null,\n \"siteId\": 0,\n \"siteName\": \"Global\",\n \"agentDownloadStatus\": -1,\n \"uploadedToRemote\": false,\n \"actionInitiator\": \"Schedule\",\n \"comment\": null,\n \"executiontype\": \"BACKUP\"\n },\n {\n \"id\": 16954,\n \"historyStatus\": \"SUCCESS\",\n \"statusReason\": \"\",\n \"lastBackupDate\": 1733990403000,\n \"fileSize\": 0,\n \"fileName\": null,\n \"isDiffer\": 0,\n \"backupDuration\": \"143\",\n \"optionId\": -9000430,\n \"baseline\": false,\n \"lastBackupDateForUI\": \"2024-12-12T08:00+0000\",\n \"deviceId\": 5,\n \"intelliChecksStatus\": \"0\",\n \"sameBackupPointer\": 0,\n \"inMaintenance\": false,\n \"restorable\": false,\n \"comparable\": false,\n \"retention\": null,\n \"siteId\": 0,\n \"siteName\": \"Global\",\n \"agentDownloadStatus\": -1,\n \"uploadedToRemote\": false,\n \"actionInitiator\": \"Schedule\",\n \"comment\": null,\n \"executiontype\": \"BACKUP\"\n }\n]", + "latency": 0, + "statusCode": 200, + "label": "", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": true, + "crudKey": "id", + "callbacks": [] + } + ], + "responseMode": null + }, + { + "uuid": "709c7a4e-f6d2-41f7-91be-b6373756b619", + "type": "http", + "documentation": "", + "method": "get", + "endpoint": "rest/data/token/api/devices", + "responses": [ + { + "uuid": "4f4823f9-4470-4833-b129-3f69d452e937", + "body": "[\n {\n \"deviceName\": \"Cisco C8000\",\n \"siteId\": 0,\n \"host\": \"192.168.1.1\",\n \"vendorId\": 5,\n \"productId\": 56,\n \"versionId\": 97,\n \"optionId\": 55697,\n \"groupId\": 1,\n \"retentionId\": 0,\n \"port\": 22,\n \"debugMode\": false,\n \"authenticationType\": \"1\",\n \"authenticationTemplateIds\": null,\n \"userName\": \"admin\",\n \"password\": \"safeway_blank\",\n \"su\": \"\",\n \"suPassword\": \"safeway_blank\",\n \"prompt\": null,\n \"commandUserName\": \"\",\n \"commandPassword\": \"safeway_blank\",\n \"snmpCommunity\": \"safeway_blank\",\n \"snmpVersion\": \"\",\n \"serverIp\": null,\n \"agentId\": 0,\n \"backupSizeDeviation\": false,\n \"natHost\": \"\",\n \"description\": null,\n \"backupSizeDeviationPercentage\": null,\n \"externalId\": \"FD12345\",\n \"enableAccess\": false,\n \"inMaintenanceMode\": false,\n \"enableIntelliChecks\": false,\n \"collected\": false,\n \"compareExceptions\": null,\n \"notes\": null,\n \"deviceAccessDetails\": null,\n \"enableNvm\": false,\n \"deviceId\": 1,\n \"notesId\": 0,\n \"groupName\": null,\n \"vendorName\": null,\n \"productName\": null,\n \"versionName\": null,\n \"siteName\": null,\n \"optionName\": null,\n \"productType\": null,\n \"productTypeName\": null,\n \"lastBackupDate\": 1733918420000,\n \"lastBackupDateToShow\": \"2024-12-11 12:00:20.0\",\n \"lastBackupId\": 16888,\n \"retention\": null,\n \"agentName\": null,\n \"backupCustomField1\": null,\n \"backupCustomField2\": null,\n \"intelliChecksStatus\": null,\n \"agentGroupId\": 0,\n \"deviceCustomFields\": null,\n \"optionCustomFields\": null,\n \"lastSuccessfulBackupDate\": \"2024-11-06 12:00:45.0\",\n \"configurationChanged\": \"no\",\n \"discoverySnmpRespond\": false,\n \"backupSize\": null,\n \"failureReason\": null,\n \"backupFailureRetry\": 0,\n \"backupFailureRetrySleepTime\": 0,\n \"cloudVault\": null,\n \"technicalSurveyItems\": null\n },\n {\n \"deviceName\": \"Palo Alto Firewall\",\n \"siteId\": 0,\n \"host\": \"192.168.1.2\",\n \"vendorId\": 48,\n \"productId\": 13,\n \"versionId\": 45,\n \"optionId\": 481345,\n \"groupId\": 1,\n \"retentionId\": 0,\n \"port\": 22,\n \"debugMode\": false,\n \"authenticationType\": \"1\",\n \"authenticationTemplateIds\": null,\n \"userName\": \"admin\",\n \"password\": \"safeway_blank\",\n \"su\": \"\",\n \"suPassword\": \"safeway_blank\",\n \"prompt\": null,\n \"commandUserName\": \"\",\n \"commandPassword\": \"safeway_blank\",\n \"snmpCommunity\": \"safeway_blank\",\n \"snmpVersion\": \"\",\n \"serverIp\": null,\n \"agentId\": 0,\n \"backupSizeDeviation\": false,\n \"natHost\": \"\",\n \"description\": null,\n \"backupSizeDeviationPercentage\": null,\n \"externalId\": null,\n \"enableAccess\": false,\n \"inMaintenanceMode\": false,\n \"enableIntelliChecks\": false,\n \"collected\": false,\n \"compareExceptions\": null,\n \"notes\": null,\n \"deviceAccessDetails\": null,\n \"enableNvm\": false,\n \"deviceId\": 2,\n \"notesId\": 0,\n \"groupName\": null,\n \"vendorName\": null,\n \"productName\": null,\n \"versionName\": null,\n \"siteName\": null,\n \"optionName\": null,\n \"productType\": null,\n \"productTypeName\": null,\n \"lastBackupDate\": 1733918401000,\n \"lastBackupDateToShow\": \"2024-12-11 12:00:01.0\",\n \"lastBackupId\": 16890,\n \"retention\": null,\n \"agentName\": null,\n \"backupCustomField1\": null,\n \"backupCustomField2\": null,\n \"intelliChecksStatus\": null,\n \"agentGroupId\": 0,\n \"deviceCustomFields\": null,\n \"optionCustomFields\": null,\n \"lastSuccessfulBackupDate\": \"2024-11-06 12:00:03.0\",\n \"configurationChanged\": \"no\",\n \"discoverySnmpRespond\": false,\n \"backupSize\": null,\n \"failureReason\": null,\n \"backupFailureRetry\": 0,\n \"backupFailureRetrySleepTime\": 0,\n \"cloudVault\": null,\n \"technicalSurveyItems\": null\n },\n {\n \"deviceName\": \"Fortinet Fortigate\",\n \"siteId\": 0,\n \"host\": \"192.168.1.3\",\n \"vendorId\": 34,\n \"productId\": 80,\n \"versionId\": 12,\n \"optionId\": 348012,\n \"groupId\": 2,\n \"retentionId\": 0,\n \"port\": 22,\n \"debugMode\": false,\n \"authenticationType\": \"1\",\n \"authenticationTemplateIds\": null,\n \"userName\": \"admin\",\n \"password\": \"safeway_blank\",\n \"su\": \"\",\n \"suPassword\": \"safeway_blank\",\n \"prompt\": null,\n \"commandUserName\": \"\",\n \"commandPassword\": \"safeway_blank\",\n \"snmpCommunity\": \"safeway_blank\",\n \"snmpVersion\": \"\",\n \"serverIp\": null,\n \"agentId\": 0,\n \"backupSizeDeviation\": false,\n \"natHost\": \"\",\n \"description\": null,\n \"backupSizeDeviationPercentage\": null,\n \"externalId\": null,\n \"enableAccess\": false,\n \"inMaintenanceMode\": false,\n \"enableIntelliChecks\": false,\n \"collected\": false,\n \"compareExceptions\": null,\n \"notes\": null,\n \"deviceAccessDetails\": null,\n \"enableNvm\": false,\n \"deviceId\": 3,\n \"notesId\": 0,\n \"groupName\": null,\n \"vendorName\": null,\n \"productName\": null,\n \"versionName\": null,\n \"siteName\": null,\n \"optionName\": null,\n \"productType\": null,\n \"productTypeName\": null,\n \"lastBackupDate\": 1733918403000,\n \"lastBackupDateToShow\": \"2024-12-11 12:00:03.0\",\n \"lastBackupId\": 16892,\n \"retention\": null,\n \"agentName\": null,\n \"backupCustomField1\": null,\n \"backupCustomField2\": null,\n \"intelliChecksStatus\": null,\n \"agentGroupId\": 0,\n \"deviceCustomFields\": null,\n \"optionCustomFields\": null,\n \"lastSuccessfulBackupDate\": \"2024-11-06 12:00:03.0\",\n \"configurationChanged\": \"no\",\n \"discoverySnmpRespond\": false,\n \"backupSize\": null,\n \"failureReason\": null,\n \"backupFailureRetry\": 0,\n \"backupFailureRetrySleepTime\": 0,\n \"cloudVault\": null,\n \"technicalSurveyItems\": null\n },\n {\n \"deviceName\": \"Juniper SRX\",\n \"siteId\": 0,\n \"host\": \"192.168.1.4\",\n \"vendorId\": 8,\n \"productId\": 93,\n \"versionId\": 42,\n \"optionId\": 89342,\n \"groupId\": 2,\n \"retentionId\": 0,\n \"port\": 22,\n \"debugMode\": false,\n \"authenticationType\": \"1\",\n \"authenticationTemplateIds\": null,\n \"userName\": \"root\",\n \"password\": \"safeway_blank\",\n \"su\": \"\",\n \"suPassword\": \"safeway_blank\",\n \"prompt\": null,\n \"commandUserName\": \"\",\n \"commandPassword\": \"safeway_blank\",\n \"snmpCommunity\": \"safeway_blank\",\n \"snmpVersion\": \"\",\n \"serverIp\": null,\n \"agentId\": 0,\n \"backupSizeDeviation\": false,\n \"natHost\": null,\n \"description\": null,\n \"backupSizeDeviationPercentage\": null,\n \"externalId\": null,\n \"enableAccess\": false,\n \"inMaintenanceMode\": false,\n \"enableIntelliChecks\": false,\n \"collected\": false,\n \"compareExceptions\": null,\n \"notes\": null,\n \"deviceAccessDetails\": null,\n \"enableNvm\": false,\n \"deviceId\": 4,\n \"notesId\": 0,\n \"groupName\": null,\n \"vendorName\": null,\n \"productName\": null,\n \"versionName\": null,\n \"siteName\": null,\n \"optionName\": null,\n \"productType\": null,\n \"productTypeName\": null,\n \"lastBackupDate\": 1733918401000,\n \"lastBackupDateToShow\": \"2024-12-11 12:00:01.0\",\n \"lastBackupId\": 16891,\n \"retention\": null,\n \"agentName\": null,\n \"backupCustomField1\": null,\n \"backupCustomField2\": null,\n \"intelliChecksStatus\": null,\n \"agentGroupId\": 0,\n \"deviceCustomFields\": null,\n \"optionCustomFields\": null,\n \"lastSuccessfulBackupDate\": \"2024-11-06 12:00:01.0\",\n \"configurationChanged\": \"no\",\n \"discoverySnmpRespond\": false,\n \"backupSize\": null,\n \"failureReason\": null,\n \"backupFailureRetry\": 0,\n \"backupFailureRetrySleepTime\": 0,\n \"cloudVault\": null,\n \"technicalSurveyItems\": null\n },\n {\n \"deviceName\": \"Cisco ASA\",\n \"siteId\": 0,\n \"host\": \"192.168.1.5\",\n \"vendorId\": 5,\n \"productId\": 46,\n \"versionId\": 24,\n \"optionId\": 54624,\n \"groupId\": 0,\n \"retentionId\": 0,\n \"port\": 22,\n \"debugMode\": false,\n \"authenticationType\": \"1\",\n \"authenticationTemplateIds\": null,\n \"userName\": \"backbox\",\n \"password\": \"safeway_blank\",\n \"su\": \"\",\n \"suPassword\": \"safeway_blank\",\n \"prompt\": null,\n \"commandUserName\": \"\",\n \"commandPassword\": \"safeway_blank\",\n \"snmpCommunity\": \"safeway_blank\",\n \"snmpVersion\": \"\",\n \"serverIp\": null,\n \"agentId\": 0,\n \"backupSizeDeviation\": false,\n \"natHost\": \"\",\n \"description\": null,\n \"backupSizeDeviationPercentage\": null,\n \"externalId\": null,\n \"enableAccess\": false,\n \"inMaintenanceMode\": false,\n \"enableIntelliChecks\": false,\n \"collected\": false,\n \"compareExceptions\": null,\n \"notes\": null,\n \"deviceAccessDetails\": null,\n \"enableNvm\": false,\n \"deviceId\": 5,\n \"notesId\": 0,\n \"groupName\": null,\n \"vendorName\": null,\n \"productName\": null,\n \"versionName\": null,\n \"siteName\": null,\n \"optionName\": null,\n \"productType\": null,\n \"productTypeName\": null,\n \"lastBackupDate\": 1733918403000,\n \"lastBackupDateToShow\": \"2024-12-11 12:00:03.0\",\n \"lastBackupId\": 16893,\n \"retention\": null,\n \"agentName\": null,\n \"backupCustomField1\": null,\n \"backupCustomField2\": null,\n \"intelliChecksStatus\": null,\n \"agentGroupId\": 0,\n \"deviceCustomFields\": null,\n \"optionCustomFields\": null,\n \"lastSuccessfulBackupDate\": \"2024-11-06 12:00:01.0\",\n \"configurationChanged\": \"no\",\n \"discoverySnmpRespond\": false,\n \"backupSize\": null,\n \"failureReason\": null,\n \"backupFailureRetry\": 0,\n \"backupFailureRetrySleepTime\": 0,\n \"cloudVault\": null,\n \"technicalSurveyItems\": null\n }\n]", + "latency": 0, + "statusCode": 200, + "label": "", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": true, + "crudKey": "id", + "callbacks": [] + } + ], + "responseMode": null } ], "rootChildren": [ @@ -108,6 +166,14 @@ { "type": "route", "uuid": "101f818e-0ef5-4468-8c2a-f0f7ab2f1d49" + }, + { + "type": "route", + "uuid": "7d03fa0c-863e-4364-84be-a4c77a75d392" + }, + { + "type": "route", + "uuid": "709c7a4e-f6d2-41f7-91be-b6373756b619" } ], "proxyMode": false, diff --git a/tests/network/backbox/restapi/devicebackup.robot b/tests/network/backbox/restapi/devicebackup.robot new file mode 100644 index 0000000000..713435cfd8 --- /dev/null +++ b/tests/network/backbox/restapi/devicebackup.robot @@ -0,0 +1,48 @@ +*** Settings *** +Documentation Check a device backup status + +Resource ${CURDIR}${/}..${/}..${/}..${/}resources/import.resource + +Suite Setup Start Mockoon ${MOCKOON_JSON} +Suite Teardown Stop Mockoon +Test Timeout 120s + + +*** Variables *** +${MOCKOON_JSON} ${CURDIR}${/}backbox.json +${HOSTNAME} 127.0.0.1 +${APIPORT} 3000 + +${cmd} ${CENTREON_PLUGINS} +... --plugin=network::backbox::restapi::plugin +... --custommode=api +... --hostname=${HOSTNAME} +... --port=${APIPORT} +... --proto=http +... --api-token=token +... --mode=device-backup + +*** Test Cases *** +Device backup ${tc} + [Documentation] Check a device backup status + [Tags] network backbox restapi backup + ${command} Catenate + ... ${cmd} + ... ${extraoptions} + Log ${cmd} + Ctn Run Command And Check Result As Strings ${command} ${expected_result} + + Examples: tc extraoptions expected_result -- + ... 1 ${EMPTY} UNKNOWN: Need to specify --device-id or --device-name option. + ... 2 --device-name="Juniper SRX" OK: Device [id: 4] [name: Juniper SRX] [status: SUCCESS] [status reason: ] + ... 3 --device-id=4 OK: Device [id: 4] [name: ] [status: SUCCESS] [status reason: ] + ... 4 --device-name="Juniper SRX" --device-id=4 OK: Device [id: 4] [name: Juniper SRX] [status: SUCCESS] [status reason: ] + ... 5 --device-name="Cisco C8000" CRITICAL: Device [id: 1] [name: Cisco C8000] [status: FAILURE] [status reason: The failed expected result was found: (No route to host)] + ... 6 --device-id=1 CRITICAL: Device [id: 1] [name: ] [status: FAILURE] [status reason: The failed expected result was found: (No route to host)] + ... 7 --device-name="Fortinet Fortigate" WARNING: Device [id: 3] [name: Fortinet Fortigate] [status: SUSPECT] [status reason: Unknown status] + ... 8 --device-id=3 WARNING: Device [id: 3] [name: ] [status: SUSPECT] [status reason: Unknown status] + ... 9 --device-id=3 --critical-status='\\\%{status} =~ /FAILURE|SUSPECT/i' CRITICAL: Device [id: 3] [name: ] [status: SUSPECT] [status reason: Unknown status] + ... 10 --device-id=1 --warning-status='\\\%{status} =~ /FAILURE|SUSPECT/i' --critical-status='' WARNING: Device [id: 1] [name: ] [status: FAILURE] [status reason: The failed expected result was found: (No route to host)] + ... 11 --device-id=3 --critical-status='\\\%{status_reason} =~ /unknown/i' CRITICAL: Device [id: 3] [name: ] [status: SUSPECT] [status reason: Unknown status] + ... 12 --device-name="Fortinet Fortigate" --critical-status='\\\%{device_name} =~ /Fortinet/i' CRITICAL: Device [id: 3] [name: Fortinet Fortigate] [status: SUSPECT] [status reason: Unknown status] + ... 13 --device-name="Fortinet Fortigate" --critical-status='\\\%{device_id} == 3' CRITICAL: Device [id: 3] [name: Fortinet Fortigate] [status: SUSPECT] [status reason: Unknown status] diff --git a/tests/network/backbox/restapi/listdevices.robot b/tests/network/backbox/restapi/listdevices.robot new file mode 100644 index 0000000000..37de3b6931 --- /dev/null +++ b/tests/network/backbox/restapi/listdevices.robot @@ -0,0 +1,37 @@ +*** Settings *** +Documentation Test the Backbox list-devices mode + +Resource ${CURDIR}${/}..${/}..${/}..${/}resources/import.resource + +Suite Setup Start Mockoon ${MOCKOON_JSON} +Suite Teardown Stop Mockoon +Test Timeout 120s + + +*** Variables *** +${MOCKOON_JSON} ${CURDIR}${/}backbox.json +${HOSTNAME} 127.0.0.1 +${APIPORT} 3000 + +${cmd} ${CENTREON_PLUGINS} +... --plugin=network::backbox::restapi::plugin +... --custommode=api +... --hostname=${HOSTNAME} +... --port=${APIPORT} +... --proto=http +... --api-token=token +... --mode=list-devices + +*** Test Cases *** +List-Devices ${tc} + [Documentation] Check list-devices results + [Tags] network backbox restapi list-devices + ${command} Catenate + ... ${cmd} + ... ${extraoptions} + Ctn Run Command And Check Result As Regexp ${command} ${expected_result} + + Examples: tc extraoptions expected_result -- + ... 1 ${EMPTY} ^Devices: (\\\\n\\\\[.*\\\\]){5}\\\\Z + ... 2 --disco-show \\\\<\\\\?xml version="1.0" encoding="utf-8"\\\\?\\\\>\\\\n\\\\(\\\\n\\\\s*\\\\