Monitor script execution

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
liviobai
Posts: 4
Joined: Thu Mar 23, 2017 11:11 am

Monitor script execution

Post by liviobai »

Hello
I triend to search in the forum, but is not simple to find useful results when you have "script" as key search.
My question is:
If we have a bash script in a server is it possible to monitor if the script is correctly finished with nagios?
Normally a bash script have an exit status and can send an email in case of the script do not run correcly.
If you need to create a new script I know that we can manager exit status and nagios check, but suppose you have 10 old script that you want to monitor, how you can do that?

For example I found that zabbix have this plugin.
https://share.zabbix.com/dir-libraries/ ... monitoring

Maybe Nagios has a similar plugin?

Thank you
Liv.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Monitor script execution

Post by mcapra »

I don't know of anything ready-made for a use case like this, but you're welcome to check on the exchange:
http://exchange.nagios.org/

In my mind, you could write a Nagios plugin that simply runs all 10 of your old scripts and checks their respective output codes. The plugin doesn't need to be terribly sophisticated, it could be a wrapper written in Bash that breaks on an "problem" exit code for your scripts. The pseudo-code might look like:

Code: Select all

for(script in list) {
    if(script's exit code == some_bad_value) {
        exit 1 or 2 or 3
    }
}
Guidelines for developing a Nagios plugin:
https://nagios-plugins.org/doc/guidelines.html
Former Nagios employee
https://www.mcapra.com/
liviobai
Posts: 4
Joined: Thu Mar 23, 2017 11:11 am

Re: Monitor script execution

Post by liviobai »

Thank you for the reply
Unfortunately I can't run from nagios the scripts because we need that is the server itself that run script.
I will check your link and maybe at this point I will check if it is possible to migrate the zabbix plugin to nagios.
Other solutions are welcome
avandemore
Posts: 1597
Joined: Tue Sep 27, 2016 4:57 pm

Re: Monitor script execution

Post by avandemore »

From what I can tell you are describing how Nagios runs plugins in general. You can find more information about that here:

https://nagios-plugins.org/doc/guidelines.html
Previous Nagios employee
liviobai
Posts: 4
Joined: Thu Mar 23, 2017 11:11 am

Re: Monitor script execution

Post by liviobai »

Hi avandemore
Maybe I am not explained well my problem.
Suppose you have a script that run in your server and for example move files between dir or make a complex job etc...
suppose that this script run and if all go well script send you an email with "all ok", otherwise send an email with "no ok, this is the error".

Suppose now that you do not want to check the emails, but you want only to find an alert in nagios.
How you can do that without modify the script? Or at maximum only with little mody without touch the core script that is not owned by you and is better to not touch...
The zabbix solution is interesting because you need only to put some line of code on top and bottom of the script without change the logic of your script, and if you have 100 script in 10 servers it is easy to modify it via an ssh script.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Monitor script execution

Post by mcapra »

liviobai wrote:Unfortunately I can't run from nagios the scripts because we need that is the server itself that run script.
Then you'd leverage an agent like NCPA, NRPE, NSClient++, just to name a few (the docs mention Nagios XI, but they are also valid for Nagios Core). The agent would then be responsible for running the script and relaying the results to Nagios Core.
liviobai wrote:Suppose now that you do not want to check the emails, but you want only to find an alert in Nagios. How you can do that without modify the script?
The script would have to be following the Nagios plugin guidelines, or have a wrapper that follows those same guidelines shared by @avandemore. The guidelines aren't terribly strict; All Nagios Core really needs is a standard Unix exit code to determine the status of any given check. In my mind, instead of sending a "there is a problem" email from your script, you would just have it exit 1 for warning or 2 for critical. Wouldn't need to be much more sophisticated than that for Nagios Core to pick it up.
Former Nagios employee
https://www.mcapra.com/
liviobai
Posts: 4
Joined: Thu Mar 23, 2017 11:11 am

Re: Monitor script execution

Post by liviobai »

Thank you for the indications, I will check docs :)
avandemore
Posts: 1597
Joined: Tue Sep 27, 2016 4:57 pm

Re: Monitor script execution

Post by avandemore »

Great let us know!
Previous Nagios employee
Locked