+ All Categories
Home > Technology > Splunk Developer Platform

Splunk Developer Platform

Date post: 27-Jan-2015
Category:
Upload: damien-dallimore
View: 120 times
Download: 1 times
Share this document with a friend
Description:
Presentation section from Splunk Live content
Popular Tags:
34
Splunk Developer Platform Damien Dallimore Developer Evangelist
Transcript
Page 1: Splunk Developer Platform

Splunk Developer Platform

Damien DallimoreDeveloper Evangelist

Page 2: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Splunk & Developers

2

REST API

Custom/Existing

Applications

SDKsSearch, chart and graph

Save and schedule searches as alertsExport search results

Manage inputs and indexesAdd & remove users and roles

SplunkUI(Splunk Apps)

Machine Data

Engine

Page 3: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

The Splunk REST API

3

• Exposes an API method for every feature in the product– Whatever you can do in the UI – you can do through the API– Run searches– Manage Splunk configurations

• API is RESTful– Endpoints are served by Splunkd– Requests are GET, POST, and DELETE HTTP methods– Responses are Atom XML Feeds or JSON – Versioning Support– Search results can be output in CSV/JSON/XML/Raw– Authentication is token based

Page 4: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Developer Platform

4

• We want to make it as easy as possible for developers to build Big Data apps and custom integrations on top of the Splunk platform

• Several different language offerings, Software Development Kits (SDKs)• Javascript, Java, Python, PHP, C#, Ruby

• Our SDKs make it easier to use the REST API• All Splunk functionality is accessible via our SDKs• Get Data into Splunk• Execute Splunk Searches, get data out of Splunk• Manage Splunk• Customized User Interfaces

Page 5: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Top 3 Developer Takeaways• Every developer can use Splunk to accelerate

dev & test and gain application intelligence

• The developer platform lets customers customize and extend the power of Splunk

• Splunk lets developers build big data apps with the skills they already have

Page 6: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Takeaway 1: Use Splunk to accelerate dev & test

6

• Splunk frees you from upfront database design for analytics• late binding schema

• Developers and QA/test engineers don’t have to ask IT/Ops to get logs off machines• Role base access to all data within one console without having to log into

production systems• All events are indexed and accessible in real-time in one place.• Ad-Hoc real-time monitoring and historical investigation searchable from one

place• Correlations and insights across multiple tiers.

• Splunk lets you find issues quickly, so you can fix issues quickly• Integrate Splunk search results into testing assertions

Page 7: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Takeaway 2: Customize and extend Splunk

7

Integrate data from Splunk into existing apps

and systems

Build custom line-of-business apps powered

by Splunk

Deliver Operational Intelligence to marketing, sales, customer service and other divisions beyond IT in the systems and apps that make sense to them.

REST API & SDKs

Page 8: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Takeaway 3: Splunk lets developers build big data apps with the skills they already have

8

• Developers can use the languages and frameworks they know and love – like Python, JavaScript, Java and PHP.

• No need to write MapReduce jobs, learn R or be some kind of scientist to build apps that use Big Data – be a developer!

Using the Python SDK to deliver customers real-time security intelligence into custom dashboards

Splunks 7 million API calls per day and exposes Splunk data to customers in their customer-facing web app via REST API

Page 9: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Why choose to develop on Splunk ?

9

• Splunk is not agnostic of its underlying data source , MapR algorithm optimized to Splunk index files

• Real time vs Batch Jobs

• Optimal for time series based data

• End to End Integrated Big Data Solution

• Fine grained protection of access and data using role based permissions

• Data retention and aging controls

• Users can submit “Map Reduce” jobs without needing to know how to code a MapR job

• Get the best of many worlds ie: Splunk Hadoop Connect

• Splunk integrates easily with other systems, developers can then just focus on developing against 1 single platform

Page 10: Splunk Developer Platform

Custom Visualizations

Page 11: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Visualizing Splunk with the SDKs

11

• Splunkweb has rich, but sometimes limited, visualization options• You can use the SDKs to extract data from Splunk using a search, and

visualize it in an entirely custom manner• Using the Javascript SDK you can integrate with third party charting

librarys like Google Charts, Rickshaw, D3,three.js etc..

Page 12: Splunk Developer Platform

Copyright © 2013, Splunk Inc.12

Development Approaches• Custom Advanced XML Modules

• Incorporate into Views in SplunkWeb Apps• Share on Splunkbase or reuse internally

• Use our new “Application Framework” (in preview mode currently)• Use our Python and Javascript SDK’s• Leverage your skills with other JS librarys (Backbone, JQuery)• Leverage the power of Django• Shareable UI components• Simple XML parser

• Code your own standalone application• Use any of our SDKs to build your own solution and UI (web based, fat, mobile)

Page 13: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Page 14: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Page 15: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Page 16: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Page 17: Splunk Developer Platform

Copyright © 2013, Splunk Inc.17

My Guiding Viz PrincipleThe visualization must be simple and intuitive to understand and derive meaning from at a glance.

Cool viz , but what are you telling me ?

Page 18: Splunk Developer Platform

SDK Code ExamplesSplunk SDK for Java

Page 19: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Get the Java SDK

19

• Open sourced under the Apache v2.0 license• Clone from Github : git clone https://github.com/splunk/splunk-sdk-java.git• Project level support for Eclipse and Intellij IDE’s• Pre-requisites

• JRE 6+• Ant , Maven coming• Splunk installed

• Loads of code examples• Project examples folder• Unit Tests• http://dev.splunk.com • http://gist.github.com/damiendallimore

• Comprehensive coverage of the REST API• Tutorial videos available at http://dev.splunk.com

Page 20: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Java SDK Class Model

20

Service

Resource

ResourceCollection Entity

EntityCollection Application Index

HTTPService

Input

InputCollection SavedSearchCollection

• Collections use a common mechanism to create and remove entities• Entities use a common mechanism to retrieve and update property values, and access entity metadata• Service is a wrapper that facilitates access to all Splunk REST endpoints

Page 21: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Key Java SDK use cases

21

• Connect and Authenticate• Manage• Input Events• Search

Page 22: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Connect and Authenticate

22

public static Service connectAndLoginToSplunkExample() {

Map<String, Object> connectionArgs = new HashMap<String, Object>(); connectionArgs.put("host", ”somehost"); connectionArgs.put("username", ”spring"); connectionArgs.put("password", ”integration"); connectionArgs.put("port", 8089); connectionArgs.put("scheme", "https");

// will login and save the session key which gets put in the HTTP Authorization header Service splunkService = Service.connect(connectionArgs); return splunkService;

}

Page 23: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Manage

23

public static void getServerInfoExample() {

Service splunkService = connectAndLoginToSplunkExample();

ServiceInfo info = splunkService.getInfo(); System.out.println("Info:"); for (String key : info.keySet()) System.out.println(" " + key + ": " + info.get(key));

Entity settings = splunkService.getSettings(); System.out.println("\nSettings:"); for (String key : settings.keySet()) System.out.println(" " + key + ": " + settings.get(key));

}

Page 24: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Input Events

24

public static void logEventToSplunkExample() {

Service splunkService = connectAndLoginToSplunkExample(); // Get a Receiver object Receiver receiver = splunkService.getReceiver();

// Set the sourcetype Args logArgs = new Args(); logArgs.put("source", ”http-rest"); logArgs.put("sourcetype", ”spring-example");

// Log an event into the spring index receiver.log(”spring", logArgs, ”SpringOne 2GX rocks");

}

• Other Input transports• HTTP REST Streaming• Raw TCP Oneshot & Streaming• Raw UDP & Syslog

Page 25: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Semantic LoggingLog anything that can add value when aggregated, charted or further analyzed

Example Bogus Pseudo-Code:

void submitPurchase(purchaseId) {

log.info("action=submitPurchaseStart, purchaseId=%d", purchaseId) //these calls throw an exception on error submitToCreditCard(...) generateInvoice(...) generateFullfillmentOrder(...) log.info("action=submitPurchaseCompleted, purchaseId=%d", purchaseId) }

• Create Human Readable Events• Clearly Timestamp Events• Use Key-Value Pairs (JSON Logging)• Separate Multi-Value Events• Log Unique Identifiers

Page 26: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Search

26

• Search query• a set of commands and functions you use to retrieve events from an index or a real-time stream , "search

index=spring error OR exception | head 10”• Saved search

• a search query that has been saved to be used again and can be set up to run on a regular schedule• Search job

• an instance of a completed or still-running search operation.Using a search ID you can access the results of the search when they become available. Job results are saved for a period of time on the server and can be retrieved

• Search Modes• Normal : asynchronous , poll job for status and results• Realtime : same as normal, but stream is kept open a results streamed in realtime• Blocking : synchronous , a job handle is returned when search is completed• Oneshot : synchronous , no job handle is returned, results are streamed• Export : synchronous, not a search per say, doesn’t return a job handle, results are streamed oldest to newest

Page 27: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Blocking Searches (Oneshot)

27

public static void simpleSearchExample() {

Service splunkService = connectAndLoginToSplunkExample(); String searchQuery = "search error OR exception| head 10"; Args queryArgs = new Args(); queryArgs.put("earliest_time", "-3d@d"); queryArgs.put("latest_time", "-1d@d"); // perform the search , blocks here InputStream stream = splunkService.search(searchQuery, queryArgs); processInputStream(stream);

}

Page 28: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Blocking Searches (Export)

28

public static void exportSearchExample() {

Service splunkService = connectAndLoginToSplunkExample(); String searchQuery = "search error OR exception | head 10"; Args queryArgs = new Args(); queryArgs.put("earliest_time", "-1d@d"); queryArgs.put("latest_time", "now"); // perform the export , blocks here InputStream stream = splunkService.export(searchQuery, queryArgs); processInputStream(stream);

}

Page 29: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Non Blocking Search

29

public static void searchJobExample() {

Service splunkService = connectAndLoginToSplunkExample();

String outputMode = "csv";// xml,json,csv

// submit the job Job job = splunkService.getJobs().create("search index=spring error OR fatal | head 10"); while (!job.isDone()) { try {Thread.sleep(500);} catch (Exception e) {} }

Args outputArgs = new Args(); outputArgs.put("output_mode", outputMode);

InputStream stream = job.getResults(outputArgs); processInputStream(stream, outputMode); // uses xml stream, opencsv and gson}

Page 30: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Realtime Search

30

public static void realTimeSearchExample() {

Service splunkService = connectAndLoginToSplunkExample();

Args queryArgs = new Args();

queryArgs.put("earliest_time", "rt-5m"); queryArgs.put("latest_time", "rt");

// submit the job Job job = splunkService.getJobs().create("search index=spring exception OR error”, queryArgs);

}

Page 31: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Alternate JVM Languages

31

Scala Groovy Clojure

Javascript(Rhino) JRuby PHP(Quercus)

Ceylon Kotlin Jython

We don’t need SDK’s for these languages , we can just use the Java SDK !

Page 32: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Groovy

32

class SplunkJavaSDKWrapper {

static main(args) { //connect and login def connectionParameters = [host:”somehost",username:"spring",password:"integration"] Service service = Service.connect(connectionParameters) //get Splunk Server info ServiceInfo info = service.getInfo()

def splunkInfo = [:]

for (key in info.keySet()) splunkInfo.put(key,info.get(key))

printSplunkInfo(splunkInfo)

} static printSplunkInfo(splunkInfo) { println "Info” splunkInfo.each { key, value ->println key + " : " + value} }}

Page 33: Splunk Developer Platform

Copyright © 2013, Splunk Inc.

Scala

33

import com.splunk.Service._

import scala.collection.mutable.HashMap

import scala.collection.JavaConversions._

object SplunkJavaSDKWrapper {

def main(args: Array[String]) = {

//connect and login

val connectionArgs = HashMap[String, Object]("host" ->”somehost”,"username" ->”me”,"password" ->”foo")

val service = connect(connectionArgs)

//get Splunk Server info

val info = service.getInfo

// Scala/Java conversion

val javaSet = info.keySet

val scalaSet = javaSet.toSet

//print out Splunk Server info

for (key <- scalaSet)

println(key + ":" + info.get(key))

}

}

Page 34: Splunk Developer Platform

Copyright © 2013, Splunk Inc.34

Contact me

Email : [email protected] : @damiendallimoreSkype : damien.dallimoreGithub : damiendallimoreSplunkbase : damiendSlideshare : http://www.slideshare.net/damiendallimore Blogs : http://blogs.splunk.com/devWeb : http://dev.splunk.com


Recommended