def insert_app_data(app_data, collection=AppCollections.UniqueApplications): """Insert application data in the unique_applications collection. This function should not be called directly. Args: app_data(list|dict): List of dictionaires or a dictionary of the application data. Kwargs: collection (str): The name of the apps per agent collection, that will be used when updating the application data. default = unique_applications Basic Usage: >>> from vFense.plugins.patching._db import insert_app_data >>> app_data = { "kb": "", "customers": ["default"], "vendor_name": "", "description": "Facebook plugin for Gwibber\n Gwibber is a social networking client for GNOME. It supports Facebook,\n Twitter, Identi.ca, StatusNet, FriendFeed, Qaiku, Flickr, and Digg.\n .", "vulnerability_categories": [], "files_download_status": 5004, "release_date": 1394769600, "vendor_severity": "recommended", "app_id": "922bcb88f6bd75c1e40fcc0c571f603cd59cf7e05b4a192bd5d69c974acc1457", "reboot_required": "no", "os_code": "linux", "repo": "precise-updates/main", "support_url": "", "version": "3.4.2-0ubuntu2.4", "cve_ids": [], "rv_severity": "Recommended", "hidden": "no", "uninstallable": "yes", "vulnerability_id": "", "name": "gwibber-service-facebook" } >>> insert_app_data(app_data, collection) Returns: Tuple (status_code, count, error, generated ids) >>> (2001, 1, None, []) """ return insert_data_in_table(app_data, collection)
def update_apps_per_agent( pkg_list, collection=AppCollections.AppsPerAgent ): """Insert or Update into the apps_per_agent collection Args: pkg_list (list): List of all the applications you want to insert or update into the database. Kwargs: collection (str, optional): The name of the collection you want to update. default = apps_per_agent Basic Usage: >>> from vFense.plugins.patching._db import update_apps_per_agent >>> collection = 'apps_per_agent' >>> pkg_list = [ { "status": "installed", "install_date": 1397697799, "app_id": "c71c32209119ad585dd77e67c082f57f1d18395763a5fb5728c02631d511df5c", "update": 5014, "dependencies": [], "agent_id": "78211125-3c1e-476a-98b6-ea7f683142b3", "last_modified_time": 1398997520, "id": "000182347981c7b54577817fd93aa6cab39477c6dc59fd2dd8ba32e15914b28f", "customer_name": "default" } ] >>> update_apps_per_agent(pkg_list, collection) Returns: Tuple (status_code, count, error, generated ids) >>> (2001, 1, None, []) """ data = insert_data_in_table(pkg_list, collection) return data
def application_updater(customer_name, app_data, os_string, collection=AppCollections.UniqueApplications): """Insert or update an existing application in the provided collection. Args: customer_name (str): The name of the customer, this application is a part of. app_data (dict): Dictionary of the application data. os_string (str): The name of the operating system... Ubuntu 12.04 Kwargs: collection (str): The collection where app_data should be inserted or updated Basic Usage: >>> from vFense.plugins.patching.patching import application_updater >>> customer_name = 'default' >>> app_data = { "kb": "", "vendor_name": "", "description": "Facebook plugin for Gwibber\n Gwibber is a social networking client for GNOME. It supports Facebook,\n Twitter, Identi.ca, StatusNet, FriendFeed, Qaiku, Flickr, and Digg.\n .", "release_date": 1394769600, "vendor_severity": "recommended", "app_id": "922bcb88f6bd75c1e40fcc0c571f603cd59cf7e05b4a192bd5d69c974acc1457", "reboot_required": "no", "os_code": "linux", "repo": "precise-updates/main", "support_url": "", "version": "3.4.2-0ubuntu2.4", "rv_severity": "Recommended", "uninstallable": "yes", "name": "gwibber-service-facebook" } >>> os_string = 'Ubuntu 12.04 ' >>> application_updater(customer_name, app_data, os_string[ ,'unique_applications']) Returns: Tuple (inserted_count, updated_count) """ updated_count = 0 inserted_count = 0 status = app_data.pop(DbCommonAppPerAgentKeys.Status, None) agent_id = app_data.pop(DbCommonAppPerAgentKeys.AgentId, None) app_data.pop(DbCommonAppPerAgentKeys.InstallDate, None) file_data = app_data.pop(DbCommonAppKeys.FileData) app_name = app_data.get(DbCommonAppKeys.Name, None) app_version = app_data.get(DbCommonAppKeys.Version, None) app_kb = app_data.get(DbCommonAppKeys.Kb, '') app_id = app_data.get(DbCommonAppKeys.AppId) exists = object_exist(app_id, collection) if exists: add_file_data(app_id, file_data, agent_id) update_customers_in_app_by_app_id(customer_name, app_id) vuln_data = get_vulnerability_info_for_app( os_string, app_name, app_version, app_kb ) data_updated = update_app_data_by_app_id( app_id, vuln_data, collection ) if data_updated[0] == DbCodes.Replaced: updated_count = data_updated[1] else: add_file_data(app_id, file_data, agent_id) app_data[AppsKey.Customers] = [customer_name] app_data[AppsKey.Hidden] = CommonKeys.NO if (len(file_data) > 0 and status == CommonAppKeys.AVAILABLE or len(file_data) > 0 and status == CommonAppKeys.INSTALLED): app_data[AppsKey.FilesDownloadStatus] = ( PackageCodes.FilePendingDownload ) elif len(file_data) == 0 and status == CommonAppKeys.AVAILABLE: app_data[AppsKey.FilesDownloadStatus] = PackageCodes.MissingUri elif len(file_data) == 0 and status == CommonAppKeys.INSTALLED: app_data[AppsKey.FilesDownloadStatus] = PackageCodes.FileNotRequired vuln_data = get_vulnerability_info_for_app( os_string, app_name, app_version, app_kb ) app_data = dict(app_data.items() + vuln_data.items()) data_inserted = insert_data_in_table(app_data, collection) if data_inserted[0] == DbCodes.Inserted: inserted_count = data_inserted[1] return(inserted_count, updated_count)