You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
assertlen(neighbors_down) ==0, f"BGP neighbors down: {', '.join([line.split()[0] for line in neighbors_down])}"
115
117
```
116
118
*This example looks for 'router bgp' in configuration and if found then executes the `show ip bgp summary` command and checks the status of all BGP neighbors. If any neighbor is in an "Idle," "Active," or "Connect" state, the rule will fail, listing the IP addresses of the down neighbors.*
119
+
120
+
## Using TextFSM
121
+
122
+
### Example: Interface Status Check Using TextFSM
123
+
124
+
This rule checks the status of a specific interface on a Cisco IOS device using TextFSM for command output parsing. It ensures that the interface is up and running.
125
+
126
+
```python
127
+
@medium(
128
+
name='rule_interface_status_check',
129
+
platform=['cisco_ios'],
130
+
)
131
+
defrule_interface_status_check(device):
132
+
# Execute the command to get interface details using TextFSM parsing
# Print the parsed output for debugging or verification purposes
136
+
print(inf_output)
137
+
138
+
# Assert that the interface is up; fail the test if it is down
139
+
assert inf_output.link_status =="up", "Interface is down"
140
+
```
141
+
*This example uses TextFSM to parse the output of the `show interface eth0/0` command. The rule then checks the parsed output to verify that the interface is up. If the interface is down, the rule will fail, reporting the issue.*
0 commit comments