Quantcast
Channel: Questions in topic: "splunk-enterprise"
Viewing all articles
Browse latest Browse all 47296

How to get Splunk to run my Python shell script?

$
0
0
I am trying to use the Splunk Synthetic App in order to set up and monitor fake transactions that I create with Python. I am running into problems when I try and get Splunk to run my shell script (Test2^SplunkOpenTest^.sh) which calls my Python program (Test2^SplunkOpenTest^.py) on a Linux VM. I go to Settings -> Data Inputs > Scripts and set the sourcetype and index to both be synthetic but somehow Splunk doesn’t collect the data even though the program works when I run it from the Linux terminal. Because of this I looked inside the Splunkd.log file and noticed that every 60 seconds when Splunk is supposed to get the data from the script, it gives an error that looks like this:
06-20-2016 12:07:19.638 -0400 ERROR ExecProcessor – message from “/opt/splunk/etc/apps/splunk-app-synthetic/bin/Test2^SplunkOpenTest^.sh ImportError: No module named selenium
I have tried to figure this out for a day now and I feel like I’m missing something so simple but for the life of me I cannot figure out what that is. My Test2^SplunkOpenTest^.sh file looks like so:
#!/bin/bash
unset PYTHONPATH
unset LD_LIBRARY_PATH
CLASSPATH=”/usr/lib/pyth/selenium-server-standalone-2.53.0.jar”
export CLASSPATH
SELENIUM_SERVER_JAR=”/usr/lib/pyth/selenium-server-standalone-2.53.0.jar”
export SELENIUM_SERVER_JAR
python /opt/splunk/etc/apps/splunk-app-synthetic/bin/Test2^SplunkOpenTest^.py
And my Test2^SplunkOpenTest^.py file looks like:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
from splunktransactions import Transaction
class SplunkOpenTest(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "http://localhost:8000/en-US/account/login?return_to=%2Fen-US%2F"
	time.sleep(5)
        self.verificationErrors = []
        self.accept_next_alert = True
    def test_splunk_open(self):
        driver = self.driver
	a=Transaction(driver, 'Splunk')
	a.TransactionStart(driver, 'Splunk Login Page')
        driver.get(self.base_url + "/")
	a.TransactionEnd(driver, 'Splunk Login Page')
	time.sleep(4)
    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException as e: return False
        return True
    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
    unittest.main()
I appreciate the assistance with this!

Viewing all articles
Browse latest Browse all 47296

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>