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

Commit

Permalink
style: fix of duplicated code linter problem
Browse files Browse the repository at this point in the history
  • Loading branch information
omrozowicz-splunk authored and Artem Rys committed Aug 24, 2021
1 parent 2fa415a commit c855088
Showing 1 changed file with 69 additions and 56 deletions.
125 changes: 69 additions & 56 deletions splunk_connect_for_snmp_poller/manager/task_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,51 @@ def _any_failure_happened(
return True


def _any_walk_failure_happened(
errorIndication,
errorStatus,
errorIndex,
host,
index,
otel_logs_url,
otel_metrics_url,
one_time_flag,
is_metric,
varBinds,
):
if errorIndication:
result = f"error: {errorIndication}"
logger.info(result)
post_data_to_splunk_hec(
host,
otel_logs_url,
otel_metrics_url,
result,
is_metric,
index,
one_time_flag,
)
return True
elif errorStatus:
result = "error: {} at {}".format(
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or "?",
)
logger.info(result)
post_data_to_splunk_hec(
host,
otel_logs_url,
otel_metrics_url,
result,
is_metric,
index,
one_time_flag,
)
return True
else:
return False


def snmp_bulk_handler(
mongo_connection,
enricher_presence,
Expand Down Expand Up @@ -365,34 +410,18 @@ def walk_handler(
lexicographicMode=False,
):
is_metric = False
if errorIndication:
result = f"error: {errorIndication}"
logger.info(result)
post_data_to_splunk_hec(
host,
otel_logs_url,
otel_metrics_url,
result,
is_metric,
index,
one_time_flag,
)
break
elif errorStatus:
result = "error: {} at {}".format(
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or "?",
)
logger.info(result)
post_data_to_splunk_hec(
host,
otel_logs_url,
otel_metrics_url,
result,
is_metric,
index,
one_time_flag,
)
if _any_walk_failure_happened(
errorIndication,
errorStatus,
errorIndex,
host,
index,
otel_logs_url,
otel_metrics_url,
one_time_flag,
is_metric,
varBinds,
):
break
else:
result, is_metric = get_translated_string(mib_server_url, varBinds)
Expand Down Expand Up @@ -439,34 +468,18 @@ def walk_handler_with_enricher(
lexicographicMode=False,
):
is_metric = False
if errorIndication:
result = f"error: {errorIndication}"
logger.info(result)
post_data_to_splunk_hec(
host,
otel_logs_url,
otel_metrics_url,
result,
is_metric,
index,
one_time_flag,
)
break
elif errorStatus:
result = "error: {} at {}".format(
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or "?",
)
logger.info(result)
post_data_to_splunk_hec(
host,
otel_logs_url,
otel_metrics_url,
result,
is_metric,
index,
one_time_flag,
)
if _any_walk_failure_happened(
errorIndication,
errorStatus,
errorIndex,
host,
index,
otel_logs_url,
otel_metrics_url,
one_time_flag,
is_metric,
varBinds,
):
break
else:
result, is_metric = get_translated_string(mib_server_url, varBinds, True)
Expand Down

0 comments on commit c855088

Please sign in to comment.