Exemple #1
0
    def render_POST(self, request):
        try:
            postData = request.content.read()
            unpacker = json.loads(postData)
            logging.debug('fed data to unpacker')
            for msg in unpacker:
                logging.debug('found message in unpacker')

                if type(msg) == dict:
                    logging.debug('found object in message')

                    msg['hash'] = ErrorHasher(msg).get_hash()
                    if 'timestamp' not in msg:
                        msg['timestamp'] = int(time())

                    Error.validate_and_upsert(msg)
                    logging.debug('saved error')

                    ErrorInstance.from_raw(msg).save(safe=False)
                    HourlyOccurrence.from_msg(msg)
                    DailyOccurrence.from_msg(msg)

                    logging.debug('saved instance')

        except Exception, a:
            logging.exception('Failed to process error')
            logging.info(postData)
            return 'FAILED';
Exemple #2
0
unpacker = msgpack.Unpacker()

# serve!
logging.info('Serving!')
while True:
    try:
        data = socket.recv()
        logging.debug('received data')
        unpacker.feed(data)
        logging.debug('fed data to unpacker')
        for msg in unpacker:
            logging.debug('found message in unpacker')
            if type(msg) == dict:
                logging.debug('found object in message')

                msg['hash'] = ErrorHasher(msg).get_hash()
                if 'timestamp' not in msg:
                    msg['timestamp'] = int(time())

                Error.validate_and_upsert(msg)
                logging.debug('saved error')

                ErrorInstance.from_raw(msg).save(safe=False)
                HourlyOccurrence.from_msg(msg)
                DailyOccurrence.from_msg(msg)

                logging.debug('saved instance')

    except Exception, a:
        logging.exception('Failed to process error')