Powershell

使用 AWS Powershell 工具返回 AWS“VPN 隧道狀態”

  • June 1, 2017

我們有許多 VPN 隧道連接不同 VPC 中的各種虛擬設備。

如何使用AWS Powershell 工具查詢tunnel status與 a 關聯的每個隧道的 ,vpn connection以確定它們是up還是downtunnel status在 AWS Web GUI 中的 VPC > VPN 連接 > 選擇連接 > 隧道詳細資訊子選項卡下可用。

命令:

get-ec2vpnconnection

返回具有屬性的對象state,但這不是單個隧道的狀態;這是整個 VPN 連接的狀態。

如何使用 AWS Powershell 工具獲取 VPN 連接中單個 VPN 隧道的狀態?

事實上,可以使用 AWS PowerShell 工具監控 VPC VPN 隧道狀態。以下腳本複制自Alex Neihaus 於 2017 年 3 月 13 日在 yobyot.com 上發表的一篇部落格文章,根據 Apache 許可證 2.0(包括在內)獲得許可。

此腳本返回 VPN 連接 ID,無論它是打開還是關閉,以及與之關聯的狀態消息。它通過獲取給定 VPN 隧道的 vgw-telemetry 屬性來做到這一點。

<#Copyright 2017 Air11 Technology LLC

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. #>

Get-EC2VpnConnection | Select-Object -Property VpnConnectionId, VgwTelemetry | ` # Pass all objects to the pipeline
ForEach-Object -Process {

$connectionID = $_.VpnConnectionId # get connection ID
$_.VgwTelemetry | ForEach-Object {
   # There are multiple Amazon.Model.EC2.VgwTelemetry objects in each Amazon.Model.EC2.VPNConnection
   if (($_.status).value -ne 'UP')
   {
       Write-Host "Connection $connectionID is $(($_.status).value) and has a status message of $(($_.StatusMessage))"
       # Uncomment the next statement and change the arn to send a message to an SNS topic
       # Publish-SNSMessage -TopicArn arn:aws:sns:us-east-1:01234567890:your-SNS-topic -Subject "VPN Status Alert!" -Message "The $ConnectionID is showing it's ($_.status).value"
       }
       else
       {
           Write-Host "Connection $connectionID is $(($_.status).value) and has 
a status message of $(($_.StatusMessage))"

       }
   }
}

引用自:https://serverfault.com/questions/852689