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

Commit

Permalink
style: apply pre-commit black
Browse files Browse the repository at this point in the history
  • Loading branch information
artemrys authored and Artem Rys committed Aug 24, 2021
1 parent 9a24536 commit c53b8b6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
1 change: 0 additions & 1 deletion splunk_connect_for_snmp_poller/manager/poller.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,3 @@ def scheduled_task(host, version, community, profile, server_config, splunk_inde
)

snmp_polling.delay(host, version, community, profile, server_config, splunk_indexes)

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def extract_current_index_from_metric(current_translated_oid):
try:
if current_translated_oid:
return (
int(current_translated_oid[current_translated_oid.rindex("_") + 1:])
int(current_translated_oid[current_translated_oid.rindex("_") + 1 :])
- 1
)
except ValueError:
Expand Down
8 changes: 2 additions & 6 deletions splunk_connect_for_snmp_poller/manager/task_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ def get_translated_string(mib_server_url, varBinds, return_multimetric=False):
logger.debug(
f"==========result before translated -- is_metric={is_metric}============\n{result}"
)
result = get_translation(
varBinds, mib_server_url, data_format
)
result = get_translation(varBinds, mib_server_url, data_format)
if data_format == "MULTIMETRIC":
result = json.loads(result)["metric"]
logger.info(f"=========result=======\n{result}")
Expand All @@ -134,9 +132,7 @@ def get_translated_string(mib_server_url, varBinds, return_multimetric=False):
if not is_metric_data(_value):
is_metric = False
data_format = _get_data_format(is_metric, return_multimetric)
result = get_translation(
varBinds, mib_server_url, data_format
)
result = get_translation(varBinds, mib_server_url, data_format)
except Exception as e:
logger.info(f"Could not perform translation. Exception: {e}")
logger.info(
Expand Down
18 changes: 14 additions & 4 deletions splunk_connect_for_snmp_poller/manager/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,36 @@ def snmp_polling(
logger.info(f"Varbind collection: {varbind_collection}")
# Perform SNMP BULK
get_snmp_data(
varbind_collection.bulk, snmp_bulk_handler, *get_bulk_specific_parameters, *static_parameters
varbind_collection.bulk,
snmp_bulk_handler,
*get_bulk_specific_parameters,
*static_parameters,
)
# Perform SNMP WALK
get_snmp_data(
varbind_collection.get, snmp_get_handler, *get_bulk_specific_parameters, *static_parameters
varbind_collection.get,
snmp_get_handler,
*get_bulk_specific_parameters,
*static_parameters,
)
# Perform SNNP Polling for oid profile in inventory.csv
else:
# Perform SNNP WALK for oid end with *
if profile[-1] == "*":
logger.info(f"Executing SNMP WALK for {host} profile={profile}")
if enricher_presence:
walk_handler_with_enricher(profile, server_config, mongo_connection, *static_parameters)
walk_handler_with_enricher(
profile, server_config, mongo_connection, *static_parameters
)
else:
walk_handler(profile, *static_parameters)
# Perform SNNP GET for an oid
else:
logger.info(f"Executing SNMP GET for {host} profile={profile}")
prepared_profile = [ObjectType(ObjectIdentity(profile))]
snmp_get_handler(*get_bulk_specific_parameters, *static_parameters, prepared_profile)
snmp_get_handler(
*get_bulk_specific_parameters, *static_parameters, prepared_profile
)

return f"Executing SNMP Polling for {host} version={version} profile={profile}"
except Exception as e:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_hec_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ def test__enrich_metric_data_index_3(self):
def test__enrich_event_data_index_1(self):
variables_binds = {
"metric": '{"metric_name": "sc4snmp.IF-MIB.ifDescr_1", "_value": "lo", '
'"metric_type": "OctetString"}',
'"metric_type": "OctetString"}',
"metric_name": "sc4snmp.IF-MIB.ifDescr_1",
"non_metric": 'oid-type1="ObjectIdentity" value1-type="OctetString" '
'1.3.6.1.2.1.2.2.1.2.1="lo" value1="lo" IF-MIB::ifDescr.1="lo" ',
'1.3.6.1.2.1.2.2.1.2.1="lo" value1="lo" IF-MIB::ifDescr.1="lo" ',
}
variables_binds_result = (
'oid-type1="ObjectIdentity" value1-type="OctetString" 1.3.6.1.2.1.2.2.1.2.1="lo" '
Expand All @@ -128,10 +128,10 @@ def test__enrich_event_data_index_1(self):
def test__enrich_event_data_index_2(self):
variables_binds = {
"metric": '{"metric_name": "sc4snmp.IF-MIB.ifDescr_2", "_value": "eth0", '
'"metric_type": "OctetString"}',
'"metric_type": "OctetString"}',
"metric_name": "sc4snmp.IF-MIB.ifDescr_2",
"non_metric": 'oid-type1="ObjectIdentity" value1-type="OctetString" '
'1.3.6.1.2.1.2.2.1.2.1="lo" value1="eth0" IF-MIB::ifDescr.2="eth0" ',
'1.3.6.1.2.1.2.2.1.2.1="lo" value1="eth0" IF-MIB::ifDescr.2="eth0" ',
}
variables_binds_result = (
'oid-type1="ObjectIdentity" value1-type="OctetString" 1.3.6.1.2.1.2.2.1.2.1="lo" '
Expand All @@ -143,10 +143,10 @@ def test__enrich_event_data_index_2(self):
def test__enrich_event_data_index_3(self):
variables_binds = {
"metric": '{"metric_name": "sc4snmp.IF-MIB.ifDescr_3", "_value": "eth1", '
'"metric_type": "OctetString"}',
'"metric_type": "OctetString"}',
"metric_name": "sc4snmp.IF-MIB.ifDescr_3",
"non_metric": 'oid-type1="ObjectIdentity" value1-type="OctetString" '
'1.3.6.1.2.1.2.2.1.2.1="lo" value1="eth1" IF-MIB::ifDescr.3="eth1" ',
'1.3.6.1.2.1.2.2.1.2.1="lo" value1="eth1" IF-MIB::ifDescr.3="eth1" ',
}
variables_binds_result = (
'oid-type1="ObjectIdentity" value1-type="OctetString" 1.3.6.1.2.1.2.2.1.2.1="lo" '
Expand Down

0 comments on commit c53b8b6

Please sign in to comment.