Skip to content

Commit ae2b3ab

Browse files
committed
feat: init commit, new function to retrieve stanzas based on rest
1 parent 619a53e commit ae2b3ab

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

solnlib/modular_input/event_writer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ def __init__(
233233
scheme, host, hec_port = utils.extract_http_scheme_host_port(hec_uri)
234234
else:
235235
if not all([scheme, host, port]):
236-
scheme, host, port = get_splunkd_access_info(session_key=self._session_key)
236+
scheme, host, port = get_splunkd_access_info(
237+
session_key=self._session_key
238+
)
237239
hec_port, hec_token = self._get_hec_config(
238240
hec_input_name, session_key, scheme, host, port, **context
239241
)

solnlib/splunkenv.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ def make_splunkhome_path(parts: Union[List, Tuple]) -> str:
8181

8282

8383
def get_splunk_host_info(
84-
use_btool: Optional[bool] = False,
85-
session_key: Optional[str] = None
84+
use_btool: Optional[bool] = False, session_key: Optional[str] = None
8685
) -> Tuple:
8786
"""Get splunk host info.
8887
@@ -96,7 +95,7 @@ def get_splunk_host_info(
9695
"serverName",
9796
use_btool=use_btool,
9897
session_key=session_key,
99-
app_name=APP_SYSTEM
98+
app_name=APP_SYSTEM,
10099
)
101100
host_name = socket.gethostname()
102101

@@ -118,8 +117,7 @@ def get_splunk_bin() -> str:
118117

119118

120119
def get_splunkd_access_info(
121-
use_btool: Optional[bool] = False,
122-
session_key: Optional[str] = None
120+
use_btool: Optional[bool] = False, session_key: Optional[str] = None
123121
) -> Tuple[str, str, int]:
124122
"""Get splunkd server access info.
125123
@@ -132,7 +130,7 @@ def get_splunkd_access_info(
132130
"enableSplunkdSSL",
133131
use_btool=use_btool,
134132
session_key=session_key,
135-
app_name=APP_SYSTEM
133+
app_name=APP_SYSTEM,
136134
)
137135

138136
if is_true(enable_splunkd_ssl):
@@ -146,7 +144,7 @@ def get_splunkd_access_info(
146144
"mgmtHostPort",
147145
use_btool=use_btool,
148146
session_key=session_key,
149-
app_name=APP_SYSTEM
147+
app_name=APP_SYSTEM,
150148
)
151149
host_port = host_port.strip()
152150
host_port_split_parts = host_port.split(":")
@@ -162,8 +160,7 @@ def get_splunkd_access_info(
162160

163161

164162
def get_scheme_from_hec_settings(
165-
use_btool: Optional[bool] = False,
166-
session_key: Optional[str] = None
163+
use_btool: Optional[bool] = False, session_key: Optional[str] = None
167164
) -> str:
168165
"""Get scheme from HEC global settings.
169166
@@ -177,7 +174,7 @@ def get_scheme_from_hec_settings(
177174
"enableSSL",
178175
use_btool=use_btool,
179176
session_key=session_key,
180-
app_name=APP_HEC
177+
app_name=APP_HEC,
181178
)
182179
except KeyError:
183180
raise KeyError(
@@ -216,7 +213,7 @@ def get_conf_key_value(
216213
use_btool: Optional[bool] = False,
217214
app_name: Optional[str] = None,
218215
session_key: Optional[str] = None,
219-
user: Optional[str] = "nobody"
216+
user: Optional[str] = "nobody",
220217
) -> Union[str, List, dict]:
221218
"""Get value of `key` of `stanza` in `conf_name`.
222219
@@ -244,11 +241,7 @@ def get_conf_key_value(
244241
raise KeyError("app name must be specified if use_btool is True")
245242

246243
stanzas = _get_conf_stanzas_from_splunk_api(
247-
conf_name,
248-
app_name,
249-
session_key=session_key,
250-
user=user,
251-
stanza=stanza
244+
conf_name, app_name, session_key=session_key, user=user, stanza=stanza
252245
)
253246

254247
stanza = stanzas.get("entry")[0].get("content")
@@ -262,7 +255,7 @@ def get_conf_stanza(
262255
use_btool: Optional[bool] = False,
263256
app_name: Optional[str] = None,
264257
session_key: Optional[str] = None,
265-
user: Optional[str] = "nobody"
258+
user: Optional[str] = "nobody",
266259
) -> dict:
267260
"""Get `stanza` in `conf_name`.
268261
@@ -290,11 +283,7 @@ def get_conf_stanza(
290283
raise KeyError("app name must be specified if use_btool is True")
291284

292285
stanzas = _get_conf_stanzas_from_splunk_api(
293-
conf_name,
294-
app_name,
295-
session_key=session_key,
296-
user=user,
297-
stanza=stanza
286+
conf_name, app_name, session_key=session_key, user=user, stanza=stanza
298287
)
299288

300289
stanza = stanzas.get("entry")[0].get("content")
@@ -357,6 +346,7 @@ def _get_conf_stanzas_from_splunk_api(
357346
stanza: Optional[str] = None,
358347
) -> dict:
359348
"""Get stanzas of `conf_name` using splunk API:
349+
360350
/servicesNS/{user}/{app_name}/configs/conf-{conf_name}/{stanza}
361351
362352
Arguments:

0 commit comments

Comments
 (0)