in elkserver/docker/redelk-base/redelkinstalldata/scripts/modules/enrich_domainscategorization/cat_ibmxforce.py [0:0]
def check_domain(self, domain):
"""Check the domain categoriation in IBM X-Force Exchange"""
result = {
"domain": domain,
"categories": [],
"status": "unknown",
"response_code": -1,
"extra_data": {},
}
self.logger.debug("Checking domain %s", domain)
session = requests.session()
url = f"https://api.xforce.ibmcloud.com/api/url/{domain}"
headers = {
"Accept": "application/json",
"Authorization": self.ibm_basic_auth,
}
response = session.get(url, headers=headers, verify=False)
self.logger.debug("Response: %s", response.content)
result["response_code"] = response.status_code
# Domain was not found in IBM X-Force Exchange
if response.status_code == 404:
self.logger.debug(
"IBM x-Force does not have entries for the domain %s!", domain
)
result["status"] = "not_found"
# Domain was found in IBM X-Force Exchange
elif response.status_code == 200:
try:
json_data = response.json()
self.logger.debug("Json Response: %s", json_data)
result["status"] = "found"
for category in get_value("result.cats", json_data, {}):
result["categories"].append(category)
except Exception: # pylint: disable=broad-except
self.logger.error(
"Error checking domain %s: %s", domain, traceback.print_exc()
)
self.logger.error(traceback.format_exc())
result["status"] = "error"
return result