5 Replies Latest reply on Oct 8, 2017 2:58 PM by thsw

    Central Repository for Scripts


      Hi All,


      I hope someone can help on an issue related to the component Linux/Unix Script Monitor and in general with components that allow to add some custom code for a check, like Nagios script monitor and Windows script monitor.


      Let's say I have developed a general script, called check_folders for example, and that it's long 100 lines of code, in order to check multiple folders for certain conditions.

      Also let's assume I can pass the folder to be checked via command line and that the script will check what's needed based on that parameter.


      if [ -d "$1" ]; then
        echo "Message: Congratulations, $1 exists!"
        echo "Statistic: 1"
        exit 0 # UP
        echo "Message: Oh nooo, $1 Does NOT exist!"
        echo "Statistic: 0"
        exit 3 # CRITICAL
      # We shouldn't reach this point
      exit 4 # UNKNOWN
      # This is very basic, let's assume it's a 100 lines script, for the purpose of this post :)


      What I understand I can do in SolarWinds is creating an Application Template and add a Component Monitor called Linux/Unix Script Monitor.



      Than I need to configure the component by doing (just the important bits here)

      • Script Working Directory > /tmp
      • Command Line > /bin/bash ${SCRIPT} FOLDER_TO_CHECK
      • adding the script in the Script Body section



      Now imagine that the behaviour of the script is not that simple and that it would output different messages and statistics according to the name of the folder specified at command line.


      I would need to call exactly the same script multiple times, inside my application template, to make sure that everything is working fine; each time with a different folder, e.g.


      • /bin/bash ${SCRIPT} /tmp
      • /bin/bash ${SCRIPT} /var
      • /bin/bash ${SCRIPT} /opt
      • /bin/bash ${SCRIPT} /home
      • /bin/bash ${SCRIPT} /etc
      • etc.


      My understanding is that I can clone it by copying it to an Application Monitor Template but before doing that I have to assign it at least to a node. So I have to:

      • open Manage Application Monitor Templates
      • find my template
      • assign to a node
      • go to Manage Assigned Component Monitors
      • find my component
      • select my component (the one I'd like to duplicate)
      • click on Copy to Application Monitor Template


      • assign it to my template


      That's not the end of the story, then I have to

      • click again on my component
      • edit it
      • change the Command Line to /bin/bash ${SCRIPT} /var, for example
      • submit it


      I know, it's a long journey , maybe someone knows how to do it faster?


      Now I'm going to make it a bit more interesting. I need to do the above 10 times, i.e. 10 folders.

      That would mean duplicating 10 times my component and therefore 10 times my "100 lines" of code, for a total of 10 components and 1000 lines of code!


      Ideally if everything has been done perfectly we'll never need to change the code but that's not what the real world teaches us.

      What should I do if I find something's wrong in my initial script? Change it on the first component and re-duplicating or copying and pasting the new code to all the other components??


      Maybe I'm not using the tool the right way but this doesn't seem quite right to me?


      Does anyone know if it's possible to set up a central repository where I can put my script and tell SolarWinds to retrieve it in each component so that it can be referenced as many times as needed?


      Ideally it would be nice to link the Script Body to a versioning system.


      Thanks in advance for your help!

        • Re: Central Repository for Scripts

          No central repo capability exists as of now, in cases like yours where scalability of a repeating function becomes an issue I usually begin to edit the SQL directly, but that can be a bit of a mess to manage if you aren't familiar with the DB.  IIRC in the case of the scripts they are all stored on [dbo].[APM_ExternalSetting], I think the args are stored under the componentsettings or templatesettings table though.

            • Re: Central Repository for Scripts

              Thank you. As a general rule it would be better not to allow people to play around with the database but I appreciate you saying there is no central repo.

              Any better idea on how to improve the process without acting on the database? Thanks!

                • Re: Central Repository for Scripts

                  The only way I could think would be to write it such that the script of the SAM component doesn't actually contain the real meat of the scripts, instead you create it as a sort of pointer and place holder, have the script in SAM point to another file on your repo and display the second scripts outputs.  Thinking it through it seems like the best bet would be to do all SAM scripting functions using the SAM powershell component, locally execute them, load the ssh plugin, read the repo files to get the actual ssh/bash/whatever stuff you need it to run.  Definitely would need a good bit of testing to get it going but I believe it could be done.  Then all you need to do is edit the repo file and it would instantly have that change propagate to all the instances of the SAM template.  One thing to watch out for is if you change the name and number the outputs then the SAM components would definitely complain as they establish the outputs they expect the first time you run it and changing them on the fly causes it to complain.

                    • Re: Central Repository for Scripts

                      I see what you mean, it's pretty much like double indirection.


                      Correct me if I'm wrong, are you saying something like:


                      PowerShell Component > Run the Script Body Code locally on the SolarWinds Server(?) / Poller?,

                        (not sure about loading the ssh plugin, is it from the PowerShell script?) >

                      > get the file from the repository > remotely execute on the destination server (where I'd like to do the check) > return the result as text

                      (but then I would need to manage the exit codes properly)


                      I'll try to have a look at the PowerShell component to see what I can do.

                      It sounds to me though that rolling this out to users that need to use this method may add an extra layer and potential issues with the maintenance of the solution.


                      Thanks for the advice!

                  • Re: Central Repository for Scripts

                    This is a feature request for a Component Template


                    Create component templates or copy existing components


                    It might partially apply to what I'm asking here.