Updating a device's address(IP, FQDN or NetBios, the Address field is always the same) only having the device's old and new address consists of two distinct operations:
1. Since all API operations have to be done based on the ID of the object that you want to change, you have to look for the objects with the current address to find their ID's first, if you were looking for the device with address 1.2.3.4:
/api/table.xml?content=devices&output=xml&columns=objid,probe,device,host&filter_host=1.2.3.4 |
Or if you wanted to partially match a hostname "myserver" but with variations (myserver, myserver.domainx, myserver.domainy) :
api/table.xml?content=devices&output=xml&columns=objid,probe,device,host&filter_host=@sub(myserver) |
The query above would return something like:
<?xml version="1.0" encoding="UTF-8"?>
<devices totalcount="2" listend="1">
<prtg-version>16.2.24.4274</prtg-version>
<item>
<objid>2003</objid>
<probe>Probe on NEMO-VM2012-2</probe>
<device>Some Device</device>
<host>myserver</host>
</item>
<item>
<objid>2236</objid>
<probe>My Local probe</probe>
<device>Some Other Device</device>
<host>myserver.domainx</host>
</item>
</devices>
2. Now, we have to use the previously acquired ID's (2003, 2236) to issue the setobjecproperty operation to effectively change the address. For instance if we were to update the address of "Some Device" (ID: 2003) to newaddress.xyz we would issue the following:
/api/setobjectproperty.htm?id=2003&name=host&value=newaddress.xyz |
To modify several addresses, implement a repetition mechanism that goes trough all resulting ID's and changes them to the new address using the setobjecproperty for every result of the table.xml?content=devices query.
The API will also require you to provide an username and password or passhash for authentication, an introduction to using the API is available here.
If you're looking for a working example for changing the domain in device's names in bulk using a powershell script, you can check out this: KB: Change Device Name Using Script
Best Regards,
Luciano Lingnau [Paessler Support]
Add comment