API devices update_device_field does not allow updating hostname


I’m trying to automatically update some of my hostnames in LibreNMS when they are changing with a script. The easiest way to do this would be with the API’s devices->update_device_field call I think. Only when I tried to make a call to this API function with the hostname field I get the following error;

500 Server Error: Internal Server Error for url: https://librenms/api/v0/devices/device-hostname
b'{\n    "status": "error",\n    "message": "Device field is not allowed to be updated"\n}'

Looking through the source code I can see the following in includes/html/api_functions.inc.php:1910$bad_fields = ['device_id', 'hostname'];. Seems like this is denied on purpose, but I can’t figure out why? On the web interface you can update hostnames through the settings page, why not through the API?

Maybe there is another way of doing this? I would like to avoid a direct DB call :slight_smile:

validate.php output for good measure;

Component | Version
--------- | -------
LibreNMS  | 22.9.0-3-g06c361c2b
DB Schema | 2022_08_15_084507_add_rrd_type_to_wireless_sensors_table (248)
PHP       | 8.1.12
Python    | 3.6.8
Database  | MariaDB 10.3.35-MariaDB
RRDTool   | 1.7.0
SNMP      | 5.8

There is a rename_device endpoint two after the one you’ve tried in the doco.

I guess I need to RTFM more. Thanks!

I don’t think you’re alone in finding the API endpoints pages hard to navigate/discover from!

Not sure what the best way to reform that is but we’re all open to ideas.

Perhaps try the Librenms handler

We see here (search for rename) it looks possible:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.