Skip to content

Commit

Permalink
Merge ad52d89 into aa113af
Browse files Browse the repository at this point in the history
  • Loading branch information
yuuki committed Oct 18, 2018
2 parents aa113af + ad52d89 commit 9262a11
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions check-redis/lib/check-redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ type redisSetting struct {
}

var commands = map[string](func([]string) *checkers.Checker){
"reachable": checkReachable,
"slave": checkSlave,
"reachable": checkReachable,
"replication": checkReplication,
"slave": checkSlave, // deprecated command
}

func separateSub(argv []string) (string, []string) {
Expand Down Expand Up @@ -135,10 +136,59 @@ func checkReachable(args []string) *checkers.Checker {
)
}

type replicationOpts struct {
redisSetting
SkipMaster bool `long:"skip-master" description:"return ok if redis role is master"`
}

func checkReplication(args []string) *checkers.Checker {
opts := replicationOpts{}
psr := flags.NewParser(&opts, flags.Default)
psr.Usage = "replication [OPTIONS]"
_, err := psr.ParseArgs(args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

c, info, err := connectRedisGetInfo(opts.redisSetting)
if err != nil {
return checkers.Unknown(err.Error())
}
defer c.Close()

if role, ok := (*info)["role"]; ok {
if role != "slave" && opts.SkipMaster {
return checkers.Ok("role is not slave")
}
} else {
return checkers.Unknown("couldn't get role")
}

if status, ok := (*info)["master_link_status"]; ok {
msg := fmt.Sprintf("master_link_status: %s", status)

switch status {
case "up":
return checkers.Ok(msg)
case "down":
return checkers.Critical(msg)
default:
return checkers.Unknown(msg)
}

} else {
return checkers.Unknown("couldn't get master_link_status")
}
}

// Deprecated: For backward compatibility.
func checkSlave(args []string) *checkers.Checker {
opts := redisSetting{}
psr := flags.NewParser(&opts, flags.Default)
psr.Usage = "slave [OPTIONS]"
psr.Usage = `slave [OPTIONS]
DEPRECATED: For backward compatibility. Use 'replication' command.`
_, err := psr.ParseArgs(args)
if err != nil {
fmt.Println(err)
Expand Down

0 comments on commit 9262a11

Please sign in to comment.