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.
#!/bin/bash
if [ -d "$1" ]; then
echo "Message: Congratulations, $1 exists!"
echo "Statistic: 1"
exit 0 # UP
else
echo "Message: Oh nooo, $1 Does NOT exist!"
echo "Statistic: 0"
exit 3 # CRITICAL
fi
# 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!