2017-06-15 18:46:06 +02:00
|
|
|
package structs
|
2014-01-30 15:35:38 -08:00
|
|
|
|
2014-02-03 15:15:35 -08:00
|
|
|
import (
|
2017-05-15 21:49:13 +02:00
|
|
|
"time"
|
|
|
|
|
2017-04-19 16:00:11 -07:00
|
|
|
"github.com/hashicorp/consul/api"
|
2016-06-06 13:19:31 -07:00
|
|
|
"github.com/hashicorp/consul/types"
|
2014-02-03 15:15:35 -08:00
|
|
|
)
|
|
|
|
|
2016-06-07 15:24:51 -05:00
|
|
|
// CheckDefinition is used to JSON decode the Check definitions
|
2014-01-30 15:35:38 -08:00
|
|
|
type CheckDefinition struct {
|
2016-06-06 13:19:31 -07:00
|
|
|
ID types.CheckID
|
2014-02-03 15:15:35 -08:00
|
|
|
Name string
|
|
|
|
Notes string
|
2015-01-13 17:52:17 -08:00
|
|
|
ServiceID string
|
2015-04-28 12:44:46 -07:00
|
|
|
Token string
|
2015-04-12 00:53:48 +00:00
|
|
|
Status string
|
2017-05-15 21:49:13 +02:00
|
|
|
|
|
|
|
// Copied fields from CheckType without the fields
|
|
|
|
// already present in CheckDefinition:
|
|
|
|
//
|
|
|
|
// ID (CheckID), Name, Status, Notes
|
|
|
|
//
|
2017-10-04 16:48:00 -07:00
|
|
|
ScriptArgs []string
|
2017-05-15 21:49:13 +02:00
|
|
|
HTTP string
|
2017-06-07 01:11:56 +02:00
|
|
|
Header map[string][]string
|
|
|
|
Method string
|
2017-05-15 21:49:13 +02:00
|
|
|
TCP string
|
|
|
|
Interval time.Duration
|
|
|
|
DockerContainerID string
|
|
|
|
Shell string
|
2017-12-26 23:35:22 -05:00
|
|
|
GRPC string
|
2018-02-02 17:29:34 -08:00
|
|
|
GRPCUseTLS bool
|
2017-05-15 21:49:13 +02:00
|
|
|
TLSSkipVerify bool
|
2018-06-29 23:09:58 -07:00
|
|
|
AliasNode string
|
|
|
|
AliasService string
|
2017-05-15 21:49:13 +02:00
|
|
|
Timeout time.Duration
|
|
|
|
TTL time.Duration
|
|
|
|
DeregisterCriticalServiceAfter time.Duration
|
2019-06-26 17:43:25 +02:00
|
|
|
OutputMaxSize int
|
2014-01-30 15:35:38 -08:00
|
|
|
}
|
|
|
|
|
2017-06-15 18:46:06 +02:00
|
|
|
func (c *CheckDefinition) HealthCheck(node string) *HealthCheck {
|
|
|
|
health := &HealthCheck{
|
2015-01-13 17:52:17 -08:00
|
|
|
Node: node,
|
|
|
|
CheckID: c.ID,
|
|
|
|
Name: c.Name,
|
2017-04-19 16:00:11 -07:00
|
|
|
Status: api.HealthCritical,
|
2015-01-13 17:52:17 -08:00
|
|
|
Notes: c.Notes,
|
|
|
|
ServiceID: c.ServiceID,
|
2014-02-03 15:15:35 -08:00
|
|
|
}
|
2015-04-12 00:53:48 +00:00
|
|
|
if c.Status != "" {
|
|
|
|
health.Status = c.Status
|
|
|
|
}
|
2014-02-03 15:15:35 -08:00
|
|
|
if health.CheckID == "" && health.Name != "" {
|
2016-06-06 13:19:31 -07:00
|
|
|
health.CheckID = types.CheckID(health.Name)
|
2014-02-03 15:15:35 -08:00
|
|
|
}
|
|
|
|
return health
|
2014-01-30 15:35:38 -08:00
|
|
|
}
|
2015-04-27 19:01:02 -07:00
|
|
|
|
2017-05-15 21:49:13 +02:00
|
|
|
func (c *CheckDefinition) CheckType() *CheckType {
|
|
|
|
return &CheckType{
|
2017-06-23 01:15:48 -07:00
|
|
|
CheckID: c.ID,
|
|
|
|
Name: c.Name,
|
|
|
|
Status: c.Status,
|
|
|
|
Notes: c.Notes,
|
|
|
|
|
2018-11-07 02:16:03 -08:00
|
|
|
ScriptArgs: c.ScriptArgs,
|
|
|
|
AliasNode: c.AliasNode,
|
|
|
|
AliasService: c.AliasService,
|
|
|
|
HTTP: c.HTTP,
|
|
|
|
GRPC: c.GRPC,
|
|
|
|
GRPCUseTLS: c.GRPCUseTLS,
|
|
|
|
Header: c.Header,
|
|
|
|
Method: c.Method,
|
2019-06-26 17:43:25 +02:00
|
|
|
OutputMaxSize: c.OutputMaxSize,
|
2018-11-07 02:16:03 -08:00
|
|
|
TCP: c.TCP,
|
|
|
|
Interval: c.Interval,
|
|
|
|
DockerContainerID: c.DockerContainerID,
|
|
|
|
Shell: c.Shell,
|
|
|
|
TLSSkipVerify: c.TLSSkipVerify,
|
|
|
|
Timeout: c.Timeout,
|
|
|
|
TTL: c.TTL,
|
2017-05-15 21:49:13 +02:00
|
|
|
DeregisterCriticalServiceAfter: c.DeregisterCriticalServiceAfter,
|
|
|
|
}
|
|
|
|
}
|