def get_plugin_sids_package(system_id, md5): """ Check the :system_id: system if its alienvault-plugin-sids package has md5 sum of :md5:. Download the package from remote system. check if not reconfig / update is running. Install package """ # First, check remote md5 rt = False emsg = '' try: result, info = get_plugin_package_info_from_system_id(system_id) if not result: raise Exception("Can't obtain alienvault-plugin-sid info for system %s : %s" % (system_id, str(info))) if info['md5'] != md5: raise Exception("md5 provided doesn't match with stored md5") # Use ansible to download file to temp directory result, ipremote = get_system_ip_from_system_id(system_id) if not result: raise Exception("Can't obtain remote system ip") result, iplocal = get_system_ip_from_local() if not result: raise Exception("Can't obtain local system ip") result, idlocal = get_system_id_from_local() if not result: raise Exception("Can't obtain local system id") # Create a temp file temp = NamedTemporaryFile(delete=True) tempname = temp.name plugin_package = "alienvault-plugin-sids_" + info['version'] + "_all.deb" remote_path = "/var/cache/apt/archives" result, emsg = fetch_if_changed(ipremote, os.path.join(remote_path, plugin_package), iplocal, tempname) if not result: raise Exception("Can't copy remote from %s file name %s Error: %s" % (ipremote, os.path.join(remote_path, plugin_package), emsg)) shutil.copy(tempname, remote_path) # Atomic rename os.rename(os.path.join(remote_path, os.path.basename(tempname)), os.path.join(remote_path, plugin_package)) # Check if we're not updaing / configuring result, status = check_update_and_reconfig_status(idlocal) if not result: raise Exception("Can't check current status reconfig / update") if status['alienvault-update']['job_status'] == 'running': raise Exception("alienvault-update running") if status['alienvault-reconfig']['job_status'] == 'running': raise Exception("alienvault-reconfig running") if status['ossim-reconfig']['job_status'] == 'running': raise Exception("ossim-reconfig running") # Okey, install package result, status = install_debian_package([iplocal], os.path.join(remote_path, plugin_package)) if not result: raise Exception("Can't install %s" % os.path.join(remote_path, plugin_package)) rt = True emsg = '' except Exception as excep: emsg = str(excep) rt = False return (rt, emsg)
def get_tasks(system_id): """ Blueprint to get the status of system tasks Args: system_id (UUID): system to update Returns: data: JSON with status and job ID or error message success example: { "data": { tasks:{ "alienvault-update" : {"job_id": "XXXXXXXXX", "job_status": "<job_status>"}, "alienvault-reconfig" : {"job_id": "XXXXXXXXX", "job_status": "<job_status>"} } }, "status": "success" } error example: { "message": "Cannot retrieve tasks for system 564D9762-9196-99CD-46E6-3D941F32AA6. Please verify that the system is reachable.", "status": "error", "status_code": 500, "status_long_message": "Server got itself in trouble", "status_short_message": "Internal Server Error" } """ success, tasks = check_update_and_reconfig_status(system_id) if not success: error_msg = "Cannot retrieve task status for system %s. " % system_id error_msg = error_msg + "Please verify that the system is reachable." return make_error(error_msg, 500) return make_ok(tasks=tasks)
def get_tasks(system_id): """ Blueprint to get the status of system tasks Args: system_id (UUID): system to update Returns: data: JSON with status and job ID or error message success example: { "data": { tasks:{ "alienvault-update" : {"job_id": "XXXXXXXXX", "job_status": "<job_status>"}, "alienvault-reconfig" : {"job_id": "XXXXXXXXX", "job_status": "<job_status>"} } }, "status": "success" } error example: { "message": "Cannot retrieve tasks for system 564D9762-9196-99CD-46E6-3D941F32AA6. Please verify that the system is reachable.", "status": "error", "status_code": 500, "status_long_message": "Server got itself in trouble", "status_short_message": "Internal Server Error" } """ success, tasks = check_update_and_reconfig_status(system_id) if not success: error_msg = "Cannot retrieve task status for system %s. Please verify that the system is reachable." % system_id return make_error(error_msg, 500) return make_ok(tasks=tasks)