A production-ready Python script for monitoring BGP neighbor states on network devices via Telnet, designed for PRTG Network Monitor's EXE/XML Advanced sensor.
This script connects to a Cisco-like CLI device via Telnet, authenticates, runs the show ip bgp neigh <neighbor> command, parses the output to check if the BGP state is "Established", and reports the status to PRTG in XML format.
- Telnet connection with robust authentication handling
- Supports username/password or password-only login
- Parses BGP state from command output
- Outputs PRTG-compatible XML for EXE/XML Advanced sensors
- Configurable timeouts, ports, and prompts
- Debug mode for troubleshooting
- Compiled to standalone EXE for easy deployment
- Python 3.6+ (for development)
- For compiled EXE: Windows with the provided
bgp_telnet_prtg.exe - Network access to the target device on the specified port
- Ensure Python 3 is installed.
- Download
bgp_telnet_prtg.py. - Run directly:
python bgp_telnet_prtg.py [options]
- Download
bgp_telnet_prtg.exefrom the releases. - Place it in PRTG's custom sensors directory (e.g.,
C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\). - Configure PRTG sensor as described below.
python bgp_telnet_prtg.py --host <IP> --password <PASS> --neighbor <IP> [options]
--host(required): Target device IP or hostname--port(optional): Telnet port (default: 23)--password(required): Password for authentication--neighbor(required): BGP neighbor IP to check--username(optional): Username if required--timeout(optional): Connection timeout in seconds (default: 10)--prompt(optional): Device prompt substring (default: "#")--debug(flag): Enable debug output to stderr
Check BGP neighbor on a device:
python bgp_telnet_prtg.py --host 192.168.1.1 --password mypass --neighbor 10.0.0.1 --prompt ">"With username:
python bgp_telnet_prtg.py --host 192.168.1.1 --username admin --password mypass --neighbor 10.0.0.1 --port 23- In PRTG, add a new sensor: "EXE/XML Custom"
- Set "EXE File":
bgp_telnet_prtg.exe - Set "Parameters":
--host %host --password %password --neighbor %neighbor --port %port --prompt ">" - Define parameters in PRTG (e.g., %host, %password, etc.)
- The sensor will report:
- Value 1: BGP Established (Up)
- Error: BGP not established (Down)
<prtg>
<result>
<channel>BGP Neighbor State</channel>
<value>1</value>
<unit>Custom</unit>
<customunit>state</customunit>
</result>
<text>OK - BGP Established (neighbor 10.0.0.1)</text>
</prtg><prtg>
<error>1</error>
<text>CRITICAL - BGP state is Idle (neighbor 10.0.0.1)</text>
</prtg>- Timeout errors: Increase
--timeoutor check network connectivity. - Prompt not found: Verify the
--promptmatches the device's prompt (e.g., ">" for Quagga). - Authentication failure: Ensure correct username/password and device configuration.
- BGP state not found: Check if the command output contains "BGP state = ...".
- Enable
--debugfor detailed logs.
To modify the script:
- Edit
bgp_telnet_prtg.py. - Test with Python.
- Compile to EXE:
pyinstaller --onefile bgp_telnet_prtg.py
MIT License - see LICENSE file for details.
- Fork the repository.
- Create a feature branch.
- Submit a pull request with description.
- v1.0: Initial release with basic Telnet BGP monitoring.