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

Commit

Permalink
fixing logging level
Browse files Browse the repository at this point in the history
  • Loading branch information
okuzhel committed Sep 29, 2021
1 parent edf4fc9 commit c23399b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 31 deletions.
2 changes: 1 addition & 1 deletion splunk_connect_for_snmp_poller/manager/hec_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _enrich_event_data(mib_enricher: MibEnricher, variables_binds: dict) -> str:
metric_result = json.loads(variables_binds["metric"])
non_metric_result = variables_binds["non_metric"]
additional_dimensions = mib_enricher.append_additional_dimensions(metric_result)
logger.info(additional_dimensions)
logger.debug(additional_dimensions)
for field_name in additional_dimensions:
if field_name in metric_result:
non_metric_result += f'{field_name}="{metric_result[field_name]}" '
Expand Down
2 changes: 1 addition & 1 deletion splunk_connect_for_snmp_poller/manager/poller.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __check_inventory(self):
continue

inventory_hosts.add(entry_key)
logger.info(
logger.debug(
"[-] server_config['profiles']: %s", self._server_config["profiles"]
)
if entry_key not in self._jobs_map:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def extract_network_interface_data_from_existing_config(config_as_dict):
"splunk_dimension_name": splunk_dimension[key],
}
)
logger.info(f"IF-MIB additional attributes for Splunk: {result}")
logger.debug(f"IF-MIB additional attributes for Splunk: {result}")
return result


Expand Down
23 changes: 9 additions & 14 deletions splunk_connect_for_snmp_poller/manager/task_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def get_translated_string(mib_server_url, varBinds, return_multimetric=Fal
@return result: formated string ready to be sent to Splunk HEC
@return is_metric: boolean, metric data flag
"""
logger.info(f"I got these var binds: {varBinds}")
logger.debug(f"I got these var binds: {varBinds}")
# Get Original varbinds as backup in case the mib-server is unreachable
try:
for name, val in varBinds:
Expand All @@ -107,38 +107,33 @@ async def get_translated_string(mib_server_url, varBinds, return_multimetric=Fal
result = '{oid}="{value}"'.format(
oid=name.prettyPrint(), value=val.prettyPrint()
)
logger.info("Our result is - %s", result)
logger.debug("Our result is - %s", result)
except Exception as e:
logger.info(
logger.error(
f"Exception occurred while logging varBinds name & value. Exception: {e}"
)

# Override the varBinds string with translated varBinds string
try:
data_format = _get_data_format(is_metric, return_multimetric)
logger.debug(
"==========result before translated -- is_metric={is_metric}============\n%s",
result,
)
logger.debug(f"result before translated -- is_metric={is_metric}\n{result}")
result = await get_translation(varBinds, mib_server_url, data_format)
if data_format == "MULTIMETRIC":
result = json.loads(result)["metric"]
logger.info(f"=========result=======\n{result}")
logger.debug(f"multimetric result\n{result}")
# TODO double check the result to handle the edge case,
# where the value of an metric data was translated from int to string
if "metric_name" in result:
result_dict = json.loads(result)
_value = result_dict.get("_value", None)
logger.debug(f"=========_value=======\n{_value}")
logger.debug(f"metric value\n{_value}")
if not is_metric_data(_value):
is_metric = False
data_format = _get_data_format(is_metric, return_multimetric)
result = await get_translation(varBinds, mib_server_url, data_format)
except Exception as e:
logger.info(f"Could not perform translation. Exception: {e}")
logger.info(
f"###############final result -- metric: {is_metric}#######################\n{result}"
)
logger.error(f"Could not perform translation. Exception: {e}")
logger.debug(f"final result -- metric: {is_metric}\n{result}")
return result, is_metric


Expand Down Expand Up @@ -307,7 +302,7 @@ def _any_walk_failure_happened(
):
if errorIndication:
result = f"error: {errorIndication}"
logger.info(result)
logger.info(f"Result with error indication - {result}")
post_data_to_splunk_hec(
host,
otel_logs_url,
Expand Down
8 changes: 4 additions & 4 deletions splunk_connect_for_snmp_poller/manager/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,18 @@ async def snmp_polling_async(
otel_logs_url = os.environ["OTEL_SERVER_LOGS_URL"]
otel_metrics_url = os.environ["OTEL_SERVER_METRICS_URL"]
host, port = parse_port(ir.host)
logger.info("Using the following MIBS server URL: %s", mib_server_url)
logger.debug("Using the following MIBS server URL: %s", mib_server_url)

# create one SnmpEngie for snmp_get_handler, walk_handler, mib_string_handler
snmp_engine = get_shared_snmp_engine()

# create auth_data depending on SNMP's version
auth_data = build_authData(ir.version, ir.community, server_config)
logger.debug("==========auth_data=========\n%s", auth_data)
logger.debug("auth_data\n%s", auth_data)

# create context_data for SNMP v3
context_data = build_contextData(ir.version, ir.community, server_config)
logger.debug("==========context_data=========\n%s", context_data)
logger.debug("context_data\n%s", context_data)

mongo_connection = WalkedHostsRepository(server_config["mongo"])
additional_metric_fields = server_config.get("additionalMetricField")
Expand Down Expand Up @@ -179,7 +179,7 @@ async def snmp_polling_async(
var_binds = mib_profile.get("varBinds", None)
# Divide varBinds for WALK/BULK actions
varbind_collection = sort_varbinds(var_binds)
logger.info(f"Varbind collection: {varbind_collection}")
logger.debug(f"Varbind collection: {varbind_collection}")
# Perform SNMP BULK
await get_snmp_data(
varbind_collection.bulk,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ def is_valid_profile(profile):


def is_valid_inventory_line_from_dict(host, version, community, profile, seconds):
logger.info(
f"Validating host = [{host}], version = [{version}], community = [{community}], profile = [{profile}], "
f"seconds = [{seconds}]"
)

if None in [host, version, community, profile, seconds]:
return False

Expand All @@ -131,5 +126,8 @@ def is_valid_inventory_line_from_dict(host, version, community, profile, seconds
and is_valid_second_quantity(seconds.strip())
)
if not valid_inventory_line:
logger.error("Invalid inventory line")
logger.error(
f"Invalid inventory line [{host}], version = [{version}], community = [{community}], profile = [{profile}],"
f" seconds = [{seconds}]"
)
return valid_inventory_line
4 changes: 2 additions & 2 deletions splunk_connect_for_snmp_poller/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def add_host(self, host):
self._walked_hosts.insert_one({"_id": host})

def delete_host(self, host):
logger.info(f"Delete host {host} from walked_host collection")
logger.debug("Delete host %s from walked_host collection", host)
self._walked_hosts.delete_one({"_id": host})

def clear(self):
Expand All @@ -125,7 +125,7 @@ def real_time_data_for(self, host):
def static_data_for(self, host):
full_collection = self._walked_hosts.find_one({"_id": host})
if not full_collection:
logger.info(f"No id {host} in walked_host collection")
logger.debug("No id %s in walked_host collection", host)
return None
if WalkedHostsRepository.MIB_STATIC_DATA in full_collection:
mib_static_data = full_collection[WalkedHostsRepository.MIB_STATIC_DATA]
Expand Down
4 changes: 2 additions & 2 deletions splunk_connect_for_snmp_poller/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def parse_command_line_arguments():
parser.add_argument(
"-l",
"--loglevel",
default="debug",
help="Provide logging level. Example --loglevel debug, default=warning",
default="info",
help="Provide logging level. Example --loglevel debug, default=info",
)
parser.add_argument("-c", "--config", default="config.yaml", help="Config File")
parser.add_argument(
Expand Down

0 comments on commit c23399b

Please sign in to comment.