2015-02-06 23:06:37 +01:00
|
|
|
#! /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
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v postfix) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "postfix" '')
|
|
|
|
MSG=$(service_info "25" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
|
|
|
## FI POSTFIX
|
|
|
|
|
|
|
|
### IF APACHE2
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v apache2) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "apache2" '')
|
|
|
|
MSG=$(service_info "80 443" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
|
|
|
### FI APACHE2
|
|
|
|
|
|
|
|
### IF NGINX
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v nginx) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "nginx" '')
|
|
|
|
MSG=$(service_info "80 443" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
|
|
|
### FI NGINX
|
|
|
|
|
|
|
|
### IF MYSQLD
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v mysqld) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "mysqld" '')
|
|
|
|
MSG=$(service_info "3306" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
2015-08-29 09:23:41 +02:00
|
|
|
### FI MYSQLD
|
2015-02-06 23:06:37 +01:00
|
|
|
|
|
|
|
### IF SLAPD
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v slapd) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "slapd" '')
|
|
|
|
MSG=$(service_info "389 636" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
2015-08-29 09:23:41 +02:00
|
|
|
### FI SLAPD
|
2015-02-06 23:06:37 +01:00
|
|
|
|
|
|
|
### IF ZFS
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v zfs) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "zfs" '')
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
|
|
|
### FI ZFS
|
|
|
|
|
2015-04-20 16:20:18 +02:00
|
|
|
### IF Ceph Monitor
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v ceph) ]; then
|
2015-09-01 11:44:03 +02:00
|
|
|
# Ensure the host is define as a initial monitor
|
2015-08-29 10:01:47 +02:00
|
|
|
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
|
2015-04-20 16:20:18 +02:00
|
|
|
fi
|
|
|
|
### FI Ceph Monitor
|
|
|
|
|
2015-08-29 09:23:41 +02:00
|
|
|
### IF Ceph OSD
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v ceph) ]; then
|
2015-09-01 11:44:03 +02:00
|
|
|
# If there is a specific user
|
|
|
|
if [ -f /etc/ceph/*.keyring ]; then
|
|
|
|
for keyring in "$(find /etc/ceph -type f -name *.keyring)"; do
|
|
|
|
CEPH_USERNAME=$(grep client ${keyring} | sed 's/^\[client.\(.*\)\]/\1/')
|
|
|
|
CEPH_OSD_OK=$(ceph osd tree --id ${CEPH_USERNAME} | grep -i -- "host $(hostname)" 2> /dev/null)
|
|
|
|
if [ "${CEPH_OSD_OK}" ]; then
|
|
|
|
MSG="${MAGENTA}+++ ${WHITEB}BEGIN - ${keyring}${MAGENTA} +++${RESET}\n"
|
|
|
|
MSG=$(process_info "ceph-osd" "${MSG}")
|
|
|
|
MSG=$(service_info "6800 6801 6802" "${MSG}")
|
|
|
|
MSG="${MSG}\n${MAGENTA}+++ ${WHITEB}END - ${keyring}${MAGENTA} +++${RESET}"
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# Use default Ceph user
|
|
|
|
else
|
|
|
|
CEPH_OSD_OK=$(ceph osd tree | grep -i -- "host $(hostname)" 2> /dev/null)
|
|
|
|
if [ ${CEPH_OSD_OK} ]; then
|
|
|
|
MSG=$(process_info "ceph-osd" '')
|
|
|
|
MSG=$(service_info "6800 6801 6802" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
2015-08-29 10:01:47 +02:00
|
|
|
fi
|
2015-08-29 09:23:41 +02:00
|
|
|
fi
|
|
|
|
### FI Ceph OSD
|
2015-04-20 16:20:18 +02:00
|
|
|
|
2015-02-06 23:06:37 +01:00
|
|
|
### IF PUPPETMASTER
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v puppetmaster) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "puppetmaster" '')
|
|
|
|
MSG=$(service_info "8140" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
2015-08-29 09:23:41 +02:00
|
|
|
### IF PUPPETMASTER
|
2015-02-06 23:06:37 +01:00
|
|
|
|
|
|
|
### IF NFS Server
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v nfsd) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "nfsd" '')
|
|
|
|
MSG=$(service_info "111 2049" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
2015-08-29 09:23:41 +02:00
|
|
|
### FI NFS Server
|
2015-02-06 23:06:37 +01:00
|
|
|
|
|
|
|
### IF TFTPD
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v in.tftpd) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "in.tftpd" '')
|
|
|
|
#MSG=$(service_info "69" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
|
|
|
### FI TFTPD
|
|
|
|
|
|
|
|
### IF SQUID3
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v squid3) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "squid3" '')
|
|
|
|
MSG=$(service_info "3128" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
|
|
|
### FI SQUID3
|
|
|
|
|
|
|
|
### IF APT-CACHER-NG
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v apt-cacher-ng) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "apt-cacher-ng" '')
|
|
|
|
MSG=$(service_info "3142" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
|
|
|
### FI APT-CACHER-NG
|
|
|
|
|
|
|
|
### IF SSHD
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v sshd) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "sshd" '')
|
|
|
|
MSG=$(service_info "22" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
2015-08-29 09:23:41 +02:00
|
|
|
### FI SSHD
|
2015-02-06 23:06:37 +01:00
|
|
|
|
|
|
|
### IF DHCPD
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v dhcpd) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "dhcpd" '')
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
2015-08-29 09:23:41 +02:00
|
|
|
### FI DHCPD
|
2015-02-06 23:06:37 +01:00
|
|
|
|
|
|
|
### IF FAIL2BAN
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v fail2ban-server) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "fail2ban" '')
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
2015-08-29 09:23:41 +02:00
|
|
|
### FI FAIL2BAN
|
2015-02-06 23:06:37 +01:00
|
|
|
|
|
|
|
### IF ETHERPAD
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v etherpad) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "etherpad" '')
|
|
|
|
MSG=$(service_info "9001" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
2015-08-29 09:23:41 +02:00
|
|
|
### FI ETHERPAD
|
2015-02-06 23:06:37 +01:00
|
|
|
|
|
|
|
### IF ETHERCALC
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v ethercalc) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "ethercalc" '')
|
|
|
|
MSG=$(service_info "8000" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
2015-08-29 09:23:41 +02:00
|
|
|
### FI ETHERCALC
|
2015-02-06 23:06:37 +01:00
|
|
|
|
|
|
|
### IF GITLAB
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v gitlab-ctl) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "nginx" '')
|
|
|
|
MSG=$(service_info "80 443" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
MSG=$(process_info "gitlab" '')
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
2015-08-29 09:23:41 +02:00
|
|
|
### FI GITLAB
|
2015-02-06 23:06:37 +01:00
|
|
|
|
|
|
|
### IF XYMONSERVER
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v xymond) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "xymond" '')
|
|
|
|
MSG=$(service_info "1984" "${MSG}")
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
2015-08-29 09:23:41 +02:00
|
|
|
### FI XYMONSERVER
|
2015-02-06 23:06:37 +01:00
|
|
|
|
|
|
|
### IF XYMONCLIENT
|
2015-08-29 10:01:47 +02:00
|
|
|
if [ $(command -v xymon) ]; then
|
2015-02-06 23:06:37 +01:00
|
|
|
MSG=$(process_info "xymonlaunch" '')
|
|
|
|
printf '%b' "\n${MSG}"
|
|
|
|
fi
|
2015-08-29 09:23:41 +02:00
|
|
|
### FI XYMONCLIENT
|
2015-02-06 23:06:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
## 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}"
|