예제 #1
0
    def post(self):
        data = json.loads(self.request.body)
        logging.debug("received push msg: %s", str(data))
       
        meter_name = data.get('counter_name')
        if not meter_name:
            logging.info("ignoring message with no counter_name")
            return

        s = sample.SampleCreator(name=meter_name,
                                 type=data.get('counter_type'),
                                 unit=data.get('counter_unit'),
                                 volume=float(data.get('counter_volume') or 0),
                                 user_id=options.user_id,
                                 project_id=options.project_id,
                                 resource_id="custom_"+options.project_id+"_"+str(data.get('resource_id')),
                                 timestamp=timeutils.isotime(),
                                 resource_metadata=data.get('resource_metadata'),
                                 source="useragent")
        logging.debug("message to send: " + json.dumps(s.get_msg()))
        msg = s.get_packed_msg(options.secret)
 
        pub = UdpPublisher()
        pub.send(msg)  
예제 #2
0
def publish(result, rule):
    msg = MsgMaker.makeMsg(rule, result)
    pub = UdpPublisher()
    pub.send(msg)