Created
December 2, 2014 00:43
-
-
Save jpadams/b63383dc0eb7d3d45fe4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/bin/bash | |
| if [ "$#" -ne 1 ]; then | |
| echo "Takes exactly 1 arg: the resolvable name of the graphite server. Exiting..." | |
| exit 1 | |
| fi | |
| ping -c 1 $1 | |
| if [ "$?" -ne 0 ]; then | |
| echo "Could not ping graphite server. Exiting..." | |
| exit 2 | |
| fi | |
| declare -x PE_CERT=$(/opt/puppet/bin/puppet agent --configprint hostcert) | |
| declare -x PE_KEY=$(/opt/puppet/bin/puppet agent --configprint hostprivkey) | |
| declare -x PE_CA=$(/opt/puppet/bin/puppet agent --configprint localcacert) | |
| declare -x NC_CURL_OPT="-s --cacert $PE_CA --cert $PE_CERT --key $PE_KEY --insecure" | |
| find_guid() | |
| { | |
| echo $(curl $NC_CURL_OPT --insecure https://localhost:4433/classifier-api/v1/groups| python -m json.tool |grep -C 2 "$1" | grep "id" | cut -d: -f2 | sed 's/[\", ]//g') | |
| } | |
| # PE Infrastructure group is the parent of the PE Master group | |
| PE_Infra_ID=$(find_guid 'PE Infrastructure') | |
| PE_Master_ID=$(find_guid 'PE Master') | |
| # Graphite metrics are not enabled by default. | |
| # This classification changes the setting of | |
| # the "metrics_graphite_enabled" param | |
| # to true. | |
| curl -X POST -H 'Content-Type: application/json' \ | |
| -d \ | |
| '{ | |
| "name": "PE Master", | |
| "environment": "production", | |
| "parent": "'$PE_Infra_ID'", | |
| "classes": { | |
| "puppet_enterprise::profile::master": { | |
| "metrics_graphite_enabled": true, | |
| "metrics_graphite_host": "'$1'" | |
| } | |
| }, | |
| "variables": {} | |
| }' \ | |
| --cacert $PE_CA \ | |
| --cert $PE_CERT \ | |
| --key $PE_KEY \ | |
| --insecure \ | |
| https://localhost:4433/classifier-api/v1/groups/$PE_Master_ID | python -m json.tool |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment