Monitor uptime with threshold

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
ericssonvietnam
Posts: 239
Joined: Mon Jun 27, 2016 11:05 pm

Monitor uptime with threshold

Post 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!
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: Monitor uptime with threshold

Post 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
Be sure to check out our Knowledgebase for helpful articles and solutions!
ericssonvietnam
Posts: 239
Joined: Mon Jun 27, 2016 11:05 pm

Re: Monitor uptime with threshold

Post 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.
kyang

Re: Monitor uptime with threshold

Post 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 (!).
ericssonvietnam
Posts: 239
Joined: Mon Jun 27, 2016 11:05 pm

Re: Monitor uptime with threshold

Post 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
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Monitor uptime with threshold

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
ericssonvietnam
Posts: 239
Joined: Mon Jun 27, 2016 11:05 pm

Re: Monitor uptime with threshold

Post 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$
}
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Monitor uptime with threshold

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
ericssonvietnam
Posts: 239
Joined: Mon Jun 27, 2016 11:05 pm

Re: Monitor uptime with threshold

Post 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.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Monitor uptime with threshold

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked