bdambola / BD

Collection of scripts and misc info
0 stars 0 forks source link

Alert based script to verify exchange application version #1

Open bdambola opened 8 years ago

bdambola commented 8 years ago

This is an alert based script written in python along with a sub script written in shell to verify an exchange's application version across all matching engine, order book, trade manager, etc servers. The script will report a color based alert to the screen (green good, red bad).

bdambola commented 8 years ago
# Import required modules here:
import os
import commands
import subprocess

os.system("clear")
print ("\n")
version = input("Enter expected gts version: ")
print ("Expected version is: " + version)
print ("\n")

#Getting GTS version on core servers
current_version_count = commands.getoutput('./checkGtsVersionProd.sh | grep -o ' + version + ' | wc -w ')
current_version = commands.getoutput('./checkGtsVersionProd.sh | grep -v ' + version + ' | grep -v Release | grep -v 005' )
print current_version
results = int(current_version_count)
print ("\n")
#Reporting results
if (results == 231 ):
    print '\033[32m\033[1mSuccess GTS version upgraded on all ISE and Gemini servers\033[0m'
    print ("\n")
    print '\033[32m\033[1m' + current_version_count + ' servers were upgraded to version ' + version + '\033[0m'
else:
    print '\033[31m\033[1m!ALERT! GTS version not upgraded successfully on all ISE and Gemini servers\033[0m'
    print ("\n")
    print '\033[31m\033[1mOnly ' + current_version_count + ' servers were upgraded to version ' + version + '\033[0m'
bdambola commented 8 years ago
#Removing previous txt files
sudo -i rm /tmp/IseGemServers.txt
sudo -i rm /tmp/Servers.txt
#Getting ISE/Gemini servers and outputting them to a file
hostList=`/usr/local/bin/known-hosts.sh | egrep "^pc-amq|^pc-at|^pc-cpm|^pc-dd|^pc-efi|^pc-log|^pc-me|^pc-mgw|^pc-ofi|^pc-pmw|^pc-pp|^pc-sc|^pc-cdb" >> /tmp/Servers.txt`
#Removing Mercury servers and creating a file with only ISE/Gemini servers
cat /tmp/Servers.txt | egrep -v "101|102|103|104|105|106|107|108|109|110"  >> /tmp/IseGemServers.txt
for server in `cat /tmp/IseGemServers.txt` ; do
   echo ""
   ssh -t -q $server "echo 'Checking GTS version on'; hostname; gtsenv list all | cut -c1-48 | grep -v Owner"
   echo ""
done
bdambola commented 8 years ago

Added color here to distinguish between exchanges

#Setting color to distinguish between exchanges
setterm -term linux -back cyan -fore default -clear
#Removing previous txt files
sudo -i rm /tmp/MerServers.txt
sudo -i rm /tmp/Servers.txt
#Getting ISE/Gemini servers and outputting them to a file
hostList=`/usr/local/bin/known-hosts.sh | egrep "^pc-amq1|^pc-at1|^pc-cpm1|^pc-dd1|^pc-efi1|^pc-log1|^pc-me1|^pc-gwm|^pc-ofi1|^pc-pmw1|^pc-pp1|^pc-sc1|^pc-cdb1" >> /tmp/Servers.txt`
#Removing Mercury servers and creating a file with only ISE/Gemini servers
cat /tmp/Servers.txt | egrep -v "me10a|me10b|pp10a|pp10b|dd10a|dd10b|pc-at10.prod.ise.com|pc-ofi10.prod.ise.com|pc-ofi11.prod.ise.com"  >> /tmp/MerServers.txt
for server in `cat /tmp/MerServers.txt` ; do
   echo ""
   ssh -t -q $server "echo 'Checking GTS version on'; hostname; gtsenv list all | cut -c1-48 | grep -v Owner"
   echo ""
done