Extract Information For Prerequisites
Extract information about the host and checks for the prerequisites
Pre-check Script:
K2 On-Premises Script for Prerequisites Checks
Extract information about the host and checks for the prerequisites.
Save below script as
on-prem-check.sh
###############################################################################
# Copyright (C) 2018 - K2 Cyber Security, Inc. All rights reserved.
# This software is proprietary information of K2 Cyber Security, Inc and
# constitutes valuable trade secrets of K2 Cyber Security, Inc. You shall
# not disclose this information and shall use it only in accordance with the
# terms of License.
# K2 CYBER SECURITY, INC MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
# SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
# NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE, OR NON-INFRINGEMENT. K2 CYBER SECURITY, INC SHALL
# NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
# MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
# "K2 Cyber Security, Inc"
################################################################################
#!/bin/bash
NONE='\033[00m'
GREEN='\033[01;32m'
RED='\033[01;31m'
CYAN='\033[01;36m'
YELLOW='\033[01;33m'
UNDERLINE='\033[4m'
PASS="${GREEN}PASS${NONE}"
FAIL="${RED}FAIL${NONE}"
WARN="${YELLOW}WARN${NONE}"
PRESENT="${YELLOW}PRESENT${NONE}"
NOTPRESENT="${GREEN}NOT PRESENT${NONE}"
# Set ENV for systemd service
export XDG_RUNTIME_DIR=/run/user/$(id -u)
# Installation location to check the allocated space
if [ "$1" == "" ]; then
installation_location="/"
else
installation_location=$1
fi
# Utility Methods
numCompare() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" == "$1";
}
distribution_check=${PASS}
kernel_version=$(uname -r)
distribution=$(cat /etc/os-release | grep -w NAME | awk -F= '{print $2}' | tr -d '"')
if [ "${distribution}" == "CentOS Linux" ]; then
version_id=$(cat /etc/centos-release | head -1 | sed 's/[^0-9\.]//g')
else
version_id=$(cat /etc/os-release | grep -w VERSION_ID | awk -F= '{print $2}' | tr -d '"')
fi
if [[ -z ${distribution} ]]; then
distribution=$(cat /etc/*release | head -1 | awk -F' ' '{print $1}' | tr -d '"')
version_id=$(cat /etc/*release | head -1 | awk -F' ' '{print $3}' | tr -d '"')
fi
if [ "${distribution}" != "CentOS Linux" -a "${distribution}" == "Red Hat Enterprise Linux Server" -a "${distribution}" == "Red Hat Enterprise Linux" ]; then
distribution_check=${FAIL}
else
distribution_check=${PASS}
fi
# Check if docker is installed
docker_version=$(docker --version 2>&1)
if [ $? -eq 0 ]; then
docker_check=${PASS}
else
if [[ "${docker_version}" =~ "command not found" ]]; then
docker_version="NA"
docker_check=${FAIL}
docker_reason="Command not found"
fi
fi
docker_access=$(docker ps 2>&1)
if [[ "${docker_access}" =~ "permission denied" ]]; then
docker_access_check=${FAIL}
docker_reason="Permission Denied"
else
docker_access_check=${PASS}
docker_storage_dir=$(docker info | grep "Docker Root Dir" | awk -F':' '{print $2}' | tr -d ' ')
docker_storage_dir_space_kb=$(df -k ${docker_storage_dir} | awk -F' ' 'NR==2{ print $4}')
docker_storage_dir_space=$(echo "${docker_storage_dir_space_kb} 1048576" | awk '{ printf "%.2f", $1/$2}')
fi
# Check if user systemd service is available
service_check=${PASS}
init_symlink=$(ls -l /sbin/init | grep systemd | wc -l)
if [[ -d "/usr/lib/systemd" && ${init_symlink} -eq 1 ]]; then
init_system="systemd"
# echo "Detected a systemd init system"
init_flag=0
systemd_permission_check=$(systemctl --user status --no-page 2>&1 | grep -i "Permission denied" | wc -l)
if [ ${systemd_permission_check} -eq 1 ]; then
init_flag=1
service_reason="Permission Denied!!!"
service_remark="Please follow the instructions on K2 Installation UI to setup the same."
service_check="${RED}FAIL${NONE}"
fi
systemd_user_check=$(systemctl --user status --no-page 2>&1 | grep -i "No such file or directory" | wc -l)
if [[ ( ${systemd_user_check} -eq 1 ) && ( ${init_flag} -eq 0 ) ]]; then
service_reason="User management systemd service not present"
service_remark="Please follow the instructions on K2 Installation UI to setup the same."
service_check="${RED}FAIL${NONE}"
fi
systemd_user_generic_check=$(systemctl --user status --no-page 2>&1 | grep -i "connection refused" | wc -l)
if [[ ( ${systemd_user_generic_check} -eq 1 ) && ( ${init_flag} -eq 0 ) ]]; then
service_reason="User management systemd service not present"
service_remark="Please follow the instructions on K2 Installation UI to setup the same."
service_check="${RED}FAIL${NONE}"
fi
fi
# Memory Check
memory_check=${PASS}
free_memory_in_kb=$(cat /proc/meminfo | grep "MemAvailable:" | awk -F' ' '{print $2}')
free_memory_in_gb=$(echo "${free_memory_in_kb} 1048576" | awk '{ printf "%.2f", $1/$2}')
# Check if its lower than the required value
if numCompare "${free_memory_in_gb}" "7.99" ; then
memory_check="${RED}FAIL${NONE}"
elif numCompare "${free_memory_in_gb}" "15.99" ; then
memory_check="${YELLOW}WARN${NONE}"
fi
# Disk Space Check
disk_space_check=${PASS}
available_disk_in_kb=$(df -k ${installation_location} | awk -F' ' 'NR==2{ print $4}')
available_disk_in_gb=$(echo "${available_disk_in_kb} 1048576" | awk '{ printf "%.2f", $1/$2}')
# Check if its lower than the required value
if numCompare "${available_disk_in_gb}" "29.99" ; then
disk_space_check="${RED}FAIL${NONE}"
elif numCompare "${available_disk_in_gb}" "39.99" ; then
disk_space_check="${YELLOW}WARN${NONE}"
fi
# Extract number of cores
num_of_cores=$(lscpu | grep -w "CPU(s):" | grep -v "NUMA" | awk -F':' '{print $2}' | tr -d ' ')
# Extract Glibc version
glibc_version=$(ldd --version | grep libc)
# Conflicting utilites check
# Check the presence of the following utilities
# Python Check
count=0
python_version=$(python3 --version 2>&1)
if [ $? -eq 0 ]; then
python_check=${PRESENT}
count=$(( count + 1 ))
else
if [[ "${python_version}" =~ "command not found" ]]; then
python_version="NA"
python_check=${NOTPRESENT}
python_reason="Command not found"
fi
fi
# Java Check
java_version=$(java -version 2>&1)
if [ $? -eq 0 ]; then
java_check=${PRESENT}
count=$(( count + 1 ))
else
if [[ "${java_version}" =~ "command not found" ]]; then
java_version="NA"
java_check=${NOTPRESENT}
java_reason="Command not found"
fi
fi
# Ansible Check
ansible_version=$(ansible --version 2>&1)
if [ $? -eq 0 ]; then
ansible_check=${PRESENT}
count=$(( count + 1 ))
else
if [[ "${ansible_version}" =~ "command not found" ]]; then
ansible_version="NA"
ansible_check=${NOTPRESENT}
ansible_reason="Command not found"
fi
fi
# Mongo Check
mongo_version=$(mongo --version 2>&1)
if [ $? -eq 0 ]; then
mongo_check=${PRESENT}
count=$(( count + 1 ))
else
if [[ "${mongo_version}" =~ "command not found" ]]; then
mongo_version="NA"
mongo_check=${NOTPRESENT}
mongo_reason="Command not found"
fi
fi
# HAProxy Check
haproxy_version=$(haproxy -v 2>&1)
if [ $? -eq 0 ]; then
haproxy_check=${PRESENT}
count=$(( count + 1 ))
else
if [[ "${haproxy_version}" =~ "command not found" ]]; then
haproxy_version="NA"
haproxy_check=${NOTPRESENT}
haproxy_reason="Command not found"
fi
fi
# Perl
perl_version=$(perl -v 2>&1)
if [ $? -eq 0 ]; then
perl_check=${PRESENT}
count=$(( count + 1 ))
else
if [[ "${perl_version}" =~ "command not found" ]]; then
perl_version="NA"
perl_check=${NOTPRESENT}
perl_reason="Command not found"
fi
fi
printf "\n${YELLOW}Detected a $distribution operating system running on your machine with following configuration:${NONE}"
printf "\nStatus: ${distribution_check}"
printf "\nDistribution name: ${distribution}"
printf "\nVersion ID: ${version_id}"
printf "\nKernel Version: ${kernel_version}"
printf "\nCPU Cores: ${num_of_cores}"
printf "\nGlibc Version: ${glibc_version}"
printf "\n\n${YELLOW}Memory${NONE}"
printf "\nStatus: ${memory_check}"
printf "\nAvailable: ${free_memory_in_gb}"
printf "\n\n${YELLOW}Disk Space${NONE}"
printf "\nStatus: ${disk_space_check}"
printf "\nAvailable: ${available_disk_in_gb} (Location: ${installation_location})"
printf "\n\n${YELLOW}Docker Check${NONE}"
printf "\nInstallation: ${docker_check}"
printf "\nPermission: ${docker_access_check}"
printf "\nVersion: ${docker_version}"
printf "\nStorage Location: ${docker_storage_dir}"
printf "\nAvailable disk space at Storage Location: ${docker_storage_dir_space}"
printf "\n\n${YELLOW}User systemd Service${NONE}"
printf "\nStatus: ${service_check}"
printf "\nReason: ${service_reason}"
printf "\nRemark: ${service_remark}"
printf "\n\n${YELLOW}Conflicting Utilities Check${NONE}"
printf "\nCount: ${count}"
if [ ${count} -gt 0 ]; then
printf "\n\n${YELLOW}Java${NONE}"
printf "\nVersion: ${java_version}"
printf "\nStatus: ${java_check}"
printf "\nReason: ${java_reason}"
printf "\n\n${YELLOW}Python${NONE}"
printf "\nVersion: ${python_version}"
printf "\nStatus: ${python_check}"
printf "\nReason: ${python_reason}"
printf "\n\n${YELLOW}Ansible${NONE}"
printf "\nVersion: ${ansible_version}"
printf "\nStatus: ${ansible_check}"
printf "\nReason: ${ansible_reason}"
printf "\n\n${YELLOW}Mongo${NONE}"
printf "\nVersion: ${mongo_version}"
printf "\nStatus: ${mongo_check}"
printf "\nReason: ${mongo_reason}"
printf "\n\n${YELLOW}HAProxy${NONE}"
printf "\nVersion: ${haproxy_version}"
printf "\nStatus: ${haproxy_check}"
printf "\nReason: ${haproxy_reason}"
printf "\n\n${YELLOW}Perl${NONE}"
printf "\nVersion: ${perl_version}"
printf "\nStatus: ${perl_check}"
printf "\nReason: ${perl_reason}"
fi
printf "\n"
# Extracting packages installed on the host
rpm -qa > rpm_list.txt
Running the script
bash on-prem-check.sh [installation_directory] 2>&1 | tee -a on-prem-check-output.txt
Last updated
Was this helpful?