Forum Discussion

Shawn's avatar
7 years ago

How to change "Send Collector Down Notification" to more then 60 collectors using script

I have more then 100 collectors. I want to change "Send Collector Down Notification" to "One Time" all at once. Is it possible using script or do we have any other option rather then going into one by one manually to do it. At the moment they all in a single group say "Group A" most of them are set to 15 minutes. I want to change them all into "One Time" any suggestions..

3 Replies

Replies have been turned off for this discussion
  • Hi Shawn, 

    Yes, you can use our REST API to programmatically change the "Send Collector Notifications" to One Time.  We have documentation on how to make the PUT request here, but you can use a PATCH request so that you're only modifying the resendIval field.  Here's the code I used to execute this:  

    #Request Info
    httpVerb ='PATCH'
    resourcePath = '/setting/collectors/8'
    queryParams = '?patchFields=resendIval'
    data = '{"resendIval":0}'
    
    #Construct URL 
    url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath +queryParams
    
    #Get current time in milliseconds
    epoch = str(int(time.time() * 1000))
    
    #Concatenate Request details
    requestVars = httpVerb + epoch + data + resourcePath
    
    #Construct signature
    signature = base64.b64encode(hmac.new(AccessKey,msg=requestVars,digestmod=hashlib.sha256).hexdigest())
    
    #Construct headers
    auth = 'LMv1 ' + AccessId + ':' + signature + ':' + epoch
    headers = {'Content-Type':'application/json','Authorization':auth}
    
    #Make request
    response = requests.patch(url, data=data, headers=headers)
    
    #Print status and body of response
    print 'Response Status:',response.status_code
    print 'Response Body:',response.content

    With this, you'll loop through your collector ID's (recommend using the GET all collectors request, followed by the PATCH requests).

    Hope this helps!

    Jake

  • Hi Jake,

    Good day, I have trouble in running this script. I tried to change the "Collector/8" number to one of my collectors say 86 for ex. I have updated this script in the "data source" in Logic monitor  but still having trouble to run this script. it shows no results.

    I use logic monitor for a long time but I am a bit new to running scripts in it. Could you please guide me on how to/where to put this script and run successfully. any kind of help/ links is appreciated.

     

    I also have question on whether to run this in the "Data Source' logic monitor or run on the server in the powershell where logic monitor installed.

     

    thanks for all your help.