Solved

Get DOWN events using clapi or rest api

  • 30 March 2023
  • 2 replies
  • 236 views

Userlevel 1
Badge +6

Hello,

is it possible  to get DOWN events using clapi or rest api?

 

Every week I use the Event Logs to look for DOWN status and HARD ONLY type  during the last 7 days. Looking at the documentation I’m not able to find how/if I can use clapi or rest API for that.

 

Regards,

Enrique

icon

Best answer by christophe.niel-ACT 30 March 2023, 14:42

View original

2 replies

Userlevel 5
Badge +14

hello

interesting question, as far as i know you cannot query the event log from api directly

Clapi is used to configure the platform, apiv1 can also get you realtime status, and api v2 returns you realtime status

in api v2 there is the possibility to query the “timeline” thoug, here is an example for a random host with this query

/api/latest/monitoring/hosts/1059/timeline?search={"$and":[{"type":{"$eq":"event"}},{"date":{"$ge":"2023-03-01"}},{"content":{"$lk":"CRITICAL%"}}]}

result in postman : 

 

so if you look the doc : Centreon Web RestAPI the example are pretty bad as you cannot search by name, you can only search : 

date, type, content

not status, not hard/soft, or do a query on multiple host

 

what you need to do then is code something that will

  • list all your host id (and name)
  • for each host id, do the query for the timeline of this host
  • filter the result based on the property “tries” (assuming you only want the hard event, and all your host all have 3 retry, it’s simple to filter )
  • then output all you need, host name, event time etc…

this work because the content of a host down is the result of a check that returns “CRITICAL ...”, and the filter I put in the query looks for that

 

happy coding

Userlevel 1
Badge +6

Thanks christophe.niel-ACT.

 

I think I can work with this.

 

Regards,

Reply