Using jQuery to Search Sumo Logic (API)

Getting your data out of Sumo Logic is easy.  You can export raw results from the UI, but you can also leverage the REST API to query your data.  Here’s a quick snippet of code to use jQuery/AJAX to search Sumo

$.ajax
({ type: "GET",
   url: $sumoURL,
   dataType: "json",
   beforeSend: function(xhr) {
 xhr.setRequestHeader("Authorization", "Basic " + btoa($sumoAccessID+":"+$sumoAccessKey));},
    async: false,
   success : function(JSONdata)
     {
       response = JSONdata;
     }
}

A few notes, the $sumoURL variable is the URL encoded API search. Here is an example:

https://api.sumologic.com/api/v1/logs/search?q=error&from=2012-04-04T13:01:02&to=2012-04-04T15:01:02

For details on valid parameters and formatting, check out the documentation on GitHub

The $sumoAccessID and $sumoAccessKey variables refer to the API keys that you can set up in the Sumo Logic UI.

And that’s about it.  The results come back in JSON, so do some crafty parsing and do awesome stuff with it.

Be sure to protect your API keys, putting them in an HTML or JS file on a public server is a BAD idea - this is all client side, so prying eyes could get your credentials.

Eventually, I’d like to put together a form where you can enter the authentication info and a search and have it return a JSON document - thinking that this could be integrated as a header for a web application that uses the Sumo Logic data.  However, my free time is a bit limited these days, too busy keeping up with the 4PB of data we’re processing daily!