Any way to automate tasks via alerts?
Hi,
I know LM doesn't support taking any action when there's an alert. However, I'm wondering if anyone has any neat ideas on how to accomplish something by way of some other automation program. Maybe Power Automate?
Here's what I'm thinking.
I have a module that monitors a service to see if it's running or not. If it's not, it generates an alert. This seems like the most basic thing to automate because all I'd want to do is run the start-service command to start it back up. So, I'm wondering if I can have the alert send an email to a certain address. That address could then watch for a certain email to arrive. It could then parse out the servername and service name and put that into a start-service -computername xxx -name yyy.
Has anyone looked into doing anything like that and did you have any success?
Thanks.
Michael Baker
Look at StackStorm integration? webhook to there and then write actions based on the alert context?
Or even something like a generic webhook to say a self hosted n8n instance again do things based on the context
Rob Sapsford
Could you just include the logic to restart the service in the existing datasource?
I've done something similar with a datasource collection. Checks to see if the service is running, tracks restarts, checks to see how long the service is up (didn't want to issue a restart if the service is starting due to a reboot), etc.
Regarding your direct question, I think you could automate it with Alert rules and Integrations (custom email delivery or custom HTTP delivery).
I'm sure others will have stronger suggestions.
Kel L
OPI've always been told that LM doesn't have the ability to take any action based on an alert. If there's a way to have LM issue a Start Service command, when it sees that one has stopped, I'd love to know how to do that.
Rob Sapsford
In which scenario?
The first I was talking about is taking the action in the datasource. For example, you have a Powershell datasource that checks to see if a windows service is running and if it's not, it restarts the service. I see your point that it isn't really based on an alert, but it's still doable and I've used it in basic situations to pretty good success. You could create an alert about restarting the service if you wanted to track restarts. If you go this route, I'd recommend you check server uptime (you don't want to re-start the service if the server was just rebooted and it hasn't been up long enough for the service to start).
The second would be to create an alert rule and an integration (specific alerts send to a specific integration). The integration is either a http or email delivery. You'd need to code the endpoint for the integration to take an action based on the alert. For example, a lambda function in AWS.
Hope this helps. I'm sure you'll get other good (probably better) feedback.
Cheers!
Kel L
OPOh. So I could make a PowerShell source that would be a script to check if the service was running, and start it if it wasn't, all within the script. So LM wouldn't be doing anything other than running the check every X minutes. The script would get the status of the service and run a start if it wasn't working?
That's a near idea. Are there docs on how to create a PowerShell DataSource? hmm.
Rob Sapsford
Yep. I've done pretty much exactly that in some places. LM would run the check every X minutes, check to see if the service is running, and return a value (e.g. 1) if it is running. If it is not running, it would attempt to restart the service and then check if it was successful, etc. You could also read in from a custom property which services you cared about.
There is a very knowledgeable user who posts a lot here (@Stuart Weenig). This is a link to his github where he does pretty much what we're talking about. Hope I'm not breaking any rules by posting it. Service_restart
Kel L
OPI just tried importing the file and got an error about an Applies To Function or something.
Any ideas?