0
votes
splunkmonitormessage= subprocess.Popen(["sudo", "/opt/splunkforwarder/bin/splunk", "add monitor", path], stdin=subprocess.PIPE, stdout=subprocess.PIPE)

(Ive also tried str(path))

is throwing an error:

Command error: The subcommand '/opt/logs/node_Default_Node.log' is not valid for command 'add monitor'. Data forwarding configuration management tools.

Commands: enable local-index [-parameter ] ... disable local-index [-parameter ] ... display local-index add [forward-server|search-server] server remove [forward-server|search-server] server list [forward-server|search-server]

Objects: forward-server a Splunk forwarder to forward data to be indexed search-server a Splunk server to forward searches local-index a local search index on the Splunk server

sudo /opt/splunkforwarder/bin/splunk add monitor /opt/logs/node_Default_Node.log

works completely fine

What am I doing wrong?

1

1 Answers

2
votes

Pass "add" and "monitor" as separate arguments:

splunkmonitormessage = subprocess.Popen(
    ["sudo", "/opt/splunkforwarder/bin/splunk", "add", "monitor", path],
    stdin=subprocess.PIPE, stdout=subprocess.PIPE
)

It's how the shell would naturally pass it, so that's what it expects.