def quotes_feed(app, handler, finance_path, series_name, symbol_list): data = handler.get(finance_path + symbol_list) app.log.debug('Fetch data: %s' % data.text) # Can't use raw JSON response from Google, must convert numbers to numeric financial_data = [{k: numerify(v) for k, v in d.items()} for d in json.loads(data.text[3:])] # Have to iterate over quotes as some Google values are optional for quote in financial_data: # Re-key the JSON response with friendly names rekeyed_quote = dict([(CODES_GOOGLE.get(key, key), value) for key, value in quote.items()]) tags = extract_tags(rekeyed_quote, ['id', 'exchange', 'symbol']) event = [{ 'measurement': series_name, 'tags': tags, 'fields': rekeyed_quote }] app.log.debug('Event data: %s' % event) handler.postEvent(event, batch=True)
def quotes_feed(app, handler, finance_path, series_name, symbol_list): data = handler.get(finance_path + symbol_list) app.log.debug('Fetch data: %s' % data.text) # Can't use raw JSON response from Google, must convert numbers to numeric financial_data = [{k: numerify(v) for k, v in d.items()} for d in json.loads(data.text[3:])] # Have to iterate over quotes as some Google values are optional for quote in financial_data: # Re-key the JSON response with friendly names rekeyed_quote = dict([(CODES_GOOGLE.get(key, key), value) for key, value in quote.items()]) event = [{ 'name': series_name, 'columns': list(rekeyed_quote.keys()), 'points': [list(rekeyed_quote.values())] }] app.log.debug('Event data: %s' % event) handler.postEvent(event)
except Exception as e: app.log.error('Unhandled exception: %s' % e) # Check for errors and assemble results if errorIndication: app.log.error(errorIndication) elif errorStatus: app.log.error(errorStatus) else: for name, val in varBinds: app.log.debug('%s = %s (%s)' % (name, val, oids[str(name)]['desc'])) if oids[str(name)]['name'] == 'runtime': # Convert runtime into seconds data[oids[str(name)]['name']] = int( numerify(str(val)) / 100) elif oids[str(name)]['name'] == 'battemp': data[oids[str(name)]['name']] = numerify(str(val)) # Also provide temp in F data['battempf'] = CtoF(data[oids[str(name)]['name']]) else: data[oids[str(name)]['name']] = numerify(str(val)) tags = extract_tags(data, ['lasttestdate']) event = [{ 'measurement': 'apcups', # Time Series Name 'tags': tags, 'fields': data # Data points }]
n = handler.post(app.config.get('eagle', 'eagle_addr') + '/cgi-bin/cgi_manager', data=network_command) u = handler.post(app.config.get('eagle', 'eagle_addr') + '/cgi-bin/cgi_manager', data=usage_command) except Exception as e: # If event handler was unsuccessful retrying stop app.log.fatal(e) app.close(1) app.log.debug('Network data: %s' % n.text) app.log.debug('Usage data: %s' % u.text) networkdata = dict( (k, numerify(v)) for k, v in json.loads(n.text).items()) usagedata = dict( (k, numerify(v)) for k, v in json.loads(u.text).items()) # Normalize to W or Wh try: demand = float(usagedata['demand']) *\ units[usagedata['demand_units']] received = float(usagedata['summation_received']) *\ units[usagedata['summation_units']] delivered = float(usagedata['summation_delivered']) *\ units[usagedata['summation_units']] link_strength = int(networkdata['network_link_strength'], base=16) except ValueError: app.log.error('Unsupport demand or summation units')
while True: try: n = handler.post(app.config.get('eagle', 'eagle_addr') + '/cgi-bin/cgi_manager', data=network_command) u = handler.post(app.config.get('eagle', 'eagle_addr') + '/cgi-bin/cgi_manager', data=usage_command) except Exception as e: # If event handler was unsuccessful retrying stop app.log.fatal(e) app.close(1) app.log.debug('Network data: %s' % n.text) app.log.debug('Usage data: %s' % u.text) networkdata = dict((k, numerify(v)) for k, v in json.loads(n.text).items()) usagedata = dict((k, numerify(v)) for k, v in json.loads(u.text).items()) # Normalize to W or Wh try: demand = float(usagedata['demand']) *\ units[usagedata['demand_units']] received = float(usagedata['summation_received']) *\ units[usagedata['summation_units']] delivered = float(usagedata['summation_delivered']) *\ units[usagedata['summation_units']] link_strength = int(networkdata['network_link_strength'], base=16) except ValueError:
<Name>get_usage_data</Name>\n\ <MacId>' + device_macid + '</MacId>\n\ </LocalCommand>' while True: try: r = handler.post(app.config.get('eagle', 'eagle_addr') + '/cgi-bin/cgi_manager', data=command) except Exception as e: # If event handler was unsuccessful retrying stop app.log.fatal(e) app.close(1) app.log.debug('Fetch data: %s' % r.text) devicedata = dict((k, numerify(v)) for k, v in json.loads(r.text).items()) # Normalize to W or Wh try: power = float(devicedata['demand']) *\ units[devicedata['demand_units']] received = float(devicedata['summation_received']) *\ units[devicedata['summation_units']] delivered = float(devicedata['summation_delivered']) *\ units[devicedata['summation_units']] except ValueError: app.log.error('Unsupport demand or summation units') pass try: