How to automate creation of multiple OCI Alarms using Terraform Observability module

 


Recently, I need to monitor client cloud environment using observability and management OCI service.

And I found I need to create each alarm manually for each metric using OCI console which is very time consuming.

After research I found Terraform already have Observability module which we can use to create multiple Alarms in one shot.

Here is the link for module.. Terraform Module

This module has three submodules. alarm, logan_sources and serviceconnector.

I am using the alarm creation submodule and will show you how to create multiple alarms.

Pre-requisites:

1. git is installed

2. Terraform 1.3.0 or higher version is installed

3. Required keys for OCI authentication.

I used below git hub code from Oracle community

Alarm example


Steps:

1. First I clone the repository to local system.


2. Go to the ../example/multiplealarm directory


3. Rename the provider.tf.example to provider.tf and fill the OCI provider info, region, fingerprint, private_key_path, tenancy_ocid and user_ocid.

You can check this link for more info.. OCI Authentication



4. I created a alarm.csv file like below in same folder, this is just an example, you can create as many rows depend on number of alarms. 

To create Alarm, four fields are required.. destination, display_name, query and namespace and other fields are optional.


In the above csv file, destination is basically a topic name(in my case topic name is email).

and last field create_topic, I used false as topic already exists in my case. But if you want to create topic as well, you can set create_topic to true

5. Below is my main.tf file code, where I utilize terraform module "alarm" to create alarms as per my csv file.


You can see the above code in git repo as well I mentioned above.

6. Now once all files ready, run below commands to create alarms.

terraform init  = to initialize the OCI provider and download the module


now run 

terraform plan = To check the code and plan what it would create. (showing the partial output below).


and now we can run

terraform apply = to apply the code and create the alarms. (showing the partial output below)


7. Now we can check on OCI console if these alarms created or not.



So alarms created. 

NOTE: We can add more columns if we need more info like trigger , body, message_format, resolution etc.



No comments:

Post a Comment

How To Disable Automatic Database Backups Using DBAASCLI on ExaCC

  In this blog post I will show you how to disable Automatic database backups on ExaCC using dbaascli.