X

An Oracle blog about Oracle Enterprise Manager and Oracle Management Cloud

How to configure Enterprise Manager notifications for sending to Slack or Microsoft Teams

Pallab Rath
Prinicipal Member Technical Staff

What happens when risk is not properly managed? In many cases, outages and security breaches result from a variety and combination of factors. Vulnerabilities may stem from ineffective, decentralized and siloed monitoring. As a consequence, the inability to correlate different monitoring data and gain insight from data can have a negative impact on systems and leave them open to unmitigated risk.

This blog addresses how the Oracle Enterprise Manager (EM) used commonly by Oracle DBAs can easily be configured to share the information it collects with Slack and Microsoft Teams to send events, and incidents or alerts to other third-party products often used by DevOps, Systems Administrators, or Operations.

Oracle Enterprise Manager provides capabilities that lead to quick response times, improved computing processes and satisfied customers. Fixing, accelerating and optimizing your environment enables performance and availability.

OS commands

Using Oracle Enterprise Manager’s notification system a script can be invoked using operating system commands when an incident rule matches an OS Command advanced notification action. The script receives notifications for matching events, incidents and problems via environment variables.

In this example, we will show how you can use a Python to send EM notifications to Slack and Microsoft Teams. A Python script will receive the message from EM and post it to Slack or Microsoft Teams through a Webhook. For more details and capabilities visit Sending Notifications Using OS Commands and Scripts in the documentation.

To use a Python script, there are four steps to register the script with the EM notification system:

  1. Define your OS command or script
  2. Deploy the script on each Management Service host
  3. Register your OS Command or Script as a new Notification Method
  4. Assign the notification method to an incident rule

NOTE: For those who have configured a multi-node Oracle Enterprise Manager Management (OMS) you need to deploy the Python script on each OMS host machine or in a share location so it can be accessed by all OMS nodes.

Example Script

The following script is a template that you can customize for your own requirements. 

Keep in mind EmNotification_push_webhook.py and NotifyJobEventsToSlackSysadminGroup.py must exist in same directory of each node of OMS.

EmNotification_push_webhook.py

# Copyright (c) 2021, Oracle and/or its affiliates.
# EmNotification_push_webhook.py
# @Author pallab.rath@oracle.com
# Created on 2nd March 2021
 
# This is a sample script which can act as OS command in Enterprise Manager to be invoked when to publish notifications
# It reads notification details from the environment and post it to webhook.
 
import json
import requests
import os
import logging
 
logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p',
filename='EmNotification_push_webhook.log', encoding='utf-8', level=logging.DEBUG)
def fecthNotificationAndPush(webHook, reqHeader, useProxy, proxies):
    logging.debug('fecthNotificationAndPush invoked.')
    logging.debug('webHook:' + webHook)
    logging.debug('reqHeader:' + json.dumps(reqHeader))
    logging.debug('useProxy:' + str(useProxy))
    logging.debug('proxies:' + json.dumps(proxies))
    issue_type = os.getenv('ISSUE_TYPE')
    issue_type_icon = "";
    if (issue_type == "1"):
        issue_type_icon = ":oem_notify: "
    elif (issue_type == "2"):
        issue_type_icon = ":oem_incident: "
 
    message = os.getenv('MESSAGE')
    targetName = os.getenv('TARGET_NAME')
    severity = os.getenv('SEVERITY')
    logging.debug('issue_type:' + issue_type)
    logging.debug('message:' + message)
    logging.debug('targetName:' + targetName)
    logging.debug('severity:' + severity)
    request_format = { "text": "This is a plain text section block."}
    request_format["text"] = issue_type_icon + " " + severity + "= In  " + targetName + " target " + message
    logging.debug('request data:' + json.dumps(request_format))
    if (useProxy):
        response = requests.post(webHook, data=json.dumps(request_format), headers=reqHeader, proxies=proxies)
    else:
        response = requests.post(webHook, data=json.dumps(request_format), headers=reqHeader)
    logging.debug('fecthNotificationAndPush executed.')

NotifyJobEventsToSlackSysadminGroup.py contains the webhook URL, you can create other scripts like this to send different types of notifications to different channels. 

NotifyJobEventsToSlackSysadminGroup.py

# Copyright (c) 2021, Oracle and/or its affiliates.
# NotifyJobEventsToSlackSysadminGroup.py
# @Author pallab.rath@oracle.com
# Created on 2nd March 2021
 
# This is a sample script which can act as OS command in Enterprise Manager, This can be configured to send job events
# notification post it to slack channel through webhook.
 
from EmNotification_push_webhook import *
 
# Please configure the below section
# Configuration details Start
# Proxy details, if proxy not required turn off by useProxy = False
useProxy = False
proxies = {
 "http": "http://www-proxy-test.com:80",
 "https": "http://www-proxy-test.com:80"
}
 
# Slack unique Webhook to send message to a particular channel or as a direct message
slackUrl = "https://hooks.slack.com/services/test/test-webhook/"
slackReqHeader = {"Content-type": "application/json"}
# Configuration details End
 
fecthNotificationAndPush(slackUrl, slackReqHeader, useProxy, proxies)

Register the Python script as an OS command type Notification Method. 

Under your Oracle Enterprise Manager Setup menu, using the Notifications menu selection, select Scripts and SNMPv1 Traps. There setup and configure an OS command and attach it to your Python script. 

Next, assign the notification method to an incident rule. In the OS Command field as pictured, enter the command script to assign a notification method to the incident rule. For more details and capabilities visit Setting Up Rule Sets in the documentation.

In this example, you will configure EM Job Events to notify via the Python script. Under your Oracle Enterprise Manager Setup menu, using the Incidents menu selection, then select Incident Rules.

On the Incident Rules – All Enterprise Rules page, you will create an incident rule and add conditional actions to send advanced notifications. For example, you see the sample script as an OS command you can select.

Slack Integration

To receive Slack notifications, you need a Slack App in the Slack workspace which can send direct messages to a user or to a channel and has the privileges to send messages to a Slack user or to a Slack channel.

To learn how to create a new Slack App, view Slack API in the Slack documentation.

Next is to create a webhook for the Slack App so Oracle Enterprise Manager can post the notifications to it. Such webhooks are unique for a Slack App and particular User/Channel.

To learn how to create a new Slack webhook, view Sending messages using Incoming Webhooks in the Slack documentation.

 

Microsoft Teams Integration

Microsoft Teams also supports webhook to post messages. Learn how to  Post external requests to Teams with incoming webhooks in Microsoft documentation.

First create an incoming webhook to the channel where Oracle Enterprise Manager notifications will be posted.

In Microsoft Teams navigate to Manage teams, and under the App section , locate the incoming webhook app (if not in default list, click on More apps and search there).

 

Once there, enter the required details to obtain the webhook. Now, this webhook  can be used in the Python script to send notifications.

Conclusion

We’ve shown how Oracle Enterprise Manager users can easily extend its notifications to other team members using Slack or Microsoft teams. Using existing Oracle Enterprise Manager functionality, a Python script can act as a connector between Oracle Enterprise Manager and other third-party products.

Disclaimer

Oracle Enterprise Manager Notifications, OS commands and Incident rules are supported functionality. The Python script used in this example or examples created using this template are considered custom code and not supported by Oracle.

Visit us on the web to learn more about Oracle's observability and management portfolio including Oracle Enterprise Manager.

Join the discussion

Comments ( 2 )
  • Mahesh Chikkanna Friday, May 21, 2021
    The work looks good Pallab !!
  • Dileep Raghavan Saturday, May 22, 2021
    Awesome solution Pallab, great job
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.