2014-01-08 21:52:09 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
2014-01-08 21:56:34 +00:00
|
|
|
"fmt"
|
2014-01-08 21:52:09 +00:00
|
|
|
"github.com/hashicorp/consul/consul/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Health endpoint is used to query the health information
|
|
|
|
type Health struct {
|
|
|
|
srv *Server
|
|
|
|
}
|
|
|
|
|
|
|
|
// ChecksInState is used to get all the checks in a given state
|
|
|
|
func (h *Health) ChecksInState(args *structs.ChecksInStateRequest,
|
|
|
|
reply *structs.HealthChecks) error {
|
|
|
|
if done, err := h.srv.forward("Health.ChecksInState", args.Datacenter, args, reply); done {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-01-08 21:56:34 +00:00
|
|
|
// Get the state specific checks
|
|
|
|
state := h.srv.fsm.State()
|
|
|
|
checks := state.ChecksInState(args.State)
|
|
|
|
*reply = checks
|
2014-01-08 21:52:09 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NodeChecks is used to get all the checks for a node
|
|
|
|
func (h *Health) NodeChecks(args *structs.NodeSpecificRequest,
|
|
|
|
reply *structs.HealthChecks) error {
|
|
|
|
if done, err := h.srv.forward("Health.NodeChecks", args.Datacenter, args, reply); done {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-01-08 21:56:34 +00:00
|
|
|
// Get the node checks
|
|
|
|
state := h.srv.fsm.State()
|
|
|
|
checks := state.NodeChecks(args.Node)
|
|
|
|
*reply = checks
|
2014-01-08 21:52:09 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServiceChecks is used to get all the checks for a service
|
|
|
|
func (h *Health) ServiceChecks(args *structs.ServiceSpecificRequest,
|
|
|
|
reply *structs.HealthChecks) error {
|
2014-01-08 21:56:34 +00:00
|
|
|
// Reject if tag filtering is on
|
|
|
|
if args.TagFilter {
|
|
|
|
return fmt.Errorf("Tag filtering is not supported")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Potentially forward
|
2014-01-08 21:52:09 +00:00
|
|
|
if done, err := h.srv.forward("Health.ServiceChecks", args.Datacenter, args, reply); done {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-01-08 21:56:34 +00:00
|
|
|
// Get the service checks
|
|
|
|
state := h.srv.fsm.State()
|
|
|
|
checks := state.ServiceChecks(args.ServiceName)
|
|
|
|
*reply = checks
|
2014-01-08 21:52:09 +00:00
|
|
|
return nil
|
|
|
|
}
|
2014-01-08 23:06:13 +00:00
|
|
|
|
|
|
|
// ServiceNodes returns all the nodes registered as part of a service including health info
|
|
|
|
func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *structs.CheckServiceNodes) error {
|
|
|
|
if done, err := h.srv.forward("Health.ServiceNodes", args.Datacenter, args, reply); done {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify the arguments
|
|
|
|
if args.ServiceName == "" {
|
|
|
|
return fmt.Errorf("Must provide service name")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the nodes
|
|
|
|
state := h.srv.fsm.State()
|
|
|
|
var nodes structs.CheckServiceNodes
|
|
|
|
if args.TagFilter {
|
|
|
|
nodes = state.CheckServiceTagNodes(args.ServiceName, args.ServiceTag)
|
|
|
|
} else {
|
|
|
|
nodes = state.CheckServiceNodes(args.ServiceName)
|
|
|
|
}
|
|
|
|
|
|
|
|
*reply = nodes
|
|
|
|
return nil
|
|
|
|
}
|