コード例 #1
0
def _exists_d(url):
    def handle_response(response):
        return response.code in (200, 301, 302)

    def handle_error(reason):
        reason.printTraceback()

    dfrd = Agent(reactor).request('POST', url)
    dfrd.addCallbacks(handle_response, handle_error)
    return dfrd
コード例 #2
0
ファイル: wrenchpoller.py プロジェクト: BrzVlad/benchmarker
def _exists_d(url):
    def handle_response(response):
        return response.code in (200, 301, 302)

    def handle_error(reason):
        reason.printTraceback()

    dfrd = Agent(reactor).request('POST', url)
    dfrd.addCallbacks(handle_response, handle_error)
    return dfrd
コード例 #3
0
    def event(self,
              title,
              text,
              date_happened=None,
              handle=None,
              priority=None,
              related_event_id=None,
              tags=None,
              host=config.dataDog.eventHostName,
              device_name=None,
              aggregation_key="FreeSwitch",
              source_type_name="FreeSwitch",
              **kwargs):
        if config.dataDog.apiKey:
            body = {
                'title': "%s: %s" % (config.dataDog.eventHostName, title),
                'text': text,
            }

            if date_happened is not None:
                body['date_happened'] = date_happened

            if handle is not None:
                body['handle'] = handle

            if priority is not None:
                body['priority'] = priority

            if related_event_id is not None:
                body['related_event_id'] = related_event_id

            if tags is not None:
                body['tags'] = ','.join(tags)

            if host is not None:
                body['host'] = host

            if device_name is not None:
                body['device_name'] = device_name

            if aggregation_key is not None:
                body['aggregation_key'] = aggregation_key

            if source_type_name is not None:
                body['source_type_name'] = source_type_name

            body.update(kwargs)

            d = Agent(reactor).request(
                'POST', 'https://app.datadoghq.com/api/v1/events?api_key=' +
                config.dataDog.apiKey,
                Headers({'Content-Type': ['application/json']}),
                JSONProducer(body))
            d.addCallbacks(self.eventHandleResponse, self.eventHandleError)
コード例 #4
0
    def event(self, title, text, date_happened=None, handle=None, priority=None, related_event_id=None, tags=None, host=config.dataDog.eventHostName, device_name=None, aggregation_key="FreeSwitch", source_type_name="FreeSwitch", **kwargs):
        if config.dataDog.apiKey:
            body = {
                'title': "%s: %s" % (config.dataDog.eventHostName, title),
                'text': text,
            }

            if date_happened is not None:
                body['date_happened'] = date_happened

            if handle is not None:
                body['handle'] = handle

            if priority is not None:
                body['priority'] = priority

            if related_event_id is not None:
                body['related_event_id'] = related_event_id

            if tags is not None:
                body['tags'] = ','.join(tags)

            if host is not None:
                body['host'] = host

            if device_name is not None:
                body['device_name'] = device_name

            if aggregation_key is not None:
                body['aggregation_key'] = aggregation_key
                
            if source_type_name is not None:
                body['source_type_name'] = source_type_name

            body.update(kwargs)
            
            d = Agent(reactor).request('POST', 'https://app.datadoghq.com/api/v1/events?api_key='+config.dataDog.apiKey, Headers({'Content-Type': ['application/json']}), JSONProducer(body))
            d.addCallbacks(self.eventHandleResponse, self.eventHandleError)
コード例 #5
0
 def my_getPage(self, p_url):
     l_d = Agent(reactor).request('GET', p_url, Headers({'User-Agent': ['twisted']}), None)
     l_d.addCallbacks(self.handleResponse, self.handleError)
     return l_d
コード例 #6
0
ファイル: upnp.py プロジェクト: bopopescu/PyHouse_1
 def my_getPage(self, p_url):
     l_d = Agent(reactor).request('GET', p_url,
                                  Headers({'User-Agent': ['twisted']}),
                                  None)
     l_d.addCallbacks(self.handleResponse, self.handleError)
     return l_d
コード例 #7
0
from twisted.internet import reactor
from twisted.web.client import Agent
import sys


def printPage(result):
    print(result)


def printError(failure):
    # print >>sys.stderr, failure
    print(failure, file=sys.stderr)


def stop(result):
    reactor.stop()


if len(sys.argv) != 2:
    # print >>sys.stderr, "Usage: python print_resource.py <URL>"
    print("Usage: python print_resource.py <URL>", file=sys.stderr)
    exit(1)

# d = getPage(sys.argv[1].encode()) # deprecated since Twisted 16.7.0, use Agent
# todo: fix the rest!!!
d = Agent()
d.addCallbacks(printPage, printError)
d.addBoth(stop)

reactor.run()