关于通过Restful服务获取OpenNMS Availability by node报告的技术咨询
Got it, I’ve run into this exact issue before with OpenNMS—there isn’t a single dedicated REST endpoint that directly spits out the exact "Availability by node" report you see in the UI, but you can absolutely build this yourself using existing OpenNMS REST APIs. Here’s how I’ve done it:
1. 先获取目标节点的基础信息
First, pull the list of nodes you want to report on using the nodes API. This lets you filter by category, foreign source, or just grab all nodes:
- 单个节点查询:
GET /rest/nodes/{nodeId} - 批量节点查询:
GET /rest/nodes(add query params likecategory=Serversto filter results)
This returns core details like nodeId, nodeLabel, and current status (Up/Down) for each node—perfect for building the base of your report.
2. 拉取节点的时间范围可用性数据
OpenNMS has a dedicated availability API that calculates uptime/downtime percentages for any node over a specified window. Use this to get the actual availability metrics:
- Request format:
GET /rest/availability/nodes/{nodeId}?start={startTime}&end={endTime} - Or use relative time for simplicity (e.g., past week:
GET /rest/availability/nodes/{nodeId}?relative=1w)
The response will include metrics like availabilityPercentage, upTime, downTime, and unresponsiveTime—exactly the data you need for the "Availability by node" breakdown.
3. 组合数据生成自定义报告
To replicate the full report:
- Call the nodes API to get your target node list
- Loop through each
nodeIdand call the availability API for your desired time range - Merge the node metadata (label, status) with the availability metrics into a JSON/XML structure that matches your needs
Here’s a quick curl example to test:
# Get all nodes in the "Database" category curl -u admin:admin "http://your-opennms:8980/opennms/rest/nodes?category=Database" # Get availability for node ID 42 over the past 30 days curl -u admin:admin "http://your-opennms:8980/opennms/rest/availability/nodes/42?relative=30d"
4. Bonus: Exporting the native UI report format
If you need the exact same output as the UI’s "Availability by node" report (e.g., PDF/CSV), you can use the reports API:
- First get the list of available reports with
GET /rest/reportsto find the ID for the "Availability by node" report - Then call
GET /rest/reports/{reportId}/pdforGET /rest/reports/{reportId}/csvto download the pre-generated report file (note: this returns binary data, so you’ll need to handle the download accordingly)
Quick Notes
- Make sure your OpenNMS version is 19.0+—these REST endpoints were standardized around that release
- Always use Basic Auth (include your admin credentials in the request)
- Double-check time format if using absolute dates: use
yyyy-MM-dd'T'HH:mm:ss.SSSZ(e.g.,2024-01-01T00:00:00.000Z)
内容的提问来源于stack exchange,提问作者Sumit Mehta

