brynq-sdk-elastic 2.2.0__tar.gz → 2.2.1__tar.gz
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.
- {brynq_sdk_elastic-2.2.0 → brynq_sdk_elastic-2.2.1}/PKG-INFO +1 -1
- {brynq_sdk_elastic-2.2.0 → brynq_sdk_elastic-2.2.1}/brynq_sdk/elastic/elastic.py +85 -70
- {brynq_sdk_elastic-2.2.0 → brynq_sdk_elastic-2.2.1}/brynq_sdk_elastic.egg-info/PKG-INFO +1 -1
- {brynq_sdk_elastic-2.2.0 → brynq_sdk_elastic-2.2.1}/setup.py +1 -1
- {brynq_sdk_elastic-2.2.0 → brynq_sdk_elastic-2.2.1}/brynq_sdk/elastic/__init__.py +0 -0
- {brynq_sdk_elastic-2.2.0 → brynq_sdk_elastic-2.2.1}/brynq_sdk_elastic.egg-info/SOURCES.txt +0 -0
- {brynq_sdk_elastic-2.2.0 → brynq_sdk_elastic-2.2.1}/brynq_sdk_elastic.egg-info/dependency_links.txt +0 -0
- {brynq_sdk_elastic-2.2.0 → brynq_sdk_elastic-2.2.1}/brynq_sdk_elastic.egg-info/not-zip-safe +0 -0
- {brynq_sdk_elastic-2.2.0 → brynq_sdk_elastic-2.2.1}/brynq_sdk_elastic.egg-info/requires.txt +0 -0
- {brynq_sdk_elastic-2.2.0 → brynq_sdk_elastic-2.2.1}/brynq_sdk_elastic.egg-info/top_level.txt +0 -0
- {brynq_sdk_elastic-2.2.0 → brynq_sdk_elastic-2.2.1}/setup.cfg +0 -0
|
@@ -96,29 +96,34 @@ class Elastic:
|
|
|
96
96
|
:param space_name: The name of the space
|
|
97
97
|
:return: The status of the creation of the space
|
|
98
98
|
"""
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
99
|
+
try:
|
|
100
|
+
if self.disabled:
|
|
101
|
+
return 'Space creation disabled'
|
|
102
|
+
|
|
103
|
+
url = f'{self.kibana_host}/api/spaces/space'
|
|
104
|
+
data = {
|
|
105
|
+
"id": space_name,
|
|
106
|
+
"name": space_name,
|
|
107
|
+
"description": f"This is the space for {space_name}",
|
|
108
|
+
"color": "#aabbcc",
|
|
109
|
+
"initials": space_name[0:2].upper(),
|
|
110
|
+
"disabledFeatures": [],
|
|
111
|
+
}
|
|
111
112
|
|
|
112
|
-
|
|
113
|
+
response = requests.head(url=url + fr'/{space_name}', headers=self.kibana_headers, verify=self.verify)
|
|
113
114
|
|
|
114
|
-
if response.status_code == 200:
|
|
115
|
-
return f'Index \'{space_name}\' already exists'
|
|
116
|
-
else:
|
|
117
|
-
response = requests.post(url=url, headers=self.kibana_headers, data=json.dumps(data), verify=self.verify)
|
|
118
115
|
if response.status_code == 200:
|
|
119
|
-
return f'
|
|
116
|
+
return f'Index \'{space_name}\' already exists'
|
|
120
117
|
else:
|
|
121
|
-
|
|
118
|
+
response = requests.post(url=url, headers=self.kibana_headers, data=json.dumps(data), verify=self.verify)
|
|
119
|
+
if response.status_code == 200:
|
|
120
|
+
return f'space {space_name} created'
|
|
121
|
+
else:
|
|
122
|
+
raise ConnectionError(f'Could not create space {space_name} with status code: {response.status_code}. Response: {response.text}')
|
|
123
|
+
except:
|
|
124
|
+
message = "Could not create space, since this is not strictly necessary to write logs, continue without it"
|
|
125
|
+
print(message)
|
|
126
|
+
return message
|
|
122
127
|
|
|
123
128
|
def create_data_view(self, space_name: str, view_name: str, name: str, time_field: str) -> str:
|
|
124
129
|
"""
|
|
@@ -128,29 +133,34 @@ class Elastic:
|
|
|
128
133
|
:param time_field: The name of the time field
|
|
129
134
|
:return: The status of the creation of the data view
|
|
130
135
|
"""
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
"
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
try:
|
|
137
|
+
if self.disabled:
|
|
138
|
+
return 'Data view creation disabled'
|
|
139
|
+
|
|
140
|
+
url = f'{self.kibana_host}/s/{space_name}/api/data_views/data_view'
|
|
141
|
+
data = {
|
|
142
|
+
"data_view": {
|
|
143
|
+
"title": f'{view_name}*',
|
|
144
|
+
"id": f'{view_name}',
|
|
145
|
+
"name": f'{name}',
|
|
146
|
+
"timeFieldName": time_field
|
|
147
|
+
}
|
|
141
148
|
}
|
|
142
|
-
}
|
|
143
149
|
|
|
144
|
-
|
|
150
|
+
response = requests.head(url=url + fr'/{view_name}', headers=self.kibana_headers, verify=self.verify)
|
|
145
151
|
|
|
146
|
-
if response.status_code == 200:
|
|
147
|
-
return f'Data view \'{view_name}\' already exists'
|
|
148
|
-
else:
|
|
149
|
-
response = requests.post(url=url, headers=self.kibana_headers, data=json.dumps(data), verify=self.verify)
|
|
150
152
|
if response.status_code == 200:
|
|
151
|
-
return f'
|
|
153
|
+
return f'Data view \'{view_name}\' already exists'
|
|
152
154
|
else:
|
|
153
|
-
|
|
155
|
+
response = requests.post(url=url, headers=self.kibana_headers, data=json.dumps(data), verify=self.verify)
|
|
156
|
+
if response.status_code == 200:
|
|
157
|
+
return f'data view {view_name} created'
|
|
158
|
+
else:
|
|
159
|
+
raise ConnectionError(f'Could not create data view {view_name} with status code: {response.status_code}. Response: {response.text}')
|
|
160
|
+
except:
|
|
161
|
+
message = "Could not create data view, since this is not strictly necessary to write logs, continue without it"
|
|
162
|
+
print(message)
|
|
163
|
+
return message
|
|
154
164
|
|
|
155
165
|
def get_all_docs_from_index(self, index: str) -> pd.DataFrame:
|
|
156
166
|
"""
|
|
@@ -248,44 +258,49 @@ class Elastic:
|
|
|
248
258
|
:param index: one or more index names in a list.
|
|
249
259
|
:return: The response of the request to elasticsearch
|
|
250
260
|
"""
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
'
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
'kibana': [{
|
|
267
|
-
'feature': {
|
|
268
|
-
'dashboard': ['read'],
|
|
269
|
-
'discover': ['read']
|
|
261
|
+
try:
|
|
262
|
+
if self.disabled:
|
|
263
|
+
return 'Role creation disabled'
|
|
264
|
+
|
|
265
|
+
url = f'{self.kibana_host}/api/security/role/{role_name}'
|
|
266
|
+
# Set the body
|
|
267
|
+
body = {
|
|
268
|
+
'elasticsearch': {
|
|
269
|
+
'cluster': ['transport_client'],
|
|
270
|
+
'indices': [
|
|
271
|
+
{
|
|
272
|
+
'names': [index],
|
|
273
|
+
'privileges': ['read', 'write', 'read_cross_cluster', 'view_index_metadata', 'index']
|
|
274
|
+
}
|
|
275
|
+
]
|
|
270
276
|
},
|
|
271
|
-
'
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
277
|
+
'kibana': [{
|
|
278
|
+
'feature': {
|
|
279
|
+
'dashboard': ['read'],
|
|
280
|
+
'discover': ['read']
|
|
281
|
+
},
|
|
282
|
+
'spaces': [role_name],
|
|
283
|
+
}],
|
|
284
|
+
'metadata': {
|
|
285
|
+
'version': 1
|
|
286
|
+
}
|
|
275
287
|
}
|
|
276
|
-
|
|
277
|
-
body = json.dumps(body)
|
|
288
|
+
body = json.dumps(body)
|
|
278
289
|
|
|
279
|
-
|
|
290
|
+
response = requests.head(url=url, headers=self.kibana_headers, verify=self.verify)
|
|
280
291
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
else:
|
|
284
|
-
response = requests.put(url=url, data=body, headers=self.kibana_headers, verify=self.verify)
|
|
285
|
-
if response.status_code == 204:
|
|
286
|
-
return f'Role {role_name} created'
|
|
292
|
+
if response.status_code == 200:
|
|
293
|
+
return f'Role \'{role_name}\' already exists'
|
|
287
294
|
else:
|
|
288
|
-
|
|
295
|
+
response = requests.put(url=url, data=body, headers=self.kibana_headers, verify=self.verify)
|
|
296
|
+
if response.status_code == 204:
|
|
297
|
+
return f'Role {role_name} created'
|
|
298
|
+
else:
|
|
299
|
+
raise ConnectionError(f'Could not create role {role_name} with status code: {response.status_code}. Response: {response.text}')
|
|
300
|
+
except:
|
|
301
|
+
message = "Could not create role, since this is not strictly necessary to write logs, continue without it"
|
|
302
|
+
print(message)
|
|
303
|
+
return message
|
|
289
304
|
|
|
290
305
|
def get_indices(self) -> dict:
|
|
291
306
|
"""
|
|
File without changes
|
|
File without changes
|
{brynq_sdk_elastic-2.2.0 → brynq_sdk_elastic-2.2.1}/brynq_sdk_elastic.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{brynq_sdk_elastic-2.2.0 → brynq_sdk_elastic-2.2.1}/brynq_sdk_elastic.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|