#! /usr/bin/env sh ############################################################################# # # Usage: # ############################################################################# #### Colors definition BLACK='\033[30;40m' RED='\033[0;31m' REDB='\033[1;31m' GREEN='\033[1;32m' YELLOW='\033[1;33m' BLUE='\033[34;40m' MAGENTA='\033[0;35m' CYAN='\033[36;40m' WHITE='\033[0;37m' WHITEB='\033[1;37m' RESET='\033[0m' ## Return the state of processes passed in parameters # process_info $PROCESS_LIST_TO_MONITOR $MESSAGE process_info() { local PROCESS_LIST="${1}" local MSG="${2}" for PROCESS in ${PROCESS_LIST}; do MSG="${MSG}${MAGENTA}+ " if (ps ax | grep -v grep | grep ${PROCESS} > /dev/null); then MSG="${MSG}${WHITEB}${PROCESS}${RESET} [ ${GREEN}RUNNING${RESET} ] " else MSG="${MSG}${WHITEB}${PROCESS}${RESET} [ ${REDB}NOT RUNNING${RESET} ] " fi done printf '%b' "${MSG}" } ## Return the listening socket # service_info $PORT_LIST_TO_MONITOR $MESSAGE service_info() { local PORT_LIST="${1}" local MSG="${2}" for PORT in ${PORT_LIST}; do MSG="${MSG}${MAGENTA}+ " # If a port listen if (ss -lutn|grep -m1 ":${PORT}" > /dev/null); then # Example: "tcp/127.0.0.1:25" #MSG="${MSG}${GREEN}$(ss -lutn|grep -m1 ":${PORT}"|awk '{print $1"/"$5}')${RESET} " MSG="${MSG}${GREEN}$(ss -lutn|grep ${PORT}|sort|head -n1|awk '{print $1"/"$5}')${RESET} " else # Example: "22: NOT LISTENING" MSG="${MSG}${REDB}${PORT}: NOT LISTENING${RESET} " fi done printf '%b' "${MSG}" } printf '%b' "${MAGENTA}+++++++++++++++++++: ${WHITE}Service Info${MAGENTA} :++++++++++++++++++++${RESET}" ## IF POSTFIX if [ $(which postfix) ]; then MSG=$(process_info "postfix" '') MSG=$(service_info "25" "${MSG}") printf '%b' "\n${MSG}" fi ## FI POSTFIX ### IF APACHE2 if [ $(which apache2) ]; then MSG=$(process_info "apache2" '') MSG=$(service_info "80 443" "${MSG}") printf '%b' "\n${MSG}" fi ### FI APACHE2 ### IF NGINX if [ $(which nginx) ]; then MSG=$(process_info "nginx" '') MSG=$(service_info "80 443" "${MSG}") printf '%b' "\n${MSG}" fi ### FI NGINX ### IF MYSQLD if [ $(which mysqld) ]; then MSG=$(process_info "mysqld" '') MSG=$(service_info "3306" "${MSG}") printf '%b' "\n${MSG}" fi ### IF MYSQLD ### IF SLAPD if [ $(which slapd) ]; then MSG=$(process_info "slapd" '') MSG=$(service_info "389 636" "${MSG}") printf '%b' "\n${MSG}" fi ### IF SLAPD ### IF ZFS if [ $(which zfs) ]; then MSG=$(process_info "zfs" '') printf '%b' "\n${MSG}" fi ### FI ZFS ### IF Ceph Monitor ## ceph-mon is installed with the 'ceph' package # so we can't just check if `ceph-mon` is available on a system if (grep "mon_initial_members.*$(hostname)" /etc/ceph/*.conf > /dev/null); then MSG=$(process_info "ceph-mon" '') MSG=$(service_info "6789" "${MSG}") printf '%b' "\n${MSG}" fi ### FI Ceph Monitor ### IF PUPPETMASTER if [ $(which puppetmaster) ]; then MSG=$(process_info "puppetmaster" '') MSG=$(service_info "8140" "${MSG}") printf '%b' "\n${MSG}" fi ### IF SLAPD ### IF NFS Server if [ $(which nfsd) ]; then MSG=$(process_info "nfsd" '') MSG=$(service_info "111 2049" "${MSG}") printf '%b' "\n${MSG}" fi ### IF SLAPD ### IF TFTPD if [ $(which in.tftpd) ]; then MSG=$(process_info "in.tftpd" '') #MSG=$(service_info "69" "${MSG}") printf '%b' "\n${MSG}" fi ### FI TFTPD ### IF SQUID3 if [ $(which squid3) ]; then MSG=$(process_info "squid3" '') MSG=$(service_info "3128" "${MSG}") printf '%b' "\n${MSG}" fi ### FI SQUID3 ### IF APT-CACHER-NG if [ $(which apt-cacher-ng) ]; then MSG=$(process_info "apt-cacher-ng" '') MSG=$(service_info "3142" "${MSG}") printf '%b' "\n${MSG}" fi ### FI APT-CACHER-NG ### IF SSHD if [ $(which sshd) ]; then MSG=$(process_info "sshd" '') MSG=$(service_info "22" "${MSG}") printf '%b' "\n${MSG}" fi ### FI SSH ### IF DHCPD if [ $(which dhcpd) ]; then MSG=$(process_info "dhcpd" '') printf '%b' "\n${MSG}" fi ### IF DHCPD ### IF FAIL2BAN if [ $(which fail2ban-server) ]; then MSG=$(process_info "fail2ban" '') printf '%b' "\n${MSG}" fi ### IF FAIL2BAN ### IF ETHERPAD if [ $(which etherpad) ]; then MSG=$(process_info "etherpad" '') MSG=$(service_info "9001" "${MSG}") printf '%b' "\n${MSG}" fi ### IF ETHERPAD ### IF ETHERCALC if [ $(which ethercalc) ]; then MSG=$(process_info "ethercalc" '') MSG=$(service_info "8000" "${MSG}") printf '%b' "\n${MSG}" fi ### IF ETHERCALC ### IF GITLAB if [ $(which gitlab-ctl) ]; then MSG=$(process_info "nginx" '') MSG=$(service_info "80 443" "${MSG}") printf '%b' "\n${MSG}" MSG=$(process_info "gitlab" '') printf '%b' "\n${MSG}" fi ### IF GITLAB ### IF XYMONSERVER if [ $(which xymond) ]; then MSG=$(process_info "xymond" '') MSG=$(service_info "1984" "${MSG}") printf '%b' "\n${MSG}" fi ### IF XYMONSERVER ### IF XYMONCLIENT if [ $(which xymon) ]; then MSG=$(process_info "xymonlaunch" '') printf '%b' "\n${MSG}" fi ### IF XYMONCLIENT ## Service need a warning if running YELLOW_SERVICE='tmux screen glances htop automysqlbackup vzdump puppet aptitude' for SERVICE in ${YELLOW_SERVICE}; do if (ps ax | grep -v grep | grep ${SERVICE} > /dev/null); then printf '%b' "\n${MAGENTA}+ ${WHITEB}${SERVICE}${RESET} [ ${YELLOW}RUNNING${RESET} ]" fi done printf '%b' "${RESET}\n" #echo -e "${MAGENTA}+++++++++++++: ${RED}Maintenance Information${MAGENTA} :+++++++++++++++${RESET} #${MAGENTA}+${RED}"" #echo -e "${MAGENTA}+++++++++++++++++++++++++++++++++++++++++++++++++++++++${RESET}"