Help Needed: API to Move Discovered Instances of Device Data Source to Default Group
Hi,
I have a Python script to move discovered instances of a Device Data Source to a default group. I tried using the PATCH /device/devices/{deviceId}/devicedatasources/{hdsId}/instances/{id} endpoint but wasn't successful. Which REST API should I be using for this?
Code snippet:
import logicmonitor_sdk
from logicmonitor_sdk.rest import ApiException
# Configure API client
configuration = logicmonitor_sdk.Configuration()
configuration.company = 'your_company'
configuration.access_id = 'your_access_id'
configuration.access_key = 'your_access_key'
api_instance = logicmonitor_sdk.LMApi(logicmonitor_sdk.ApiClient(configuration))
# Set up parameters
device_id = 3242
device_datasource_id = 353463564
instance_id = 13543752
device_datasource_default_group_id = 16343007
# Fetch the current instance details
try:
instance = api_instance.get_device_datasource_instance_by_id(device_id, device_datasource_id, instance_id)
print(f"Before Instance Update:\n {instance}")
# Update group information
updated_instance_body = logicmonitor_sdk.models.DeviceDataSourceInstance(
wild_value=instance.wild_value,
display_name=instance.display_name,
group_id=device_datasource_default_group_id,
group_name='@default'
)
# Update the instance with new group information
api_response = api_instance.patch_device_datasource_instance_by_id(device_id, device_datasource_id, instance_id, updated_instance_body)
print(f"After Instance Update:\n {api_response}")
except ApiException as e:
print(f"Exception when calling LogicMonitor API: {e}")
hkommuri
Posted 1 year ago·Last reply 1 year ago
6 comments
hkommuri
OP1 year agoThe same request from the portal (UIv3) is calling the REST endpoint used in my code, and the result is the same—the instance is not moved to the default group, even though a 200 response is received.
However, after the portal switched to UIv4, the request is now handled by "PATCH /santaba/rest/dataSourceInstances HTTP/2". While I'm unsure about the exact REST API call it is making, instances are being successfully moved.
Mike Moniz
·1 year agoIf you click on that entry in the Network tab, there will be a Request (and Response) tab that should show you the full details. Turning on "raw" may make it easier to read.
hkommuri
OP1 year agoI checked, and the request payload differs between UIv3 (which matches REST API v3) and UIv4. The UIv4 request payload follows below format, with the header set to X-version: 4. However, I can't find the REST API documentation for that version yet. 😞 (It hasn't been published.)
Mike Moniz
·1 year agoI don't know this myself but one trick is that the portal itself mostly uses the same API. So frequently you can make the change in the portal and see the network request in the browser's Dev tools. There are some undocumented/inaccessible APIs the portal uses too, but most are the same you would use. If it doesn't work try using uiv3, I haven't checked recently if uiv4 changes things.