Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alert service sample code #1

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7069591
aep
Mar 22, 2022
42c06c2
merge
Mar 22, 2022
9eae72f
Update
dylanyeoEnvision Mar 23, 2022
cc5b7ef
Migrate
dylanyeoEnvision Mar 23, 2022
ce74490
migrate
dylanyeoEnvision Mar 23, 2022
343521b
Migrate
dylanyeoEnvision Mar 23, 2022
9b64077
test
dylanyeoEnvision Mar 23, 2022
917f542
Application Portal App Update
dylanyeoEnvision Mar 23, 2022
a7cf8b4
API Testing: BPM
dylanyeoEnvision Mar 23, 2022
b3a4847
API Testing: BPM
dylanyeoEnvision Mar 24, 2022
d2a6cee
API Testing: IAM
dylanyeoEnvision Mar 25, 2022
b5c89b8
API Testing: IAM
dylanyeoEnvision Mar 25, 2022
162835c
API Testing: IAM
dylanyeoEnvision Mar 25, 2022
ad2e004
App Portal Update Login
dylanyeoEnvision Mar 25, 2022
0f4b8ea
API Testing: IAM
dylanyeoEnvision Mar 25, 2022
1a223e2
API Testing: IAM
dylanyeoEnvision Mar 25, 2022
21b7c84
API Testing: Notification Management
dylanyeoEnvision Mar 25, 2022
764abf3
API Update
dylanyeoEnvision Mar 30, 2022
cdcae12
API Update
dylanyeoEnvision Mar 30, 2022
f1a507f
API Update
dylanyeoEnvision Mar 30, 2022
fe6aa93
Dev iot hub
charleshuangcai Sep 23, 2022
5e127a0
fix sample code
charleshuangcai Oct 11, 2022
f5a646e
fix associateAssetBatch sample
charleshuangcai Oct 11, 2022
b2a5dd0
fix firmware api param
charleshuangcai Oct 27, 2022
a724b71
refact the folder
hunan2-envison Nov 15, 2022
f10e2ee
refact the folder
hunan2-envison Nov 15, 2022
a561c10
Add new file
Nov 15, 2022
7234c0e
readme
StephanieEnvision Nov 15, 2022
1e81bda
date
StephanieEnvision Nov 16, 2022
28b2495
add metric api
Oct 19, 2022
bf07f69
remove sensitive info
mingwang4 Apr 6, 2023
e57cbac
Delete .env
Apr 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.idea/workspace.xml
/.idea/inspectionProfiles/profiles_settings.xml
/.idea
.idea
.DS_Store
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# sample-code-python
# Python Sample Code

## About

This repository includes code samples to use EnOS™ APIs in Python. To learn more about EnOS™ APIs, see [EnOS API Documentation](https://support.envisioniot.com/docs/api/en/2.4.0/overview.html).


## Prerequisites

Before using the code samples, complete the tasks described in [Using Python SDK](https://support.envisioniot.com/docs/api/en/2.4.0/gettingstarted.html#using-python-sdk).


## Using the Code Samples

You need to replace the [environment variables](environment_variables.md) with the actual values you want to use.

## Release Notes

2022/12/30
798 changes: 798 additions & 0 deletions alert/alertApp.py

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions alert/content/createAlertContent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
* Copyright (C), 2015-2021, Envision
* FileName: createAlertContent
* Author: Dylan Yeo
* Date: 15/02/22
* Description: Create a new alert content
* History:
* <author> <time> <version> <desc>
*
* https://support.envisioniot.com/docs/alert-api/en/2.3.0/create_alert_content.html
"""

import poseidon.poseidon
from requests.models import PreparedRequest

def createAlertContent(accessKey, secretKey, orgId, url):
accessURL = url + '/event-service/v2.1/alert-contents'
params = {"action": "create", "orgId": orgId}
req = PreparedRequest()
req.prepare_url(accessURL, params)
print(req.url)

body={"alertContent": {"contentId": "Python_Content_ID",
"contentDesc": {"defaultValue": "Default_Contents",
"i18nValue": {"en_US": "Contents",
"zh_CN": "内容",
"ja_JP":"コンテンツ",
"es_ES":"Contenido"}},
"tags": {"ContentKey1": "ContentValue1",
"ContentKey2": "ContentValue2",
"ContentKey3": "ContentValue3"},
"modelId": "Python_Demo_Model",
"alertTypeId": "Python_Type_ID"}
}
print(body)

response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, body)
print(response)


30 changes: 30 additions & 0 deletions alert/content/deleteAlertContent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
* Copyright (C), 2015-2021, Envision
* FileName: deleteAlertContent
* Author: Dylan Yeo
* Date: 15/02/22
* Description: Delete an alert content. It cannot be deleted if it is used by other rules
* History:
* <author> <time> <version> <desc>
*
* https://support.envisioniot.com/docs/alert-api/en/2.3.0/delete_alert_content.html
"""

import poseidon.poseidon
from requests.models import PreparedRequest

def deleteAlertContent(accessKey, secretKey, orgId, url):
accessURL = url + '/event-service/v2.1/alert-contents'
params = {"action": "delete", "orgId": orgId, "alertContentId": "Python_Content_ID"}
req = PreparedRequest()
req.prepare_url(accessURL, params)
print(req.url)

body={
}
print(body)

response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, body)
print(response)


30 changes: 30 additions & 0 deletions alert/content/getAlertContent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
* Copyright (C), 2015-2021, Envision
* FileName: getAlertContent
* Author: Dylan Yeo
* Date: 15/02/22
* Description: Get an alert content based on orgId and contentId
* History:
* <author> <time> <version> <desc>
*
* https://support.envisioniot.com/docs/alert-api/en/2.3.0/get_alert_content.html
"""

import poseidon.poseidon
from requests.models import PreparedRequest

def getAlertContent(accessKey, secretKey, orgId, url):
accessURL = url + '/event-service/v2.1/alert-contents'
params = {"action": "get", "orgId": orgId, "contentId": "Python_Content_ID"}
req = PreparedRequest()
req.prepare_url(accessURL, params)
print(req.url)

body={
}
print(body)

response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, body)
print(response)


91 changes: 91 additions & 0 deletions alert/content/searchAlertContent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"""
* Copyright (C), 2015-2021, Envision
* FileName: searchAlertContent
* Author: Dylan Yeo
* Date: 15/02/22
* Description: Search for alert content based on the search criteria
* History:
* <author> <time> <version> <desc>
*
* https://support.envisioniot.com/docs/alert-api/en/2.3.0/search_alert_content.html
"""

import poseidon.poseidon
from requests.models import PreparedRequest

def searchAlertContent(accessKey, secretKey, orgId, url):
accessURL = url + '/event-service/v2.1/alert-contents'
params = {"action": "search", "orgId": orgId}
req = PreparedRequest()
req.prepare_url(accessURL, params)
print(req.url)

body={"pagination": {"pageNo": 1,
"pageSize": 10}
}
print(body)

response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, body)
print(response)


def searchAlertContent_modelId(accessKey, secretKey, orgId, url):
accessURL = url + '/event-service/v2.1/alert-contents'
params = {"action": "search", "orgId": orgId}
req = PreparedRequest()
req.prepare_url(accessURL, params)
print(req.url)

body={"modelId": "Python_Demo_Model"
}
print(body)

response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, body)
print(response)


def searchAlertContent_alertTypeId(accessKey, secretKey, orgId, url):
accessURL = url + '/event-service/v2.1/alert-contents'
params = {"action": "search", "orgId": orgId}
req = PreparedRequest()
req.prepare_url(accessURL, params)
print(req.url)

body={"alertTypeId": "Python_Type_ID"
}
print(body)

response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, body)
print(response)


def searchAlertContent_subAlertTypeId(accessKey, secretKey, orgId, url):
accessURL = url + '/event-service/v2.1/alert-contents'
params = {"action": "search", "orgId": orgId}
req = PreparedRequest()
req.prepare_url(accessURL, params)
print(req.url)

body={"subAlertTypeId": "Python_Type_ID"
}
print(body)

response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, body)
print(response)


def searchAlertContent_Expression(accessKey, secretKey, orgId, url, Expression):
accessURL = url + '/event-service/v2.1/alert-contents'
params = {"action": "search", "orgId": orgId}
req = PreparedRequest()
req.prepare_url(accessURL, params)
print(req.url)

body={"expression": Expression
}
print(body)

response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, body)
print(response)


40 changes: 40 additions & 0 deletions alert/content/updateAlertContent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
* Copyright (C), 2015-2021, Envision
* FileName: updateAlertContent
* Author: Dylan Yeo
* Date: 15/02/22
* Description: Update an alert content
* History:
* <author> <time> <version> <desc>
*
* https://support.envisioniot.com/docs/alert-api/en/2.3.0/update_alert_content.html
"""

import poseidon.poseidon
from requests.models import PreparedRequest

def updateAlertContent(accessKey, secretKey, orgId, url):
accessURL = url + '/event-service/v2.1/alert-contents'
params = {"action": "update", "orgId": orgId, "isPatchUpdate": "true"}
req = PreparedRequest()
req.prepare_url(accessURL, params)
print(req.url)

body={"alertContent": {"contentId": "Python_Content_ID",
"contentDesc": {"defaultValue": "Updated_Default_Contents",
"i18nValue": {"en_US": "Updated_Contents",
"zh_CN": "更新内容",
"ja_JP":"更新された内容",
"es_ES":"Contenidos Actualizados"}},
"tags": {"NewContentKey1": "NewContentValue1",
"NewContentKey2": "NewContentValue2",
"NewContentKey3": "NewContentValue3"},
"modelId": "Python_Demo_Model",
"alertTypeId": "Python_Type_ID"}
}
print(body)

response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, body)
print(response)


32 changes: 32 additions & 0 deletions alert/record/new/alertTags/batchUpdateAlertTags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
* Copyright (C), 2015-2021, Envision
* FileName: batchUpdateAlertTags
* Author: Dylan Yeo
* Date: 18/02/22
* Description: Batch update the tags for the specified history and active alerts. The returned structure describes the update results of each alert. If an error message occurs, the error message will be recorded and the rest of the update will continue
* History:
* <author> <time> <version> <desc>
*
* https://support.envisioniot.com/docs/alert-api/en/2.3.0/new_version/batch_update_alert_tags.html
"""

import poseidon.poseidon
from requests.models import PreparedRequest

def batchUpdateAlertTags(accessKey, secretKey, orgId, url, alertId_list):
accessURL = url + '/alert-service/v2.1/alerts'
params = {"action": "batchUpdateTags", "orgId": orgId}
req = PreparedRequest()
req.prepare_url(accessURL, params)
print(req.url)

body = {"alertIds": alertId_list,
"isPatchUpdate": True,
"tags": {"NewActiveAlert_newverKey1": "NewActiveAlert_newverValue1",
"NewActiveAlert_newverKey2": "NewActiveAlert_newverValue2",
"NewActiveAlert_newverKey3": "NewActiveAlert_newverValue3"},
}
print(body)

response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, body)
print(response)
33 changes: 33 additions & 0 deletions alert/record/new/alertTags/updateAlertTags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
* Copyright (C), 2015-2021, Envision
* FileName: updateAlertTags
* Author: Dylan Yeo
* Date: 18/02/22
* Description: Update history and active alert tags
* History:
* <author> <time> <version> <desc>
*
* https://support.envisioniot.com/docs/alert-api/en/2.3.0/new_version/update_alert_tags.html
"""

import poseidon.poseidon
from requests.models import PreparedRequest

def updateAlertTags(accessKey, secretKey, orgId, url, alertId):
accessURL = url + '/alert-service/v2.1/alerts'
params = {"action": "updateTags", "orgId": orgId}
req = PreparedRequest()
req.prepare_url(accessURL, params)
print(req.url)

body = {"alertId": alertId,
"isPatchUpdate": True,
"tags": {"NewActiveAlert_newverKey1": "NewActiveAlert_newverValue1",
"NewActiveAlert_newverKey2": "NewActiveAlert_newverValue2",
"NewActiveAlert_newverKey3": "NewActiveAlert_newverValue3"},
}
print(body)

response = poseidon.poseidon.urlopen(accessKey, secretKey, req.url, body)
print(response)

Loading