def droplet_status(): all_result = [] print 'Sending Request...' success, call = digital_ocean_api_call('droplets', 'get') if success: print 'Success' data = call.json() droplets = data['droplets'] else: print 'Failed' raise RuntimeError for droplet in droplets: result = {} result['id'] = droplet['id'] result['name'] = droplet['name'] result['status'] = droplet['status'] hostname = str(droplet['name']) result['region'] = droplet['region']['slug'] system_ips = {} for protocols, ips in droplet['networks'].items(): temp_ips = {} for ip in ips: if ip['type'] == 'public': temp_ips['public'] = ip['ip_address'] elif ip['type'] == 'private': temp_ips['private'] = ip['ip_address'] system_ips[protocols] = temp_ips result.update(system_ips) result['ping'] = check_ping(system_ips['v4']['public']) if result['status'] == 'active' else False result['check_http'] = True # check_django(hostname) if result['status'] == 'active' else False result['last_check'] = get_amsterdam_time() all_result.append(result) return all_result
def vultr_status(): success, call = vultr_api_call('server', 'list', 'get') if success: data = call.json() else: raise RuntimeError vultr_machines = [] for vm_id, properties in data.items(): vultr = {} vultr['id'] = vm_id vultr['internal_ip'] = properties['internal_ip'] vultr['ip'] = properties['main_ip'] vultr['hostname'] = properties['label'] vultr['region'] = properties['location'] vultr['status'] = properties['status'] vultr['server_state'] = properties['server_state'] vultr['ping'] = check_ping(vultr['ip']) vultr['check_http'] = True # check_http(vultr['ip']) vultr['last_check'] = get_amsterdam_time() vultr_machines.append(vultr) return vultr_machines