Page 1 of 1

Correct usage of 'starttime' to query objects/statehistory?

Posted: Thu May 06, 2021 3:27 pm
by amoss24
Hi all,

Trying to look at the API in order to have a better idea of how ServiceNow's Event Management module is collecting data from Nagios.

In querying the objects/statehistory endpoint, what is the correct use of 'starttime'?

I have an example based on what arguments ServiceNow uses, and I am adding in pretty=1 so I can read the output when I try to query the API:

Code: Select all

https://nagiosxi.domain.com/nagiosxi/api/v1/objects/statehistory?starttime=1620331491&orderby=state_time:d&pretty=1&records=3000&apikey=MyAPIKeyHere
By setting my start time to 1620331491, I am under the belief that I would expect results from Thu May 06 2021 20:04:51 GMT and newer. However, I am confused because I am seeing results that go further back than expected, here's the oldest result from the request above:

Code: Select all

 "state_time": "2021-05-06 15:06:36"
Just looking for clarification, or if something with our Nagios installation is not correct.

Thank you in advance!

Re: Correct usage of 'starttime' to query objects/statehisto

Posted: Fri May 07, 2021 10:16 am
by gsmith
Hi,

The starttime is GMT. Is your Nagios XI server's timezone set for America/Chicago?

Thanks

Re: Correct usage of 'starttime' to query objects/statehisto

Posted: Fri May 07, 2021 10:28 am
by amoss24
Hi @gsmith,

It is interesting you bring that up. Our team recently standardized on UTC (GMT) time since we span multiple time zones, and the server was changed. This means I can run 'date' and output the expected results: Fri May 7 15:21:36 UTC 2021

However, I checked our system profile and can see this:
Date/Time
PHP Timezone: America/Chicago
PHP Time: Fri, 07 May 2021 10:24:08 -0500
System Time: Fri, 07 May 2021 15:24:08 +0000
Should the PHP timezone match the system time? That would make sense if that is causing our issues. I hadn't even thought to check that.

To add to this,

I just checked and I do indeed see that we did not change the timezone in the XI interface. If the system time and the time in XI need to match I will change.

Re: Correct usage of 'starttime' to query objects/statehisto

Posted: Fri May 07, 2021 2:21 pm
by gsmith
Hi,

Yes, matching the XI timezone with the server's timezone is the recommended practice.

Once you make the change please let me know if things are working as expected.

Thanks

Re: Correct usage of 'starttime' to query objects/statehisto

Posted: Fri May 07, 2021 2:27 pm
by amoss24
That indeed fixed the issues I was encountering. I think we mistakenly updated the system time from the terminal when the documentation states that we should just update it from the XI interface.

Thank you @gsmith