github.com/outbrain/consul@v1.4.5/agent/structs/check_definition.go (about)

     1  package structs
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/hashicorp/consul/api"
     7  	"github.com/hashicorp/consul/types"
     8  )
     9  
    10  // CheckDefinition is used to JSON decode the Check definitions
    11  type CheckDefinition struct {
    12  	ID        types.CheckID
    13  	Name      string
    14  	Notes     string
    15  	ServiceID string
    16  	Token     string
    17  	Status    string
    18  
    19  	// Copied fields from CheckType without the fields
    20  	// already present in CheckDefinition:
    21  	//
    22  	//   ID (CheckID), Name, Status, Notes
    23  	//
    24  	ScriptArgs                     []string
    25  	HTTP                           string
    26  	Header                         map[string][]string
    27  	Method                         string
    28  	TCP                            string
    29  	Interval                       time.Duration
    30  	DockerContainerID              string
    31  	Shell                          string
    32  	GRPC                           string
    33  	GRPCUseTLS                     bool
    34  	TLSSkipVerify                  bool
    35  	AliasNode                      string
    36  	AliasService                   string
    37  	Timeout                        time.Duration
    38  	TTL                            time.Duration
    39  	DeregisterCriticalServiceAfter time.Duration
    40  }
    41  
    42  func (c *CheckDefinition) HealthCheck(node string) *HealthCheck {
    43  	health := &HealthCheck{
    44  		Node:      node,
    45  		CheckID:   c.ID,
    46  		Name:      c.Name,
    47  		Status:    api.HealthCritical,
    48  		Notes:     c.Notes,
    49  		ServiceID: c.ServiceID,
    50  	}
    51  	if c.Status != "" {
    52  		health.Status = c.Status
    53  	}
    54  	if health.CheckID == "" && health.Name != "" {
    55  		health.CheckID = types.CheckID(health.Name)
    56  	}
    57  	return health
    58  }
    59  
    60  func (c *CheckDefinition) CheckType() *CheckType {
    61  	return &CheckType{
    62  		CheckID: c.ID,
    63  		Name:    c.Name,
    64  		Status:  c.Status,
    65  		Notes:   c.Notes,
    66  
    67  		ScriptArgs:                     c.ScriptArgs,
    68  		AliasNode:                      c.AliasNode,
    69  		AliasService:                   c.AliasService,
    70  		HTTP:                           c.HTTP,
    71  		GRPC:                           c.GRPC,
    72  		GRPCUseTLS:                     c.GRPCUseTLS,
    73  		Header:                         c.Header,
    74  		Method:                         c.Method,
    75  		TCP:                            c.TCP,
    76  		Interval:                       c.Interval,
    77  		DockerContainerID:              c.DockerContainerID,
    78  		Shell:                          c.Shell,
    79  		TLSSkipVerify:                  c.TLSSkipVerify,
    80  		Timeout:                        c.Timeout,
    81  		TTL:                            c.TTL,
    82  		DeregisterCriticalServiceAfter: c.DeregisterCriticalServiceAfter,
    83  	}
    84  }