Ok this all doesn't seems to work at my environment. I have to say I'm also running El Capitan 10.11.3.
Commands.conf:
[ucmstest]
filename = ucmstest.py
supports_getinfo = true
supports_rawargs = false
passauth = true
enableheader = true
requires_srinfo = true
And ucmstest.py is:
from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators
import sys, os
import time
import logging, logging.handlers
import splunk
import urllib2
###passauth=True; enableheader=True
@Configuration()
class ucmstest(GeneratingCommand):
count = Option(require=True, validate=validators.Integer(0))
text = Option(require=True)
def generate(self):
logger = logging.getLogger('UCMS dq Logging')
SPLUNK_HOME = os.environ['SPLUNK_HOME']
LOGGING_DEFAULT_CONFIG_FILE = os.path.join(SPLUNK_HOME, 'etc', 'log.cfg')
LOGGING_LOCAL_CONFIG_FILE = os.path.join(SPLUNK_HOME, 'etc', 'log-local.cfg')
LOGGING_STANZA_NAME = 'pythondebug'
LOGGING_FILE_NAME = "ucmsdqreconsilestats.log"
BASE_LOG_PATH = os.path.join('var', 'log', 'splunk')
LOGGING_FORMAT = "%(asctime)s %(levelname)-s\t%(module)s:%(lineno)d - %(message)s"
splunk_log_handler = logging.handlers.RotatingFileHandler(os.path.join(SPLUNK_HOME, BASE_LOG_PATH, LOGGING_FILE_NAME), mode='a')
splunk_log_handler.setFormatter(logging.Formatter(LOGGING_FORMAT))
logger.addHandler(splunk_log_handler)
logmode = logging.DEBUG
logger.setLevel(logmode)
splunk.setupSplunkLogger(logger, LOGGING_DEFAULT_CONFIG_FILE, LOGGING_LOCAL_CONFIG_FILE, LOGGING_STANZA_NAME)
logger.info("Start of logging...................................................")
yield {'_serial': 1, '_time': time.time(), '_raw':"this is a test"}
logger.debug("sys.stdin is: %s",str(sys.stdin))
#logger.debug("read %s", str(sys.stdin.read()))
csvf = sys.stdin.readline().strip()
logger.debug("csvf file is: %s and length %i", csvf, len(csvf))
#csvf = csvf.replace("infoPath:", "")
logger.debug("csvf is now: %s", csvf)
with open(csvf) as hfile:
logger.debug("within open section")
reader = csv.DictReader(hfile)
for row in reader:
tkn = row['_auth_token']
logger.debug("tkn is: %s", tkn)
dispatch(ucmstest, sys.argv, sys.stdin, sys.stdout, __name__)
When i do |ucmstest count=1 text="bla" in Splunk Web, I do get:
External search command 'ucmstest' returned error code 1. Script output = "error_message=IOError at "/Applications/splunkucmsdq/splunk/etc/apps/ucmsdq/bin/ucmstest.py", line 41 : [Errno 2] No such file or directory: '' _raw,__mv__raw,_time,__mv__time,_serial,__mv__serial this is a test,,1456854995.48,,1, "
And i do get the following in my "ucmsdqreconsilestats.log":
2016-03-01 19:03:43,565 INFO __init__:168 - Using default logging config file: /Applications/splunkucmsdq/splunk/etc/log.cfg
2016-03-01 19:03:43,566 INFO __init__:206 - Setting logger=splunk level=INFO
2016-03-01 19:03:43,566 INFO __init__:206 - Setting logger=splunk.appserver level=INFO
2016-03-01 19:03:43,567 INFO __init__:206 - Setting logger=splunk.appserver.controllers level=INFO
2016-03-01 19:03:43,567 INFO __init__:206 - Setting logger=splunk.appserver.controllers.proxy level=INFO
2016-03-01 19:03:43,567 INFO __init__:206 - Setting logger=splunk.appserver.lib level=WARN
2016-03-01 19:03:43,567 INFO __init__:206 - Setting logger=splunk.pdfgen level=INFO
2016-03-01 19:03:43,567 INFO __init__:206 - Setting logger=splunk.search level=INFO
2016-03-01 19:03:43,567 INFO ucmstest:32 - Start of logging...................................................
2016-03-01 19:03:43,567 DEBUG ucmstest:34 - sys.stdin is: <open file '<stdin>', mode 'r' at 0x107dc10c0>
2016-03-01 19:03:43,568 DEBUG ucmstest:38 - csvf file is: and length 0
2016-03-01 19:03:43,568 DEBUG ucmstest:40 - csvf is now:
Can you otherwise share your code?
... View more