Forum Discussion

Lewis_Beard's avatar
2 years ago

Does the API work for updating a Collector's customProperties? (V1)

I have some code that snags the custom properties from a collector (/setting/collectors) and then I'm updating or adding one, and then I use /setting/collectors with the collector ID to make an update.
And my code works perfectly if I update the description and put the description as the patchFields. I can update my description to "MEH" or whatever.

But as soon as I try to set the customProperties, nothing happens. The data is just like it needs to be. I even get a response of 200.

So I can update description but not customProperties. I wonder if I'm doing it right, maybe you cant update them in bulk (total replace)?

Any thoughts? Code fragment below.

                    if c_update_required == True:
                        print ("Update REQUIRED")
                        patch_data = '{\'customProperties\': ' + str(new_collector_properties) + '}'
                        #patch_data = '{"description":"' + 'MEH' + '"}'
                        http_verb ='PATCH'
                        print (patch_data)
                        resource_path = '/setting/collectors/'+collector_id
                        query_params ='?patchFields=customProperties'
                        #query_params ='?patchFields=description'
                        url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resource_path + query_params
                        epoch = str(int(time.time() * 1000))
                        requestVars = http_verb + epoch + patch_data + resource_path
                        hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
                        signature = base64.b64encode(hmac1.encode())
                        auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
                        headers = {'Content-Type':'application/json','Authorization':auth}
                        
                        patch_response = lm_session.patch(url, data=patch_data, headers=headers)

                        if patch_response.ok:
                            print("Success")
 

Oh and below you can see the customProperties I get back when snagging it, and what I have it set to when I try to set it. I'm sure its right. BUT I am completely stumped. Success 200. No change.

                        GET DATA:    customProperties': [{'name': 'bar', 'value': 'Melvin NoName'}, {'name': 'foo', 'value': '123'}]
                        PATCH DATA: 'customProperties': [{'name': 'bar', 'value': 'Melvin NoName'}, {'name': 'foo', 'value': '123'}, {'name': 'mynew.clientID', 'value': '1037524379'}]

                        
Any ideas? Description works, customProperties does nothing, but both give status 200.

 

  • Just in case someone finds this later, it seems that v1 just didnt do it. I switched to v3 using the header, and converted my patch data to json compatible (swapping single quotes for doubles) and it worked fine (I had tried the json format on the single quote version in my OP under v1 and it didnt work).

    Here is the final code fragment, in case anyone is interested. I changed 3 things, more or less: 1) resource path changed to v3 style, 2) headers have v3 info in them, 3) I converted the re-built collector properties to json style with json.dumps.

                        #update the COLLECTOR CONTEXT if required
                        if c_update_required == True:
                            #build request (API v3)
                            patch_data = '{"customProperties": ' + json.dumps(new_collector_properties) + '}'
                            http_verb ='PATCH'
                            resource_path = '/setting/collector/collectors/'+collector_id
                            query_params =''
                            url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resource_path + query_params
                            epoch = str(int(time.time() * 1000))
                            requestVars = http_verb + epoch + patch_data + resource_path
                            hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
                            signature = base64.b64encode(hmac1.encode())
                            auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
                            headers = {'Content-Type':'application/json','Authorization':auth,'X-Version': '3'}
                            
                            patch_response = lm_session.patch(url, data=patch_data, headers=headers)

                            if patch_response.ok:
     

    (etc)

  • Anonymous's avatar
    Anonymous

    Yeah, def don't build on API v1. It's going away "soon".