No problem, this is the code of that .py (renamed it to be more generic for this) All the logger.debug messages print none for search info / session key stuff """
Custom Splunk Command
"""
import os,sys
import logging
import splunk.Intersplunk
from utils import Utils
# Library-loading boilerplate
APP_NAME = 'my_app'
splunkhome = os.environ['SPLUNK_HOME']
apphome = os.path.join(splunkhome, 'etc', 'apps', APP_NAME)
sys.path.append(os.path.join(apphome, 'vendor'))
import splunklib.client as client
from splunklib.client import Service
from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators
@Configuration()
class MyCommand(GeneratingCommand):
ip = Option(require=True)
def generate(self):
logger = self.utils.setup_logger()
logger.debug("Starting command search")
try:
logger.debug(self.service)
logger.debug(self._metadata.searchinfo.session_key)
#logger.debug(self._metadata.searchinfo.auth_token)
logger.debug(sys.stdin.readline().strip())
logger.debug(self.search_results_info.auth_token)
logger.debug(f"Splunk version: {service.info.version}") #This errors
# Extract IP addresses from the command's argument
logger.debug("ip pased into search " + self.ip)
except Exception as e:
logger.error("Error:", e)
def __init__(self):
super(MyCommand, self).__init__()
# Initialize Utils class with the session key
session_key = sys.stdin.readline().strip()
self.utils = Utils(session_key)
# Dispatch your custom search command
dispatch(MyCommand, sys.argv, sys.stdin, sys.stdout, __name__)
... View more