check_ping

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.
donnyforbes
Posts: 357
Joined: Tue Jun 13, 2017 2:17 pm

Re: check_ping

Post by donnyforbes »

Sorry I haven't made any changes. What were the changes again that you had requested. Please show me. Again thank you for assisting me with this.
donnyforbes
Posts: 357
Joined: Tue Jun 13, 2017 2:17 pm

Re: check_ping

Post by donnyforbes »

Code: Select all

define host {
    host_name                       test
    alias                           test
    address                         1.1.1.1    
    check_command                   check-host-alive
    check_interval                  5
    retry_interval                  1
    max_check_attempts              5
    check_period                    24x7
    notifications_enabled         1
    contacts                       jdoe
    notification_interval           60
    notification_period             24x7
    notification_options            d,u,r
}

define contact {
    contact_name                    jdoe
    alias                           John Doe
    host_notifications_enabled      1
    service_notifications_enabled   1
    service_notification_period     24x7
    host_notification_period        24x7
    service_notification_options    w,u,c,r
    host_notification_options       d,u,r
    service_notification_commands   notify-by-email
    host_notification_commands      host-notify-by-email
    email                           jdoe@test.com
    can_submit_commands             1
}
I think this is what you had sent me. So I need to make the proper changes to the "contact" one correct? I will do this now and see what happens.
donnyforbes
Posts: 357
Joined: Tue Jun 13, 2017 2:17 pm

Re: check_ping

Post by donnyforbes »

ok here is my command.cfg

Code: Select all

###############################################################################
# COMMANDS.CFG - SAMPLE COMMAND DEFINITIONS FOR NAGIOS 4.3.2 # # # NOTES: This config file provides you with some example command definitions
#        that you can reference in host, service, and contact definitions.
#       
#        You don't need to keep commands in a separate file from your other
#        object definitions.  This has been done just to make things easier to
#        understand.
#
###############################################################################


#check_nrpe

define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }


#host and service definitions

define host{
name linux-box ; Name of this template
use generic-host ; Inherit default values
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period 24x7
notification_interval 30
notification_options d,r
contact_groups admins
register 0 ; DONT REGISTER THIS - ITS A TEMPLATE
}


define host {
    host_name                       ori
    alias                           ori
    address                         192.168.1.20    
    check_command                   check-host-alive
    check_interval                  5
    retry_interval                  1
    max_check_attempts              5
    check_period                    24x7
    notifications_enabled         1
    contacts                       dforbes
    notification_interval           60
    notification_period             24x7
    notification_options            d,u,r
}

# Defince Contact 
define contact {
contact_name dforbes
alias Donny Forbes
host_notifications_enabled 1
service_notifications_enabled 1
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email dforbes@allamericanasphalt.com
can_submit_commands 1
}

#remote Linux/Unix hosts

define host{
use linux-box ; Inherit default values from a template
host_name huey  ; The name or IP or remote server
alias RHEL 7.3 ; A longer name for the server
address 192.168.1.42 ; IP address of the remote server
}

define host{
use linux-box ; Inherit default values from a template
host_name duey  ; The name or IP or remote server
alias RHEL 7.3 ; A longer name for the server
address 192.168.1.43 ; IP address of the remote server
}

define host{
use linux-box ; Inherit default values from a template
host_name louie   ; The name or IP or remote server
alias RHEL 7.3 ; A longer name for the server
address 192.168.39.10 ; IP address of the remote server
}

define host{
use linux-box ; Inherit default values from a template
host_name proxy4gl   ; The name or IP or remote server
alias RHEL 7.3 ; A longer name for the server
address 192.168.1.12 ; IP address of the remote server
}

define host{
use linux-box ; Inherit default values from a template
host_name taz2   ; The name or IP or remote server
alias RHEL 7.3 ; A longer name for the server
address 192.168.1.10 ; IP address of the remote server
}

define host{
use linux-box ; Inherit default values from a template
host_name tank   ; The name or IP or remote server
alias RHEL 7.3 ; A longer name for the server
address 192.168.1.15 ; IP address of the remote server
}

define host{
use linux-box ; Inherit default values from a template
host_name ernestine   ; The name or IP or remote server
alias RHEL 7.3 ; A longer name for the server
address 192.168.39.12 ; IP address of the remote server
}


#remote services monitored

#This service will monitor the CPU Load

define service{
use generic-service
host_name huey
service_description CPU Load
check_command check_nrpe!check_load
}

define service{
use generic-service
host_name duey
service_description CPU Load
check_command check_nrpe!check_load
}

define service{
use generic-service
host_name louie
service_description CPU Load
check_command check_nrpe!check_load
}

define service{
use generic-service
host_name proxy4gl
service_description CPU Load
check_command check_nrpe!check_load
}

define service{
use generic-service
host_name taz2
service_description CPU Load
check_command check_nrpe!check_load
}

define service{
use generic-service
host_name tank
service_description CPU Load
check_command check_nrpe!check_load
}

define service{
use generic-service
host_name ernestine
service_description CPU Load
check_command check_nrpe!check_load
}


#This service will monitor number of currenlty logged on users

define service{
use generic-service
host_name huey
service_description Current Users
check_command check_nrpe!check_users
}

define service{
use generic-service
host_name duey
service_description Current Users
check_command check_nrpe!check_users
}

define service{
use generic-service
host_name louie
service_description Current Users
check_command check_nrpe!check_users
}

define service{
use generic-service
host_name proxy4gl
service_description Current Users
check_command check_nrpe!check_users
}

define service{
use generic-service
host_name taz2
service_description Current Users
check_command check_nrpe!check_users
}

define service{
use generic-service
host_name tank
service_description Current Users
check_command check_nrpe!check_users
}

define service{
use generic-service
host_name ernestine
service_description Current Users
check_command check_nrpe!check_users
}

#This service will monitor the free drive space on /dev/hda1

define service{
use generic-service
host_name huey
service_description /dev/hda1 Free Space
check_command check_nrpe!check_hda1
}

define service{
use generic-service
host_name duey
service_description /dev/hda1 Free Space
check_command check_nrpe!check_hda1
}

define service{
use generic-service
host_name louie
service_description /dev/hda1 Free Space
check_command check_nrpe!check_hda1
}

define service{
use generic-service
host_name proxy4gl
service_description /dev/hda1 Free Space
check_command check_nrpe!check_hda1
}

define service{
use generic-service
host_name taz2
service_description /dev/hda1 Free Space
check_command check_nrpe!check_hda1
}

define service{
use generic-service
host_name tank
service_description /dev/hda1 Free Space
check_command check_nrpe!check_hda1
}

define service{
use generic-service
host_name ernestine
service_description /dev/hda1 Free Space
check_command check_nrpe!check_hda1
}

#service will monitor the total number of processes

define service{
use generic-service
host_name huey
service_description Total Processes
check_command check_nrpe!check_total_procs
}

define service{
use generic-service
host_name duey
service_description Total Processes
check_command check_nrpe!check_total_procs
}

define service{
use generic-service
host_name louie
service_description Total Processes
check_command check_nrpe!check_total_procs
}

define service{
use generic-service
host_name proxy4gl
service_description Total Processes
check_command check_nrpe!check_total_procs
}

define service{
use generic-service
host_name taz2
service_description Total Processes
check_command check_nrpe!check_total_procs
}

define service{
use generic-service
host_name tank
service_description Total Processes
check_command check_nrpe!check_total_procs
}


define service{
use generic-service
host_name ernestine
service_description Total Processes
check_command check_nrpe!check_total_procs
}


# SAMPLE NOTIFICATION COMMANDS
#
# These are some example notification commands.  They may or may not work on
# your system without modification.  As an example, some systems will require 
# you to use "/usr/bin/mailx" instead of "/usr/bin/mail" in the commands below.
#
################################################################################


# 'notify-host-by-email' command definition
define command{
	command_name	notify-host-by-email
	command_line	/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
	}

# 'notify-service-by-email' command definition
define command{
	command_name	notify-service-by-email
	command_line	/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
	}


################################################################################
#
# SAMPLE HOST CHECK COMMANDS
#
################################################################################


# This command checks to see if a host is "alive" by pinging it
# The check must result in a 100% packet loss or 5 second (5000ms) round trip 
# average time to produce a critical error.
# Note: Five ICMP echo packets are sent (determined by the '-p 5' argument)

# 'check-host-alive' command definition
define command{
        command_name    check-host-alive
        command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
        }



################################################################################
#
# SAMPLE SERVICE CHECK COMMANDS
#
# These are some example service check commands.  They may or may not work on
# your system, as they must be modified for your plugins.  See the HTML 
# documentation on the plugins for examples of how to configure command definitions.
#
# NOTE:  The following 'check_local_...' functions are designed to monitor
#        various metrics on the host that Nagios is running on (i.e. this one).
################################################################################

# 'check_local_disk' command definition
define command{
        command_name    check_local_disk
        command_line    $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
        }


# 'check_local_load' command definition
define command{
        command_name    check_local_load
        command_line    $USER1$/check_load -w $ARG1$ -c $ARG2$
        }


# 'check_local_procs' command definition
define command{
        command_name    check_local_procs
        command_line    $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
        }


# 'check_local_users' command definition
define command{
        command_name    check_local_users
        command_line    $USER1$/check_users -w $ARG1$ -c $ARG2$
        }


# 'check_local_swap' command definition
define command{
	command_name	check_local_swap
	command_line	$USER1$/check_swap -w $ARG1$ -c $ARG2$
	}


# 'check_local_mrtgtraf' command definition
define command{
	command_name	check_local_mrtgtraf
	command_line	$USER1$/check_mrtgtraf -F $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -e $ARG5$
	}


################################################################################
# NOTE:  The following 'check_...' commands are used to monitor services on
#        both local and remote hosts.
################################################################################

# 'check_ftp' command definition
define command{
        command_name    check_ftp
        command_line    $USER1$/check_ftp -H $HOSTADDRESS$ $ARG1$
        }


# 'check_hpjd' command definition
define command{
        command_name    check_hpjd
        command_line    $USER1$/check_hpjd -H $HOSTADDRESS$ $ARG1$
        }


# 'check_snmp' command definition
define command{
        command_name    check_snmp
        command_line    $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$
        }


# 'check_http' command definition
define command{
        command_name    check_http
        command_line    $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
        }


# 'check_ssh' command definition
define command{
	command_name	check_ssh
	command_line	$USER1$/check_ssh $ARG1$ $HOSTADDRESS$
	}


# 'check_dhcp' command definition
define command{
	command_name	check_dhcp
	command_line	$USER1$/check_dhcp $ARG1$
	}


# 'check_ping' command definition
define command{
        command_name    check_ping
        command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5
        }


# 'check_pop' command definition
define command{
        command_name    check_pop
        command_line    $USER1$/check_pop -H $HOSTADDRESS$ $ARG1$
        }


# 'check_imap' command definition
define command{
        command_name    check_imap
        command_line    $USER1$/check_imap -H $HOSTADDRESS$ $ARG1$
        }


# 'check_smtp' command definition
define command{
        command_name    check_smtp
        command_line    $USER1$/check_smtp -H $HOSTADDRESS$ $ARG1$
        }


# 'check_tcp' command definition
define command{
	command_name	check_tcp
	command_line	$USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$
	}


# 'check_udp' command definition
define command{
	command_name	check_udp
	command_line	$USER1$/check_udp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$
	}


# 'check_nt' command definition
define command{
	command_name	check_nt
	command_line	$USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s F1reF1411  -v $ARG1$ $ARG2$
	}



################################################################################
#
# SAMPLE PERFORMANCE DATA COMMANDS
#
# These are sample performance data commands that can be used to send performance
# data output to two text files (one for hosts, another for services).  If you
# plan on simply writing performance data out to a file, consider using the 
# host_perfdata_file and service_perfdata_file options in the main config file.
#
################################################################################


# 'process-host-perfdata' command definition
define command{
	command_name	process-host-perfdata
	command_line	/usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /usr/local/nagios/var/host-perfdata.out
	}


# 'process-service-perfdata' command definition
define command{
	command_name	process-service-perfdata
	command_line	/usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /usr/local/nagios/var/service-perfdata.out
	}


what I am seeing when trying to restart is the following message tail -f /var/log/messages
Jun 26 10:09:09 nag nagios: Warning: Duplicate definition found for host 'ori' (config file '/usr/local/nagios/etc/objects/windows.cfg', starting on line 22)
Jun 26 10:09:09 nag nagios: Error: Could not add object property in file '/usr/local/nagios/etc/objects/windows.cfg' on line 24.

ori is a windows machine and it is in the windows.cfg file. I guess my question is how do I check if hosts is UP or DOWN from nagios if it won't let me add the windows server to the command.cfg file?
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: check_ping

Post by dwhitfield »

donnyforbes wrote:I guess my question is how do I check if hosts is UP or DOWN from nagios if it won't let me add the windows server to the command.cfg file?
As has already been stated, you do not need to add hosts to the command.cfg.

The "ping" command should look something like the following:

Code: Select all

$USER1$/check_icmp -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
That $HOSTADDRESS will pick up the host from your other configuration files. The $USER1$ will come from resources.cfg, but is usually /usr/local/nagios/libexec

Please use the quote button on the right of the post screen if you are going to quote people.
donnyforbes
Posts: 357
Joined: Tue Jun 13, 2017 2:17 pm

Re: check_ping

Post by donnyforbes »

Are you saying I don't need to do anything and I can leave it like it is?
or are you suggessting I need to add this to the each host in the command.cfg file

Code: Select all

$USER1$/check_icmp -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
I am a little confused on this response.

Thanks
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: check_ping

Post by dwhitfield »

Your commands are defined as such (this is just an example! Make your warning and critical what you want!):

Code: Select all

define command {
       command_name                             check-host-alive
       command_line                             $USER1$/check_icmp -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
}
You just need one command. Then under your hosts, you have a directive called check_command, which in this case will be check-host-alive.

You really need to read over the object definitions. There's literally no way to configure this if you don't know the object definitions: https://assets.nagios.com/downloads/nag ... tions.html

If you want all of your definitions in one file, then you need to get rid of your windows.cfg. I personally think that's the wrong way to do it, but if that's what you want to do, that will work.
Last edited by dwhitfield on Mon Jun 26, 2017 3:31 pm, edited 1 time in total.
Reason: clarification that the command is just an example
donnyforbes
Posts: 357
Joined: Tue Jun 13, 2017 2:17 pm

Re: check_ping

Post by donnyforbes »

Ok so I need to add this command to my command.cfg file?

Code: Select all

define command {
       command_name                             check-host-alive
       command_line                             $USER1$/check_icmp -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
}
then all I need to do is under each hosts add
this:

Code: Select all

define service{ 
use generic-service
host_name ernestine
service_description Current Users
check_command check_nrpe!check_users
check_command  check-host-alive
}
donnyforbes
Posts: 357
Joined: Tue Jun 13, 2017 2:17 pm

Re: check_ping

Post by donnyforbes »

I added this.

Code: Select all

#check-host-alive

define command{
command_namen check-host-alive
command_line  $USER1$/check_icmp -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
}
and then this.

Code: Select all

define service{ 
use generic-service
host_name huey
service_description Current Users
check_command check_nrpe!check_users
check_command  check-host-alive
}
tail -f /var/log/messages and getting the following error message:
Jun 26 15:35:39 nag nagios: Starting nagios:
Jun 26 15:35:39 nag nagios: Nagios Core 4.3.2
Jun 26 15:35:39 nag nagios: Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Jun 26 15:35:39 nag nagios: Copyright (c) 1999-2009 Ethan Galstad
Jun 26 15:35:39 nag nagios: Last Modified: 2017-05-09
Jun 26 15:35:39 nag nagios: License: GPL
Jun 26 15:35:39 nag nagios: Website: https://www.nagios.org
Jun 26 15:35:39 nag nagios: Reading configuration data...
Jun 26 15:35:39 nag nagios: Read main config file okay...
Jun 26 15:35:39 nag nagios: Error: Invalid command object directive 'command_namen'.
Jun 26 15:35:39 nag nagios: Error: Could not add object property in file '/usr/local/nagios/etc/objects/commands.cfg' on line 25.
Jun 26 15:35:39 nag nagios: Error processing object config files!
Jun 26 15:35:39 nag nagios: ***> One or more problems was encountered while processing the config files...
Jun 26 15:35:39 nag nagios: Check your configuration file(s) to ensure that they contain valid
Jun 26 15:35:39 nag nagios: directives and data definitions. If you are upgrading from a previous
Jun 26 15:35:39 nag nagios: version of Nagios, you should be aware that some variables/definitions
Jun 26 15:35:39 nag nagios: may have been removed or modified in this version. Make sure to read
Jun 26 15:35:39 nag nagios: the HTML documentation regarding the config files, as well as the
Jun 26 15:35:39 nag nagios: 'Whats New' section to find out what has changed.
Jun 26 15:35:39 nag systemd: nagios.service: control process exited, code=exited status=8
Jun 26 15:35:39 nag systemd: Failed to start Nagios Core Monitoring Daemon.
Jun 26 15:35:39 nag systemd: Unit nagios.service entered failed state.
Jun 26 15:35:39 nag systemd: nagios.service failed.
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: check_ping

Post by tgriep »

You have a typo in your check-hosts-alive command. Take a look at the error output and it will tell you what the error is.
Jun 26 15:35:39 nag nagios: Error: Invalid command object directive 'command_namen'.
Jun 26 15:35:39 nag nagios: Error: Could not add object property in file '/usr/local/nagios/etc/objects/commands.cfg' on line 25.
Jun 26 15:35:39 nag nagios: Error processing object config files!
Edit it and change the following from

Code: Select all

#check-host-alive

define command{
command_namen check-host-alive
command_line  $USER1$/check_icmp -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
}
to

Code: Select all

#check-host-alive

define command{
command_name check-host-alive
command_line  $USER1$/check_icmp -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
}
Another problem that I see if that the service check you posted for the host called huey has 2 check_commands, make sure you remove the command you do not need.
Be sure to check out our Knowledgebase for helpful articles and solutions!
donnyforbes
Posts: 357
Joined: Tue Jun 13, 2017 2:17 pm

Re: check_ping

Post by donnyforbes »

Good Morning,
I have added the following.

Code: Select all

#check-host-alive

define command{
command_name check-host-alive
command_line  $USER1$/check_icmp -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
}
In the service check command I have the following.

Code: Select all

define service{
use generic-service
host_name huey
service_description CPU Load
check_command check_nrpe!check_load
}

Are you saying I can only have one service check_command? For this to work I have to remove this.

Code: Select all

check_command check_nrpe!check_load
and only had this?

Code: Select all

check_command  check-host-alive
What exactly does the check_command check_nrpe!check_load do?
Locked