## Overview

This template is designed as a master template that discovers various Oracle Cloud Infrastructure (OCI) services
and resources, such as:

* OCI Compute;

* OCI Autonomous Database (serverless);

* OCI Object Storage;

* OCI Virtual Cloud Networks (VCNs);

* OCI Block Volumes;

* OCI Boot Volumes.

For communication with OCI, this template utilizes script items which execute HTTP `GET` and `POST` requests. 
`POST` requests are required for OCI Monitoring API as it utilizes Monitoring Query Language (MQL) which uses an
HTTP request body for queries.


## Setup

## Required setup

For this template to work, it needs authentication details to use in requests. To acquire this information, see
the following steps:

1. Log into your administrator account in Oracle Cloud Console.

2. Create a new user that will be used by Zabbix for monitoring.

3. Create a new security policy and assign a previously created user to it.

4. This policy will contain a set of rules that will give monitoring user access to specific resources in your
OCI. Make sure to add the following rules to the policy:
  
    ```
    Allow group 'zabbix_api' to read metrics in tenancy
    Allow group 'zabbix_api' to read instances in tenancy
    Allow group 'zabbix_api' to read subnets in tenancy
    Allow group 'zabbix_api' to read vcns in tenancy
    Allow group 'zabbix_api' to read vnic-attachments in tenancy
    Allow group 'zabbix_api' to read volumes in tenancy
    Allow group 'zabbix_api' to read objectstorage-namespaces in tenancy
    Allow group 'zabbix_api' to read buckets in tenancy
    Allow group 'zabbix_api' to read autonomous-databases in tenancy
    ```
  
    In this example, `zabbix_api` is the name of the previously created monitoring user. Rename it to your
monitoring user's name.

5. Generate an API key pair for your monitoring user - open your monitoring user profile and on the left side,
press `API keys` and then, `Add API key` (if generating a new key pair, do not forget to save the private key).
  
6. After this, Oracle Cloud Console will provide additional information that is required for access, such as:

    * Tenancy OCID;
      
    * User OCID;
      
    * Fingerprint;
      
    * Region.

    > Save this information somewhere or keep this window open. This information will be required in later steps.

7. In Zabbix, create a new host and assign this template to it (Oracle Cloud by HTTP).

8. In host wizard configuration fields please set next values (from step #6):

    * `OCID tenancy` - set the tenancy OCID value;
      
    * `OCID user` - set the user OCID value;
      
    * `Fingerprint` - set the fingerprint value;
      
    * `Private key` - copy and paste the contents of private key file here.

9. After the authentication credentials are entered, you need to identify the OCI API endpoints that match your
region (as provided by Oracle Cloud Console in step #6).
To do so, you can use the OCI [API Reference and Endpoints](https://docs.public.oneportal.content.oci.oraclecloud.com/en-us/iaas/api/#/) list, where each API service has a dedicated page with the respective API endpoints.

   The required API service endpoints are:
  
   * [Core Services API](https://docs.public.oneportal.content.oci.oraclecloud.com/en-us/iaas/api/#/en/iaas/20160918/);
  
   * [Database Service API](https://docs.public.oneportal.content.oci.oraclecloud.com/en-us/iaas/api/#/en/database/20160918/);
  
   * [Object Storage Service API](https://docs.public.oneportal.content.oci.oraclecloud.com/en-us/iaas/api/#/en/objectstorage/20160918/);
  
   * [Monitoring API](https://docs.public.oneportal.content.oci.oraclecloud.com/en-us/iaas/api/#/en/monitoring/20180401/).
        
10. When the API endpoints are identified, you need to set them in host wizard configuration fields (similarly to step #8):

    * `Core Services host` - Core Services API endpoint, for example, `iaas.eu-stockholm-1.oraclecloud.com`;

    * `Database Service host` - Database Service API endpoint, for example, `database.eu-stockholm-1.oraclecloud.com`;

    * `Object Storage host` - Object Storage Service API endpoint, for example, `objectstorage.eu-stockholm-1.oraclecloud.com`;

    * `Monitoring host` - Monitoring API endpoint, for example, `telemetry.eu-stockholm-1.oraclecloud.com`;
                            
    > IMPORTANT! API Endpoint URLs need to be entered without the HTTP scheme (`https://`).
                            
11. Once you've completed adding the host to Zabbix, and it will automatically discover services and monitor them.

## Optional setup

#### Example

1. In Oracle Cloud Console, add a free-form tag to a resource, for example, a compute instance.
The tag key will be `location_group` and the tag value will be `eu-north-1`.

2. Open the Oracle Cloud by HTTP template in Zabbix and go to "Discovery rules".
Find "Compute instances discovery" and open it.

3. Under "LLD macros", add a new macro that will represent this location group tag, for example:
`{#LOCATION_GROUP}` `$.tags.location_group`.
                                                                                            
4. Under the "Filters" tab, there will already be filters regarding the compute instance name and state.
Click "Add" to add a new filter and define the previously created LLD macro and add a matching pattern and
value, for example, `{#LOCATION_GROUP}` `matches` `eu-north-*`.

5. The next time `Compute instances discovery` is executed, it will only discover OCI compute instances that
have the free-form tag `location_group` that matches the regex of `eu-north-*`. You can also experiment with
the LLD filter pattern matching value to receive different matching results for a specified value.