Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiActions: Remove child downtimes recursively #10345

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yhabteab
Copy link
Member

@yhabteab yhabteab commented Feb 5, 2025

Services downtimes scheduled via the all_services flag get already removed automatically when removing their parent downtimes (introduced with #8913). Now, this commit makes it possible to perform the same actions for all child downtimes, i.e. not only for those of service objects, but for all child objects represented in the dependency tree.

Config

template Host "default" default {
	check_command = "dummy"
	check_interval = 120s
	vars.dummy_text = "I'm just testing something"
	vars.dummy_state = 2
}

object Host "father" {}
object Host "mother" {}
object Host "grandfather" {}
object Host "sister" {}
object Host "brother" {}

apply Dependency "father" to Host {
	parent_host_name = "father"
	redundancy_group = "Parents"
	assign where host.name == "sister" || host.name == "brother"
}

apply Dependency "mother" to Host {
 	parent_host_name = "mother"
 	redundancy_group = "Parents"
 	assign where host.name == "sister" || host.name == "brother"
}

apply Dependency "grandfather" to Host {
 	parent_host_name = "grandfather"
 	redundancy_group = "Grand Parents"
 	assign where host.name == "mother" || host.name == "father"
}
$ curl -ksSu root:icinga 'https://localhost:5667/v1/objects/downtimes' | jq '.results | length'
0
$ curl -ksSu root:icinga 'https://localhost:5667/v1/objects/hosts' | jq '.results | length'
5
$ curl -ksSu root:icinga 'https://localhost:5667/v1/objects/dependencies' | jq '.results | length'
6

Tests

Before:

$ curl -k -s -S -i -u root:icinga -H 'Accept: application/json' \
 -X POST 'https://localhost:5667/v1/actions/schedule-downtime' \
 -d @<(cat <<EOF
{ "type": "Host", "filter": "host.name == \"grandfather\"", "start_time": $(date +%s), "end_time": $(date -v+30M +%s), "child_options": "DowntimeTriggeredChildren", "author": "icingaadmin", "comment": "IPv4 network maintenance", "pretty": true }
EOF
)
HTTP/1.1 200 OK
...
$ curl -ksSu root:icinga 'https://localhost:5667/v1/objects/downtimes' | jq '.results | length'
5
$ curl -k -s -S -i -u root:icinga -H 'Accept: application/json' \
 -X POST 'https://localhost:5667/v1/actions/remove-downtime' \
 -d '{ "filter": "host.name == \"grandfather\"", "pretty": true, "type": "Host" }'
{
    "results": [
        {
            "code": 200,
            "status": "Successfully removed all downtimes for object 'grandfather' and 0 child downtimes."
        }
    ]
}
$ curl -ksSu root:icinga 'https://localhost:5667/v1/objects/downtimes' | jq '.results | length'
4

After:

$ curl -k -s -S -i -u root:icinga -H 'Accept: application/json' \
 -X POST 'https://localhost:5667/v1/actions/schedule-downtime' \
 -d @<(cat <<EOF
{ "type": "Host", "filter": "host.name == \"grandfather\"", "start_time": $(date +%s), "end_time": $(date -v+30M +%s), "child_options": "DowntimeTriggeredChildren", "author": "icingaadmin", "comment": "IPv4 network maintenance", "pretty": true }
EOF
)

$ curl -ksSu root:icinga 'https://localhost:5667/v1/objects/downtimes' | jq '.results | length'
5
$ curl -k -s -S -i -u root:icinga -H 'Accept: application/json' \
 -X POST 'https://localhost:5667/v1/actions/remove-downtime' \
 -d '{ "filter": "host.name == \"grandfather\"", "pretty": true, "type": "Host" }'
{
    "results": [
        {
            "code": 200,
            "status": "Successfully removed all downtimes for object 'grandfather' and 4 child downtimes."
        }
    ]
}
$ curl -ksSu root:icinga 'https://localhost:5667/v1/objects/downtimes' | jq '.results | length'
0

fixes #10333

@cla-bot cla-bot bot added the cla/signed label Feb 5, 2025
@yhabteab yhabteab added enhancement New feature or request area/api REST API area/runtime Downtimes, comments, dependencies, events and removed area/api REST API labels Feb 5, 2025
@yhabteab yhabteab requested a review from julianbrost February 5, 2025 13:17
@yhabteab yhabteab added this to the 2.14.5 milestone Feb 5, 2025
Services downtimes scheduled via the `all_services` flag get already
removed automatically when removing their parent downtimes (introduced
with #8913). Now, this commit makes it possible to perform the same actions
for all child downtimes, i.e. not only for those of service objects, but
for all child objects represented in the dependency tree.
@yhabteab yhabteab force-pushed the remove-child-downtimes branch from 66b2186 to 56b6f09 Compare February 5, 2025 13:32
@yhabteab yhabteab modified the milestones: 2.14.5, 2.15.0 Feb 5, 2025
@julianbrost
Copy link
Contributor

Now, this commit makes it possible to perform the same actions for all child downtimes

Not only performing the same action but also using the very same code, hence the diff is so small. So this just makes use of the existing parent-tracking mechanism for downtimes. It's probably noteworthy (for the changelog for example) that this will only work for new downtimes.

ScheduledDowntime has an child_options attribute as well that's handled somewhere else:

Downtime::Ptr childDowntime = Downtime::AddDowntime(child, GetAuthor(), GetComment(),
segment.first, segment.second, GetFixed(), trigger, GetDuration(), GetName(), GetName());

Did you intentionally leave that as-is? Maybe due to the following?

if (!config_owner.IsEmpty() && removalReason == DowntimeRemovedByUser) {
BOOST_THROW_EXCEPTION(invalid_downtime_removal_error("Cannot remove downtime '" + downtime->GetName() +
"'. It is owned by scheduled downtime object '" + config_owner + "'"));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/runtime Downtimes, comments, dependencies, events cla/signed enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically delete downtimes for children
2 participants