This post will be mainly about Oracle Cloud Infrastructure Notification Service, the Autonomous Database scaling is just used to demonstrate what you can do with the notification service. So what is Notification Service? It’s a service where you can create different topics where you publish messages to set of subscribers. Depending on your configuration you could then add further actions based on the notification.

At the moment the service is still not integrated together with other services so you could easily build notifications from services you are using. So in this example I’m going to scale Autonomous Database CPU cores and get notified on that using the Python SDK. The inspiration on how to use Python SDK to scale up / down was taken from Richard Garsthagen’s Github example. If you like you could also use OCI CLI or Console to send the notifications.

You can virtually get notification on any action you like, another real world example is that we scale our Exadata on a specific schedule and want to get notified on that.

Creating a topic and a subscription

First we will need a topic where we will publish our messages into. Just go to Application Integration => Notifications and press Create Topic.

I’ve created MyScalingTopic as an example and as I’m the tenancy administrator I won’t look deeper into policies.

Clicking Create Subscription brings a pop-up where you can add subscribers to your Topic. In this example I’m just going to add my own email address there. You could also select protocol as HTTPS (PagerDuty) and utilize PagerDuty for your notifications.

That’s pretty much it from configuration perspective what we need!

Publishing messages

Now I need to get notified when my Autonomous Databases has a scaling event. What I’ve done in the code is follows:

       bodyMessage = "Your ATP Database is being scaled to CPU count: " +scalecpus
       notificationMessage = {"default": "ScaleMsg", "body": bodyMessage, "title": "ATP Database Notification"}
       print(notificationMessage)
       notificationClient.publish_message(topic_ocid, notificationMessage)

I’m creating message which will be send to subscribers and then creating a JSON string with the body and title, based on documentation this could be submitted also as raw text and not as JSON. Notice that the default key/value pair must be included in the string. After that I’m using the notificationClient.publish_message to send the message.

When I run my atp.py I see following:

[opc@demo1 ~]# python atp.py 2
{'default': 'ScaleMsg', 'body': 'Your ATP Database is being scaled to CPU count: 2', 'title': 'ATP Database Notification'}

And within few minutes I get the notification email.

This is a really simple example but it should give you an idea how you can utilize the notification service to be on top what is happening with your OCI resources. Now I can stop the ATP database and as you can see I receive a different notification since I’ve configured it to send it if ATP database is being stopped.

[opc@demo1 ~]# python not.py 0
{'default': 'ScaleMsg', 'body': 'Your ATP Database has been stopped and CPU count set to 0', 'title': 'ATP Database Notification'}

And after few moments I receive the email that my database has been stopped.

This should give you a basic idea how to utilize OCI Notification Service. Let’s hope it gets integrated with other services soon so you don’t need to build everything your own. Would be interesting to hear where their roadmap is heading into.

In this example I’m running the code from my own server, however I really don’t want to do it in the long run. Perhaps Functions Service would give me a better platform to run these type of changes?

You can get the full code I used from my Github page.

One thought on “Use OCI Notification Service to get informed on your Autonomous Database scaling events”

Leave a Reply

Your email address will not be published.