def http_simple_input(self, *args, **kwargs):
        # init
        output = ODataEntity()
        responseCode = 500
        serverResponse = None
        messages = []
        
        # Unfortunately, we can't use the Splunk API for this, so we just do it
        # ourselves
        base_url = "https://" + self.request['headers']['host'] + "/"
        path = self.request['path'].replace("/services/json/v1/", "")
        query = self.request["query"] 
        query_string = ""
        if len(query): 
            query_string = "?" + urllib.urlencode(query)
        uri = base_url + path + query_string
        
        # fetch data
        
        # Construct httplib2 such that it works with the version of httplib2 that requires SSL disabling
        h = None
        try:
            h = httplib2.Http(timeout=splunk.rest.SPLUNKD_CONNECTION_TIMEOUT, disable_ssl_certificate_validation=True)
        except:
            h = httplib2.Http(timeout=splunk.rest.SPLUNKD_CONNECTION_TIMEOUT) 
            
        serverStatus, serverResponse = h.request(
            uri, 
            self.method, 
            headers=self.request["headers"], 
            body=self.request["payload"]
        )
        responseCode = serverStatus.status
        
        # convert XML to struct
        if serverResponse:
            root = et.fromstring(serverResponse)
            result = {}
            
            for field in root.findall("results/result/field"):
                result[field.get("k")] = field.findtext("value/text")
                
            output.data = result

            # service may return messages in the body; try to parse them
            try:
                msg = splunk.rest.extractMessages(root)
                if msg:
                    messages.append(msg)
            except:
                raise
                
        # package and return
        output.messages = messages
        return responseCode, self.render_odata(output) 
    def http_simple_input(self, *args, **kwargs):
        # init
        output = ODataEntity()
        responseCode = 500
        serverResponse = None
        messages = []

        # Unfortunately, we can't use the Splunk API for this, so we just do it
        # ourselves
        base_url = "https://" + self.request['headers']['host'] + "/"
        path = self.request['path'].replace("/services/json/v1/", "")
        query = self.request["query"]
        query_string = ""
        if len(query):
            query_string = "?" + urllib.urlencode(query)
        uri = base_url + path + query_string

        # fetch data

        # Construct httplib2 such that it works with the version of httplib2 that requires SSL disabling
        h = None
        try:
            h = httplib2.Http(timeout=splunk.rest.SPLUNKD_CONNECTION_TIMEOUT,
                              disable_ssl_certificate_validation=True)
        except:
            h = httplib2.Http(timeout=splunk.rest.SPLUNKD_CONNECTION_TIMEOUT)

        serverStatus, serverResponse = h.request(
            uri,
            self.method,
            headers=self.request["headers"],
            body=self.request["payload"])
        responseCode = serverStatus.status

        # convert XML to struct
        if serverResponse:
            root = et.fromstring(serverResponse)
            result = {}

            for field in root.findall("results/result/field"):
                result[field.get("k")] = field.findtext("value/text")

            output.data = result

            # service may return messages in the body; try to parse them
            try:
                msg = splunk.rest.extractMessages(root)
                if msg:
                    messages.append(msg)
            except:
                raise

        # package and return
        output.messages = messages
        return responseCode, self.render_odata(output)
Beispiel #3
0
    def response2odata(self, response_node, entity_class):
        '''
        A handful of Splunk endpoints will not return a full Atom feed, but
        rather a short message block like:

        <response>
            <messages>
                <msg type="INFO">this is a message</msg>
                <msg type="ERROR">this is a message</msg>
            </messages>
        </response>
        '''

        output = ODataEntity()
        output.entity_class = entity_class
        output.messages = splunk.rest.extractMessages(response_node)
        return output
Beispiel #4
0
    def response2odata(self, response_node, entity_class):
        """
        A handful of Splunk endpoints will not return a full Atom feed, but
        rather a short message block like:

        <response>
            <messages>
                <msg type="INFO">this is a message</msg>
                <msg type="ERROR">this is a message</msg>
            </messages>
        </response>
        """

        output = ODataEntity()
        output.entity_class = entity_class
        output.messages = splunk.rest.extractMessages(response_node)
        return output