Tag: python

Using Pynetbox

Pynetbox is a Python API client library for NetBox. Here are some basic examples of using pynetbox. In this page: Getting started Creating and changing something Retrieving objects Deleting objects Handling object status Using tags Referring to other objects Here we assume that you already have NetBox running (I have NetBox 2.8.6 in this demo), […]

Subcommands with Argument Parsing in Python

An example how subcommands can be used with argparse module: Sample output: markku@btest:~/temp$ python3 argtest.py usage: argtest.py [-h] [-c CONFIG_FILE] {update-device,add-vlan} … positional arguments: {update-device,add-vlan} update-device update device data add-vlan add a VLAN optional arguments: -h, –help show this help message and exit -c CONFIG_FILE, –config-file CONFIG_FILE specify the configuration file to read (default: argtest.cfg) […]

Webhook Listener for NetBox

Note: There is an improved version in the next post. Following my earlier post about implementing a REST API, here is a simple listener for NetBox webhooks: webhook-listener.py: With the other configurations described in the earlier post (and after configured NetBox to send the webhook POST requests to http://my.server.local/webhook/), these are the outputs: webhook-listener.log: Automatically […]

My First REST API with Python and Flask-RESTPlus

With few or no explanations, on Debian 10: The actual API app, in ~/resttest/resttest.py: ~/resttest/wsgi.py: /etc/systemd/system/resttest.service: /etc/nginx/sites-available/resttest: Final setup steps: Testing results: Also note that the Swagger UI is automatically accessible in http://my.server.name/: Some future considerations: TLS encryption (= reconfiguring NGINX) Authentication for the API Disabling/customizing the Swagger UI Links: Flask Flask-RESTPlus NGINX The post […]