Page 1 of 1

JSON api start/ent

PostPosted: Tue Oct 01, 2019 2:47 pm
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
}
}
}

Re: JSON api start/ent

PostPosted: Wed Oct 02, 2019 7:19 am
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

Re: JSON api start/ent

PostPosted: Wed Oct 02, 2019 11:53 am
by benjaminsmith
Thanks @mcapra!

The JSON query api uses Unix timestamps. Let us know if you have any other questions.