This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Alert Manager - Trigger Actions, external programs, and arguments

I'm trying to use the Alert Manager to trigger an external application, well really a PowerShell script, but because PowerShell isn't an option in the trigger actions, I've selected external application and fed in PowerShell and the script name. I'm then trying to pass arguments to the PowerShell script which the script uses to do some action (Triggers a RESTful API call to some vendor service).

This isn't working, in fact, it doesn't appear to execute it at all, so I went dumb. I made a very basic script that takes 2 arguments, and writes to a log file...

param(

    [Parameter(Mandatory=$true)]

    [string]$Node,

    [Parameter(Mandatory=$true)]

    [string]$Status

)

Add-Content -Path c:\temp\log.txt -Value $('{0} is in {1}' -f $Node, $Status)

Then I setup a test alert that has an alert trigger that looks like this:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe D:\Scripts\svc_check.ps1 -Node ${NodeName} -Status ${Node.Status}

I verified that local service had write access to the temp folder, and the file mentioned, I even used psexec to launch a command prompt as the local service account, and tested execution.  When I trigger a test of the alert, it writes that the action was successful, and yet nothing was written to the temp file.

sw_alert_execprog.png

If I copy the line executed from the test log, and paste it into the same command prompt running in the service context, it works fine.

What am I missing? How can I enable more logging for the alert manager to see what's going on, because success isn't really true? Or am I just using the function incorrectly? Can we not pass arguments to executables?

  • I thought I'd closed out my own thoughts on this one after uncovering a solution.  Despite a system wide execution policy being defined on the server to allow scripts to run (Set-ExecutionPolicy RemoteSigned), this was still not working when executed as a service.  This could be due to elevated security due to it being a service.  Ultimately the solution was to call powershell.exe with extra switches.

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy unrestricted -command D:\Scripts\svc_check.ps1 -Node ${NodeName} -Status ${Node.Status}

    Without explicitly telling PowerShell to run unrestricted, it never executed, even when set at the System level.