2016-06-11 03:13:33 -05:00
package alerting
import (
2021-11-12 07:35:38 -06:00
"context"
2019-01-10 02:35:48 -06:00
"errors"
2016-06-11 03:13:33 -05:00
"fmt"
2021-04-12 07:53:51 -05:00
"reflect"
2016-06-13 03:40:46 -05:00
"regexp"
"strconv"
2018-11-01 10:04:38 -05:00
"time"
2016-06-11 03:13:33 -05:00
"github.com/grafana/grafana/pkg/components/simplejson"
2019-05-14 01:15:05 -05:00
"github.com/grafana/grafana/pkg/models"
2022-09-21 07:04:01 -05:00
"github.com/grafana/grafana/pkg/services/tag"
2016-06-11 03:13:33 -05:00
)
2021-04-12 07:53:51 -05:00
var unitMultiplier = map [ string ] int {
"s" : 1 ,
"m" : 60 ,
"h" : 3600 ,
"d" : 86400 ,
}
var (
valueFormatRegex = regexp . MustCompile ( ` ^\d+ ` )
isDigitRegex = regexp . MustCompile ( ` ^[0-9]+$ ` )
unitFormatRegex = regexp . MustCompile ( ` [a-z]+ ` )
)
2019-01-10 02:35:48 -06:00
var (
2019-05-20 05:13:32 -05:00
// ErrFrequencyCannotBeZeroOrLess frequency cannot be below zero
2019-01-10 02:35:48 -06:00
ErrFrequencyCannotBeZeroOrLess = errors . New ( ` "evaluate every" cannot be zero or below ` )
2019-05-20 05:13:32 -05:00
// ErrFrequencyCouldNotBeParsed frequency cannot be parsed
ErrFrequencyCouldNotBeParsed = errors . New ( ` "evaluate every" field could not be parsed ` )
2021-04-12 07:53:51 -05:00
// ErrWrongUnitFormat wrong unit format
ErrWrongUnitFormat = fmt . Errorf ( ` time unit not supported. supported units: %s ` , reflect . ValueOf ( unitMultiplier ) . MapKeys ( ) )
2019-01-10 02:35:48 -06:00
)
2019-05-20 05:13:32 -05:00
// Rule is the in-memory version of an alert rule.
2016-07-27 09:29:28 -05:00
type Rule struct {
2019-06-03 03:25:58 -05:00
ID int64
OrgID int64
DashboardID int64
PanelID int64
2016-11-04 05:28:12 -05:00
Frequency int64
Name string
Message string
2018-11-01 10:04:38 -05:00
LastStateChange time . Time
2018-11-05 04:05:30 -06:00
For time . Duration
2019-05-14 01:15:05 -05:00
NoDataState models . NoDataOption
ExecutionErrorState models . ExecutionErrorOption
State models . AlertStateType
2016-11-04 05:28:12 -05:00
Conditions [ ] Condition
2018-12-14 03:53:50 -06:00
Notifications [ ] string
2022-09-21 07:04:01 -05:00
AlertRuleTags [ ] * tag . Tag
2018-10-01 07:13:03 -05:00
StateChanges int64
2016-07-19 09:15:26 -05:00
}
2019-05-20 05:13:32 -05:00
// ValidationError is a typed error with meta data
// about the validation error.
2016-07-27 09:29:28 -05:00
type ValidationError struct {
2016-11-15 04:47:44 -06:00
Reason string
Err error
2019-06-03 03:25:58 -05:00
AlertID int64
DashboardID int64
PanelID int64
2016-07-21 06:09:12 -05:00
}
2016-07-27 09:29:28 -05:00
func ( e ValidationError ) Error ( ) string {
2018-10-13 00:53:28 -05:00
extraInfo := e . Reason
2019-06-03 03:25:58 -05:00
if e . AlertID != 0 {
extraInfo = fmt . Sprintf ( "%s AlertId: %v" , extraInfo , e . AlertID )
2016-11-15 04:47:44 -06:00
}
2019-06-03 03:25:58 -05:00
if e . PanelID != 0 {
extraInfo = fmt . Sprintf ( "%s PanelId: %v" , extraInfo , e . PanelID )
2016-11-15 04:47:44 -06:00
}
2019-06-03 03:25:58 -05:00
if e . DashboardID != 0 {
extraInfo = fmt . Sprintf ( "%s DashboardId: %v" , extraInfo , e . DashboardID )
2016-11-15 04:47:44 -06:00
}
if e . Err != nil {
2020-07-31 02:45:20 -05:00
return fmt . Sprintf ( "alert validation error: %s%s" , e . Err . Error ( ) , extraInfo )
2016-11-15 04:47:44 -06:00
}
2020-07-31 02:45:20 -05:00
return fmt . Sprintf ( "alert validation error: %s" , extraInfo )
2016-07-21 06:09:12 -05:00
}
2021-04-12 07:53:51 -05:00
func getTimeDurationStringToSeconds ( str string ) ( int64 , error ) {
// Check if frequency lacks unit
if isDigitRegex . MatchString ( str ) || str == "" {
return 0 , ErrFrequencyCouldNotBeParsed
}
2016-06-13 03:40:46 -05:00
2021-04-12 07:53:51 -05:00
unit := unitFormatRegex . FindAllString ( str , 1 ) [ 0 ]
if _ , ok := unitMultiplier [ unit ] ; ! ok {
return 0 , ErrWrongUnitFormat
}
2016-06-13 03:40:46 -05:00
2021-04-12 07:53:51 -05:00
multiplier := unitMultiplier [ unit ]
2016-06-13 03:40:46 -05:00
2019-05-20 05:13:32 -05:00
matches := valueFormatRegex . FindAllString ( str , 1 )
2016-10-11 10:36:30 -05:00
2020-07-16 07:39:01 -05:00
if len ( matches ) == 0 {
2019-01-10 02:35:48 -06:00
return 0 , ErrFrequencyCouldNotBeParsed
2016-10-11 10:36:30 -05:00
}
value , err := strconv . Atoi ( matches [ 0 ] )
if err != nil {
return 0 , err
}
2019-01-10 02:35:48 -06:00
if value == 0 {
return 0 , ErrFrequencyCannotBeZeroOrLess
}
2021-04-12 07:53:51 -05:00
return int64 ( value * multiplier ) , nil
}
2016-06-13 03:40:46 -05:00
2021-04-12 07:53:51 -05:00
func getForValue ( rawFor string ) ( time . Duration , error ) {
var forValue time . Duration
var err error
if rawFor != "" {
if rawFor != "0" {
strings := unitFormatRegex . FindAllString ( rawFor , 1 )
if strings == nil {
return 0 , ValidationError { Reason : fmt . Sprintf ( "no specified unit, error: %s" , ErrWrongUnitFormat . Error ( ) ) }
}
if _ , ok := unitMultiplier [ strings [ 0 ] ] ; ! ok {
return 0 , ValidationError { Reason : fmt . Sprintf ( "could not parse for field, error: %s" , ErrWrongUnitFormat . Error ( ) ) }
}
}
forValue , err = time . ParseDuration ( rawFor )
if err != nil {
return 0 , ValidationError { Reason : "Could not parse for field" }
}
2016-06-13 03:40:46 -05:00
}
2021-04-12 07:53:51 -05:00
return forValue , nil
2016-06-11 15:33:02 -05:00
}
2020-06-01 10:11:25 -05:00
// NewRuleFromDBAlert maps a db version of
2019-05-20 05:13:32 -05:00
// alert to an in-memory version.
2022-04-08 07:30:25 -05:00
func NewRuleFromDBAlert ( ctx context . Context , store AlertStore , ruleDef * models . Alert , logTranslationFailures bool ) ( * Rule , error ) {
2016-07-27 09:29:28 -05:00
model := & Rule { }
2019-06-03 03:25:58 -05:00
model . ID = ruleDef . Id
model . OrgID = ruleDef . OrgId
model . DashboardID = ruleDef . DashboardId
model . PanelID = ruleDef . PanelId
2016-06-11 03:13:33 -05:00
model . Name = ruleDef . Name
2016-08-12 03:12:04 -05:00
model . Message = ruleDef . Message
2016-07-22 06:14:09 -05:00
model . State = ruleDef . State
2018-11-01 10:04:38 -05:00
model . LastStateChange = ruleDef . NewStateDate
2018-11-05 04:05:30 -06:00
model . For = ruleDef . For
2019-05-14 01:15:05 -05:00
model . NoDataState = models . NoDataOption ( ruleDef . Settings . Get ( "noDataState" ) . MustString ( "no_data" ) )
model . ExecutionErrorState = models . ExecutionErrorOption ( ruleDef . Settings . Get ( "executionErrorState" ) . MustString ( "alerting" ) )
2018-10-02 04:19:09 -05:00
model . StateChanges = ruleDef . StateChanges
2016-06-11 03:13:33 -05:00
2019-01-10 02:35:48 -06:00
model . Frequency = ruleDef . Frequency
// frequency cannot be zero since that would not execute the alert rule.
2020-06-01 10:11:25 -05:00
// so we fallback to 60 seconds if `Frequency` is missing
2019-01-10 02:35:48 -06:00
if model . Frequency == 0 {
model . Frequency = 60
}
2016-07-19 09:15:26 -05:00
for _ , v := range ruleDef . Settings . Get ( "notifications" ) . MustArray ( ) {
2016-07-26 05:29:52 -05:00
jsonModel := simplejson . NewFromAny ( v )
2018-12-20 09:12:47 -06:00
if id , err := jsonModel . Get ( "id" ) . Int64 ( ) ; err == nil {
2022-04-08 07:30:25 -05:00
uid , err := translateNotificationIDToUID ( ctx , store , id , ruleDef . OrgId )
2019-04-23 03:24:47 -05:00
if err != nil {
2020-10-22 06:43:12 -05:00
if ! errors . Is ( err , models . ErrAlertNotificationFailedTranslateUniqueID ) {
2021-01-21 02:17:46 -06:00
logger . Error ( "Failed to translate notification id to uid" , "error" , err . Error ( ) , "dashboardId" , model . DashboardID , "alert" , model . Name , "panelId" , model . PanelID , "notificationId" , id )
2020-10-22 06:43:12 -05:00
}
if logTranslationFailures {
logger . Warn ( "Unable to translate notification id to uid" , "dashboardId" , model . DashboardID , "alert" , model . Name , "panelId" , model . PanelID , "notificationId" , id )
}
2020-06-02 11:33:13 -05:00
} else {
model . Notifications = append ( model . Notifications , uid )
2018-12-20 09:12:47 -06:00
}
2020-03-18 08:00:56 -05:00
} else if uid , err := jsonModel . Get ( "uid" ) . String ( ) ; err == nil {
model . Notifications = append ( model . Notifications , uid )
} else {
return nil , ValidationError { Reason : "Neither id nor uid is specified in 'notifications' block, " + err . Error ( ) , DashboardID : model . DashboardID , AlertID : model . ID , PanelID : model . PanelID }
2016-06-23 09:07:23 -05:00
}
}
2019-06-06 06:29:30 -05:00
model . AlertRuleTags = ruleDef . GetTagsFromSettings ( )
2016-06-23 09:07:23 -05:00
2016-07-21 14:54:12 -05:00
for index , condition := range ruleDef . Settings . Get ( "conditions" ) . MustArray ( ) {
2016-07-19 09:15:26 -05:00
conditionModel := simplejson . NewFromAny ( condition )
2016-07-27 09:18:10 -05:00
conditionType := conditionModel . Get ( "type" ) . MustString ( )
Outdent code after if block that ends with return (golint)
This commit fixes the following golint warnings:
pkg/bus/bus.go:64:9: if block ends with a return statement, so drop this else and outdent its block
pkg/bus/bus.go:84:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:137:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:177:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:183:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:199:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:208:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/components/dynmap/dynmap.go:236:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:242:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:257:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:263:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:278:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:284:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:299:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:331:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:350:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:356:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:366:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:390:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:396:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:405:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:427:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:433:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:442:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:459:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:465:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:474:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:491:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:497:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:506:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:523:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:529:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:538:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:555:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:561:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:570:12: if block ends with a return statement, so drop this else and outdent its block
pkg/login/ldap.go:55:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/login/ldap_test.go:372:10: if block ends with a return statement, so drop this else and outdent its block
pkg/middleware/middleware_test.go:213:12: if block ends with a return statement, so drop this else and outdent its block
pkg/plugins/dashboard_importer.go:153:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:39:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:121:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:210:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:235:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/eval_context.go:111:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:92:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:98:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:122:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:108:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:118:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:121:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifiers/telegram.go:94:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/annotation.go:34:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/annotation.go:99:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/dashboard_test.go:107:13: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/plugin_setting.go:78:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/preferences.go:91:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/user.go:50:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/migrator/migrator.go:106:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/migrator/postgres_dialect.go:48:10: if block ends with a return statement, so drop this else and outdent its block
pkg/tsdb/time_range.go:59:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/time_range.go:67:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/cloudwatch/metric_find_query.go:225:9: if block ends with a return statement, so drop this else and outdent its block
pkg/util/filepath.go:68:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
2018-04-27 15:42:49 -05:00
factory , exist := conditionFactories [ conditionType ]
if ! exist {
2019-06-03 03:25:58 -05:00
return nil , ValidationError { Reason : "Unknown alert condition: " + conditionType , DashboardID : model . DashboardID , AlertID : model . ID , PanelID : model . PanelID }
2016-07-19 09:15:26 -05:00
}
Outdent code after if block that ends with return (golint)
This commit fixes the following golint warnings:
pkg/bus/bus.go:64:9: if block ends with a return statement, so drop this else and outdent its block
pkg/bus/bus.go:84:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:137:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:177:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:183:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:199:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:208:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/components/dynmap/dynmap.go:236:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:242:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:257:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:263:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:278:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:284:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:299:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:331:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:350:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:356:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:366:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:390:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:396:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:405:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:427:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:433:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:442:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:459:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:465:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:474:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:491:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:497:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:506:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:523:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:529:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:538:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:555:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:561:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:570:12: if block ends with a return statement, so drop this else and outdent its block
pkg/login/ldap.go:55:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/login/ldap_test.go:372:10: if block ends with a return statement, so drop this else and outdent its block
pkg/middleware/middleware_test.go:213:12: if block ends with a return statement, so drop this else and outdent its block
pkg/plugins/dashboard_importer.go:153:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:39:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:121:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:210:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:235:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/eval_context.go:111:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:92:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:98:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:122:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:108:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:118:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:121:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifiers/telegram.go:94:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/annotation.go:34:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/annotation.go:99:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/dashboard_test.go:107:13: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/plugin_setting.go:78:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/preferences.go:91:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/user.go:50:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/migrator/migrator.go:106:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/migrator/postgres_dialect.go:48:10: if block ends with a return statement, so drop this else and outdent its block
pkg/tsdb/time_range.go:59:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/time_range.go:67:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/cloudwatch/metric_find_query.go:225:9: if block ends with a return statement, so drop this else and outdent its block
pkg/util/filepath.go:68:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
2018-04-27 15:42:49 -05:00
queryCondition , err := factory ( conditionModel , index )
if err != nil {
2019-06-03 03:25:58 -05:00
return nil , ValidationError { Err : err , DashboardID : model . DashboardID , AlertID : model . ID , PanelID : model . PanelID }
Outdent code after if block that ends with return (golint)
This commit fixes the following golint warnings:
pkg/bus/bus.go:64:9: if block ends with a return statement, so drop this else and outdent its block
pkg/bus/bus.go:84:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:137:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:177:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:183:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:199:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:208:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/components/dynmap/dynmap.go:236:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:242:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:257:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:263:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:278:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:284:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:299:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:331:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:350:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:356:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:366:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:390:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:396:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:405:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:427:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:433:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:442:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:459:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:465:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:474:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:491:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:497:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:506:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:523:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:529:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:538:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:555:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:561:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:570:12: if block ends with a return statement, so drop this else and outdent its block
pkg/login/ldap.go:55:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/login/ldap_test.go:372:10: if block ends with a return statement, so drop this else and outdent its block
pkg/middleware/middleware_test.go:213:12: if block ends with a return statement, so drop this else and outdent its block
pkg/plugins/dashboard_importer.go:153:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:39:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:121:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:210:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:235:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/eval_context.go:111:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:92:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:98:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:122:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:108:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:118:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:121:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifiers/telegram.go:94:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/annotation.go:34:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/annotation.go:99:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/dashboard_test.go:107:13: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/plugin_setting.go:78:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/preferences.go:91:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/user.go:50:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/migrator/migrator.go:106:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/migrator/postgres_dialect.go:48:10: if block ends with a return statement, so drop this else and outdent its block
pkg/tsdb/time_range.go:59:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/time_range.go:67:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/cloudwatch/metric_find_query.go:225:9: if block ends with a return statement, so drop this else and outdent its block
pkg/util/filepath.go:68:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
2018-04-27 15:42:49 -05:00
}
model . Conditions = append ( model . Conditions , queryCondition )
2016-06-11 03:13:33 -05:00
}
2016-07-19 09:15:26 -05:00
if len ( model . Conditions ) == 0 {
2018-10-13 01:15:23 -05:00
return nil , ValidationError { Reason : "Alert is missing conditions" }
2016-06-11 03:13:33 -05:00
}
return model , nil
}
2016-07-27 09:18:10 -05:00
2022-04-08 07:30:25 -05:00
func translateNotificationIDToUID ( ctx context . Context , store AlertStore , id int64 , orgID int64 ) ( string , error ) {
notificationUID , err := getAlertNotificationUIDByIDAndOrgID ( ctx , store , id , orgID )
2020-03-18 08:00:56 -05:00
if err != nil {
return "" , err
}
2020-04-16 09:09:27 -05:00
return notificationUID , nil
2020-03-18 08:00:56 -05:00
}
2022-04-08 07:30:25 -05:00
func getAlertNotificationUIDByIDAndOrgID ( ctx context . Context , store AlertStore , notificationID int64 , orgID int64 ) ( string , error ) {
2020-03-18 08:00:56 -05:00
query := & models . GetAlertNotificationUidQuery {
OrgId : orgID ,
Id : notificationID ,
}
2022-04-08 07:30:25 -05:00
if err := store . GetAlertNotificationUidWithId ( ctx , query ) ; err != nil {
2020-03-18 08:00:56 -05:00
return "" , err
}
return query . Result , nil
}
2019-05-20 05:13:32 -05:00
// ConditionFactory is the function signature for creating `Conditions`.
2016-07-27 09:29:28 -05:00
type ConditionFactory func ( model * simplejson . Json , index int ) ( Condition , error )
2016-07-27 09:18:10 -05:00
2018-04-27 15:14:36 -05:00
var conditionFactories = make ( map [ string ] ConditionFactory )
2016-07-27 09:18:10 -05:00
2019-05-20 05:13:32 -05:00
// RegisterCondition adds support for alerting conditions.
2016-07-27 09:18:10 -05:00
func RegisterCondition ( typeName string , factory ConditionFactory ) {
conditionFactories [ typeName ] = factory
}