Solved

Getting downtimes from the API v2

  • 6 February 2024
  • 4 replies
  • 66 views

Badge +3

Hello,

I’m getting downtimes using API v2 without problems. I need to filter those downtimes that are really actives, specifically those you can see at ‘Downtimes’ page in the Centreon interface. 

However, from the API I get many more than the ones I see at ‘Downtimes’ page. How can I get the same result? Which filter do I have to use?

I thought the active ones were those with ‘deletion_time’ to NULL or ‘actual_end_time‘ to NULL, but the are a lot with these values that don’yt appear on the interface. So I don’t know how to get the ‘real’ ones.

Can you help me?

Thanks in advance.

Albert

icon

Best answer by ponchoh 6 February 2024, 22:11

View original

4 replies

Userlevel 4
Badge +13

Hello,

You are on the right track, remember that the results on the WebUI are paged, so you might have more results totals. I see you are using the filter so you might be interested in being more specific.

Also, can try 

  • start_time
  • end_time

So it matches the “now”

 

https://docs-api.centreon.com/api/centreon-web/23.10/#tag/Downtime/paths/~1monitoring~1downtimes/get

 

The available parameters to search / sort_by are:

  • id
  • entry_time
  • is_cancelled
  • comment
  • deletion_time
  • duration
  • end_time
  • is_fixed
  • start_time
  • host.id
  • host.name
  • host.alias
  • host.address
  • host.display_name
  • host.state
  • poller.id
  • contact.id
  • contact.name
Badge +3

Hello,

Ummmm, I’ll reformulate my question.

If I log on the web interface and I go to ‘Downtimes’->’Downtimes’ page (version 22.10 or 23.10),, I can see a list of downtimes. At that page there is no data restriction, at least as far as I can see, so I don’t know what is the default filter that is applied. Is web interface applying a ‘last 24h’ filter? Is it applying a ‘started=yes’ filter? It’s confusing…What filter do i have to apply on the fields you gave to me to get the same result that one on the web interface? start_time different than null and end_time greater than current time and is_fixed equal to true but is_cancelled equal to false? This is my problem, I don’t know the logical condition I have to use...

On the other way, I’m not sure about the meaning of some of the fields and their values when I get the data from the API.

For example: if I define a downtime and I cancel it afterwards, is end_time equal to null and is_cancelled equal to true? if the dowtime is applied in a normal way, are start_time and end_time different than null but is_cancelled equal to false? The ‘started’ field we see on the interface, where is it in the API results? It is calculated by the interface using other fields?

And what is ‘deletion_time’? In the API results, there are other fields: actual_end_time, actual_start_time, end_time, start_time….So I’m not sure if I can filter afterwards according to the results...

Thinking about that. and if I filter ‘a priori’, I guess I should look for downtimes with is_cancelled equal to false and end_time greater tha current time. Is it enough? And if it is correct, which format do the data fileds have to have? Unix time?

Thanks!

Albert

Badge +3

More info...Filters on ‘start_time’ or ‘end_time’ using ISO8601 format have no efect.

Badge +3

Hello again,

I finally got it.

The right filter is {"$and":[{"end_time":{"$gt":"<now_in_unix_time_format>"}},{"is_cancelled":{"$eq":"false"}}]}

This filter shows the same than the web interface.

Thanks!

Albert

Reply