def get_pci_info(ns): """ Prints tabular data of PCI devices info. """ result = [('PCI Devices:', '')] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: pci_dev = get_all_instances(ns, 'LMI_PCIDevice') pci_br = get_all_instances(ns, 'LMI_PCIBridge') except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing PCI related classes. Is openlmi-hardware package installed on the server?')] tf.produce_output(result) return [] pci = pci_dev + pci_br pci.sort(key=lambda x: x.DeviceID) if not pci: result += [(' N/A', 'No PCI Device was detected on the system.')] tf.produce_output(result) return [] result += get_pci_list(ns, pci) if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_storageinfo(ns): """ Prints tabular data of storage info. """ tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) try: localfss = get_all_instances(ns, 'LMI_LocalFileSystem') except Exception: result = [(get_colored_string('error:', RED_COLOR), 'Missing class LMI_LocalFileSystem. Is openlmi-storage package installed on the server?')] tf.produce_output(result) return [] total = 0 free = 0 for fs in localfss: if fs.FileSystemSize: total += fs.FileSystemSize if fs.AvailableSpace: free += fs.AvailableSpace result = [('Disk Space:', '%s total, %s free' % (format_memory_size(total), format_memory_size(free)))] tf.produce_output(result) return []
def get_osinfo(ns): """ Prints tabular data of system OS info. """ tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) try: os = get_single_instance(ns, 'PG_OperatingSystem') except Exception: result = [(get_colored_string('error:', RED_COLOR), 'Missing class PG_OperatingSystem on the server.')] tf.produce_output(result) return [] os_str = '' kernel_str = '' if os: os_str = os.Caption kernel_str = os.Version if not os_str: os_str = 'N/A' if not kernel_str: kernel_str = 'N/A' result = [ ('OS:', os_str), ('Kernel:', kernel_str)] tf.produce_output(result) return []
def get_networkinfo(ns): """ Prints tabular data of networking status. """ tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) result = [('', ''), ('Networking:', '')] try: lan_endpoints = get_all_instances(ns, 'LMI_LANEndpoint') except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing class LMI_LANEndpoint. Is openlmi-networking package installed on the server?')] tf.produce_output(result) return [] nic = 1 for lan_endpoint in lan_endpoints: if lan_endpoint.Name == 'lo': continue result += [ (' NIC %d' % nic, ''), (' Name:', lan_endpoint.Name)] try: ip_net_con = lan_endpoint.associators( AssocClass='LMI_EndpointForIPNetworkConnection', ResultClass='LMI_IPNetworkConnection')[0] result += [(' Status:', ns.LMI_IPNetworkConnection.OperatingStatusValues.value_name( ip_net_con.OperatingStatus))] except Exception: pass try: for ip_protocol_endpoint in lan_endpoint.associators( AssocClass='LMI_BindsToLANEndpoint', ResultClass='LMI_IPProtocolEndpoint'): if ip_protocol_endpoint.ProtocolIFType == \ ns.LMI_IPProtocolEndpoint.ProtocolIFTypeValues.IPv4: result += [(' IPv4 Address:', ip_protocol_endpoint.IPv4Address)] elif ip_protocol_endpoint.ProtocolIFType == \ ns.LMI_IPProtocolEndpoint.ProtocolIFTypeValues.IPv6: result += [(' IPv6 Address:', ip_protocol_endpoint.IPv6Address)] except Exception: pass result += [ (' MAC Address:', lan_endpoint.MACAddress)] tf.produce_output(result) result = [] nic += 1 return []
def get_motherboard_info(ns): """ Prints tabular data of motherboard info. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: i = get_single_instance(ns, 'LMI_Baseboard') if i: model = '' if i.Manufacturer: model += i.Manufacturer if i.Model: if model: model += ' ' model += i.Model result += [('Motherboard:', model)] else: if STANDALONE: result += [(get_colored_string( 'warning:', YELLOW_COLOR ), 'LMI_Baseboard instance is missing. This usually means that the server is virtual machine.' )] except Exception: result += [(get_colored_string( 'error:', RED_COLOR ), 'Missing class LMI_Baseboard. Is openlmi-hardware package installed on the server?' )] tf.produce_output(result) result = [] try: i = get_single_instance(ns, 'LMI_BIOSElement') if i and i.Name: result += [('BIOS:', i.Name)] else: result += [('BIOS:', 'N/A')] except Exception: result += [(get_colored_string( 'error:', RED_COLOR ), 'Missing LMI_BIOSElement class. Openlmi-hardware package is probably out-dated.' )] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_storageinfo(ns): """ Prints tabular data of storage info. """ tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) try: localfss = get_all_instances(ns, 'LMI_LocalFileSystem') except Exception: result = [(get_colored_string( 'error:', RED_COLOR ), 'Missing class LMI_LocalFileSystem. Is openlmi-storage package installed on the server?' )] tf.produce_output(result) return [] total = 0 free = 0 for fs in localfss: if fs.FileSystemSize: total += fs.FileSystemSize if fs.AvailableSpace: free += fs.AvailableSpace result = [('Disk Space:', '%s total, %s free' % (format_memory_size(total), format_memory_size(free)))] tf.produce_output(result) return []
def get_osinfo(ns): """ Prints tabular data of system OS info. """ tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) try: os = get_single_instance(ns, 'PG_OperatingSystem') except Exception: result = [(get_colored_string('error:', RED_COLOR), 'Missing class PG_OperatingSystem on the server.')] tf.produce_output(result) return [] os_str = '' kernel_str = '' if os: os_str = os.Caption kernel_str = os.Version if not os_str: os_str = 'N/A' if not kernel_str: kernel_str = 'N/A' result = [('OS:', os_str), ('Kernel:', kernel_str)] tf.produce_output(result) return []
def get_system_info(ns): """ Prints tabular data of system info, from the ``LMI_Chassis`` instance. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: i = get_single_instance(ns, 'LMI_Chassis') except Exception: result += [(get_colored_string( 'error:', RED_COLOR ), 'Missing class LMI_Chassis. Is openlmi-hardware package installed on the server?' )] tf.produce_output(result) return [] if i.Model and i.ProductName: model = '%s (%s)' % (i.Model, i.ProductName) elif i.Model: model = i.Model elif i.ProductName: model = i.ProductName else: model = 'N/A' if i.Manufacturer: model = '%s %s' % (i.Manufacturer, model) virt = getattr(i, 'VirtualMachine', None) if virt is None: virt = 'N/A. You are probably using old openlmi-hardware package on the server.' elif not virt: virt = 'N/A' result += [('Chassis Type:', ns.LMI_Chassis.ChassisPackageTypeValues.value_name( i.ChassisPackageType)), ('Model:', model), ('Serial Number:', i.SerialNumber), ('Asset Tag:', i.Tag), ('Virtual Machine:', virt)] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_selinuxinfo(ns): """ Prints tabular data of SELinux info. """ tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) try: selinux = get_single_instance(ns, 'LMI_SELinuxService') except Exception: result = [(get_colored_string('error:', RED_COLOR), 'Missing class LMI_SELinuxService. Is openlmi-selinux package installed on the server?')] tf.produce_output(result) return [] if selinux.SELinuxState == 0: selinux_str = 'off' else: selinux_str = 'on (%s)' % \ ns.LMI_SELinuxService.SELinuxStateValues.value_name(selinux.SELinuxState) tf.produce_output([('SELinux:', selinux_str)]) return []
def get_servicesinfo(ns): """ Prints tabular data of some system services. """ tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) # Firewall try: fw = '' firewalld = get_service(ns, 'firewalld') if firewalld and firewalld.Status == 'OK': fw = 'on (firewalld)' else: iptables = get_service(ns, 'iptables') if iptables and iptables.Status == 'OK': fw = 'on (iptables)' if not fw: fw = 'off' except Exception: fw = 'N/A' tf.produce_output([('Firewall:', fw)]) # Logging try: logging = '' journald = get_service(ns, 'systemd-journald') if journald and journald.Status == 'OK': logging = 'on (journald)' else: rsyslog = get_service(ns, 'rsyslog') if rsyslog and rsyslog.Status == 'OK': logging = 'on (rsyslog)' if not logging: logging = 'off' except Exception: logging = 'N/A' tf.produce_output([('Logging:', logging)]) return []
def get_motherboard_info(ns): """ Prints tabular data of motherboard info. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: i = get_single_instance(ns, 'LMI_Baseboard') if i: model = '' if i.Manufacturer: model += i.Manufacturer if i.Model: if model: model += ' ' model += i.Model result += [('Motherboard:', model)] else: if STANDALONE: result += [(get_colored_string('warning:', YELLOW_COLOR), 'LMI_Baseboard instance is missing. This usually means that the server is virtual machine.')] except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing class LMI_Baseboard. Is openlmi-hardware package installed on the server?')] tf.produce_output(result) result = [] try: i = get_single_instance(ns, 'LMI_BIOSElement') if i and i.Name: result += [('BIOS:', i.Name)] else: result += [('BIOS:', 'N/A')] except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing LMI_BIOSElement class. Openlmi-hardware package is probably out-dated.')] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_system_info(ns): """ Prints tabular data of system info, from the ``LMI_Chassis`` instance. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: i = get_single_instance(ns, 'LMI_Chassis') except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing class LMI_Chassis. Is openlmi-hardware package installed on the server?')] tf.produce_output(result) return [] if i.Model and i.ProductName: model = '%s (%s)' % (i.Model, i.ProductName) elif i.Model: model = i.Model elif i.ProductName: model = i.ProductName else: model = 'N/A' if i.Manufacturer: model = '%s %s' % (i.Manufacturer, model) virt = getattr(i, 'VirtualMachine', None) if virt is None: virt = 'N/A. You are probably using old openlmi-hardware package on the server.' elif not virt: virt = 'N/A' result += [ ('Chassis Type:', ns.LMI_Chassis.ChassisPackageTypeValues.value_name( i.ChassisPackageType)), ('Model:', model), ('Serial Number:', i.SerialNumber), ('Asset Tag:', i.Tag), ('Virtual Machine:', virt)] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_networkinfo(ns): """ Prints tabular data of networking status. """ tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) result = [('', ''), ('Networking:', '')] try: lan_endpoints = get_all_instances(ns, 'LMI_LANEndpoint') except Exception: result += [(get_colored_string( 'error:', RED_COLOR ), 'Missing class LMI_LANEndpoint. Is openlmi-networking package installed on the server?' )] tf.produce_output(result) return [] nic = 1 for lan_endpoint in lan_endpoints: if lan_endpoint.Name == 'lo': continue result += [(' NIC %d' % nic, ''), (' Name:', lan_endpoint.Name)] try: ip_net_con = lan_endpoint.associators( AssocClass='LMI_EndpointForIPNetworkConnection', ResultClass='LMI_IPNetworkConnection')[0] result += [ (' Status:', ns.LMI_IPNetworkConnection.OperatingStatusValues.value_name( ip_net_con.OperatingStatus)) ] except Exception: pass try: for ip_protocol_endpoint in lan_endpoint.associators( AssocClass='LMI_BindsToLANEndpoint', ResultClass='LMI_IPProtocolEndpoint'): if ip_protocol_endpoint.ProtocolIFType == \ ns.LMI_IPProtocolEndpoint.ProtocolIFTypeValues.IPv4: result += [(' IPv4 Address:', ip_protocol_endpoint.IPv4Address)] elif ip_protocol_endpoint.ProtocolIFType == \ ns.LMI_IPProtocolEndpoint.ProtocolIFTypeValues.IPv6: result += [(' IPv6 Address:', ip_protocol_endpoint.IPv6Address)] except Exception: pass result += [(' MAC Address:', lan_endpoint.MACAddress)] tf.produce_output(result) result = [] nic += 1 return []
def get_langinfo(ns): """ Prints tabular data of language and time zone info. """ tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) try: locale = get_single_instance(ns, 'LMI_Locale') except Exception: result = [(get_colored_string('error:', RED_COLOR), 'Missing class LMI_Locale. Is openlmi-locale package installed on the server?')] tf.produce_output(result) return [] tf.produce_output([('Language:', locale.Lang)]) try: tf.produce_output([('Time Zone:', "%s (NTP is %s)" % (locale.Timezone, 'on' if locale.NTP else 'off'))]) except Exception: # Time Zone info was added later to the LMI_Locale class pass return []
def get_cpu_info(ns): """ Prints tabular data of processor info. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: cpus = get_all_instances(ns, 'LMI_Processor') cpu_caps = get_all_instances(ns, 'LMI_ProcessorCapabilities') except Exception: result += [(get_colored_string( 'error:', RED_COLOR ), 'Missing CPU related classes. Is openlmi-hardware package installed on the server?' )] tf.produce_output(result) return [] cores = 0 threads = 0 for i in cpu_caps: cores += i.NumberOfProcessorCores threads += i.NumberOfHardwareThreads result += [ ('CPU:', cpus[0].Name), ('Topology:', '%d cpu(s), %d core(s), %d thread(s)' % \ (len(cpus), cores, threads)), ('Max Freq:', '%d MHz' % cpus[0].MaxClockSpeed), ('Arch:', cpus[0].Architecture)] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_cpu_info(ns): """ Prints tabular data of processor info. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: cpus = get_all_instances(ns, 'LMI_Processor') cpu_caps = get_all_instances(ns, 'LMI_ProcessorCapabilities') except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing CPU related classes. Is openlmi-hardware package installed on the server?')] tf.produce_output(result) return [] cores = 0 threads = 0 for i in cpu_caps: cores += i.NumberOfProcessorCores threads += i.NumberOfHardwareThreads result += [ ('CPU:', cpus[0].Name), ('Topology:', '%d cpu(s), %d core(s), %d thread(s)' % \ (len(cpus), cores, threads)), ('Max Freq:', '%d MHz' % cpus[0].MaxClockSpeed), ('Arch:', cpus[0].Architecture)] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_all_info(ns): """ Prints tabular data of all available info. """ global STANDALONE STANDALONE = False tf = TableFormatter(stdout, 0, True) tf.print_host(get_hostname(ns)) try: get_system_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_motherboard_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_cpu_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_memory_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_pci_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_disks_info(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) STANDALONE = True return []
def get_memory_info(ns): """ Prints tabular data of memory info. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: memory = get_single_instance(ns, 'LMI_Memory') phys_memory = get_all_instances(ns, 'LMI_PhysicalMemory') memory_slots = get_all_instances(ns, 'LMI_MemorySlot') except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing memory related classes. Is openlmi-hardware package installed on the server?')] tf.produce_output(result) return [] size = format_memory_size(memory.NumberOfBlocks) slots = '' if phys_memory: slots += '%d' % len(phys_memory) else: slots += 'N/A' slots += ' used, ' if memory_slots: slots += '%d' % len(memory_slots) else: slots += 'N/A' slots += ' total' modules = [] if phys_memory: for m in phys_memory: module = format_memory_size(m.Capacity) if m.MemoryType: module += ', %s' % \ ns.LMI_PhysicalMemory.MemoryTypeValues.value_name(m.MemoryType) if m.FormFactor: module += ' (%s)' % \ ns.LMI_PhysicalMemory.FormFactorValues.value_name( m.FormFactor) if m.ConfiguredMemoryClockSpeed: module += ', %d MHz' % m.ConfiguredMemoryClockSpeed if m.Manufacturer: module += ', %s' % m.Manufacturer if m.BankLabel: module += ', %s' % m.BankLabel if not modules: modules.append(('Modules:', module)) else: modules.append(('', module)) if not modules: modules.append(('Modules:', 'N/A')) result += [('Memory:', size)] result += modules result += [('Slots:', slots)] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_disks_info(ns): """ Prints tabular data of disk info. """ result = [('Disks:', '')] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: hdds = get_all_instances(ns, 'LMI_DiskDrive') except Exception: result += [(get_colored_string('error:', RED_COLOR), 'Missing LMI_DiskDrive class. Openlmi-hardware package is probably out-dated.')] tf.produce_output(result) return [] if not hdds: result += [(' N/A', 'No disk was detected on the system.')] tf.produce_output(result) return [] for hdd in hdds: phys_hdds = hdd.associators( AssocClass='LMI_DiskDriveRealizes', ResultClass='LMI_DiskPhysicalPackage') fws = hdd.associators( AssocClass='LMI_DiskDriveElementSoftwareIdentity', ResultClass='LMI_DiskDriveSoftwareIdentity') if phys_hdds and phys_hdds[0].Model: model = phys_hdds[0].Model else: model = 'N/A' if phys_hdds[0].Manufacturer \ and not model.startswith(phys_hdds[0].Manufacturer): man_model = '%s %s' % (phys_hdds[0].Manufacturer, model) else: man_model = model if fws[0].VersionString: fw = fws[0].VersionString else: fw = 'N/A' form_factor_dict = { 3: '5.25"', 4: '3.5"', 5: '2.5"', 6: '1.8"',} if hdd.FormFactor in form_factor_dict: form_factor = form_factor_dict[hdd.FormFactor] else: form_factor = 'N/A' if hdd.RPM != 0xffffffff: rpm = hdd.RPM else: rpm = 'N/A' if hdd.DiskType == 2: disk_type = 'HDD' elif hdd.DiskType == 3: disk_type = 'SSD' else: disk_type = 'N/A' status_to_color = { 'OK': GREEN_COLOR, 'Unknown': YELLOW_COLOR, 'Predictive Failure': RED_COLOR,} if hdd.OperationalStatus: smart = ns.LMI_DiskDrive.OperationalStatusValues.value_name( hdd.OperationalStatus[0]) smart = get_colored_string(smart, status_to_color[smart]) else: smart = get_colored_string('Unknown', YELLOW_COLOR) temp = getattr(hdd, 'Temperature', None) if temp: temp_str = '%d' % temp else: temp_str = 'N/A' temp_str += u' °C' if hdd.Name != hdd.DeviceID and hdd.Name != model: result += [(' %s' % hdd.DeviceID, hdd.Name)] else: result += [(' %s' % hdd.DeviceID, '')] result += [(' Model:', man_model), (' Firmware:', fw), (' Capacity:', format_memory_size(hdd.Capacity)), (' Form Factor:', form_factor), (' HDD/SSD:', disk_type), (' RPM:', rpm), (' SMART Status:', smart), (' Temperature:', temp_str)] tf.produce_output(result) result = [EMPTY_LINE] tf.produce_output(result) return []
def get_hwinfo(ns): """ Prints tabular data of system hw info. """ tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) # Chassis try: chassis = get_single_instance(ns, 'LMI_Chassis') except Exception: result = [(get_colored_string('error:', RED_COLOR), 'Missing class LMI_Chassis. Is openlmi-hardware package installed on the server?')] tf.produce_output(result) return [] hwinfo = chassis.Manufacturer if chassis.Model and chassis.Model != 'Not Specified' \ and chassis.Model != chassis.Manufacturer: hwinfo += ' ' + chassis.Model elif chassis.ProductName and chassis.ProductName != 'Not Specified' \ and chassis.ProductName != chassis.Manufacturer: hwinfo += ' ' + chassis.ProductName virt = getattr(chassis, 'VirtualMachine', None) if virt and virt != 'No': hwinfo += ' (%s virtual machine)' % virt chassis_res = [ ('Hardware:', hwinfo), ('Serial Number:', chassis.SerialNumber), ('Asset Tag:', chassis.Tag)] tf.produce_output(chassis_res) # CPUs try: cpus = get_all_instances(ns, 'LMI_Processor') cpu_caps = get_all_instances(ns, 'LMI_ProcessorCapabilities') except Exception: cpus = None cpu_caps = None if cpus and cpu_caps: cores = 0 threads = 0 for i in cpu_caps: cores += i.NumberOfProcessorCores threads += i.NumberOfHardwareThreads cpus_res = [ ('CPU:', '%s, %s arch' % (cpus[0].Name, cpus[0].Architecture)), ('CPU Topology:', '%d cpu(s), %d core(s), %d thread(s)' % \ (len(cpus), cores, threads))] else: cpus_res = [('CPU:', 'N/A')] tf.produce_output(cpus_res) # Memory try: memory = get_single_instance(ns, 'LMI_Memory') except Exception: memory = None if memory: memory_size = format_memory_size(memory.NumberOfBlocks) else: memory_size = 'N/A GB' tf.produce_output([('Memory:', memory_size)]) return []
def get_system_info(ns): """ Prints tabular data of all general system information. """ tf = TableFormatter(stdout, 0, True) tf.print_host(get_hostname(ns)) try: get_hwinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_storageinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_osinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_langinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_selinuxinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_servicesinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) try: get_networkinfo(ns) except Exception as e: tf.produce_output([(get_colored_string('error:', RED_COLOR), str(e))]) return []
def get_disks_info(ns): """ Prints tabular data of disk info. """ result = [('Disks:', '')] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: hdds = get_all_instances(ns, 'LMI_DiskDrive') except Exception: result += [(get_colored_string( 'error:', RED_COLOR ), 'Missing LMI_DiskDrive class. Openlmi-hardware package is probably out-dated.' )] tf.produce_output(result) return [] if not hdds: result += [(' N/A', 'No disk was detected on the system.')] tf.produce_output(result) return [] for hdd in hdds: phys_hdds = hdd.associators(ResultClass='LMI_DiskPhysicalPackage') fws = hdd.associators(ResultClass='LMI_DiskDriveSoftwareIdentity') if phys_hdds and phys_hdds[0].Model: model = phys_hdds[0].Model else: model = 'N/A' if phys_hdds[0].Manufacturer \ and not model.startswith(phys_hdds[0].Manufacturer): man_model = '%s %s' % (phys_hdds[0].Manufacturer, model) else: man_model = model if fws[0].VersionString: fw = fws[0].VersionString else: fw = 'N/A' form_factor_dict = { 3: '5.25"', 4: '3.5"', 5: '2.5"', 6: '1.8"', } if hdd.FormFactor in form_factor_dict: form_factor = form_factor_dict[hdd.FormFactor] else: form_factor = 'N/A' if hdd.RPM != 0xffffffff: rpm = hdd.RPM else: rpm = 'N/A' if hdd.DiskType == 2: disk_type = 'HDD' elif hdd.DiskType == 3: disk_type = 'SSD' else: disk_type = 'N/A' status_to_color = { 'OK': GREEN_COLOR, 'Unknown': YELLOW_COLOR, 'Predictive Failure': RED_COLOR, } if hdd.OperationalStatus: smart = ns.LMI_DiskDrive.OperationalStatusValues.value_name( hdd.OperationalStatus[0]) smart = get_colored_string(smart, status_to_color[smart]) else: smart = get_colored_string('Unknown', YELLOW_COLOR) temp = getattr(hdd, 'Temperature', None) if temp: temp_str = '%d' % temp else: temp_str = 'N/A' temp_str += u' °C' if hdd.Name != hdd.DeviceID and hdd.Name != model: result += [(' %s' % hdd.DeviceID, hdd.Name)] else: result += [(' %s' % hdd.DeviceID, '')] result += [(' Model:', man_model), (' Firmware:', fw), (' Capacity:', format_memory_size(hdd.Capacity)), (' Form Factor:', form_factor), (' HDD/SSD:', disk_type), (' RPM:', rpm), (' SMART Status:', smart), (' Temperature:', temp_str)] tf.produce_output(result) result = [EMPTY_LINE] tf.produce_output(result) return []
def get_memory_info(ns): """ Prints tabular data of memory info. """ result = [] tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) if STANDALONE: tf.print_host(get_hostname(ns)) try: memory = get_single_instance(ns, 'LMI_Memory') phys_memory = get_all_instances(ns, 'LMI_PhysicalMemory') memory_slots = get_all_instances(ns, 'LMI_MemorySlot') except Exception: result += [(get_colored_string( 'error:', RED_COLOR ), 'Missing memory related classes. Is openlmi-hardware package installed on the server?' )] tf.produce_output(result) return [] size = format_memory_size(memory.NumberOfBlocks) slots = '' if phys_memory: slots += '%d' % len(phys_memory) else: slots += 'N/A' slots += ' used, ' if memory_slots: slots += '%d' % len(memory_slots) else: slots += 'N/A' slots += ' total' modules = [] if phys_memory: for m in phys_memory: module = format_memory_size(m.Capacity) if m.MemoryType: module += ', %s' % \ ns.LMI_PhysicalMemory.MemoryTypeValues.value_name(m.MemoryType) if m.FormFactor: module += ' (%s)' % \ ns.LMI_PhysicalMemory.FormFactorValues.value_name( m.FormFactor) if m.ConfiguredMemoryClockSpeed: module += ', %d MHz' % m.ConfiguredMemoryClockSpeed if m.Manufacturer: module += ', %s' % m.Manufacturer if m.BankLabel: module += ', %s' % m.BankLabel if not modules: modules.append(('Modules:', module)) else: modules.append(('', module)) if not modules: modules.append(('Modules:', 'N/A')) result += [('Memory:', size)] result += modules result += [('Slots:', slots)] if not STANDALONE: result += [EMPTY_LINE] tf.produce_output(result) return []
def get_hwinfo(ns): """ Prints tabular data of system hw info. """ tf = TableFormatter(stdout, 0, True, {0: FIRST_COLUMN_MIN_SIZE}) # Chassis try: chassis = get_single_instance(ns, 'LMI_Chassis') except Exception: result = [(get_colored_string( 'error:', RED_COLOR ), 'Missing class LMI_Chassis. Is openlmi-hardware package installed on the server?' )] tf.produce_output(result) return [] hwinfo = chassis.Manufacturer if chassis.Model and chassis.Model != 'Not Specified' \ and chassis.Model != chassis.Manufacturer: hwinfo += ' ' + chassis.Model elif chassis.ProductName and chassis.ProductName != 'Not Specified' \ and chassis.ProductName != chassis.Manufacturer: hwinfo += ' ' + chassis.ProductName virt = getattr(chassis, 'VirtualMachine', None) if virt and virt != 'No': hwinfo += ' (%s virtual machine)' % virt chassis_res = [('Hardware:', hwinfo), ('Serial Number:', chassis.SerialNumber), ('Asset Tag:', chassis.Tag)] tf.produce_output(chassis_res) # CPUs try: cpus = get_all_instances(ns, 'LMI_Processor') cpu_caps = get_all_instances(ns, 'LMI_ProcessorCapabilities') except Exception: cpus = None cpu_caps = None if cpus and cpu_caps: cores = 0 threads = 0 for i in cpu_caps: cores += i.NumberOfProcessorCores threads += i.NumberOfHardwareThreads cpus_res = [ ('CPU:', '%s, %s arch' % (cpus[0].Name, cpus[0].Architecture)), ('CPU Topology:', '%d cpu(s), %d core(s), %d thread(s)' % \ (len(cpus), cores, threads))] else: cpus_res = [('CPU:', 'N/A')] tf.produce_output(cpus_res) # Memory try: memory = get_single_instance(ns, 'LMI_Memory') except Exception: memory = None if memory: memory_size = format_memory_size(memory.NumberOfBlocks) else: memory_size = 'N/A GB' tf.produce_output([('Memory:', memory_size)]) return []