Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ryanwilsonperkin
Last active January 20, 2021 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanwilsonperkin/10754f02286644965eb3246bd38f46d0 to your computer and use it in GitHub Desktop.
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
#!/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