#!/bin/bash ######################################################################### # Script for show all FAN status # # Created by PM-DoIT # # ver 0.2 # ######################################################################### #----------------------------- VARIABLES -------------------------------# YOURMAIL="info@doit.sk" CPUT="50" #---------------------------- CREDENTIALS ------------------------------# source /home/.credentials test -f /home/.credentials || echo -e "- \e[1;31mMissing\e[0m credentials source" test -f /home/.credentials || exit 1 #----------------------------- CATEGORY --------------------------------# CAT="ILO" #------------------------------ TEMP -----------------------------------# STARTTIME=$(date +%s) TMP=/tmp/fanall.tmp LOG=/tmp/fanall.log TXT=/tmp/fanall.txt REP=/tmp/fanall.rep SOG=/tmp/fanall.srv EMA=/tmp/fanall.mail WEB=/opt/librenms/html/admin/ilo DOMAINPATH="/etc/hosts" test -d $WEB || mkdir $WEB rm -rf /tmp/fanall* #--------------------------- PING CHECK --------------------------------# checkping(){ if [ "$READSITE" = "ALL" ]; then READSITE=$CAT; fi cat $DOMAINPATH | sort | uniq | egrep "$READSITE" | egrep -w $CAT | awk '{print $2}' | sort | uniq | while read output do ping -c 1 -n -i 0.2 -W1 "$output" > /dev/null if [ $? -eq 0 ]; then echo "$output" >> $TMP else echo -e "* $output is \e[1;31mDOWN\e[0m" fi done test -f $TMP || echo -e "! Devices \e[1;31mNOT\e[0m exist in LIST definition" test -f $TMP || exit 1 } #---------------------------- FEATURE CHECK ----------------------------# checksens(){ rm -rf $REP echo -e "\e[1;37mHOSTNAME MODEL FAN OPERATIONAL SPEED(%) HEALTH\e[0m" > $REP echo "----------------- ------------ ---- ----------- -------- ------" >> $REP echo -e "- \e[1;32mExtracting\e[0m ILO [\e[1;33mfan\e[0m] status:" for i in `cat $TMP | sed -r 's/\s+//g'` do echo -e "* \e[1;33m$i\e[0m" rm -rf $LOG rm -rf /tmp/fanall.srv sshpass -p $EPAS timeout 20 ssh -o "UserKnownHostsFile=/dev/null" -o StrictHostKeyChecking=no -o ConnectTimeout=10 Administrator@${i} 2> /dev/null "show system1" > $SOG dos2unix $SOG 2> /dev/null SRV=$(cat $SOG | grep -v oem | grep name | awk '{print $2"-"$3}') FAN=$(cat $SOG | grep fan | awk '{print $1}') for FN in $FAN; do FN="$FN" sshpass -p $EPAS timeout 20 ssh -o "UserKnownHostsFile=/dev/null" -o StrictHostKeyChecking=no -o ConnectTimeout=10 Administrator@${i} 2> /dev/null "show system1/$FN" > $LOG dos2unix $LOG 2> /dev/null MOD=$(cat $LOG | grep -i "system1" | grep -v show | sed 's/\// /g' | awk '{print $2}') VAL=$(cat $LOG | grep -i "DesiredSpeed" | sed 's/=/ /g' | awk '{print $2}') STA=$(cat $LOG | grep -i "OperationalStatus" | sed 's/=/ /g' | awk '{print $2}') HEA=$(cat $LOG | grep -i "HealthState" | sed 's/=/ /g' | awk '{print $2}') echo "$i $SRV $MOD $STA $VAL $HEA" > $TXT cat $TXT >> $REP done done } #---------------------------- WEB REPORT -------------------------------# webstart(){ cat > $WEB/index.html <<\EOF [SITE] ILO-FAN

ILO FAN Status

FANs [NUM] on [SNM] servers | Last update: DATE

EOF } webend(){ cat >> $WEB/index.html <<\EOF
Hostname Model Fan Operational Speed (%) Health
EOF NUM=$(cat $REP | egrep -v "HOSTNAME|---" | grep -i Fan | wc -l) SNM=$(cat $REP | egrep -v "HOSTNAME|---" | awk '{print $1}'| sort | uniq | wc -l) SITE=$(hostname -s | sed 's/-/ /g' | awk '{print $1}') sed -i "s/NUM/$NUM/g" $WEB/index.html sed -i "s/SNM/$SNM/g" $WEB/index.html sed -i "s/DATE/`date`/g" $WEB/index.html sed -i "s/SITE/$SITE/g" $WEB/index.html } webbody(){ echo "------------------------------------------------------------------------------" echo -e "- \e[1;32mGenerating\e[0m webpage location" ZR=$(cat $REP | sort | egrep "ILO" | awk '{print $1}' | uniq) for z in $ZR; do IR=$(cat $REP | sort | grep $z | awk '{print $3}' | uniq) for i in $IR; do DHS=$(cat $REP | grep $z | grep $i | awk '{print $1}') MOD=$(cat $REP | grep $z | grep $i | awk '{print $2}') DID=$(cat $REP | grep $z | grep $i | awk '{print $4}') DCP=$(cat $REP | grep $z | grep $i | awk '{print $5}') DRA=$(cat $REP | grep $z | grep $i | awk '{print $6}') echo "" >> $WEB/index.html if [[ "$DID" != "Ok" ]] || [[ "$DRA" != "Ok" ]] || [[ "$DCP" -gt "$CPUT" ]]; then echo " $DHS" >> $WEB/index.html else echo " $DHS" >> $WEB/index.html fi echo " $MOD" >> $WEB/index.html echo " $i" >> $WEB/index.html if [[ "$DID" != "Ok" ]]; then echo " $DID" >> $WEB/index.html else echo " $DID" >> $WEB/index.html fi if [[ "$DCP" -gt "$CPUT" ]]; then echo " $DCP %" >> $WEB/index.html else echo " $DCP %" >> $WEB/index.html fi if [[ "$DRA" != "Ok" ]]; then echo " $DRA" >> $WEB/index.html else echo " $DRA" >> $WEB/index.html fi echo "" >> $WEB/index.html done echo "" >> $WEB/index.html done } #---------------------------- STATISTIC --------------------------------# notify(){ NOTI=$(cat $REP | egrep -vw "Ok|HEALTH|------") if [ -z $NOTI ]; then echo -e "- \e[1;32mNot\e[0m find [\e[1;33mfan\e[0m] issue" else echo -e "- \e[1;31mFind\e[0m [\e[1;33mfan\e[0m] issue" $NOTI > $EMA mutt -s "FAN issue - Notifikacia" "$YOURMAIL" <$EMA fi } #---------------------------- STATISTIC --------------------------------# stat(){ ENDTIME=$(date +%s) RUNTIME=$(($ENDTIME - $STARTTIME)) echo "------------------------------------------------------------------------------" echo -e "- Executing of the script was: (\e[1;33m$RUNTIME\e[0m sec)" echo "==============================================================================" cat $REP | column -t echo "==============================================================================" echo -e "- LOG file [\e[1;34m$REP\e[0m]" echo "==============================================================================" } #------------------------------- CORE ----------------------------------# clear checkping checksens webstart webbody webend notify stat