2 Protocol Checkers
Leon Schmidt edited this page 2023-10-04 12:59:21 +02:00

The keys under the "services" object are the service names. They can be chosen freely and are displayed in the API response. Under every service, there must be another JSON object containing the "friendy_url" and "protocol" keys. The friendly URL is always displayed in the API response. The protocol must be set to one of the registered checkers (e.g. "http").

Some protocols allow setting protocol specific options via the "protocol_config" key. This key is also optional and will be populated with the protocols defaults if not provided.

Keep in mind that it is not checked whether the contents of "protocol_config" are well-formed and have the correct types. Please read the protocol specific options carefully to prevent unexpected behavior!

The protocol specific options can be looked up below.

Protocol module list

Adding protocol checkers

To add a protocol checkers, create a go file in server/protocols/checkers with a struct implementing the following interface:

type Checker interface {
  Check(name string, config *structs.ServiceConfig) (structs.CheckResult, error)
}

If you want to implement a function that validates the configuration provided to the checker, also implement this interface:

type ValidatableChecker interface {
  Checker
  ValidateConfig(config *structs.ServiceConfig) error
}

When done, just add an init function, and register the struct there with a name.

func init() {
  protocols.Register("your-protocol", YourStruct{})
}

You can then use your protocol in the config.json here:

{
  "services": {
    "bla": {
      "friendly_name": "some-name",
      "protocol": "your-protocol", // <-- here 
      "protocol_config": {}        // <-- this is the struct provided to `config` in `Check` and `ValidateConfig`
    }
  },
  ...
}

You can take a look at the smtp protocol checker for a simple example.