python - 自动排除网络故障

标签 python linux bash ansible expect

我想开发一个工具来自动排除网络故障。今天我使用我创建的 shell 脚本,它使用 bashexpect 但问题是我只能使用脚本末尾的数据。

Current functions: the bash script requests some information for the user (user, password, IP, MAC), after this the bash script starts an expect script that enters on the equipment of my network, runs a list of predetermined commands and the output is recorded in a variable of the bash script, after the finishing of the expect script the bash script acts on the data parser.

我想做一些更“智能”的事情,即在设备上输入并且可以单独处理每个命令,而不需要运行所有可能的命令,返回命令行,执行解析器并根据输出再次执行所有操作

我需要一些“无代理”的东西,并且我正在使用 Linux。我可以使用什么编程语言/框架?你能给我一些想法和建议吗? (我不需要 GUI,只要命令行就完美了)

我使用SSH进入设备(在某些情况下我需要使用SSH进入跳转服务器,并在其中使用脚本进入设备)。命令示例:

show ip bgp summary

ping xxx.yyy.zzz.www

show ports X

show vlan X

还有其他几个

如果我没有留下明确的信息,请告诉我并提前谢谢您。

最佳答案

对于常见情况,您应该尝试 Ansible - 查看 network documentation .

对于更特殊的情况,我强烈推荐 Netmiko 。它是一个 Python 库,提供类似预期的界面并处理许多网络 ssh 怪癖。

要使命令通过跳转框运行,您可以查看 ssh 配置选项来转发命令。然后您的脚本命令将自动通过您的跳转盒进行代理。抱歉,我不记得确切的选项,找到神奇的组合可能很痛苦。

您还应该考虑加入 Network To Code Slack community 。这是一个提出快速问题的好地方,也是初学者和专家的良好组合。

关于python - 自动排除网络故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54375788/

相关文章:

bash - 如何从 bash 中的字符串中删除非贪婪后缀?

javascript - 在expressJS应用程序中,是否可以在脚本执行时实时收集写入控制台的数据?

python - 与列表列中的项目关联的总金额

python - 在 Python 中基于 XSD 验证和填充 XML 中的默认值

c - 如何更改 tcsetattr() 的 Linux 中断定时器

linux - 如何使用 curl 命令将文件上传到网络服务器?

bash - 有没有办法在长脚本完成后自动发送电子邮件?

python - 使用列表理解在python中连接字典中的项目

python - 当客户端不干净地退出时,如何检测服务器上 Python aiohttp web 套接字的关闭

linux - 如何测试/验证 vmalloc 保护页在 Linux 中是否正常工作