def get_osinfo(self): ''' @return: dict d with keys: 'osdevicename', 'osplatform', 'ostime', 'osuptime' ''' d = {'osdevicename': '', 'osplatform': '', 'ostime': '', 'osuptime': ''} if self._is_online: version = VERSION_OUT_FRMT o = json.loads(NXAPITransport.clid('show version')) version = version.format(chassis=o['chassis_id'], image=o['kick_file_name']) osuptime = ('days: {0}, hrs: {1}, mins: {2}, secs: {3}' ''.format(o['kern_uptm_days'], o['kern_uptm_hrs'], o['kern_uptm_mins'], o['kern_uptm_secs'])) devicename = o['host_name'] try: o = json.loads(NXAPITransport.clid('show clock')) except cmd_exec_error: # N3K issue o['simple_time'] = NXAPITransport.cli('show clock') ostime = o["simple_time"] d['osplatform'] = version d['osdevicename'] = devicename d['ostime'] = ostime d['osuptime'] = osuptime return d
def get_osinfo(self): ''' @return: dict d with keys: 'osdevicename', 'osplatform', 'ostime', 'osuptime' ''' d = { 'osdevicename': '', 'osplatform': '', 'ostime': '', 'osuptime': '' } if self._is_online: version = VERSION_OUT_FRMT o = json.loads(NXAPITransport.clid('show version')) version = version.format(chassis=o['chassis_id'], image=o['kick_file_name']) osuptime = ('days: {0}, hrs: {1}, mins: {2}, secs: {3}' ''.format(o['kern_uptm_days'], o['kern_uptm_hrs'], o['kern_uptm_mins'], o['kern_uptm_secs'])) devicename = o['host_name'] o = json.loads(NXAPITransport.clid('show clock')) ostime = o["simple_time"] d['osplatform'] = version d['osdevicename'] = devicename d['ostime'] = ostime d['osuptime'] = osuptime return d
def get_modulestats(self): ''' @return: dict d with keys matching exactly as attributes of dashboardperdevice.models.ModulesStats ''' l = list() if self._is_online: o = json.loads(NXAPITransport.clid('show module')) try: diaginfos = o['TABLE_moddiaginfo']['ROW_moddiaginfo'] modinfos = o['TABLE_modinfo']['ROW_modinfo'] modmacinfos = o['TABLE_modmacinfo']['ROW_modmacinfo'] for r in modinfos: d = dict() d['status'] = r['status'] d['hw_desc'] = r['modtype'] d['hw_model'] = r['model'] d['mod_id'] = r['modinf'] d['ports'] = r['ports'] d['serial_no'] = [ i['serialnum'] for i in modmacinfos if i['modmac'] == d['mod_id'] ][0] d['diag_stat'] = [ i['diagstatus'] for i in diaginfos if i['mod'] == d['mod_id'] ][0] l.append(d) except Exception as e: print 'Error while get_modulestats', e return l
def get_modulestats(self): ''' @return: dict d with keys matching exactly as attributes of dashboardperdevice.models.ModulesStats ''' l = list() if self._is_online: o = json.loads(NXAPITransport.clid('show module')) try: diaginfos = o['TABLE_moddiaginfo']['ROW_moddiaginfo'] modinfos = o['TABLE_modinfo']['ROW_modinfo'] modmacinfos = o['TABLE_modmacinfo']['ROW_modmacinfo'] for r in modinfos: d = dict() d['status'] = r['status'] d['hw_desc'] = r['modtype'] d['hw_model'] = r['model'] d['mod_id'] = r['modinf'] d['ports'] = r['ports'] d['serial_no'] = [i['serialnum'] for i in modmacinfos if i['modmac'] == d['mod_id']][0] d['diag_stat'] = [i['diagstatus'] for i in diaginfos if i['mod'] == d['mod_id']][0] l.append(d) except Exception as e: print 'Error while get_modulestats', e return l
def sw_version(self): version = '' if self._is_online is True: version = VERSION_OUT_FRMT o = json.loads(NXAPITransport.clid('show version')) version = version.format(chassis=o['chassis_id'], image=o['kick_file_name']) return version
def get_intstats(self): ''' @return: dict d with keys matching exactly as attributes of dashboardperdevice.models.InterfacesStats ''' list_of_ints = list() if self._is_online: rows = json.loads(NXAPITransport.clid( 'show interface'))['TABLE_interface']['ROW_interface'] for o in rows: d = dict() int_name = o["interface"] d['int_name'] = int_name if 'vlan' in int_name.lower(): int_state = o.get("svi_line_proto", '') int_adminstate = o.get("svi_admin_state", '') int_mtu = o.get("svi_mtu", '') int_bw = o.get("svi_bw", '') int_hwdesc = o.get("svi_hw_desc", "VLAN") int_hwaddr = o.get("svi_mac", '') int_ipaddr = o.get("svi_ip_addr", '') int_ipmask = o.get("svi_ip_mask", '') else: int_state = o.get("state", '') int_adminstate = o.get("admin_state", int_state) int_mtu = o.get("eth_mtu", '') int_bw = o.get("eth_bw", '') int_hwdesc = o.get("eth_hw_desc", '') int_hwaddr = o.get("eth_hw_addr", '') int_ipaddr = o.get("eth_ip_addr", '') int_ipmask = o.get("eth_ip_mask", '') if 'mgmt' in int_name.lower(): int_bpsrate_rx = o.get("vdc_lvl_in_avg_bits", '') int_bpsrate_tx = o.get("vdc_lvl_out_avg_bits", '') int_loadinterval = 60 else: int_bpsrate_rx = o.get("eth_inrate1_bits", '') int_bpsrate_tx = o.get("eth_outrate1_bits", '') int_loadinterval = o.get("eth_load_interval1_rx", 0) if 'down' in int_state.lower(): int_bpsrate_tx = int_bpsrate_rx = 0 d['int_state'] = int_state d['int_adminstate'] = int_adminstate d['int_mtu'] = int_mtu d['int_bw'] = int_bw d['int_desc'] = o.get("desc", '') d['int_hwdesc'] = int_hwdesc d['int_hwaddr'] = int_hwaddr d['int_ipaddr'] = int_ipaddr d['int_ipmask'] = int_ipmask d['int_bpsrate_rx'] = int_bpsrate_rx d['int_bpsrate_tx'] = int_bpsrate_tx d['int_loadinterval'] = int(int_loadinterval) list_of_ints.append(d) return list_of_ints
def get_intstats(self): ''' @return: dict d with keys matching exactly as attributes of dashboardperdevice.models.InterfacesStats ''' list_of_ints = list() if self._is_online: rows = json.loads(NXAPITransport.clid('show interface'))['TABLE_interface']['ROW_interface'] for o in rows: d = dict() int_name = o["interface"] d['int_name'] = int_name if 'vlan' in int_name.lower(): int_state = o.get("svi_line_proto", '') int_adminstate = o.get("svi_admin_state", '') int_mtu = o.get("svi_mtu", '') int_bw = o.get("svi_bw", '') int_hwdesc = o.get("svi_hw_desc", "VLAN") int_hwaddr = o.get("svi_mac", '') int_ipaddr = o.get("svi_ip_addr", '') int_ipmask = o.get("svi_ip_mask", '') else: int_state = o.get("state", '') int_adminstate = o.get("admin_state", int_state) int_mtu = o.get("eth_mtu", '') int_bw = o.get("eth_bw", '') int_hwdesc = o.get("eth_hw_desc", '') int_hwaddr = o.get("eth_hw_addr", '') int_ipaddr = o.get("eth_ip_addr", '') int_ipmask = o.get("eth_ip_mask", '') if 'mgmt' in int_name.lower(): int_bpsrate_rx = o.get("vdc_lvl_in_avg_bits", '') int_bpsrate_tx = o.get("vdc_lvl_out_avg_bits", '') int_loadinterval = 60 else: int_bpsrate_rx = o.get("eth_inrate1_bits", '') int_bpsrate_tx = o.get("eth_outrate1_bits", '') int_loadinterval = o.get("eth_load_interval1_rx", 0) if 'down' in int_state.lower(): int_bpsrate_tx = int_bpsrate_rx = 0 d['int_state'] = int_state d['int_adminstate'] = int_adminstate d['int_mtu'] = int_mtu d['int_bw'] = int_bw d['int_desc'] = o.get("desc", '') d['int_hwdesc'] = int_hwdesc d['int_hwaddr'] = int_hwaddr d['int_ipaddr'] = int_ipaddr d['int_ipmask'] = int_ipmask d['int_bpsrate_rx'] = int_bpsrate_rx d['int_bpsrate_tx'] = int_bpsrate_tx d['int_loadinterval'] = int(int_loadinterval) list_of_ints.append(d) return list_of_ints
def get_memstats(self): ''' @return: dict d with keys matching exactly as attributes of dashboardperdevice.models.MemStats ''' d = dict() if self._is_online: o = json.loads(NXAPITransport.clid('show system resources')) d['mem_used'] = o['memory_usage_used'] d['mem_free'] = o['memory_usage_free'] d['mem_total'] = o['memory_usage_total'] return d
def get_cpustats(self): ''' @return: dict d with keys matching exactly as attributes of dashboardperdevice.models.CpuStats ''' d = dict() if self._is_online: o = json.loads(NXAPITransport.clid('show system resources')) d['per1min'] = o['load_avg_1min'] d['per5min'] = o['load_avg_5min'] d['per15min'] = o['load_avg_15min'] return d
def get_modulestats(self): ''' @return: dict d with keys matching exactly as attributes of dashboardperdevice.models.ModulesStats ''' l = list() if self._is_online: o = json.loads(NXAPITransport.clid('show module')) try: try : diaginfos = o['TABLE_moddiaginfo']['ROW_moddiaginfo'] except KeyError: diaginfos = None tmpmodinfo = o['TABLE_modinfo']['ROW_modinfo'] if type(tmpmodinfo) == dict: #N3K issue modinfos = list() modinfos.append( tmpmodinfo) else: modinfos = o['TABLE_modinfo']['ROW_modinfo'] tmpmac = o['TABLE_modmacinfo']['ROW_modmacinfo'] if type(tmpmac) == dict: #N3K issue modmacinfos = list() modmacinfos.append(tmpmac) else: modmacinfos = tmpmac for r in modinfos: d = dict() d['status'] = r['status'] d['hw_desc'] = r['modtype'] d['hw_model'] = r['model'] d['mod_id'] = r['modinf'] d['ports'] = r['ports'] d['serial_no'] = [i['serialnum'] for i in modmacinfos if i['modmac'] == d['mod_id']][0] if diaginfos != None: d['diag_stat'] = [i['diagstatus'] for i in diaginfos if i['mod'] == d['mod_id']][0] l.append(d) except Exception as e: print 'Error while get_modulestats', e traceback.print_exc(file=sys.stdout) return l
def is_healthy(self): healthy = True if self._is_online is True: o1 = json.loads(NXAPITransport.clid('show system resources')) loads = list() loads.append(float(o1['cpu_state_kernel'])) loads.append(float(o1['load_avg_1min'])) loads.append(float(o1['load_avg_15min'])) loads.append(float(o1['cpu_state_user'])) healthy_cpu = True cpu_used_percent = ('{0} (Kernel), {1} (1min), {2} ' '(15min), {3} (User)' '').format(loads[0], loads[1], loads[2], loads[3]) for load in loads: if load > CPU_THRESHOLD: healthy_cpu = False healthy = False loggedin_msg = 'Logged in successfully to {0}'.format( self.target_url) self.health_statuses.append((loggedin_msg, True)) self.health_statuses.append( ('CPU Used (%): {0}'.format(cpu_used_percent), healthy_cpu)) memory_usage_used = float(o1['memory_usage_used']) memory_usage_total = float(o1['memory_usage_total']) mem_used_percent = memory_usage_used / memory_usage_total * 100 if mem_used_percent > MEMORY_USED_THRESHOLD: healthy_mem = False healthy = False else: healthy_mem = True self.health_statuses.append( (('Memory Used (%): {0:.2f}' ''.format(mem_used_percent)), healthy_mem)) current_memory_status = o1['current_memory_status'] if current_memory_status != 'OK': healthy_mem_txt = False healthy = False else: healthy_mem_txt = True self.health_statuses.append( (('Current Memory Status: {0}' ''.format(current_memory_status)), healthy_mem_txt)) o2 = json.loads(NXAPITransport.clid('show module')) online_diag_statuses = o2['TABLE_moddiaginfo']['ROW_moddiaginfo'] diagstatuses = True for r in online_diag_statuses: diagstatus = r['diagstatus'] if diagstatus != 'Pass': diagstatuses = False healthy = False self.health_statuses.append( (('Module no. {0} ' 'Diag Status: {1}' ''.format(r['mod'], diagstatus)), diagstatuses)) if diagstatuses: self.health_statuses.append( ('Modules Diag Status: Pass', diagstatuses)) modinfo = o2['TABLE_modinfo']['ROW_modinfo'] modstatus = True for r in modinfo: status = r['status'] if status not in ['ok', 'active', 'active *', 'standby']: modstatus = False healthy = False self.health_statuses.append( (('Module no. {0} Status: {1}' ''.format(r['modinf']), status), modstatus)) if modstatus: self.health_statuses.append(('Modules Status: Ok', modstatus)) else: healthy = False return healthy
def is_healthy(self): healthy = True if self._is_online is True: o1 = json.loads(NXAPITransport.clid('show system resources')) loads = list() loads.append(float(o1['cpu_state_kernel'])) loads.append(float(o1['load_avg_1min'])) loads.append(float(o1['load_avg_15min'])) loads.append(float(o1['cpu_state_user'])) healthy_cpu = True cpu_used_percent = ('{0} (Kernel), {1} (1min), {2} ' '(15min), {3} (User)' '').format(loads[0], loads[1], loads[2], loads[3]) for load in loads: if load > CPU_THRESHOLD: healthy_cpu = False healthy = False loggedin_msg = 'Logged in successfully to {0}'.format(self.target_url) self.health_statuses.append((loggedin_msg, True)) self.health_statuses.append(('CPU Used (%): {0}'.format(cpu_used_percent), healthy_cpu)) memory_usage_used = float(o1['memory_usage_used']) memory_usage_total = float(o1['memory_usage_total']) mem_used_percent = memory_usage_used/memory_usage_total*100 if mem_used_percent > MEMORY_USED_THRESHOLD: healthy_mem = False healthy = False else: healthy_mem = True self.health_statuses.append((('Memory Used (%): {0:.2f}' ''.format(mem_used_percent)), healthy_mem)) if not o1.has_key('current_memory_status'): current_memory_status = 'NA' else: current_memory_status = o1['current_memory_status'] if current_memory_status != 'OK': healthy_mem_txt = False healthy = False else: healthy_mem_txt = True self.health_statuses.append((('Current Memory Status: {0}' ''.format(current_memory_status)), healthy_mem_txt)) o2 = json.loads(NXAPITransport.clid('show module')) try : online_diag_statuses = o2['TABLE_moddiaginfo']['ROW_moddiaginfo'] diagstatuses = True for r in online_diag_statuses: diagstatus = r['diagstatus'] if diagstatus != 'Pass': diagstatuses = False healthy = False self.health_statuses.append((('Module no. {0} ' 'Diag Status: {1}' ''.format(r['mod'], diagstatus)), diagstatuses)) if diagstatuses: self.health_statuses.append(('Modules Diag Status: Pass', diagstatuses)) except KeyError: pass modinfo = o2['TABLE_modinfo']['ROW_modinfo'] modstatus = True if type(modinfo) == dict: #N3K issue r = modinfo status = r['status'].strip() if status not in ['ok', 'active', 'active *', 'standby']: modstatus = False healthy = False self.health_statuses.append((('Module no. {0} Status: {1}' ''.format(r['modinf']), status), modstatus)) else: for r in modinfo: status = r['status'] if status.strip() not in ['ok', 'active', 'active *', 'standby']: modstatus = False healthy = False self.health_statuses.append((('Module no. {0} Status: {1}' ''.format(r['modinf']), status), modstatus)) if modstatus: self.health_statuses.append(('Modules Status: Ok', modstatus)) else: healthy = False return healthy