/*
Copyright 2024 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
syntax = "proto3";

package workloadagentplatform.sharedprotos.configurablemetrics;

option go_package = "github.com/GoogleCloudPlatform/workloadagentplatform/sharedprotos/configurablemetrics";

enum OSVendor {
  OS_VENDOR_UNSPECIFIED = 0;
  ALL = 1;
  RHEL = 2;
  SLES = 3;
}

enum OutputSource {
  OUTPUT_SOURCE_UNSPECIFIED = 0;
  STDOUT = 1;
  STDERR = 2;
  EXIT_CODE = 3;
}

message EvalMetric {
  MetricInfo metric_info = 1;
  oneof eval_rule_types {
    EvalMetricRule and_eval_rules = 2;
    OrEvalMetricRule or_eval_rules = 3;
  }
}

message OSCommandMetric {
  MetricInfo metric_info = 1;
  OSVendor os_vendor = 2;
  string command = 3;
  repeated string args = 4;
  oneof eval_rule_types {
    EvalMetricRule and_eval_rules = 6;
    OrEvalMetricRule or_eval_rules = 7;
  }
}

message MetricInfo {
  string min_version = 1;
  string type = 2;
  string label = 3;
}

message OrEvalMetricRule {
  repeated EvalMetricRule or_eval_rules = 1;
}

message EvalMetricRule {
  repeated EvalRule eval_rules = 1;
  EvalResult if_true = 2;
  EvalResult if_false = 3;
}

message EvalRule {
  OutputSource output_source = 1;
  oneof eval_rule_types {
    string output_equals = 2;
    string output_not_equals = 3;
    double output_less_than = 4;
    double output_less_than_or_equal = 5;
    double output_greater_than = 6;
    double output_greater_than_or_equal = 7;
    string output_starts_with = 8;
    string output_ends_with = 9;
    string output_contains = 10;
    string output_not_contains = 11;
  }
}

message EvalResult {
  oneof eval_result_types {
    string value_from_literal = 1;
    bool value_from_output = 2;
    string value_from_regex = 3;
  }
  OutputSource output_source = 4;
}
