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'] = start_time+' - '+end_time+current_summary # Add the start and end time to the summary current = get_data('calendar_'+item['start']['date']) # Check if an existing key exists for the date in question if current == None: set_data('calendar_'+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_'+item['start']['date'], current+calendar_split+item['summary']) # Append to the existing item else: log_messages('Could not parse calendar', 'error')
def store_sirportly_results(): # Store all the sirportly data in redis sirportly_data = get_sirportly_data() for key in sirportly_data: if key == 'users': for key in sirportly_data['users']: set_data(key, sirportly_data['users'][key]) else: set_data(key, sirportly_data[key])
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_data('resources:tick#{}'.format(to_uuid(host)), json.dumps([host_data])) set_data('resources_success:tick', json.dumps([tick_data_validity]))
def store_newrelic_servers_data(newrelic_servers_data, newrelic_servers_data_validity): """ Store data returned by get_newrelic_servers_data in redis as key value pairs """ for host in newrelic_servers_data: host_data = newrelic_servers_data[host] set_data('resources:newrelic_servers#{}'.format(to_uuid(host)), json.dumps([host_data])) set_data('resources_success:newrelic_servers', json.dumps([newrelic_servers_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'] = start_time + ' - ' + end_time + current_summary # Add the start and end time to the summary current = get_data( 'calendar_' + item['start']['date'] ) # Check if an existing key exists for the date in question if current == None: set_data('calendar_' + 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_' + item['start']['date'], current + calendar_split + item['summary']) # Append to the existing item else: log_messages('Could not parse calendar', 'error')
def store_newrelic_results(): failed_newrelic = 0 total_accounts = 0 newrelic_data = get_newrelic_data() # Get all the newrelic checks for account in newrelic_data: if newrelic_data[account] != None: # Check we actually got some data for a check set_data('newrelic_'+account, newrelic_data[account]) # Store it in redis else: failed_newrelic +=1 log_messages('Could not get newrelic data for '+account, 'error') total_accounts+=1 set_data('total_newrelic_accounts', total_accounts) set_data('failed_newrelic', failed_newrelic)
def store_pingdom_results(): failed_pingdom = 0 total_accounts = 0 pingdom_data = get_pingdom_data() # Get all the pingdom data for account in pingdom_data: if pingdom_data[account] != None: # If we get a don't get a None store it, otherwise log the error set_data('pingdom_'+account, pingdom_data[account]) else: failed_pingdom +=1 log_messages('Could not get pingdom data for '+account, 'error') total_accounts +=1 set_data('total_pingdom_accounts', total_accounts) set_data('failed_pingdom', failed_pingdom)