python - 如何在 textfsm 中捕获多行但在同一行打印
问题描述
我有以下数据
SW#show syslog-servers
IP/IPv6 Address/Hostname Port Severity Description
-------------------------- ------ -------------- --------------
1.1.1.1 514 informational
2.2.2.2 515 warning
3.3.3.3 516 informational
Transport Type Authentication Certificate Index
-------------- ----------------- -------------------
UDP
UDP
TCP
switch show 命令的图像
Value IP (\S+)
Value PORT (\d+)
Value SEVERITY (\S+)
Value TRANSPORT (TCP|UDP)
Start
^.*---- -> syslog
syslog
^${IP}\s+${PORT}\s+${SEVERITY} -> Record
^${TRANSPORT} -> Record
我希望输出看起来像这样
[
{
"IP": "1.1.1.1",
"PORT": "514",
"SEVERITY": "informational",
"TRANSPORT": "UDP"
},
{
"IP": "2.2.2.2",
"PORT": "515",
"SEVERITY": "warning",
"TRANSPORT": "UDP"
},
{
"IP": "3.3.3.3",
"PORT": "516",
"SEVERITY": "informational",
"TRANSPORT": "TCP"
}
]
但相反,我得到了这个
[
{
"IP": "1.1.1.1",
"PORT": "514",
"SEVERITY": "informational",
"TRANSPORT": ""
},
{
"IP": "2.2.2.2",
"PORT": "515",
"SEVERITY": "warning",
"TRANSPORT": ""
},
{
"IP": "3.3.3.3",
"PORT": "516",
"SEVERITY": "informational",
"TRANSPORT": ""
},
{
"IP": "",
"PORT": "",
"SEVERITY": "",
"TRANSPORT": "UDP"
},
{
"IP": "",
"PORT": "",
"SEVERITY": "",
"TRANSPORT": "UDP"
},
{
"IP": "",
"PORT": "",
"SEVERITY": "",
"TRANSPORT": "TCP"
}
]
解决方案
推荐阅读
- https - jmeter中的ERR_SSL_PROTOCOL_ERROR
- ansible - Ansible 剧本无法选择 openshift
- php - 如何在 PHP Post 方法中返回/获取列表?
- r - 使用减号删除变量和选择那些想要的变量有什么区别?
- python - 从随机数中选择所有数字的概率是否相等?
- javascript - 使用下拉菜单动态更改条形图
- ios - 如何在响应所有设备的 react-native 应用程序中设置 marginLeft 和 marginRight
- python - Python 中的正则表达式,用于检测整数、浮点数或科学记数法中的数字
- python - 圆上的非最大值抑制
- javascript - 为什么在此反应代码中释放外部 div 时不会触发 mouseup 事件(使用 window.addEventListener)