Downtime and uptime 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
TadejT
Posts: 6
Joined: Thu Nov 07, 2019 4:52 am

Downtime and uptime duration

Post by TadejT »

Hi,

I have problem gettin info about previous state duration.
For example, when i gate alert about host is down I would like to know how long it was up and vice-versa.

I tried with $LASTHOSTDOWN$ but it returned 0 value.

Can someone help me?

Best regards

Tadej
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Downtime and uptime duration

Post by scottwilkerson »

Are you using $LASTHOSTDOWN$ from a service check? On service checks you would want to use $LASTSERVICECRITICAL$

If you want to know the last time it was UP you would use:
$LASTHOSTUP$

and for a service
$LASTSERVICEOK$
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
TadejT
Posts: 6
Joined: Thu Nov 07, 2019 4:52 am

Re: Downtime and uptime duration

Post by TadejT »

I use $LASTHOSTUP$ and $LASTHOSTDOWN$.

But for example on recovery, when host is UP, I always get similar time. It is somehow logical because last time down it was just before reocvery.

I would just like to know how long was host DOWN when I get RECOVERY notification.

Thanks
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Downtime and uptime duration

Post by scottwilkerson »

Hmm, I would think you would want something like

Code: Select all

$LASTHOSTDOWN$ - $LASTHOSTCHECK$
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
TadejT
Posts: 6
Joined: Thu Nov 07, 2019 4:52 am

Re: Downtime and uptime duration

Post by TadejT »

Hm, I will try but wouldn't this return time between last check and last time down?

I would need time between last host down and "first".
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Downtime and uptime duration

Post by scottwilkerson »

$LASTHOSTCHECK$ will be the last time the host was checked, which should be the check that produced the recovery.

so
$LASTHOSTDOWN$ - $LASTHOSTCHECK$ = seconds host was down
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
TadejT
Posts: 6
Joined: Thu Nov 07, 2019 4:52 am

Re: Downtime and uptime duration

Post by TadejT »

I tried but diffrence is about one minutor or less, what is logical because $LASTHOSTDOWN$ is just before recover and not time when device went to DOWN state.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Downtime and uptime duration

Post by scottwilkerson »

I see the problem, but unfortunately there isn't a macro that defines what you are looking for.
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
adamto99
Posts: 1
Joined: Sun Nov 17, 2019 12:45 pm

Re: Downtime and uptime duration

Post by adamto99 »

TadejT wrote:I tried but diffrence is about one minutor or less, what is logical because $LASTHOSTDOWN$ is just before recover and not time when device went to DOWN state.
I have problem gettin info about previous state duration.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Downtime and uptime duration

Post by scottwilkerson »

As mentioned before, there is no macro for getting duration of a previous state.
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked