Splunk Dev

Looking for an example generating custom script that execute OS command

melonman
Motivator

Hi

I am looking for a simple example of custom generating search command that
executes OS command and show the result of execution.

I don't have much knowledge of Python SDK, but I want to start from an simple example.

Thank you, and any commend would be appreciated.

0 Karma

kamal_jagga
Contributor

Its better if you do this in a separate/new app.

In local directory of app, create commands.conf (if it is already not there).
Commands.conf
[cachecheck]
filename=command_cachecheck.py

In bin directory of app create command_cachecheck.py
import os,re,csv
import sys
os.system("data \" +%c\" ")
command = 'vmstat -s'
os.system(command)

Restart searchhead and give proper permissions.

In SH get the results by searching |cachecheck.

Get Updates on the Splunk Community!

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...