Created
December 13, 2018 14:13
-
-
Save matsimitsu/fb10ab856142262004369b3ed4c27983 to your computer and use it in GitHub Desktop.
This file contains 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
# Consumer that updates dashboards for an app | |
# through the AppSignal GraphQL API. | |
require 'rest-client' | |
require 'active_support' | |
require 'active_support/core_ext' | |
APPID = '' # app/site id, can be found in the url (/sites/<id>) | |
TOKEN = '' # Can be found on https://appsignal.com/users/edit | |
# The GraphQL mutation | |
QUERY = <<-GRAPHQL | |
mutation updateDashboardMutation($appId: String!, $dashboards: [DashboardInput]!) { | |
updateDashboards(appId: $appId, dashboards: $dashboards) { | |
title | |
graphs { | |
title | |
} | |
__typename | |
} | |
} | |
GRAPHQL | |
# Variables, such as app ID and the Dashboard to post | |
variables = { | |
'appId' => APPID, | |
'dashboards' => [ # Insert your dashboards here, this is an example | |
{ | |
'title' => 'Heroku Postres', | |
'graphs' => [ | |
{ | |
'title' => 'Connections', | |
'kind' => 'gauge', | |
'format' => 'number', | |
'fields' => [ | |
'active_connections', | |
'waiting_connections' | |
], | |
'tags' => [ | |
{ | |
'key' => 'source', | |
'value' => '*' | |
}, | |
{ | |
'key' => 'addon', | |
'value' => '*' | |
} | |
] | |
} | |
] | |
} | |
] | |
} | |
# Execute the query and parse the result | |
result = RestClient.post( | |
"https://appsignal.com/graphql?token=#{TOKEN}", | |
{:query => QUERY, :variables => variables} | |
) | |
puts JSON.parse(result).inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment