def store_tick_data(tick_data, tick_data_validity): """ Store data returned by get_tick_data in redis as key value pairs """ for host in tick_data: host_data = tick_data[host] set_volatile_data('resources:tick#{}'.format(to_uuid(host)), json.dumps([host_data])) set_data('resources_success:tick', json.dumps([tick_data_validity]))
def store_newrelic_infra_data(newrelic_infra_data, newrelic_infra_data_validity): """ Store data returned by get_newrelic_infra_data in redis as key value pairs """ for host in newrelic_infra_data: host_data = newrelic_infra_data[host] set_data('resources:newrelic_infrastructure#{}'.format(to_uuid(host)), json.dumps([host_data])) set_data('resources_success:newrelic_infrastructure', json.dumps([newrelic_infra_data_validity]))
def store_calendar_items(): with open(calendar_export) as c_file: try: c_data = json.load(c_file) except ValueError: c_data = False c_file.close() if c_data != False: prune_calendar_items() for item in c_data['items']: if 'dateTime' in item['start']: # Check if the datetime is set item['start']['date'] = item['start']['dateTime'].split( 'T' )[0] # Split the datetime to get the date and set the data parameter current_summary = item['summary'] try: start_time = datetime.datetime.strptime( item['start']['dateTime'].split('T')[1], '%H:%M:%SZ').strftime( '%H:%M') # Convert the start time to a nice date end_time = datetime.datetime.strptime( item['end']['dateTime'].split('T')[1], '%H:%M:%SZ').strftime( '%H:%M: ') # Convert the end time to a nice date except ValueError: start_time = datetime.datetime.strptime( item['start']['dateTime'].split('T')[1], '%H:%M:%S+01:00').strftime( '%H:%M') # To work with DST times end_time = datetime.datetime.strptime( item['end']['dateTime'].split('T')[1], '%H:%M:%S+01:00').strftime('%H:%M: ') item['summary'] = '{} - {}{}'.format( start_time, end_time, current_summary ) # Add the start and end time to the summary current = get_data( 'calendar_{}'.format(item['start']['date']) ) # Check if an existing key exists for the date in question if current == None: set_data('calendar_{}'.format(item['start']['date']), item['summary']) # If a date doesn't exist create one elif item[ 'summary'] not in current: # If a key exists but it's not the current summary it means we have two items for one date set_data('calendar_{}'.format(item['start']['date']), '{}{}{}'.format( current, calendar_split, item['summary'])) # Append to the existing item else: logger.error('Could not parse calendar')
def store_resource_data(module_name, data, validity): """ Store data returned by get_module_name_data in redis as key value pairs The module must return data in the format returned by get_prometheus_data other modules will be moved over to this format since it doesn't allow host names to collide between accounts """ for account in data: for host in data[account]: uuid = to_uuid('{}{}'.format(account, host)) if data[account][host].get('volatile') == True: set_volatile_data('resources:{}#{}'.format(module_name, uuid), json.dumps([data[account][host]]), 300) else: set_data('resources:{}#{}'.format(module_name, uuid), json.dumps([data[account][host]])) set_data('resources_success:{}'.format(module_name), json.dumps([validity]))
def store_port_monitoring_results(module, module_data, module_validity): # we are storing everything inside an extra list so we can take it # out of that list when we pull it out of redis - don't ask set_data('port_monitoring:{}'.format(module), json.dumps([module_data])) set_data('port_monitoring_success:{}'.format(module), json.dumps([module_validity]))