Forum Discussion

Savad_Mottammel's avatar
5 years ago

Run Script only if the Device/Instance is not under SDT

I've created a Datasource to Monitor Windows Service on machine and try to restart it using Powershell.

But, i want it to run only if the Machine/Instance is not under SDT.

How can i write it the code?

How can i get the SDT status from LM via powershell.

  • Anonymous's avatar
    Anonymous

    You'd have to write a bit of powershell code to fetch the current SDT status from the LM API. Generate an API token and set the ID and key as a properties on the group containing your servers. I recommend calling these properties after your datasource since that is how it will be used. Once you have that setup, you can pull those values into your posh script and call the Devices endpoint: https://www.logicmonitor.com/swagger-ui-master/dist/#/Devices/getAllSDTListByDeviceId. I believe the "isEffective" attribute should do it. You can pull in the system.deviceId property to construct the API call url.

    I know this is a bit bare bones. Let me know if you want more detail on what the script strategy would be.