JSON api start/ent

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

JSON api start/ent

Postby swissarmychainsaw » Tue Oct 01, 2019 2:47 pm

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

Re: JSON api start/ent

Postby mcapra » Wed Oct 02, 2019 7:19 am

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
http://www.mcapra.com/
User avatar
mcapra
 
Posts: 3584
Joined: Thu May 05, 2016 3:54 pm

Re: JSON api start/ent

Postby benjaminsmith » Wed Oct 02, 2019 11:53 am

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!
User avatar
benjaminsmith
 
Posts: 1874
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul


Return to Nagios Core

Who is online

Users browsing this forum: Google [Bot] and 19 guests