def makeMsg(rule, volume): s = sample.SampleCreator(name=rule['meter_name'], type=rule['meter_type'], unit=rule['meter_unit'], volume=float(volume), user_id=options.user_id, project_id=options.project_id, resource_id="custom_"+str(rule['meter_rid']), timestamp=timeutils.isotime(), resource_metadata=None, source="user") logging.debug("message to send: " + json.dumps(s.get_msg())) msg = s.get_packed_msg(options.secret) return msg
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)