Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ jobs:
if: "contains(needs.integration-tests-check.outputs.commit_message, '[run-int-tests]') || github.ref_name == 'develop'"
timeout-minutes: 120
strategy:
fail-fast: false
matrix:
index: [1, 2, 3, 4, 5, 6]
steps:
Expand Down Expand Up @@ -189,6 +190,7 @@ jobs:
if: "contains(needs.integration-tests-check.outputs.commit_message, '[run-int-tests]') || github.ref_name == 'develop'"
timeout-minutes: 120
strategy:
fail-fast: false
matrix:
index: [ 1, 2, 3, 4, 5, 6 ]
steps:
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
- Enabled AOF persistence by default for data durability
- add CounterBasedGauge64 and ZeroBasedCounter64 as metrics types

### Fixes
### Fixed
- fix problem with service rendering when `traps.service.usemetallb` is set to false
- fix reusing the snmp engine for snmpv3 calls

## [1.14.1]
- update mongodb volumePermission image repository to `bitnamileagcy`
Expand Down
16 changes: 8 additions & 8 deletions integration_tests/test_poller_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ def test_enrich_works_for_IFMIB(self, setup_splunk):
logger.info("Integration test for enrichment")
search_string = """| mpreview index=netmetrics | search sourcetype="sc4snmp:metric"
| search "metric_name:sc4snmp.IF-MIB*if"
| search "ifDescr" AND "ifAdminStatus" AND "ifOperStatus" AND "ifPhysAddress" AND "ifIndex" """
| search "ifDescr" AND "ifAdminStatus" AND "ifName" AND "ifAlias" """
result_count, metric_count = splunk_single_search(setup_splunk, search_string)

assert result_count > 0
assert metric_count > 0

# def test_default_profiles_events(self, setup_splunk):
# logger.info("Integration test for sc4snmp:event")
# search_string = """search index=netops | search "IF-MIB.ifAlias" AND "IF-MIB.ifAdminStatus"
# AND "IF-MIB.ifDescr" AND "IF-MIB.ifName" sourcetype="sc4snmp:event" """
# result_count, metric_count = splunk_single_search(setup_splunk, search_string)
# assert result_count > 0
# assert metric_count > 0
def test_default_profiles_events(self, setup_splunk):
logger.info("Integration test for sc4snmp:event")
search_string = """search index=netops | search "IF-MIB.ifAlias" AND "IF-MIB.ifAdminStatus"
AND "IF-MIB.ifDescr" AND "IF-MIB.ifName" sourcetype="sc4snmp:event" """
result_count, metric_count = splunk_single_search(setup_splunk, search_string)
assert result_count > 0
assert metric_count > 0


@pytest.fixture(scope="class")
Expand Down
4 changes: 3 additions & 1 deletion splunk_connect_for_snmp/snmp/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,7 @@ def get_auth(
return get_auth_v1(ir)
elif ir.version == "2c":
return get_auth_v2c(ir)
else:
elif ir.version == "3":
return get_auth_v3(logger, ir, snmp_engine)
else:
raise SnmpActionError(f"Wrong SNMP version {ir.version}")
26 changes: 21 additions & 5 deletions splunk_connect_for_snmp/snmp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ def __init__(self, **kwargs):
self.profiles_collection = ProfileCollection(self.profiles)
self.profiles_collection.process_profiles()
self.last_modified = time.time()
self.snmpEngine = SnmpEngine()
self.snmp_engine = SnmpEngine()
self.already_loaded_mibs = set()
self.builder = self.snmpEngine.getMibBuilder()
self.builder = self.snmp_engine.getMibBuilder()
self.mib_view_controller = view.MibViewController(self.builder)
compiler.addMibCompiler(self.builder, sources=[MIB_SOURCES])

Expand All @@ -315,6 +315,18 @@ def __init__(self, **kwargs):
f"Unable to load mib map from index http error {self.mib_response.status_code}"
)

def get_snmp_engine(self, version="", create_new=False) -> SnmpEngine:
"""
:returns: The new SnmpEngine with mibViewController cache attached if snmp version is 3,
else it reuses already defined snmp poller.
"""
if version == "3" or create_new:
snmp_engine = SnmpEngine()
snmp_engine.cache["mibViewController"] = self.mib_view_controller
return snmp_engine
else:
return self.snmp_engine

def do_work(
self,
ir: InventoryRecord,
Expand All @@ -335,7 +347,7 @@ def do_work(
address, walk=walk, profiles=profiles
)

auth_data = get_auth(logger, ir, self.snmpEngine)
auth_data = get_auth(logger, ir, self.get_snmp_engine(ir.version))
context_data = get_context_data()

transport = setup_transport_target(ir)
Expand Down Expand Up @@ -399,7 +411,11 @@ def run_get_request(
error_index,
varbind_table,
) in getCmd(
self.snmpEngine, auth_data, transport, context_data, *varbind_chunk
self.get_snmp_engine(create_new=True),
auth_data,
transport,
context_data,
*varbind_chunk,
):
if not _any_failure_happened(
error_indication,
Expand Down Expand Up @@ -429,7 +445,7 @@ def run_bulk_request(
error_index,
varbind_table,
) in bulkCmd(
self.snmpEngine,
self.get_snmp_engine(create_new=True),
auth_data,
transport,
context_data,
Expand Down
11 changes: 7 additions & 4 deletions test/snmp/test_do_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestDoWork(TestCase):
def test_do_work_no_work_to_do(self):
poller = Poller.__new__(Poller)
poller.last_modified = 1609675634
poller.snmpEngine = None
poller.snmp_engine = None
poller.profiles_manager = MagicMock()
poller.profiles_collection = MagicMock()
poller.profiles_collection.process_profiles = MagicMock()
Expand All @@ -57,14 +57,15 @@ def test_do_work_no_work_to_do(self):
@patch("mongolock.MongoLock.release", MagicMock())
@patch("splunk_connect_for_snmp.snmp.auth.get_auth", None)
@patch("splunk_connect_for_snmp.snmp.manager.get_context_data", MagicMock())
@patch("splunk_connect_for_snmp.snmp.manager.Poller.get_snmp_engine", MagicMock())
@patch("splunk_connect_for_snmp.snmp.manager.setup_transport_target", MagicMock())
@patch("splunk_connect_for_snmp.snmp.manager.bulkCmd")
@patch("splunk_connect_for_snmp.snmp.manager.getCmd")
@patch("splunk_connect_for_snmp.common.collection_manager.ProfilesManager")
def test_do_work_bulk(self, load_profiles, getCmd, bulkCmd):
poller = Poller.__new__(Poller)
poller.last_modified = 1609675634
poller.snmpEngine = None
poller.snmp_engine = None
poller.builder = MagicMock()
poller.profiles_manager = MagicMock()
m_process_data = MagicMock()
Expand Down Expand Up @@ -93,6 +94,7 @@ def test_do_work_bulk(self, load_profiles, getCmd, bulkCmd):
@patch("mongolock.MongoLock.release", MagicMock())
@patch("splunk_connect_for_snmp.snmp.auth.get_auth", None)
@patch("splunk_connect_for_snmp.snmp.manager.get_context_data", MagicMock())
@patch("splunk_connect_for_snmp.snmp.manager.Poller.get_snmp_engine", MagicMock())
@patch("splunk_connect_for_snmp.snmp.manager.setup_transport_target", MagicMock())
@patch("splunk_connect_for_snmp.snmp.manager.bulkCmd")
@patch("splunk_connect_for_snmp.snmp.manager.getCmd")
Expand All @@ -102,7 +104,7 @@ def test_do_work_bulk(self, load_profiles, getCmd, bulkCmd):
def test_do_work_get(self, load_profiles, getCmd, bulkCmd):
poller = Poller.__new__(Poller)
poller.last_modified = 1609675634
poller.snmpEngine = None
poller.snmp_engine = None
poller.builder = MagicMock()
poller.process_snmp_data = MagicMock()
poller.profiles_manager = MagicMock()
Expand Down Expand Up @@ -136,6 +138,7 @@ def test_do_work_get(self, load_profiles, getCmd, bulkCmd):
@patch("mongolock.MongoLock.release", MagicMock())
@patch("splunk_connect_for_snmp.snmp.auth.get_auth", None)
@patch("splunk_connect_for_snmp.snmp.manager.get_context_data", MagicMock())
@patch("splunk_connect_for_snmp.snmp.manager.Poller.get_snmp_engine", MagicMock())
@patch("splunk_connect_for_snmp.snmp.manager.setup_transport_target", MagicMock())
@patch("splunk_connect_for_snmp.snmp.manager.bulkCmd")
@patch("splunk_connect_for_snmp.snmp.manager.getCmd")
Expand All @@ -145,7 +148,7 @@ def test_do_work_get(self, load_profiles, getCmd, bulkCmd):
def test_do_work_errors(self, load_profiles, getCmd, bulkCmd):
poller = Poller.__new__(Poller)
poller.last_modified = 1609675634
poller.snmpEngine = None
poller.snmp_engine = None
poller.builder = MagicMock()
poller.process_snmp_data = MagicMock()
poller.profiles_manager = MagicMock()
Expand Down
Loading