(function() { var logstash = { params: { offset: 0, count: 50, }, search: function(query) { logstash.params.q = query; document.location.hash = escape(JSON.stringify(logstash.params)); $("#results").load("/search/ajax", logstash.params); $("#query").val(logstash.params.q); }, /* search */ appendquery: function(query) { var newquery = $("#query").val(); newquery += " " + query; logstash.search(newquery.trim()); }, /* appendquery */ plot: function(data) { var target = $("#visual"); var plot = $.plot(target, [ { /* data */ data: data, bars: { show: true, barWidth: 3600000, } } ], { /* options */ xaxis: { mode: "time" }, grid: { hoverable: true, clickable: true }, } ); target.bind("plotclick", function(e, pos, item) { if (item) { start = logstash.ms_to_iso8601(item.datapoint[0]); end = logstash.ms_to_iso8601(item.datapoint[0] + 3600000); logstash.appendquery("@timestamp:[" + start + " TO " + end + "]"); } }); }, /* plot */ ms_to_iso8601: function(milliseconds) { /* From: * https://developer.mozilla.org/en/JavaScript/Reference/global_objects/date#Example.3a_ISO_8601_formatted_dates */ var d = new Date(milliseconds); function pad(n){return n<10 ? '0'+n : n} return d.getUTCFullYear()+'-' + pad(d.getUTCMonth()+1)+'-' + pad(d.getUTCDate())+'T' + pad(d.getUTCHours())+':' + pad(d.getUTCMinutes())+':' + pad(d.getUTCSeconds())+'Z' }, }; /* logstash */ window.logstash = logstash; $().ready(function() { if (location.hash.length > 1) { try { logstash.params = JSON.parse(unescape(location.hash.substring(1))); } catch (e) { // Do nothing } logstash.search(logstash.params.q); } $(window).hashchange(function() { logstash.params = JSON.parse(unescape(location.hash.substring(1))); query = logstash.params.q if (query != $("#query").val()) { scroll(0, 0); logstash.search(query); } }); $("a.pager").live("click", function() { var href = $(this).attr("href"); var params = href.replace(/^[^?]*\?/, "").split("&") for (var p in params) { var a = params[p].split("="); var key = a[0] var value = a[1] logstash.params[key] = value } logstash.search(logstash.params.q) return false; }); $("a.querychanger").live("click", function() { var href = $(this).attr("href"); var re = new RegExp("[&?]q=([^&]+)"); var match = re.exec(href); if (match) { logstash.search(match[1]); } return false; }); $("ul.results li.event").live("click", function() { var data = eval($(this).data("full")); /* Apply template to the dialog */ var query = $("#query").val().replace(/^\s+|\s+$/g, "") var sanitize = function(str) { if (!/^".*"$/.test(str)) { str = '"' + str + '"'; } return escape(str); }; var template = $.template("inspector", "