Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuto committed Nov 6, 2023
2 parents 2aa3713 + d129f3e commit acd381e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ before:
builds:
- env:
- CGO_ENABLED=0
- PACKAGE_PATH=github.com/mackerelio-labs/check-mackerel-metric/checkmackerelmetric
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
ldflags:
- -s -w
- -X {{ .Env.PACKAGE_PATH }}.version={{ .Version }}
- -X {{ .Env.PACKAGE_PATH }}.revision={{ .ShortCommit }}

archives:
- format: zip
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ command = ["check-mackerel-metric", "-s", "SERVICE_NAME", "-n", "METRIC_NAME", "
- `--critical MINUTE, -c MINUTE`: minute to be CRITICAL (MINUTE: 1-1441)
- `--status-as STATUS=NEWSTATUS,[STATUS=NEWSTATUS,...]`: override the status
- `--help, -h`: display the help and exit
- `--version`: display version and exit
- `--host` is for host metrics and `--service` is for service metrics. Choose one of these.
- HOST_ID is displayed at the top of the Mackerel host screen, like `4Hkc5RWzXXX`.
- METRIC_NAME can be looked up with `mkr metric-names -H HOST_ID`.
Expand Down Expand Up @@ -97,6 +98,7 @@ command = ["check-mackerel-metric", "-s", "SERVICE_NAME", "-n", "METRIC_NAME", "
- `--critical MINUTE, -c MINUTE`: 指定の分数内にメトリックがなければCRITICAL(MINUTEは1〜1441)
- `--status-as STATUS=NEWSTATUS,[STATUS=NEWSTATUS,...]`: 状態の書き換え
- `--help, -h`: ヘルプの表示と終了
- `--version`: バージョンの表示と終了
- `--host`はホストメトリック用、`--service`はサービスメトリック用です。どちらか1つを選んでください。
- HOST_ID (ホストID) はMackerelのホスト画面の上部に `4Hkc5RWzXXX` のように表示されています。
- METRIC_NAME (メトリック名) は `mkr metric-names -H HOST_ID` で調べることができます。
Expand Down
16 changes: 13 additions & 3 deletions checkmackerelmetric/checkmackerelmetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ type mackerelMetricOpts struct {
StatusAs string `arg:"--status-as" help:"overwrite status=new_status, support multiple comma separates"`
}

var version string
var revision string

func (mackerelMetricOpts) Version() string {
return fmt.Sprintf("version %s (rev %s)", version, revision)
}

func Do() {
opts, maps, err := parseArgs(os.Args[1:])
if err != nil {
Expand All @@ -39,11 +46,14 @@ func parseArgs(args []string) (*mackerelMetricOpts, map[checkers.Status]checkers
p, _ := arg.NewParser(arg.Config{}, &mo)
err := p.Parse(args)

if err == arg.ErrHelp {
switch {
case err == arg.ErrHelp:
p.WriteHelp(os.Stdout)
os.Exit(0)
}
if err != nil {
case err == arg.ErrVersion:
fmt.Println(mo.Version())
os.Exit(0)
case err != nil:
return &mo, nil, err
}

Expand Down

0 comments on commit acd381e

Please sign in to comment.