syntax = "proto3";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "asset.proto";
import "hook.proto";
import "meta.proto";
import "time_window.proto";

package sensu.core.v2;

option go_package = "v2";
option (gogoproto.populate_all) = true;
option (gogoproto.equal_all) = true;
option (gogoproto.marshaler_all) = true;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.sizer_all) = true;
option (gogoproto.testgen_all) = true;

// A CheckRequest represents a request to execute a check
message CheckRequest {
  // Config is the specification of a check.
  CheckConfig config = 1 [(gogoproto.nullable) = true];

  // Assets are a list of assets required to execute check.
  repeated Asset assets = 2 [(gogoproto.nullable) = false];

  // Hooks are a list of hooks to be executed after a check.
  repeated HookConfig hooks = 3 [(gogoproto.nullable) = false];

  // Issued describes the time in which the check request was issued
  int64 Issued = 4 [(gogoproto.jsontag) = "issued"];
}

// A ProxyRequests represents a request to execute a proxy check
message ProxyRequests {
	// EntityAttributes store serialized arbitrary JSON-encoded data to match
	// entities in the registry.
  repeated string entity_attributes = 1 [(gogoproto.jsontag) = "entity_attributes"];

	// Splay indicates if proxy check requests should be splayed, published evenly
	// over a window of time.
	bool splay = 2 [(gogoproto.jsontag) = "splay"];

	// SplayCoverage is the percentage used for proxy check request splay
	// calculation.
	uint32 splay_coverage = 3 [(gogoproto.jsontag) = "splay_coverage"];
}

// CheckConfig is the specification of a check.
message CheckConfig {
  option (gogoproto.face) = true;
  option (gogoproto.goproto_getters) = false;

  // Command is the command to be executed.
  string command = 1;

  // Handlers are the event handler for the check (incidents and/or metrics).
  repeated string handlers = 3 [(gogoproto.jsontag) = "handlers"];

  // HighFlapThreshold is the flap detection high threshold (% state change) for
  // the check. Sensu uses the same flap detection algorithm as Nagios.
  uint32 high_flap_threshold = 4 [(gogoproto.jsontag) = "high_flap_threshold"];

  // Interval is the interval, in seconds, at which the check should be run.
  uint32 interval = 5 [(gogoproto.jsontag) = "interval"];

  // LowFlapThreshold is the flap detection low threshold (% state change) for
  // the check. Sensu uses the same flap detection algorithm as Nagios.
  uint32 low_flap_threshold = 6 [(gogoproto.jsontag) = "low_flap_threshold"];

  // Publish indicates if check requests are published for the check
  bool publish = 9 [(gogoproto.jsontag) = "publish"];

  // RuntimeAssets are a list of assets required to execute check.
  repeated string runtime_assets = 10 [(gogoproto.jsontag) = "runtime_assets"];

  // Subscriptions is the list of subscribers for the check.
  repeated string subscriptions = 11 [(gogoproto.jsontag) = "subscriptions"];

  // ExtendedAttributes store serialized arbitrary JSON-encoded data
  bytes ExtendedAttributes = 12 [(gogoproto.jsontag) = "-"];

  // Sources indicates the name of the entity representing an external resource
  string proxy_entity_name = 13 [(gogoproto.jsontag) = "proxy_entity_name", (gogoproto.customname) = "ProxyEntityName"];

  // CheckHooks is the list of check hooks for the check
  repeated HookList check_hooks = 14 [(gogoproto.jsontag) = "check_hooks", (gogoproto.nullable) = false];

  // STDIN indicates if the check command accepts JSON via stdin from the agent
  bool stdin = 15 [(gogoproto.jsontag) = "stdin"];

  // Subdue represents one or more time windows when the check should be subdued.
  TimeWindowWhen subdue = 16 [(gogoproto.jsontag) = "subdue"];

  // Cron is the cron string at which the check should be run.
  string cron = 17;

  // TTL represents the length of time in seconds for which a check result is valid.
  int64 ttl = 18 [(gogoproto.jsontag) = "ttl"];

  // Timeout is the timeout, in seconds, at which the check has to run
  uint32 timeout = 19 [(gogoproto.jsontag) = "timeout"];

  // ProxyRequests represents a request to execute a proxy check
  ProxyRequests proxy_requests = 20;

  // RoundRobin enables round-robin scheduling if set true.
  bool round_robin = 21 [(gogoproto.jsontag) = "round_robin"];

  // OutputOutputMetricFormat is the metric protocol that the check's output will be
  // expected to follow in order to be extracted.
  string output_metric_format = 22 [(gogoproto.jsontag) = "output_metric_format"];

  // OutputOutputMetricHandlers is the list of event handlers that will respond to metrics
  // that have been extracted from the check.
  repeated string output_metric_handlers = 23 [(gogoproto.jsontag) = "output_metric_handlers"];

  // EnvVars is the list of environment variables to set for the check's
  // execution environment.
  repeated string env_vars = 24 [(gogoproto.jsontag) = "env_vars"];

  // Metadata contains the name, namespace, labels and annotations of the check
  ObjectMeta metadata = 26 [(gogoproto.jsontag) = "metadata,omitempty", (gogoproto.embed) = true, (gogoproto.nullable) = false];
}

// A Check is a check specification and optionally the results of the check's
// execution.
message Check {
  option (gogoproto.face) = true;
  option (gogoproto.goproto_getters) = false;

  // Command is the command to be executed.
  string command = 1;

  // Handlers are the event handler for the check (incidents and/or metrics).
  repeated string handlers = 3 [(gogoproto.jsontag) = "handlers"];

  // HighFlapThreshold is the flap detection high threshold (% state change) for
  // the check. Sensu uses the same flap detection algorithm as Nagios.
  uint32 high_flap_threshold = 4 [(gogoproto.jsontag) = "high_flap_threshold"];

  // Interval is the interval, in seconds, at which the check should be run.
  uint32 interval = 5 [(gogoproto.jsontag) = "interval"];

  // LowFlapThreshold is the flap detection low threshold (% state change) for
  // the check. Sensu uses the same flap detection algorithm as Nagios.
  uint32 low_flap_threshold = 6 [(gogoproto.jsontag) = "low_flap_threshold"];

  // Publish indicates if check requests are published for the check
  bool publish = 9 [(gogoproto.jsontag) = "publish"];

  // RuntimeAssets are a list of assets required to execute check.
  repeated string runtime_assets = 10 [(gogoproto.jsontag) = "runtime_assets"];

  // Subscriptions is the list of subscribers for the check.
  repeated string subscriptions = 11 [(gogoproto.jsontag) = "subscriptions"];

  // Sources indicates the name of the entity representing an external resource
  string proxy_entity_name = 13 [(gogoproto.jsontag) = "proxy_entity_name", (gogoproto.customname) = "ProxyEntityName"];

  // CheckHooks is the list of check hooks for the check
  repeated HookList check_hooks = 14 [(gogoproto.jsontag) = "check_hooks", (gogoproto.nullable) = false];

  // STDIN indicates if the check command accepts JSON via stdin from the agent
  bool stdin = 15 [(gogoproto.jsontag) = "stdin"];

  // Subdue represents one or more time windows when the check should be subdued.
  TimeWindowWhen subdue = 16 [(gogoproto.jsontag) = "subdue"];

  // Cron is the cron string at which the check should be run.
  string cron = 17;

  // TTL represents the length of time in seconds for which a check result is valid.
  int64 ttl = 18 [(gogoproto.jsontag) = "ttl"];

  // Timeout is the timeout, in seconds, at which the check has to run
  uint32 timeout = 19 [(gogoproto.jsontag) = "timeout"];

  // ProxyRequests represents a request to execute a proxy check
  ProxyRequests proxy_requests = 20;

  // RoundRobin enables round-robin scheduling if set true.
  bool round_robin = 21 [(gogoproto.jsontag) = "round_robin"];

  // Duration of execution
  double duration = 22;

  // Executed describes the time in which the check request was executed
  int64 executed = 23 [(gogoproto.jsontag) = "executed"];

  // History is the check state history.
  repeated CheckHistory history = 24 [(gogoproto.jsontag) = "history", (gogoproto.nullable) = false];

  // Issued describes the time in which the check request was issued
  int64 issued = 25 [(gogoproto.jsontag) = "issued"];

  // Output from the execution of Command
  string output = 26 [(gogoproto.jsontag) = "output"];

  // State provides handlers with more information about the state change
  string state = 27;

  // Status is the exit status code produced by the check
  uint32 status = 28 [(gogoproto.jsontag) = "status"];

  // TotalStateChange indicates the total state change percentage for the
  // check's history
  uint32 total_state_change = 29 [(gogoproto.jsontag) = "total_state_change"];

  // LastOK displays last time this check was ok; if event status is 0 this is set to timestamp
  int64 last_ok = 30 [(gogoproto.customname) = "LastOK", (gogoproto.jsontag) = "last_ok"];

  // Occurrences indicates the number of times an event has occurred for a client/check pair with the same check status
  int64 occurrences = 31 [(gogoproto.jsontag) = "occurrences"];

  // OccurrencesWatermark indicates the high water mark tracking number of occurrences at the current severity
  int64 occurrences_watermark = 32 [(gogoproto.jsontag) = "occurrences_watermark"];

  // Silenced is a list of silenced entry ids (subscription and check name)
  repeated string silenced = 33 [(gogoproto.nullable) = true];

  // Hooks describes the results of multiple hooks; if event is associated to hook execution.
  repeated Hook hooks = 34 [(gogoproto.nullable) = true];

  // OutputOutputMetricFormat is the metric protocol that the check's output will be
  // expected to follow in order to be extracted.
  string output_metric_format = 35 [(gogoproto.jsontag) = "output_metric_format"];

  // OutputOutputMetricHandlers is the list of event handlers that will respond to metrics
  // that have been extracted from the check.
  repeated string output_metric_handlers = 36 [(gogoproto.jsontag) = "output_metric_handlers"];

  // EnvVars is the list of environment variables to set for the check's
  // execution environment.
  repeated string env_vars = 37 [(gogoproto.jsontag) = "env_vars"];

  // Metadata contains the name, namespace, labels and annotations of the check
  ObjectMeta metadata = 38 [(gogoproto.jsontag) = "metadata,omitempty", (gogoproto.embed) = true, (gogoproto.nullable) = false];

  // ExtendedAttributes store serialized arbitrary JSON-encoded data
  bytes ExtendedAttributes = 99 [(gogoproto.jsontag) = "-"];
}

// CheckHistory is a record of a check execution and its status
message CheckHistory {
  // Status is the exit status code produced by the check.
  uint32 status = 1 [(gogoproto.jsontag) = "status"];

  // Executed describes the time in which the check request was executed
  int64 executed = 2 [(gogoproto.jsontag) = "executed"];
}
