Forum Discussion

Lewis_Beard's avatar
3 years ago

LM SDK update_device_datasource_instance_alert_setting_by_id (and auto.interface.ifindex vs system.instanceId)

All,

So I used the Logicmonitor_sdk to pull the device id, instance id, instance wild value, and the datasource id on the device, because my goal was to try to use the API to set an alert threshold on InMbps for a modified clone of Network Interfaces.

I'm sure I have the right numbers, because all my api pulls show in the response the values I'm using.

device_id = 31068
datasource_id = 2106068
instance_id = 12776109
instance_wild_value = 37978112
alert_setting_id = 18572

Original Body values for the alert setting I pulled, if I were to try to set it to the exact same thing:

    body = {
        "global_alert_expr":'',
        "alert_clear_interval":0,
        "disable_alerting":False,
        "alert_expr_note":'',
        "data_point_description":'Inbound throughput, in megabits per second.',
        "data_source_instance_id":12776109,
        "disable_dp_alert_host_groups":None,
        "data_point_name":'InMbps',
        "data_point_id":18572,
        "device_group_id":10895,
        "parent_device_group_alert_expr_list":[],
        "alerting_disabled_on":None,
        "id":18572,
        "data_source_instance_alias":'1/2/7, 10/100/Gig Ethernet SFP, "eNodeB001-LTE-e" [ID:37978112]',
        "device_group_full_path":'blah/blah/WSAE/All Devices/7705 DES',
        "alert_expr":'',
        "alert_transition_interval":0
    }

Body I'm actually attempting to set:

    body = {
        "id":18572,
        "alert_expr":'>= 99 99 99'
    }
 

    #from SDK DOCS: update_device_datasource_instance_alert_setting_by_id(deviceId, hdsId, instanceId, id, body)
    update_response = api_instance.update_device_datasource_instance_alert_setting_by_id (device_id, datasource_id, instance_id, alert_setting_id, body)
    print (update_response)
 

RESULTS: when I call the update on the alert setting, I get an OK response, and a response body IDENTICAL to the body I got when querying the alert setting BEFORE my change. So it seems this call did NOT actually do anything, aside from give me an OK response with an unchanged body.

QUESTIONS:

1) Has anybody else used this method? Does it just not work? I am pretty sure I have all the right numbers for the params because when I dont, an error happens.

2) what is the difference between auto.interface.ifindex and system.instanceId ? The API tells me different values for instance ID and instance WILD ID. Instance ID corresponds to system.instanceId on the instance's info (in the UI), and the WILD ID corresponds in the UI to auto.interface.ifindex, and is also the [ID: blah] shown on the display name.

 

So I'm just hoping someone can see anything I'm doing wrong in terms of maybe using the wrong values conceptually in the code above, or if you've experienced the same problem of the update just not doing anything, or even knowledge of the difference between auto.interface.ifindex and system.instanceId.

 

Thanks!!

 

 

 

3 Replies

  • 43 minutes ago, Lewis Beard said:

    Does it just not work?

    That may very well be. I've run into some parts of the SDK that just don't do what they're supposed to.

    auto.interface.ifindex is the number used to identify the interface on the device. It should be the same as the wildvalue and the [ID: blah].  It is used when polling via SNMP as it forms the last term in the OID.

    The system.instanceid is the id number LM uses to identify that object in the database. This should be the ID number used in API calls.

  • Thanks. I also just asked an engineer in support chat and they told me the same thing about the ifindex.

    So the good news is, I was using the correct value in my SDK call (the instance id in LM).

    But I guess that means the bad news is that I was making the call right, using the right values, so maybe this part of the SDK isnt implemented.

    I guess I could drop back to just using the API directly, but it makes the code so ugly having to build all the security and URL and verb stuff with all the credentials for every single thing. But I guess I could try the update the naked way.

     

    Thanks!

     

  • On 7/22/2022 at 8:52 AM, Lewis Beard said:

    it makes the code so ugly

    Yep, it does. Squirrel that away into a library you import? I just had to do that because i needed to make some v3 API calls that don't exist in the SDK at all.

    import requests, json, hashlib, base64, time, hmac
    
    def LM_API(AccessId, AccessKey, Company, httpVerb, resourcePath, data=""):
        url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath
        epoch = str(int(time.time() * 1000))
        requestVars = httpVerb + epoch + data + resourcePath
        digest = hmac.new(
                AccessKey.encode('utf-8'),
                msg=requestVars.encode('utf-8'),
                digestmod=hashlib.sha256
        ).hexdigest()
        signature = base64.b64encode(digest.encode('utf-8')).decode('utf-8')
        auth = 'LMv1 ' + AccessId + ':' + str(signature) + ':' + epoch
        headers = {
            'Content-Type':'application/json',
            'Authorization':auth,
            'X-Version': "3"
        }
        if httpVerb == "GET":
            response = requests.get(url, data=data, headers=headers)
        elif httpVerb == "POST":
            response = requests.post(url, data=data, headers=headers)
        elif httpVerbe == "PUT":
            response = requests.put(url, data=data, headers=headers)
        # print('Response Status:',response.status_code)
        # print('Response Body:',response.content)
        return json.loads(response.text)