39
39
]
40
40
41
41
ETC_LEAF = "etc"
42
+ APP_SYSTEM = "system"
43
+ APP_HEC = "splunk_httpinput"
42
44
43
45
# See validateSearchHeadPooling() in src/libbundle/ConfSettings.cpp
44
46
on_shared_storage = [
@@ -73,8 +75,8 @@ def _get_shared_storage() -> Optional[str]:
73
75
"""
74
76
75
77
try :
76
- state = get_conf_key_value ("server" , "pooling" , "state" )
77
- storage = get_conf_key_value ("server" , "pooling" , "storage" )
78
+ state = get_conf_key_value ("server" , "pooling" , "state" , APP_SYSTEM )
79
+ storage = get_conf_key_value ("server" , "pooling" , "storage" , APP_SYSTEM )
78
80
except KeyError :
79
81
state = "disabled"
80
82
storage = None
@@ -154,7 +156,7 @@ def get_splunk_host_info() -> Tuple:
154
156
Tuple of (server_name, host_name).
155
157
"""
156
158
157
- server_name = get_conf_key_value ("server" , "general" , "serverName" )
159
+ server_name = get_conf_key_value ("server" , "general" , "serverName" , APP_SYSTEM )
158
160
host_name = socket .gethostname ()
159
161
return server_name , host_name
160
162
@@ -180,12 +182,12 @@ def get_splunkd_access_info() -> Tuple[str, str, int]:
180
182
Tuple of (scheme, host, port).
181
183
"""
182
184
183
- if is_true (get_conf_key_value ("server" , "sslConfig" , "enableSplunkdSSL" )):
185
+ if is_true (get_conf_key_value ("server" , "sslConfig" , "enableSplunkdSSL" , APP_SYSTEM )):
184
186
scheme = "https"
185
187
else :
186
188
scheme = "http"
187
189
188
- host_port = get_conf_key_value ("web" , "settings" , "mgmtHostPort" )
190
+ host_port = get_conf_key_value ("web" , "settings" , "mgmtHostPort" , APP_SYSTEM )
189
191
host_port = host_port .strip ()
190
192
host_port_split_parts = host_port .split (":" )
191
193
host = ":" .join (host_port_split_parts [:- 1 ])
@@ -206,7 +208,7 @@ def get_scheme_from_hec_settings() -> str:
206
208
scheme (str)
207
209
"""
208
210
try :
209
- ssl_enabled = get_conf_key_value ("inputs" , "http" , "enableSSL" )
211
+ ssl_enabled = get_conf_key_value ("inputs" , "http" , "enableSSL" , APP_HEC )
210
212
except KeyError :
211
213
raise KeyError (
212
214
"Cannot get enableSSL setting form conf: 'inputs' and stanza: '[http]'. "
@@ -237,13 +239,14 @@ def get_splunkd_uri() -> str:
237
239
return f"{ scheme } ://{ host } :{ port } "
238
240
239
241
240
- def get_conf_key_value (conf_name : str , stanza : str , key : str ) -> Union [str , List , dict ]:
242
+ def get_conf_key_value (conf_name : str , stanza : str , key : str , app_name : Optional [ str ] = None ) -> Union [str , List , dict ]:
241
243
"""Get value of `key` of `stanza` in `conf_name`.
242
244
243
245
Arguments:
244
246
conf_name: Config file.
245
247
stanza: Stanza name.
246
248
key: Key name.
249
+ app_name: Application name. Optional.
247
250
248
251
Returns:
249
252
Config value.
@@ -252,16 +255,17 @@ def get_conf_key_value(conf_name: str, stanza: str, key: str) -> Union[str, List
252
255
KeyError: If `stanza` or `key` doesn't exist.
253
256
"""
254
257
255
- stanzas = get_conf_stanzas (conf_name )
258
+ stanzas = get_conf_stanzas (conf_name , app_name )
256
259
return stanzas [stanza ][key ]
257
260
258
261
259
- def get_conf_stanza (conf_name : str , stanza : str ) -> dict :
262
+ def get_conf_stanza (conf_name : str , stanza : str , app_name : Optional [ str ] = None ) -> dict :
260
263
"""Get `stanza` in `conf_name`.
261
264
262
265
Arguments:
263
266
conf_name: Config file.
264
267
stanza: Stanza name.
268
+ app_name: Application name. Optional.
265
269
266
270
Returns:
267
271
Config stanza.
@@ -270,15 +274,16 @@ def get_conf_stanza(conf_name: str, stanza: str) -> dict:
270
274
KeyError: If stanza doesn't exist.
271
275
"""
272
276
273
- stanzas = get_conf_stanzas (conf_name )
277
+ stanzas = get_conf_stanzas (conf_name , app_name )
274
278
return stanzas [stanza ]
275
279
276
280
277
- def get_conf_stanzas (conf_name : str ) -> dict :
281
+ def get_conf_stanzas (conf_name : str , app_name : Optional [ str ] = None ) -> dict :
278
282
"""Get stanzas of `conf_name`
279
283
280
284
Arguments:
281
285
conf_name: Config file.
286
+ app_name: Application name. Optional.
282
287
283
288
Returns:
284
289
Config stanzas.
@@ -299,6 +304,10 @@ def get_conf_stanzas(conf_name: str) -> dict:
299
304
conf_name ,
300
305
"list" ,
301
306
]
307
+
308
+ if app_name :
309
+ btool_cli .append (f"--app={ app_name } " )
310
+
302
311
p = subprocess .Popen ( # nosemgrep: python.lang.security.audit.dangerous-subprocess-use.dangerous-subprocess-use
303
312
btool_cli , stdout = subprocess .PIPE , stderr = subprocess .PIPE
304
313
)
0 commit comments