def _validate_config_or_die(self): if not os.path.exists(self.exe_path): raise ConfigException('Invalid or missing EXE_PATH: %s' % self.exe_path) if not os.path.isdir(self.dat_directory): raise ConfigException('Invalid or missing DAT_DIRECTORY: %s' % self.dat_directory) if not os.path.isdir(self.working_directory): raise ConfigException('Working directory does not exist %s' % self.working_directory)
def start(self): # Validate configuration and tool locations. self.sigcheck_exe = self.cfg.get('SIGCHECK_PATH', '') if not os.path.isfile(self.sigcheck_exe): raise ConfigException('SIGCHECK_PATH (%s) is invalid or missing.' % self.sigcheck_exe) self.signtool_exe = self.cfg.get('SIGNTOOL_PATH', '') if not os.path.isfile(self.signtool_exe): raise ConfigException('SIGNTOOL_PATH (%s) is invalid or missing.' % self.signtool_exe)
def _update_rules(self, **_): self.log.info("Starting Yara's rule updater...") if not self.update_client: self.update_client = Client(self.signature_url, auth=(self.signature_user, self.signature_pass)) if self.signature_cache.exists(self.rule_path): api_response = self.update_client.signature.update_available(self.last_update) update_available = api_response.get('update_available', False) if not update_available: self.log.info("No update available. Stopping...") return self.log.info("Downloading signatures with query: %s (%s)" % (self.signature_query, str(self.last_update))) signature_data = StringIO() self.update_client.signature.download(output=signature_data, query=self.signature_query, safe=True) rules_txt = signature_data.getvalue() if not rules_txt: errormsg = "No rules to compile:\n%s" % rules_txt self.log.error("{}/api/v3/signature/download/?query={} - {}:{}".format( self.signature_url, self.signature_query, self.signature_user, self.signature_pass) ) self.log.error(errormsg) raise ConfigException(errormsg) self.signature_cache.save(self.rule_path, rules_txt) last_update, rules, rules_md5 = self._compile_rules(rules_txt) if rules: with self.initialization_lock: self.last_update = last_update self.rules = rules self.rules_md5 = rules_md5
def get_vmcfg_for_localhost(): ip = net.get_hostip() mac = net.get_mac_for_ip(ip) store = forge.get_datastore() host_registration = store.get_node(mac) if not host_registration: raise ConfigException('Could not find host registration fr %s' % mac) profile_name = host_registration.get('profile', None) if not profile_name: raise ConfigException('Could not find profile for host: %s' % mac) host_profile = store.get_profile(profile_name) if not host_profile: raise ConfigException('Could not fetch host profile %s' % profile_name) vm_config = host_profile.get('virtual_machines', None) if not vm_config: raise ConfigException('Could not find virtual machine section in %s' % profile_name) store.client.close() return vm_config
def _install_missing(self, missing): for name in missing: self.log.info('Installing VM: %s', name) vprof = self.vm_profiles[name] cpu = vprof['vcpus'] ram = vprof['ram'] os_type = vprof['os_type'] variant = vprof['os_variant'] disk = os.path.join(self.disk_root, vprof.get('virtual_disk_url', "").rpartition('/')[-1]) if not os.path.isfile(disk): raise ConfigException('Missing disk for this vm (%s). Run vm_disk --sync.' % disk) mac = get_mac_for_serviceinstance(name) # noinspection PyBroadException try: self.virt_install(os_type, variant, name, cpu, ram, disk, mac) reg_mac = mac.replace(':', '').upper() self.pre_registration(name, reg_mac, vprof['name'], vprof['num_workers']) except: self.log.exception("While installing VM: %s", name)
def validate_config_or_raise(self): if not os.path.isfile(self.exe_path): raise ConfigException('BitDefender not found at %s', self.exe_path)
def _validate_config_or_die(self): if not os.path.isfile(self.exe_path): raise ConfigException('Missing or invalid EXE_PATH: %s' % self.exe_path)