Skip to content

Instantly share code, notes, and snippets.

@nstielau
Last active August 22, 2019 15:32
Show Gist options
  • Save nstielau/4e7e380dd74d6566f21d3aeea56261f2 to your computer and use it in GitHub Desktop.
Save nstielau/4e7e380dd74d6566f21d3aeea56261f2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'yaml'
#
# dasher
# This script takes a configmap yaml file and a JSON grafana dashboard file,
# and replaces the JSON in the configmap with the JSON from the file. This
# is useful for updating the telemeter-lts dashboard config maps with JSON
# expoerted from a modified Grafana dashboard.
if ARGV.length != 2
raise "Usage: dasher /path/to/grafana-dash.configmap.yaml /path/to/dashboard.json"
end
puts "Loading configmap from #{ARGV.first}, JSON dashboard from #{ARGV.last}"
configmap = YAML.load_file(ARGV.first)
raise "Expected a single key, found #{configmap["data"].keys}" unless configmap["data"].length == 1
key = configmap["data"].keys.first
configmap["data"][key] = File.open(ARGV.last).read
File.open(ARGV.first, "w") { |file| file.write(configmap.to_yaml) }
puts "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment