Skip to content

Commit

Permalink
updated types
Browse files Browse the repository at this point in the history
Signed-off-by: Shashank Reddy Boyapally <[email protected]>
  • Loading branch information
shashank-boyapally committed Oct 2, 2024
1 parent e62527a commit ed8bbb6
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions fmatch/splunk_matcher.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
#pylint: disable = C0209, R0913, E0401
# pylint: disable = C0209, R0913, E0401
"""
Matcher for splunk datasource
"""
import orjson
from splunklib import client, results
from typing import Dict, Any


class SplunkMatcher:
"""Splunk data source matcher
"""
def __init__(self, host, port, username, password, indice): #pylint: disable = R0917
"""Splunk data source matcher"""

def __init__(
self, host: str, port: int, username: str, password: str, indice: str
): # pylint: disable = R0917
self.indice = indice
self.service = client.connect(
host=host, port=port, username=username, password=password
)

async def query(self, query, searchList="", max_results=10000):
async def query(
self, query: Dict[Any, Any], searchList: str = "", max_results: int = 10000
):
"""
Query data from splunk server using splunk lib sdk
Expand All @@ -33,7 +38,7 @@ async def query(self, query, searchList="", max_results=10000):
)
try:
oneshotsearch_results = self.service.jobs.oneshot(searchindex, **query)
except Exception as e: #pylint: disable = W0718
except Exception as e: # pylint: disable = W0718
print("Error querying splunk: {}".format(e))
return None

Expand All @@ -43,7 +48,7 @@ async def query(self, query, searchList="", max_results=10000):
try:
res_array.append(
{
"data": orjson.loads(record["_raw"]), #pylint: disable = E1101
"data": orjson.loads(record["_raw"]), # pylint: disable = E1101
"host": record["host"],
"source": record["source"],
"sourcetype": record["sourcetype"],
Expand All @@ -52,12 +57,12 @@ async def query(self, query, searchList="", max_results=10000):
"timestamp": record["_indextime"],
}
)
except Exception as e: #pylint: disable = W0718
except Exception as e: # pylint: disable = W0718
print(f"Error on including Splunk record query in results array: {e}")

return res_array

async def _stream_results(self, oneshotsearch_results):
async def _stream_results(self, oneshotsearch_results: Any) -> Any:
for record in results.JSONResultsReader(oneshotsearch_results):
yield record

Expand Down

0 comments on commit ed8bbb6

Please sign in to comment.