Page 1 of 1

Nagios mail Notification with Duration

Posted: Wed Feb 08, 2017 12:41 pm
by Pradhap
Hello Team,

i am configured nagios mail alert. it is working fine.

***** Nagios *****

Notification Type: PROBLEM
Host: Test_Linux
State: DOWN
Address: 10.10.2.45
Info: PING CRITICAL - Packet loss = 100%
Date/Time: Wed Feb 8 22:31:56 +0530 2017


but i want Duration also. please share the comment.

Re: Nagios mail Notification with Duration

Posted: Wed Feb 08, 2017 12:47 pm
by rkennedy
Take a look at how your notification commands are defined, for example -

Code: Select all

# '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 $NOTIFICATIONCOMMENT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
You can add to the message by appending to the first part of what's being printed, using any of the variables allowed to customize it further. The general list is here - https://assets.nagios.com/downloads/nag ... olist.html

For your case, I believe you're after either $SERVICEDURATION$ or $HOSTDURATION$

Re: Nagios mail Notification with Duration

Posted: Wed Feb 08, 2017 1:10 pm
by Pradhap
Thanks for your support.

please share both command definition.
1.notify-host-by-email
2.notify-service-by-email

Re: Nagios mail Notification with Duration

Posted: Wed Feb 08, 2017 1:12 pm
by rkennedy
The information has been provided above - you'll want to customize the commands based on your requirements.

Re: Nagios mail Notification with Duration

Posted: Thu Feb 09, 2017 10:23 am
by Pradhap
Hello Team,

Thanks for support.

one problem.

***** Nagios *****

Notification Type: RECOVERY
Host: TestLinux
State: UP
Address: 10.10.4.1
Duration: 0d 0h 0m 0s
Info: PING OK - Packet loss = 28%, RTA = 2156.19 ms
Date/Time: Thu Feb 9 19:38:19 +0530 2017

it is show current status. i want last down duration.
please suggest.

Re: Nagios mail Notification with Duration

Posted: Thu Feb 09, 2017 11:07 am
by rkennedy
Pradhap wrote:Hello Team,

Thanks for support.

one problem.

***** Nagios *****

Notification Type: RECOVERY
Host: TestLinux
State: UP
Address: 10.10.4.1
Duration: 0d 0h 0m 0s
Info: PING OK - Packet loss = 28%, RTA = 2156.19 ms
Date/Time: Thu Feb 9 19:38:19 +0530 2017

it is show current status. i want last down duration.
please suggest.
The notification you posted is for a recovery in an OK status, if this were a warning / critical email then I'd expect it to show 0d 0h 0m 0s right away, but as your notifications send in further this number should increase.

I don't believe this is possible currently based on the macros -

Code: Select all

$HOSTDURATION$ 	A string indicating the amount of time that the host has spent in its current state. Format is "XXh YYm ZZs", indicating hours, minutes and seconds.
$HOSTDURATIONSEC$ 	A number indicating the number of seconds that the host has spent in its current state.
There are references to the $LAST##############$ macros though, so I imagine something like this is feasible. Please create a request on our GitHub page located at https://github.com/NagiosEnterprises/nagioscore/issues

Re: Nagios mail Notification with Duration

Posted: Sat Feb 11, 2017 8:21 am
by Pradhap
Hi Team,
thanks for support.

am used $LASTHOSTDOWN$ and $LASTHOSTUP$
but am getting the result not time formate

Last Host up: 1452567
Last Host Down: 1465234

please suggest.

Re: Nagios mail Notification with Duration

Posted: Mon Feb 13, 2017 11:43 am
by rkennedy
See the documentation for what the variables are referencing. If you're looking for these to output otherwise, you'll need to write a wrapper to process the math.

Code: Select all

$LASTHOSTUP$	This is a timestamp in time_t format (seconds since the UNIX epoch) indicating the time at which the host was last detected as being in an UP state.
$LASTHOSTDOWN$	This is a timestamp in time_t format (seconds since the UNIX epoch) indicating the time at which the host was last detected as being in a DOWN state.

Re: Nagios mail Notification with Duration

Posted: Wed Mar 01, 2017 2:25 pm
by tmcdonald
Just checking in since we have not heard from you in a while. Did @rkennedy's post clear things up or has the issue otherwise been resolved?