Страницы

8 октября 2021 г.

Python. Использование LibreNMS API

Использование LibreNMS API на примере запроса информации об устройстве.

import requests

lnms_host = '????????'
lnms_token = '????????'

res = requests.get('http://' + lnms_host + '/api/v0/devices/<hostname>', headers={'X-Auth-Token': lnms_token})

answer = res.text
print(answer)


Другие поддерживаемые API LibreNMS, для справки:
"ack_alert": "http://<host_librenms>/api/v0/alerts/{id}",
"add_components": "http://<host_librenms>/api/v0/devices/{hostname}/components/{type}",
"add_device": "http://<host_librenms>/api/v0/devices",
"add_device_group": "http://<host_librenms>/api/v0/devicegroups",
"add_location": "http://<host_librenms>/api/v0/locations",
"add_parents_to_host": "http://<host_librenms>/api/v0/devices/{id}/parents",
"add_port_group": "http://<host_librenms>/api/v0/port_groups",
"add_rule": "http://<host_librenms>/api/v0/rules",
"add_service_for_host": "http://<host_librenms>/api/v0/services/{hostname}",
"assign_port_group": "http://<host_librenms>/api/v0/port_groups/{port_group_id}/assign",
"create_bill": "http://<host_librenms>/api/v0/bills",
"del_device": "http://<host_librenms>/api/v0/devices/{hostname}",
"del_location": "http://<host_librenms>/api/v0/locations/{location}",
"del_parents_from_host": "http://<host_librenms>/api/v0/devices/{id}/parents",
"del_service_from_host": "http://<host_librenms>/api/v0/services/{id}",
"delete_bill": "http://<host_librenms>/api/v0/bills/{bill_id}",
"delete_components": "http://<host_librenms>/api/v0/devices/{hostname}/components/{component}",
"delete_rule": "http://<host_librenms>/api/v0/rules/{id}",
"device_availability": "http://<host_librenms>/api/v0/devices/{hostname}/availability",
"device_outages": "http://<host_librenms>/api/v0/devices/{hostname}/outages",
"edit_bgp_descr": "http://<host_librenms>/api/v0/bgp/{id}",
"edit_components": "http://<host_librenms>/api/v0/devices/{hostname}/components",
"edit_location": "http://<host_librenms>/api/v0/locations/{location_id_or_name}",
"edit_rule": "http://<host_librenms>/api/v0/rules",
"edit_service_for_host": "http://<host_librenms>/api/v0/services/{id}",
"get_alert": "http://<host_librenms>/api/v0/alerts/{id}",
"get_alert_rule": "http://<host_librenms>/api/v0/rules/{id}",
"get_all_ports": "http://<host_librenms>/api/v0/ports",
"get_bgp": "http://<host_librenms>/api/v0/bgp/{id}",
"get_bill": "http://<host_librenms>/api/v0/bills/{bill_id}",
"get_bill_graph": "http://<host_librenms>/api/v0/bills/{bill_id}/graphs/{graph_type}",
"get_bill_graphdata": "http://<host_librenms>/api/v0/bills/{bill_id}/graphdata/{graph_type}",
"get_bill_history": "http://<host_librenms>/api/v0/bills/{bill_id}/history",
"get_bill_history_graph": "http://<host_librenms>/api/v0/bills/{bill_id}/history/{bill_hist_id}/graphs/{graph_type}",
"get_bill_history_graphdata": "http://<host_librenms>/api/v0/bills/{bill_id}/history/{bill_hist_id}/graphdata/{graph_type}",
"get_components": "http://<host_librenms>/api/v0/devices/{hostname}/components",
"get_device": "http://<host_librenms>/api/v0/devices/{hostname}",
"get_device_groups": "http://<host_librenms>/api/v0/devicegroups",
"get_device_groups_device": "http://<host_librenms>/api/v0/devices/{hostname}/groups",
"get_devices_by_group": "http://<host_librenms>/api/v0/devicegroups/{name}",
"get_fdb": "http://<host_librenms>/api/v0/devices/{hostname}/fdb",
"get_graph_by_port_hostname": "http://<host_librenms>/api/v0/devices/{hostname}/ports/{ifname}/{type}",
"get_graph_by_portgroup": "http://<host_librenms>/api/v0/portgroups/{group}",
"get_graph_by_portgroup_multiport_bits": "http://<host_librenms>/api/v0/portgroups/multiport/bits/{id}",
"get_graph_generic_by_hostname": "http://<host_librenms>/api/v0/devices/{hostname}/{type}",
"get_graphs": "http://<host_librenms>/api/v0/devices/{hostname}/graphs",
"get_health_graph": "http://<host_librenms>/api/v0/devices/{hostname}/graphs/health/{type}/{sensor_id?}",
"get_inventory": "http://<host_librenms>/api/v0/inventory/{hostname}",
"get_inventory_for_device": "http://<host_librenms>/api/v0/inventory/{hostname}/all",
"get_ip_addresses": "http://<host_librenms>/api/v0/devices/{hostname}/ip",
"get_link": "http://<host_librenms>/api/v0/resources/links/{id}",
"get_network_ip_addresses": "http://<host_librenms>/api/v0/resources/ip/networks/{id}/ip",
"get_oxidized_config": "http://<host_librenms>/api/v0/oxidized/config/{device_name}",
"get_port_graphs": "http://<host_librenms>/api/v0/devices/{hostname}/ports",
"get_port_groups": "http://<host_librenms>/api/v0/port_groups",
"get_port_info": "http://<host_librenms>/api/v0/ports/{portid}",
"get_port_ip_info": "http://<host_librenms>/api/v0/ports/{portid}/ip",
"get_port_stack": "http://<host_librenms>/api/v0/devices/{hostname}/port_stack",
"get_port_stats_by_port_hostname": "http://<host_librenms>/api/v0/devices/{hostname}/ports/{ifname}",
"get_vlans": "http://<host_librenms>/api/v0/devices/{hostname}/vlans",
"get_vrf": "http://<host_librenms>/api/v0/routing/vrf/{id}",
"get_wireless_graph": "http://<host_librenms>/api/v0/devices/{hostname}/graphs/wireless/{type}/{sensor_id?}",
"list_alert_rules": "http://<host_librenms>/api/v0/rules",
"list_alertlog": "http://<host_librenms>/api/v0/logs/alertlog/{hostname?}",
"list_alerts": "http://<host_librenms>/api/v0/alerts",
"list_arp": "http://<host_librenms>/api/v0/resources/ip/arp/{query}/{cidr?}",
"list_authlog": "http://<host_librenms>/api/v0/logs/authlog",
"list_available_health_graphs": "http://<host_librenms>/api/v0/devices/{hostname}/health/{type?}/{sensor_id?}",
"list_available_wireless_graphs": "http://<host_librenms>/api/v0/devices/{hostname}/wireless/{type?}/{sensor_id?}",
"list_bgp": "http://<host_librenms>/api/v0/bgp",
"list_bills": "http://<host_librenms>/api/v0/bills",
"list_cbgp": "http://<host_librenms>/api/v0/routing/bgp/cbgp",
"list_devices": "http://<host_librenms>/api/v0/devices",
"list_eventlog": "http://<host_librenms>/api/v0/logs/eventlog/{hostname?}",
"list_fdb": "http://<host_librenms>/api/v0/resources/fdb",
"list_fdb_mac": "http://<host_librenms>/api/v0/resources/fdb/{mac}",
"list_ip_addresses": "http://<host_librenms>/api/v0/resources/ip/addresses",
"list_ip_networks": "http://<host_librenms>/api/v0/resources/ip/networks",
"list_ipsec": "http://<host_librenms>/api/v0/routing/ipsec/data/{hostname}",
"list_links": "http://<host_librenms>/api/v0/resources/links",
"list_links_device": "http://<host_librenms>/api/v0/devices/{hostname}/links",
"list_locations": "http://<host_librenms>/api/v0/resources/locations",
"list_ospf": "http://<host_librenms>/api/v0/ospf",
"list_ospf_ports": "http://<host_librenms>/api/v0/ospf_ports",
"list_oxidized": "http://<host_librenms>/api/v0/oxidized/{hostname?}",
"list_sensors": "http://<host_librenms>/api/v0/resources/sensors",
"list_services": "http://<host_librenms>/api/v0/services",
"list_services_device": "http://<host_librenms>/api/v0/services/{hostname}",
"list_syslog": "http://<host_librenms>/api/v0/logs/syslog/{hostname?}",
"list_vlans": "http://<host_librenms>/api/v0/resources/vlans",
"list_vrf": "http://<host_librenms>/api/v0/routing/vrf",
"maintenance_device": "http://<host_librenms>/api/v0/devices/{hostname}/maintenance",
"remove_port_group": "http://<host_librenms>/api/v0/port_groups/{port_group_id}/remove",
"rename_device": "http://<host_librenms>/api/v0/devices/{hostname}/rename/{new_hostname}",
"search_mac": "http://<host_librenms>/api/v0/ports/mac/{search}",
"search_oxidized": "http://<host_librenms>/api/v0/oxidized/config/search/{searchstring}",
"search_ports": "http://<host_librenms>/api/v0/ports/search/{field}/{search?}",
"server_info": "http://<host_librenms>/api/v0/system",
"trigger_device_discovery": "http://<host_librenms>/api/v0/devices/{hostname}/discover",
"unmute_alert": "http://<host_librenms>/api/v0/alerts/unmute/{id}",
"update_device_field": "http://<host_librenms>/api/v0/devices/{hostname}"