Hi.
I want to use the Execute An External Program as a Trigger Action on an alert. I want that to call a powershell script, but i also want to pass the Server Hostname generating the alert to the powershell script. Has anyone been successful and if so can you please explain how to do this. Screenshot below is an example of what i thought after reading other pages i could do. I am doubting the variable i call out is correct, or is that even the correct method to pass it?
Also when you do get the name to pass corrrectly, how do you then get that parameter in your script. What i read suggests if you pass 1 parameter it would be $args[0] so something like
$hostname = $args[0]
Can anyone please help me with this. I have taken the live trainings and asked in there. Seems my question was out of scope for those trainings, or the trainers don't work with powershell or doing this type of action much.
Thanks in advance.
I'll also include 1 use case here. I only use SAM for server monitoring. The OOTB Node Rebooted is generic. Email alert says "Hostnmae rebooted". I want to use a Powershell script to collect the event from the host for the reboot and the message stating who/why the server rebooted. so like this.
$server = "$args[0]"
$info = Get-WinEvent -ComputerName $server -FilterHashtable @{Logname='System';ID=1074} -MaxEvents 1
$time = $info.timecreated
$message = $info.message
$body = "Server $server has rebooted at $time, `n $message "
then use Send-Mailmessage to email out the alert.