我们拥有众多 VPN 隧道,连接不同 VPC 中的各种虚拟设备。
我如何使用AWS Powershell 工具查询tunnel status
与关联的每个隧道的vpn connection
以确定它们是否是up
。down
可 tunnel status
在 AWS Web GUI 下的 VPC > VPN 连接 > 选择连接 > 隧道详细信息子选项卡下使用。
命令:
get-ec2vpnconnection
返回具有属性的对象state
,但这不是单个隧道的状态;这是整个 VPN 连接的状态。
如何使用 AWS Powershell 工具获取 VPN 连接中单个 VPN 隧道的状态?
答案1
实际上,可以使用 AWS PowerShell 工具监控 VPC VPN 隧道状态。以下脚本摘自yobyot.com 上的博客文章由 Alex Neihaus 于 2017 年 3 月 13 日发布,根据 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))"
}
}
}