Mais conteúdo relacionado Semelhante a Splunk Developer Platform (20) Mais de Damien Dallimore (9) Splunk Developer Platform2. Copyright©2013,SplunkInc.
Splunk & Developers
2
REST API
Custom/Existin
g Applications
SDKs
Search, chart and graph
Save and schedule searches as alerts
Export search results
Manage inputs and indexes
Add & remove users and roles
SplunkUI
(Splunk Apps)
Machine Data
Engine
3. Copyright©2013,SplunkInc.
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
– Requestsare 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
4. Copyright©2013,SplunkInc.
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
5. Copyright©2013,SplunkInc.
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
6. Copyright©2013,SplunkInc.
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
7. Copyright©2013,SplunkInc.
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
8. Copyright©2013,SplunkInc.
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
9. Copyright©2013,SplunkInc.
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
11. Copyright©2013,SplunkInc.
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..
12. Copyright©2013,SplunkInc.
Development Approaches
12
• 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)
19. Copyright©2013,SplunkInc.
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 levelsupport for Eclipse and IntellijIDE’s
• Pre-requisites
• JRE6+
• Ant , Maven coming
• Splunk installed
• Loadsof code examples
• Project examplesfolder
• Unit Tests
• http://dev.splunk.com
• http://gist.github.com/damiendallimore
• Comprehensivecoverageof the REST API
• Tutorialvideos availableat http://dev.splunk.com
20. Copyright©2013,SplunkInc.
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
22. Copyright©2013,SplunkInc.
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;
}
23. Copyright©2013,SplunkInc.
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));
}
24. Copyright©2013,SplunkInc.
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
25. Copyright©2013,SplunkInc.
Semantic Logging
Log 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
26. Copyright©2013,SplunkInc.
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
27. Copyright©2013,SplunkInc.
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);
}
28. Copyright©2013,SplunkInc.
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);
}
29. Copyright©2013,SplunkInc.
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
}
30. Copyright©2013,SplunkInc.
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);
…
}
32. Copyright©2013,SplunkInc.
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}
}
}
34. Copyright©2013,SplunkInc.
Contact me
34
Email : ddallimore@splunk.com
Twitter : @damiendallimore
Skype : damien.dallimore
Github : damiendallimore
Splunkbase : damiend
Slideshare : http://www.slideshare.net/damiendallimore
Blogs : http://blogs.splunk.com/dev
Web : http://dev.splunk.com
Notas do Editor UsingSplunk on development and testing to improve application quality and time-to-release Developers can use the Splunk SDKs to: Run real-time searches and retrieve Splunk data from line-of-business systems like Customer Service applications Integrate data and visualizations (charts, tables) from Splunk into BI tools and reporting dashboardsBuild mobile applications with real-time KPI dashboards and alerts powered by Splunk Log directly to Splunk from remote devices and applications via TCP, UDP and HTTPBuild customer-facing dashboards in your applications powered by user-specific data in Splunk Manage a Splunk instance, including adding and removing users as well as creating data inputs from an application outside of SplunkProgrammatically extract data from Splunk for long-term data warehousing Ohio-based Security MSP Hurricane Labs delivers real-time security intelligence to customers using the Splunk SDK for Python. Hurricane Labs deliver’s relevant security-related data from Splunk to their customers via custom dashboards embedded in their website.San Francisco-based startup Socialize allows mobile developers to instantly add social features to their apps. More than just ratings and comments, the Socialize platform encourages mobile app users to take “social actions” within the app to drive re-engagement, retention and distribution. These “social actions” are measured, analyzed and leveraged for subsequent re-actions that increase activity and engagement in mobile apps.Socialize leverages Splunk for MapReduce and Big Data analysis. Mobile apps using Socialize create large amounts of data, averaging over 7 million API requests per day and one million actions per month. Building on the Splunk REST API to integrate at the application level for business intelligence, reporting and alerting, Socialize exposes Splunk data to its customers through highly customized dashboards. Example of a silicon valley startup , tshark , mac , 3 weeks coding custom programs , I did this in 30 mins