-
-
Save ryanwilsonperkin/10754f02286644965eb3246bd38f46d0 to your computer and use it in GitHub Desktop.
A script that treats arguments as DataDog queries and opens them in a notebook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
# usage: dog query1 query2 ... | |
# Opens a new DataDog notebook with the provided queries | |
# When given no arguments, just opens a new notebook | |
require 'cgi' | |
require 'json' | |
URI_BASE = 'https://shopify.datadoghq.com/notebook' | |
def query_cell(query) | |
{ | |
source: { | |
requests: [ | |
{q: query, type: 'line'} | |
], | |
}, | |
type: 'timeseries' | |
} | |
end | |
def open_link(url) | |
system("open #{url}") | |
end | |
if __FILE__ == $PROGRAM_NAME | |
if ARGV.length.zero? | |
open_link(URI_BASE) | |
else | |
cells = ARGV.map { |query| query_cell(query) } | |
escaped = CGI.escape(cells.to_json) | |
open_link("#{URI_BASE}?cells=#{escaped}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment