|
1 | 1 | from faraday.server.models import db, Host |
2 | 2 | from faraday.server.config import faraday_server |
| 3 | +from faraday.server.tasks import calc_vulnerability_stats |
| 4 | +from tqdm import tqdm |
| 5 | +from colorama import Fore |
3 | 6 |
|
4 | 7 |
|
5 | | -def _sync_hosts_stats(): |
6 | | - print("Syncing hosts stats ...") |
| 8 | +def _sync_hosts_stats(async_mode=False): |
| 9 | + print(f"[{Fore.GREEN}*{Fore.RESET}] Syncing hosts stats ...") |
7 | 10 | hosts_id = db.session.query(Host.id).all() |
8 | 11 | if hosts_id: |
9 | | - print(f"Found {len(hosts_id)} hosts ...") |
10 | | - print("This may take a while ...") |
| 12 | + print(f"[{Fore.GREEN}*{Fore.RESET}] Found {len(hosts_id)} hosts ...") |
| 13 | + print(f"[{Fore.YELLOW}!{Fore.RESET}] This may take a while ...") |
11 | 14 | from faraday.server.tasks import update_host_stats # pylint: disable=import-outside-toplevel |
12 | 15 | _hosts_id = [host_id[0] for host_id in hosts_id] |
13 | | - if faraday_server.celery_enabled: |
14 | | - print("Processing updates in background ...") |
15 | | - update_host_stats.delay(_hosts_id, []) |
| 16 | + if async_mode: |
| 17 | + print(f"[{Fore.GREEN}*{Fore.RESET}] Updating asynchronously") |
| 18 | + if faraday_server.celery_enabled: |
| 19 | + print(f"[{Fore.GREEN}*{Fore.RESET}] Processing updates in background ...") |
| 20 | + update_host_stats.delay(_hosts_id, []) |
| 21 | + else: |
| 22 | + update_host_stats(_hosts_id, []) |
16 | 23 | else: |
17 | | - update_host_stats(_hosts_id, []) |
| 24 | + print(F"[{Fore.GREEN}*{Fore.RESET}] Updating synchronously") |
| 25 | + for host_id in tqdm(_hosts_id, colour="blue"): |
| 26 | + calc_vulnerability_stats(host_id) |
0 commit comments