Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add: count alive and dead hosts found during the scan and return the results All information in the Results struct allows to calculate the scan progress. For testing with a running Redis server, check that the nvticache is already loaded (use the old openvas -u or nasl-cli feed update). Add example items for results and status ``` $ redis-cli -s /var/run/redis-openvas/redis.sock redis /var/run/redis-openvas/redis.sock> info keyspace db0:keys=1,expires=0,avg_ttl=0 db1:keys=57685,expires=0,avg_ttl=0 db2:keys=429536,expires=0,avg_ttl=0 redis /var/run/redis-openvas/redis.sock> SELECT 3 OK redis /var/run/redis-openvas/redis.sock[3]> LPUSH internal/results "LOG|||127.0.0.1||| localhost ||||||||| HOST_START" "ERRMSG|||127.0.0.1||| localhost ||||||1.2.3.4.5.6||| NVT timeout" "ALARM|||127.0.0.1||| example.com |||22/tcp|||12.11.10.9.8.7||| Something wrong|||/var/lib/lib1.jar" "DEADHOST||| ||| ||| ||| |||3" "HOST_COUNT||| ||| ||| ||| |||12" "DEADHOST||| ||| ||| ||| |||1" "HOSTS_EXCLUDED||| ||| ||| ||| |||4" (integer) 7 redis /var/run/redis-openvas/redis.sock[3]> LPUSH internal/status 127.0.0.1/0/1000 127.0.0.2/15/1000 127.0.0.3/750/1000 127.0.0.2/0/-1 127.0.0.4/500/1000 127.0.0.1/128/1000 127.0.0.4/1000/1000 127.0.0.5/0/-1 (integer) 8 redis /var/run/redis-openvas/redis.sock[3]> info keyspace db0:keys=1,expires=0,avg_ttl=0 db1:keys=57685,expires=0,avg_ttl=0 db2:keys=429536,expires=0,avg_ttl=0 db3:keys=2,expires=0,avg_ttl=0 ``` And run the following test, which initialize a RedisHelper struct with both dbs, cache(2) and main kb (3), and get results and scan status ``` use std::sync::{Arc, Mutex}; use openvas::{ openvas_redis::RedisHelper, result_collector::ResultHelper, }; use redis_storage::{NameSpaceSelector, RedisCtx}; async fn main() -> Result<(), std::fmt::Error> { let redis_url = "unix:///run/redis-openvas/redis.sock"; let rctx = RedisCtx::open(redis_url, &[NameSpaceSelector::Fix(3)]).unwrap(); let cache = RedisCtx::open(redis_url, &[NameSpaceSelector::Key("nvticache")]).unwrap(); let rc = RedisHelper::<RedisCtx>::new(Arc::new(Mutex::new(cache)), Arc::new(Mutex::new(rctx))); let mut p = ResultHelper::init(rc); p.get_results().await.unwrap(); p.get_status().await.unwrap(); if let Ok(r) = Arc::as_ref(&p.results).lock() { println!("{:?}", r); } Ok(()) } ``` * Doc: document progress calculation
- Loading branch information