diff --git a/CHANGELOG.md b/CHANGELOG.md index e9cc6969..989580be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Check if the amount of vts in redis is coherent. [#195](https://github.com/greenbone/ospd-openvas/pull/195) [#197](https://github.com/greenbone/ospd-openvas/pull/197) +- Add support for test_alive_hosts_only feature of openvas. [#204](https://github.com/greenbone/ospd-openvas/pull/204) ### Changed - Less strict checks for the nvti cache version diff --git a/ospd_openvas/daemon.py b/ospd_openvas/daemon.py index db63f13b..4cee3f0f 100644 --- a/ospd_openvas/daemon.py +++ b/ospd_openvas/daemon.py @@ -1569,6 +1569,34 @@ def exec_scan(self, scan_id: str): # Set alive test option. Overwrite the scan config settings. target_options = self.get_scan_target_options(scan_id) if target_options: + # Check if test_alive_hosts_only feature of openvas is active. + # If active, put ALIVE_TEST enum in preferences. + settings = Openvas.get_settings() + if settings: + test_alive_hosts_only = settings.get( + 'test_alive_hosts_only' + ) + if test_alive_hosts_only: + if target_options and target_options.get('alive_test'): + try: + alive_test = int( + target_options.get('alive_test') + ) + except ValueError: + logger.debug( + 'Alive test settings not applied. ' + 'Invalid alive test value %s', + target_options.get('alive_test'), + ) + # Put ALIVE_TEST enum in db, this is then taken + # by openvas to determine the method to use + # for the alive test. + if alive_test >= 1 and alive_test <= 31: + item = 'ALIVE_TEST|||%s' % str(alive_test) + kbdb.add_scan_preferences( + openvas_scan_id, [item] + ) + alive_test_opt = self.build_alive_test_opt_as_prefs( target_options )