MCPcopy Create free account
hub / github.com/adobe/Marinus / SplunkHECManager

Class SplunkHECManager

python3_cron_scripts/libs3/SplunkHECManager.py:51–164  ·  view source on GitHub ↗

This class is for sending data to a Splunk HEC

Source from the content-addressed store, hash-verified

49
50
51class SplunkHECManager(object):
52 """
53 This class is for sending data to a Splunk HEC
54 """
55
56 splunk_config_file = "connector.config"
57 _logger = None
58
59 def _log(self):
60 """
61 Get the log
62 """
63 return logging.getLogger(__name__)
64
65 def _init_splunk_hec_connection(self, config):
66 """
67 Initialize the class members
68 """
69 self.HOST = ConnectorUtil.get_config_setting(
70 self._logger, config, "SplunkHEC", "splunk.host"
71 )
72 self.PORT = ConnectorUtil.get_config_setting(
73 self._logger, config, "SplunkHEC", "splunk.port"
74 )
75 self.ACCESS_TOKEN = ConnectorUtil.get_config_setting(
76 self._logger, config, "SplunkHEC", "splunk.access_token"
77 )
78 self.HOSTNAME = ConnectorUtil.get_config_setting(
79 self._logger, config, "SplunkHEC", "splunk.hostname"
80 )
81 self.INDEX = ConnectorUtil.get_config_setting(
82 self._logger, config, "SplunkHEC", "splunk.index"
83 )
84 self.URL = "https://" + self.HOST + ":" + self.PORT + "/services/collector/"
85 self.HEADERS = {"Authorization": "Splunk {}".format(self.ACCESS_TOKEN)}
86
87 def __init__(self, log_level=None):
88 """
89 Class initialization
90 """
91 self._logger = self._log()
92 if log_level is not None:
93 self._logger.setLevel(log_level)
94
95 config = configparser.ConfigParser()
96 config_file = config.read(self.splunk_config_file)
97 if len(config_file) == 0:
98 self._logger.error("Error: Could not find the config file")
99 exit(1)
100
101 self._init_splunk_hec_connection(config)
102
103 def push_to_splunk_hec(
104 self, source, message, endpoint=HECEndpoint.EVENT, level=HECLogLevel.INFO
105 ):
106 """
107 Create the HTTPS request and send the data as a JSON object.
108 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected