Skip to content

Instantly share code, notes, and snippets.

@jhoblitt
Created June 3, 2024 18:46
Show Gist options
  • Save jhoblitt/40577e31a84c5cb8fe744a1e2a010788 to your computer and use it in GitHub Desktop.
Save jhoblitt/40577e31a84c5cb8fe744a1e2a010788 to your computer and use it in GitHub Desktop.
finding route53 records with names that match 'pdu' and formatting them into prometheus file sd json format.
aws route53 list-resource-record-sets --hosted-zone-id ZPIEHXTK3ZPMR | jq '.ResourceRecordSets' > ls.lsst.org.json
aws route53 list-resource-record-sets --hosted-zone-id Z2CCXZLXGUUYM5 | jq '.ResourceRecordSets' > cp.lsst.org.json
./r53_to_file_sd.rb ls.lsst.org.json cp.lsst.org.json > /home/jhoblitt/github/k8s-cookbook/fleet/lib/snmp-exporter-pre/files/sd/dev/snmp-raritan-pdu.json
#!/bin/env ruby
require 'json'
files = ARGV
file_sd_config = []
files.each do |file|
dns = JSON.parse(File.read(file))
dns.each do |record|
name = record['Name']
next unless name =~ /pdu/
# trim tailing dot from record name
name = name.gsub!(/\.$/, '')
file_sd_config << {
'labels' => {
'__meta_hostname' => name,
},
'targets' => [record['ResourceRecords'].first['Value']],
}
end
end
puts JSON.pretty_generate(file_sd_config.sort_by { |h| h['labels']['__meta_hostname'] })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment