JSON api start/ent

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
swissarmychainsaw
Posts: 3
Joined: Mon Apr 11, 2011 11:23 pm

JSON api start/ent

Post by swissarmychainsaw »

I'm looking to do a custom "Availability Report" using the JSON query api.

For the life of me I can't figure out the "start/end" time.

I'm happy to read docs and figure this out, but I have not found ANY documentation on how the (new and awesome APIs actaully work) which is a surprise considering how well documented CORE is.
+ the APIs are awesome.

Any help is much appreciated!

Here are details:
https://MyHost/nagios/jsonquery.html
CGI: Archive Json
Query: availability

Availability Object Type: hosts
Hostname: MyHost

Service Desc: PING
Start Time: ???
End Time: ???

When I enter:
Start: 1
End Time: -30



"host": {
"name": "MyHost",
"time_up": 1569920418, <-- How do I translate this into something meaningful?
"time_down": 38115,
"time_unreachable": 0,
"scheduled_time_up": 0,
"scheduled_time_down": 0,
"scheduled_time_unreachable": 0,
"time_indeterminate_nodata": 0,
"time_indeterminate_notrunning": 0
}
}
}
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: JSON api start/ent

Post by mcapra »

swissarmychainsaw wrote: "time_up": 1569920418, <-- How do I translate this into something meaningful?
That looks like a Unix epoch to me:
https://www.epochconverter.com/

Practically every main-stream programming language has standard libraries/tools for turning that into something human-readable. Also, practically every flavor of Linux:

Code: Select all

[root@ahri ~]# date +%s
1570018475
[root@ahri ~]# date +%s | perl -pe 's/(\d+)/localtime($1)/e'
Wed Oct  2 12:15:16 2019
[root@ahri ~]# date -d @$(date +%s)
Wed Oct  2 12:16:02 UTC 2019
[root@ahri ~]# python
Python 2.7.5 (default, Aug  4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> ts = int("1569920418")
>>> print(datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))
2019-10-01 09:00:18
The specific implementation would depend on how you're generating the availability report. Here's how the native "percent availability" calculations happen in Nagios Core:
https://github.com/NagiosEnterprises/na ... il.c#L3698
https://github.com/NagiosEnterprises/na ... il.c#L3704
Former Nagios employee
https://www.mcapra.com/
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: JSON api start/ent

Post by benjaminsmith »

Thanks @mcapra!

The JSON query api uses Unix timestamps. Let us know if you have any other questions.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked