#!/bin/sh echo $0 $* | /usr/bin/ts '[%Y-%m-%d %H:%M:%S]' # RootDir=/home/oleg/develop/cvtt2 RootDir="${HOME}/prod" export PYTHONPATH=${RootDir} # Temporary MmStatusSender= MmStatusSender="${MmStatusSender} ${HOME}/.pyenv/python3.10-venv/bin/python3" MmStatusSender="${MmStatusSender} ${RootDir}/cvttpy/apps/utils/mmost_sender.py" MmStatusSender="${MmStatusSender} --channel=Status-CVTT" MmStatusSender="${MmStatusSender} --log_level=ERROR" MmAlertSender= MmAlertSender="${MmAlertSender} ${HOME}/.pyenv/python3.10-venv/bin/python3" MmAlertSender="${MmAlertSender} ${RootDir}/cvttpy/apps/utils/mmost_sender.py" MmAlertSender="${MmAlertSender} --channel=Alerts-CVTT" MmAlertSender="${MmAlertSender} --log_level=ERROR" Hosts= Hosts="${Hosts} cloud11.cvtt.vpn" Hosts="${Hosts} cloud14.cvtt.vpn" Hosts="${Hosts} cloud15.cvtt.vpn" Hosts="${Hosts} cloud16.cvtt.vpn" Hosts="${Hosts} cloud17.cvtt.vpn" Hosts="${Hosts} cloud19.cvtt.vpn" Hosts="${Hosts} cloudstore.cvtt.vpn" Hosts="${Hosts} cvttdata.cvtt.vpn" Hosts="${Hosts} cryptoval1.cvtt.vpn" Hosts="${Hosts} cryptoval2.cvtt.vpn" Hosts="${Hosts} cryptoval3.cvtt.vpn" Hosts="${Hosts} homestore.cvtt.vpn" Hosts="${Hosts} nsbackup.cvtt.vpn" Hosts="${Hosts} dtvmhost.cvtt.vpn" Hosts="${Hosts} ops-server.cvtt.vpn" function space_alert() { ALERT_USAGE=75% for ln in "${Measurements[@]}" do IFS=$' '; args=($ln); unset IFS host=${args[0]} fs=${args[1]} space_used=${args[2]} if [ ${space_used%?} -ge ${ALERT_USAGE%?} ]; then echo ":red_circle: Filesystem **${host}:${fs}** is using **${space_used}** :red_circle:" fi done } function storage_check() { echo "## :card_file_box: STORAGE HEALTH CHECK" echo echo "| host | filesystem | usage |" echo "| --- | --- | --- |" for host in ${Hosts} do Cmd="ssh $host" Cmd="${Cmd} eval \"df -hTl" Cmd="${Cmd} -x squashfs" Cmd="${Cmd} | grep -v tmpfs" Cmd="${Cmd} | grep -v Filesystem\"" IFS=$'\n' ; lines=$(eval ${Cmd}) for ln in $lines do IFS=$' '; args=($ln); unset IFS echo "| **${host}** | ***${args[6]}*** | *${args[5]}* |" Measurements+=("${host} ${args[6]} ${args[5]}") done unset IFS echo "| | | |" done } Measurements=() tmpfile=$(mktemp) storage_check > ${tmpfile} cat ${tmpfile} | ${MmStatusSender} tmpfile=$(mktemp) space_alert > ${tmpfile} cat ${tmpfile} if [ -s ${tmpfile} ] then (echo "### :card_file_box: STORAGE ALERTS" && cat ${tmpfile}) | ${MmAlertSender} else echo File ${tmpfile} is empty fi rm ${tmpfile}