Last active
October 21, 2021 15:31
-
-
Save Richard-Barrett/0a0bc7b4515ddf1737f73d3b994aedeb to your computer and use it in GitHub Desktop.
OpenStack Collection Info Script
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 | |
# ====================================================== | |
# Author: Richard Barrett | |
# Date Created: 06/08/2021 | |
# Purpose: Initialize OpenStack Collection Script | |
# ====================================================== | |
# Official documentation | |
# ========================================================================================================================================================== | |
# ... | |
# ========================================================================================================================================================== | |
start=`date +%s` | |
#set -e | |
# keep track of the last executed command | |
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG | |
# echo an error message before exiting | |
#trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT | |
# EXIT Codes | |
# ========== | |
EXIT=1 | |
EXIT_2=2 | |
EXIT_126=126 | |
# System Variables | |
# ================ | |
DATE="$(date +'%Y%-m%d')" | |
OS_VERSION=$(cat /etc/os-release) | |
AUTH_FILE=$(sudo find / -name admin-openrc.sh | sort -n | uniq | grep -i root | head -n 1) | |
AUTHENTICATE=$(source $AUTH_FILE) | |
OPENSTACK_VERSION=$(openstack --version) | |
CLUSTER_NAME=$(openstack region list -c Region -f value) | |
SUPPORT_DUMP_DIR="/tmp/$CLUSTER_NAME" | |
OPENSTACK_INFO_DIR="/tmp/$CLUSTER_NAME/openstack_info" | |
PROMETHEUS_SCRAPE_TARGET="grep mon /etc/hosts | awk '{print $1}' | sed -n 1p" | |
PROMETHEUS_SCRAPE="curl -s http://$(grep mon /etc/hosts | awk '{print $1}' | sed -n 1p):15010/alerts | grep -wi active" | |
KIBANA_SCRAPE_TARGET="grep log /etc/hosts | awk '{print $1}' | sed -n 1p" | |
# OpenStack Info Directories needed for $OPENSTACK_INFO_DIR | |
# ========================================================= | |
OPENSTACK_SERVERS="$OPENSTACK_INFO_DIR/openstack_servers" | |
OPENSTACK_NETWORKS="$OPENSTACK_INFO_DIR/openstack_networks" | |
OPENSTACK_VOLUMES="$OPENSTACK_INFO_DIR/openstack_volumes" | |
OPENSTACK_SERVICES="$OPENSTACK_INFO_DIR/openstack_services" | |
OPENSTACK_COMPUTE="$OPENSTACK_INFO_DIR/openstack_compute" | |
OPENSTACK_HYPERVISORS="$OPENSTACK_INFO_DIR/openstack_hypervisors" | |
OPENSTACK_IMAGES="$OPENSTACK_INFO_DIR/openstack_images" | |
OPENSTACK_PROJECTS="$OPENSTACK_INFO_DIR/openstack_projects" | |
OPENSTACK_FLAVORS="$OPENSTACK_INFO_DIR/openstack_flavors" | |
OPENSTACK_QUOTAS="$OPENSTACK_INFO_DIR/openstack_quotas" | |
OPENSTACK_REGION="$OPENSTACK_INFO_DIR/openstack_region" | |
# Make Cluster OpenStack Info Directory | |
# ===================================== | |
echo "OpenStack Version is $OPENSTACK_VERSION..." | |
# Make Directories in $SUPPORT_DUMP_DIR | |
if [ -d "$SUPPORT_DUMP_DIR" ]; then | |
# Take action if $SUPPORT_DUMP_DIR exists | |
echo "The Directry $SUPPORT_DUMP_DIR exists..." | |
echo "Check for Pre-Existing OpenStack Info..." | |
if [ -d "$OPENSTACK_INFO_DIR" ]; then | |
echo "Pre-Existing OpenStack Info $OPENSTACK_INFO_DIR Exists..." | |
else | |
echo "Pre-Existing OpenStack Info $OPENSTACK_INFO_DIR Does Not Exist..." | |
echo "Making openStack Info $OPENSTACK_INFO_DIR Sub-Directories..." | |
sudo mkdir $OPENSTACK_SERVERS $OPENSTACK_NETWORKS $OPENSTACK_VOLUMES $OPENSTACK_SERVICES $OPENSTACK_HYPERVISORS | |
sudo mkdir $OPENSTACK_IMAGES $OPENSTACK_PROJECTS $OPENSTACK_SNAPSHOTS $OPENSTACK_FLAVORS $OPENSTACK_QUOTAS | |
sudo mkdir $OPENSTACK_REGIONS $OPENSTACK_CLUSTERS $OPENSTACK_FLOATINGIPS $OPENSTACK_SECURITY_GROUPS | |
fi | |
# Check for SOSReport Availability | |
#if [ | |
# Prompt for Install and Congifuration of SOSReport Availability | |
# Run SOSReport | |
else | |
echo "Directory $SUPPORT_DUMP_DIR does not exist..." | |
echo "Making $SUPPORT_DUMP_DIR for OpenStack Info..." | |
sudo mkdir $SUPPORT_DUMP_DIR | |
if [ -d "$OPENSTACK_INFO_DIR" ]; then | |
echo "Pre-Existing OpenStack Info $OPENSTACK_INFO_DIR Exists..." | |
else | |
echo "Pre-Existing OpenStack Info $OPENSTACK_INFO_DIR Does Not Exist..." | |
echo "Making OpenStack Info $OPENSTACK_INFO_DIR Sub-Directories......" | |
sudo mkdir $OPENSTACK_SERVERS $OPENSTACK_NETWORKS $OPENSTACK_VOLUMES $OPENSTACK_SERVICES $OPENSTACK_HYPERVISORS | |
sudo mkdir $OPENSTACK_IMAGES $OPENSTACK_PROJECTS $OPENSTACK_SNAPSHOTS $OPENSTACK_FLAVORS $OPENSTACK_QUOTAS | |
sudo mkdir $OPENSTACK_REGIONS $OPENSTACK_CLUSTERS $OPENSTACK_FLOATINGIPS $OPENSTACK_SECURITY_GROUPS | |
fi | |
fi | |
$AUTHENTICATE | |
openstack --version > $OPENSTACK_INFO_DIR/openstack_version.txt | |
openstack server list --all-projects -f json > $OPENSTACK_SERVERS/openstack_servers.json | |
for i in $(openstack project list -c ID -f value); do openstack network list --project $i -f json; done > $OPENSTACK_NETWORKS/openstack_networks.json | |
openstack volume list --all-projects --long -f json > $OPENSTACK_VOLUMES/openstack_volumes.json | |
openstack service list --long -f json > $OPENSTACK_SERVICES/openstack_services.json | |
openstack compute service list -f json > $OPENSTACK_COMPUTE/openstack_compute_services.json | |
openstack image list --long -f json > $OPENSTACK_IMAGES/openstack_images.json | |
openstack project list -f json > $OPENSTACK_PROJECTS/openstack_projects.json | |
openstack flavor list --all --long -f json > $OPENSTACK_FLAVORS/openstack_flavors.json | |
openstack hypervisor list -f json > $OPENSTACK_HYPERVISORS/openstack_hypervisors.json | |
openstack quota list --compute -f json > $OPENSTACK_QUOTAS/openstack_compute_quotas.json | |
openstack quota list --network -f json > $OPENSTACK_QUOTAS/openstack_network_quotas.json | |
openstack quota list --volume -f json > $OPENSTACK_QUOTAS/openstack_volume_quotas.json | |
openstack region list -f json > $OPENSTACK_REGION/openstack_region.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment