Skip to content

Commit

Permalink
Plugin(cloud::azure::network::vpngateway::plugin) - Mode(vpn-gateway-…
Browse files Browse the repository at this point in the history
…status) : Wrong variable assignment (#5342)

Co-authored-by: sdepassio <[email protected]>
Co-authored-by: omercier <[email protected]>
Refs: CTOR-1073
  • Loading branch information
3 people authored Feb 20, 2025
1 parent 0d10876 commit 48f85e3
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 32 deletions.
14 changes: 7 additions & 7 deletions src/cloud/azure/network/vpngateway/mode/health.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ Set resource group (required if resource's name is used).
=item B<--warning-status>
Define the conditions to match for the status to be WARNING (default: '').
You can use the following variables: %{status}, %{summary}
You can use the following variables: C<%{status}>, C<%{summary}>.
=item B<--critical-status>
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /^Unavailable$/').
You can use the following variables: %{status}, %{summary}
Define the conditions to match for the status to be CRITICAL (default: C<'%{status} =~ /^Unavailable$/'>).
You can use the following variables: C<%{status}>, C<%{summary}>.
=item B<--unknown-status>
Define the conditions to match for the status to be UNKNOWN (default: '%{status} =~ /^Unknown$/').
You can use the following variables: %{status}, %{summary}
Define the conditions to match for the status to be UNKNOWN (default: C<'%{status} =~ /^Unknown$/'>).
You can use the following variables: C<%{status}>, C<%{summary}>.
=item B<--ok-status>
Define the conditions to match for the status to be OK (default: '%{status} =~ /^Available$/').
You can use the following variables: %{status}, %{summary}
Define the conditions to match for the status to be OK (default: C<'%{status} =~ /^Available$/''>).
You can use the following variables: C<%{status}>, C<%{summary}>.
=back
Expand Down
37 changes: 24 additions & 13 deletions src/cloud/azure/network/vpngateway/mode/sitetraffic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,11 @@ Example:
Using resource name:
perl centreon_plugins.pl --plugin=cloud::azure::network::vpngateway::plugin --custommode=azcli --mode=site-traffic
--resource=MyResource --resource-group=MYRGROUP --aggregation='average' --aggregation='total' --critical-bandwidth-average='10'
--verbose
C<perl centreon_plugins.pl --plugin=cloud::azure::network::vpngateway::plugin --custommode=azcli --mode=site-traffic --resource=MyResource --resource-group=MYRGROUP --aggregation='average' --aggregation='total' --critical-bandwidth-average='10' --verbose>
Using resource ID:
perl centreon_plugins.pl --plugin=cloud::azure::network::vpngateway::plugin --custommode=azcli --mode=site-traffic
--resource='/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Network/virtualNetworkGateways/xxx'
--aggregation='average' --aggregation='total' --critical-bandwidth-average='10' --verbose
C<perl centreon_plugins.pl --plugin=cloud::azure::network::vpngateway::plugin --custommode=azcli --mode=site-traffic --resource='/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Network/virtualNetworkGateways/xxx' --aggregation='average' --aggregation='total' --critical-bandwidth-average='10' --verbose>
Default aggregation: 'average' (*Bandwidth), 'total' (P2SConnectionCount)
Expand All @@ -153,18 +149,33 @@ Set resource group (required if resource's name is used).
=item B<--filter-metric>
Filter metrics (can be: 'AverageBandwidth', 'P2SBandwidth', 'P2SConnectionCount')
Filter metrics (can be: C<AverageBandwidth>, C<P2SBandwidth>, C<P2SConnectionCount>)
(can be a regexp).
=item B<--warning-$label$>
Warning thresholds
($label$ can be: 'bandwidth-average', 'p2s-bandwidth', p2s-connections)
=item B<--warning-bandwidth-average>
=item B<--critical-$label$>
Thresholds.
Critical thresholds
($label$ can be: 'bandwidth-average', 'p2s-bandwidth', p2s-connections)
=item B<--critical-bandwidth-average>
Thresholds.
=item B<--warning-p2s-bandwidth>
Thresholds.
=item B<--critical-p2s-bandwidth>
Thresholds.
=item B<--warning-p2s-connections>
Thresholds.
=item B<--critical-p2s-connections>
Thresholds.
=back
Expand Down
53 changes: 47 additions & 6 deletions src/cloud/azure/network/vpngateway/mode/tunneltraffic.pm
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#
# Copyright 2024 Centreon (http://www.centreon.com/)
#
Expand Down Expand Up @@ -175,15 +176,55 @@ Filter metrics (can be: 'TunnelIngressBytes', 'TunnelEgressBytes', 'TunnelIngres
'TunnelEgressPackets', 'TunnelIngressPacketDropTSMismatch', 'TunnelEgressPacketDropTSMismatch')
(can be a regexp).
=item B<--warning-$label$>
=item B<--warning-traffic-in>
Thresholds.
=item B<--critical-traffic-in>
Thresholds.
=item B<--warning-traffic-out>
Thresholds.
=item B<--critical-traffic-out>
Thresholds.
=item B<--warning-packets-in>
Thresholds.
=item B<--critical-packets-in>
Thresholds.
=item B<--warning-packets-out>
Thresholds.
=item B<--critical-packets-out>
Thresholds.
=item B<--warning-dropped-packets-in>
Thresholds.
=item B<--critical-dropped-packets-in>
Thresholds.
=item B<--warning-dropped-packets-out>
Thresholds.
=item B<--critical-dropped-packets-out>
Warning thresholds.
($label$ can be traffic-in, traffic-out, packets-in, packets-out, dropped-packets-in, dropped-packets-out)
Thresholds.
=item B<--critical-$label$>
Critical thresholds
($label$ can be traffic-in, traffic-out, packets-in, packets-out, dropped-packets-in, dropped-packets-out)
=item B<--per-sec>
Expand Down
11 changes: 5 additions & 6 deletions src/cloud/azure/network/vpngateway/mode/vpngatewaystatus.pm
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ sub manage_selection {
&& $vpn->{name} !~ /$self->{option_results}->{filter_name}/);

$self->{vpns}->{$vpn->{id}} = {
display => $vpn->{name},
name => $vpn->{name},
provisioning_state => ($vpn->{provisioningState}) ? $vpn->{provisioningState} : $vpn->{properties}->{provisioningState},
gateway_type => ($vpn->{gatewayType}) ? $vpn->{gatewayType} : $vpn->{properties}->{gatewayType},
vpn_type => ($vpn->{vpnType}) ? $vpn->{vpnType} : $vpn->{properties}->{vpnType},
Expand All @@ -120,8 +120,7 @@ __END__
Check VPN gateways status.
Example:
perl centreon_plugins.pl --plugin=cloud::azure::network::vpngateway::plugin --custommode=azcli --mode=vpn-gateways-status
--resource-group='MYRESOURCEGROUP' --verbose
C<perl centreon_plugins.pl --plugin=cloud::azure::network::vpngateway::plugin --custommode=azcli --mode=vpn-gateways-status --resource-group='MYRESOURCEGROUP' --verbose>
=over 8
Expand All @@ -131,16 +130,16 @@ Set resource group (required).
=item B<--filter-name>
Filter vpn name (can be a regexp).
Filter VPN Gateways by name (can be a regexp).
=item B<--warning-status>
Define the conditions to match for the status to be WARNING (default: '').
You can use the following variables: %{provisioning_state}, %{gateway_type}, %{vpn_type}, %{display}
You can use the following variables: %{provisioning_state}, %{gateway_type}>, %{vpn_type}, %{display}
=item B<--critical-status>
Define the conditions to match for the status to be CRITICAL (default: '%{provisioning_state} ne "Succeeded"').
Define the conditions to match for the status to be CRITICAL (default: C<'%{provisioning_state} ne "Succeeded"'>).
You can use the following variables: %{provisioning_state}, %{gateway_type}, %{vpn_type}, %{display}
=back
Expand Down
125 changes: 125 additions & 0 deletions tests/cloud/azure/network/vpngateway/vpngatewaystatus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"uuid": "e745f255-dee8-48eb-a952-88bb0f9e5a0c",
"lastMigration": 32,
"name": "Azure vpn gateway",
"endpointPrefix": "",
"latency": 0,
"port": 3004,
"hostname": "",
"folders": [],
"routes": [
{
"uuid": "f8dc6ac1-febc-46a8-be79-9e5e14cedd3a",
"type": "http",
"documentation": "List By Resource Group Reference (reduced reponse info)",
"method": "get",
"endpoint": "subscriptions/:subscriptionId/resourcegroups/:resourceGroup/providers/Microsoft.Network/virtualNetworkGateways",
"responses": [
{
"uuid": "4b0edd9d-2052-45a3-9969-cf0cf461154c",
"body": "{\r\n \"value\": [\r\n {\r\n \"name\": \"gateway1\",\r\n \"id\": \"/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/vpnGateways/gateway1\",\r\n \"type\": \"Microsoft.Network/vpnGateways\",\r\n \"properties\": {\r\n \"provisioningState\": \"Succeeded\"\r\n },\r\n \"gatewayType\": \"ExpressRoute\",\r\n \"vpnType\": \"RouteBased\"\r\n },\r\n {\r\n \"name\": \"gateway2\",\r\n \"id\": \"/subscriptions/subid/resourceGroups/rg2/providers/Microsoft.Network/vpnGateways/gateway2\",\r\n \"type\": \"Microsoft.Network/vpnGateways\",\r\n \"properties\": {\r\n \"provisioningState\": \"Succeeded\"\r\n },\r\n \"gatewayType\": \"ExpressRoute\",\r\n \"vpnType\": \"RouteBased\"\r\n }\r\n ]\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
},
{
"uuid": "325811e6-6a5d-4906-90a1-3df24183d529",
"type": "http",
"documentation": "Azure login",
"method": "post",
"endpoint": "login/:tenant/oauth2/token",
"responses": [
{
"uuid": "e381c634-cbff-431e-851e-e4631f0f9e2c",
"body": "{\n \"access_token\": \"token\",\n \"expires_on\": \"{{ faker 'string.numeric' 10 }}\"\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": "f8dc6ac1-febc-46a8-be79-9e5e14cedd3a"
},
{
"type": "route",
"uuid": "325811e6-6a5d-4906-90a1-3df24183d529"
}
],
"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": []
}
38 changes: 38 additions & 0 deletions tests/cloud/azure/network/vpngateway/vpngatewaystatus.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
*** Settings ***
Documentation Azure Network VPN Gateway plugin
Resource ${CURDIR}${/}..${/}..${/}..${/}..${/}resources/import.resource

Suite Setup Start Mockoon ${MOCKOON_JSON}
Suite Teardown Stop Mockoon
Test Timeout 120s


*** Variables ***
${MOCKOON_JSON} ${CURDIR}${/}vpngatewaystatus.json

${BASE_URL} http://${HOSTNAME}:${APIPORT}
${LOGIN_ENDPOINT} ${BASE_URL}/login
${CMD} ${CENTREON_PLUGINS} --plugin=cloud::azure::network::vpngateway::plugin --custommode=api --subscription=subscription --tenant=tenant --client-id=client_id --client-secret=secret --resource-group=resource-group --login-endpoint=${LOGIN_ENDPOINT}


*** Test Cases ***
VPN Gateway status ${tc}
[Tags] cloud azure api mockoon
${command} Catenate
... ${CMD}
... --mode=vpn-gateway-status
... --management-endpoint=${BASE_URL}
... ${extra_options}

Ctn Run Command And Check Result As Strings ${command} ${expected_result}

Examples: tc extra_options expected_result --
... 1 ${EMPTY} OK: All VPN gateways are ok
... 2 --warning-status='\\%\{provisioning_state\} eq "Succeeded"' WARNING: VPN Gateway 'gateway1' Provisioning State 'Succeeded' [Gateway type: ExpressRoute] [VPN type: RouteBased] - VPN Gateway 'gateway2' Provisioning State 'Succeeded' [Gateway type: ExpressRoute] [VPN type: RouteBased]
... 3 --critical-status='\\%\{provisioning_state\} eq "Succeeded"' CRITICAL: VPN Gateway 'gateway1' Provisioning State 'Succeeded' [Gateway type: ExpressRoute] [VPN type: RouteBased] - VPN Gateway 'gateway2' Provisioning State 'Succeeded' [Gateway type: ExpressRoute] [VPN type: RouteBased]
... 4 --filter-name='gateway1' OK: VPN Gateway 'gateway1' Provisioning State 'Succeeded' [Gateway type: ExpressRoute] [VPN type: RouteBased]
... 5 --filter-name='gateway1' --warning-status='\\%\{provisioning_state\} eq "Succeeded"' WARNING: VPN Gateway 'gateway1' Provisioning State 'Succeeded' [Gateway type: ExpressRoute] [VPN type: RouteBased]
... 6 --filter-name='gateway1' --critical-status='\\%\{provisioning_state\} eq "Succeeded"' CRITICAL: VPN Gateway 'gateway1' Provisioning State 'Succeeded' [Gateway type: ExpressRoute] [VPN type: RouteBased]


0 comments on commit 48f85e3

Please sign in to comment.