Minor code cleanups
This commit is contained in:
parent
511c6bcb6a
commit
9b72c10134
|
@ -39,7 +39,7 @@ func CheckConfig(args []string) error {
|
|||
config, _, err := config.LoadFile(arg)
|
||||
if err != nil {
|
||||
fmt.Printf(" FAILED: %s\n", err)
|
||||
failed += 1
|
||||
failed++
|
||||
} else {
|
||||
fmt.Printf(" SUCCESS\n")
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func CheckConfig(args []string) error {
|
|||
_, err = template.FromGlobs(config.Templates...)
|
||||
if err != nil {
|
||||
fmt.Printf(" FAILED: %s\n", err)
|
||||
failed += 1
|
||||
failed++
|
||||
} else {
|
||||
fmt.Printf(" SUCCESS\n")
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ type Formatter interface {
|
|||
}
|
||||
|
||||
// Formatters is a map of cli argument name to formatter inferface object
|
||||
var Formatters map[string]Formatter = map[string]Formatter{}
|
||||
var Formatters = map[string]Formatter{}
|
||||
|
||||
func FormatDate(input time.Time) string {
|
||||
dateformat := viper.GetString("date.format")
|
||||
|
|
|
@ -9,29 +9,29 @@ import (
|
|||
"github.com/prometheus/alertmanager/types"
|
||||
)
|
||||
|
||||
type JsonFormatter struct {
|
||||
type JSONFormatter struct {
|
||||
writer io.Writer
|
||||
}
|
||||
|
||||
func init() {
|
||||
Formatters["json"] = &JsonFormatter{writer: os.Stdout}
|
||||
Formatters["json"] = &JSONFormatter{writer: os.Stdout}
|
||||
}
|
||||
|
||||
func (formatter *JsonFormatter) SetOutput(writer io.Writer) {
|
||||
func (formatter *JSONFormatter) SetOutput(writer io.Writer) {
|
||||
formatter.writer = writer
|
||||
}
|
||||
|
||||
func (formatter *JsonFormatter) FormatSilences(silences []types.Silence) error {
|
||||
func (formatter *JSONFormatter) FormatSilences(silences []types.Silence) error {
|
||||
enc := json.NewEncoder(formatter.writer)
|
||||
return enc.Encode(silences)
|
||||
}
|
||||
|
||||
func (formatter *JsonFormatter) FormatAlerts(alerts []*dispatch.APIAlert) error {
|
||||
func (formatter *JSONFormatter) FormatAlerts(alerts []*dispatch.APIAlert) error {
|
||||
enc := json.NewEncoder(formatter.writer)
|
||||
return enc.Encode(alerts)
|
||||
}
|
||||
|
||||
func (formatter *JsonFormatter) FormatConfig(config Config) error {
|
||||
func (formatter *JSONFormatter) FormatConfig(config Config) error {
|
||||
enc := json.NewEncoder(formatter.writer)
|
||||
return enc.Encode(config)
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ func add(cmd *cobra.Command, args []string) error {
|
|||
return fmt.Errorf("No matchers specified")
|
||||
}
|
||||
|
||||
expire_on, err := addFlags.GetString("expire-on")
|
||||
expireOn, err := addFlags.GetString("expire-on")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -96,8 +96,8 @@ func add(cmd *cobra.Command, args []string) error {
|
|||
expires := viper.GetString("expires")
|
||||
var endsAt time.Time
|
||||
|
||||
if expire_on != "" {
|
||||
endsAt, err = time.Parse(time.RFC3339, expire_on)
|
||||
if expireOn != "" {
|
||||
endsAt, err = time.Parse(time.RFC3339, expireOn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -111,9 +111,9 @@ func add(cmd *cobra.Command, args []string) error {
|
|||
|
||||
author := viper.GetString("author")
|
||||
comment := viper.GetString("comment")
|
||||
comment_required := viper.GetBool("comment_required")
|
||||
commentRequired := viper.GetBool("comment_required")
|
||||
|
||||
if comment_required && comment == "" {
|
||||
if commentRequired && comment == "" {
|
||||
return errors.New("Comment required by config")
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ func add(cmd *cobra.Command, args []string) error {
|
|||
response := addResponse{}
|
||||
err = json.NewDecoder(res.Body).Decode(&response)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("Unable to parse silence json response from %s", u.String()))
|
||||
return fmt.Errorf("Unable to parse silence json response from %s", u.String())
|
||||
}
|
||||
|
||||
if response.Status == "error" {
|
||||
|
|
|
@ -26,9 +26,8 @@ func (s ByAlphabetical) Less(i, j int) bool {
|
|||
return s[i].Type < s[j].Type
|
||||
} else if s[i].Value != s[j].Value {
|
||||
return s[i].Value < s[j].Value
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func GetAlertmanagerURL() (*url.URL, error) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"gopkg.in/yaml.v2"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEmailToIsPresent(t *testing.T) {
|
||||
|
|
|
@ -36,7 +36,7 @@ func (m *Entry) IsResolvedSubset(subset map[uint64]struct{}) bool {
|
|||
}
|
||||
|
||||
func isSubset(set, subset map[uint64]struct{}) bool {
|
||||
for k, _ := range subset {
|
||||
for k := range subset {
|
||||
_, exists := set[k]
|
||||
if !exists {
|
||||
return false
|
||||
|
|
|
@ -981,12 +981,12 @@ func (n *Pushover) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
|
|||
}
|
||||
parameters.Add("message", message)
|
||||
|
||||
supplementaryUrl := tmpl(n.conf.URL)
|
||||
if len(supplementaryUrl) > 512 {
|
||||
supplementaryUrl = supplementaryUrl[:509] + "..."
|
||||
level.Debug(n.logger).Log("msg", "Truncated URL due to Pushover url limit", "truncated_url", supplementaryUrl, "incident", key)
|
||||
supplementaryURL := tmpl(n.conf.URL)
|
||||
if len(supplementaryURL) > 512 {
|
||||
supplementaryURL = supplementaryURL[:509] + "..."
|
||||
level.Debug(n.logger).Log("msg", "Truncated URL due to Pushover url limit", "truncated_url", supplementaryURL, "incident", key)
|
||||
}
|
||||
parameters.Add("url", supplementaryUrl)
|
||||
parameters.Add("url", supplementaryURL)
|
||||
|
||||
parameters.Add("priority", tmpl(n.conf.Priority))
|
||||
parameters.Add("retry", fmt.Sprintf("%d", int64(time.Duration(n.conf.Retry).Seconds())))
|
||||
|
|
|
@ -536,7 +536,7 @@ func (n *DedupStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Al
|
|||
case 1:
|
||||
entry = entries[0]
|
||||
case 2:
|
||||
return ctx, nil, fmt.Errorf("Unexpected entry result size %d", len(entries))
|
||||
return ctx, nil, fmt.Errorf("unexpected entry result size %d", len(entries))
|
||||
}
|
||||
if ok, err := n.needsUpdate(entry, firingSet, resolvedSet, repeatInterval); err != nil {
|
||||
return ctx, nil, err
|
||||
|
@ -588,7 +588,7 @@ func (r RetryStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Ale
|
|||
numFailedNotifications.WithLabelValues(r.integration.name).Inc()
|
||||
level.Debug(l).Log("msg", "Notify attempt failed", "attempt", i, "integration", r.integration.name, "err", err)
|
||||
if !retry {
|
||||
return ctx, alerts, fmt.Errorf("Cancelling notify retry for %q due to unrecoverable error: %s", r.integration.name, err)
|
||||
return ctx, alerts, fmt.Errorf("cancelling notify retry for %q due to unrecoverable error: %s", r.integration.name, err)
|
||||
}
|
||||
|
||||
// Save this error to be able to return the last seen error by an
|
||||
|
|
|
@ -82,7 +82,7 @@ func (m *memMarker) Count(states ...AlertState) int {
|
|||
for _, status := range m.m {
|
||||
for _, state := range states {
|
||||
if status.State == state {
|
||||
count += 1
|
||||
count++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue