python-eigen-ingenuity-nocli 0.5.6b4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- eigeningenuity/__init__.py +29 -0
- eigeningenuity/assetmodel.py +433 -0
- eigeningenuity/auth.py +178 -0
- eigeningenuity/core/__init__.py +236 -0
- eigeningenuity/elastic.py +171 -0
- eigeningenuity/events.py +88 -0
- eigeningenuity/historian.py +786 -0
- eigeningenuity/historianmulti.py +481 -0
- eigeningenuity/settings.py +87 -0
- eigeningenuity/smartdash.py +103 -0
- eigeningenuity/sql.py +132 -0
- eigeningenuity/util.py +548 -0
- modelbuilder/__init__.py +7 -0
- modelbuilder/src/__init__.py +0 -0
- modelbuilder/src/assetmodelbuilder.py +164 -0
- modelbuilder/src/assetmodelcsvwriter.py +31 -0
- modelbuilder/src/assetmodelutilities.py +51 -0
- modelbuilder/src/configmanager.py +500 -0
- modelbuilder/src/connectors/__init__.py +0 -0
- modelbuilder/src/connectors/boltconnector.py +108 -0
- modelbuilder/src/connectors/dbconnectors.py +40 -0
- modelbuilder/src/connectors/genericconnector.py +30 -0
- modelbuilder/src/connectors/httpsconnector.py +132 -0
- modelbuilder/src/csvcontentsmanager.py +135 -0
- modelbuilder/src/csvwriter.py +305 -0
- modelbuilder/src/fileanalyser.py +91 -0
- modelbuilder/src/filemanager.py +400 -0
- modelbuilder/src/messages.py +61 -0
- modelbuilder/src/processors/__init__.py +0 -0
- modelbuilder/src/processors/cypherfileprocessor.py +73 -0
- modelbuilder/src/processors/labelmanager.py +133 -0
- modelbuilder/src/processors/nodefileprocessor.py +282 -0
- modelbuilder/src/processors/propertymanager.py +129 -0
- modelbuilder/src/processors/relationshipfileprocessor.py +285 -0
- modelbuilder/src/processors/relationshipmanager.py +31 -0
- modelbuilder/src/queries/__init__.py +0 -0
- modelbuilder/src/queries/cypherbuilder.py +323 -0
- modelbuilder/src/queries/query.py +82 -0
- modelbuilder/src/queries/typedefs.py +180 -0
- modelbuilder/src/versionmanager.py +356 -0
- python_eigen_ingenuity_nocli-0.5.6b4.dist-info/METADATA +30 -0
- python_eigen_ingenuity_nocli-0.5.6b4.dist-info/RECORD +44 -0
- python_eigen_ingenuity_nocli-0.5.6b4.dist-info/WHEEL +5 -0
- python_eigen_ingenuity_nocli-0.5.6b4.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"""Eigen Ingenuity - Core Functions
|
|
2
|
+
|
|
3
|
+
This module deals with basic common tasks to do with interacting with an
|
|
4
|
+
Eigen Ingenuity server.
|
|
5
|
+
|
|
6
|
+
In order to find a particular subsystem ("app"), you can use e.g.
|
|
7
|
+
|
|
8
|
+
ei = EigenServer(servername)
|
|
9
|
+
ei.get_historian(datasource)
|
|
10
|
+
|
|
11
|
+
If no server name or URL is given it searches sys.argv for a --eigenserver
|
|
12
|
+
argument, falling back on the environment variable EIGENSERVER.
|
|
13
|
+
This may either be in the form of a URL (http://foo:8087/) or a
|
|
14
|
+
hostname, or hostname:port combination. If no variable is set, it defaults
|
|
15
|
+
to http://localhost:8080/
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import sys, os, requests
|
|
19
|
+
from eigeningenuity.util import _do_eigen_json_request, EigenException, RemoteServerException, serverTimeToPythonTime, _authenticate_azure_user
|
|
20
|
+
import eigeningenuity.settings as settings
|
|
21
|
+
|
|
22
|
+
_INSTANCE = None
|
|
23
|
+
class EigenServer (object):
|
|
24
|
+
def __init__(self, name:str = None, disableSsl = False):
|
|
25
|
+
"""Takes the base URL for the Eigen Ingenuity server.
|
|
26
|
+
"""
|
|
27
|
+
if name is None:
|
|
28
|
+
try:
|
|
29
|
+
for i in range(len(sys.argv)):
|
|
30
|
+
arg = sys.argv[i]
|
|
31
|
+
|
|
32
|
+
if arg.startswith("--eigenserver="):
|
|
33
|
+
name = arg[14 : ]
|
|
34
|
+
break
|
|
35
|
+
elif arg == "--eigenserver":
|
|
36
|
+
name = sys.argv[i + 1]
|
|
37
|
+
break
|
|
38
|
+
else:
|
|
39
|
+
name = os.environ['EIGENSERVER']
|
|
40
|
+
except:
|
|
41
|
+
pass
|
|
42
|
+
|
|
43
|
+
try:
|
|
44
|
+
if name.startswith("http://") or name.startswith("https://"):
|
|
45
|
+
if name.endswith("/"):
|
|
46
|
+
baseurl = name
|
|
47
|
+
else:
|
|
48
|
+
baseurl = name + "/"
|
|
49
|
+
else:
|
|
50
|
+
baseurl = "https://" + name + "/"
|
|
51
|
+
except:
|
|
52
|
+
baseurl = "http://localhost:8080/"
|
|
53
|
+
|
|
54
|
+
if settings._azure_auth_enabled_:
|
|
55
|
+
preflight = requests.get(baseurl + "historian-servlet/jsonbridge/calc?cmd=LISTHISTORIANS", verify=False)
|
|
56
|
+
|
|
57
|
+
if preflight.status_code != 200:
|
|
58
|
+
raise EigenException("Could not find an ingenuity Instance at this url: ", baseurl)
|
|
59
|
+
else:
|
|
60
|
+
try:
|
|
61
|
+
preflight.json()
|
|
62
|
+
self.auth = False
|
|
63
|
+
except:
|
|
64
|
+
self.auth = True
|
|
65
|
+
else:
|
|
66
|
+
self.auth = False
|
|
67
|
+
|
|
68
|
+
self.__baseurl = baseurl
|
|
69
|
+
self.__disablessl = disableSsl
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def getEigenServerUrl(self):
|
|
73
|
+
"""Find the base URL for the Eigen Ingenuity server.
|
|
74
|
+
"""
|
|
75
|
+
return self.__baseurl
|
|
76
|
+
|
|
77
|
+
def getAppsInfo(self):
|
|
78
|
+
"""Request information about install Eigen Ingenuity apps/components.
|
|
79
|
+
"""
|
|
80
|
+
return _do_eigen_json_request(self.__baseurl + "eigenpluscore-servlet/prodseminfo", cmd = "GETAPPS",auth=self.auth, _cachetime = 10)
|
|
81
|
+
|
|
82
|
+
def listApps(self):
|
|
83
|
+
return list(self.getAppsInfo().keys())
|
|
84
|
+
|
|
85
|
+
def getAppUrl(self, appname):
|
|
86
|
+
"""Find the base URL for a specified Eigen Ingenuity apps. Note this is
|
|
87
|
+
something like "historian-servlet" not "trend" or "jsonbridgehistorian".
|
|
88
|
+
Think "module" rather than "tool".
|
|
89
|
+
Returns None if the app is not installed.
|
|
90
|
+
"""
|
|
91
|
+
apps = self.getAppsInfo()
|
|
92
|
+
if appname in apps:
|
|
93
|
+
# Remove leading / from appname if present
|
|
94
|
+
appurl = apps[appname]['url']
|
|
95
|
+
if appurl.startswith('/'):
|
|
96
|
+
appurl = appurl[1:]
|
|
97
|
+
return self.__baseurl + appurl
|
|
98
|
+
else:
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
def listDataSourceTypes(self):
|
|
102
|
+
"""Request information about installed Eigen Ingenuity Factory Types.
|
|
103
|
+
"""
|
|
104
|
+
return _do_eigen_json_request(self.__baseurl + "eigenpluscore-servlet/prodseminfo", cmd = "LISTFACTORYTYPES",auth=self.auth, _cachetime = 10)
|
|
105
|
+
|
|
106
|
+
def listDataSources(self):
|
|
107
|
+
return _do_eigen_json_request(self.__baseurl + "historian/list")
|
|
108
|
+
|
|
109
|
+
def listWritableDataSources(self):
|
|
110
|
+
return _do_eigen_json_request(self.__baseurl + "historian/listwritable")
|
|
111
|
+
|
|
112
|
+
def _listDataSources_legacy(self, type):
|
|
113
|
+
"""List the instances for a specified Eigen Ingenuity Factory Type
|
|
114
|
+
Returns None if there are no instances
|
|
115
|
+
"""
|
|
116
|
+
data_source_types = self.listDataSourceTypes()
|
|
117
|
+
if type in data_source_types:
|
|
118
|
+
args = {}
|
|
119
|
+
args['cmd'] = "LISTFACTORYINSTANCES"
|
|
120
|
+
args['type'] = type
|
|
121
|
+
return _do_eigen_json_request(self.__baseurl + "eigenpluscore-servlet/prodseminfo",auth=self.auth, **args)
|
|
122
|
+
else:
|
|
123
|
+
return None
|
|
124
|
+
|
|
125
|
+
def getDefaultDataSource(self, type):
|
|
126
|
+
"""Gets the default instance for the named Factory Type. Returns None if none has been specified."""
|
|
127
|
+
data_source_types = self.listDataSourceTypes()
|
|
128
|
+
if type in data_source_types:
|
|
129
|
+
args = {}
|
|
130
|
+
args['cmd'] = "GETDEFAULTFACTORYINSTANCE"
|
|
131
|
+
args['type'] = type
|
|
132
|
+
try:
|
|
133
|
+
return _do_eigen_json_request(self.__baseurl + "eigenpluscore-servlet/prodseminfo",auth=self.auth, **args)
|
|
134
|
+
except RemoteServerException:
|
|
135
|
+
return None
|
|
136
|
+
else:
|
|
137
|
+
return None
|
|
138
|
+
|
|
139
|
+
def listFeatureProperties(self):
|
|
140
|
+
"""Request information about installed Eigen Ingenuity Feature Properties.
|
|
141
|
+
"""
|
|
142
|
+
return _do_eigen_json_request(self.__baseurl + "eigenpluscore-servlet/prodseminfo", cmd = "LISTFEATUREPROPERTIES",auth=self.auth)
|
|
143
|
+
|
|
144
|
+
def getFeatureProperty(self, property):
|
|
145
|
+
"""Get the value of the specified Eigen Ingenuity Feature Property
|
|
146
|
+
"""
|
|
147
|
+
args = {}
|
|
148
|
+
args['cmd'] = "GETFEATUREPROPERTY"
|
|
149
|
+
args['property'] = property
|
|
150
|
+
try:
|
|
151
|
+
return _do_eigen_json_request(self.__baseurl + "eigenpluscore-servlet/prodseminfo",auth=self.auth, **args)
|
|
152
|
+
except RemoteServerException:
|
|
153
|
+
return None
|
|
154
|
+
|
|
155
|
+
def getServerTimeInFloatingPointMillis(self):
|
|
156
|
+
"""Get the current time from the Server in floating point milliseconds.
|
|
157
|
+
"""
|
|
158
|
+
args = {}
|
|
159
|
+
args['cmd'] = "GETSERVERTIME"
|
|
160
|
+
try:
|
|
161
|
+
ts = _do_eigen_json_request(self.__baseurl + "eigenpluscore-servlet/prodseminfo",auth=self.auth, **args)
|
|
162
|
+
return serverTimeToPythonTime(ts)
|
|
163
|
+
except RemoteServerException:
|
|
164
|
+
return None
|
|
165
|
+
|
|
166
|
+
def getServerTimezone(self):
|
|
167
|
+
"""Get the current timezone and DST status from the Server
|
|
168
|
+
"""
|
|
169
|
+
args = {}
|
|
170
|
+
args['cmd'] = "GETSERVERTIMEZONE"
|
|
171
|
+
try:
|
|
172
|
+
tz = _do_eigen_json_request(self.__baseurl + "eigenpluscore-servlet/prodseminfo",auth=self.auth, **args)
|
|
173
|
+
return tz
|
|
174
|
+
except RemoteServerException:
|
|
175
|
+
return None
|
|
176
|
+
|
|
177
|
+
def getHistorian(self, *args, **kwargs):
|
|
178
|
+
from eigeningenuity.historian import get_historian
|
|
179
|
+
return get_historian(*args, eigenserver=self, **kwargs)
|
|
180
|
+
|
|
181
|
+
def getAssetModel(self, *args, **kwargs):
|
|
182
|
+
from eigeningenuity.assetmodel import get_assetmodel
|
|
183
|
+
return get_assetmodel(*args, eigenserver=self, **kwargs)
|
|
184
|
+
|
|
185
|
+
def getSmartdash(self, *args, **kwargs):
|
|
186
|
+
from eigeningenuity.smartdash import get_smartdash
|
|
187
|
+
return get_smartdash(*args, eigenserver=self, **kwargs)
|
|
188
|
+
|
|
189
|
+
def getDebugletsForApp(self, *args, **kwargs):
|
|
190
|
+
from eigeningenuity.debuglets import get_debuglets_for_app
|
|
191
|
+
return get_debuglets_for_app(*args, eigenserver=self, **kwargs)
|
|
192
|
+
|
|
193
|
+
def getDebuglets(self, *args, **kwargs):
|
|
194
|
+
from eigeningenuity.debuglets import get_debuglets
|
|
195
|
+
return get_debuglets(*args, eigenserver=self, **kwargs)
|
|
196
|
+
|
|
197
|
+
def get_default_server():
|
|
198
|
+
global _INSTANCE
|
|
199
|
+
|
|
200
|
+
if _INSTANCE is None:
|
|
201
|
+
_INSTANCE = EigenServer()
|
|
202
|
+
|
|
203
|
+
return _INSTANCE
|
|
204
|
+
|
|
205
|
+
def get_eigenserver_url():
|
|
206
|
+
return get_default_server().getEigenserverUrl()
|
|
207
|
+
|
|
208
|
+
def get_apps_info():
|
|
209
|
+
return get_default_server().getAppsInfo()
|
|
210
|
+
|
|
211
|
+
def list_apps():
|
|
212
|
+
return get_default_server().listApps()
|
|
213
|
+
|
|
214
|
+
def get_app_url(appname):
|
|
215
|
+
return get_default_server().getAppUrl(appname)
|
|
216
|
+
|
|
217
|
+
def list_data_source_types():
|
|
218
|
+
return get_default_server().listDataSourceTypes()
|
|
219
|
+
|
|
220
|
+
def list_data_sources(type):
|
|
221
|
+
return get_default_server()._listDataSources_legacy(type)
|
|
222
|
+
|
|
223
|
+
def get_default_data_source(type):
|
|
224
|
+
return get_default_server().getDefaultDataSource(type)
|
|
225
|
+
|
|
226
|
+
def list_feature_properties():
|
|
227
|
+
return get_default_server().listFeatureProperties()
|
|
228
|
+
|
|
229
|
+
def get_feature_property(property):
|
|
230
|
+
return get_default_server().getFeatureProperty(property)
|
|
231
|
+
|
|
232
|
+
def get_server_time_in_floating_point_millis():
|
|
233
|
+
return get_default_server().getServerTimeInFloatingPointMillis()
|
|
234
|
+
|
|
235
|
+
def get_server_timezone():
|
|
236
|
+
return get_default_server().getServerTimezone()
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""Eigen Ingenuity - Elasticsearch
|
|
2
|
+
|
|
3
|
+
This package deals with the Eigen Ingenuity Elasticsearch database.
|
|
4
|
+
|
|
5
|
+
To retrieve an AssetObject use matchNode, or execute a custom cypher query with
|
|
6
|
+
|
|
7
|
+
from eigeningenuity.assetmodel import matchNode
|
|
8
|
+
from time import gmtime, asctime
|
|
9
|
+
|
|
10
|
+
nodes = matchNodes("code","System_")
|
|
11
|
+
|
|
12
|
+
for node in nodes:
|
|
13
|
+
code = node.code
|
|
14
|
+
print(code)
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from eigeningenuity import EigenServer
|
|
18
|
+
from urllib.parse import quote as urlquote
|
|
19
|
+
from eigeningenuity.util import is_list,force_list,_do_eigen_json_request,EigenException
|
|
20
|
+
from eigeningenuity.core import get_default_server
|
|
21
|
+
import pandas as pd
|
|
22
|
+
import datetime as dt
|
|
23
|
+
import json
|
|
24
|
+
import requests
|
|
25
|
+
import fnmatch
|
|
26
|
+
from requests.exceptions import ConnectionError
|
|
27
|
+
from urllib.error import URLError
|
|
28
|
+
from typing import Union
|
|
29
|
+
|
|
30
|
+
from urllib3.exceptions import InsecureRequestWarning
|
|
31
|
+
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
|
32
|
+
|
|
33
|
+
class ElasticConnection (object):
|
|
34
|
+
"""An elasticsearch instance which talks the Eigen elastic endpoint.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(self, baseurl, auth):
|
|
38
|
+
"""This is a constructor. It takes in a URL like http://infra:8080/ei-applet/search/"""
|
|
39
|
+
self.baseurl = baseurl
|
|
40
|
+
self.auth = auth
|
|
41
|
+
|
|
42
|
+
def _doJsonRequest(self,cmd,params):
|
|
43
|
+
url = self.baseurl + "?cmd=" + urlquote(cmd)
|
|
44
|
+
return _do_eigen_json_request(url,self.auth,**params)
|
|
45
|
+
|
|
46
|
+
def _testConnection(self,instance,index):
|
|
47
|
+
"""Preflight Request to verify connection to ingenuity"""
|
|
48
|
+
try:
|
|
49
|
+
status = requests.get(self.baseurl + "?cmd=DODIRECTSEARCH&clientname=" + instance + "&index=" + index + "&search=%7B%7D", verify=False).status_code
|
|
50
|
+
if status != 200:
|
|
51
|
+
raise ConnectionError(
|
|
52
|
+
"Invalid API Response from " + self.baseurl + "?cmd=DODIRECTSEARCH&clientname" + instance + ". Please check the base url is correct, the instance is running and has an elasticsearch database.")
|
|
53
|
+
except (URLError, ConnectionError):
|
|
54
|
+
raise ConnectionError ("Failed to connect to ingenuity instance at " + self.baseurl + "?cmd=DODIRECTSEARCH&clientname=" + instance + "&index=" + index + ". Please check the url is correct and the instance is up.")
|
|
55
|
+
|
|
56
|
+
return status
|
|
57
|
+
|
|
58
|
+
def listIndices(self,instance:str, wildcard:str=None):
|
|
59
|
+
"""Lists all indices in Elastic Database.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
instance: The elasticsearch instance to query indices from.
|
|
63
|
+
wildcard: (Optional) Return indices that match the wildcard
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
List of all indices
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
args = {"clientname": instance}
|
|
70
|
+
|
|
71
|
+
mappings = self._doJsonRequest("GETMAPPINGS",args)
|
|
72
|
+
|
|
73
|
+
if wildcard is not None:
|
|
74
|
+
indices = [item for item in mappings if wildcard in item]
|
|
75
|
+
else:
|
|
76
|
+
indices = mappings
|
|
77
|
+
|
|
78
|
+
return indices
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def checkIndices(self,instance:str,indices:str):
|
|
82
|
+
"""Checks for indices in Elastic Database.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
instance: The elasticsearch instance to query instances from.
|
|
86
|
+
indices: The elasticsearch indices to search for
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
Boolean indicating existence of the index, or dict of form {index: boolean}
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
foundIndices = self.listIndices(instance)
|
|
93
|
+
indices = force_list(indices)
|
|
94
|
+
|
|
95
|
+
result = {}
|
|
96
|
+
|
|
97
|
+
if len(indices) != 1:
|
|
98
|
+
for index in indices:
|
|
99
|
+
if index in foundIndices:
|
|
100
|
+
result[index] = True
|
|
101
|
+
else:
|
|
102
|
+
result[index] = False
|
|
103
|
+
else:
|
|
104
|
+
if indices[0] in foundIndices:
|
|
105
|
+
return True
|
|
106
|
+
else:
|
|
107
|
+
return False
|
|
108
|
+
|
|
109
|
+
return result
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def executeRawQuery(self,index:str, query:Union[str,dict], instance:str = "elasticsearch-int", output:str = "json", filepath:str = None):
|
|
113
|
+
"""Executes a raw cypher query against Elastic.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
index: The elasticsearch index to query
|
|
117
|
+
query: The body of the query
|
|
118
|
+
instance: (Optional) The instance of elasticsearch to query. Defaults to elasticsearch-int
|
|
119
|
+
output: (Optional) The format in which to return the data. Accepts one of: "raw" - The raw json returned by the API; "json" - A processed version of the json response; "df" - A formatted pandas dataframe object; "file" - Writes the response to a .json file in the local directory. Defaults to "json"
|
|
120
|
+
filepath: (Optional) Name and path to the .json file that will be created/overwritten. If omitted, will create a file in the current directory with a generated name. Has no effect unless output is "file".
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
Elasticsearch API response to the query, the format is dependent on the output parameter
|
|
124
|
+
"""
|
|
125
|
+
# self._testConnection(instance,index)
|
|
126
|
+
validOutputTypes = ["raw", "json", "df", "file"]
|
|
127
|
+
if output not in validOutputTypes:
|
|
128
|
+
raise ValueError("output must be one of %r." % validOutputTypes)
|
|
129
|
+
|
|
130
|
+
if type(query) is dict:
|
|
131
|
+
query = json.dumps(query)
|
|
132
|
+
|
|
133
|
+
args = {}
|
|
134
|
+
args["clientname"] = instance
|
|
135
|
+
args["index"] = index
|
|
136
|
+
args["search"] = query
|
|
137
|
+
|
|
138
|
+
response = self._doJsonRequest("DODIRECTSEARCH", args)
|
|
139
|
+
|
|
140
|
+
if "error" in response.keys():
|
|
141
|
+
raise EigenException("Invalid request", response["error"])
|
|
142
|
+
|
|
143
|
+
if output == "raw":
|
|
144
|
+
return response
|
|
145
|
+
elif output == "json":
|
|
146
|
+
return response['results']
|
|
147
|
+
elif output == "df":
|
|
148
|
+
return pd.json_normalize(response['results'])
|
|
149
|
+
elif output == "file":
|
|
150
|
+
if filepath is None:
|
|
151
|
+
filepath = "eigenElasticResponse-" + index + "-" + str(dt.datetime.now().strftime("%Y-%m-%dT%H:%M:%S"))
|
|
152
|
+
with open(filepath + ".json", "w") as f:
|
|
153
|
+
f.write(json.dumps(response, indent=4))
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def get_elastic(eigenserver:EigenServer = None):
|
|
158
|
+
"""Instantiate an elasticsearch connection for the given EigenServer.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
eigenserver: (Optional) An EigenServer Object linked to the ingenuity url containing the elasticsearch. Can be omitted if environmental variable "EIGENSERVER" exists and is equal to the Ingenuity base url
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
An Object that can be used to query elasticsearch data from the ingenuity.
|
|
165
|
+
"""
|
|
166
|
+
if eigenserver is None:
|
|
167
|
+
eigenserver = get_default_server()
|
|
168
|
+
elif type(eigenserver) == str:
|
|
169
|
+
eigenserver = EigenServer(eigenserver)
|
|
170
|
+
|
|
171
|
+
return ElasticConnection(eigenserver.getEigenServerUrl() + "ei-applet/search", eigenserver.auth)
|
eigeningenuity/events.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
|
|
3
|
+
from eigeningenuity.core import get_default_server, EigenServer
|
|
4
|
+
from eigeningenuity.util import get_eigenserver, divide_chunks, parseEvents, _do_chunked_eigen_post_request
|
|
5
|
+
|
|
6
|
+
from typing import Union
|
|
7
|
+
|
|
8
|
+
class EventLog (object):
|
|
9
|
+
"""An elasticsearch instance which talks the Eigen elastic endpoint.
|
|
10
|
+
"""
|
|
11
|
+
def __init__(self, baseurl, auth):
|
|
12
|
+
"""This is a constructor. It takes in a URL like http://infra:8080/ei-applet/search/"""
|
|
13
|
+
self.baseurl = baseurl
|
|
14
|
+
self.eigenserver = get_eigenserver(baseurl)
|
|
15
|
+
self.auth = auth
|
|
16
|
+
|
|
17
|
+
def _testConnection(self):
|
|
18
|
+
"""Preflight Request to verify connection to ingenuity"""
|
|
19
|
+
try:
|
|
20
|
+
status = requests.get(self.baseurl, verify=False).status_code
|
|
21
|
+
except (ConnectionError):
|
|
22
|
+
raise ConnectionError ("Failed to connect to ingenuity instance at " + self.eigenserver + ". Please check the url is correct and the instance is up.")
|
|
23
|
+
|
|
24
|
+
def _doJsonRequest(self,relative_url,data,label):
|
|
25
|
+
url = self.baseurl + relative_url
|
|
26
|
+
return _do_chunked_eigen_post_request(url,data,label,self.auth)
|
|
27
|
+
|
|
28
|
+
def pushToEventlog(self, events):
|
|
29
|
+
"""
|
|
30
|
+
Push one or more events to the ingenuity eventlog, accepts any event structure
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
events: A single event as dict, many events as a list of dicts, or the string filepath of a file containing events
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
A boolean representing the successful push of all events. False if at least one event failed to be created
|
|
37
|
+
"""
|
|
38
|
+
events = parseEvents(events)
|
|
39
|
+
relative_url = "events/save-multiple"
|
|
40
|
+
label = "events"
|
|
41
|
+
|
|
42
|
+
failures = self._doJsonRequest(relative_url, events, label)
|
|
43
|
+
|
|
44
|
+
if failures:
|
|
45
|
+
print("Some Events failed to push")
|
|
46
|
+
return failures
|
|
47
|
+
else:
|
|
48
|
+
return True
|
|
49
|
+
|
|
50
|
+
def pushTo365(self, events:Union[dict,list,str]) -> bool:
|
|
51
|
+
"""
|
|
52
|
+
Push one or more events to the office 365 connector, only accepts pre-defined event structures
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
events: Can only accept event structures that have been pre-defined in ingenuity. A single event as dict, many events as a list of dicts, or the string filepath of a file containing events
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
A boolean representing the successful push of all events. False if at least one event failed to be created
|
|
59
|
+
"""
|
|
60
|
+
events = parseEvents(events)
|
|
61
|
+
relative_url = "eventbus/publish-multiple"
|
|
62
|
+
label = "events"
|
|
63
|
+
|
|
64
|
+
failures = self._doJsonRequest(relative_url, events, label)
|
|
65
|
+
|
|
66
|
+
if failures:
|
|
67
|
+
print("Some Events failed to push")
|
|
68
|
+
return failures
|
|
69
|
+
else:
|
|
70
|
+
return True
|
|
71
|
+
|
|
72
|
+
def get_eventlog(eigenserver:EigenServer=None):
|
|
73
|
+
"""
|
|
74
|
+
Connect to Assetmodel of eigenserver. If eigenserver is not provided this will default to the EIGENSERVER environmental variable
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
eigenserver: An instance of EigenServer() to query
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
An object defining a connection to the AssetModel
|
|
81
|
+
"""
|
|
82
|
+
if eigenserver is None:
|
|
83
|
+
eigenserver = get_default_server()
|
|
84
|
+
elif type(eigenserver) == str:
|
|
85
|
+
eigenserver = EigenServer(eigenserver)
|
|
86
|
+
|
|
87
|
+
return EventLog(eigenserver.getEigenServerUrl() + "eventlog-servlet" + "/", eigenserver.auth)
|
|
88
|
+
|