Embedding output into an alert email action

Hello everyone,

I'm stuck and I'm not sure what to do next.  First the disclaimer,  I am NOT a programmer, so the majority of my code was inherited by a lot of you in the community or in the Google universe.  


Embed output from a batch file into an email alert action.  The output is ping and tracert results from the poller to the device.

Trigger Actions - Configuration Settings:

1st trigger is Execute An External Program:

Network path to external program = c:\Scripts\Ping-TraceRT.bat ${IP_Address} ${NodeName} -alert=${N=Alerting;M=AlertDefID} -alertId=${N=Alerting;M=AlertID} -${N=Alerting;M=Notes}

I'm receiving the expected output (ping and tracert) results in the text file.

2nd trigger is Send An Email/Page:

Message body:

Device Name: ${NodeName}
IP Address: ${N=SwisEntity;M=IP_Address}
Status: ${N=SwisEntity;M=Status}
Group: ${N=SwisEntity;M=CustomProperties.Assignment_Group}
Priority: ${N=SwisEntity;M=CustomProperties.Priority}
Date: ${DateTime}
Polling Engine: ${N=SwisEntity;M=Engine.DisplayName}

Ping & Tracert Information:

The email doesn't contain any of the expected output from the batch file.  My first thought is that I'm missing something in script, but I'm not sure what that is and I'm not sure how I would code it.

Attached is the batch file I'm using.

@echo off

  cd C:\Scripts

  rem: This sends the Orion variables to a text file for later analysis.  This overwrites existing files of the same name.

  echo %* > %2.txt

  rem: This appends a ping to the text file.  This appends to the current file.

  ping %1 >> %2.txt

  rem: This appends a tracert to the text file.  This appends to the current file.

  tracert %1 >> %2.txt

  • Corrected the Subject line. Got a little paste happy. We're on the 2020.5 HF1 version.  I updated the network path to include the quotes. I installed the OrionSDK.msi which included the SwisPowerShell module.  The install didn't ask the question about all users or just one.  I've been using the Define user option it tests successfully.  One thing I will mention, when I  tested the connection using $swis = Connect-Swis, I entered my local SolarWinds administrator account to access the API. Since it's not a Windows account, do I need a Windows account with Admin permissions to run this successfully?  I checked the Alert Notes on Web and the field is blank. Could it be a timing thing?  Maybe the script is taking longer than 5 minutes.

  • It might be taking longer than 5 minutes.  If so, that's an easy fix.

    If you are running it on the Orion server itself, you should be able to connect to SWIS via:

    $SwisConnection = Connect-Swis -Hostname "OrionServerNameGoeshere" -Certificate

    That'll connect with the Orion 'service' account and won't need credentials.

    What if you run the script set manually?

    Open a command prompt (not PowerShell) window and put the execution string (swapping in a valid IP and a valid AlertObjectID)?

    Then when I refreshed the web page at /Orion/NetPerfMon/ActiveAlertDetails.aspx?NetObject=AAT:1080

    I got this:

  • OMG - I think I've been leading you down the complete wrong path here.  Let me investigate something...

  • No worries.  Wink Just as an fyi, I did follow the steps above and I did receive output (similar to yours) for the Alert Notes. I ran it in CMD with the service account.

  • After re-reading the names of the verbs and having a come to $diety meeting with myself, I think we need to use the AddNote verb on the Orion.AlertStatus entity.For parameters it takes:

    • [string]alertDefinitionId
    • [string]activeObject
    • [string]objectType
    • [string]note

    Like I said before, I need to dig in a little bit more here and do some testing, but the framework we already have should work.  I'm so, so sorry for the delay.

  • No need to apologize.  I REALLY appreciate your help with this. I'm learning a lot and it's forcing me out of my comfort zone by getting me to learn the code so that I can do this myself going forward. 

  • OK - I think I've got it (but I've said that before haven't I?)

    The files are:

    I've rewritten them to be a little more in line with some best practices, but it's not my best work.

    I also added notes/details in the first one on how to call it.

    After I executed it, this is what appeared on my web console:

    Let's (hopefully) call that part done.  You can validate after you make the edits by running:

    SELECT AlertDefID
         , ActiveObject
         , ObjectType
         , ObjectName
         , AlertMessage
         , Notes
    FROM Orion.AlertStatus
    ORDER BY ObjectName

    In SWQL Studio and looking at the "Notes" field.

    In my environment, the total execution time for the script was 1.39 minutes - so under the 5 minute thing.

  • Verified that this works on two nodes running the script through the command line.  Just like you I received the correct information in the History of this alert on this object and in the Alert Notes field.  Both ran under 2 minutes.

  • Let's count this as step 1 being complete.  The script works and updates the notes.  Hopefully the second part (your email message) picks up the details. Fingers crossed

    Let me know how you fare. (I don't have email enabled in my home lab, so that's one part that I cannot test properly).

  • Seems to only work through the command line and not through the alert action.  I tested six devices and none of them show any of the ping & tracert information.  I checked the Orion.AlertStatus and none of them have a note.  I added the parameters in prior to enabling the alert with the below information.  The interesting thing is that the variable search page does not have an ActiveObject option.  I went ahead and added it manually ${N=Alerting;M=ActiveObject} but that didn't help and also tried "${N=Alerting;M=AlertID}" which was listed in the search options.  That didn't work either.  I also tried putting the IP address, AlertDefID, ActiveObject and Node and that didn't work. Both actions are set with the service account for authentication.  I also tried it with Default System and that didn't fix it.  All the simulation tests have been successfully with no errors.

    "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Unrestricted -File "C:\Scripts\Ping-TraceRT.ps1" "${N=SwisEntity;M=IP_Address}" "${N=Alerting;M=AlertDefID}" "${N=Alerting;M=AlertID}" "Node"