Skip to content

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.

Notifications You must be signed in to change notification settings

kkonig/prtg-sensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PRTG BGP Neighbor State Monitor via Telnet

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.

Description

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.

Features

  • 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

Requirements

  • 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

Installation

Option 1: Using Python Script

  1. Ensure Python 3 is installed.
  2. Download bgp_telnet_prtg.py.
  3. Run directly: python bgp_telnet_prtg.py [options]

Option 2: Using Compiled EXE

  1. Download bgp_telnet_prtg.exe from the releases.
  2. Place it in PRTG's custom sensors directory (e.g., C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\).
  3. Configure PRTG sensor as described below.

Usage

Command Line Options

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

Examples

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

PRTG Configuration

  1. In PRTG, add a new sensor: "EXE/XML Custom"
  2. Set "EXE File": bgp_telnet_prtg.exe
  3. Set "Parameters": --host %host --password %password --neighbor %neighbor --port %port --prompt ">"
  4. Define parameters in PRTG (e.g., %host, %password, etc.)
  5. The sensor will report:
    • Value 1: BGP Established (Up)
    • Error: BGP not established (Down)

Output Format

Success (BGP Established)

<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>

Failure

<prtg>
  <error>1</error>
  <text>CRITICAL - BGP state is Idle (neighbor 10.0.0.1)</text>
</prtg>

Troubleshooting

  • Timeout errors: Increase --timeout or check network connectivity.
  • Prompt not found: Verify the --prompt matches 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 --debug for detailed logs.

Development

To modify the script:

  1. Edit bgp_telnet_prtg.py.
  2. Test with Python.
  3. Compile to EXE: pyinstaller --onefile bgp_telnet_prtg.py

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository.
  2. Create a feature branch.
  3. Submit a pull request with description.

Changelog

  • v1.0: Initial release with basic Telnet BGP monitoring.

About

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.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages