def protobuf_to_obj_and_host(serialized_pb_event): """ converts a serialized protobuff from the event bus. These are different because the have host info embedded as part of the CbEnvironmentMsg (which doesn't exist in the files) returns the cb_type object and the host info (as a tuple) (sensor_id, cb_object) """ msg = cbevents.CbEventMsg() msg.ParseFromString(serialized_pb_event) sensor_id = None hostname = None if msg.HasField('env'): sensor_id = msg.env.endpoint.SensorId hostname = msg.env.endpoint.SensorHostName cb_type = convert_protobuf_to_cb_type(msg, sensor_id) retobj = cb_type.to_obj() if hostname: retobj["computer_name"] = hostname return sensor_id, retobj
def protobuf_to_obj(serialized_protobuf_event, sensor_id): """ converts a serialized protobuf CB event to a native python dictionary """ msg = cbevents.CbEventMsg() msg.ParseFromString(serialized_protobuf_event) cb_type = convert_protobuf_to_cb_type(msg, sensor_id) return cb_type.to_obj()
def on_message(channel, method_frame, header_frame, body): try: print method_frame.routing_key if "application/protobuf" == header_frame.content_type: x = cpb.CbEventMsg() x.ParseFromString(body) print "EVENT: %s" % x elif "application/json" == header_frame.content_type: print "json" else: print header_frame.content_type # pprint.pprint(body) print except Exception, e: print e
def protobuf_to_obj_and_host(serialized_pb_event): ''' converts a serialized protobuff from the event bus. These are different because the have host info embedded as part of the CbEnvironmentMsg (which doesn't exist in the files) returns the cb_type object and the host info (as a tuple) (sensor_id, cb_object) ''' msg = cbevents.CbEventMsg() msg.ParseFromString(serialized_pb_event) sensor_id = None if (msg.HasField('env')): sensor_id = msg.env.endpoint.SensorId cb_type = convert_protobuf_to_cb_type(msg, sensor_id) return (sensor_id, cb_type.to_obj())