Move all Ceph tests to a file (05ceph).

This commit is contained in:
gardouille 2015-09-01 14:41:39 +02:00
parent 857cb3c57e
commit 5d404a55fc
6 changed files with 154 additions and 78 deletions

View File

@ -46,6 +46,8 @@ class dynmotd (
$auth_info_script_content = $dynmotd::params::auth_info_script_content,
$fs_info_script_name = $dynmotd::params::fs_info_script_name,
$fs_info_script_content = $dynmotd::params::fs_info_script_content,
$ceph_info_script_name = $dynmotd::params::ceph_info_script_name,
$ceph_info_script_content = $dynmotd::params::ceph_info_script_content,
$service_info_script_name = $dynmotd::params::service_info_script_name,
$service_info_script_content = $dynmotd::params::service_info_script_content,
$static_motd_path = $dynmotd::params::static_motd_path,

View File

@ -35,6 +35,11 @@ class dynmotd::install {
content => template($dynmotd::fs_info_script_content),
}
->
file { "${dynmotd::update_motd_dir_path}/${dynmotd::ceph_info_script_name}":
ensure => present,
content => template($dynmotd::ceph_info_script_content),
}
->
file { "${dynmotd::update_motd_dir_path}/${dynmotd::service_info_script_name}":
ensure => present,
content => template($dynmotd::service_info_script_content),

View File

@ -18,6 +18,8 @@ class dynmotd::params {
$auth_info_script_content = 'dynmotd/motd_auth_info.erb'
$fs_info_script_name = '04fs'
$fs_info_script_content = 'dynmotd/motd_fs_info.erb'
$ceph_info_script_name = '05ceph'
$ceph_info_script_content = 'dynmotd/motd_ceph_info.erb'
$service_info_script_name = '06service'
$service_info_script_content = 'dynmotd/motd_service_info.erb'

145
templates/motd_ceph_info.erb Executable file
View File

@ -0,0 +1,145 @@
#! /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}"
}
### IF CEPH
if [ $(command -v ceph) ]; then
# If a keyring file exists
if [ -f /etc/ceph/*.keyring ]; then
printf '%b' "${MAGENTA}++++++++++++++++++++++++ ${WHITE}Ceph${RESET} ${MAGENTA}:++++++++++++++++++++++++${RESET}"
for keyring in "$(find /etc/ceph -type f -name *.keyring)"; do
CEPH_USERNAME=$(grep client ${keyring} | sed 's/^\[client.\(.*\)\]/\1/')
# 1: test health
CEPH_HEALTH=$(ceph health --id ${CEPH_USERNAME})
CEPH_HEALTH_OK=$(ceph health --id ${CEPH_USERNAME} | grep -i -- 'health_ok')
# Determine the color to use
if [ ${CEPH_HEALTH_OK} ]; then
CEPH_COLOR=${GREEN}
else
CEPH_COLOR=${RED}
fi
# Print
printf '%b' "\n${MAGENTA}+ ${WHITEB}${keyring}: ${CEPH_COLOR}${CEPH_HEALTH}${RESET}"
# 2: test MON
# Ensure the host is define as a initial monitor
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
# 3: test OSD
CEPH_OSD_OK=$(ceph osd tree --id ${CEPH_USERNAME} | grep -i -- "host $(hostname)" 2> /dev/null)
if [ "${CEPH_OSD_OK}" ]; then
MSG=$(process_info "ceph-osd" "${MSG}")
MSG=$(service_info "6800 6801 6802" "${MSG}")
printf '%b' "\n${MSG}"
fi
# Display end message for this keyring
printf '%b' "\n${MAGENTA}++++++ ${WHITEB}END - ${keyring}${MAGENTA} ++++++${RESET}"
# Reset color
printf '%b' "${RESET}\n"
done
# Else use default
elif [ -f /etc/ceph/ceph.conf ]; then
printf '%b' "${MAGENTA}++++++++++++++++++++++++ ${WHITE}Ceph${RESET} ${MAGENTA}:++++++++++++++++++++++++${RESET}"
# 1: test health
CEPH_HEALTH=$(ceph health)
CEPH_HEALTH_OK=$(ceph health | grep -i -- 'health_ok')
# Determine the color to use
if [ ${CEPH_HEALTH_OK} ]; then
CEPH_COLOR=${GREEN}
else
CEPH_COLOR=${RED}
fi
# Print
printf '%b' "\n${MAGENTA}+ ${CEPH_COLOR}${CEPH_HEALTH}$RESET"
# 2: test MON
# Ensure the host is define as a initial monitor
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
# 3: test OSD
CEPH_OSD_OK=$(ceph osd tree --id ${CEPH_USERNAME} | grep -i -- "host $(hostname)" 2> /dev/null)
if [ "${CEPH_OSD_OK}" ]; then
MSG=$(process_info "ceph-osd" "${MSG}")
MSG=$(service_info "6800 6801 6802" "${MSG}")
printf '%b' "\n${MSG}"
# Reset color
printf '%b' "${RESET}\n"
fi
fi
fi
### FI CEPH

View File

@ -51,45 +51,5 @@ if [ $(command -v zpool) ]; then
fi
### FI ZFS
### IF CEPH
# First, test if a keyring file exists
if [ -f /etc/ceph/*.keyring ]; then
printf '%b' "\n${MAGENTA}++++++++++++++++++++++++ ${WHITEB}Ceph${RESET} ${MAGENTA}:++++++++++++++++++++++++${RESET}"
for keyring in "$(find /etc/ceph -type f -name *.keyring)"; do
CEPH_USERNAME=$(grep client ${keyring} | sed 's/^\[client.\(.*\)\]/\1/')
CEPH_HEALTH=$(ceph health --id ${CEPH_USERNAME})
CEPH_HEALTH_OK=$(ceph health --id ${CEPH_USERNAME} | grep -i -- 'ok')
# Test health to determine the color to use
if [ ${CEPH_HEALTH_OK} ]; then
CEPH_COLOR=${GREEN}
else
CEPH_COLOR=${RED}
fi
# Print
printf '%b' "\n${MAGENTA}+ ${WHITEB}${keyring}: ${CEPH_COLOR}${CEPH_HEALTH}"
done
# Else use default
elif [ -f /etc/ceph/ceph.conf ]; then
printf '%b' "\n${MAGENTA}++++++++++++++++++++++++ ${WHITEB}Ceph${RESET} ${MAGENTA}:++++++++++++++++++++++++${RESET}"
CEPH_HEALTH=$(ceph health)
CEPH_HEALTH_OK=$(ceph health | grep -i -- 'health_ok')
# Test health to determine the color to use
if [ ${CEPH_HEALTH_OK} ]; then
CEPH_COLOR=${GREEN}
else
CEPH_COLOR=${RED}
fi
# Print
printf '%b' "\n${MAGENTA}+ ${CEPH_COLOR}${CEPH_HEALTH}"
fi
### FI CEPH
printf '%b' "${RESET}\n"

View File

@ -108,44 +108,6 @@ if [ $(command -v zfs) ]; then
fi
### FI ZFS
### IF Ceph Monitor
if [ $(command -v ceph) ]; then
# Ensure the host is define as a initial monitor
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
### FI Ceph Monitor
### IF Ceph OSD
if [ $(command -v ceph) ]; then
# 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
fi
fi
### FI Ceph OSD
### IF PUPPETMASTER
if [ $(command -v puppetmaster) ]; then
MSG=$(process_info "puppetmaster" '')