Merge "Allow users to set periodic notifications on all notification types"
This commit is contained in:
commit
176985da7c
@ -1673,7 +1673,7 @@ None.
|
||||
* name (string(250), required) - A descriptive name of the notification method.
|
||||
* type (string(100), required) - The type of notification method (see [List supported Notification Method Types](#list-supported-notification-method-types) for supported types).
|
||||
* address (string(100), required) - The email/url address to notify.
|
||||
* period (integer, optional) - The interval in seconds to periodically send the notification. Only can be set as a non zero value for WEBHOOK methods. Allowed periods for Webhooks by default are 0, 60. You can change allow periods for webhooks in the api config. The notification will continue to be sent at the defined interval until the alarm it is associated with changes state.
|
||||
* period (integer, optional) - The interval in seconds to periodically send the notification. Supported periods are defined in the Monasca API and Notification service config. The notification will continue to be sent at the defined interval until the alarm it is associated with changes state.
|
||||
|
||||
#### Request Examples
|
||||
```
|
||||
@ -1889,7 +1889,7 @@ None.
|
||||
* name (string(250), required) - A descriptive name of the notification method.
|
||||
* type (string(100), required) - The type of notification method (see [List supported Notification Method Types](#list-supported-notification-method-types) for supported types).
|
||||
* address (string(100), required) - The email/url address to notify.
|
||||
* period (integer, required) - The interval in seconds to periodically send the notification. Only can be set as a non zero value for WEBHOOK methods. Allowed periods for Webhooks by default are 0, 60. You can change allow periods for webhooks in the api config. The notification will continue to be sent at the defined interval until the alarm it is associated with changes state.
|
||||
* period (integer, required) - The interval in seconds to periodically send the notification. Supported periods are defined in the Monasca API and Notification service config. The notification will continue to be sent at the defined interval until the alarm it is associated with changes state.
|
||||
|
||||
#### Request Examples
|
||||
````
|
||||
@ -1960,7 +1960,7 @@ None.
|
||||
* name (string(250), optional) - A descriptive name of the notification method.
|
||||
* type (string(100), optional) - The type of notification method (see [List supported Notification Method Types](#list-supported-notification-method-types) for supported types).
|
||||
* address (string(100), optional) - The email/url address to notify.
|
||||
* period (integer, optional) - The interval in seconds to periodically send the notification. Only can be set as a non zero value for WEBHOOK methods. Allowed periods for Webhooks by default are 0, 60. You can change allow periods for webhooks in the api config. The notification will continue to be sent at the defined interval until the alarm it is associated with changes state.
|
||||
* period (integer, optional) - The interval in seconds to periodically send the notification. Supported periods are defined in the Monasca API and Notification service config. The notification will continue to be sent at the defined interval until the alarm it is associated with changes state.
|
||||
|
||||
#### Request Examples
|
||||
````
|
||||
|
@ -175,16 +175,16 @@ class TestNotificationValidation(base.BaseTestCase):
|
||||
notification, valid_periods)
|
||||
self.assertEqual("Address name@ is not of correct format", str(ex))
|
||||
|
||||
def test_validation_exception_for_invalid_period_for_email(self):
|
||||
def test_validation_for_email_non_zero_period(self):
|
||||
notification = {
|
||||
"name": "MyEmail",
|
||||
"type": "EMAIL",
|
||||
"address": "name@domain.com",
|
||||
"period": "60"}
|
||||
ex = self.assertRaises(schemas_exceptions.ValidationException,
|
||||
schemas_notifications.parse_and_validate,
|
||||
notification, valid_periods)
|
||||
self.assertEqual("Period can only be set with webhooks", str(ex))
|
||||
try:
|
||||
schemas_notifications.parse_and_validate(notification, valid_periods)
|
||||
except schemas_exceptions.ValidationException:
|
||||
self.fail("shouldn't happen")
|
||||
|
||||
def test_validation_for_webhook(self):
|
||||
notification = {"name": "MyWebhook", "type": "WEBHOOK", "address": "http://somedomain.com"}
|
||||
@ -228,7 +228,7 @@ class TestNotificationValidation(base.BaseTestCase):
|
||||
ex = self.assertRaises(schemas_exceptions.ValidationException,
|
||||
schemas_notifications.parse_and_validate,
|
||||
notification, valid_periods)
|
||||
self.assertEqual("10 is not a valid period, not in [0, 60]", str(ex))
|
||||
self.assertEqual("10 is not in the configured list of valid periods: [0, 60]", str(ex))
|
||||
|
||||
def test_validation_for_pagerduty(self):
|
||||
notification = {"name": "MyPagerduty", "type": "PAGERDUTY",
|
||||
@ -238,13 +238,13 @@ class TestNotificationValidation(base.BaseTestCase):
|
||||
except schemas_exceptions.ValidationException:
|
||||
self.fail("shouldn't happen")
|
||||
|
||||
def test_validation_exception_for_invalid_period_for_pagerduty(self):
|
||||
def test_validation_for_pagerduty_non_zero_period(self):
|
||||
notification = {"name": "MyPagerduty", "type": "PAGERDUTY",
|
||||
"address": "nzH2LVRdMzun11HNC2oD", "period": 60}
|
||||
ex = self.assertRaises(schemas_exceptions.ValidationException,
|
||||
schemas_notifications.parse_and_validate,
|
||||
notification, valid_periods)
|
||||
self.assertEqual("Period can only be set with webhooks", str(ex))
|
||||
try:
|
||||
schemas_notifications.parse_and_validate(notification, valid_periods)
|
||||
except schemas_exceptions.ValidationException:
|
||||
self.fail("shouldn't happen")
|
||||
|
||||
def test_validation_for_max_name_address(self):
|
||||
name = "A" * 250
|
||||
|
@ -60,9 +60,6 @@ def parse_and_validate(msg, valid_periods, require_all=False):
|
||||
elif notification_type == 'WEBHOOK':
|
||||
_validate_url(msg['address'])
|
||||
|
||||
if notification_type != 'WEBHOOK' and msg['period'] != 0:
|
||||
raise exceptions.ValidationException("Period can only be set with webhooks")
|
||||
|
||||
|
||||
def _validate_email(address):
|
||||
if not validation.validate_email_address(address):
|
||||
@ -92,5 +89,5 @@ def _parse_and_validate_period(period, valid_periods):
|
||||
raise exceptions.ValidationException("Period {} must be a valid integer".format(period))
|
||||
if period != 0 and period not in valid_periods:
|
||||
raise exceptions.ValidationException(
|
||||
"{} is not a valid period, not in {}".format(period, valid_periods))
|
||||
"{} is not in the configured list of valid periods: {}".format(period, valid_periods))
|
||||
return period
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Adds support for configuring periodic notifications for all notification types.
|
Loading…
Reference in New Issue
Block a user