This is a code sample on how to push simple data from PowerShell and into elastic search. Note that $metrics can be just about anything, here it is a dictionary but you can use a PS custom object or even define your own class in an external assembly. The JSON serialization understands nesting so your data can be deeply structured.
Have fun! Post a comment if this was helpful.
I recommend using Chrome with the Sense plugin to see what landed in ES.
[Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
$metrics = new-object 'System.Collections.Generic.Dictionary[string,object]'
$metrics.Add("foo",1)
$serializedMetric = new-object System.Text.StringBuilder
$javaScriptSerializer = new-object System.Web.Script.Serialization.JavaScriptSerializer
$javaScriptSerializer.Serialize($metrics, $serializedMetric);
$ESEndPoint = "http://localhost:9200"
$indexname = "my-index"
$typename = "mytype"
$id = [Guid]::NewGuid().ToString('n')
$indexedEndpoint = $ESEndPoint + "/" + $indexname + "/" + $typename + "/" + $id
$webClient = new-object System.net.WebClient
$webClient.UploadString($indexedEndpoint, $serializedMetric.ToString())
# Note: Retrieve from ES with GET /my-index/mytype/_all
READY.
Tuesday, January 14, 2014
Wednesday, January 8, 2014
gVim: a macro to insert an underline (====) with Ctrl-L
:map <C-l> :call append(".",repeat("=",(col("$")-1)))<CR>:echo "*BOOM*"<CR>
Friday, March 9, 2012
How to crash CMD.EXE
dir | for %i in () do nothing
You can find an access violation in the Windows event log after crashing CMD.EXE with the above command line. Enjoy!
You can find an access violation in the Windows event log after crashing CMD.EXE with the above command line. Enjoy!
how to get a list of all file types on Windows and the programs that open them
for /f "delims== tokens=2" %i in ('assoc') do
@FTYPE "%i">>programs.list 2>&1
Subscribe to:
Posts (Atom)