Icinga2 Rest-API Dynamic Content Acknowledgement

Hi,
we got some dynamical content which i do build every night via a script querying the icinga-api. (about 200 hosts)
As a first step i delete everything that has been there the previous run to make sure there are no unwanted leftovers, afterwards i recreate the hosts (including eventual new ones) and corresponding graphs in grafana.

So far everything is working quite well, besides i ran into some problems recreating corresponding acknowledgments and downtimes. Since the hosts are being recreated i do need to recover those settings.

Downtimes:

my %json_data = (
attrs => [“author”,“comment”,“name”,“start_time”,“end_time”],
joins => [“host.name”,“service.name”],
);

Acknowledgment:

my %json_data = (
attrs => [“author”,“text”,“name”],
joins => [“host.name”,“service.name”],
filter => [“service.acknowledgement != 0.0 && service.state != ServiceOK”],
);

The past time i was gathering all downtimes/acks and after everything was set up fresh i redeployed everything i have gotten, which was working fine. Meanwhile the script has gotten big/slow enough to cause false/positive alarming at night for already handled services.

So i was trying to get away from the approach to recover every settings and just to do so for services and hosts i actually touch by iterating over the list and limit what i want to ack by passing the hostname like this, right after the host has been created:

sub acknowledge{
my $hostname = shift;
  for(my $i=0;$i<=$#{$ackHash->{results}};$i++){
    my %json_data_ack = (
      author  => $ackHash->{results}[$i]->{attrs}->{author},
      comment => $ackHash->{results}[$i]->{attrs}->{text},
    );
    if($ackHash->{results}[$i]->{joins}->{host}->{name} eq $hostname && !$ackHash->{results}[$i]->{joins}->{service}->{name}){
      sleep(60);
      $json_data_ack{filter} = ["host.name == \"$ackHash->{results}[$i]->{joins}->{host}->{name}\""];
      my $data_ack = encode_json(\%json_data_ack);
      $restClient->addHeader("X-HTTP-Method-Override", "POST");
      $restClient->POST("/v1/actions/acknowledge-problem?type=Host", $data_ack);
      #if($restClient->responseCode() != 200){
        print Dumper($restClient->responseContent());
      #}
    }elsif($ackHash->{results}[$i]->{joins}->{host}->{name} eq $hostname && $ackHash->{results}[$i]->{joins}->{service}->{name}){
      sleep(60);
      #filter  => ["service.state != ServiceOK && service.name == \"$ackHash->{results}[$i]->{joins}->{service}->{name}\" && host.name == \"$ackHash->{results}[$i]->{joins}->{host}->{name}\""],
      $json_data_ack{filter} = ["service.name == \"$ackHash->{results}[$i]->{joins}->{service}->{name}\" && host.name == \"$ackHash->{results}[$i]->{joins}->{host}->{name}\""],
      my $data_ack = encode_json(\%json_data_ack);
      $restClient->addHeader("X-HTTP-Method-Override", "POST");
      $restClient->POST("/v1/actions/acknowledge-problem?type=Service", $data_ack);
      #if($restClient->responseCode() != 200){
        print Dumper($restClient->responseContent());
      #}
    }
  }
}

Now with just running the function i do loose all acknowledgements (downtimes are working), only “workaround” so far has been a sleep(60) before applying the acknowledgements which i well really slow depending on how many acknowledgements there are to handle. Smaller sleep time is leading to inconsistent results (some services are getting applied some dont).

Nevertheless output of the api-call is always:

$VAR1 = ‘{“results”:[{“code”:200.0,“status”:“Successfully acknowledged problem for object ‘fw_name!ipsec-tunnelname’.”}]}’;

Am i missing something obvious or can any of you guys think of a possible solution?
Any advice would be highly appreciated.