#! /bin/bash autodialer_tst() { aut_tst=`cat /usr/src/mor/sh_scripts/install_configs.sh | grep -o "INSTALL_AUTO_DIALER=1"` if [ -n "$aut_tst" ]; then echo -ne "$1" if [ -r "/home/mor_ad/mor_ad_cron.log" ]; then tail -n 2 /home/mor_ad/mor_ad_cron.log | grep "Successfully connected to database." &> /dev/null if [ $? == 0 ]; then return 0 else return 1; fi else return 1; fi fi return 3; #not to execute this test } #========================================================= report() { #parameters #1 - string what are you testing + tabs #2 {"FAILED", "OK"} prints only OK or FAILED if present if [ "$?" == "0" ]; then if [ "$2" == "FAILED" ]; then return 0; fi #causes not to print [OK] blabblabla echo -e "$1\t[\E[32m OK \E[37m]"; return 0; else ALL_OK=1 if [ "$2" == "OK" ]; then return 1; fi echo -e "$1\t[\E[31m FAILED \E[37m]"; return 1; fi } #========================================================= port_check() { echo -ne "Cheking if port $1 is open" wget --post-data "port=$1" "$PORT_CHECKER_ADDRESS"/ -O /tmp/port_status &> /dev/null cat /tmp/port_status | grep "online" &> /dev/null if [ $? == 0 ]; then rm -rf /tmp/port_status return 0; elif [ $? == 1 ]; then cat /tmp/port_status | grep "offline" &> /dev/null if [ $? == 0 ]; rm -rf /tmp/port_status then return 1; else echo "Failed to connect to checking server"; fi fi } #===================FULL DUPLEX CHECK======================================= ethtool_check_eth() { #argument 1 - device. example: eth0 echo -ne "Checking for FULL DUPLEX on $1" ethtool $1 2> /dev/null | grep -o 'Duplex: Full' &> /dev/null if [ $? == 0 ]; then return 0 else return 1; fi } #=================================================================== localhost_accessibility_test() { echo -n "Checking http://127.0.0.1/billing accessibility"; wget -O /tmp/login http://127.0.0.1/billing &> /tmp/wget_out IS_ACCESSIBLE=`cat /tmp/login | grep "Please enter your Username and Password to login:"` rm -rf /tmp/login /tmp/wget_out if [ "$IS_ACCESSIBLE" != "" ]; then return 0; else return 1; fi } #===================================================================== lame_test() { echo -ne "Testing lame\t\t\t\t"; _lame=`which lame 2> /dev/null` if [ $? == 0 ]; then return 0; else return 1; fi } #===================================================================== debug_disturbers() { echo "== Connected users, who might be disturbing your further debuging by modifying configs =="; w; echo "========================================================================================="; } #===================================================================== all_files_are_downloaded() { echo -ne "Checking if all packages were downloaded" if [ -r $DOWNLOAD_LOG ]; then return 1; else return 0; fi } #======================================== rep_test() { if [ -n "$REPLICATION" ] ; then echo $REPLICATION | grep "No" &> /dev/null if [ $? == 0 ]; then return 1; fi #replication is not running echo $REPLICATION | grep "Slave_IO_Running: Yes" &> /dev/null if [ $? == 0 ]; then return 0; fi echo "Something went wrong during the test"; return 10; fi if [ -z "$REPLICATION" ] ; then return 2; fi #replication not enabled return 10; } #======================================== mysql_replication_test() { #======manually set these============ DB_HOST="localhost"; DB_USERNAME="root"; DB_PASSWORD=""; #==================================== conn=`/usr/bin/mysql -h "$DB_HOST" -u "$DB_USERNAME" --password="$DB_PASSWORD" -e "SHOW SLAVE STATUS\G" &> /dev/null` if [ $? != 0 ]; then echo "Erron encountered when connecting to database"; return 1; fi REPLICATION=`/usr/bin/mysql -h "$DB_HOST" -u "$DB_USERNAME" --password="$DB_PASSWORD" -e "SHOW SLAVE STATUS\G" | grep Slave` #==================================== rep_test if [ $? == 2 ]; then report_to_stdout 6 "Replication is not enabled\t\t\t"; return 0; fi if [ $? == 0 ]; then report_to_stdout 0 "Replication is running\t\t\t"; return 0; fi if [ $? == 1 ]; then report_to_stdout 1 "Replication is not running\t\t\t"; return 0; fi if [ $? == 10 ]; then report_to_stdout 1 "Other error\t\t\t\t\t"; return 0; fi } #======================================== client_tag_test() { grep 'CLIENT' /home/mor/config/environment.rb > /dev/null if [ "$?" == "0" ]; then return 1; elif [ "$?" == "1" ]; then return 0 else return 1; fi } #======================================== log_test.sh() { #arguments #1 - message to log #2 - {0 - success message, 1 - failure message}. If variable is not present - plain text with date only will be written to log mor_time=`date +%Y\.%-m\.%-d\-%-k\-%-M\-%-S`; if [ "$2" == "0" ]; then echo -e "[OK]\t[$mor_time]\t\t$1" >> /var/log/mor/test_sh.log return 0; elif [ "$2" == "1" ]; then echo -e "[FAILED]\t[$mor_time]\t\t$1" >> /var/log/mor/test_sh.log return 1; else echo -e "\t\t[$mor_time]\t\t$1" >> /var/log/mor/test_sh.log fi } #===== Fail2Ban === fail2ban_started() { RUNNING=`/etc/init.d/fail2ban status | head -n 1 | awk '{ print $5}'` if [ "$RUNNING" == "running..." ]; then return 0; else return 1; fi } #------------------------------------------------------------------------------ fail2ban_test() { if [ -f "/etc/fail2ban/filter.d/asterisk.conf" ] && [ -f "/etc/fail2ban/jail.conf" ] && [ -f "/etc/fail2ban/fail2ban.conf" ] && [ -f "/etc/init.d/fail2ban" ]; then fail2ban_started report "Is Fail2Ban running?\t\t\t\t\t\t\t\t\t" else echo -e "Fail2Ban is not installed \t\t\t\t\t\t[\E[31m FAILED \E[37m]"; fi } #------------------------------------------------------------------------------