From d40ae9bb6d3b418e67ac32d7cb53405b330a3fd8 Mon Sep 17 00:00:00 2001 From: sfarouq-ext <116093375+sfarouq-ext@users.noreply.github.com> Date: Thu, 20 Feb 2025 10:10:29 +0100 Subject: [PATCH] enh(purestorage-flasharray): add handling of 'flagged' information + tests to alerts mode (#5403) Co-authored-by: Fabien-Bernard <78682398+Fabien-Bernard@users.noreply.github.com> Refs: CTOR-1218 --- .../flasharray/v2/restapi/mode/alerts.pm | 8 +- .../flasharray/v2/restapi/alerts.robot | 35 +++++ .../flasharray/v2/restapi/mokoon.json | 130 ++++++++++++++++++ 3 files changed, 169 insertions(+), 4 deletions(-) create mode 100644 tests/storage/purestorage/flasharray/v2/restapi/alerts.robot create mode 100644 tests/storage/purestorage/flasharray/v2/restapi/mokoon.json diff --git a/src/storage/purestorage/flasharray/v2/restapi/mode/alerts.pm b/src/storage/purestorage/flasharray/v2/restapi/mode/alerts.pm index c3a423a5a..4692ab5d1 100644 --- a/src/storage/purestorage/flasharray/v2/restapi/mode/alerts.pm +++ b/src/storage/purestorage/flasharray/v2/restapi/mode/alerts.pm @@ -58,7 +58,7 @@ sub set_counters { key_values => [ { name => 'category' }, { name => 'code' }, { name => 'severity' }, { name => 'opened' }, { name => 'state' }, - { name => 'component_name' }, { name => 'issue' } + { name => 'component_name' }, { name => 'issue' }, { name => 'flagged' } ], closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, @@ -98,7 +98,7 @@ sub manage_selection { my $last_time; if (defined($self->{option_results}->{memory})) { - $self->{statefile_cache}->read(statefile => 'purestorage_' . $self->{mode} . '_' . $options{custom}->get_connection_infos()); + $self->{statefile_cache}->read(statefile => 'purestorage_' . $self->{mode} . '_' . $options{custom}->get_connection_info()); $last_time = $self->{statefile_cache}->get(name => 'last_time'); } @@ -166,12 +166,12 @@ Filter by category name (can be a regexp). =item B<--warning-status> Define the conditions to match for the status to be WARNING (default: '%{state} ne "closed" and %{severity} =~ /warning/i') -You can use the following variables: %{category}, %{code}, %{severity}, %{opened}, %{state}, %{issue}, %{component_name} +You can use the following variables: %{category}, %{code}, %{severity}, %{opened}, %{state}, %{issue}, %{component_name}, %{flagged} =item B<--critical-status> Define the conditions to match for the status to be CRITICAL (default: '%{state} ne "closed" and %{severity} =~ /critical/i'). -You can use the following variables: %{category}, %{code}, %{severity}, %{opened}, %{state}, %{issue}, %{component_name} +You can use the following variables: %{category}, %{code}, %{severity}, %{opened}, %{state}, %{issue}, %{component_name}, %{flagged} =item B<--memory> diff --git a/tests/storage/purestorage/flasharray/v2/restapi/alerts.robot b/tests/storage/purestorage/flasharray/v2/restapi/alerts.robot new file mode 100644 index 000000000..8a5589e24 --- /dev/null +++ b/tests/storage/purestorage/flasharray/v2/restapi/alerts.robot @@ -0,0 +1,35 @@ +*** Settings *** + +Resource ${CURDIR}${/}..${/}..${/}..${/}..${/}..${/}resources/import.resource + +Suite Setup Start Mockoon ${MOCKOON_JSON} +Suite Teardown Stop Mockoon +Test Timeout 120s + +** Variables *** +${MOCKOON_JSON} ${CURDIR}${/}mokoon.json + +${CMD} ${CENTREON_PLUGINS} +... --plugin=storage::purestorage::flasharray::v2::restapi::plugin +... --mode=alerts +... --hostname=${HOSTNAME} +... --proto='http' +... --api-version='2.4' +... --api-token='token' +... --port=${APIPORT} + +*** Test Cases *** +alerts ${tc} + [Tags] storage purestorage flasharray restapi + ${command} Catenate + ... ${CMD} + ... ${extra_options} + Ctn Verify Command Output ${command} ${expected_result} + + Examples: tc extra_options expected_result -- + ... 1 ${EMPTY} CRITICAL: 1 problem(s) detected | 'alerts.detected.count'=1;;;0; + ... 2 --filter-category='array' CRITICAL: 1 problem(s) detected | 'alerts.detected.count'=1;;;0; + ... 3 --warning-status='\\\%{component_name} eq "ct1.eth0"' --filter-category="toto" --insecure --verbose WARNING: 1 problem(s) detected | 'alerts.detected.count'=1;;;0; warning: alert [component: ct1.eth0] [severity: warning] [category: toto] [issue: failure] + ... 4 --critical-status='\\\%{component_name} eq "ch0" and \\\%{severity} =~ /critical/i' --filter-category="array" --insecure --verbose CRITICAL: 1 problem(s) detected | 'alerts.detected.count'=1;;;0; critical: alert [component: ch0] [severity: critical] [category: array] [issue: shelf drive failures(s)] + ... 5 --memory CRITICAL: 1 problem(s) detected | 'alerts.detected.count'=1;;;0; #first memory alert to be defined + ... 6 --memory OK: 0 problem(s) detected | 'alerts.detected.count'=0;;;0; #second check to ensure no new memory alert \ No newline at end of file diff --git a/tests/storage/purestorage/flasharray/v2/restapi/mokoon.json b/tests/storage/purestorage/flasharray/v2/restapi/mokoon.json new file mode 100644 index 000000000..94e6e4ac3 --- /dev/null +++ b/tests/storage/purestorage/flasharray/v2/restapi/mokoon.json @@ -0,0 +1,130 @@ +{ + "uuid": "cf22c628-8819-46d3-b1b7-fc46f3aee39b", + "lastMigration": 32, + "name": "Mokoon", + "endpointPrefix": "", + "latency": 0, + "port": 3000, + "hostname": "", + "folders": [], + "routes": [ + { + "uuid": "98036266-a85e-484f-9af8-26690151180c", + "type": "http", + "documentation": "", + "method": "post", + "endpoint": "api/2.4/login", + "responses": [ + { + "uuid": "ad6920b9-8a22-4ffc-b066-936819921ba0", + "body": "{\r\n \"continuation_token\": null,\r\n \"items\": [\r\n {\r\n \"created\": 1737462338078,\r\n \"state\": \"closed\",\r\n \"description\": \"(drive:ch0.nvb1): failure Expected: healthy, Actual: failed\",\r\n \"component_type\": \"drive\",\r\n \"name\": \"81204734\",\r\n \"id\": \"5576557655765576557655765576\",\r\n \"code\": 60,\r\n \"category\": \"array\",\r\n \"severity\": \"warning\",\r\n \"flagged\": false,\r\n \"updated\": null,\r\n \"closed\": null,\r\n \"notified\": null,\r\n \"component_name\": \"ch0.nvb1\",\r\n \"expected\": \"healthy\",\r\n \"actual\": \"failed\",\r\n \"knowledge_base_url\": \"https://support.purestorage.com/?cid=Alert_0060\",\r\n \"summary\": \"(drive:ch0.nvb1): failure\",\r\n \"issue\": \"failure\"\r\n },\r\n {\r\n \"created\": 1737464651017,\r\n \"state\": \"open\",\r\n \"description\": \"(shelf:ch0): shelf drive failures(s) Expected: 0, Actual: 1\",\r\n \"component_type\": \"shelf\",\r\n \"name\": \"81204806\",\r\n \"id\": \"f823f823f823f823f823f823f823\",\r\n \"code\": 60,\r\n \"category\": \"array\",\r\n \"severity\": \"critical\",\r\n \"flagged\": true,\r\n \"updated\": null,\r\n \"closed\": null,\r\n \"notified\": null,\r\n \"component_name\": \"ch0\",\r\n \"expected\": \"0\",\r\n \"actual\": \"1\",\r\n \"knowledge_base_url\": \"https://support.purestorage.com/?cid=Alert_0060\",\r\n \"summary\": \"(shelf:ch0): shelf drive failures(s)\",\r\n \"issue\": \"shelf drive failures(s)\"\r\n },\r\n {\r\n \"created\": 1536744300846,\r\n \"description\": \"(hardware:ct1.eth0): failure Expected: , Actual: \",\r\n \"state\": \"closed\",\r\n \"component_type\": \"hardware\",\r\n \"name\": \"10088780\",\r\n \"id\": \"18525aa28bee4eb3a68eb901c1483fea\",\r\n \"category\": \"array\",\r\n \"severity\": \"warning\",\r\n \"code\": 42,\r\n \"flagged\": false,\r\n \"updated\": null,\r\n \"closed\": null,\r\n \"notified\": null,\r\n \"component_name\": \"ct1.eth0\",\r\n \"expected\": \"\",\r\n \"actual\": \"\",\r\n \"knowledge_base_url\": \"https://support.purestorage.com/?cid=Alert_0042\",\r\n \"issue\": \"failure\",\r\n \"summary\": \"(hardware:ct1.eth0): failure\"\r\n }\r\n ],\r\n \"more_items_remaining\": false,\r\n \"total_item_count\": null\r\n}", + "latency": 0, + "statusCode": 200, + "label": "", + "headers": [ + { + "key": "x-auth-token", + "value": "token" + } + ], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": true, + "crudKey": "id", + "callbacks": [] + } + ], + "responseMode": null + }, + { + "uuid": "5c108f96-531d-43e3-b7cc-38cf5aa5dca9", + "type": "http", + "documentation": "", + "method": "get", + "endpoint": "api/2.4/alerts", + "responses": [ + { + "uuid": "31a6a6d7-7c12-4269-9783-14c6e42be22e", + "body": "{\r\n \"continuation_token\": null,\r\n \"items\": [\r\n {\r\n \"created\": 1737462338078,\r\n \"state\": \"closed\",\r\n \"description\": \"(drive:ch0.nvb1): failure Expected: healthy, Actual: failed\",\r\n \"component_type\": \"drive\",\r\n \"name\": \"81204734\",\r\n \"id\": \"5576557655765576557655765576\",\r\n \"code\": 60,\r\n \"category\": \"array\",\r\n \"severity\": \"warning\",\r\n \"flagged\": false,\r\n \"updated\": null,\r\n \"closed\": null,\r\n \"notified\": null,\r\n \"component_name\": \"ch0.nvb1\",\r\n \"expected\": \"healthy\",\r\n \"actual\": \"failed\",\r\n \"knowledge_base_url\": \"https://support.purestorage.com/?cid=Alert_0060\",\r\n \"summary\": \"(drive:ch0.nvb1): failure\",\r\n \"issue\": \"failure\"\r\n },\r\n {\r\n \"created\": 1737464651017,\r\n \"state\": \"open\",\r\n \"description\": \"(shelf:ch0): shelf drive failures(s) Expected: 0, Actual: 1\",\r\n \"component_type\": \"shelf\",\r\n \"name\": \"81204806\",\r\n \"id\": \"f823f823f823f823f823f823f823\",\r\n \"code\": 60,\r\n \"category\": \"array\",\r\n \"severity\": \"critical\",\r\n \"flagged\": true,\r\n \"updated\": null,\r\n \"closed\": null,\r\n \"notified\": null,\r\n \"component_name\": \"ch0\",\r\n \"expected\": \"0\",\r\n \"actual\": \"1\",\r\n \"knowledge_base_url\": \"https://support.purestorage.com/?cid=Alert_0060\",\r\n \"summary\": \"(shelf:ch0): shelf drive failures(s)\",\r\n \"issue\": \"shelf drive failures(s)\"\r\n },\r\n {\r\n \"created\": 1536744300846,\r\n \"description\": \"(hardware:ct1.eth0): failure Expected: , Actual: \",\r\n \"state\": \"closed\",\r\n \"component_type\": \"hardware\",\r\n \"name\": \"10088780\",\r\n \"id\": \"18525aa28bee4eb3a68eb901c1483fea\",\r\n \"category\": \"toto\",\r\n \"severity\": \"warning\",\r\n \"code\": 42,\r\n \"flagged\": false,\r\n \"updated\": null,\r\n \"closed\": null,\r\n \"notified\": null,\r\n \"component_name\": \"ct1.eth0\",\r\n \"expected\": \"\",\r\n \"actual\": \"\",\r\n \"knowledge_base_url\": \"https://support.purestorage.com/?cid=Alert_0042\",\r\n \"issue\": \"failure\",\r\n \"summary\": \"(hardware:ct1.eth0): failure\"\r\n }\r\n ],\r\n \"more_items_remaining\": false,\r\n \"total_item_count\": null\r\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": [ + { + "type": "route", + "uuid": "98036266-a85e-484f-9af8-26690151180c" + }, + { + "type": "route", + "uuid": "5c108f96-531d-43e3-b7cc-38cf5aa5dca9" + } + ], + "proxyMode": false, + "proxyHost": "", + "proxyRemovePrefix": false, + "tlsOptions": { + "enabled": false, + "type": "CERT", + "pfxPath": "", + "certPath": "", + "keyPath": "", + "caPath": "", + "passphrase": "" + }, + "cors": true, + "headers": [ + { + "key": "Content-Type", + "value": "application/json" + }, + { + "key": "Access-Control-Allow-Origin", + "value": "*" + }, + { + "key": "Access-Control-Allow-Methods", + "value": "GET,POST,PUT,PATCH,DELETE,HEAD,OPTIONS" + }, + { + "key": "Access-Control-Allow-Headers", + "value": "Content-Type, Origin, Accept, Authorization, Content-Length, X-Requested-With" + } + ], + "proxyReqHeaders": [ + { + "key": "", + "value": "" + } + ], + "proxyResHeaders": [ + { + "key": "", + "value": "" + } + ], + "data": [], + "callbacks": [] +} \ No newline at end of file