Skip to content

Commit 2b0aea1

Browse files
committed
Add: option to use nasl-cli instead of openvas for feed update
Adds a new option `--feed-updater` to switch between `openvas -u` and `nasl-cli feed update`. With this ospd-openvas can use the newly created `nasl-cli` to improve the speed of importing nasl feed.
1 parent 88cabad commit 2b0aea1

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

ospd/parser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ def __init__(self, description: str) -> None:
219219
'Default %(default)s'
220220
),
221221
)
222+
parser.add_argument(
223+
'--feed-updater',
224+
default="openvas",
225+
choices=['openvas', 'nasl-cli'],
226+
help=(
227+
'Sets the method of updating the feed.'
228+
' Can either be openvas or nasl-cli.'
229+
' Default: %(default)s.'
230+
),
231+
)
222232

223233
self.parser = parser
224234

ospd_openvas/daemon.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
from ospd_openvas.db import MainDB, BaseDB
5151
from ospd_openvas.lock import LockFile
5252
from ospd_openvas.preferencehandler import PreferenceHandler
53-
from ospd_openvas.openvas import Openvas
53+
from ospd_openvas.openvas import NASLCli, Openvas
5454
from ospd_openvas.vthelper import VtHelper
5555
from ospd_openvas.messaging.mqtt import MQTTClient, MQTTDaemon, MQTTSubscriber
5656
from ospd_openvas.feed import Feed
@@ -472,6 +472,7 @@ def __init__(
472472
lock_file_dir='/var/lib/openvas',
473473
mqtt_broker_address="localhost",
474474
mqtt_broker_port=1883,
475+
feed_updater="openvas",
475476
disable_notus_hashsum_verification=False,
476477
**kwargs,
477478
):
@@ -488,6 +489,7 @@ def __init__(
488489
disable_notus_hashsum_verification,
489490
)
490491

492+
self.feed_updater = feed_updater
491493
self.nvti = NVTICache(self.main_db)
492494

493495
super().__init__(
@@ -670,8 +672,13 @@ def update_vts(self):
670672
# reload notus cache
671673
if self.notus:
672674
self.notus.reload_cache()
675+
loaded = False
676+
if self.feed_updater == "nasl-cli":
677+
loaded = NASLCli.load_vts_into_redis()
678+
else:
679+
loaded = Openvas.load_vts_into_redis()
673680

674-
if Openvas.load_vts_into_redis():
681+
if loaded:
675682
new = self.nvti.get_feed_version()
676683
if new != old:
677684
logger.info(

ospd_openvas/openvas.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@
2828
_BOOL_DICT = {'no': 0, 'yes': 1}
2929

3030

31+
class NASLCli:
32+
"""Class for calling nasl-cli executable"""
33+
34+
@staticmethod
35+
def load_vts_into_redis() -> bool:
36+
"""Loads all VTs into the redis database"""
37+
try:
38+
subprocess.check_call(
39+
['nasl-cli', 'feed', 'update'], stdout=subprocess.DEVNULL
40+
)
41+
return True
42+
except (subprocess.SubprocessError, OSError) as err:
43+
logger.error('nasl-cli failed to load VTs. %s', err)
44+
return False
45+
46+
3147
class Openvas:
3248
"""Class for calling the openvas executable"""
3349

0 commit comments

Comments
 (0)