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.

Calling existing script from SAM

I find the option of being able to execute bash scripts from SAM to be very useful and helpful. However, that requires me to add those scripts to SAM monitor template. I wonder if there is a way to call an already existing script on the system.

So, I have developers that utilize helpful scripts to monitor stuff on their servers. I would like to incorporate those into Solarwinds. It works if I copy it directly into SAM template but those scripts get edited/changed fairly often and I can't keep up with updating the templates every time. Is there a way to directly call those scripts from SAM?

Thanks!

  • Just make a small SAM powershell script that calls the other script.  

  • Or a small BASH script in this case
  • Yep, sorry, it did specify bash scripts.  I need to learn to read...

    so on the linux scripts, there is a "command line" option as well as the "Script Body".  *IF* the script already outputs the proper SAM "statistic:" format, then you can call the script from the command line, and in the script body isn't used.  You will still need to edit the script to get the output results, so just put in a "#" as the script body.

  • That was my first thought but I didn't know if there are any issues with this method or if there was a better way to handle it.

    So, now, when I add command line argument to point to the actual script, I get the result back in the correct format but SAM doesn't recognize it (with Script body being empty). When I test it, it fails but does return correct values.

    7877010F-B717-40B8-AAEF-66611FC9E78F.jpg

  • One possibility is that the exit code from the script is non-zero.

    When you manually run it at the command line, do "echo $?" to see what the exit code was.

  • It does return 0. Actually, when I test the script in SAM it returns the correct values, it's just not recognized by SAM. As if I need to convert those return values somehow.

    This is the return of test:
    No fields were recognized in the script output:
    Statistic.Alias1Age: 0
    Message.Alias1Age: alias-..... on a..........edu is 22 seconds (0:00:22) old.
    Statistic.Alias2Age: 0
    Message.Alias2Age: alias-...... on a..........edu is 22 seconds (0:00:22) old.
    Statistic.Alias3Age: 0
    Message.Alias3Age: a....... on a.........edu is 22 seconds (0:00:22) old.
    Statistic.Alias4Age: 0
    Message.Alias4Age: a........ on a...........edu is 22 seconds (0:00:22) old.

  • It looks right.  I litterally took your text made it a script with just echo's of your data and it works.

    2020-02-27 14_11_38-New Application Template.png

  • Building on that, it is pretty unlikely that pre-existing scripts would already be in a SAM friendly format, but you could just execute their script, then in SAM the body of our script translates whatever they gave you into Statistic: Message: format for Orion.

  • When they were writing their scripts, I told them what they needed to add to make it SAM-friendly which they did. If I copy the script into SAM, it works. So, my question is if I want to use the output of the script, how do I manipulate it? If in "command line" I'm putting /dir/folder/script.sh (the script is executable).

  • Ok, next step.  Assign the template to the node, even though it's not working quite right.  Edit the monitor (or I guess you could do this in the template), and turn Debug: On.  And do a "poll now".

    Then on the node, go to /opt/SolarWinds/Agent/bin/appdata/Logs/ApplicationLogs/AppId<blah>

    See what the log says.