Last active
June 29, 2018 09:47
-
-
Save superseb/dacac8bc5bb29110ccd92ab5c107f799 to your computer and use it in GitHub Desktop.
Print all not healthy infrastructure stacks/services in Rancher 1.6 install
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
#!/bin/bash | |
# Set needed account key info | |
RANCHER_URL=http://your_rancher_url:8080 | |
CATTLE_ACCESS_KEY=account_api_acces_key | |
CATTLE_SECRET_KEY=account_api_secret_key | |
# alias curl so we dont have to specify everything each invocation | |
curl="curl -s --connect-timeout 10 --max-time 30 -u $CATTLE_ACCESS_KEY:$CATTLE_SECRET_KEY $@" | |
# Get all environment ids | |
ENVIRONMENTS=$($curl $RANCHER_URL/v2-beta/projects | jq -r '.data[] | select(.state != "inactive") | .id') | |
# Loop through environment ids | |
for ENV in $ENVIRONMENTS; do | |
# Get environment name | |
ENV_NAME=$($curl $RANCHER_URL/v2-beta/projects/$ENV | jq -r .name) | |
# Get all system stacks that do not have healthState healthy | |
NOT_HEALTHY_STACKS=$($curl $RANCHER_URL/v2-beta/projects/$ENV/stacks | jq -r '.data[] | select((.system == true or .name == "kubernetes-ingress-lbs" or .name == "kubernetes-loadbalancers") and .healthState != "healthy") | .id') | |
# Loop through not active stacks | |
for STACK in $NOT_HEALTHY_STACKS; do | |
# Get stack info | |
STACK_INFO=$($curl $RANCHER_URL/v2-beta/projects/$ENV/stacks/$STACK | jq -r '.') | |
# Extract stack healthState from stack info | |
STACK_STATE=$(echo $STACK_INFO | jq -r '.healthState') | |
# Extract stackname from stack info | |
STACK_NAME=$(echo $STACK_INFO | jq -r '.name') | |
# Print info | |
echo "stack;$ENV_NAME;$STACK_NAME;$STACK_STATE" | |
# Get all services from this stack | |
STACK_SERVICES=$($curl $RANCHER_URL/v2-beta/projects/$ENV/services?stackId=$STACK | jq -r '.data[] | select(.healthState != "healthy") | .id') | |
for SERVICE in $STACK_SERVICES; do | |
# Get service info | |
SERVICE_INFO=$($curl $RANCHER_URL/v2-beta/projects/$ENV/services/$SERVICE | jq -r '.') | |
# Extract service healthState from service info | |
SERVICE_STATE=$(echo $SERVICE_INFO | jq -r '.healthState') | |
# Extract servicename from service info | |
SERVICE_NAME=$(echo $SERVICE_INFO | jq -r '.name') | |
# Print info | |
echo "service;$ENV_NAME;$SERVICE_NAME;$SERVICE_STATE" | |
done | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment