Skip to main content

A Python library to interact with the LibreNMS API (v0)

Project description

LibreNMS handler

PyPI image Downloads Black Bandit CodeQL

A Python library to interact with the LibreNMS API (v0).

The project aims to provide the user with as much information as if they were looking at the reference guide themselves.

I have not used it myself so I cannot endorse it, but a quick search shows that LibreNMSAPI has a similar goal with a different outlook. Consider checking it out if this project doesn't suit your needs!

Usage

The package is installed with the following package managers like so:

Pip

pip install librenms-handler

Pipenv

pipenv install librenms-handler

The following statement will initialise the chosen endpoint:

from librenms_handler.devices import Devices

devices = Devices(
    'https://librenms.example.com',
    'e4ef9234abab59a90628dd3f616a60b4'
)

NOTE: If you are using a self-signed certificate for your server, you can bypass the errors by passing the initialisation option verify=False.

Once done, a list of methods will be available to you such as devices.list_devices(). Upon operation, the method will execute and return the required request to your LibreNMS instance.

>>> devices.add_device('test_device', snmp_disable=True, force_add=True)
{'status': 'ok', 'message': 'Device test_device (13) has been added successfully'}
>>> devices.del_device('test')
{'status': 'ok', 'devices': [{'device_id': 13, 'inserted': '2021-03-13 15:56:19', 'hostname': 'test_device', 'sysName': '', 'ip': None, 'overwrite_ip': None, 'community': '', 'authlevel': None, 'authname': None, 'authpass': None, 'authalgo': None, 'cryptopass': None, 'cryptoalgo': None, 'snmpver': 'v2c', 'port': 161, 'transport': 'udp', 'timeout': None, 'retries': None, 'snmp_disable': 1, 'bgpLocalAs': None, 'sysObjectID': None, 'sysDescr': None, 'sysContact': None, 'version': None, 'hardware': '', 'features': None, 'location_id': None, 'os': 'ping', 'status': True, 'status_reason': '', 'ignore': 0, 'disabled': 0, 'uptime': None, 'agent_uptime': 0, 'last_polled': None, 'last_poll_attempted': None, 'last_polled_timetaken': None, 'last_discovered_timetaken': None, 'last_discovered': None, 'last_ping': None, 'last_ping_timetaken': None, 'purpose': None, 'type': 'server', 'serial': None, 'icon': 'images/os/ping.svg', 'poller_group': 0, 'override_sysLocation': 0, 'notes': None, 'port_association_mode': 1, 'max_depth': 0, 'disable_notify': 0, 'location': None, 'lat': None, 'lng': None, 'attribs': [], 'vrf_lite_cisco': []}], 'message': 'Removed device test_device\n', 'count': 1}

The output is exactly the same as if you were using Curl to make the requests.

Should you wish to use any other endpoint, the situation would be the same: from librenms_handler.endpoint import Endpoint

Environment variables

While initialising the handler, the following parameters are required. The handler first checks for the following environment variables, should you choose to use them.

Environment variable Description Type Example
LIBRENMS_URL Full URL to the target LibreNMS instance string https://librenms.example.com
LIBRENMS_TOKEN Token generated from LIBRENMS_URL/api-access string e4ef9234abab59a90628dd3f616a60b4

Endpoints

The progress of API endpoints are shown in their respective projects below: See Projects to track the progress of the endpoints or select individual ones below.

It is not possible to say when an endpoint is 'done', as they are being expanded as time goes on. Each function will have its own issue tracked, so you can search to see if implemented or not.

Endpoint Started
Alerts False
ARP True
Bills False
Device Groups True
Devices True
Inventory True
Locations True
Logs True
Port Groups False
Ports False
Routing False
Services False
Switching False
System True

Collaboration

The project has no complex logic behind it - all you need to do is read the API docs and follow the existing code structure. Sometimes the documentation is not consistent, so providing more information in the docstring is preferred than not explaining arguments.

All code should be formatted by Black before submission and adhere to Pylint recommendations where reasonable. Linting is not absolute; functionality is the priority.

By following these standards, the code should be easy for people from all skill-sets to help out!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

librenms-handler-0.3.1.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

librenms_handler-0.3.1-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file librenms-handler-0.3.1.tar.gz.

File metadata

  • Download URL: librenms-handler-0.3.1.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for librenms-handler-0.3.1.tar.gz
Algorithm Hash digest
SHA256 228a97c6c7ae616ede2432cc9bec0b58f0d0df56465c22547e12d27817c5bd65
MD5 5c99a961888e3955e5672afb93347a6e
BLAKE2b-256 db7e6a9e8c2744ec04a3b1a507742acc2b9a46892223cb07c1229eaaab91caa2

See more details on using hashes here.

File details

Details for the file librenms_handler-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for librenms_handler-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ae6b4bc1136c5ad4d01fffde4046245677537c7d03596cb351bd1395249ff860
MD5 6f7817f8281c2d4fa17128e33ebaf485
BLAKE2b-256 ec8e082c3689829928bf67bdd7bf05f56962f572f1b995560e4e2f4bb4dd06ea

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page