-
Notifications
You must be signed in to change notification settings - Fork 43
SMPROD-1309: Example for restoring Alerts now removes non-existent notification channel IDs #54
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
Conversation
| found = False | ||
| for ch in res.json()["notificationChannels"]: | ||
| if c['type'] == ch['type']: | ||
| if c['type'] == 'SNS': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I don't think it should be part of this review but VictorOps is missing from this list of types. It can be compared the same way as OpsGenie, by name.
|
I don't think I know enough about how the monitor side of the structures works to properly comment on this. Are the notification ids supposed to be globally unique, although the set of them may not be the same from one environment to another? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Writing a review with the disclaimer that I am "level 1 python user".
Code looks good but when I tried running the restore of alerts:
- python 2.7 complains on
a['description'] += ' (created via restore_alerts.py)' TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str' - python 3.6 complains on
SyntaxError: Missing parentheses in call to 'print'.
|
Ok, got it. 2.7 should be used. |
|
@Chobicus: Can you share your exported alert? I'd run into something similar when first revisiting this method, which is why this branch contains the Your error message makes it seem like you had a Perhaps you could also respond to @mstemm's question above. Based on my black box testing, I think they're going to be globally unique within a given environment. I say this because I created two separate on-prem environments, and the first Notification Channel created in each had ID of @mstemm's comment about "the set of them may not be the same from one environment to another" reminds me that I should explain the logic a bit more. The use case that motivated the original example was a customer who wanted to keep their Alerts config always under revision control is JSON objects in GitHub and never configure them through the UI. In this regard, they'd always expect the same Notification Channels IDs to be present and re-used each time the Alerts are "updated" from the JSON. Meanwhile, a separate user stumbled onto this same example and pulled the Alerts down in one environment and tried to restore them into another. Assuming SaaS and the globally unique pool of IDs, this was guaranteed to fail, hence the approach of just silently skipping over IDs that don't exist. In a Slack discussion I also floated the idea of making a new option so the user could explicitly decide they want to drop all IDs on restore, but @adityakinifr seemed to like the silent approach I'm using here and it was easy to implement, so I just went with it. I recognize this leaves open the possibility using this example to download/restore between two on-prem environments, they might end up restoring with enabled Notification Channel IDs they didn't intend (e.g. if ID |
|
@philrz Here is one of the alerts I used: and you are right. The description has value of null. I exported the alerts using UI "Export JSON" button on alerts page. @mstemm I can just confirm that Phil is again right. Notification channels get an auto-incremented id during the creation which are unique in an environment. |
|
@Chobicus: Thanks for the additional info. When working on these examples, I'd only considered the possibility of the Alerts JSON having come from the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch on time formats.
I just noticed that check if description exists is needed also during the alert creation before line 83.
|
@Chobicus: Thanks for spotting that. I've pushed another commit that addresses that. Maybe we're done? :) |
Someone might be restoring Alert configs from another environment, in which case the Notification Channel IDs in the saved Alert JSON is not expected to match the Notification Channel IDs in the target environment. This enhancement drops the non-matching IDs but still restores the Alert config.
To support this, the
get_notification_ids()method is enhanced such that if nochannelsfilter is provided, it just lists all IDs. It used to only support returning a filtered list based on type/name of channels.