Skip to content
This repository has been archived by the owner on Oct 11, 2020. It is now read-only.

Healthbot REST calls with Python

Khelil Sator edited this page Feb 10, 2019 · 11 revisions

We will use the python module requests to make REST calls to healthbot to:

  • configure healthbot with an end to end configuration
  • collect and print the healthbot configuration
  • delete healthbot configuration

Demo

install the requirements

run this command on ubuntu to install these python libraries

$ pip install requests
$ pip install pyyaml
$ pip install jinja2

Describe healthbot desired configuration

edit the file python_input.yml to indicate healthbot ip address and credentials, and the healthbot desired configuration (devices ip address ...)

$ vi  python_input.yml

configure healthbot using Python

The python script configure_healthbot.py configures healthbot with the details described in the file python_input.yml
It adds an end to end configuration:

  • devices (vMX1 to vMX7)
  • A topic (bgp) and rules to monitor BGP using
    • snmp (rule check-bgp-state-using-snmp)
    • netconf (rule check-bgp-state-using-netconf)
  • tables and views for BGP (bgp_sessions_state.yml for the rule check-bgp-state-using-netconf)
  • playbooks
    • bgp-using-netconf uses the rule check-bgp-state-using-netconf
    • bgp-using-snmp uses the rule check-bgp-state-using-snmp
  • webhook notifications
  • device-groups
    • Group1 with devices vMX1 to vMX7 and an instance of playbook bgp-using-netconf
    • Group2 with devices vMX3 and vMX4 and an instance of playbook bgp-using-snmp

Run this command to execute the The python script configure_healthbot.py

$ python ./configure_healthbot.py
****************** Adding devices to healthbot ******************
loaded healthbot configuration for the device: vMX1
loaded healthbot configuration for the device: vMX2
loaded healthbot configuration for the device: vMX3
loaded healthbot configuration for the device: vMX4
loaded healthbot configuration for the device: vMX5
loaded healthbot configuration for the device: vMX6
loaded healthbot configuration for the device: vMX7
****************** Adding tables to healthbot ******************
added table: bgp_sessions_state.yml
****************** Adding notifications to healthbot ******************
loaded healthbot configuration for the notification: healthbot_to_saltstack
****************** Adding topics and rules to healthbot ******************
loaded healthbot configuration for the topic: bgp
****************** Adding playbooks to healthbot ******************
loaded healthbot configuration for the playbook: bgp-using-netconf
loaded healthbot configuration for the playbook: bgp-using-snmp
****************** Adding device groups to healthbot ******************
loaded healthbot configuration for the device group: Group1
loaded healthbot configuration for the device group: Group2
****************** commiting healthbot configuration ******************
healthbot configuration commited!

Healthbot dashboard: dashboard2.png

Verify healthbot configuration using Python

Run this command to verify you were able to configure Healthbot properly with the details described in the file python_input.yml.
This will collect configuration from Healthbot and print it.

$ python ./audit_healthbot_configuration.py

Delete healthbot configuration using Python

Run this command to delete the healthtbot configuration described in the file python_input.yml
This will delete:

  • device-groups (including playbook instances)
  • playbooks
  • topics and rules
  • notifications
  • devices

This will also remove the tables and views listed in the file python_input.yml

$ python ./delete_healthbot_configuration.py
Clone this wiki locally