Customers often ask about using third-party tools and services with Splunk data. So, we came up with this application that uses the Splunk SDK for Python and demonstrates how to use a Leftronic dashboard to show real-time Twitter data that we index using Splunk.

You'll need a few things before you can get this application running:
The basic process components to the Dashboard application are:
We use a variety of searches to get Twitter data out of Splunk and into Leftronic. Here are the real-time searches we run.
Top sources of tweets
We get the top sources (such as web client and mobile devices) of tweets from the last five minutes:
def top_sources(service):
query = "search index=twitter status_source=* | stats count(status_source) as count by status_source | sort -count | head 5"
created_job = service.jobs.create(query, search_mode="realtime", earliest_time="rt-5m", latest_time="rt")
Geo-location of tweets
We get all the tweets with geo-location enabled and their coordinates:
geo(service):
query = "search index=twitter coordinates_type=Point coordinates_coordinates=* | fields coordinates_coordinates"
created_job = service.jobs.create(query, search_mode="realtime", earliest_time="rt-5m", latest_time="rt")
Most recent tweets
We get the most recent tweets from the last five minutes:
def tweets(service):
query = "search index=twitter | head 15 | fields user_name, user_screen_name, text, user_profile_image_url "
created_job = service.jobs.create(query, search_mode="realtime", earliest_time="rt-5m", latest_time="rt")
User and tweet counts
We run a single search to get two statistics—the number of distinct users who tweeted in the last five minutes and the total number of tweets:
def counts(service):
query = "search index=twitter | stats count by user_id | fields user_id, count | stats count(user_id) as user_count, sum(count) as tweet_count"
created_job = service.jobs.create(query, search_mode="realtime", earliest_time="rt-5m", latest_time="rt")
Top tags
We get a list of the top hashtags from the last five minutes:
def top_tags(service):
query = 'search index=twitter text=* | rex field=text max_match=1000 "#(?<tag>\w{1,})" | fields tag | mvexpand tag | top 5 tag'
created_job = service.jobs.create(query, search_mode="realtime", earliest_time="rt-5m", latest_time="rt")
We poll these searches for new results in a loop. Then, we transform the results and submit the output to Leftronic using the Leftronic API. For more about the Leftronic API and the data format it requires, see the Leftronic API page.
def send_data(access_key, stream_name, point = None, command = None):
data = {
"accessKey": access_key,
"streamName": stream_name
}
if not point is None:
data["point"] = point
if not command is None:
data["command"] = command
request = urllib2.Request("https://beta.leftronic.com/customSend/",
data = json.dumps(data)
)
response = urllib2.urlopen(request)
Assuming you have everything that we said you'd need, here's how to run the Dashboard application.
You'll need to build a Leftronic dashboard by adding a custom data source for each Splunk search you want to display.
For example, the Leftronic dashboard in the image above uses these widgets, titles, and streams:
| Widget | Title | Stream name |
| Custom Leaderboard | Top sources | top_sources |
| Custom Geo | Tweet locations | geo |
| Custom Text | Tweets | tweets |
| Custom Text | User count (last 5 min) | users_count_5m |
| Custom Text | Tweet count (last 5 min) | tweets_count_5m |
| Custom Leaderboard | Top tags | top_tags |
Run the Twitted example to index Twitter data:
./splunk restart
python input.py
You should immediately see incoming Twitter data in the console.
The Dashboard application is located in the /splunk-sdk-python/examples/dashboard directory. Before you can run it, you need to edit the source file (feed.py) with your Leftronic access key.
leftronic_access_key = ""
python feed.py