Splunk Cheat Sheet – Some Commonly Used Splunk Commands

Get N number of results
index=myIndex sourcetype=myFileType SearchTermOrExpression | head 2

Exclude a Phrase
index=myIndex sourcetype=myFileType PhraseToSearch NOT PhraseNotToSearch

Search Exceptions or Errors
index=myIndex sourcetype=myFileType *Exception* OR *Error*

Stats – Count by Host
index=myIndex sourcetype=myFileType SearchTerm | status count by host

Stats – Count per day
index=myIndex sourcetype=myFileType SearchTerm |convert timeformat=”%Y-%m-%d” ctime(_time) AS date | stats count by date

Table of Extracted Fields
index=myIndex sourcetype=myFileType SearchTerm |table myExtractedField1, myExtractedField2, myExtractedField3

Status – Sort Descending
index=myIndex sourcetype=myFileType SearchTerm | status count by someField | sort by someField

Status – Sort Ascending
index=myIndex sourcetype=myFileType SearchTerm | status count by someField | sort by -someField

Items per hour (date_hour)
index=myIndex sourcetype=myFileType SearchTerm | top date_hour

Remove Duplicates
index=myIndex sourcetype=myFileType SearchTerm |table myExtractedField1, myExtractedField2, myExtractedField3 | dedup myExtractedField1

A Basic Implementation of Binary Tree in Java

A Binary Tree simply can be defined in Java as a node that holds a value for itself and holds reference to a left child node and a right child node. The binary tree can have nodes that have a maximum of 2 children. As you can see in the example below, I have defined the value to be of type Comparable, so that it can be any object that can be compare for less than, greater than or equals. However, if you are going to only store either integers or Strings, for example, you can change the data type to int or String as needed.

The following is a very simple implementation of this concept.

Note: – if the binary tree has left nodes only or right nodes only, it becomes a singly linked list.

package com.icodejava.blog.published.datastructure;
/**
* @author Kushal Paudyal
* Created on 12/5/2016
* Last Modified on 12/5/2016
*
* Binary Tree Node representation.
* - Node has a value, a left node and a right node.
* - Single node, when created, has left and right node as null.
*/
@SuppressWarnings("rawtypes")
class BinaryTreeNode {
Comparable value;
BinaryTreeNode left;
BinaryTreeNode right;

public BinaryTreeNode(Comparable value) {
this.value = value;
this.left = null;
this.right = null;
}

public Comparable getValue() {
return value;
}

public void setValue(Comparable value) {
this.value = value;
}

public BinaryTreeNode getLeft() {
return left;
}

public void setLeft(BinaryTreeNode left) {
this.left = left;
}

public BinaryTreeNode getRight() {
return right;
}

public void setRight(BinaryTreeNode right) {
this.right = right;
}

}

A Basic Implementation of Generic Tree in Java

A generic tree data structure can be implemented in Java with the concept of an object to define a node and the object itself having a reference to n children nodes (or null to point the tree termination i.e. Leaf Nodes).

The following is a very trivial implementation of this data structure to show the concept of generic tree. The use of an array is completely voluntary, you can use any other datastructure of your choice to hold the children based on your need (Such as ArrayList or even LinkedLists).

This code any any other codes published in this blog are also available at Github (search for icodejava)

package com.icodejava.blog.published.datastructure;

/**
 * 
 * @author Kushal Paudyal www.icodejava.com Created On - Dec 5, 2016 Last
 *         Modified On - Dec 5, 2016
 * 
 *         This class shows a basic implementation of Generic Tree concept in
 *         Java.
 */
public abstract class AbstractGenericTreeNode {

	private AbstractGenericTreeNode [] children;

	public AbstractGenericTreeNode [] getChildren() {
		return children;
	}

	public void setChildren(AbstractGenericTreeNode [] children) {
		this.children = children;
	}
	
	public int getNumberOfChildren () {
		
		return children != null ? children.length : 0;
	}
	
}

The following is a concrete implementation of the Abstract node above and is defined to hold integer values. You however can implement this class to hold the object of your choice.

package com.icodejava.blog.published.datastructure;

/**
 * 
 * @author Kushal Paudyal www.icodejava.com Created On - Dec 5, 2016 Last
 *         Modified On - Dec 5, 2016
 * 
 *         This class shows a basic implementation of Generic Tree concept in
 *         Java.
 */

public class IntegerTreeNode extends AbstractGenericTreeNode {
	private int value;

	public IntegerTreeNode(int value, AbstractGenericTreeNode[] children) {
		super();
		this.value = value;
		this.setChildren(children);
	}

	public int getValue() {
		return value;
	}

}

Generic trees are different from Binary Trees. Binary Trees have 2 child nodes at maximum whereas the generic trees can have n-number of children.