Skip to content

Commit

Permalink
use smarter err
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuto committed Dec 21, 2023
1 parent 6e24bb6 commit 2735985
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions checkmackerelmetric/checkmackerelmetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ func (opts *mackerelMetricOpts) run() *checkers.Checker {
newpath := filepath.Join(config.DefaultConfig.Conffile, "../../../mackerel-agent.conf")
conf, err = config.LoadConfig(newpath)
if err != nil {
return checkers.Unknown(fmt.Sprintf("%v", err))
return checkers.Unknown(err.Error())
}
conf.Conffile = newpath
conf.Root = filepath.Dir(newpath)
} else {
return checkers.Unknown(fmt.Sprintf("%v", err))
return checkers.Unknown(err.Error())
}
}
apibase := conf.Apibase
Expand All @@ -113,7 +113,7 @@ func (opts *mackerelMetricOpts) run() *checkers.Checker {

client, err := mackerel.NewClientWithOptions(apikey, apibase, false)
if err != nil {
return checkers.Unknown(fmt.Sprintf("%v", err))
return checkers.Unknown(err.Error())
}

return checkMetric(client, opts, criticalFrom, warningFrom, to)
Expand All @@ -125,7 +125,7 @@ func checkMetric(client *mackerel.Client, opts *mackerelMetricOpts, criticalFrom
// CRITICAL check
metricValue, err := fetchMetricValues(client, opts.Host, opts.Service, opts.Metric, criticalFrom, to)
if err != nil {
return checkers.Unknown(fmt.Sprintf("%v", err))
return checkers.Unknown(err.Error())
}
if len(metricValue) == 0 {
return checkers.Critical(fmt.Sprintf("no metric for %s has been posted since at least %d minutes ago", opts.Metric, opts.Critical))
Expand Down

0 comments on commit 2735985

Please sign in to comment.