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): https://github.com/Icinga/icingadb/pull/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 }'
```
2. Select all downtimes from Icinga DB database:
```
mysql icingadb -e "select id, parent_id, object_type from downtime order by object_type;"
```
3. 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 }'
```
4. 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'."
}
]
}
```
2. 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 |
+--------------------------------------------+-------------+
```
3. 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'."
}
]
}
```
4. 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'."
}
]
}
```
2. 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 |
+--------------------------------------------+--------------------------------------------+-------------+
```
3. 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."
}
]
}
```
4. 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
```