Skip to content

Commit

Permalink
fix:no data state value for alertrulev9
Browse files Browse the repository at this point in the history
Signed-off-by: kamilswiec <kamilswiec@protonmail.com>
  • Loading branch information
kamilswiec committed Jun 30, 2023
1 parent 407a34c commit 98e036e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Changelog
* Extended SqlTarget to support parsing queries from files
* Fix AlertCondition backwards compatibility (``useNewAlerts`` default to ``False``)
* Added RateMetricAgg_ for ElasticSearch
* Fix AlertRuleV9 "unknown NoData state option No Data"

.. _`Bar_Chart`: https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/bar-chart/
.. _`RateMetricAgg`: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-rate-aggregation.html
Expand Down
26 changes: 16 additions & 10 deletions grafanalib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ def to_json_data(self):
ALERTRULE_STATE_DATA_ALERTING = 'Alerting'
ALERTRULE_STATE_DATA_ERROR = 'Error'

# Alert Rule state filter options (Grafana 9.x)
ALERTRULEV9_STATE_DATA_OK = 'OK'
ALERTRULEV9_STATE_DATA_NODATA = 'NoData'
ALERTRULEV9_STATE_DATA_ALERTING = 'Alerting'
ALERTRULEV9_STATE_DATA_ERROR = 'Error'

# Display Sort Order
SORT_ASC = 1
SORT_DESC = 2
Expand Down Expand Up @@ -1591,10 +1597,10 @@ class AlertRulev9(object):
The Interval is set by the alert group
:param noDataAlertState: Alert state if no data or all values are null
Must be one of the following:
[ALERTRULE_STATE_DATA_OK, ALERTRULE_STATE_DATA_ALERTING, ALERTRULE_STATE_DATA_NODATA ]
[ALERTRULEV9_STATE_DATA_OK, ALERTRULEV9_STATE_DATA_ALERTING, ALERTRULEV9_STATE_DATA_NODATA]
:param errorAlertState: Alert state if execution error or timeout
Must be one of the following:
[ALERTRULE_STATE_DATA_OK, ALERTRULE_STATE_DATA_ALERTING, ALERTRULE_STATE_DATA_ERROR ]
[ALERTRULEV9_STATE_DATA_OK, ALERTRULEV9_STATE_DATA_ALERTING, ALERTRULEV9_STATE_DATA_ERROR ]
:param timeRangeFrom: Time range interpolation data start from
:param timeRangeTo: Time range interpolation data finish at
Expand All @@ -1610,19 +1616,19 @@ class AlertRulev9(object):

evaluateFor = attr.ib(default=DEFAULT_ALERT_EVALUATE_FOR, validator=instance_of(str))
noDataAlertState = attr.ib(
default=ALERTRULE_STATE_DATA_ALERTING,
default=ALERTRULEV9_STATE_DATA_ALERTING,
validator=in_([
ALERTRULE_STATE_DATA_OK,
ALERTRULE_STATE_DATA_ALERTING,
ALERTRULE_STATE_DATA_NODATA
ALERTRULEV9_STATE_DATA_OK,
ALERTRULEV9_STATE_DATA_ALERTING,
ALERTRULEV9_STATE_DATA_NODATA
])
)
errorAlertState = attr.ib(
default=ALERTRULE_STATE_DATA_ALERTING,
default=ALERTRULEV9_STATE_DATA_ALERTING,
validator=in_([
ALERTRULE_STATE_DATA_OK,
ALERTRULE_STATE_DATA_ALERTING,
ALERTRULE_STATE_DATA_ERROR
ALERTRULEV9_STATE_DATA_OK,
ALERTRULEV9_STATE_DATA_ALERTING,
ALERTRULEV9_STATE_DATA_ERROR
])
)
condition = attr.ib(default='B')
Expand Down

0 comments on commit 98e036e

Please sign in to comment.