-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbrowse_event_frames.py
More file actions
107 lines (93 loc) · 3.95 KB
/
browse_event_frames.py
File metadata and controls
107 lines (93 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from osisoft_client import OSIsoftClient
from osisoft_plugin_common import get_credentials, build_select_choices, build_requests_params
from osisoft_domain_handling import DomainHandler
def do(payload, config, plugin_config, inputs):
if "config" in config:
config = config.get("config")
if "credentials" not in config:
return build_select_choices("Requires DSS v10.0.4 or above. Please use the OSIsoft Search custom dataset instead")
elif config.get("credentials") == {}:
return build_select_choices("Pick a credential")
domain_handler = DomainHandler(config)
auth_type, username, password, server_url, is_ssl_check_disabled, credential_error = get_credentials(config, can_raise=False)
if credential_error:
return build_select_choices(credential_error)
if not (auth_type and username and password):
return build_select_choices("Pick a credential")
if not username or not password:
return build_select_choices(
"Incorrect credential. "
+ "Go to you profile page > Credentials > Your preset, click the edit button and fill in you username and password details."
)
if not server_url:
return build_select_choices("Fill in the server address")
client = OSIsoftClient(server_url, auth_type, username, password, is_ssl_check_disabled=is_ssl_check_disabled)
parameter_name = payload.get("parameterName")
if parameter_name == "server_name":
choices = []
choices.extend(domain_handler.ui_side_url(client.get_asset_servers()))
return build_select_choices(choices)
if parameter_name == "database_name":
choices = []
next_url = config.get("server_name")
next_url = domain_handler.client_side_url(next_url)
if next_url:
choices.extend(
domain_handler.ui_side_url(
client.get_next_choices(next_url, "Self")
)
)
return build_select_choices(choices)
else:
return build_select_choices()
if parameter_name == "category_name":
choices = [{
"label": "<All>",
"value": None
}]
next_links = config.get("database_name")
if not next_links:
return build_select_choices()
next_url = next_links + "/elementcategories"
next_url = domain_handler.client_side_url(next_url)
choices.extend(
domain_handler.ui_side_url(
client.get_next_choices(next_url, "Self", use_name_as_link=True)
)
)
return build_select_choices(choices)
if parameter_name == "template_name":
choices = [{
"label": "<All>",
"value": None
}]
next_links = config.get("database_name")
if not next_links:
return build_select_choices()
next_url = next_links + "/elementtemplates"
next_url = domain_handler.client_side_url(next_url)
next_choices = domain_handler.ui_side_url(
client.get_next_choices(next_url, "Self", use_name_as_link=True, filter={'InstanceType': 'EventFrame'})
)
choices.extend(next_choices)
return build_select_choices(choices)
if parameter_name == "event_frame_to_retrieve":
choices = []
next_links = config.get("database_name")
if not next_links:
return build_select_choices(choices)
next_url = next_links + "/eventframes"
next_url = domain_handler.client_side_url(next_url)
params = build_requests_params(
**config
)
endpoint_name = "Self"
if config.get("must_retrieve_metrics"):
endpoint_name = config.get("data_type", "Self")
choices.extend(
domain_handler.ui_side_url(
client.get_next_choices(next_url, endpoint_name, params=params)
)
)
return build_select_choices(choices)
return build_select_choices()