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

Commit

Permalink
fix: Remove unused async
Browse files Browse the repository at this point in the history
  • Loading branch information
rfaircloth-splunk committed Nov 4, 2021
1 parent 86611d3 commit 6c04bb1
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions splunk_connect_for_snmp_poller/manager/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# limitations under the License.
#
import os
import threading

from asgiref.sync import async_to_sync
from celery import Task
from celery.utils.log import get_task_logger
from pysnmp.hlapi import ObjectIdentity, ObjectType, SnmpEngine

Expand All @@ -39,18 +39,9 @@
)
from splunk_connect_for_snmp_poller.mongo import WalkedHostsRepository

thread_local = threading.local()
logger = get_task_logger(__name__)


def get_shared_snmp_engine():
if not hasattr(thread_local, "local_snmp_engine"):
thread_local.local_snmp_engine = SnmpEngine()
logger.info("Created a single shared instance of an SnmpEngine() object")

return thread_local.local_snmp_engine


async def get_snmp_data(
var_binds,
handler,
Expand Down Expand Up @@ -117,9 +108,14 @@ def sort_varbinds(varbind_list: list) -> VarbindCollection:
casted_multikey_elements += VarbindCollection(get=get_list, bulk=bulk_list)
return casted_multikey_elements

class SNMPTask(Task):

def __init__(self):
self.snmp_engine = SnmpEngine()

@app.task(ignore_result=True)
def snmp_polling(

@app.task(bind=True,ignore_result=True)
def snmp_polling(self,
ir_json: str,
server_config,
index,
Expand All @@ -144,9 +140,6 @@ async def snmp_polling_async(
host, port = parse_port(ir.host)
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)
Expand All @@ -159,7 +152,7 @@ async def snmp_polling_async(
additional_metric_fields = server_config.get("additionalMetricField")
enricher_presence = "enricher" in server_config
static_parameters = [
snmp_engine,
self.snmp_engine,
hec_sender,
auth_data,
context_data,
Expand Down

0 comments on commit 6c04bb1

Please sign in to comment.