Skip to content

Commit

Permalink
Merge pull request #7 from cloudlinux/feature/ip-only-id
Browse files Browse the repository at this point in the history
The hostname now does not affect to id
  • Loading branch information
histrio authored Sep 10, 2019
2 parents 29d53f6 + f300b7e commit 053cdb5
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/kcare_qualys.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ def fetch(args, qgc, keys):
logger.info("{0} was saved".format(report_filename))


def cache_latest(clbl):
_CACHE = {}
@functools.wraps(clbl)
def wrapper(kernel):
if kernel not in _CACHE:
_CACHE[kernel] = clbl(kernel)
return _CACHE[kernel]
return wrapper


@cache_latest
def get_latest(kernel):
patch_path = "/{0}/latest.v2".format(kernel)
resp = requests.get(PATCHES_INFO_URL + patch_path)
Expand Down Expand Up @@ -230,14 +241,9 @@ def summary(args, qgc, keys):
cve_set = get_cve(asset) or frozenset()
rec = [asset.host, asset.ip, ', '.join(cve_set)]

ip = dns_name = None

if asset.ip in report_assets:
ip, dns_name = report_assets[asset.ip]
if asset.host in report_assets:
ip, dns_name = report_assets[asset.host]
ids = report_assets.get(asset.ip, ()) + report_assets.get(asset.host, ())
was_in_report = [report_assets.pop(id_, None) for id_ in ids]

was_in_report = [report_assets.pop(ip, None), report_assets.pop(dns_name, None)]
if any(was_in_report):
latest = get_latest(asset.kernel_id)
if latest > asset.patch_level:
Expand All @@ -252,7 +258,7 @@ def summary(args, qgc, keys):
rec.append('patched')
writer.writerow(rec)

for host, ip in set(report_assets.values()):
for ip, host in set(report_assets.values()):
rec = [host, ip, '', 'not patched', "Not registered"]
writer.writerow(rec)

Expand Down

0 comments on commit 053cdb5

Please sign in to comment.