#! /bin/bash
# script checks apache
. /usr/src/k_framework/main.sh
VERSION="1.0.0"
SCRIPT_NAME="Apache Checking"
k_start
k_config_details
CONF="/etc/httpd/conf/httpd.conf"
k_service_check httpd
k_service_check_enabled httpd
k_file_exists_check $CONF
TMPF="/tmp/apache_check.tmp"
cat $CONF | grep -A 50 "" | grep -v "#" > $TMPF
FILESIZE=$(stat -c%s "$TMPF")
if [[ $FILESIZE > 0 ]]; then
report " section found" 3
# get all active server IPs from DB
server_ips=$(MYSQL_PWD=$DB_PASSWORD /usr/bin/mysql -h "$DB_HOST" -u $DB_USERNAME "$DB_NAME" $P_OPT --silent -e "SELECT server_ip FROM servers WHERE active = 1;" | grep -v value)
# clean from \n
server_ips=$(echo $server_ips|tr -d '\n')
if [ ${#server_ips} -gt 0 ]; then
report "Found active servers with IPs [$server_ips]" 0
else
report "Not found active servers in DB. Nothing to check. Error in GUI/DB configuration?" 1
EXIT_CODE=1
fi
# make array out of string
IFS=' ' read -r -a array <<< "$server_ips"
# loop for all server IPs
for index in "${!array[@]}"; do
server_ip=${array[index]}
#report "Processing server with IP [$server_ip]" 3
if cat $TMPF | grep -q $server_ip; then
report "Server $server_ip found in section" 0
else
report "Server $server_ip not found in section" 1
EXIT_CODE=1
fi
done
else
report " not found" 3
fi
rm -fr $TMPF
k_exit $EXIT_CODE