Показаны сообщения с ярлыком Splunk. Показать все сообщения
Показаны сообщения с ярлыком Splunk. Показать все сообщения

вторник, 1 сентября 2015 г.

AWS S3 logs in Splunk

With Splunk it is possible to solve any task where we have lot's of unstructured data and want quickly to insight value from data. Let's consider one of example in case of cloud technologies such as AudienceStream DMP This is amazing data management platform which services us for real marketing automatization.

One of capabilities of AS platform is enriching current customer database with external data. For example we can using machine learning and internal transaction data for  defining score for every customer who is online. We can calculate scoring via R or enterprise data mining platform such as SAS or SPSS and send result to Amazon S3. AS can connect S3 and ingest files. But how can we analyze this process? There are lots of S3 logs in our bucket with GET, PUT methods.  Splunk can easy connect AWS S3 via splunk app - Splunk Add-on for Amazon Web Service.

As usual we download this app and install. Than we have to connect to AWS account:
We only need copy paste Account Key ID and Secret Key.
After connecting to AWS account we should setup new data inputs. Let's go to AWS S3:
And click "Add New".
Than choose existing account, S3 host name (in my case it is default) and S3 bucket:
Moreover we can specify index and white/blacklist and some other options. When we finish, Splunk will update input.conf file which we can access any time and adjust. There are all possible parameters of S3 input
When we finish, splunk begin to ingest logs. We can easy search them by typing name of index, in my case it is "s3logs":
 By default splunk didn't extract any field from S3 logs. But we can easy find structure of log and
using field extractor create all fields:
We have all information in order to create report, which shows us hourly upload by AS for the last 48 hours.

index=* sourcetype=aws:s3 earliest=-48h method_detail="REST.GET.OBJECT" clientip = 107.14.21.138 object_name=*.csv | timechart span=1h count by object_name

We filter by filetype, method and ip of AS.

Moreover, we can use Splunk CLI and automatically run search via crontab and extract to flatfile in order to visualize and update report every 5 minutes.

There is shell script for linux:

#!/bin/bash
# File: test_action.sh 
# Description: To output saved search result
#

SPLUNK_HOME="/Applications/Splunk"
OUTPUT="test_output.log"
USER=admin
PASSWORD=changeme
$SPLUNK_HOME/bin/splunk search 'index=* sourcetype=aws:s3 earliest=-48h method_detail="REST.GET.OBJECT" clientip = 107.14.21.138 object_name=*.csv | timechart span=1h count by object_name' -auth ${USER}:${PASSWORD} > ${OUTPUT}






четверг, 13 августа 2015 г.

SlackIT with Splunk

Splunk has announced cool new app SlackIT. You can easy download it.






Wait, do you know what is slack? It is the best in class team communication service. Do you have a team? Then you definitely should use slack.

Ok, let's connect splunk and slack.

First, we should download new app in splunk. It is easy. Moreover we haven't do any addition actions in splunk interface, except some actions with slack.conf file. But before we start, lets go to slack and add new integration:





Let's choose channel, which will get result from splunk search






In addition, we can choose any person, who will get result. Then click on "Add Incoming WebHook Integration" and copy Webhook URL, which will send json result from splunk to slack.

We have done with slack. Let's start to configure slack.conf file, which we can find in slackit app:


  • url: Webhook URL , for example: https://hooks.slack.com/services/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
  • username: the username that appears in slack
  • channel: the channel that will receive the search results, channel can be specified by slackit search arg or person
  • icon: the icon that appears in slack.
  • allow_user_set_slack_url: enable this option if you're allowing the users send results to different # slack teams
  • send_message_even_no_results: disable option to send message without result



[config]
url = https://hooks.slack.com/services/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y
username = gold_unicorn
channel = our-team
icon = https://www.splunk.com/content/dam/splunk2/images/icons/favicons/mstile-150x150.png
allow_user_set_slack_url = 0
send_message_even_no_results=0

Save file. That's all. Now we can easy send result from splunk to the salck channel. Let's try to do it.



As you see on screen, I've just added slackit command. And what is the result? All my team in channel saw this result:)


PS As a bonus you send any message via terminal using the same Webhock URL:

curl -X POST --data-urlencode 'payload={"channel "#our-team", "username": "webhookbot", "text": "What's up!", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/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y





среда, 15 октября 2014 г.

Splunk TRANSACTION Command


Splunk definition of the command:

Given events as input, this command finds transactions based on events that meet various constraints. Transactions are made up of the raw text (the _raw field) of each member, the time and date fields of the earliest member, as well as the union of all other fields of each member.
Additionally, the transaction command produces two fields to the raw events, duration and eventcount. The duration value is the difference between the timestamps for the first and last events in the transaction. The eventcount value is the number of events in the transaction.


• A transaction is any group of related events that span time
• Events can come from multiple applications or hosts
- Events related to a single purchase from an online store can span across an
application server, database, and e-commerce engine
- One email message can create multiple events as it travels through various queues
– Each event in the network traffic logs represents a single user generating a single http request
– Visiting a single website normally generates multiple http requests - HTML, JavaScript, CSS files
- Flash, Images, etc. 

• <field-list>
–  One field or a list of field names
–  The events are grouped into transactions based on the values of this field list
–  If a quoted list of fields is specified, events are grouped together if they have the same value for each of the fields

• Common constraints:
– <maxspan> | <maxpause> | <maxevents> | <startswith> | <endswith> | <keepevicted> 

• Here you can see a number of events that share the same JSESSIONID
• However, it is difficult to display or gain insight to what is happening






Example 1
Display customer transactions in the online store during the last 15 minutes.

• Use the transaction command to create a single event from a group of events that share the same value in a given field
• Transactions can cross multiple tiers (i.e., web server, application server) using a common field(s), in this example, JSESSIONID



Type in search:
sourcetype=access_combined | transaction JSESSIONID

Example 2
Display a table of what customers are doing in the online store during the last 60 minutes.
With the transaction command, you can also use tables to easily view the information that you want
Scenario ?
Type in search:
sourcetype=access_combined | transaction JSESSIONID | table JSESSIONID, action, product_name

Specific Fields of transaction:
• The transaction command produces some additional fields, such as:
–  duration – the difference between the timestamps for the first and last event in the transaction
–  eventcount – the number of events in the transaction

Example 3
Use of maxspan/maxpause
Display customer actions on the website during the last 4 hours.
• You can also define a max overall time span and max gap between events
Scenario ?
- maxspan=10m
         ▸ Maximum total time between the earliest and latest events
         ▸ If not specified, default is -1 (or no limit)
 - maxpause=1m
         ▸ Maximum total time between events 
         ▸ If not specified, default is -1 (or no limit)
Note
Assumptions: Transactions spanning more than 10 minutes with the same client IP are considered unrelated, nor can there be more than one 1 minute between any two related events.

Type in search:
sourcetype=access_combined | transaction clientip maxspan=10m maxpause=1m | eval duration = round(duration/60,2) | sort -duration | table clientip duration action | rename duration as "Time Spent", clientip as "Client IP",   action as "Client Actions"

Type in search:
sourcetype=access_combined | transaction clientip maxspan=10m maxpause=1m | eval duration = round(duration/60,2) | sort -duration | table clientip duration action | rename duration as "Time Spent", clientip as "Client IP",   action as "Client Actions"

Example 4
Use of startswith/endswith
Determine the length of time spent by customers in the online store to purchase.
• To form transactions based on terms, field values, or evaluations, use startswith and endswith options
• In this example, the first event in the transaction includes addtocart and the last event includes purchase

Type in search:
sourcetype=access_combined | transaction clientip startswith=action="addtocart" endswith=action="purchase" | table clientip,  JSESSIONID, product_name, action, duration, eventcount, price

Example 5
Investigating with Transactions
Find emails that were rejected during the last 24 hours.

• Transactions can be useful when a single event does not provide enough information
• This example searches email logs for the term “REJECT”
• Events that include the term don’t provide much information about the rejection Scenario ?

Type in search:
sourcetype=cisco_esa REJECT


Find emails that were rejected.
• By creating a transaction, we can then search and see additional events related to the rejection, such as:
- IP address of sender
- Reverse DNS lookup results
- Action taken by the mail system following the rejection
• mid – Message ID
• dcid – Delivery Connection ID 
• icid – Incoming Connection ID

Type in search:
sourcetype=cisco_esa | transaction mid dcid icid | search REJECT




Reporting on Transactions
• You can use statistics and reporting commands with transactions
• This example takes advantage of the duration field
–  It shows a trend of the mail queue slowing, then correcting, then slowing again
- Adding events to the transaction from additional hosts or sources can uncover the cause of the slowdown

Type in search:
sourcetype=cisco_esa | transaction mid dcid ion) | timechart avg(duration)


Transaction vs. Stats
• Use transaction when you
     –  Need to see events correlated together
     –  Must define event grouping based on start/end values
• Use stats when you:
     –  Want to see the results of a calculation
     –  Can group events based on a field value (e.g. "by src")
• When you have a choice, always use stats
     –  stats is faster and more efficient, especially in large Splunk environments

Lets consider example:

sourcetype=sales_entries                                                             sourcetype=sales_entries
| transaction CustomerID                                                             | stats count as eventcount
| table CustomerID eventcount                                                    by CustomerID        
Returned 101 by scanning 31,767 events                                    Returned 101 results by scanning                                
 in 0.802 seconds                                                                          31,797 events   in 0.499 seconds


  

    

воскресенье, 21 сентября 2014 г.

What is Splunk?


Technically speaking, Splunk is a time-series indexer, but to simplify things we will just say that it is a product that takes care of the three Vs very well. 

If we go to technical details, Splunk is key-value store, where key is a timestmap. In addition, it use MapReduce in order to process data.

Whereas most of the products that we described earlier had their origins in processing human-generated digital footprints, Splunk started as a product designed to process machine data. Because of these humble beginnings, Splunk is not always considered a player in big data. But that should not prevent you from using it to analyze big data belonging in the digital footprint category, because, as this book shows, Splunk does a great job of it. Splunk has three main functionalities: 



  • Data collection, which can be done for static data or by monitoring changes and additions to files or complete directories on a real time basis. Data can also be collected from network ports or directly from programs or scripts. Additionally, Splunk can connect with relational databases to collect, insert or update data.
  • Data indexing, in which the collected data is broken down into events, roughly equivalent to database records, or simply lines of data. Then the data is processed and a high performance index is updated, which points to the stored data.\
  • Search and analysis. Using the Splunk Processing Language, you are able to search for data and manipulate it to obtain the desired results, whether in the form of reports or alerts. The results can be presented as individual events, tables, or charts.

Each one of these functionalities can scale independently; for example, the data collection component can scale to handle hundreds of thousands of servers. The data indexing functionality can scale to a large number of servers, which can be configured as distributed peers, and, if necessary, with a high availability option to transparently handle fault tolerance. The search heads, as the servers dedicated to the search and analysis functionality are known, can also scale to as many as needed. Additionally, each of these functionalities can be arranged in such a way that they can be optimized to accommodate geographical locations, time zones, data centers, or any other requirements. Splunk is so flexible regarding scalability that you can start with a single instance of the product running on your laptop and grow from there.
You can interact with Splunk by using SplunkWeb, the browser-based user interface, or directly using the command line interface (CLI). Splunk is flexible in that it can run on Windows or just about any variation of Unix.
Splunk is also a platform that can be used to develop applications to handle big data analytics. It has a powerful set of APIs that can be used with Python, Java, JavaScript, Ruby, PHP, and C#. The development of apps on top of Splunk is beyond the scope of this book; however, we do describe how to use some of the popular apps that are freely available. We will leave it at that, as all the rest of the book is about Splunk.