Skip to main content

A thin Python wrapper for the OpenNMS REST API (Horizon 35)

Project description

opennms-api-wrapper

CI GitHub release Python License: MIT

A thin, dependency-minimal Python 3 wrapper for the OpenNMS REST API (Horizon 35+). Validated against OpenNMS Meridian 2024.3.0 with a live-server smoke test suite.

Features

  • Covers every v1 (/opennms/rest/) and v2 (/opennms/api/v2/) endpoint
  • JSON everywhere — no XML handling required
  • Single runtime dependency: requests
  • Synchronous and straightforward — no async complexity
  • 290-test suite with full method coverage (mocked HTTP — no live server required)
  • Live-server smoke test validated against Meridian 2024.3.0

Installation

From the GitHub release (no clone required — recommended for most users):

pip install https://github.com/cnewkirk/opennms-api-wrapper/archive/refs/tags/v0.2.0.tar.gz

From source (clone first, then install):

git clone https://github.com/cnewkirk/opennms-api-wrapper.git
cd opennms-api-wrapper
pip install .

When the package is published to PyPI, installation will simplify to pip install opennms-api-wrapper.

Quick start

import opennms_api_wrapper as opennms

client = opennms.OpenNMS(
    url="https://opennms.example.com:8443",
    username="admin",
    password="admin",
)

# Server info
info = client.get_info()
print(info["displayVersion"])

# List alarms
alarms = client.get_alarms(limit=25, order_by="lastEventTime", order="desc")
for alarm in alarms["alarm"]:
    print(alarm["id"], alarm["severity"], alarm["nodeLabel"])

# Acknowledge an alarm
client.ack_alarm(alarm_id=42)

# List alarms with FIQL filter (v2)
alarms = client.get_alarms_v2(fiql="severity==MAJOR")

API coverage

Resource group Methods
Alarms (v1 + v2) list, get, count, ack/unack/clear/escalate, bulk ops
Alarm statistics stats, stats by severity
Alarm history history, history at timestamp, state changes
Events list, get, count, create, ack/unack, bulk ack/unack
Nodes full CRUD + IP interfaces, SNMP interfaces, services, categories, assets, hardware
Outages list, get, count, node outages
Notifications list, get, count, trigger destination path
Acknowledgements list, get, count, create, ack/unack notification
Requisitions full CRUD including nodes, interfaces, services, categories, assets
Foreign sources full CRUD including detectors and policies
SNMP configuration get, set
Groups full CRUD + user and category membership
Users full CRUD + role assignment
Categories full CRUD + node and group associations
Scheduled outages full CRUD + daemon associations
KSC reports list, get, count, create, update
Resources list, get, get for node, select, delete
Measurements single attribute (GET), multi-source (POST)
Heatmap outages + alarms × categories / foreign sources / services / nodes
Maps full CRUD + map elements
Topology graphs containers, graph, graph view (POST), search suggestions, search results
Flows count, exporters, applications, conversations, hosts
Device configuration list, get, get by interface, latest, download, backup
Situations (v2) list, create, add alarms, clear, accept, remove alarms
Business services (v2) full CRUD
Metadata (v2) full CRUD for node, interface, and service metadata
Server info get
Discovery (v2) submit scan configuration
IP interfaces (v2) list with FIQL
SNMP interfaces (v2) list with FIQL

Authentication

Basic authentication is used. Pass verify_ssl=False to disable certificate verification (useful for self-signed certs in lab environments):

client = opennms.OpenNMS(
    url="https://opennms.example.com:8443",
    username="admin",
    password="admin",
    verify_ssl=False,
)

Smoke testing

smoke_test.py exercises the wrapper against a real OpenNMS server. It is intended for use against a dev or staging instance before each release — not as a substitute for the 290-test mocked unit suite.

Tests that depend on optional plugins or heavy endpoints are reported as WARN (non-fatal) rather than FAIL. Each warning includes the specific plugin or feature required.

Read-only mode (default) is safe to run against any server, including production. It issues only GET requests and makes no changes.

export OPENNMS_URL="https://opennms.example.com:8443"
export OPENNMS_USER="admin"
export OPENNMS_PASSWORD="secret"
export OPENNMS_VERIFY_SSL="false"   # omit or set to "true" for valid certs
export OPENNMS_TIMEOUT="60"         # per-request timeout in seconds (default 60)

python smoke_test.py

Write mode creates and then deletes objects on the server (events, categories, groups, requisitions, maps, etc.). It will prompt for explicit confirmation and print the target URL before running a single write. Only use write mode against a dev or staging instance — never production.

python smoke_test.py --write          # interactive prompt required
python smoke_test.py --write --yes    # skip prompt (CI pipelines only)
python smoke_test.py --no-color       # plain output for log files
python smoke_test.py --skip get_resources --skip get_flow  # skip slow tests

The --skip flag accepts a prefix — --skip get_flow skips all tests whose label starts with get_flow.

Development

git clone https://github.com/cnewkirk/opennms-api-wrapper.git
cd opennms-api-wrapper
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest tests/ -v

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/cnewkirk/opennms-api-wrapper.

Acknowledgements

This library was designed and tested by a human, with implementation assistance from Claude Code (Anthropic). All API shapes are derived from the official OpenNMS Horizon 35 REST API documentation.

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

opennms_api_wrapper-0.2.0.tar.gz (46.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opennms_api_wrapper-0.2.0-py3-none-any.whl (37.9 kB view details)

Uploaded Python 3

File details

Details for the file opennms_api_wrapper-0.2.0.tar.gz.

File metadata

  • Download URL: opennms_api_wrapper-0.2.0.tar.gz
  • Upload date:
  • Size: 46.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for opennms_api_wrapper-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9bada5d78e52480021f3282682fd85d7eff18df1467765180477af8abbd6fca3
MD5 ed68fa5465796496d1612bb13d7481f6
BLAKE2b-256 665e98bb47763384240fd2072dd5fd0cd9c7fb43be89079d35ba703e63bdf93e

See more details on using hashes here.

Provenance

The following attestation bundles were made for opennms_api_wrapper-0.2.0.tar.gz:

Publisher: publish.yml on cnewkirk/opennms-api-wrapper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opennms_api_wrapper-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for opennms_api_wrapper-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d14ff815f6f648b73ed19ec46afdfc24805de0e90ca36d359739976b97d2cab9
MD5 5ecfafaa66dbd5b4a3f10a659e0ffe19
BLAKE2b-256 701cf278b22d135bec78f2292cb266d0ebcdd6fdfff4dcd202babe5b3c0b3f16

See more details on using hashes here.

Provenance

The following attestation bundles were made for opennms_api_wrapper-0.2.0-py3-none-any.whl:

Publisher: publish.yml on cnewkirk/opennms-api-wrapper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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