Can ScheduledDowntimes objects be created via REST API?

I am using version: r2.12.1-1 and would like to create ScheduledDowntimes objects via the REST API.
Currently I can query them, but until now have not found a way to create them.

Thank you in advance,
bye //emil.

Hi @eer

Welcome to the community,
Be sure to check out the guidelines:
https://community.icinga.com/guidelines

Have you seen this page?:


I should tell you al you want to know

thanks @belastingvormulier,

I have read the documentation but unfortunately there are no examples (or references) on how to create the above mentioned objects.

I found everything else (regarding objects/actions/etc.) that I needed for my work, the only missing piece in the puzzle is the creation of ScheduledDowntime objects.

Hi @eer

I am sure there are plenty of examples just like this one right under:

Example for scheduling a downtime for all ping4 services:

 curl -k -s -u root:icinga -H 'Accept: application/json' \
 -X POST 'https://localhost:5665/v1/actions/schedule-downtime' \
 -d '{ "type": "Service", "filter": "service.name==\"ping4\"", "start_time": 1446388806, "end_time": 1446389806, "duration": 1000, "author": "icingaadmin", "comment": "IPv4 network maintenance", "pretty": true }'

on the page i gave you

hi @belastingvormulier,

I do not want to schedule a downtime, I want to create a ScheduledDowntime object.
You can find its definition here:

Your example is perfectly valid for an action (this is what you normally create from icingaweb2 if you schedule a downtime). A ScheduledDowntime object is not an action.

HI @eer,

Right, Again my example, you would need to create your own script that runs that example each time you need such a downtime I am afraid.

hi @belastingvormulier,

thanks - I was afraid that I had to go that way :wink:
Basically what I want to do is to re-play all comments (incl. acknowledgements), downtimes and recurring downtimes (e.g. ScheduledDowntimes objects) from our “old” system to the new one.
Everything is working smoothly except that last step.
Somehow icinga director can do that (at least according to this link it seems to be possible: https://github.com/Icinga/icingaweb2-module-director/issues/1879).
I hoped to achieve the same thing via the icinga2 API.

Have you tried it as follows?

curl -k -v -u root:icinga -H 'Accept: application/json' \ 
-X PUT 'https://localhost:5665/v1/objects/scheduleddowntimes/hostName!ServiceName!some-downtime.example' \ 
-d '{ "attrs": { "host_name": "hostName", "service_name": "ServiceName", "author": "icingaadmin", "comment": "Some comment here", "ranges": { "monday": "02:00-03:00", "sunday": "02:00-03:00" } }, "pretty": true }'

Best,
Yonas

Hi @yhabteab

That is impressive if it works I should try this :slight_smile:
It is not documented on the API page so I am very curious about this one

Thanks @yhabteab,

I can confirm that the API call works as you described.
I could infer that the name has to consist of the combination of host_name!service_name!comment by looking into the code for scheduleddowntime.cpp (https://github.com/Icinga/icinga2/blob/master/lib/icinga/scheduleddowntime.cpp) at line 44 (the exception on line 45 was the first problem that I encountered).
What I still missed was that the API still wanted an explicit host_name and service_name as parameters.

Should anyone use the python client icinga2apic (https://github.com/joni1993/icinga2apic/blob/master/doc/3-objects.md) below a working sample:

icinga2_api_client.objects.create('ScheduledDowntime','icingaussat1-staging.teamplay.monitoring.net!load!my-python-comment',
  attrs=
  { 
      'host_name': 'icingaussat1-staging.teamplay.monitoring.net', 
      'service_name': 'load', 
      'author':'icingaadmin',
      'comment':'some python comment',
      'ranges': { "sunday" : "22:00-23:00"},
  }
)
1 Like