Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notScannedSince now goes through full report, instead of just the first page #80

Merged
merged 3 commits into from
Feb 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 31 additions & 19 deletions qualysapi/api_actions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from urllib import parse as urlparse

from lxml import objectify

Expand Down Expand Up @@ -187,29 +188,40 @@ def listReports(self, id=0):
def notScannedSince(self, days):
call = "/api/2.0/fo/asset/host/"
parameters = {"action": "list", "details": "All"}
hostData = objectify.fromstring(self.request(call, parameters).encode("utf-8"))
hostArray = []
today = datetime.date.today()
for host in hostData.RESPONSE.HOST_LIST.HOST:
if host.find("LAST_VULN_SCAN_DATETIME"):
last_scan = str(host.LAST_VULN_SCAN_DATETIME).split("T")[0]
last_scan = datetime.date(
int(last_scan.split("-")[0]),
int(last_scan.split("-")[1]),
int(last_scan.split("-")[2]),
)
if (today - last_scan).days >= days:
hostArray.append(
Host(
host.find("DNS"),
host.find("ID"),
host.find("IP"),
host.find("LAST_VULN_SCAN_DATETIME"),
host.find("NETBIOS"),
host.find("OS"),
host.find("TRACKING_METHOD"),
hasNextPage = True
while hasNextPage:
hostData = objectify.fromstring(self.request(call, parameters).encode("utf-8"))
for host in hostData.RESPONSE.HOST_LIST.HOST:
if host.find("LAST_VULN_SCAN_DATETIME"):
last_scan = str(host.LAST_VULN_SCAN_DATETIME).split("T")[0]
last_scan = datetime.date(
int(last_scan.split("-")[0]),
int(last_scan.split("-")[1]),
int(last_scan.split("-")[2]),
)
if (today - last_scan).days >= days:
hostArray.append(
Host(
host.find("DNS"),
host.find("ID"),
host.find("IP"),
host.find("LAST_VULN_SCAN_DATETIME"),
host.find("NETBIOS"),
host.find("OS"),
host.find("TRACKING_METHOD"),
)
)
try:
id_min = dict(
urlparse.parse_qsl(
urlparse.urlparse(str(hostData.RESPONSE.WARNING.URL)).query
)
)["id_min"]
parameters["id_min"] = id_min
except:
hasNextPage = False

return hostArray

Expand Down