// Copyright 2018 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
//
//     http://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 google.monitoring.v3;

import "google/api/monitored_resource.proto";
import "google/protobuf/duration.proto";

option csharp_namespace = "Google.Cloud.Monitoring.V3";
option go_package = "google.golang.org/genproto/googleapis/monitoring/v3;monitoring";
option java_multiple_files = true;
option java_outer_classname = "UptimeProto";
option java_package = "com.google.monitoring.v3";
option php_namespace = "Google\\Cloud\\Monitoring\\V3";


// An internal checker allows uptime checks to run on private/internal GCP
// resources.
message InternalChecker {
  // A unique resource name for this InternalChecker. The format is:
  //
  //
  //   `projects/[PROJECT_ID]/internalCheckers/[INTERNAL_CHECKER_ID]`.
  //
  // PROJECT_ID is the stackdriver workspace project for the
  // uptime check config associated with the internal checker.
  string name = 1;

  // The checker's human-readable name. The display name
  // should be unique within a Stackdriver Workspace in order to make it easier
  // to identify; however, uniqueness is not enforced.
  string display_name = 2;

  // The [GCP VPC network](https://cloud.google.com/vpc/docs/vpc) where the
  // internal resource lives (ex: "default").
  string network = 3;

  // The GCP zone the uptime check should egress from. Only respected for
  // internal uptime checks, where internal_network is specified.
  string gcp_zone = 4;

  // The GCP project_id where the internal checker lives. Not necessary
  // the same as the workspace project.
  string peer_project_id = 6;
}

// This message configures which resources and services to monitor for
// availability.
message UptimeCheckConfig {
  // The resource submessage for group checks. It can be used instead of a
  // monitored resource, when multiple resources are being monitored.
  message ResourceGroup {
    // The group of resources being monitored. Should be only the
    // group_id, not projects/<project_id>/groups/<group_id>.
    string group_id = 1;

    // The resource type of the group members.
    GroupResourceType resource_type = 2;
  }

  // Information involved in an HTTP/HTTPS uptime check request.
  message HttpCheck {
    // A type of authentication to perform against the specified resource or URL
    // that uses username and password.
    // Currently, only Basic authentication is supported in Uptime Monitoring.
    message BasicAuthentication {
      // The username to authenticate.
      string username = 1;

      // The password to authenticate.
      string password = 2;
    }

    // If true, use HTTPS instead of HTTP to run the check.
    bool use_ssl = 1;

    // The path to the page to run the check against. Will be combined with the
    // host (specified within the MonitoredResource) and port to construct the
    // full URL. Optional (defaults to "/").
    string path = 2;

    // The port to the page to run the check against. Will be combined with host
    // (specified within the MonitoredResource) and path to construct the full
    // URL. Optional (defaults to 80 without SSL, or 443 with SSL).
    int32 port = 3;

    // The authentication information. Optional when creating an HTTP check;
    // defaults to empty.
    BasicAuthentication auth_info = 4;

    // Boolean specifiying whether to encrypt the header information.
    // Encryption should be specified for any headers related to authentication
    // that you do not wish to be seen when retrieving the configuration. The
    // server will be responsible for encrypting the headers.
    // On Get/List calls, if mask_headers is set to True then the headers
    // will be obscured with ******.
    bool mask_headers = 5;

    // The list of headers to send as part of the uptime check request.
    // If two headers have the same key and different values, they should
    // be entered as a single header, with the value being a comma-separated
    // list of all the desired values as described at
    // https://www.w3.org/Protocols/rfc2616/rfc2616.txt (page 31).
    // Entering two separate headers with the same key in a Create call will
    // cause the first to be overwritten by the second.
    // The maximum number of headers allowed is 100.
    map<string, string> headers = 6;
  }

  // Information required for a TCP uptime check request.
  message TcpCheck {
    // The port to the page to run the check against. Will be combined with host
    // (specified within the MonitoredResource) to construct the full URL.
    // Required.
    int32 port = 1;
  }

  // Used to perform string matching. It allows substring and regular
  // expressions, together with their negations.
  message ContentMatcher {
    // String or regex content to match (max 1024 bytes)
    string content = 1;
  }

  // A unique resource name for this UptimeCheckConfig. The format is:
  //
  //
  //   `projects/[PROJECT_ID]/uptimeCheckConfigs/[UPTIME_CHECK_ID]`.
  //
  // This field should be omitted when creating the uptime check configuration;
  // on create, the resource name is assigned by the server and included in the
  // response.
  string name = 1;

  // A human-friendly name for the uptime check configuration. The display name
  // should be unique within a Stackdriver Workspace in order to make it easier
  // to identify; however, uniqueness is not enforced. Required.
  string display_name = 2;

  // The resource the check is checking. Required.
  oneof resource {
    // The [monitored
    // resource](https://cloud.google.com/monitoring/api/resources) associated
    // with the configuration.
    // The following monitored resource types are supported for uptime checks:
    //   uptime_url
    //   gce_instance
    //   gae_app
    //   aws_ec2_instance
    //   aws_elb_load_balancer
    google.api.MonitoredResource monitored_resource = 3;

    // The group resource associated with the configuration.
    ResourceGroup resource_group = 4;
  }

  // The type of uptime check request.
  oneof check_request_type {
    // Contains information needed to make an HTTP or HTTPS check.
    HttpCheck http_check = 5;

    // Contains information needed to make a TCP check.
    TcpCheck tcp_check = 6;
  }

  // How often, in seconds, the uptime check is performed.
  // Currently, the only supported values are `60s` (1 minute), `300s`
  // (5 minutes), `600s` (10 minutes), and `900s` (15 minutes). Optional,
  // defaults to `300s`.
  google.protobuf.Duration period = 7;

  // The maximum amount of time to wait for the request to complete (must be
  // between 1 and 60 seconds). Required.
  google.protobuf.Duration timeout = 8;

  // The expected content on the page the check is run against.
  // Currently, only the first entry in the list is supported, and other entries
  // will be ignored. The server will look for an exact match of the string in
  // the page response's content. This field is optional and should only be
  // specified if a content match is required.
  repeated ContentMatcher content_matchers = 9;

  // The list of regions from which the check will be run.
  // Some regions contain one location, and others contain more than one.
  // If this field is specified, enough regions to include a minimum of
  // 3 locations must be provided, or an error message is returned.
  // Not specifying this field will result in uptime checks running from all
  // regions.
  repeated UptimeCheckRegion selected_regions = 10;

  // If this is true, then checks are made only from the 'internal_checkers'.
  // If it is false, then checks are made only from the 'selected_regions'.
  // It is an error to provide 'selected_regions' when is_internal is true,
  // or to provide 'internal_checkers' when is_internal is false.
  bool is_internal = 15;

  // The internal checkers that this check will egress from. If `is_internal` is
  // true and this list is empty, the check will egress from all the
  // InternalCheckers configured for the project that owns this CheckConfig.
  repeated InternalChecker internal_checkers = 14;
}

// Contains the region, location, and list of IP
// addresses where checkers in the location run from.
message UptimeCheckIp {
  // A broad region category in which the IP address is located.
  UptimeCheckRegion region = 1;

  // A more specific location within the region that typically encodes
  // a particular city/town/metro (and its containing state/province or country)
  // within the broader umbrella region category.
  string location = 2;

  // The IP address from which the uptime check originates. This is a full
  // IP address (not an IP address range). Most IP addresses, as of this
  // publication, are in IPv4 format; however, one should not rely on the
  // IP addresses being in IPv4 format indefinitely and should support
  // interpreting this field in either IPv4 or IPv6 format.
  string ip_address = 3;
}

// The regions from which an uptime check can be run.
enum UptimeCheckRegion {
  // Default value if no region is specified. Will result in uptime checks
  // running from all regions.
  REGION_UNSPECIFIED = 0;

  // Allows checks to run from locations within the United States of America.
  USA = 1;

  // Allows checks to run from locations within the continent of Europe.
  EUROPE = 2;

  // Allows checks to run from locations within the continent of South
  // America.
  SOUTH_AMERICA = 3;

  // Allows checks to run from locations within the Asia Pacific area (ex:
  // Singapore).
  ASIA_PACIFIC = 4;
}

// The supported resource types that can be used as values of
// `group_resource.resource_type`.
// `INSTANCE` includes `gce_instance` and `aws_ec2_instance` resource types.
// The resource types `gae_app` and `uptime_url` are not valid here because
// group checks on App Engine modules and URLs are not allowed.
enum GroupResourceType {
  // Default value (not valid).
  RESOURCE_TYPE_UNSPECIFIED = 0;

  // A group of instances from Google Cloud Platform (GCP) or
  // Amazon Web Services (AWS).
  INSTANCE = 1;

  // A group of Amazon ELB load balancers.
  AWS_ELB_LOAD_BALANCER = 2;
}
