Nagios can't send notifications

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.
Locked
mingyuan
Posts: 1
Joined: Wed Dec 09, 2015 1:58 am

Nagios can't send notifications

Post by mingyuan »

I'm developing an automation tool for managing nagios (nagiosql is not sufficient enough for me).

When I am doing a integration test with nagios, something weird happens.

Here is the situation:

1. Nagios Configuration

Code: Select all

# grep log_notification /usr/local/nagios/etc/nagios.cfg
log_notifications=1

#grep enable_notifications /usr/local/nagios/etc/nagios.cfg
enable_notifications=1
2. I created a sample contact, host, service, all without using templates

Code: Select all

define contact { 
    contact_name    jone.doe
    host_notifications_enabled  1
    service_notifications_enabled   1
    host_notification_period    7x24
    service_notification_period 7x24
    host_notification_options   d,u,r,f,s,n
    service_notification_options    w,u,c,r,f,s,n
    email   [email protected]
    host_notification_commands  notify_service_by_state
    service_notification_commands   notify_service_by_state
}

define host{
    host_name   localhost
    address localhost
    max_check_attempts  1
    check_period    7x24
    active_checks_enabled   1
    passive_checks_enabled  0
    check_command   check_host_alive
}

define service{
    host_name   localhost
    service_description check_the_process_count_of_the_local_machine
    check_command   check_local_procs!10!20!RSZDT
    max_check_attempts  3
    check_interval  3
    retry_interval  1
    notification_interval   3
    check_period    7x24
    notification_period 7x24
    notifications_enabled   1
    contacts   john.doe
}
3. Hereby are some additional configuration file:

Code: Select all

define timeperiod{
    timeperiod_name 7x24
    alias   7x24
    monday  00:00-24:00
    tuesday 00:00-24:00
    wednesday   00:00-24:00
    thursday    00:00-24:00
    friday  00:00-24:00
    saturday    00:00-24:00
    sunday  00:00-24:00
}

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

define command { 
    command_name    notify_service_by_state
    command_line    /usr/local/nagios/etc/scripts/notify.py "$SERVICESTATE$" "$CONTACTEMAIL$" "$CONTACTADDRESS1$" "$NOTIFICATIONTYPE$" "$HOSTALIAS$" "$SERVICEDESC$" "$HOSTADDRESS$" "$SERVICEOUTPUT$" "$LONGDATETIME$"
}

define command { 
    command_name    check_host_alive
    command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
}
and this is the notify.py source code, all packages installed.

Code: Select all

#!/usr/bin/python
#coding:utf-8
import codecs
import sys
import urllib
import commands

import smtplib
from email.mime.text import MIMEText
from email.header import Header

import time

fi = codecs.open('/data/appdatas/logs/message.log', 'a' , encoding='utf-8')
fi.write("=======Begin Log\n");
fi.write("Notify\n");
fi.write(time.strftime('%Y-%m-%d %H:%M:%S') + "\n");
fi.write(sys.argv[1]+ "\n");
fi.write("End Log=========\n");
fi.close()
To simplify the test process, I had

Code: Select all

chmod +777 to the log_file
.

And

Code: Select all

chmod +x notify.py
. And I've tested to execute the python script in the terminal, and there are logs in the log file.

As you can see the check_local_proc command. This command will return a code 2 as it executed.

In the nagios.log file, I have see these logs:

Code: Select all

[1449588806] SERVICE ALERT: localhost;check_the_process_count_of_the_local_machine;CRITICAL;SOFT;1;PROCS CRITICAL: 423 processes with STATE = RSZDT
[1449588866] SERVICE ALERT: localhost;check_the_process_count_of_the_local_machine;CRITICAL;SOFT;2;PROCS CRITICAL: 423 processes with STATE = RSZDT
[1449588926] SERVICE ALERT: localhost;check_the_process_count_of_the_local_machine;CRITICAL;HARD;3;PROCS CRITICAL: 423 processes with STATE = RSZDT
As you can see from the log, this service is checked every 1 minute.

But there's no log in the message.log file (no execution of the notify.py).

Would you please help me with this problem.

This is the Url on stackoverflow.com
http://stackoverflow.com/questions/3416 ... ifications
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Nagios can't send notifications

Post by tmcdonald »

It looks like you answered your own question on the SO link, so I will post it here for reference and close the thread:
I know why I cann't sent any notification. Because I wrongly configured contact's configuration. According to the official document: Nagios Object Definitions, the field host_notification_options [d,u,r,f,s,n], service_notification_options [w,u,c,r,f,s,n]; the option n means the contact will not receive any notifications.
In the future if your question has been answered outside of the forum please post back indicating such.
Former Nagios employee
Locked