Hello Team,
I have added most of the devices in LibreNMS, i am checking the possibilities if i can export all my switches so that it can pull like model, OS, Serial number of the switches, As i need to create an inventory for the switches first and servers, If you can assit me on this, would be very helpfully.
Well, you have a MySQL/MariaDB with all the information so building a query, save as CSV and import into excel should be simple with a bit of SQL knowledge.
Or use the API with a quick script. Create a read only API token then run the script. In Python something like…
import requests
import json
import urllib3
urllib3.disable_warnings()
api_token = "000000000000000000000"
librenms_url = "https://librenms.local"
output_file = "./librenms_inventory.csv"
headers = {
"X-Auth-Token": api_token,
"Content-Type": "application/json",
}
try:
# Get all devices
response = requests.get(f"{librenms_url}/api/v0/devices", headers=headers, verify=False)
response.raise_for_status()
data = response.json()
if data["devices"]:
for d in data["devices"]:
if d["serial"]:
line = (f'{d["device_id"]}, {d["hostname"]}, {d["sysName"]}, {d["ip"]}, {d["hardware"]}, {d["os"]}, {d["serial"]}')
# Write the results to a file
with open(output_file, "a") as f:
f.write(f"{line}\n")
else:
print("No devices found.")
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
except json.JSONDecodeError as e:
print(f"Error decoding JSON: {e}")
1 Like
librenms@wihl-librenms:~$ ./inventory.py
import-im6.q16: unable to open X server ' @ error/import.c/ImportImageCommand/346. import-im6.q16: unable to open X server
’ @ error/import.c/ImportImageCommand/346.
import-im6.q16: unable to open X server ' @ error/import.c/ImportImageCommand/346. ./inventory.py: line 7: syntax error near unexpected token
api_token’
./inventory.py: line 7: `api_token = “88f22e66619af65fabf5631ba0ae52ee”’
Sorry the script run fine, I forget to put shebang, Thank you very much all good.
1 Like
Thanks the script work i forget to put shebange, all good
1 Like