Skip to content

Commit b857fab

Browse files
authored
New Set Project Parameter block
1 parent ed067f0 commit b857fab

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
### This block updates a project parameter.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"@visokiotype": "CustomBlockSchema.CustomBlockManifest",
3+
"name": "Set Project Parameter",
4+
"scriptFilename": "script.py",
5+
"language": "PYTHON",
6+
"executableVersion": null,
7+
"minVersions": [
8+
null
9+
],
10+
"optionsVersion": 1,
11+
"apiVersion": "VERSION_0",
12+
"isResourceIntensiveScript": false,
13+
"showPartitioning": false,
14+
"icon": null,
15+
"description": "The block updates a project parameter",
16+
"category": "Preparation",
17+
"subcategory": null,
18+
"tags": [
19+
"parameter",
20+
"param"
21+
],
22+
"introductoryText": "## Set Project Parameter\nThis block sets a project parameter.",
23+
"dependencies": "",
24+
"options": [
25+
{
26+
"name": "Iox_File_Url",
27+
"title": "IOX file URL",
28+
"description": "The URL of the project to set the param",
29+
"groupTitle": "File",
30+
"width": "THREE",
31+
"@visokiotype": "CustomBlockSchema.TextCustomBlockPublicOption",
32+
"mandatory": true,
33+
"defaultValue": "http://127.0.0.1:24679/Admin+dashboards/Errors+Monitor.iox/"
34+
},
35+
{
36+
"name": "Param_Name",
37+
"title": "Name",
38+
"description": "The name of the parameter to change",
39+
"groupTitle": "Parameter",
40+
"width": "TWO",
41+
"@visokiotype": "CustomBlockSchema.TextCustomBlockPublicOption",
42+
"mandatory": true,
43+
"defaultValue": ""
44+
},
45+
{
46+
"name": "Param_Value",
47+
"title": "Value",
48+
"description": "The value to set in the parameter",
49+
"groupTitle": "Parameter",
50+
"width": "ONE",
51+
"@visokiotype": "CustomBlockSchema.TextCustomBlockPublicOption",
52+
"mandatory": false,
53+
"defaultValue": ""
54+
}
55+
],
56+
"blockOutputs": [],
57+
"docker": {
58+
"@visokiotype": "CustomBlockSchema.DockerCustomBlockPublicOption",
59+
"customBaseImage": null,
60+
"useCustomBaseImage": false,
61+
"customSystemLibraries": null,
62+
"installVisokioRepLibraries": false
63+
},
64+
"designLock": false,
65+
"apiMode": "BATCH"
66+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from omniscope.api import OmniscopeApi
2+
import urllib3
3+
import json
4+
5+
def send_update(omniscope_api, message):
6+
try:
7+
omniscope_api.update_message(message)
8+
except Exception:
9+
pass # For compatibility with older API versions
10+
11+
# Initialize the Omniscope API
12+
omniscope_api = OmniscopeApi()
13+
14+
# Read the parameter name and value from Omniscope options.
15+
# Ensure that your block has options "Param_Name" and "Param_Value" defined.
16+
param_name = omniscope_api.get_option("Param_Name")
17+
param_value = omniscope_api.get_option("Param_Value")
18+
19+
# Build the JSON payload for the parameter update request.
20+
payload = json.dumps({
21+
"updates": [
22+
{
23+
"name": param_name,
24+
"value": param_value
25+
}
26+
],
27+
"waitForIdle" : False
28+
})
29+
30+
# Retrieve the Iox_File_Url from the block options.
31+
iox_url = omniscope_api.get_option("Iox_File_Url")
32+
if not iox_url.endswith("/"):
33+
iox_url += "/"
34+
35+
# Construct the URL for updating project parameters.
36+
update_params_url = iox_url + "w/updateparams"
37+
38+
# Create an HTTP pool manager.
39+
http = urllib3.PoolManager()
40+
41+
# Log the update attempt.
42+
send_update(omniscope_api, f"Updating parameter '{param_name}' with value '{param_value}'...")
43+
44+
# Send the POST request to update the parameter.
45+
http.request('POST', update_params_url, headers={'Content-Type': 'application/json'}, body=payload)
46+
47+
# Close the API with a completion message.
48+
omniscope_api.close(f"Parameter '{param_name}' update enqueued.")

0 commit comments

Comments
 (0)