3232from .. import splunk_rest_client as rest_client
3333from .. import utils
3434from ..hec_config import HECConfig
35- from ..splunkenv import get_splunkd_access_info
35+ from ..splunkenv import get_splunkd_access_info , get_scheme_from_hec_settings
3636from ..utils import retry
3737from .event import HECEvent , XMLEvent
3838
@@ -203,6 +203,7 @@ def __init__(
203203 port : int = None ,
204204 hec_uri : str = None ,
205205 hec_token : str = None ,
206+ global_settings_schema : bool = True ,
206207 logger : logging .Logger = None ,
207208 ** context : dict
208209 ):
@@ -217,6 +218,7 @@ def __init__(
217218 hec_uri: (optional) If hec_uri and hec_token are provided, they will
218219 higher precedence than hec_input_name.
219220 hec_token: (optional) HEC token.
221+ global_settings_schema: (optional) if True, scheme will be set based on HEC global settings, default False.
220222 logger: Logger object.
221223 context: Other configurations for Splunk rest client.
222224 """
@@ -237,6 +239,9 @@ def __init__(
237239 hec_input_name , session_key , scheme , host , port , ** context
238240 )
239241
242+ if global_settings_schema :
243+ scheme = get_scheme_from_hec_settings ()
244+
240245 if not context .get ("pool_connections" ):
241246 context ["pool_connections" ] = 10
242247
@@ -249,7 +254,10 @@ def __init__(
249254
250255 @staticmethod
251256 def create_from_token (
252- hec_uri : str , hec_token : str , ** context : dict
257+ hec_uri : str ,
258+ hec_token : str ,
259+ global_settings_schema : bool = False ,
260+ ** context : dict
253261 ) -> "HECEventWriter" :
254262 """Given HEC URI and HEC token, create HECEventWriter object. This
255263 function simplifies the standalone mode HECEventWriter usage (not in a
@@ -258,6 +266,7 @@ def create_from_token(
258266 Arguments:
259267 hec_uri: HTTP Event Collector URI, like https://localhost:8088.
260268 hec_token: HTTP Event Collector token.
269+ global_settings_schema: (optional) if True, scheme will be set based on HEC global settings, default False.
261270 context: Other configurations.
262271
263272 Returns:
@@ -272,12 +281,17 @@ def create_from_token(
272281 None ,
273282 hec_uri = hec_uri ,
274283 hec_token = hec_token ,
284+ global_settings_schema = global_settings_schema ,
275285 ** context
276286 )
277287
278288 @staticmethod
279289 def create_from_input (
280- hec_input_name : str , splunkd_uri : str , session_key : str , ** context : dict
290+ hec_input_name : str ,
291+ splunkd_uri : str ,
292+ session_key : str ,
293+ global_settings_schema : bool = False ,
294+ ** context : dict
281295 ) -> "HECEventWriter" :
282296 """Given HEC input stanza name, splunkd URI and splunkd session key,
283297 create HECEventWriter object. HEC URI and token etc will be discovered
@@ -289,6 +303,7 @@ def create_from_input(
289303 hec_input_name: Splunk HEC input name.
290304 splunkd_uri: Splunkd URI, like https://localhost:8089
291305 session_key: Splunkd access token.
306+ global_settings_schema: (optional) if True, scheme will be set based on HEC global settings, default False.
292307 context: Other configurations.
293308
294309 Returns:
@@ -297,7 +312,13 @@ def create_from_input(
297312
298313 scheme , host , port = utils .extract_http_scheme_host_port (splunkd_uri )
299314 return HECEventWriter (
300- hec_input_name , session_key , scheme , host , port , ** context
315+ hec_input_name ,
316+ session_key ,
317+ scheme ,
318+ host ,
319+ port ,
320+ global_settings_schema = global_settings_schema ,
321+ ** context
301322 )
302323
303324 @staticmethod
@@ -306,6 +327,7 @@ def create_from_token_with_session_key(
306327 session_key : str ,
307328 hec_uri : str ,
308329 hec_token : str ,
330+ global_settings_schema : bool = False ,
309331 ** context : dict
310332 ) -> "HECEventWriter" :
311333 """Given Splunkd URI, Splunkd session key, HEC URI and HEC token,
@@ -318,6 +340,7 @@ def create_from_token_with_session_key(
318340 session_key: Splunkd access token.
319341 hec_uri: Http Event Collector URI, like https://localhost:8088.
320342 hec_token: Http Event Collector token.
343+ global_settings_schema: (optional) if True, scheme will be set based on HEC global settings, default False.
321344 context: Other configurations.
322345
323346 Returns:
@@ -333,6 +356,7 @@ def create_from_token_with_session_key(
333356 port ,
334357 hec_uri = hec_uri ,
335358 hec_token = hec_token ,
359+ global_settings_schema = global_settings_schema ,
336360 ** context
337361 )
338362
0 commit comments