我想开发一个工具来自动排除网络故障。今天我使用我创建的 shell 脚本,它使用 bash 和 expect 但问题是我只能使用脚本末尾的数据。
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/