Nagios mail Notification with Duration

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
Pradhap
Posts: 7
Joined: Sat Oct 01, 2016 12:01 pm

Nagios mail Notification with Duration

Post 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.
Attachments
dur.PNG
dur.PNG (1.45 KiB) Viewed 3751 times
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios mail Notification with Duration

Post 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$
Former Nagios Employee
Pradhap
Posts: 7
Joined: Sat Oct 01, 2016 12:01 pm

Re: Nagios mail Notification with Duration

Post by Pradhap »

Thanks for your support.

please share both command definition.
1.notify-host-by-email
2.notify-service-by-email
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios mail Notification with Duration

Post by rkennedy »

The information has been provided above - you'll want to customize the commands based on your requirements.
Former Nagios Employee
Pradhap
Posts: 7
Joined: Sat Oct 01, 2016 12:01 pm

Re: Nagios mail Notification with Duration

Post 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.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios mail Notification with Duration

Post 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
Former Nagios Employee
Pradhap
Posts: 7
Joined: Sat Oct 01, 2016 12:01 pm

Re: Nagios mail Notification with Duration

Post 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.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Nagios mail Notification with Duration

Post 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.
Former Nagios Employee
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Nagios mail Notification with Duration

Post 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?
Former Nagios employee
Locked