Commit 8a7bc268 authored by Alberts S's avatar Alberts S
Browse files

Add ability to Inventory to filter hosts

parent 5e082627
......@@ -11,8 +11,18 @@ class Inventory(CapybaraNetty):
super().__init__()
self.chef_api = chef.autoconfigure()
self.chef_api.ssl_verify = False
self.inventory_match_hosts = self.config.get("inventory_match_hosts", None)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def is_matched_host(self, hostname: str):
if not self.inventory_match_hosts:
return False
else:
for node_filter in self.inventory_match_hosts:
if hostname.startswith(node_filter):
return True
return False
async def get_hosts(self):
hosts = []
for node_name in self.chef_api["/nodes"]:
......@@ -21,6 +31,11 @@ class Inventory(CapybaraNetty):
nodeTime = datetime.utcfromtimestamp(chefNode.attributes["ohai_time"])
ipv4 = chefNode.attributes["base"]["public_ipv4"].strip()
hostname = chefNode.attributes["base"]["hostname"]
if not self.is_matched_host(hostname):
self.__logger.warning(f"host {hostname} is FILTERED out")
continue
# If Node time is less than 1 hour old - its active
if (nodeTime + timedelta(hours=1)) > datetime.utcnow():
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment