-
Notifications
You must be signed in to change notification settings - Fork 434
feat(event_sources): add CloudWatch dashboard custom widget event #1474
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
Merged
leandrodamascena
merged 4 commits into
aws-powertools:develop
from
sthuber90:feat-cw-dashboard-custom-widget-event-1461
Aug 29, 2022
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8b3dbfe
feat(data_classes): add CloudWatch dashboard custom widget event
sthuber90 41f8df5
docs(data_classes): document CW dashboard widget return types
sthuber90 967a3c1
feat(data_classes): add domain name to CW widget event
sthuber90 0d02f26
feat(data_classes): removed unused example class
leandrodamascena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
aws_lambda_powertools/utilities/data_classes/cloud_watch_custom_widget_event.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
from typing import Any, Dict, Optional | ||
|
||
from aws_lambda_powertools.utilities.data_classes.common import DictWrapper | ||
|
||
|
||
class TimeZone(DictWrapper): | ||
@property | ||
def label(self) -> str: | ||
"""The time range label. Either 'UTC' or 'Local'""" | ||
return self["label"] | ||
|
||
@property | ||
def offset_iso(self) -> str: | ||
"""The time range offset in the format +/-00:00""" | ||
return self["offsetISO"] | ||
|
||
@property | ||
def offset_in_minutes(self) -> int: | ||
"""The time range offset in minutes""" | ||
return int(self["offsetInMinutes"]) | ||
|
||
|
||
class TimeRange(DictWrapper): | ||
@property | ||
def mode(self) -> str: | ||
"""The time range mode, i.e. 'relative' or 'absolute'""" | ||
return self["mode"] | ||
|
||
@property | ||
def start(self) -> int: | ||
"""The start time within the time range""" | ||
return self["start"] | ||
|
||
@property | ||
def end(self) -> int: | ||
"""The end time within the time range""" | ||
return self["end"] | ||
|
||
@property | ||
def relative_start(self) -> Optional[int]: | ||
"""The relative start time within the time range""" | ||
return self.get("relativeStart") | ||
|
||
@property | ||
def zoom_start(self) -> Optional[int]: | ||
"""The start time within the zoomed time range""" | ||
return (self.get("zoom") or {}).get("start") | ||
|
||
@property | ||
def zoom_end(self) -> Optional[int]: | ||
"""The end time within the zoomed time range""" | ||
return (self.get("zoom") or {}).get("end") | ||
|
||
|
||
class CloudWatchWidgetContext(DictWrapper): | ||
@property | ||
def dashboard_name(self) -> str: | ||
"""Get dashboard name, in which the widget is used""" | ||
return self["dashboardName"] | ||
|
||
@property | ||
def widget_id(self) -> str: | ||
"""Get widget ID""" | ||
return self["widgetId"] | ||
|
||
@property | ||
def account_id(self) -> str: | ||
"""Get AWS Account ID""" | ||
return self["accountId"] | ||
|
||
@property | ||
def locale(self) -> str: | ||
"""Get locale language""" | ||
return self["locale"] | ||
|
||
@property | ||
def timezone(self) -> TimeZone: | ||
"""Timezone information of the dashboard""" | ||
return TimeZone(self["timezone"]) | ||
|
||
@property | ||
def period(self) -> int: | ||
"""The period shown on the dashboard""" | ||
return int(self["period"]) | ||
|
||
@property | ||
def is_auto_period(self) -> bool: | ||
"""Whether auto period is enabled""" | ||
return bool(self["isAutoPeriod"]) | ||
|
||
@property | ||
def time_range(self) -> TimeRange: | ||
"""The widget time range""" | ||
return TimeRange(self["timeRange"]) | ||
|
||
@property | ||
def theme(self) -> str: | ||
"""The dashboard theme, i.e. 'light' or 'dark'""" | ||
return self["theme"] | ||
|
||
@property | ||
def link_charts(self) -> bool: | ||
"""The widget is linked to other charts""" | ||
return bool(self["linkCharts"]) | ||
|
||
@property | ||
def title(self) -> str: | ||
"""Get widget title""" | ||
return self["title"] | ||
|
||
@property | ||
def params(self) -> Dict[str, Any]: | ||
"""Get widget parameters""" | ||
return self["params"] | ||
|
||
@property | ||
def forms(self) -> Dict[str, Any]: | ||
"""Get widget form data""" | ||
return self["forms"]["all"] | ||
|
||
@property | ||
def height(self) -> int: | ||
"""Get widget height""" | ||
return int(self["height"]) | ||
|
||
@property | ||
def width(self) -> int: | ||
"""Get widget width""" | ||
return int(self["width"]) | ||
|
||
|
||
class CloudWatchDashboardCustomWidgetEvent(DictWrapper): | ||
"""CloudWatch dashboard custom widget event | ||
|
||
You can use a Lambda function to create a custom widget on a CloudWatch dashboard. | ||
|
||
Documentation: | ||
------------- | ||
- https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/add_custom_widget_dashboard_about.html | ||
""" | ||
|
||
@property | ||
def describe(self) -> bool: | ||
"""Display widget documentation""" | ||
return bool(self.get("describe", False)) | ||
|
||
@property | ||
def widget_context(self) -> Optional[CloudWatchWidgetContext]: | ||
"""The widget context""" | ||
if self.get("widgetContext"): | ||
return CloudWatchWidgetContext(self["widgetContext"]) | ||
|
||
return None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"original": "param-to-widget", | ||
"widgetContext": { | ||
"dashboardName": "Name-of-current-dashboard", | ||
"widgetId": "widget-16", | ||
"accountId": "123456789123", | ||
"locale": "en", | ||
"timezone": { | ||
"label": "UTC", | ||
"offsetISO": "+00:00", | ||
"offsetInMinutes": 0 | ||
}, | ||
"period": 300, | ||
"isAutoPeriod": true, | ||
"timeRange": { | ||
"mode": "relative", | ||
"start": 1627236199729, | ||
"end": 1627322599729, | ||
"relativeStart": 86400012, | ||
"zoom": { | ||
"start": 1627276030434, | ||
"end": 1627282956521 | ||
} | ||
}, | ||
"theme": "light", | ||
"linkCharts": true, | ||
"title": "Tweets for Amazon website problem", | ||
"forms": { | ||
"all": {} | ||
}, | ||
"params": { | ||
"original": "param-to-widget" | ||
}, | ||
"width": 588, | ||
"height": 369 | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.