Getting Data In

Service item.update causes modular input to restart

aronsemle
New Member

In my modular input I want to update a configuration setting between runs so I don't poll for the same data again and again. The code I use to do this is below. It's using the splunklib.client library (https://docs.splunk.com/DocumentationStatic/PythonSDK/1.1/client.html#splunklib.client.Service.login) to make a REST connection to Splunk, using the session held by the modular input, it grabs the config section and calls item.update to update the query_param.

The call to item.update causes the entire modular input to reload... and in the logs I get a "Winsock error 10054", most likely because of the reload.

I'm on Splunk 8.0.1 running Python3. I can't find any documentation on this behavior. I tried not using the SESSION_TOKEN, and instead connecting with username/password, but same issue. I also tried adding service.logout at the end, but that code never executes. Is this expected?

            try:
                args = {'host':'localhost','port':SPLUNK_PORT,'token':SESSION_TOKEN}
                service = Service(**args)

                item = service.inputs.__getitem__(STANZA[len(APP_NAME) + 3:])
                item.update(query_params = dictionary_to_params(url_args))

            except Exception as e:
                logging.error("Error trying to update args: %s" % str(e))

One last note. In the logs I get the following warning. I assume this is being causes by the app restarting.

03-16-2020 08:52:25.232 -0400 WARN HttpListener - Socket error from 127.0.0.1:56292 while accessing /servicesNS/nobody/launcher/data/inputs/my_app/my_data_input/: Winsock error 10054

0 Karma
Get Updates on the Splunk Community!

.conf24 | Day 0

Hello Splunk Community! My name is Chris, and I'm based in Canberra, Australia's capital, and I travelled for ...

Enhance Security Visibility with Splunk Enterprise Security 7.1 through Threat ...

(view in My Videos)Struggling with alert fatigue, lack of context, and prioritization around security ...

Troubleshooting the OpenTelemetry Collector

  In this tech talk, you’ll learn how to troubleshoot the OpenTelemetry collector - from checking the ...