Page 1 of 2

Monitor uptime with threshold

Posted: Wed Oct 04, 2017 7:02 pm
by ericssonvietnam
Can you let me know how i can monitor server uptime with critical therehold of 30 min.


Checking objects...
Error: Service check command 'check_uptime --warning 30: --critical 15' specified in service 'UPTIME' for host 'localhost' not defined anywhere!

Re: Monitor uptime with threshold

Posted: Thu Oct 05, 2017 10:06 am
by tgriep
The error could be caused from either the check_uptime command is not defined in the commands.cfg file and you could use the example below if needed to add the command

Code: Select all

define command {
command_name check_uptime
command_line $USER1$/check_uptime $ARG1$
}
Or that there is a mis-configuration for the UPTIME service and you would have to post the configuration here so we can see what is wrong with it.
I am guessing that you may be missing the exclamation points (!) in that check between the command name and the threshold settings.

You example for the thresholds should generate a warning if the uptime is less than 30 minutes and a critical if the uptime is longer than 15 minutes.
Take a look at the link below for some threshold examples and adjust your command to your requirements.
https://nagios-plugins.org/doc/guidelin ... HOLDFORMAT

Re: Monitor uptime with threshold

Posted: Wed Oct 25, 2017 7:10 am
by ericssonvietnam
tgriep wrote:The error could be caused from either the check_uptime command is not defined in the commands.cfg file and you could use the example below if needed to add the command

Code: Select all

define command {
command_name check_uptime
command_line $USER1$/check_uptime $ARG1$
}
Or that there is a mis-configuration for the UPTIME service and you would have to post the configuration here so we can see what is wrong with it.
I am guessing that you may be missing the exclamation points (!) in that check between the command name and the threshold settings.

You example for the thresholds should generate a warning if the uptime is less than 30 minutes and a critical if the uptime is longer than 15 minutes.
Take a look at the link below for some threshold examples and adjust your command to your requirements.
https://nagios-plugins.org/doc/guidelin ... HOLDFORMAT
I have added the up time check but i recently checked and found that it is not giving me the correct up-time for the node

Below is how i have added the command.

Re: Monitor uptime with threshold

Posted: Wed Oct 25, 2017 9:30 am
by kyang
@ericssonvietnam, as tgriep mentioned. If your command is the same for check_uptime, could you show us your $ARG$ when using this?

The check command for this service is what we're looking for to see if you are passing (!).

Re: Monitor uptime with threshold

Posted: Wed Oct 25, 2017 9:50 am
by ericssonvietnam
kyang wrote:@ericssonvietnam, as tgriep mentioned. If your command is the same for check_uptime, could you show us your $ARG$ when using this?

The check command for this service is what we're looking for to see if you are passing (!).
Below is how i have defined the command in commands.cfg
define command {
command_name heck_uptime
command_line $USER1$/check_uptime $ARG1$
}
And in remotehost.cfg i have defined service and hostname as below :
define service{
use generic-service ; Name of service template to use
host_name bhraas02,UP_WSDP63B
service_description UPTIME
check_command check_uptime! --warning 30: --critical 15:
contact_groups nocuser
}
Below is the hostconfiguration in the same file
#Host 134
define host {
use linux-server
host_name UP_WSDP63B
alias UP_WSDP63B
address 10.2.48.46
contact_groups nocuser
notifications_enabled 1
}
But it is still showing me nagios server uptime
which is 39 days

Re: Monitor uptime with threshold

Posted: Wed Oct 25, 2017 10:33 am
by npolovenko
@ericssonvietnam, You have a typo in you command definition:
Change:

Code: Select all

define command {
command_name heck_uptime
command_line $USER1$/check_uptime $ARG1$
}
to

Code: Select all

define command {
command_name check_uptime
command_line $USER1$/check_uptime $ARG1$
}
Then please run:

Code: Select all

service nagios restart
Everything should be working now.

Re: Monitor uptime with threshold

Posted: Wed Oct 25, 2017 10:47 am
by ericssonvietnam
npolovenko wrote:@ericssonvietnam, You have a typo in you command definition:
Change:

Code: Select all

define command {
command_name heck_uptime
command_line $USER1$/check_uptime $ARG1$
}
to

Code: Select all

define command {
command_name check_uptime
command_line $USER1$/check_uptime $ARG1$
}
Then please run:

Code: Select all

service nagios restart
Everything should be working now.
i missed it while posting it is correctly present there as below
define command {
command_name check_uptime
command_line $USER1$/check_uptime $ARG1$
}

Re: Monitor uptime with threshold

Posted: Wed Oct 25, 2017 11:19 am
by npolovenko
@ericssonvietnam, I see what you're saying. I don't think you can monitor remote hosts with this plugin because this plugin can only run locally.
Theoretically, you could do something like:

Code: Select all

define command {
command_name check_uptime
command_line $USER1$/check_uptime -H $HOSTADDRESS$ $ARG1$
}
But it's not going to work because the plugin itself won't accept -Host argument:

Code: Select all

Options:
 -h, --help
    Print detailed help screen
 -V, --version
    Print version information
 --extra-opts=[section][@file]
    Read options from an ini file. See
    https://www.nagios-plugins.org/doc/extra-opts.html
    for usage and examples.
-u, Time unit of measurement (seconds|minutes|hours|days) (default: minutes)
-w, Warning threshold
-c, Critcal threshold
-t, Plugin timeout, default 10 seconds
-vvv, Enable verbose output
So what you can do is install some kind of agent on your remote host, like NRPE. It's going to run the plugin locally on your host and send information back to the Nagios host:

Code: Select all

https://assets.nagios.com/downloads/nagioscore/docs/nrpe/NRPE.pdf

Re: Monitor uptime with threshold

Posted: Tue Oct 31, 2017 6:52 am
by ericssonvietnam
npolovenko wrote:@ericssonvietnam, I see what you're saying. I don't think you can monitor remote hosts with this plugin because this plugin can only run locally.
Theoretically, you could do something like:

Code: Select all

define command {
command_name check_uptime
command_line $USER1$/check_uptime -H $HOSTADDRESS$ $ARG1$
}
But it's not going to work because the plugin itself won't accept -Host argument:

Code: Select all

Options:
 -h, --help
    Print detailed help screen
 -V, --version
    Print version information
 --extra-opts=[section][@file]
    Read options from an ini file. See
    https://www.nagios-plugins.org/doc/extra-opts.html
    for usage and examples.
-u, Time unit of measurement (seconds|minutes|hours|days) (default: minutes)
-w, Warning threshold
-c, Critcal threshold
-t, Plugin timeout, default 10 seconds
-vvv, Enable verbose output
So what you can do is install some kind of agent on your remote host, like NRPE. It's going to run the plugin locally on your host and send information back to the Nagios host:

Code: Select all

https://assets.nagios.com/downloads/nagioscore/docs/nrpe/NRPE.pdf
But we need to do this without installation of any agent or nrpe on the server.can u suggest.

Re: Monitor uptime with threshold

Posted: Tue Oct 31, 2017 10:52 am
by npolovenko
@ericssonvietnam, If installing an agent on the remote host is not an option then i'd suggest ./check_by_ssh plugin.
Navigate to /usr/local/nagios/libexec/
and run:

Code: Select all

./check_by_ssh -H Your_Server_IP -C uptime
Let us know if this would work for you and if you need help creating a service definition with this plugin.