You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
2.2 KiB

# Copyright (C) 2005-2025 Splunk Inc. All Rights Reserved.
"""
SDK's Base.
Define Base Classes applicable for all Event Management here.
Importing this module is pretty useless.
The pertinent classes for you are probably in sub directories in this directory.
"""
import itsi_py3
from splunk.auth import getSessionKey
from ITOA.setup_logging import getLogger
from ITOA.event_management.notable_event_utils import ActionDispatchConfiguration
class EventBase(object):
'''All SDK classes to inherit this as their base class
tracks stuff like Splunk session key, logger info and so on...
'''
def __init__(self, session_key, username=None, password=None, logger=None):
if session_key:
if not isinstance(session_key, itsi_py3.string_type):
raise TypeError('`session_key` must be a string with length equals at least one character.')
if not session_key.strip():
raise ValueError('`session_key` must be a string with length equals at least one character.')
else:
if any([
not (username or password),
not (isinstance(username, itsi_py3.string_type) or isinstance(password, itsi_py3.string_type)),
isinstance(username, itsi_py3.string_type) and not username.strip(),
isinstance(password, itsi_py3.string_type) and not password.strip()
]):
raise ValueError(('In the absence of session_key, expecting a valid '
'non-empty string, for both your username and password.'))
session_key = getSessionKey(username, password)
if not session_key:
raise TypeError('Login failed. Check your credentials and try again.')
self.session_key = session_key
self.logger = logger
if self.logger is None:
self.logger = getLogger(logger_name="itsi.event_management.sdk")
self.action_dispatch_config = ActionDispatchConfiguration(self.session_key, self.logger)
self.master_host_uri = self.action_dispatch_config.remote_ea_mgmt_uri
if self.master_host_uri is None:
self.master_host_uri = ''
self.master_host_session_key = self.action_dispatch_config.get_master_host_session_key()