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

Commit

Permalink
fix: implement new way for enricher to work
Browse files Browse the repository at this point in the history
  • Loading branch information
omrozowicz-splunk committed Oct 19, 2021
1 parent 7c4e432 commit 8e24841
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
30 changes: 29 additions & 1 deletion splunk_connect_for_snmp_poller/manager/poller.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
extract_desc,
get_profiles,
)
from splunk_connect_for_snmp_poller.manager.realtime.oid_constant import OidConstant
from splunk_connect_for_snmp_poller.manager.static.interface_mib_utililities import (
extract_network_interface_data_from_additional_config,
)
from splunk_connect_for_snmp_poller.manager.tasks import snmp_polling
from splunk_connect_for_snmp_poller.manager.validator.inventory_validator import (
DYNAMIC_PROFILE,
Expand Down Expand Up @@ -60,6 +64,7 @@ def __init__(self, args, server_config):
self._unmatched_devices = {}
self._lock = threading.Lock()
self._force_refresh = False
self._old_enricher = {}

def force_inventory_refresh(self):
self._force_refresh = True
Expand Down Expand Up @@ -89,7 +94,30 @@ def __check_inventory(self):
)
if server_config_modified:
self._server_config = parse_config_file(self._args.config)

new_enricher = self._server_config.get("enricher", {})
if new_enricher != self._old_enricher:
profiles = get_profiles(self._server_config)
for ir in parse_inventory_file(self._args.inventory, profiles):
snmp_polling(
ir.to_json(),
self._server_config,
self.__get_splunk_indexes(),
OidConstant.IF_MIB,
)
additional_enricher_varbinds = (
extract_network_interface_data_from_additional_config(
new_enricher
)
)
additional_structure = self._mongo_walked_hosts_coll.create_mib_static_data_mongo_structure(
None, additional_enricher_varbinds
)
if additional_structure:
host_id = return_database_id(ir.host)
self._mongo_walked_hosts_coll.update_static_data_for_one(
host_id, additional_structure
)
self._old_enricher = new_enricher
inventory_config_modified, self._inventory_mod_time = file_was_modified(
self._args.inventory, self._inventory_mod_time
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ class OidConstant:
SYS_UP_TIME_INSTANCE = "1.3.6.1.2.1.1.3.0"
# see https://www.alvestrand.no/objectid/1.3.6.1.html for a better understanding
UNIVERSAL_BASE_OID = "1.3.6.1.*"
IF_MIB = "1.3.6.1.2.1.2.*"
6 changes: 1 addition & 5 deletions splunk_connect_for_snmp_poller/manager/task_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
from splunk_connect_for_snmp_poller.manager.realtime.interface_mib import InterfaceMib
from splunk_connect_for_snmp_poller.manager.realtime.oid_constant import OidConstant
from splunk_connect_for_snmp_poller.manager.static.interface_mib_utililities import (
extract_network_interface_data_from_additional_config,
extract_network_interface_data_from_walk,
)
from splunk_connect_for_snmp_poller.manager.static.mib_enricher import MibEnricher
Expand Down Expand Up @@ -587,11 +586,8 @@ async def walk_handler_with_enricher(

logger.info(f"Walk finished for {host} profile={ir.profile}")
processed_result = extract_network_interface_data_from_walk(enricher, merged_result)
additional_enricher_varbinds = (
extract_network_interface_data_from_additional_config(enricher)
)
mongo_connection.update_mib_static_data_for(
f"{host}:{port}", processed_result, additional_enricher_varbinds
f"{host}:{port}", processed_result, None
)


Expand Down
9 changes: 9 additions & 0 deletions splunk_connect_for_snmp_poller/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,12 @@ def update_mib_static_data_for(self, host, existing_data, additional_data):
return_document=ReturnDocument.AFTER,
)
return static_data_dictionary[WalkedHostsRepository.MIB_STATIC_DATA]

def update_static_data_for_one(self, host, static_data_dictionary):
logger.info(f"Updating static data for {host} with {static_data_dictionary}")
self._walked_hosts.find_one_and_update(
{"_id": host},
{"$set": static_data_dictionary},
upsert=True,
return_document=ReturnDocument.AFTER,
)

0 comments on commit 8e24841

Please sign in to comment.