Extract OCI Resource Status Using APIs

In this blog, I want to show you a way to extract every resource in a compartment along with their status using a Python script and OCI APIs.

There are several pre-reqs that you need to fulfil in order to be able to connect using APIs to OCI. Follow the same pre-reqs as in my previous blog about Metric Extensions.

Step 1 – Prerequisites



Once you have created an OCI user, setup API Keys and setup your Python host; then, go ahead and create a Python script similar to the one below.

#!/usr/bin/python3

# This is a sample python script that searches resources in a compartment
# Run this script on the client that you want to monitor.
# Command: python script_name.py

import oci,subprocess,os,datetime,json
from pytz import timezone

# using default configuration file (~/.oci/config)
from oci.config import from_file
config = from_file()

# initialize service client with default config file

search_client = oci.resource_search.ResourceSearchClient(config)
query = f"query all resources where compartmentId = '<compartment OCID>' && lifeCycleState != 'AVAILABLE' && lifeCycleState != 'ACTIVE' && lifeCycleState != 'Assigned' && lifeCycleState != 'Running' && lifeCycleState != 'Succeeded' && lifeCycleState != 'Deleted'"
search_response = search_client.search_resources(
    search_details=oci.resource_search.models.StructuredSearchDetails(
        type="Structured",
        query=query,
    ),
    limit=1000,
)
print(f"Compartment has {len(search_response.data.items)} resources")

json_format = json.loads(str(search_response.data.items))

# Iterate through the JSON array
for item in json_format:
    print(item["display_name"], item["lifecycle_state"])

As you can see from the script. We are using OCI Search in order to get all resources in a compartment (<compartment OCID>) and also we all filtering the search to only show resources that are either down, terminated or failed.

Once you get the list of resources in your compartment you can create a text/csv file and share the list with all the interested parties.

Another option is the ability to combine this with the Monitoring Service and create a Metric Extension (ME). The metric extension will hold the list of resources that have that specific lifecycle_state. Once the date is contained in the ME you can send notifications or create a dashboard showing these resources.

Thanks,
Alfredo

Oracle Cloud Infrastructure – Database Service – Bare Metal

The Database service part of the Oracle Cloud Infrastructure offers the autonomous and user-managed database options. The user-managed can be customized and you can choose between using Bare Metal, Virtual Machine or Exadata systems. These are called DB Systems.
The autonomous database cannot be customized as they come pre-configured. You can choose between Autonomous Transaction Processing or Autonomous Data Warehouse.
Licensing wise there are two models. License included covers the costs of the license in the cloud service. Bring Your Own License (BYOL) allows to use costumer’s Unlimited License Agreement or Non-Unlimited License Agreement with Oracle Cloud Infrastructure. There are some restrictions that apply to BYOL. More details about pricing can be found in below link:
There are two ways to access Oracle Cloud Infrastructure. You can use the Console (browser) and the REST API. Below is the Oracle Cloud Infrastructure menu.
Let’s start looking at Bare Metal DB Systems. They are available as a single metal server running Oracle Linux 6.8 and NVMe storage locally attached. NVMe provides additional boost in performance for these systems.
When a bare metal DB system is created you select the Oracle Database Edition for the whole system. This means that you can have multiple DB homes with different versions but all with the same edition.
Bare metal comes in two shapes available. BM.DenselO2.52 that provides 1-node with up to 52 CPU cores, 768 GB of memory and eight 6.4 TB NVMe storage drives. BM.DenselO1.36 that is 1-node with up to 36 CPU cores, 512 GB of memory and nine 3.2 TB drives.




Database versions available are 11.2.0.4, 12.1.0.2, 12.2.0.1 and 18.0.0.0.

As you can see from the previous screenshot. You can opt for automatic backups going to an Oracle Cloud Object Storage. 

I’ll cover Virtual Machine and Exadata DB systems including backups in my next post. Stay tuned!
Thanks,
Alfredo

Manage Your Oracle Cloud Database – SQL Developer

In my previous post (How To Connect To The Oracle Cloud Instance) we reviewed the steps to connect using SQL Developer. Now we will see what DBA tasks we can perform using SQL Developer.

First click on the View menu, then click on the DBA sub menu. This is going to open the DBA pane in the lower left corner.

Click on Connections and add the connection we already setup to the Oracle Cloud Instance. 




Here you can expand the tree to verify what is available from SQL Developer.

Let’s click on Tuning and then Real Time SQL Monitoring. The right pane is going to display the SQL Monitoring output. I’m really familiar to this feature in OEM 13c and honestly, looks very similar in SQL Developer.

Now let’s click on Instance Viewer under Database Status menu.
This is going to show you the overall container status and statistics on where our PDB is running on.



The storage menu can help you verify the size of your tablespaces and under RMAN Backup/Recovery you can verify that there are actually backups happening every night. 

Thanks,
Alfredo


How To Connect To The Oracle Cloud DB Instance?

In my previous post (How To Create An Oracle Cloud Instance) I showed you create your first Oracle Cloud DB instance. Now that the instance is there the question is, how to connect to it?

Let’s say you want to connect using SQL Developer to start creating objects and inserting data. First you need to enable the Client Access feature. Yes, it is disabled by default. 

Navigate to the Cloud DB instance dashboard. Click on Manage menu on the left side. 
Click on Admin Password and provide a password for the PDB_ADMIN account.

Then click on Client Access and check the enabled flag, then save.

It will show like this.


Once this is enabled you need to download the Access Credentials in order to connect to your instance.

Click on the Client Credentials button located on the right side of the Client Access one. This is going to prompt for a password (type one that you can remember) and it will download a .zip file containing these credentials and connect descriptors.

Note: You don’t have to unzip this file.

Open your SQL Developer software and click on New Connection.

Type a name for your connection. In the username & password you can either type the PDB_ADMIN username and password or the credentials for the newly created schema.

In Connection Type select Cloud PDB and provide the downloaded .zip file along with the password provided (the one that you should remember).  

It should look like this.



Click Save and then Connect.

Now let’s test our connection by executing a simple SQL statement.



Using the Cloud DB instance dashboard you can create different schemas as needed.
You just provide the username and password.


At the end you just need to follow the same steps as we did before, just provide the username and password of the new schema.

More information can be found at:

https://docs.oracle.com/en/cloud/paas/exadata-express-cloud/csdbp/connecting-sql-developer.html#GUID-238A40BD-10E9-4478-AAA3-43FC98519D3F


Thanks,
Alfredo

How To Create An Oracle Cloud Instance

In my previous post (Thinking on trying the Oracle Cloud? My 30 day experience) I showed you how to subscribe to the Oracle Cloud and how to get to the main dashboard. From here we are going to click on the Create Instance button.


After that you are going to be prompted on what kind if service this instance is for. You have 4 options; Messaging, Data Visualization, Exadata Express and Management Cloud.
In this example we want to create a database instance on Exadata Express. So we are going to select “Create” on the Exadata Express section.
Then you need to configure the instance details. First is the name (lowercase), then the plan and finally the Database shape. In this case I just want to create a small 20GB test instance.


On the right side you have administrator details. The default is the account we created to sign up to the Oracle Cloud.
Then click on Create.
You will get a message like the one below.
It took couple of minutes for the DB instance to be provisioned. Once ready, you’ll see the status of the instance as active in the dashboard.
Next click on the service instance URL and you will be re-directioned to the instance dashboard. In this dashboard you have 2 main options, Develop and Manage.
Develop option, gives you tools like SQLPlus, App Builder, SQL Developer and the option to enable access to client tools.
Manage option enables you to create users, change passwords, export/import and Apex administration.
This concludes the instance creation process. 
Thanks,
Alfredo

Thinking on trying the Oracle Cloud? My 30 day experience.

Although I already had some exposure to the Oracle Cloud (thanks to other Oracle ACEs that put an awesome workshop last year at Collaborate 2017) , I decided to sign up for a free 30 day ($300 dollars credit) and test the Cloud out.
The sing up process was kind of weird. You first go to https://cloud.oracle.com/home and click on the “Try for Free” green button in the right upper corner and then “Create Free Account”.
Then you fill the formulary with all your personal data (account details), verification code (sent to your cell), credit card details (no charge will be made) and you need to agree the terms and conditions.
You will receive an email after you submit your formulary. That night I received an email from Oracle that asked me to provide the name of the bank of my credit card and the amount that was charged to it. Yes, they charged and then they removed the charge.
After asking them by email on how to provide this information, they responded that just by replying to that email with my information (seems pretty secure, right?). I received an email couple of hours later with my login credentials and the URL. Once you click on the hyperlink or type the URL provided, you are prompted to reset your password and then sent to the main dashboard.




In my next post, I will show you how to create your first Cloud Database instance.
Thanks,
Alfredo

Oracle Management Cloud – Managing the Oracle Cloud Agent

This post is about some useful commands to administer the OMC’s Cloud agent. The very first step is to install the OMC Cloud agent. You may refer to my previous post on how to install it here.
The omcli command is located at /agent_inst/bin.
I’m skipping these 3 basic commands start, stop and status.
Here we go!
      List the targets currently managed by the Cloud agent
$ ./omcli config agent listtargets
Oracle Management Cloud Agent 
Copyright (c) 1996, 2016 Oracle Corporation.  All rights reserved.
[hostname.localdomain:1302, Lama]
[hostname.localdomain, omc_host_linux]
      Get the TimeZone of the server where the Cloud agent is running
$ ./omcli config agent getTZ
Oracle Management Cloud Agent 
Copyright (c) 1996, 2016 Oracle Corporation.  All rights reserved.
US/Eastern
      Get a detailed output of the Cloud agent scheduler
$ ./omcli status agent scheduler
Oracle Management Cloud Agent 
Copyright (c) 1996, 2016 Oracle Corporation.  All rights reserved.
—————————————————————
Number of currently running scheduled items :: 0
Number of currently ready scheduled items :: 0
Number of scheduled items :: 57
Schedule Attempts Delay Percentage :: 0.000%
Running entries::
Ready entries::
Scheduled entries::
2017-03-31 14:32:58.968 : HeapMonitorTask
2017-03-31 22:34:14.667 : PurgeTargetEvents
2017-03-31 22:35:47.885 : PurgeADR
2017-04-01 13:34:20.810 : EventStatusPurge
—————————————————————
Agent is Running and Ready
      Get a summary of the Cloud agent’s scheduler
$ ./omcli status agent scheduler -summary
Oracle Management Cloud Agent 
Copyright (c) 1996, 2016 Oracle Corporation.  All rights reserved.
—————————————————————
Number of currently running scheduled items :: 0
Number of currently ready scheduled items :: 0
Number of scheduled items :: 57
Schedule Attempts Delay Percentage :: 0.000%
—————————————————————
Agent is Running and Ready
      Dump the internal state of the agent [option component name]
$ ./omcli dumpstate agent
Oracle Management Cloud Agent 
Copyright (c) 1996, 2016 Oracle Corporation.  All rights reserved.
Generated file: /u01/omc/infra/agent_inst/sysman/emd/dumps/SystemDump_1490985620656.xml
      Dump internal information of all components of the Cloud agent
$ ./omcli dumpstate agent -dump_full_state
Oracle Management Cloud Agent 
Copyright (c) 1996, 2016 Oracle Corporation.  All rights reserved.
Generated file: /u01/omc/infra/agent_inst/sysman/emd/dumps/SystemDump_1490985775823.xml
      Add entities to the Cloud agent using JSON template
$ ./omcli add_entity agent /home/oracle/omc_weblogic.json
Oracle Management Cloud Agent 
Copyright (c) 1996, 2016 Oracle Corporation.  All rights reserved.
Operation Succeeded: Accepted 2 of 2 entities for processing.
      Delete entities from the Cloud agent using JSON template
$ ./omcli delete_entity agent /home/oracle/omc_weblogic.json
Oracle Management Cloud Agent 
Copyright (c) 1996, 2016 Oracle Corporation.  All rights reserved.
Request for removing the entities was accepted for processing.
This is just a small taste of all the options built into the Oracle’s Cloud agent.  For more information about all the options refer to Oracle’s documentation.
Thanks,

Alfredo

Oracle Management Cloud – Install the Cloud Agent

This is my first experience with the Oracle Cloud, in particular with Oracle Management Cloud (OMC). In this first post I will guide you through the installation of the Cloud Agent in a Linux host.
First you have to login to OMC and click on the navigation icon below.


It’ going to open the navigation screen that contains 4 sections; Home, Cloud Services, Explorers and Administration.


In the Administration section click on Agents.
In this page we are looking into 2 important items for us. Registration Keys and Download.


The way I see the Registration Keys is like the Agent Registration password in OEM 13c. You need a valid Registration Key to deploy your Cloud Agent. So, click on that link and verify that you have a Registration Key; if not, you can create one.   
Then proceed to download the agent by clicking on the Download link.
In order to install the Cloud Agent in the Linux host there are some pre-reqs to be met.
First verify that you have acl and libaio.i686 packages installed.
# rpm -q acl
acl-2.2.49-6.el6.x86_64
# rpm -qa|grep libaio
libaio-devel-0.3.107-10.el6.x86_64
libaio-0.3.107-10.el6.x86_64
libaio-0.3.107-10.el6.i686
Then move the AgentInstall.zip previously downloaded into an staging directory and unzip it.
$ mkdir –p /home/oracle/omc
$ mv AgentInstall.zip /home/oracle/omc
$ cd /home/oracle/omc
$ unzip AgentInstall.zip
$ $ ls
AgentInstall.bat  AgentInstall.sh  AgentInstall.zip  README
Create a folder to install the Cloud Agent.
$ mkdir –p /u01/omc/infra
Verify that the server has the FQN configured (name.domain_name).
$ hostname
ol6-121-plug.localdomain
Finally install the Cloud Agent.
$ ./AgentInstall.sh AGENT_TYPE=cloud_agent AGENT_REGISTRATION_KEY=R******************1  AGENT_BASE_DIR=/u01/omc/infra AGENT_PORT=1302 ORACLE_HOSTNAME=ol6-121-plug.localdomain
WARNING: The current cURL version 7.19.7 does not support TLS1.2 protocol; the downloader script will attempt to continue but may not work. Please install 7.49.1 or later versions of cURL for error-free execution.
Downloading lama agent software …
Generating emaas.properties …
Extracting Agent Software …
Installing the Agent …
Registering the Agent …
Downloading Certificates …
Configuring the Agent …
Cleanup temporary files …
Then you have to run the root script required after the installation.
# /u01/omc/infra/core/1.15.0/root.sh
/etc exist
/u01/omc/infra/core/1.15.0
Check the status of the Cloud Agent.
$ ./omcli status agent
Oracle Management Cloud Agent 
Copyright (c) 1996, 2016 Oracle Corporation.  All rights reserved.
—————————————————————
Version                : 1.15.0
State Home             : /u01/omc/infra/agent_inst
Log Directory          : /u01/omc/infra/agent_inst/sysman/log
Binaries Location      : /u01/omc/infra/core/1.15.0
Process ID             : 9828
Parent Process ID      : 9790
URL                    : https://ol6-121-plug.localdomain:1302/emd/main/
Started at             : 2017-03-20 20:49:15
Started by user        : oracle
Operating System       : Linux version 3.8.13-26.2.2.el6uek.x86_64 (amd64)
Data Collector enabled : false
Sender Status          : FUNCTIONAL
Gateway Upload Status  : FUNCTIONAL
Last successful upload : 2017-03-20 21:04:39
Last attempted upload  : 2017-03-20 21:04:38
Pending Files (MB)     : 0.01
Pending Files          : 14
Backoff Expiration     : (none)
—————————————————————
Agent is Running and Ready
Now if you go to the OMC portal, the agent will show up automatically.



Want to learn more about Oracle Management Cloud? There’s a free hands on lab “Cloud Experience” at Collaborate 2017 for all attendees on Wednesday 4/5/17.
Thanks,

Alfredo