From 3ce89cad71d58bb4cdd0cc63ba838706a512c313 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 6 Sep 2018 11:20:38 +0200 Subject: [PATCH] make default values for alerting configurable --- conf/defaults.ini | 6 ++++ conf/sample.ini | 6 ++++ docs/sources/installation/configuration.md | 8 +++++ pkg/api/frontendsettings.go | 30 ++++++++++--------- pkg/setting/setting.go | 8 +++-- public/app/core/config.ts | 2 ++ .../app/features/alerting/alert_tab_ctrl.ts | 4 +-- 7 files changed, 46 insertions(+), 18 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index fff9f630690..cf924be3f9f 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -467,6 +467,12 @@ enabled = true # Makes it possible to turn off alert rule execution but alerting UI is visible execute_alerts = true +# Default setting for new alert rules. Defaults to categories error and timeouts as alerting. (alerting, keep_state) +error_or_timeout = alerting + +# Default setting for how Grafana handles nodata or null values in alerting. (alerting, no_data, keep_state, ok) +nodata_or_nullvalues = no_data + #################################### Explore ############################# [explore] # Enable the Explore section diff --git a/conf/sample.ini b/conf/sample.ini index 2b2ae497e36..67072814347 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -387,6 +387,12 @@ log_queries = # Makes it possible to turn off alert rule execution but alerting UI is visible ;execute_alerts = true +# Default setting for new alert rules. Defaults to categories error and timeouts as alerting. (alerting, keep_state) +;error_or_timeout = alerting + +# Default setting for how Grafana handles nodata or null values in alerting. (alerting, no_data, keep_state, ok) +;nodata_or_nullvalues = no_data + #################################### Explore ############################# [explore] # Enable the Explore section diff --git a/docs/sources/installation/configuration.md b/docs/sources/installation/configuration.md index 3394dfe16bc..1cd4d5d3893 100644 --- a/docs/sources/installation/configuration.md +++ b/docs/sources/installation/configuration.md @@ -1009,3 +1009,11 @@ Defaults to true. Set to false to disable alerting engine and hide Alerting from ### execute_alerts Makes it possible to turn off alert rule execution. + +### error_or_timeout + +Default setting for new alert rules. Defaults to categories error and timeouts as alerting. (alerting, keep_state) + +### nodata_or_nullvalues + +Default setting for how Grafana handles nodata or null values in alerting. (alerting, no_data, keep_state, ok) diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index da3c88566c1..a58be38781e 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -132,20 +132,22 @@ func getFrontendSettingsMap(c *m.ReqContext) (map[string]interface{}, error) { } jsonObj := map[string]interface{}{ - "defaultDatasource": defaultDatasource, - "datasources": datasources, - "panels": panels, - "appSubUrl": setting.AppSubUrl, - "allowOrgCreate": (setting.AllowUserOrgCreate && c.IsSignedIn) || c.IsGrafanaAdmin, - "authProxyEnabled": setting.AuthProxyEnabled, - "ldapEnabled": setting.LdapEnabled, - "alertingEnabled": setting.AlertingEnabled, - "exploreEnabled": setting.ExploreEnabled, - "googleAnalyticsId": setting.GoogleAnalyticsId, - "disableLoginForm": setting.DisableLoginForm, - "externalUserMngInfo": setting.ExternalUserMngInfo, - "externalUserMngLinkUrl": setting.ExternalUserMngLinkUrl, - "externalUserMngLinkName": setting.ExternalUserMngLinkName, + "defaultDatasource": defaultDatasource, + "datasources": datasources, + "panels": panels, + "appSubUrl": setting.AppSubUrl, + "allowOrgCreate": (setting.AllowUserOrgCreate && c.IsSignedIn) || c.IsGrafanaAdmin, + "authProxyEnabled": setting.AuthProxyEnabled, + "ldapEnabled": setting.LdapEnabled, + "alertingEnabled": setting.AlertingEnabled, + "alertingErrorOrTimeout": setting.AlertingErrorOrTimeout, + "alertingNoDataOrNullValues": setting.AlertingNoDataOrNullValues, + "exploreEnabled": setting.ExploreEnabled, + "googleAnalyticsId": setting.GoogleAnalyticsId, + "disableLoginForm": setting.DisableLoginForm, + "externalUserMngInfo": setting.ExternalUserMngInfo, + "externalUserMngLinkUrl": setting.ExternalUserMngLinkUrl, + "externalUserMngLinkName": setting.ExternalUserMngLinkName, "buildInfo": map[string]interface{}{ "version": setting.BuildVersion, "commit": setting.BuildCommit, diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index 789622ca0dd..d16fd4955d5 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -164,8 +164,10 @@ var ( Quota QuotaSettings // Alerting - AlertingEnabled bool - ExecuteAlerts bool + AlertingEnabled bool + ExecuteAlerts bool + AlertingErrorOrTimeout string + AlertingNoDataOrNullValues string // Explore UI ExploreEnabled bool @@ -672,6 +674,8 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error { alerting := iniFile.Section("alerting") AlertingEnabled = alerting.Key("enabled").MustBool(true) ExecuteAlerts = alerting.Key("execute_alerts").MustBool(true) + AlertingErrorOrTimeout = alerting.Key("error_or_timeout").MustString("alerting") + AlertingNoDataOrNullValues = alerting.Key("nodata_or_nullvalues").MustString("no_data") explore := iniFile.Section("explore") ExploreEnabled = explore.Key("enabled").MustBool(false) diff --git a/public/app/core/config.ts b/public/app/core/config.ts index 3b8a087132c..bf5abe37d7f 100644 --- a/public/app/core/config.ts +++ b/public/app/core/config.ts @@ -22,6 +22,8 @@ export class Settings { disableLoginForm: boolean; defaultDatasource: string; alertingEnabled: boolean; + alertingErrorOrTimeout: string; + alertingNoDataOrNullValues: string; authProxyEnabled: boolean; exploreEnabled: boolean; ldapEnabled: boolean; diff --git a/public/app/features/alerting/alert_tab_ctrl.ts b/public/app/features/alerting/alert_tab_ctrl.ts index ef8e37483cc..53f7e57fd69 100644 --- a/public/app/features/alerting/alert_tab_ctrl.ts +++ b/public/app/features/alerting/alert_tab_ctrl.ts @@ -164,8 +164,8 @@ export class AlertTabCtrl { alert.conditions.push(this.buildDefaultCondition()); } - alert.noDataState = alert.noDataState || 'no_data'; - alert.executionErrorState = alert.executionErrorState || 'alerting'; + alert.noDataState = alert.noDataState || config.alertingNoDataOrNullValues; + alert.executionErrorState = alert.executionErrorState || config.alertingErrorOrTimeout; alert.frequency = alert.frequency || '60s'; alert.handler = alert.handler || 1; alert.notifications = alert.notifications || [];