This repository has been archived by the owner on Feb 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
104 changed files
with
1,128 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ibmcloudenv~=0.0 | ||
ibmcloudenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,5 @@ | |
# GENERATE IMPORT HERE | ||
|
||
def initServices(app): | ||
# GENERATE HERE | ||
return | ||
# GENERATE HERE | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
.Package(url: "https://github.com/IBM-Swift/CloudEnvironment.git", majorVersion: 3), | ||
.package(url: "https://github.com/IBM-Swift/CloudEnvironment.git", from: "3.0.0"), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Alert Notification | ||
|
||
IBM Alert Notification instantly delivers notifications of problem occurrences in your IT operations environment using automated communication methods such as email, Short Message Service (SMS), voice and mobile messaging. You can use custom groups to send alerts for a problem or class of problem. Groups can be created based on administrative roles, application names, department names or other criteria. Custom filters can be created for alerting different users based on incident type and severity. | ||
|
||
## Credentials | ||
|
||
### LocalDevConfig | ||
|
||
This is where your local configuration is stored for Alert Notification. | ||
``` | ||
{ | ||
"alert_notification_url": "{{url}}", | ||
"alert_notification_name": "{{name}}", | ||
"alert_notification_password": "{{password}}" | ||
} | ||
``` | ||
|
||
## Usage | ||
[Alert Notification is accessed through a RESTful API](https://ibmnotifybm.mybluemix.net/docs/alerts/v1/). We provide a simple class for interacting with the three endpoints of the service: | ||
|
||
```python | ||
class Alert: | ||
def __init__(self, url, user, password): | ||
self.url = url | ||
self.user = user | ||
self.password = password | ||
self.auth = (user, password) | ||
|
||
def sendAlert(self, payload): | ||
res = requests.post(self.url, auth=self.auth, json=payload) | ||
response = res.json() | ||
return response | ||
|
||
def getAlert(self, id): | ||
res = requests.get(self.url + '/' + str(id), auth=self.auth) | ||
response = res.json() | ||
return response | ||
|
||
def deleteAlert(self, id): | ||
res = requests.delete(self.url + '/' + str(id), auth=self.auth) | ||
return res | ||
``` | ||
|
||
The `service_manager` returns an initialized instance of this object populated with the provided credentials. [Refer to the complete API documentation](https://ibmnotifybm.mybluemix.net/docs/alerts/v1/) for full details on what can be provided in the payload of `sendAlert`: | ||
|
||
```python | ||
from flask import Flask | ||
import requests | ||
|
||
app = Flask(__name__, template_folder="../public", static_folder="../public", static_url_path='') | ||
|
||
from server.services import * | ||
|
||
initServices(app) # Initialize Services | ||
|
||
alert = service_manager.get('alert-notification') | ||
|
||
alertMessage = { | ||
'What': 'Alert Message', | ||
'Where': 'myserver.mycompany.com', | ||
'Severity': 'Critical' | ||
} | ||
|
||
res = alert.sendAlert(alertMessage) | ||
if res and 'ShortId' in res: | ||
messageID = res['ShortId'] | ||
alertInfo = alert.getAlert(messageID) | ||
``` |
34 changes: 26 additions & 8 deletions
34
generators/service-alert-notification/templates/python/instrumentation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
from ibm_cloud_env import IBMCloudEnv | ||
from ibmcloudenv import IBMCloudEnv | ||
import requests | ||
|
||
config = { | ||
'url' : IBMCloudEnv.getString('alert_notification_url') if True else 'https://ibmnotifybm.mybluemix.net/api/alerts/v1', | ||
'user': IBMCloudEnv.getString('alert_notification_name') if True else '', | ||
'password': IBMCloudEnv.getString('alert_notification_password') if True else '' | ||
} | ||
class Alert: | ||
def __init__(self, url, user, password): | ||
self.url = url | ||
self.user = user | ||
self.password = password | ||
self.auth = (user, password) | ||
|
||
def getService(app): | ||
return 'alert-notification', config | ||
def sendAlert(self, payload): | ||
res = requests.post(self.url, auth=self.auth, json=payload) | ||
response = res.json() | ||
return response | ||
|
||
def getAlert(self, alertID): | ||
res = requests.get(self.url + '/' + str(alertID), auth=self.auth) | ||
response = res.json() | ||
return response | ||
|
||
def deleteAlert(self, alertID): | ||
res = requests.delete(self.url + '/' + str(alertID), auth=self.auth) | ||
return res | ||
|
||
def getService(app): | ||
url = IBMCloudEnv.getString('alert_notification_url') | ||
user = IBMCloudEnv.getString('alert_notification_name') | ||
password = IBMCloudEnv.getString('alert_notification_password') | ||
return 'alert-notification', Alert(url, user, password) |
4 changes: 3 additions & 1 deletion
4
generators/service-alert-notification/templates/python/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
requests | ||
|
||
requests | ||
|
2 changes: 1 addition & 1 deletion
2
generators/service-alert-notification/templates/swift/dependencies.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
.Package(url: "https://github.com/IBM-Swift/alert-notification-sdk.git", majorVersion: 1), | ||
.package(url: "https://github.com/IBM-Swift/alert-notification-sdk.git", from: "1.0.0"), |
8 changes: 4 additions & 4 deletions
8
generators/service-alert-notification/templates/swift/instrumentation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import LoggerAPI | ||
import CloudEnvironment | ||
import AlertNotifications | ||
|
||
var serviceCredentials: ServiceCredentials! | ||
|
||
func initializeServiceAlertNotification() throws { | ||
func initializeServiceAlertNotification(cloudEnv: CloudEnv) throws -> ServiceCredentials { | ||
guard let alertNotificationCredentials = cloudEnv.getAlertNotificationCredentials(name: "{{servLookupKey}}") else { | ||
throw InitializationError("Could not load credentials for Alert Notifications.") | ||
} | ||
serviceCredentials = ServiceCredentials( | ||
let serviceCredentials = ServiceCredentials( | ||
url: alertNotificationCredentials.url, | ||
name: alertNotificationCredentials.name, | ||
password: alertNotificationCredentials.password | ||
) | ||
Log.info("Found and loaded credentials for Alert Notifications.") | ||
return serviceCredentials | ||
} |
6 changes: 6 additions & 0 deletions
6
generators/service-alert-notification/templates/swift/meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"import":"AlertNotifications", | ||
"variableName":"alertNotificationService", | ||
"type":"ServiceCredentials", | ||
"initParams":"cloudEnv: cloudEnv" | ||
} |
2 changes: 1 addition & 1 deletion
2
generators/service-apache-spark/templates/python/instrumentation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.