Skip to content

API Action "remove-downtime": Also remove child downtimes#8913

Merged
N-o-X merged 1 commit intomasterfrom
feature/remove-child-downtimes
Jul 27, 2021
Merged

API Action "remove-downtime": Also remove child downtimes#8913
N-o-X merged 1 commit intomasterfrom
feature/remove-child-downtimes

Conversation

@N-o-X
Copy link
Copy Markdown
Contributor

@N-o-X N-o-X commented Jul 20, 2021

This PR adds the attribute parent to the Downtime object. This allows us to delete downtimes that have been created as child downtimes on a hosts services (using API parameter all_services) while deleting the hosts downtime.

Attribute PR in Icinga DB (used for testing): Icinga/icingadb#323

Testing

Config

var serviceCount = 3

object Host "DowntimeTestHost" {
        check_command = "dummy"
}

for (s in range(serviceCount)) {
        object Service "DowntimeTestService-" + s {
                check_command = "dummy"
                host_name = "DowntimeTestHost"
        }
}

Steps

  1. Schedule downtimes with all_services option:
curl -k -s -u root:icinga -H 'Accept: application/json' \
 -X POST 'https://localhost:5665/v1/actions/schedule-downtime' \
 -d '{ "type": "Host", "filter": "host.name==\"DowntimeTestHost\"", "start_time": 1446388806, "end_time": 1746389806, "author": "icingaadmin", "comment": "test", "pretty": true, "all_services": true }'
  1. Select all downtimes from Icinga DB database:
mysql icingadb -e "select id, parent_id, object_type from downtime order by object_type;"
  1. Delete parent downtime:
curl -k -s -u root:icinga -H 'Accept: application/json' \
 -X POST 'https://localhost:5665/v1/actions/remove-downtime' \
 -d '{ "downtime": "<DOWNTIME-NAME>", "pretty": true }'
  1. Again select all downtimes from Icinga DB database to validate the removal of all services downtimes:
mysql icingadb -e "select id, parent_id, object_type from downtime order by object_type;"

Results

Before

  1. Create downtimes
[noah@NoH-MB ~ ]$ curl -k -s -u root:icinga -H 'Accept: application/json' \
 -X POST 'https://localhost:5665/v1/actions/schedule-downtime' \
 -d '{ "type": "Host", "filter": "host.name==\"DowntimeTestHost\"", "start_time": 1446388806, "end_time": 1746389806, "author": "icingaadmin", "comment": "test", "pretty": true, "all_services": true }'
{
    "results": [
        {
            "code": 200,
            "legacy_id": 1,
            "name": "DowntimeTestHost!b6ad0a3b-7c8f-4a2c-968e-dc0e8fbda103",
            "service_downtimes": [
                {
                    "legacy_id": 2,
                    "name": "DowntimeTestHost!DowntimeTestService-0!58a333db-13cf-43e4-9f8b-22f60d8b3c91"
                },
                {
                    "legacy_id": 3,
                    "name": "DowntimeTestHost!DowntimeTestService-1!4dd12ad7-3b0d-49b4-b575-f81a09f694b1"
                },
                {
                    "legacy_id": 4,
                    "name": "DowntimeTestHost!DowntimeTestService-2!fb172915-0ab9-44bf-92c2-232d41b18b0e"
                }
            ],
            "status": "Successfully scheduled downtime 'DowntimeTestHost!b6ad0a3b-7c8f-4a2c-968e-dc0e8fbda103' for object 'DowntimeTestHost'."
        }
    ]
}
  1. Select from Icinga DB database
[noah@NoH-MB ~ ]$ mysql icingadb -e "select id, object_type from downtime order by object_type;"
+--------------------------------------------+-------------+
| id                                         | object_type |
+--------------------------------------------+-------------+
| 0x1498918DDF6288BCCAA8885C48950272915149ED | host        |
| 0x31CA087DCFAE8A312FF773B13923A2E314EB3685 | service     |
| 0x9A0426DBC927DC8E4188FE0DEB7344349DF2BC3E | service     |
| 0xE8427CECB1E2652403E73E8A52A9D40A41ADB32A | service     |
+--------------------------------------------+-------------+
  1. Remove parent downtime
[noah@NoH-MB ~ ]$ curl -k -s -u root:icinga -H 'Accept: application/json' \
 -X POST 'https://localhost:5665/v1/actions/remove-downtime' \
 -d '{ "downtime": "DowntimeTestHost!b6ad0a3b-7c8f-4a2c-968e-dc0e8fbda103", "pretty": true }'
{
    "results": [
        {
            "code": 200,
            "status": "Successfully removed downtime 'DowntimeTestHost!b6ad0a3b-7c8f-4a2c-968e-dc0e8fbda103'."
        }
    ]
}
  1. Again select all services from Icinga DB database:
[noah@NoH-MB ~ ]$ mysql icingadb -e "select id, object_type from downtime order by object_type;"
+--------------------------------------------+-------------+
| id                                         | object_type |
+--------------------------------------------+-------------+
| 0x31CA087DCFAE8A312FF773B13923A2E314EB3685 | service     |
| 0x9A0426DBC927DC8E4188FE0DEB7344349DF2BC3E | service     |
| 0xE8427CECB1E2652403E73E8A52A9D40A41ADB32A | service     |
+--------------------------------------------+-------------+
// Service downtimes are still there

After

  1. Create downtimes
[noah@NoH-MB ~ ]$ curl -k -s -u root:icinga -H 'Accept: application/json' \
 -X POST 'https://localhost:5665/v1/actions/schedule-downtime' \
 -d '{ "type": "Host", "filter": "host.name==\"DowntimeTestHost\"", "start_time": 1446388806, "end_time": 1746389806, "author": "icingaadmin", "comment": "test", "pretty": true, "all_services": true }'
{
    "results": [
        {
            "code": 200,
            "legacy_id": 1,
            "name": "DowntimeTestHost!e26a4f56-63cd-4388-8975-2db0d8fc8107",
            "service_downtimes": [
                {
                    "legacy_id": 2,
                    "name": "DowntimeTestHost!DowntimeTestService-0!57b60fd9-4cb7-493a-b33d-ef892aacf7b8"
                },
                {
                    "legacy_id": 3,
                    "name": "DowntimeTestHost!DowntimeTestService-1!d2e7793d-db42-40fa-88c2-6ab78f5c823e"
                },
                {
                    "legacy_id": 4,
                    "name": "DowntimeTestHost!DowntimeTestService-2!72393c64-201d-407c-8bdc-396f1601ed0e"
                }
            ],
            "status": "Successfully scheduled downtime 'DowntimeTestHost!e26a4f56-63cd-4388-8975-2db0d8fc8107' for object 'DowntimeTestHost'."
        }
    ]
}
  1. Select from Icinga DB database (should see parent_id set to the hosts downtime id)
[noah@NoH-MB ~ ]$ mysql icingadb -e "select id, parent_id, object_type from downtime order by object_type;"
+--------------------------------------------+--------------------------------------------+-------------+
| id                                         | parent_id                                  | object_type |
+--------------------------------------------+--------------------------------------------+-------------+
| 0x1ECE86DE1B6BB9D98222123E7F61059A3EBD4DDF | NULL                                       | host        |
| 0x348EDE862D53874FACAFFE3F71F26584ECF61C28 | 0x1ECE86DE1B6BB9D98222123E7F61059A3EBD4DDF | service     |
| 0x437A5875F7956B16D5AA4ED401540108FC7802EF | 0x1ECE86DE1B6BB9D98222123E7F61059A3EBD4DDF | service     |
| 0xDDBD7297C7B149C58D8D24112E56DD002EC39767 | 0x1ECE86DE1B6BB9D98222123E7F61059A3EBD4DDF | service     |
+--------------------------------------------+--------------------------------------------+-------------+
  1. Remove parent downtime
[noah@NoH-MB ~ ]$ curl -k -s -u root:icinga -H 'Accept: application/json' \
 -X POST 'https://localhost:5665/v1/actions/remove-downtime' \
 -d '{ "downtime": "DowntimeTestHost!e26a4f56-63cd-4388-8975-2db0d8fc8107", "pretty": true }'
{
    "results": [
        {
            "code": 200,
            "status": "Successfully removed downtime 'DowntimeTestHost!e26a4f56-63cd-4388-8975-2db0d8fc8107' and 3 child downtimes."
        }
    ]
}
  1. Again select all services from Icinga DB database:
[noah@NoH-MB ~ ]$ mysql icingadb -e "select id, parent_id, object_type from downtime order by object_type;"
[noah@NoH-MB ~ ]$
// Emtpy result set -> All child downtimes have been removed

@N-o-X N-o-X added enhancement New feature or request area/api REST API area/runtime Downtimes, comments, dependencies, events labels Jul 20, 2021
@N-o-X N-o-X added this to the 2.13.0 milestone Jul 20, 2021
@julianbrost
Copy link
Copy Markdown
Member

Why not have each downtime keep track of its child/service downtimes, similar to how a checkable keeps track of its downtimes (Checkable::GetDowntimes()). This would eliminate the need for having to store an explicit attribute has_child_downtimes and then actively search for these on deletion.

@N-o-X N-o-X force-pushed the feature/remove-child-downtimes branch 2 times, most recently from 0d7af54 to d936776 Compare July 22, 2021 15:43
@N-o-X N-o-X marked this pull request as ready for review July 22, 2021 15:49
@N-o-X N-o-X requested review from Al2Klimov and lippserd July 22, 2021 15:51
@N-o-X N-o-X force-pushed the feature/remove-child-downtimes branch from d936776 to 7217959 Compare July 23, 2021 11:53
Copy link
Copy Markdown
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • What’s the use case for not deleting children?
  • Why don’t let Downtimes disappear à la the scheduled ones?

Copy link
Copy Markdown
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general, but...


try {
Downtime::RemoveDowntime(downtime->GetName(), true);
Downtime::RemoveDowntime(downtime->GetName(), true, true);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why here true...


try {
Downtime::RemoveDowntime(rid, true);
Downtime::RemoveDowntime(rid, false, true);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... but here and below false?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I didn't want to touch anything, but the behavior of the API action. If we add it here, we would also need to change the behavior of downtime creation via the external command processor.

Copy link
Copy Markdown
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine.

@N-o-X N-o-X merged commit 07145d2 into master Jul 27, 2021
@N-o-X N-o-X deleted the feature/remove-child-downtimes branch July 27, 2021 16:02
yhabteab added a commit that referenced this pull request Feb 5, 2025
Services downtimes scheduled via the `all_services` parameter already
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 added a commit that referenced this pull request 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 added a commit that referenced this pull request Mar 13, 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api REST API area/runtime Downtimes, comments, dependencies, events enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants