How to use the solnlib.splunk_rest_client function in solnlib

To help you get started, we’ve selected a few solnlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PaloAltoNetworks / pandevice / install / Splunk_TA_paloalto / bin / splunk_ta_paloalto / solnlib / user_access.py View on Github external
:param port: (optional) The port number, default is None.
    :type port: ``integer``
    :param context: Other configurations for Splunk rest client.
    :type context: ``dict``
    :returns: Current user name.
    :rtype: ``string``

    :raises InvalidSessionKeyException: If `session_key` is invalid.

    Usage::

       >>> from solnlib import user_access
       >>> user_name = user_access.get_current_username(session_key)
    '''

    _rest_client = rest_client.SplunkRestClient(
        session_key,
        '-',
        scheme=scheme,
        host=host,
        port=port,
        **context)
    try:
        response = _rest_client.get('/services/authentication/current-context',
                                    output_mode='json').body.read()
    except binding.HTTPError as e:
        if e.status != 401:
            raise

        raise InvalidSessionKeyException('Invalid session key.')

    return json.loads(response)['entry'][0]['content']['username']
github PaloAltoNetworks / pandevice / install / Splunk_TA_paloalto / bin / splunk_ta_paloalto / solnlib / user_access.py View on Github external
def _get_collection_data(collection_name, session_key, app, owner,
                         scheme, host, port, **context):
    kvstore = rest_client.SplunkRestClient(session_key,
                                           app,
                                           owner=owner,
                                           scheme=scheme,
                                           host=host,
                                           port=port,
                                           **context).kvstore

    collection_name = re.sub(r'[^\w]+', '_', collection_name)
    try:
        kvstore.get(name=collection_name)
    except binding.HTTPError as e:
        if e.status != 404:
            raise

        kvstore.create(collection_name)
github PaloAltoNetworks / pandevice / install / Splunk_TA_paloalto / bin / splunk_ta_paloalto / solnlib / acl.py View on Github external
def __init__(self, session_key, app, owner='nobody',
                 scheme=None, host=None, port=None, **context):
        self._rest_client = rest_client.SplunkRestClient(session_key,
                                                         app,
                                                         owner=owner,
                                                         scheme=scheme,
                                                         host=host,
                                                         port=port,
                                                         **context)
github PaloAltoNetworks / pandevice / install / Splunk_TA_paloalto / bin / splunk_ta_paloalto / solnlib / credentials.py View on Github external
:param context: Other configurations for Splunk rest client.
    :type context: ``dict``

    :raises CredentialException: If username/password are Invalid.

    Usage::

       >>> credentials.get_session_key('user', 'password')
    '''

    if any([scheme is None, host is None, port is None]):
        scheme, host, port = get_splunkd_access_info()

    uri = '{scheme}://{host}:{port}/{endpoint}'.format(
        scheme=scheme, host=host, port=port, endpoint='services/auth/login')
    _rest_client = rest_client.SplunkRestClient(
        None, '-', 'nobody', scheme, host, port, **context)
    try:
        response = _rest_client.http.post(
            uri, username=username, password=password, output_mode='json')
    except binding.HTTPError as e:
        if e.status != 401:
            raise

        raise CredentialException('Invalid username/password.')

    return json.loads(response.body.read())['sessionKey']
github PaloAltoNetworks / pandevice / install / Splunk_TA_paloalto / bin / splunk_ta_paloalto / solnlib / hec_config.py View on Github external
def __init__(self, session_key, scheme=None,
                 host=None, port=None, **context):
        self._rest_client = rest_client.SplunkRestClient(
            session_key,
            'splunk_httpinput',
            scheme=scheme,
            host=host,
            port=port,
            **context)
github PaloAltoNetworks / pandevice / install / Splunk_TA_paloalto / bin / splunk_ta_paloalto / solnlib / server_info.py View on Github external
def __init__(self, session_key,
                 scheme=None, host=None, port=None, **context):
        self._rest_client = rest_client.SplunkRestClient(session_key,
                                                         '-',
                                                         scheme=scheme,
                                                         host=host,
                                                         port=port,
                                                         **context)
github PaloAltoNetworks / pandevice / install / Splunk_TA_paloalto / bin / splunk_ta_paloalto / solnlib / time_parser.py View on Github external
def __init__(self, session_key,
                 scheme=None, host=None, port=None, **context):
        self._rest_client = rest_client.SplunkRestClient(
            session_key,
            '-',
            scheme=scheme,
            host=host,
            port=port,
            **context)
github PaloAltoNetworks / pandevice / install / Splunk_TA_paloalto / bin / splunk_ta_paloalto / solnlib / credentials.py View on Github external
def __init__(self, session_key, app, owner='nobody', realm=None,
                 scheme=None, host=None, port=None, **context):
        self._realm = realm
        self._storage_passwords = rest_client.SplunkRestClient(
            session_key,
            app,
            owner=owner,
            scheme=scheme,
            host=host,
            port=port,
            **context).storage_passwords
github PaloAltoNetworks / pandevice / install / Splunk_TA_paloalto / bin / splunk_ta_paloalto / solnlib / modular_input / event_writer.py View on Github external
scheme, host, port = get_splunkd_access_info()

        if hec_uri and hec_token:
            scheme, host, hec_port = utils.extract_http_scheme_host_port(
                hec_uri)
        else:
            hec_port, hec_token = self._get_hec_config(
                hec_input_name, session_key, scheme, host, port, **context)

        if not context.get('pool_connections'):
            context['pool_connections'] = 10

        if not context.get('pool_maxsize'):
            context['pool_maxsize'] = 10

        self._rest_client = rest_client.SplunkRestClient(hec_token,
                                                         app='-',
                                                         scheme=scheme,
                                                         host=host,
                                                         port=hec_port,
                                                         **context)
github PaloAltoNetworks / pandevice / install / Splunk_TA_paloalto / bin / splunk_ta_paloalto / solnlib / conf_manager.py View on Github external
def __init__(self, session_key, app, owner='nobody',
                 scheme=None, host=None, port=None, **context):
        self._session_key = session_key
        self._app = app
        self._owner = owner
        self._scheme = scheme
        self._host = host
        self._port = port
        self._context = context
        self._rest_client = rest_client.SplunkRestClient(
            self._session_key,
            self._app,
            owner=self._owner,
            scheme=self._scheme,
            host=self._host,
            port=self._port,
            **self._context)
        self._confs = None