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

check_ping

Post by donnyforbes »

Nagios version: Core 4.3.2

Os version:

Code: Select all

[root@nag objects]# cat /etc/*release*
CentOS Linux release 7.0.1406 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CentOS Linux release 7.0.1406 (Core)
CentOS Linux release 7.0.1406 (Core)
cpe:/o:centos:centos:7
[root@nag objects]#
what I need to do is have nagios ping my remote servers, but need to have it setup where if there is ping loss or system not able to ping because it is down. Then need to be notified by email.
Can someone assist me with this? Or send me documentation, howto's etc on how to get this to work? Thank you support team.
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 »

Are you able to send any email at all from the server to the address in question? That's the first step, before ever getting nagios involved.

That said, here's the notification help document: https://assets.nagios.com/downloads/nag ... tions.html

More broadly, here's the Core manual: https://library.nagios.com/library/prod ... e/manuals/

We also have helpful video tutorials at https://www.youtube.com/user/nagiosvideo
donnyforbes
Posts: 357
Joined: Tue Jun 13, 2017 2:17 pm

Re: check_ping

Post by donnyforbes »

Yes I can send email from the server to the address by doing this.

Code: Select all

[root@nag objects]# cat commands.cfg |mail dforbes@allamericanasphalt.com
[root@nag objects]#
I have tested to make sure mail works from the server by the above example. I have done anything with the nagios config in regards to email notification.

Code: Select all

Jun 23 11:13:51 nag postfix/pickup[4179]: 1328C80ACF61: uid=0 from=<root>
Jun 23 11:13:51 nag postfix/cleanup[5403]: 1328C80ACF61: message-id=<20170623181351.1328C80ACF61@nag.localdomain>
Jun 23 11:13:51 nag postfix/qmgr[1641]: 1328C80ACF61: from=<root@nag.localdomain>, size=14500, nrcpt=1 (queue active)
Jun 23 11:13:52 nag postfix/smtp[5405]: 1328C80ACF61: to=<dforbes@allamericanasphalt.com>, relay=goauld.sg1.allamericanasphalt.com[192.168.1.6]:25, delay=1, delays=0.02/0.01/0.37/0.64, dsn=2.6.0, status=sent (250 2.6.0 <20170623181351.1328C80ACF61@nag.localdomain> [InternalId=12970801234150, Hostname=GOAULD.sg1.allamericanasphalt.com] Queued mail for delivery)
Jun 23 11:13:52 nag postfix/qmgr[1641]: 1328C80ACF61: removed
Last edited by donnyforbes on Fri Jun 23, 2017 1:15 pm, edited 1 time in total.
donnyforbes
Posts: 357
Joined: Tue Jun 13, 2017 2:17 pm

Re: check_ping

Post by donnyforbes »

I only have the sample notification in the command.cfg

Code: Select all

# 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$
        }
Since I know mail is working from my system. Is there a way to test to see if it works with nagios?
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 »

The following are the host configurations as they apply to notifications

Code: Select all

notification_interval	#
	first_notification_delay	#
	notification_period	timeperiod_name
	notification_options	[d,u,r,f,s]
	notifications_enabled	[0/1]
There's additional detail at https://assets.nagios.com/downloads/nag ... tions.html

The service definitions are also at the above link, in case you want to get notifications set up for those as well.

Contact definitions also very important here. Take a look at https://assets.nagios.com/downloads/nag ... ml#contact

You can just run the following from the command line and see if it works. It's not a guarantee by any stretch that it will work for downed hosts, but it's a start.

Code: Select all

/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$ **" dforbes@allamericanasphalt.com
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: check_ping

Post by lmiltchev »

Since I know mail is working from my system. Is there a way to test to see if it works with nagios?
You will have to make sure you have properly defined hosts, contacts, commands, etc. When the host is down, and it goes to hard non-ok state, then nagios will notify the monitoring contact attached to this host.

Here's an example configs of a host and a contact:

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
}
Read about notifications here: https://assets.nagios.com/downloads/nag ... tions.html
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 »

Ran this

Code: Select all

[root@nag objects]# /usr/local/nagios/libexec/check_ping -H 192.168.101.42 -w 10,2% -c 20,5% -t 5
PING CRITICAL - Packet loss = 100%|rta=20.000000ms;10.000000;20.000000;0.000000 pl=100%;2;5;0
[root@nag objects]# /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$ **" dforbes@allamericanasphalt.com
[root@nag objects]#
This sent me the following email.

***** Nagios *****

Notification Type: $

Service: $
Host: $
Address: $
State: $

Date/Time: $

Additional Info:

$

It looked like it worked. Do I just put the samples you send me anywhere in 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: Do I just put the samples you send me anywhere in the command.cfg file?
No. You go through the configs and set them up how you want them. Below is the information on the notification-related directives in the host config.

contacts: This is a list of the short names of the contacts that should be notified whenever there are problems (or recoveries) with this host. Multiple contacts should be separated by commas. Useful if you want notifications to go to just a few people and don't want to configure contact groups. You must specify at least one contact or contact group in each host definition.

contact_groups: This is a list of the short names of the contact groups that should be notified whenever there are problems (or recoveries) with this host. Multiple contact groups should be separated by commas. You must specify at least one contact or contact group in each host definition.

notification_interval: This directive is used to define the number of "time units" to wait before re-notifying a contact that this host is still down or unreachable. Unless you've changed the interval_length directive from the default value of 60, this number will mean minutes. If you set this value to 0, Nagios will not re-notify contacts about problems for this host - only one problem notification will be sent out.

first_notification_delay: This directive is used to define the number of "time units" to wait before sending out the first problem notification when this host enters a non-UP state. Unless you've changed the interval_length directive from the default value of 60, this number will mean minutes. If you set this value to 0, Nagios will start sending out notifications immediately.

notification_period: This directive is used to specify the short name of the time period during which notifications of events for this host can be sent out to contacts. If a host goes down, becomes unreachable, or recoveries during a time which is not covered by the time period, no notifications will be sent out.

notification_options: This directive is used to determine when notifications for the host should be sent out. Valid options are a combination of one or more of the following: d = send notifications on a DOWN state, u = send notifications on an UNREACHABLE state, r = send notifications on recoveries (OK state), f = send notifications when the host starts and stops flapping, and s = send notifications when scheduled downtime starts and ends. If you specify n (none) as an option, no host notifications will be sent out. If you do not specify any notification options, Nagios will assume that you want notifications to be sent out for all possible states. Example: If you specify d,r in this field, notifications will only be sent out when the host goes DOWN and when it recovers from a DOWN state.

notifications_enabled *: This directive is used to determine whether or not notifications for this host are enabled. Values: 0 = disable host notifications, 1 = enable host notifications.

Again, if you want to find out more about contacts and services, see https://assets.nagios.com/downloads/nag ... tions.html
donnyforbes
Posts: 357
Joined: Tue Jun 13, 2017 2:17 pm

Re: check_ping

Post by donnyforbes »

Code: Select all

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
}

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-by-email
    host_notification_commands      host-notify-by-email
    email                         dforbes@allamericanasphalt.com
    can_submit_commands             1
}
I added this to the command.cfg file, however when trying to start it I got the following in /var/log/messages.

Code: Select all

Jun 23 11:45:10 nag systemd: Starting Nagios Core Monitoring Daemon...
Jun 23 11:45:10 nag nagios: Starting nagios:
Jun 23 11:45:10 nag nagios: Nagios Core 4.3.2
Jun 23 11:45:10 nag nagios: Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Jun 23 11:45:10 nag nagios: Copyright (c) 1999-2009 Ethan Galstad
Jun 23 11:45:10 nag nagios: Last Modified: 2017-05-09
Jun 23 11:45:10 nag nagios: License: GPL
Jun 23 11:45:10 nag nagios: Website: https://www.nagios.org
Jun 23 11:45:10 nag nagios: Reading configuration data...
Jun 23 11:45:10 nag nagios: Read main config file okay...
Jun 23 11:45:10 nag nagios: Warning: Duplicate definition found for host 'ori' (config file '/usr/local/nagios/etc/objects/windows.cfg', starting on line 22)
Jun 23 11:45:10 nag nagios: Error: Could not add object property in file '/usr/local/nagios/etc/objects/windows.cfg' on line 24.
Jun 23 11:45:10 nag nagios: Error: Invalid max_check_attempts value for host 'duey'
Jun 23 11:45:10 nag nagios: Error: Could not register host (config file '/usr/local/nagios/etc/objects/commands.cfg', starting on line 82)
Jun 23 11:45:10 nag nagios: Error processing object config files!
All I did was add ori to the command.cfg file on nagios which is the name for a remote windows hosts. Can that not be done?
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 »

I think I mentioned this in the other thread, but I really think you could benefit from moving to XI. If you go that route, we can spend an hour helping set up your system: https://www.nagios.com/services/quickstart/nagios-xi/

Yes, quickstarts are closed now. They should be back up the second week of July. Of course, we can continue to work through the forums, but you seem to have a lot of problems with your configs, so it might be nice to quit modifying your configs by hand.

That said, if you added ori to commands.cfg, and it's already in windows.cfg, that's one of your issues. Can you post the current state of both of them?
Locked