Page 1 of 3

Exclude state=0 from api call

Posted: Mon Nov 22, 2021 7:23 pm
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

Re: Exclude state=0 from api call

Posted: Mon Nov 22, 2021 8:11 pm
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

Re: Exclude state=0 from api call

Posted: Tue Nov 23, 2021 12:11 pm
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

Re: Exclude state=0 from api call

Posted: Wed Nov 24, 2021 3:32 pm
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

Re: Exclude state=0 from api call

Posted: Wed Nov 24, 2021 4:00 pm
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

Re: Exclude state=0 from api call

Posted: Thu Nov 25, 2021 10:14 am
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]"

Re: Exclude state=0 from api call

Posted: Mon Nov 29, 2021 5:36 pm
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/

Re: Exclude state=0 from api call

Posted: Wed Dec 01, 2021 6:54 pm
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

Re: Exclude state=0 from api call

Posted: Thu Dec 02, 2021 3:08 pm
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

Re: Exclude state=0 from api call

Posted: Thu Dec 02, 2021 10:17 pm
by DonForigua
Greetings

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

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