示例#1
0
    def _get_credentials(self, prop, name=None):
        """
        :return: clear or encrypted password for specified realm, user
        """

        endpoint = self._get_endpoint(name, True)
        response, content = rest.splunkd_request(endpoint,
                                                 self._session_key,
                                                 method="GET")

        if response is None and content is None:
            raise CredException("Failed to get clear credentials")

        results = {}
        if response and response.status in (200, 201) and content:
            passwords = xdp.parse_conf_xml_dom(content)
            for password in passwords:
                if password.get("realm") == self._realm:
                    values = password[prop].split(self._sep)
                    if len(values) % 2 == 1:
                        continue
                    result = {
                        values[i]: values[i + 1]
                        for i in range(0, len(values), 2)
                    }
                    results[password.get("username")] = result
        return results
def get_conf(splunkd_uri,
             session_key,
             owner,
             app_name,
             conf_name,
             stanza=None):
    """
    :param splunkd_uri: splunkd uri, e.g. https://127.0.0.1:8089
    :param session_key: splunkd session key
    :param owner: the owner (ACL user), e.g. "-", "nobody"
    :param app_name: the app"s name, e.g. "Splunk_TA_aws"
    :param conf_name: the name of the conf file, e.g. "props"
    :param stanza: stanza name, e.g. "aws:cloudtrail"
    :return: a list of stanzas in the conf file, including metadata
    """

    uri = _conf_endpoint_ns(splunkd_uri, owner, app_name, conf_name)

    if stanza:
        uri += "/" + stanza.replace("/", "%2F")

    # get all the stanzas at one time
    uri += "?count=0&offset=0"
    
    msg = "Failed to get conf={0}, stanza={1}".format(conf_name, stanza)
    content = content_request(uri, session_key, "GET", None, msg)
    return xdp.parse_conf_xml_dom(content)
def get_data_input(splunkd_uri,
                   session_key,
                   owner,
                   app_name,
                   input_type,
                   name=None):
    """
    :param splunkd_uri: splunkd uri, e.g. https://127.0.0.1:8089
    :param session_key: splunkd session key
    :param owner: the owner (ACL user), e.g. "-", "nobody"
    :param app_name: the app"s name, e.g. "Splunk_TA_aws"
    :param input_type: name of the input type.
                       if it is a script input, the input is "script",
                       for modinput, say snow, the input is "snow"
    :param name: The name of the input stanza to create.
                 i.e. stanza [<input_type>://<name>] will be deleted.
    :return: a list of stanzas in the input type, including metadata
    """

    uri = _input_endpoint_ns(splunkd_uri, owner, app_name, input_type)
    if name:
        uri += urllib.quote("/" + name.replace("/", "%2F"))
        
    # get all the stanzas at one time
    uri += "?count=0&offset=0"
    
    msg = "Failed to get data input in app=%s: %s://%s" % (
        app_name, input_type, name)
    content = content_request(uri, session_key, "GET", None, msg)
    return xdp.parse_conf_xml_dom(content)
    def _get_credentials(self, prop, name=None):
        """
        :return: clear or encrypted password for specified realm, user
        """

        endpoint = self._get_endpoint(name, True)
        response, content = rest.splunkd_request(
            endpoint,
            self._session_key,
            method="GET")

        if response is None and content is None:
            raise CredException("Failed to get clear credentials")

        results = {}
        if response and response.status in (200, 201) and content:
            passwords = xdp.parse_conf_xml_dom(content)
            for password in passwords:
                if password.get("realm") == self._realm:
                    values = password[prop].split(self._sep)
                    if len(values) % 2 == 1:
                        continue
                    result = {
                        values[i]: values[i + 1]
                        for i in range(0, len(values), 2)
                    }
                    results[password.get("username")] = result
        return results
示例#5
0
def get_conf(splunkd_uri,
             session_key,
             owner,
             app_name,
             conf_name,
             stanza=None):
    """
    :param splunkd_uri: splunkd uri, e.g. https://127.0.0.1:8089
    :param session_key: splunkd session key
    :param owner: the owner (ACL user), e.g. "-", "nobody"
    :param app_name: the app"s name, e.g. "Splunk_TA_aws"
    :param conf_name: the name of the conf file, e.g. "props"
    :param stanza: stanza name, e.g. "aws:cloudtrail"
    :return: a list of stanzas in the conf file, including metadata
    """

    uri = _conf_endpoint_ns(splunkd_uri, owner, app_name, conf_name)

    if stanza:
        uri += "/" + stanza.replace("/", "%2F")

    # get all the stanzas at one time
    uri += "?count=0&offset=0"

    msg = "Failed to get conf={0}, stanza={1}".format(conf_name, stanza)
    content = content_request(uri, session_key, "GET", None, msg)
    return xdp.parse_conf_xml_dom(content)
示例#6
0
def get_data_input(splunkd_uri,
                   session_key,
                   owner,
                   app_name,
                   input_type,
                   name=None):
    """
    :param splunkd_uri: splunkd uri, e.g. https://127.0.0.1:8089
    :param session_key: splunkd session key
    :param owner: the owner (ACL user), e.g. "-", "nobody"
    :param app_name: the app"s name, e.g. "Splunk_TA_aws"
    :param input_type: name of the input type.
                       if it is a script input, the input is "script",
                       for modinput, say snow, the input is "snow"
    :param name: The name of the input stanza to create.
                 i.e. stanza [<input_type>://<name>] will be deleted.
    :return: a list of stanzas in the input type, including metadata
    """

    uri = _input_endpoint_ns(splunkd_uri, owner, app_name, input_type)
    if name:
        uri += urllib.quote("/" + name.replace("/", "%2F"))

    # get all the stanzas at one time
    uri += "?count=0&offset=0"

    msg = "Failed to get data input in app=%s: %s://%s" % (app_name,
                                                           input_type, name)
    content = content_request(uri, session_key, "GET", None, msg)
    return xdp.parse_conf_xml_dom(content)
def _do_rest(uri, session_key):
    resp, content = rest.splunkd_request(uri, session_key)
    if resp is None:
        return None

    if resp.status not in (200, 201):
        return None

    stanza_objs = xdp.parse_conf_xml_dom(content)
    if not stanza_objs:
        return None

    return stanza_objs[0]
def _do_rest(uri, session_key):
    resp, content = rest.splunkd_request(uri, session_key)
    if resp is None:
        return None

    if resp.status not in (200, 201):
        return None

    stanza_objs = xdp.parse_conf_xml_dom(content)
    if not stanza_objs:
        return None

    return stanza_objs[0]
示例#9
0
    def get_all_passwords(self):
        """
        :return: a list of dict when successful, None when failed.
        the dict at least contains
        {
            "realm": xxx,
            "username": yyy,
            "clear_password": zzz,
        }
        """

        endpoint = "{}/services/storage/passwords".format(self._splunkd_uri)
        response, content = rest.splunkd_request(endpoint,
                                                 self._session_key,
                                                 method="GET")
        if response and response.status in (200, 201) and content:
            return xdp.parse_conf_xml_dom(content)
        raise CredException("Failed to get credentials")
示例#10
0
    def get_all_passwords(self):
        """
        :return: a list of dict when successful, None when failed.
        the dict at least contains
        {
            "realm": xxx,
            "username": yyy,
            "clear_password": zzz,
        }
        """

        endpoint = "{}/services/storage/passwords".format(self._splunkd_uri)
        response, content = rest.splunkd_request(
            endpoint,
            self._session_key,
            method="GET")
        if response and response.status in (200, 201) and content:
            return xdp.parse_conf_xml_dom(content)
        raise CredException("Failed to get credentials")
 def _do_request(self, uri, method, payload, err_msg):
     content = req.content_request(uri, self.session_key, method,
                                      payload, err_msg)
     return xdp.parse_conf_xml_dom(content)
 def _do_request(self, uri, method, payload, err_msg):
     content = req.content_request(uri, self.session_key, method, payload,
                                   err_msg)
     return xdp.parse_conf_xml_dom(content)