Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
fix: removal of dynamic profiles fix
Browse files Browse the repository at this point in the history
  • Loading branch information
weliasz committed Nov 2, 2021
1 parent 7b37044 commit 14b85c4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions splunk_connect_for_snmp_poller/manager/poller.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(self, args, server_config):
self._inventory_mod_time = 0
self._config_mod_time = 0
self._jobs_map = {}
self._dynamic_jobs = set()
self._mongo = WalkedHostsRepository(self._server_config["mongo"])
self._local_snmp_engine = SnmpEngine()
self._unmatched_devices = {}
Expand Down Expand Up @@ -127,7 +128,7 @@ def __check_inventory(self):
inventory_hosts.add(ir_host)
inventory_hosts_with_snmp_data[ir_host] = copy.deepcopy(ir)
if ir.profile == DYNAMIC_PROFILE:
self.delete_all_entries_per_host(ir.host)
self.delete_all_dynamic_entries_per_host(ir.host)
self.add_device_for_profile_matching(ir)
self.check_if_new_host_was_added(entry_key, ir, new_enricher)
else:
Expand Down Expand Up @@ -181,12 +182,13 @@ def __add_enricher_to_a_host(self, current_enricher, ir, new_host=False):
self.__get_splunk_indexes(),
)

def delete_all_entries_per_host(self, host):
def delete_all_dynamic_entries_per_host(self, host):
for entry_key in list(self._jobs_map.keys()):
if entry_key.split("#")[0] == host:
if entry_key.split("#")[0] == host and entry_key in self._dynamic_jobs:
logger.debug("Removing job for %s", entry_key)
schedule.cancel_job(self._jobs_map.get(entry_key))
del self._jobs_map[entry_key]
self._dynamic_jobs.remove(entry_key)

def clean_job_inventory(self, inventory_entry_keys: set, inventory_hosts: set):
for entry_key in list(self._jobs_map):
Expand Down Expand Up @@ -340,6 +342,7 @@ def process_unmatched_devices(self, config_location):
frequency,
)
self.process_new_job(entry_key, new_record, profiles)
self._dynamic_jobs.add(entry_key)
for d in processed_devices:
self._unmatched_devices.pop(d)
except Exception as e:
Expand Down

0 comments on commit 14b85c4

Please sign in to comment.