Page MenuHomePhabricator
Paste P12125

check_realserver_vs_conftool.sh
ActivePublic

Authored by CDanis on Wed, Jul 29, 3:32 PM.
#!/bin/bash
set -e
set -u
set -o pipefail
yaml2json() {
ruby -rjson -ryaml -e 'puts YAML.safe_load(File.open("'"$1"'").read, [], [], true).to_json'
}
# Conftool's node YAMLs are structured like:
# datacentername: # e.g. eqsin
# clustername: # e.g. cache_text
# hostname: [servicenames] # e.g. cp5007.eqsin.wmnet: [varnish-fe, ats-be, ats-tls]
# This constructs a JSON map that looks like:
# "cp5007.eqsin.wmnet": ["cache_text.ats-be","cache_text.ats-tls","cache_text.varnish-fe"]
conftool_nodes() {
(for FILE in /var/lib/git/operations/puppet/conftool-data/node/*.yaml ; do
yaml2json "$FILE" | jq '.[] | to_entries[] | .key as $cluster | .value | map_values(map($cluster + "." + .) | unique)'
done) | jq -Ss add
}
# Construct a map that maps from top-level service names (e.g. 'text') to conftool cluster.service names (e.g. 'cache_text.varnish-fe')
# Intended for use as a jq --slurpfile.
lvspools_to_conftool_clusterservices() {
yaml2json /var/lib/git/operations/puppet/hieradata/common/service.yaml \
| jq '.["service::catalog"] | to_entries[] | {(.key): (.value.lvs.conftool.cluster + "." + .value.lvs.conftool.service)}'\
| jq -Ss add
}
# Fetches from puppetdb all the profile::lvs::realserver resources.
realserver_resources() {
curl -sG https://puppetdb1002.eqiad.wmnet/pdb/query/v4/resources \
--data-urlencode query='["=", "title", "Profile::Lvs::Realserver"]'
}
# Constructs a map of FQDN --> conftool cluster.service names.
realservers() {
realserver_resources \
| jq -S '[.[] | {(.certname): (.parameters.pools | keys)}] | add | map_values(sort)' \
| jq -S --slurpfile conftoolname <( lvspools_to_conftool_clusterservices ) \
'map_values(map($conftoolname[0][.]) | unique)'
}
diff -u <(realservers | tr -d ,) <(conftool_nodes | tr -d ,)

Event Timeline

CDanis edited the content of this paste. (Show Details)Wed, Jul 29, 3:32 PM
CDanis changed the title of this paste from untitled to Masterwork From Distant Lands.
CDanis changed the title of this paste from Masterwork From Distant Lands to check_realserver_vs_conftool.sh.Wed, Jul 29, 3:39 PM
CDanis edited the content of this paste. (Show Details)
CDanis edited the content of this paste. (Show Details)Wed, Jul 29, 3:44 PM
CDanis edited the content of this paste. (Show Details)Wed, Jul 29, 3:47 PM