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,14 @@ 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 (
186
+ get_conf_key_value ("server" , "sslConfig" , "enableSplunkdSSL" , APP_SYSTEM )
187
+ ):
184
188
scheme = "https"
185
189
else :
186
190
scheme = "http"
187
191
188
- host_port = get_conf_key_value ("web" , "settings" , "mgmtHostPort" )
192
+ host_port = get_conf_key_value ("web" , "settings" , "mgmtHostPort" , APP_SYSTEM )
189
193
host_port = host_port .strip ()
190
194
host_port_split_parts = host_port .split (":" )
191
195
host = ":" .join (host_port_split_parts [:- 1 ])
@@ -206,7 +210,7 @@ def get_scheme_from_hec_settings() -> str:
206
210
scheme (str)
207
211
"""
208
212
try :
209
- ssl_enabled = get_conf_key_value ("inputs" , "http" , "enableSSL" )
213
+ ssl_enabled = get_conf_key_value ("inputs" , "http" , "enableSSL" , APP_HEC )
210
214
except KeyError :
211
215
raise KeyError (
212
216
"Cannot get enableSSL setting form conf: 'inputs' and stanza: '[http]'. "
@@ -237,13 +241,16 @@ def get_splunkd_uri() -> str:
237
241
return f"{ scheme } ://{ host } :{ port } "
238
242
239
243
240
- def get_conf_key_value (conf_name : str , stanza : str , key : str ) -> Union [str , List , dict ]:
244
+ def get_conf_key_value (
245
+ conf_name : str , stanza : str , key : str , app_name : Optional [str ] = None
246
+ ) -> Union [str , List , dict ]:
241
247
"""Get value of `key` of `stanza` in `conf_name`.
242
248
243
249
Arguments:
244
250
conf_name: Config file.
245
251
stanza: Stanza name.
246
252
key: Key name.
253
+ app_name: Application name. Optional.
247
254
248
255
Returns:
249
256
Config value.
@@ -252,16 +259,19 @@ def get_conf_key_value(conf_name: str, stanza: str, key: str) -> Union[str, List
252
259
KeyError: If `stanza` or `key` doesn't exist.
253
260
"""
254
261
255
- stanzas = get_conf_stanzas (conf_name )
262
+ stanzas = get_conf_stanzas (conf_name , app_name )
256
263
return stanzas [stanza ][key ]
257
264
258
265
259
- def get_conf_stanza (conf_name : str , stanza : str ) -> dict :
266
+ def get_conf_stanza (
267
+ conf_name : str , stanza : str , app_name : Optional [str ] = None
268
+ ) -> dict :
260
269
"""Get `stanza` in `conf_name`.
261
270
262
271
Arguments:
263
272
conf_name: Config file.
264
273
stanza: Stanza name.
274
+ app_name: Application name. Optional.
265
275
266
276
Returns:
267
277
Config stanza.
@@ -270,15 +280,16 @@ def get_conf_stanza(conf_name: str, stanza: str) -> dict:
270
280
KeyError: If stanza doesn't exist.
271
281
"""
272
282
273
- stanzas = get_conf_stanzas (conf_name )
283
+ stanzas = get_conf_stanzas (conf_name , app_name )
274
284
return stanzas [stanza ]
275
285
276
286
277
- def get_conf_stanzas (conf_name : str ) -> dict :
287
+ def get_conf_stanzas (conf_name : str , app_name : Optional [ str ] = None ) -> dict :
278
288
"""Get stanzas of `conf_name`
279
289
280
290
Arguments:
281
291
conf_name: Config file.
292
+ app_name: Application name. Optional.
282
293
283
294
Returns:
284
295
Config stanzas.
@@ -299,6 +310,10 @@ def get_conf_stanzas(conf_name: str) -> dict:
299
310
conf_name ,
300
311
"list" ,
301
312
]
313
+
314
+ if app_name :
315
+ btool_cli .append (f"--app={ app_name } " )
316
+
302
317
p = subprocess .Popen ( # nosemgrep: python.lang.security.audit.dangerous-subprocess-use.dangerous-subprocess-use
303
318
btool_cli , stdout = subprocess .PIPE , stderr = subprocess .PIPE
304
319
)
0 commit comments