def _log(self, level, *a): if LogLevels[level] < self.level: return try: msg = json.encode(dict(level=(LogLevels[level],level),msg=a)) except TypeError: msg = json.encode(dict(level=(LogLevels[level],level),data=repr(a))) global _mseq _mseq += 1 msg = amqp.Message(body=msg, content_type=json.CODEC, message_id=base_mseq+str(_mseq)) self.channel.basic_publish(msg=msg, exchange=self.exchange, routing_key=".".join(str(x) for x in self.prefix+(level,)))
def process(self, event=None, **k): super(EventCallback, self).process(**k) # This is an event monitor. Failures will not be tolerated. try: msg = getattr(event.ctx, 'raw', None) codec = "application/binary" if msg is None: codec = json.CODEC for x, y in event.ctx: if x == 'event': continue if isinstance( y, six.string_types + six.integer_types + (bool, float, list, tuple)): d[x] = y elif hasattr(y, 'name'): d[x] = y.name if 'timestamp' not in d: d['timestamp'] = now() try: msg = json.encode(dict(event=list(event), **d)) except (TypeError, UnicodeDecodeError) as e: msg = json.encode( dict(data=repr(event) + "|" + repr(d) + "|" + repr(e))) elif isinstance(msg, six.integer_types + (float, )): msg = str(msg) codec = "text/plain" elif isinstance(msg, six.string_types): msg = msg.encode("utf-8") codec = "text/plain" global _mseq _mseq += 1 msg = amqp.Message(body=msg, content_type=codec, message_id=base_mseq + str(_mseq)) self.channel.basic_publish( msg=msg, exchange=self.exchange, routing_key=".".join( str(x) for x in self.prefix + tuple(event)[self.strip:])) except Exception as ex: fix_exception(ex) process_failure(ex) try: self.cancel() except Exception as ex: fix_exception(ex) process_failure(ex) raise TrySomethingElse
def _log(self, level, *a): if LogLevels[level] < self.level: return try: msg = json.encode(dict(level=(LogLevels[level], level), msg=a)) except TypeError: msg = json.encode( dict(level=(LogLevels[level], level), data=repr(a))) global _mseq _mseq += 1 msg = amqp.Message(body=msg, content_type=json.CODEC, message_id=base_mseq + str(_mseq)) self.channel.basic_publish( msg=msg, exchange=self.exchange, routing_key=".".join(str(x) for x in self.prefix + (level, )))
def process(self, event=None, **k): super(EventCallback,self).process(**k) # This is an event monitor. Failures will not be tolerated. try: msg = getattr(event.ctx,'raw',None) if msg is None: d = {} for x,y in event.ctx: if x == 'event': continue if isinstance(y,six.string_types+six.integer_types+(bool,float,list,tuple)): d[x]=y elif hasattr(y,'name'): d[x]=y.name if 'timestamp' not in d: d['timestamp'] = now() try: msg = json.encode(dict(event=list(event), **d)) except (TypeError,UnicodeDecodeError) as e: msg = json.encode(dict(data=repr(event)+"|"+repr(d)+"|"+repr(e))) elif isinstance(msg,six.integer_types+(float,)): msg = str(msg) elif isinstance(msg,six.string_types): msg = msg.encode("utf-8") global _mseq _mseq += 1 msg = amqp.Message(body=msg, content_type=json.CODEC, message_id=base_mseq+str(_mseq)) self.channel.basic_publish(msg=msg, exchange=self.exchange, routing_key=".".join(str(x) for x in self.prefix+tuple(event)[self.strip:])) except Exception as ex: fix_exception(ex) process_failure(ex) try: self.cancel() except Exception as ex: fix_exception(ex) process_failure(ex) raise TrySomethingElse