本文檔介紹如何在協定擺動時配置Python指令碼以收集OSPF、EIGRP和IS-IS日誌。
思科建議您熟悉下列主題:
本檔案中的資訊是根據Cisco IOS XE軟體版本17。
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
附註:本檔案沒有深入說明詳細資訊。可在引用的連結中找到更多資訊。
建立TAC案例時,收集相關資訊以節省時間非常重要。有時,故障的線索存在於可以從裝置收集的一些基本輸出中。在本文檔中,您將看到如何利用Python指令碼獲取此資料的示例。考慮了三種協定:OSPF、EIGRP和IS-IS。
步驟1。您需要做的第一件事是配置和啟用guestshell。
Router(config)#iox
Router(config)#interface VirtualPortGroup 0
Router(config-if)#ip address 192.0.2.1 255.255.255.252
Router(config-if)#exit
Router(config)#
Router(config)#app-hosting appid guestshell
Router(config-app-hosting)#app-vnic gateway0 virtualportgroup 0 guest-interface 0
Router(config-app-hosting-gateway0)#guest-ipaddress 192.0.2.2 netmask 255.255.255.252
Router(config-app-hosting)#app-default-gateway 192.0.2.1 guest-interface 0
Router(config)#end
在此配置中,有三個重要步驟:
1.啟用IOX服務。這是啟用guestshell所必需的。
2.配置用作訪客外殼預設網關的預設網關的VirtualPortGroup。
3.配置來賓外殼的應用宿主。您可以從配置中得知VirtualPortGroup的作用所在。
步驟2.接下來,您需要從許可權模式啟用guestshell。
Router#guestshell enable
Interface will be selected if configured in app-hosting
Please wait for completion
guestshell installed successfully
Current state is: DEPLOYED
guestshell activated successfully
Current state is: ACTIVATED
guestshell started successfully
Current state is: RUNNING
Guestshell enabled successfully
Router#
*Jun 15 21:31:31.499: %IM-6-IOX_INST_INFO: R0/0: ioxman: IOX SERVICE guestshell LOG: Guestshell is up at 05/15/2026 21:31:31
如果所有配置都正確,您必須檢視上例中的日誌。
步驟3.現在,您已準備好配置python指令碼。在許可權模式下運行命令guestshell。您會看到提示,如下面的示例所示:
Router#guestshell
[guestshell@guestshell ~]$
步驟4.使用vi編輯器建立檔案,並根據您啟用的協定配置指令碼。
[guestshell@guestshell ~]$ vi ospf.py
此視窗顯示
~
~
~
~
~
~
~
"ospf.py" 0L, 0C
步驟5.按「i」以插入文字。貼上指令碼,然後按「esc」,然後輸入字元:wq
~
from cli import cli
from time import sleep
cli("enable")
cli("debug ip ospf hello")
cli("debug ip ospf adj")
cli("show ip ospf interface | append bootflash:Router-ospf-logs.txt")
cli("show ip ospf neighbor | append bootflash:Router-ospf-logs.txt")
cli("show interfaces | append bootflash:Router-ospf-logs.txt")
cli("show logging | append bootflash:Router-ospf-logs.txt")
cli("show tech | append bootflash:Router-showtech.txt")
sleep(30)
cli("undebug all")
~
~
~
~
"ospf.py" [New] 14L, 458C written
[guestshell@guestshell ~]$
使用exit命令退出guestshell。
測試指令碼。使用exit命令從guestshell退出。然後運行guestshell run python3 ospf.py
F340.20.09-8500-1#guestshell run python3 ospf.py
以下是所有三種協定的指令碼;OSPF、EIGRP和IS-IS。
OSPF
from cli import cli
from time import sleep
cli("enable")
cli("debug ip ospf hello")
cli("debug ip ospf adj")
cli("show ip ospf interface | append bootflash:Router-ospf-logs.txt")
cli("show ip ospf neighbor | append bootflash:Router-ospf-logs.txt")
cli("show interfaces | append bootflash:Router-ospf-logs.txt")
cli("show logging | append bootflash:Router-ospf-logs.txt")
cli("show tech | append bootflash:Router-showtech.txt")
sleep(30)
cli("undebug all")
EIGRP
from cli import cli
from time import sleep
cli("enable")
cli("debug eigrp packet")
cli("show ip eigrp neighbor | append bootflash:Router-eigrp-logs.txt")
cli("show ip eigrp interface | append bootflash:Router-eigrp-logs.txt")
cli("show interfaces | append bootflash:Router-eigrp-logs.txt")
cli("show logging | append bootflash:Router-eigrp-logs.txt")
cli("show tech | append bootflash:Router-showtech.txt")
sleep(30)
cli("undebug all")
IS-IS
from cli import cli
from time import sleep
cli("enable")
cli("debug isis adj-packet")
cli("show isis neighbor detail | append bootflash:Router-isis-logs.txt")
cli("show clns neighbor detail | append bootflash:Router-isis-logs.txt")
cli("show clns interface | append bootflash:Router-isis-logs.txt")
cli("show interfaces | append bootflash:Router-isis-logs.txt")
cli("show logging | append bootflash:Router-isis-logs.txt")
cli("show tech | append bootflash:Router-showtech.txt")
sleep(30)
cli("undebug all")
您可以通過觀察系統日誌模式後運行Python指令碼的EEM指令碼自動收集日誌。在下一節中,您將可以配置EEM指令碼以及python指令碼來完成此任務。
OSPF
event manager applet ospf-flap authorization bypass
event syslog pattern "%OSPF-5-ADJCHG:.*from FULL to DOWN" maxrun 120 ratelimit 120
action 010 cli command "enable"
action 020 cli command "guestshell run python3 ospf.py"
action 030 exit
EIGRP
event manager applet eirgp-flap authorization bypass
event syslog pattern "%DUAL-5-NBRCHANGE: EIGRP.*Neighbor.*is down" maxrun 120 ratelimit 120
action 010 cli command "enable"
action 020 cli command "guestshell run python3 eigrp.py"
action 030 exit
IS-IS
event manager applet isis-flap authorization bypass
event syslog pattern "%CLNS-5-ADJCHANGE: ISIS: Adjacency to.*Down" maxrun 120 ratelimit 120
action 010 cli command "enable"
action 020 cli command "guestshell run python3 isis.py"
action 030 exit
附註:這些指令碼中收集的命令提供基本初始資訊。當您建立TAC案例時,TAC工程師可以要求您提供更多資訊,以便在需要時進行進一步調查。
| 修訂 | 發佈日期 | 意見 |
|---|---|---|
1.0 |
01-Jul-2026
|
初始版本 |