Exclude state=0 from api call

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
DonForigua
Posts: 94
Joined: Thu Oct 07, 2021 8:59 pm

Exclude state=0 from api call

Post by DonForigua »

Hi

I try to do a report from api and i need to exclude state=o from objects/statehistory i only wanna se values 1, 2 and 3

Thanks for your help
DonForigua
Posts: 94
Joined: Thu Oct 07, 2021 8:59 pm

Re: Exclude state=0 from api call

Post by DonForigua »

Hello

i can do it with

Code: Select all

curl -XGET "https://XISERVER/nagiosxi/api/v1/objects/statehistory?apikey=XXXXXXXXXXXXXXXXXXXXXXXX&pretty=1&state_type=1&state=in:1,2,3"
Now a have another question:

in objects/hostavailability how can i set the starttime from a specific date for example 25/10/2021 to another dat for example 25/11/2021
gsmith
Posts: 1253
Joined: Tue Mar 02, 2021 11:15 am

Re: Exclude state=0 from api call

Post by gsmith »

Hi

This should help:
Image013.jpg
You can find the API documentation by going to the Help page on your XI server:
Image014.jpg
Thanks
You do not have the required permissions to view the files attached to this post.
DonForigua
Posts: 94
Joined: Thu Oct 07, 2021 8:59 pm

Re: Exclude state=0 from api call

Post by DonForigua »

Hi gsmith

It uses epoch time, actully i use the powerbi for advanced reports and dashboard, Nevertheless i need to generate a dinamic ability report for some time periods as las 7 days, las 30 days, this month, last mont.

I cant do the expresions in bash

Code: Select all

curl -XGET "https://URL/nagiosxi/api/v1/objects/hostavailability?apikey=APIKEY&pretty=1&host=FLD0013_Puesto_de_Trabajo_PC1&starttime=$(date  +'%s' --date='31 days ago')"
but this expresion only runs on bash but in powerbi how i can generate this expressions with the link and it will be dinamic?

for example

curl -XGET "https://URL/nagiosxi/api/v1/objects/hos ... ]lastmonth[/b]"

Thanks for you help
gsmith
Posts: 1253
Joined: Tue Mar 02, 2021 11:15 am

Re: Exclude state=0 from api call

Post by gsmith »

Hi

I don't use power bi so I can't really answer your question.

Do you need to know how to get today's date/time in bash, and calculate the epoch time for 7
days ago?

Thanks
DonForigua
Posts: 94
Joined: Thu Oct 07, 2021 8:59 pm

Re: Exclude state=0 from api call

Post by DonForigua »

Hi power bi only need a Url

But when i make the url with the epoch, tomorrow will be from 8 days ago, i need a expresion as:

curl -XGET "https://URL/nagiosxi/api/v1/objects/hos ... ]lastmonth[/b]"
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Exclude state=0 from api call

Post by benjaminsmith »

Hi Don,

So the default end time is now, so determine the timestamp based on now - 30 days.

Current time = 1638225150
1 month = 2629743 seconds
30 Days ago = 1638225150 - 2629743 = 1635595407

starttime = 1635595407

Sample command from my test system would be:

Code: Select all

 curl -XGET "https://192.168.23.112/nagiosxi/api/v1/objects/hostavailability?apikey=AAXHBIAkAHq5L7nnrHdgah5RKMi7b4uKDrIrqu5ZcukdFKTmH7FRnZInLhtdk0dd&pretty=1&host=localhost&starttime=1635595407"
Hopefully, that helps. If not, please provide some more context as we may not be understanding the issue correctly. Thanks, Benjamin

References:
https://www.epochconverter.com/
https://www.unixtimestamp.com/
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!
DonForigua
Posts: 94
Joined: Thu Oct 07, 2021 8:59 pm

Re: Exclude state=0 from api call

Post by DonForigua »

Hi dear Benjamin

Thx for you reply

If i use your method tomorrow will be 31 days 8 days 1 month 1 day.

I need that our parameter allways be 1 week, 1 month, last month, this month. For reporting without change the paremeters in the api.

Greetings
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Exclude state=0 from api call

Post by benjaminsmith »

HI,
I need that our parameter always be 1 week, 1 month, last month, this month. For reporting without change the paremeters in the api
The API is using unix timestamps for start and end times, so determining the UNIX timestamp start/endpoints for the last month would have to be done in the script your using to manage the API. Unfortunately, It doesn't have the functionality built-in.

Regards,
Benjamin

Reference:
https://www.epochconverter.com/timestamp-lis
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!
DonForigua
Posts: 94
Joined: Thu Oct 07, 2021 8:59 pm

Re: Exclude state=0 from api call

Post by DonForigua »

Greetings

Ok, then what is the limit of records from api reply

https://XISERVER/nagiosxi/api/v1/object ... b]XXXXXXXX[/b]
Locked