/oci-ms-teams-notifications

This repository demonstrates how to integrate Oracle Cloud Infrastructure (OCI) Notifications with Microsoft Teams to deliver real-time event notifications directly to a Teams channel

Primary LanguagePythonMIT LicenseMIT

OCI Notifications Integration with Microsoft Teams

Oracle Notification Service (ONS) is a robust cloud-native tool that allows you to route notifications from Oracle Topics to various destinations like email, Slack channels, custom HTTP webhooks or OCI Functions with ease. Support of OCI Functions as Notification target allows to invoke custom function during Notification event and send updated notification details to communication channels that support API invocation.  In this article, I'm going to show the integration between OCI and Microsoft Teams, ensuring that critical OCI events are communicated effectively to your team.

Architecture

ONS and MS Teams drawio_1

  • Resources in Oracle Cloud Infrastructure (OCI) emit events, which are structured messages indicating the state of change of resources throughout the tenancy. For example, an event can be emitted when an instance starts, a backup completes or fails, or a file in an Object Storage bucket is added, updated, or deleted.
  • OCI Notifications route these events to the appropriate destinations.
  • OCI Functions reformat the event data (JSON Payload) to the Adaptive Card format required by Microsoft Teams.
  • The restructured message is then published to Microsoft Teams via a webhook, ensuring that the notification is displayed correctly in the Teams channel.

Prerequisites

1. Create a Workflow in Microsoft Teams

To receive notifications from OCI in Microsoft Teams, set up a workflow in Microsoft Teams to handle incoming webhook requests and post to a channel or chat. Follow the steps in the Microsoft Teams Incoming Webhook Documentation to create an incoming webhook.

2. Custom Functions Code

The function code is provided in the sample code folder with the following files:

  • func.py: Main function file, which processes incoming OCI event data and formats it for Microsoft Teams.
  • requirements.txt: Lists the dependencies needed to run the function.
  • func.yaml: Metadata file containing configuration details for deploying the function in OCI.

Ensure these files are available and accessible for deployment.

Setup

The detailed, step-by-step setup guide can be found in the setup.md file. It includes instructions to:

  1. Create a dynamic group and policy to grant necessary permissions.
  2. Create a repository and deploy the function in OCI.
  3. Set up OCI Notifications and subscribe to a topic.
  4. Test and validate the function by triggering OCI events.

Usage

After deployment, any specified OCI events (e.g., instance stopped or Object Storage file upload) will trigger the notification function, which sends a message to the configured Microsoft Teams channel. You can update the function to customize the message format or to include additional event details.

Triggering an Event

To test the integration, you can trigger an event by stopping or starting an instance, or by creating a file in Object Storage (if these events are configured as triggers). Verify that the notification appears in the designated Teams channel.

Troubleshooting

Here are some common issues and tips to help resolve them:

  • Webhook Delivery Issues: Verify that the webhook URL in the function code matches the Microsoft Teams webhook URL.
  • Permission Denied Errors: Ensure that the IAM policies and dynamic group settings are correctly configured for the function.
  • Function Deployment Errors: Check the func.yaml file for accurate configuration, and verify that all required dependencies are listed in requirements.txt.

Resources

License

This project is licensed under the MIT License - see the LICENSE file for details.


This setup enables seamless integration between OCI and Microsoft Teams, ensuring that critical OCI events are effectively communicated in real time to your team, improving visibility and operational efficiency.