def __init__(self, lsblk): Component.__init__(self, lsblk, None) self.lsblk = lsblk self.data = {"size": self.__size(), "devname": self.lsblk["name"]} if not self.__is_nvme(): self.data["smart"] = utils.get_smart_attributes(self.lsblk["name"]) match = re.search(r"^(\S+)_(\S+_\S+)", self.__getter("model")) if match: self.vendor = match.group(1) self.model = match.group(2) self.name = match.group(1) + " " + match.group(2) else: self.model = self.__getter("model") self.name = self.model if self.lsblk["vendor"] is None: self.vendor = self.model.split(" ")[0] else: self.vendor = self.lsblk["vendor"].strip() self.serial = self.__getter("serial") self.firmware_version = self.__getter("firmware_version") if self.__is_megaraid(): self.vendor = utils.get_smart_diskprop(self.lsblk["name"], "vendor") if self.vendor.strip() == "ATA": self.vendor = utils.normalize_vendor(self.model) else: self.vendor = utils.normalize_vendor(self.vendor)
def __init__(self, lshw, element): Component.__init__(self, lshw, element) self.data = { "rate": utils.xml_ev(lshw, element, "size"), "devname": utils.xml_ev(lshw, element, "logicalname"), "driver": utils.xml_ev(lshw, element, "configuration/setting[@id='driver']/@value", True), } if self.data["rate"] == "": self.data["rate"] = utils.xml_ev(lshw, element, "capacity") self.name = utils.xml_ev(lshw, element, "product") self.model = utils.xml_ev(lshw, element, "product") self.serial = utils.ethtool_mac( utils.xml_ev(lshw, element, "logicalname")) self.vendor = utils.normalize_vendor( utils.xml_ev(lshw, element, "vendor")) self.firmware_version = utils.xml_ev( lshw, element, "configuration/setting[@id='firmware']/@value", True) if not utils.xml_ev(lshw, element, "businfo") == "": self.pci_id = utils.xml_ev(lshw, element, "businfo").split(":", 1)[1] else: self.pci_id = "" if "Illegal Vendor ID" in self.vendor and self.pci_id != "": _lspci = utils.lspci(self.pci_id) self.vendor = utils.normalize_vendor(_lspci["vendor"]) self.model = _lspci["device"] self.name = self.model if "Mellanox" in self.vendor and self.pci_id != "": try: self.firmware_version = utils.get_mellanox_prop( self.pci_id, "firmware_version") self.model = utils.get_mellanox_part_number(self.pci_id) self.data["mellanox_psid"] = utils.get_mellanox_prop( self.pci_id, "psid") except Exception: self.firmware_version = "" utils.log(message="get_mellanox_prop failed.")
def __init__(self, lshw, element): Component.__init__(self, lshw, element) self.data = { "slot": utils.xml_ev(lshw, element, "slot"), "size": str(int(int(utils.xml_ev(lshw, element, "size")) / 1024000000)) + "GB", "clock": int(utils.xml_ev(lshw, element, "clock")) / 1000000 if utils.xml_ev(lshw, element, "clock") else "", "type": utils.get_dmidecode_prop( "0x" + utils.xml_ev(lshw, element, "@handle", True).split(":", 1)[1], "17", "type", ), "asset_tag": "Unknown", } self.name = utils.xml_ev(lshw, element, "description") self.model = utils.xml_ev(lshw, element, "product") self.vendor = utils.normalize_vendor( utils.xml_ev(lshw, element, "vendor")) self.serial = utils.xml_ev(lshw, element, "serial") self.firmware_version = "N/A"
def __init__(self, lshw, element): Component.__init__(self, lshw, element) self.data = { "uuid": utils.xml_ev( lshw, lshw.getroot(), "node[@class='system']/configuration/setting[@id='uuid']/@value", True, ), "date": utils.xml_ev(lshw, element, "node[@id='firmware']/date"), } self.vendor = utils.normalize_vendor( utils.xml_ev(lshw, element, "vendor")) if self.vendor == "Dell Inc.": self.model = utils.dmidecode_string("system-product-name") else: self.model = utils.xml_ev(lshw, element, "product") if self.model == "X11SSE-F": self.model = "MBD-X11SSE-F" self.name = self.model self.serial = utils.xml_ev(lshw, element, "serial") self.firmware_version = utils.xml_ev(lshw, element, "node[@id='firmware']/version")
def __init__(self, lshw, element): Component.__init__(self, lshw, element) self.name = utils.xml_ev(lshw, element, "description") self.model = utils.xml_ev(lshw, element, "product") self.serial = utils.xml_ev(lshw, element, "businfo") self.vendor = utils.normalize_vendor(utils.xml_ev(lshw, element, "vendor")) self.firmware_version = utils.xml_ev(lshw, element, "version") self.data = { "driver": utils.xml_ev( lshw, element, "configuration/setting[@id='driver']/@value", True ) } if "MegaRAID" in self.model: self.serial = utils.get_megaraid_prop("serial") for prop in ( "product_name", "firmware_bios", "firmware_ctrlr", "firmware_fw", "firmware_nvdata", "firmware_boot", "bbu", "memory_size", ): self.data["megaraid_" + prop] = utils.get_megaraid_prop(prop)
def __init__(self): Component.__init__(self) self.data = {} self.model = utils.dmidecode_string("system-product-name") self.name = self.model + " Base Management Controller" self.vendor = utils.normalize_vendor(utils.get_mc_info("vendor")) self.serial = utils.get_mc_info("guid") self.firmware_version = utils.get_mc_info("firmware_version")
def __init__(self, lshw, element): Component.__init__(self, lshw, element) self.data = { "cores": utils.xml_ev( lshw, element, "configuration/setting[@id='cores']/@value", True ), "clock": utils.xml_ev(lshw, element, "capacity"), } self.name = utils.xml_ev(lshw, element, "product") self.model = utils.xml_ev(lshw, element, "version") self.vendor = utils.normalize_vendor(utils.xml_ev(lshw, element, "vendor")) self.serial = utils.xml_ev(lshw, element, "slot") self.firmware_version = "N/A"
def sync_smart_sheet(sheet_name, sheet_id, skip_rows_without_orders): api = os.environ.get("CYBERGRX_API", "https://api.cybergrx.com").rstrip("/") token = os.environ.get("CYBERGRX_API_TOKEN", None) if not token: raise Exception( "The environment variable CYBERGRX_API_TOKEN must be set") if not os.environ.get("SMARTSHEET_ACCESS_TOKEN", None): raise Exception( "The environment variable SMARTSHEET_ACCESS_TOKEN must be set") if not sheet_id and not sheet_name: raise Exception("Either --sheet-name or --sheet-id must be provided") smart = smartsheet.Smartsheet() smart.errors_as_exceptions(True) # If sheet_id was not provided, lookup the ID using the sheet name if not sheet_id: sheet_id = lookup_sheet_id(smart, sheet_name) # Load the entire sheet sheet = smart.Sheets.get_sheet(sheet_id) print("Loaded " + str(len(sheet.rows)) + " vendors from sheet: " + sheet.name) # Build column map for later reference - translates column names to smart sheet column ids for column in sheet.columns: if column.title in HEADER_MAPPING: HEADER_MAPPING[column.id] = HEADER_MAPPING[column.title] HEADER_MAPPING[column.title] = column.id else: snake_header = stringcase.snakecase( re.sub(r"[^0-9a-zA-Z]+", "", column.title)) HEADER_MAPPING[column.id] = snake_header HEADER_MAPPING[snake_header] = column.id # Load all vendors from smart sheet all_smart_sheet_vendors = [ normalize_vendor(vendor, HEADER_MAPPING, COMPANY_SCHEMA) for vendor in sheet.rows ] # Report any records that are missing data for v in all_smart_sheet_vendors: if not v["record_has_url_and_address"]: print("Missing data in", v) # Only operate on records that have full data smart_sheet_vendors = [ v for v in all_smart_sheet_vendors if v["record_has_url_and_address"] ] # Load all third parties skipping residual risk uri = api + "/bulk-v1/third-parties" print("Fetching third parties from " + uri + " this can take some time.") response = requests.get(uri, headers={"Authorization": token.strip()}) grx_vendors = glom(json.loads(response.content.decode("utf-8")), ([GRX_COMPANY_SCHEMA])) grx_custom_ids = set( [v["custom_id"] for v in grx_vendors if v["custom_id"]]) # See which vendors in smart sheets do not have a corresponding custom_id in CyberGRX missing_vendors = [ vendor for vendor in smart_sheet_vendors if vendor["custom_id"] not in grx_custom_ids ] if missing_vendors: print( "There are vendors in smart sheet that need to be migrated to CyberGRX" ) process_missing_vendors(missing_vendors, skip_rows_without_orders, token, api, sheet_id, smart) # Associate smart sheet vendors with CyberGRX records grx_vendor_map = {vendor["custom_id"]: vendor for vendor in grx_vendors} matched_vendors = [ vendor for vendor in smart_sheet_vendors if vendor["custom_id"] in grx_custom_ids ] for vendor in matched_vendors: vendor["grx"] = grx_vendor_map[vendor["custom_id"]] # Vendors that do not haave a complete profile, need to be updated vendors_with_profile = [ vendor for vendor in matched_vendors if not vendor["grx"]["is_profile_complete"] ] if vendors_with_profile: print( "There are vendors with profile questions that need to be answered in CyberGRX" ) process_vendors_with_profile_updates(vendors_with_profile, token, api) # For vendors that have matches, sync their risk back to smart sheets if matched_vendors: print( "There are vendors that need to sync risk profiles back to smart sheets" ) process_matched_vendors(matched_vendors, token, sheet_id, api, smart)