-
Notifications
You must be signed in to change notification settings - Fork 940
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'white/staging' into white/master
- Loading branch information
Showing
4 changed files
with
25 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
from faraday.server.models import db, Host | ||
from faraday.server.config import faraday_server | ||
from faraday.server.tasks import calc_vulnerability_stats | ||
from tqdm import tqdm | ||
from colorama import Fore | ||
|
||
|
||
def _sync_hosts_stats(): | ||
print("Syncing hosts stats ...") | ||
def _sync_hosts_stats(async_mode=False): | ||
print(f"[{Fore.GREEN}*{Fore.RESET}] Syncing hosts stats ...") | ||
hosts_id = db.session.query(Host.id).all() | ||
if hosts_id: | ||
print(f"Found {len(hosts_id)} hosts ...") | ||
print("This may take a while ...") | ||
print(f"[{Fore.GREEN}*{Fore.RESET}] Found {len(hosts_id)} hosts ...") | ||
print(f"[{Fore.YELLOW}!{Fore.RESET}] This may take a while ...") | ||
from faraday.server.tasks import update_host_stats # pylint: disable=import-outside-toplevel | ||
_hosts_id = [host_id[0] for host_id in hosts_id] | ||
if faraday_server.celery_enabled: | ||
print("Processing updates in background ...") | ||
update_host_stats.delay(_hosts_id, []) | ||
if async_mode: | ||
print(f"[{Fore.GREEN}*{Fore.RESET}] Updating asynchronously") | ||
if faraday_server.celery_enabled: | ||
print(f"[{Fore.GREEN}*{Fore.RESET}] Processing updates in background ...") | ||
update_host_stats.delay(_hosts_id, []) | ||
else: | ||
update_host_stats(_hosts_id, []) | ||
else: | ||
update_host_stats(_hosts_id, []) | ||
print(F"[{Fore.GREEN}*{Fore.RESET}] Updating synchronously") | ||
for host_id in tqdm(_hosts_id, colour="blue"): | ||
calc_vulnerability_stats(host_id) |