-
Notifications
You must be signed in to change notification settings - Fork 317
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
Fix rendering AlertRulev9 json for possible use in Alerting provisioning API #568
base: main
Are you sure you want to change the base?
Changes from all commits
2abb9c8
d634ffa
3628021
e4912ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -841,6 +841,18 @@ def to_json_data(self): | |||
} | ||||
|
||||
|
||||
@attr.s | ||||
class DataSource(object): | ||||
uid = attr.ib(validator=instance_of(str)) | ||||
type = attr.ib(validator=instance_of(str)) | ||||
|
||||
def to_json_data(self): | ||||
return { | ||||
'uid': self.uid, | ||||
'type': self.type, | ||||
} | ||||
|
||||
|
||||
@attr.s | ||||
class ConstantInput(object): | ||||
name = attr.ib() | ||||
|
@@ -1574,13 +1586,15 @@ class AlertRulev9(object): | |||
:param timeRangeTo: Time range interpolation data finish at | ||||
:param uid: Alert UID should be unique | ||||
:param dashboard_uid: Dashboard UID that should be use for linking on alert message | ||||
:param panel_id: Panel ID that should should be use for linking on alert message | ||||
:param panel_id: Panel ID that should be use for linking on alert message | ||||
""" | ||||
|
||||
title = attr.ib() | ||||
triggers = attr.ib(default=[], validator=is_valid_triggersv9) | ||||
annotations = attr.ib(default={}, validator=instance_of(dict)) | ||||
labels = attr.ib(default={}, validator=instance_of(dict)) | ||||
annotations = attr.ib(factory=dict, validator=instance_of(dict)) | ||||
labels = attr.ib(factory=dict, validator=instance_of(dict)) | ||||
folderUid = attr.ib(default=None, validator=attr.validators.optional(instance_of(str))) | ||||
ruleGroup = attr.ib(default=None, validator=attr.validators.optional(instance_of(str))) | ||||
Comment on lines
+1596
to
+1597
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add document string for these |
||||
|
||||
evaluateFor = attr.ib(default=DEFAULT_ALERT_EVALUATE_FOR, validator=instance_of(str)) | ||||
noDataAlertState = attr.ib( | ||||
|
@@ -1603,8 +1617,8 @@ class AlertRulev9(object): | |||
timeRangeFrom = attr.ib(default=300, validator=instance_of(int)) | ||||
timeRangeTo = attr.ib(default=0, validator=instance_of(int)) | ||||
uid = attr.ib(default=None, validator=attr.validators.optional(instance_of(str))) | ||||
dashboard_uid = attr.ib(default="", validator=instance_of(str)) | ||||
panel_id = attr.ib(default=0, validator=instance_of(int)) | ||||
dashboard_uid = attr.ib(default=None, validator=attr.validators.optional(instance_of(str))) | ||||
panel_id = attr.ib(default=None, validator=attr.validators.optional(instance_of(int))) | ||||
|
||||
def to_json_data(self): | ||||
data = [] | ||||
|
@@ -1618,12 +1632,18 @@ def to_json_data(self): | |||
"from": self.timeRangeFrom, | ||||
"to": self.timeRangeTo | ||||
}, | ||||
"datasourceUid": target.datasource, | ||||
"datasourceUid": target.datasource.uid, | ||||
"model": target.to_json_data(), | ||||
}] | ||||
else: | ||||
data += [trigger.to_json_data()] | ||||
|
||||
if self.panel_id: | ||||
self.annotations['__panelId__'] = str(self.panel_id) | ||||
|
||||
if self.dashboard_uid: | ||||
self.annotations['__dashboardUid__'] = self.dashboard_uid | ||||
|
||||
return { | ||||
"title": self.title, | ||||
"uid": self.uid, | ||||
|
@@ -1633,7 +1653,9 @@ def to_json_data(self): | |||
"annotations": self.annotations, | ||||
"data": data, | ||||
"noDataState": self.noDataAlertState, | ||||
"execErrState": self.errorAlertState | ||||
"execErrState": self.errorAlertState, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure that this model is correct? According to this API: https://editor.swagger.io/?url=https://raw.githubusercontent.com/grafana/grafana/main/pkg/services/ngalert/api/tooling/post.json looks that grafana_alert object is required for grafana managed alerts 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please could you remove this part from the PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
"folderUid": self.folderUid, | ||||
"ruleGroup": self.ruleGroup, | ||||
} | ||||
|
||||
|
||||
|
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.