Python server SDK for IBM Cloud Event Notifications service
Project description
IBM Cloud Event Notifications Python Admin SDK 0.0.2
Python client library to interact with various IBM Cloud Event Notifications APIs.
Disclaimer: this SDK is being released initially as a pre-release version. Changes might occur which impact applications that use this SDK.
Table of Contents
- Overview
- Prerequisites
- Installation
- Initialize SDK
- Using the SDK
- Set Environment
- Questions
- Issues
- Open source @ IBM
- Contributing
- License
Overview
The IBM Cloud Event Notifications Python SDK allows developers to programmatically interact with Event Notifications service in IBM cloud.
Service Name | Module Name | Imported Class Name |
---|---|---|
Event Notifications Service | ibm_eventnotifications | EventNotificationsV1 |
Prerequisites
- An IBM Cloud account.
- An Event Notifications Instance
- Python 3.6 or above.
Installation
To install, use pip or easy_install:
pip install --upgrade "ibm_eventnotifications>=0.0.2"
or
easy_install --upgrade "ibm_eventnotifications>=0.0.2"
Initialize SDK
Initialize the sdk to connect with your Event Notifications service instance.
from ibm_eventnotifications import EventNotificationsV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
# Create an IAM authenticator.
authenticator = IAMAuthenticator('<iam-api-key>')
# Construct the service client.
event_notifications_service = EventNotificationsV1(authenticator=authenticator)
# Set our custom service URL (optional)
event_notifications_service.set_service_url('https://' + region + '.event-notifications.cloud.ibm.com/event-notifications')
- region : Region of the Event Notifications Instance
Using the SDK
SDK Methods to consume
Source
List Sources
source_list = event_notifications_service.list_sources(
<instance-id>, # Event notifications service instance GUID
).get_result()
print(json.dumps(source_list, indent=2))
Get Sources
source = event_notifications_service.get_source(
<instance-id>, # Event notifications service instance GUID
id=<source-id>, # Event notifications service instance Source ID
).get_result()
print(json.dumps(source, indent=2))
Topics
Create Topic
rules_model = {
'enabled': False,
'event_type_filter': '$.notification_event_info.event_type == \'cert_manager\'', #Add your event type filter here.
'notification_filter': '$.notification.findings[0].severity == \'MODERATE\'', #Add your notification filter here.
}
# Construct a dict representation of a TopicUpdateSourcesItem model
topic_update_sources_item_model = {
'id': <source_id>,
'rules': [rules_model],
}
topic_response = event_notifications_service.create_topic(
<instance_id>,
name=<topic-name>,
description=<topic-description>,
sources=[topic_update_sources_item_model]
)
print(json.dumps(topic_response, indent=2))
List Topics
topic_list = event_notifications_service.list_topics(
<instance-id>,
).get_result()
print(json.dumps(topic_list, indent=2))
Get Topic
topic = event_notifications_service.get_topic(
<instance-id>, # Event notifications service instance GUID
id=<topic-id>, # Event notifications service instance Topic ID
).get_result()
print(json.dumps(topic, indent=2))
Update Topic
rules_model = {
'enabled': True,
'event_type_filter': '$.notification_event_info.event_type == \'core_cert_manager\'',
'notification_filter': '$.notification.findings[0].severity == \'SEVERE\'',
}
# Construct a dict representation of a TopicUpdateSourcesItem model
topic_update_sources_item_model = {
'id': <source-id>, # Event notifications service instance Source ID
'rules': [rules_model],
}
description = "Updated Topic for GCM notifications"
name = 'Updated Admin Topic Compliance'
topic = event_notifications_service.replace_topic(
<instance-id>, # Event notifications service instance GUID
id=<topic-id>, # Event notifications service instance Topic ID
name=<topic-update-name> # Event notifications service instance Topic Name
description=<topic-update-description> # Event notifications service instance Topic description
sources=[topic_update_sources_item_model]
)
print(json.dumps(topic, indent=2))
rulesModel := &eventnotificationsv1.Rules{
Enabled: core.BoolPtr(true),
EventTypeFilter: core.StringPtr("$.notification_event_info.event_type == 'core_cert_manager'"), # Add your event type filter here.
NotificationFilter: core.StringPtr("$.notification.findings[0].severity == 'SEVERE'"), # Add your notification filter here.
}
Delete Topic
response = event_notifications_service.delete_topic(
<instance-id>,
id=<topic-id>,
)
Destinations
Create Destination
destination_config_params_model = {
'url': '<destination-config-url>',
'verb': '<destination-config-verb>',
'custom_headers': {'<header-key>': '<header-value>', },
'sensitive_headers': ['<header-key>'],
}
# Construct a dict representation of a DestinationConfig model
destination_config_model = {
'params': destination_config_params_model,
}
destination = event_notifications_service.create_destination(
<instance-id>,
<destination-name>,
type=<destination-type>,
description=description,
config=destination_config_model
).get_result()
print(json.dumps(destination, indent=2))
List Destinations
destination_list = event_notifications_service.list_destinations(
<instance-id>,
).get_result()
print(json.dumps(destination_list, indent=2))
Get Destination
destination = event_notifications_service.get_destination(
<instance-id>, # Event notifications service instance GUID
id=<destination-id>, # Event notifications service instance Destination ID
).get_result()
print(json.dumps(destination, indent=2))
Update Destination
# Construct a dict representation of a DestinationConfigParamsWebhookDestinationConfig model
destination_config_params_model = {
'url': '<destination-config-update-url>',
'verb': '<destination-config-update-verb>',
'sensitive_headers': ['<header-key>'],
}
# Construct a dict representation of a DestinationConfig model
destination_config_model = {
'params': destination_config_params_model,
}
destination = event_notifications_service.update_destination(
<instance-id>, # Event notifications service instance GUID
id=<destination-id>, # Event notifications service instance Destination ID
name=<destination-update-name>,
description=<destination-update-description>,
config=destination_config_model
).get_result()
print(json.dumps(destination, indent=2))
Delete Destination
response = event_notifications_service.delete_destination(
<instance-id>, # Event notifications service instance GUID
id=<destination-id>, # Event notifications service instance Destination ID
)
Subscriptions
Create Subscription
#`While Creating Subscription use any of one option from webhook, or email`
subscription_create_attributes_model = {
'signing_enabled': False,
}
subscription = event_notifications_service.create_subscription(
<instance-id>, # Event notifications service instance GUID
name,
<destination-id>, # Event notifications service instance Destination ID
<topic-id> # Event notifications service instance Topic ID
attributes=subscription_create_attributes_model,
description=<subscription-description>
).get_result()
print(json.dumps(subscription, indent=2))
List Subscriptions
subscription_list = event_notifications_service.list_subscriptions(
<instance-id>, # Event notifications service instance GUID
).get_result()
print(json.dumps(subscription_list, indent=2))
Get Subscription
subscription = event_notifications_service.get_subscription(
<instance-id>, # Event notifications service instance GUID
id=<subscription-id>, # Event notifications service instance Subscription ID
).get_result()
print(json.dumps(subscription, indent=2))
Update Subscription
subscription_update_attributes_model = {
'signing_enabled': True,
}
subscription = event_notifications_service.update_subscription(
<instance-id>, # Event notifications service instance GUID
id=<subscription-id>, # Event notifications service instance Subscription ID
name=<subscription-update-name>,
description=<subscription-update-description>,
attributes=subscription_update_attributes_model
).get_result()
print(json.dumps(subscription, indent=2))
Delete Subscription
response = event_notifications_service.delete_subscription(
<instance-id>, # Event notifications service instance GUID
id=<subscription-id>, # Event notifications service instance Subscriptions ID
)
Set Environment
Find event_notifications.env.hide
in the repo and rename it to event_notifications.env
. After that add the values for,
EVENT_NOTIFICATIONS_URL
- Add the Event Notifications service instance Url.EVENT_NOTIFICATIONS_APIKEY
- Add the Event Notifications service instance apikey.EVENT_NOTIFICATIONS_GUID
- Add the Event Notifications service instance GUID.
Optional
EVENT_NOTIFICATIONS_AUTH_URL
- Add the IAM url if you are using IBM test cloud.
Questions
If you are having difficulties using this SDK or have a question about the IBM Cloud services, please ask a question Stack Overflow.
Issues
If you encounter an issue with the project, you are welcome to submit a bug report. Before that, please search for similar issues. It's possible that someone has already reported the problem.
Open source @ IBM
Find more open source projects on the IBM Github Page
Contributing
See CONTRIBUTING.md.
License
This SDK is released under the Apache 2.0 license. The license's full text can be found in LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for ibm-eventnotifications-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb4f05950ce6ec4e043b45ff7a44e35a39635e38649a0ff29f41290f99ee9a91 |
|
MD5 | 701f0b3297c84d44316a468ba9d33eda |
|
BLAKE2b-256 | 7301ec0794d8f18e8a5d4b0c6db2424f3778d71ae816989100c2f50f51fdf545 |