new
This commit is contained in:
28
.gitignore
vendored
Normal file
28
.gitignore
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# ---> macOS
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
173
dsmon.sh
Executable file
173
dsmon.sh
Executable file
@@ -0,0 +1,173 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# powerwall - CLI commands to control VM guest power
|
||||||
|
|
||||||
|
source /opt/idssys/defaults/colors.inc
|
||||||
|
source /opt/idssys/defaults/default.inc
|
||||||
|
source /opt/idssys/dsmon/config.settings.inc
|
||||||
|
|
||||||
|
action="$1"
|
||||||
|
|
||||||
|
RUN(){
|
||||||
|
if [ "${SERVERMON_ID}" != "" ]; then
|
||||||
|
|
||||||
|
if [ "${1}" = "hdd" ]; then
|
||||||
|
DRIVEINFO=`df -BM | grep -vE '^Filesystem|tmpfs|cdrom|@|ram|loop|udev|veeamimage' | awk '{ print $1 " " $2 " " $4 }'`
|
||||||
|
DRIVEINFO=(${DRIVEINFO})
|
||||||
|
NUMDRIVES=$((${#DRIVEINFO[@]} / 3))
|
||||||
|
|
||||||
|
DRIVE_INFO=()
|
||||||
|
|
||||||
|
for ((i = 0 ; i <= $((${NUMDRIVES}-1)) ; i++)); do
|
||||||
|
ii=$((${i}*3))
|
||||||
|
ia=${DRIVEINFO[${ii}]}
|
||||||
|
ib=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+1))]//M/}/1024")
|
||||||
|
ic=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+2))]//M/}/1024")
|
||||||
|
ia=${ia//\/dev\/mapper\//}
|
||||||
|
ia=${ia//\/dev\//}
|
||||||
|
|
||||||
|
if [ "${ia}" = "sda1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
|
||||||
|
systempartition=true
|
||||||
|
elif [ "${ia}" = "sda2" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
|
||||||
|
systempartition=true
|
||||||
|
elif [ "${ia}" = "shm" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
|
||||||
|
systempartition=true
|
||||||
|
elif [ "${ia}" = "nvme0n1p1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
|
||||||
|
systempartition=true
|
||||||
|
elif [ "${ia}" = "mmcblk0p1" ] && [ ${DRIVEINFO[$((${ii}+1))]//M/} -lt 1024 ]; then
|
||||||
|
systempartition=true
|
||||||
|
elif [ "${ia}" != "overlay" ]; then
|
||||||
|
#echo "${ia};${ib};${ic}"
|
||||||
|
DRIVE_INFO+=("${ia};${ib};${ic}")
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
QRY="USE servermonitor; INSERT INTO sysinfo (\`host\`, \`entry\`, \`value\`) VALUES ('${SERVERMON_ID}','hdd','${DRIVE_INFO[@]}');"
|
||||||
|
MYSQL_PWD="sysmoninsert" mysql -h mysqldb.scity.us -P 6033 -u sysmoninsert -e "${QRY}"
|
||||||
|
|
||||||
|
elif [ "${1}" = "sys" ]; then
|
||||||
|
|
||||||
|
MEMORY=$(free -m | awk 'NR==2{printf "%.2f\t\t", $3*100/$2 }')
|
||||||
|
CPU=$(top -bn1 | grep load | awk '{printf "%.2f\t\t\n", $(NF-2)}')
|
||||||
|
QRY="USE servermonitor; INSERT INTO sysinfo (\`host\`, \`entry\`, \`value\`) VALUES ('${SERVERMON_ID}','sys','${CPU// /};${MEMORY}');"
|
||||||
|
MYSQL_PWD="sysmoninsert" mysql -h mysqldb.scity.us -P 3306 -u sysmoninsert -e "${QRY}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
SERVERHOSTNAME=(`hostname`)
|
||||||
|
SERVERIP=(`hostname -I`)
|
||||||
|
SERVERIPS=''
|
||||||
|
for nip in "${SERVERIP[@]}"; do
|
||||||
|
if [[ "${nip}" == *"."* ]]; then
|
||||||
|
if [ "${SERVERIPS}" = "" ]; then
|
||||||
|
SERVERIPS=${nip}
|
||||||
|
else
|
||||||
|
SERVERIPS=${SERVERIPS}";"${nip}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
thresholdlog=()
|
||||||
|
for KEY in "${!THRESHOLD[@]}"; do
|
||||||
|
thresholdlog+=("${KEY}:${THRESHOLD[$KEY]}")
|
||||||
|
done
|
||||||
|
|
||||||
|
QRY="USE servermonitor; UPDATE hosts SET ip='${SERVERIPS// /}',hostname='${SERVERHOSTNAME}',limits='${thresholdlog[@]}' WHERE id='${SERVERMON_ID}';"
|
||||||
|
mysql -h mysqldb.scity.us -P 3306 --user=sysmoninsert --password=sysmoninsert -e "${QRY}"
|
||||||
|
|
||||||
|
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(){
|
||||||
|
|
||||||
|
declare -A host_ip
|
||||||
|
declare -A host_name
|
||||||
|
declare -A host_limits
|
||||||
|
|
||||||
|
while read hostid hostname hostip hostlimits; do
|
||||||
|
if [ "$hostid" != "id" ]; then
|
||||||
|
hostip=$(echo $hostip | cut -d ";" -f1)
|
||||||
|
# echo "$hostid - $hostip - $hostname - $hostlimits"
|
||||||
|
host_ip[${hostid}]=$hostip
|
||||||
|
host_name[${hostid}]=$hostname
|
||||||
|
host_limits[${hostid}]=$hostlimits
|
||||||
|
fi
|
||||||
|
done <<< $(MYSQL_PWD="sysmoninsert" mysql -h mysqldb.scity.us -P 3306 -u sysmoninsert -e "SELECT id,host,ip,limits FROM servermonitor.hosts")
|
||||||
|
|
||||||
|
for hostid in "${!host_ip[@]}"; do
|
||||||
|
echo -e "${idsST[Bold]}"; DIVIDER
|
||||||
|
echo -e "${idsCL[LightCyan]} ${host_name[$hostid]} - Drive Space Check${idsCL[Default]}"
|
||||||
|
DIVIDER; echo -e "${idsST[Reset]}"
|
||||||
|
|
||||||
|
checkhost=$(CHECK_HOST ${host_ip[$hostid]})
|
||||||
|
if [ "${checkhost}" != "false" ]; then
|
||||||
|
DRIVEINFO=$(ssh root@${host_ip[$hostid]} df -BM | grep -vE '^Filesystem|tmpfs|cdrom|@|ram|loop|udev|veeamimage|nvme|localhost|sda|sdb|shm|mmcblk|overlay|-volume|Music|media-data|Software' | awk '{ print $1 " " $2 " " $4 }')
|
||||||
|
DRIVEINFO=(${DRIVEINFO})
|
||||||
|
NUMDRIVES=$((${#DRIVEINFO[@]} / 3))
|
||||||
|
|
||||||
|
for ((i = 0 ; i <= $((${NUMDRIVES}-1)) ; i++)); do
|
||||||
|
ii=$((${i}*3))
|
||||||
|
dname=${DRIVEINFO[${ii}]}
|
||||||
|
dtot=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+1))]}/1024/10")
|
||||||
|
dfree=$(bc <<< "scale=2; ${DRIVEINFO[$((${ii}+2))]}/1024/10")
|
||||||
|
dfreeper=$(bc <<< "scale=2; (${dfree}/${dtot})*100")
|
||||||
|
dname=${ia//\/dev\/mapper\//}
|
||||||
|
dname=${ia//\/dev\//}
|
||||||
|
|
||||||
|
if (( $(bc <<<"$dfreeper <= 15") )); then
|
||||||
|
fs_status='error'
|
||||||
|
fs_status_color='Red'
|
||||||
|
#if [ "${ALERT_EMAIL}" != "" ]; then echo -e "${dname} : ${dfree} MB free\t$(date)" | mail -s "Free Space Critical: '${NM_NODETYPES[$NTYPE]}-Node${nid}'" ${ALERT_EMAIL}; fi
|
||||||
|
|
||||||
|
elif (( $(bc <<<"$dfreeper <= 25") )); then
|
||||||
|
fs_status='warn'
|
||||||
|
fs_status_color='Yellow'
|
||||||
|
#if [ "${ALERT_EMAIL}" != "" ]; then echo -e "${dname} : ${dfree} MB free\t$(date)" | mail -s "Free Space Warning: '${NM_NODETYPES[$NTYPE]}-Node${nid}'" ${ALERT_EMAIL}; fi
|
||||||
|
|
||||||
|
else
|
||||||
|
fs_status=''
|
||||||
|
fs_status_color='Green'
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
#echo -e "${idsCL[$fs_status_color]} ${dname} - ${dfree} (${dfreeper}%) (total=$dtot) ${idsCL[Default]}"
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
else
|
||||||
|
echo -e "${idsCL[Yellow]} ${host_name[$hostid]} is down${idsCL[Default]}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
SETUPSSH(){
|
||||||
|
declare -A host_ip
|
||||||
|
declare -A host_name
|
||||||
|
|
||||||
|
while read hostid hostname hostip hostlimits; do
|
||||||
|
if [ "$hostid" != "id" ]; then
|
||||||
|
host_ip[${hostid}]=$(echo $hostip | cut -d ";" -f1)
|
||||||
|
host_name[${hostid}]=$hostname
|
||||||
|
fi
|
||||||
|
done <<< $(MYSQL_PWD="sysmoninsert" mysql -h mysqldb.scity.us -P 3306 -u sysmoninsert -e "SELECT id,host,ip,limits FROM servermonitor.hosts")
|
||||||
|
|
||||||
|
for hostid in "${!host_ip[@]}"; do
|
||||||
|
echo -e "${idsST[Bold]}${idsCL[LightCyan]} ${host_name[$hostid]} - SSH KEY COPY${idsCL[Default]}${idsST[Reset]}"
|
||||||
|
ssh-copy-id root@${host_ip[$hostid]}
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
case $action in
|
||||||
|
check) CHECK;;
|
||||||
|
setupssh) SETUPSSH;;
|
||||||
|
run) RUN ${2};;
|
||||||
|
update);;
|
||||||
|
*) RUN ${action};;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
|
||||||
63
run.sh
Executable file
63
run.sh
Executable file
@@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# UbUpdate - Ubuntu Update Scripts Loader
|
||||||
|
|
||||||
|
|
||||||
|
source /opt/idssys/dsmon/config.settings.inc
|
||||||
|
source /opt/idssys/defaults/colors.inc
|
||||||
|
|
||||||
|
|
||||||
|
if [[ "${noheader}" != *" ${1} "* ]] && [[ "${noheader}" != *" ${2} "* ]]; then
|
||||||
|
# if [ "${1}" = "gui" ]; then
|
||||||
|
# DISP_HEADER
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# if [ "${1}" != "guiX" ]; then
|
||||||
|
if curl -m 15 -s --head --request GET https://git.schroedercity.com | grep "HTTP/2 200" > /dev/null; then
|
||||||
|
if [ "${2}" != "q" ]; then
|
||||||
|
echo -en "${idsCL[LightCyan]}Checking for updates...${idsCL[Default]}"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
cd /opt/idssys/defaults
|
||||||
|
if [ "`git log --pretty=%H ...refs/heads/master^ | head -n 1`" != "`git ls-remote origin -h refs/heads/master |cut -f1`" ]; then
|
||||||
|
if [ "${2}" != "q" ]; then
|
||||||
|
echo -en "\e[1A";
|
||||||
|
echo -e "\e[0K\r ${idsCL[LightCyan]}Installing updates...${idsCL[Default]}"
|
||||||
|
fi
|
||||||
|
git fetch origin master >/dev/null 2>&1
|
||||||
|
git reset --hard origin/master >/dev/null 2>&1
|
||||||
|
git reflog expire --expire=now --all >/dev/null 2>&1
|
||||||
|
git repack -ad >/dev/null 2>&1
|
||||||
|
git prune >/dev/null 2>&1
|
||||||
|
git pull >/dev/null 2>&1
|
||||||
|
git submodule update --remote >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
cd /opt/idssys/dsmon
|
||||||
|
if [ "`git log --pretty=%H ...refs/heads/master^ | head -n 1`" != "`git ls-remote origin -h refs/heads/master |cut -f1`" ]; then
|
||||||
|
if [ "${2}" != "q" ]; then
|
||||||
|
echo -en "\e[1A";
|
||||||
|
echo -e "\e[0K\r ${idsCL[LightCyan]}Installing updates...${idsCL[Default]}"
|
||||||
|
fi
|
||||||
|
git fetch origin master >/dev/null 2>&1
|
||||||
|
git reset --hard origin/master >/dev/null 2>&1
|
||||||
|
git reflog expire --expire=now --all >/dev/null 2>&1
|
||||||
|
git repack -ad >/dev/null 2>&1
|
||||||
|
git prune >/dev/null 2>&1
|
||||||
|
git pull >/dev/null 2>&1
|
||||||
|
git submodule update --remote >/dev/null 2>&1
|
||||||
|
/bin/chmod +x /opt/idssys/nodemgmt/nodemgmt-scripts.sh 2>&1
|
||||||
|
if [ "${2}" != "q" ]; then
|
||||||
|
echo -en "\e[1A";
|
||||||
|
echo -e "\e[0K\r ${idsCL[Green]}Updates Completed${idsCL[Default]}"
|
||||||
|
fi
|
||||||
|
elif [ "${2}" != "q" ]; then
|
||||||
|
echo -en "\e[1A";
|
||||||
|
echo -e "\e[0K\r ${idsCL[LightCyan]}No Updates Available${idsCL[Default]}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -e "${idsCL[Red]}Could not connect to 'git.schroedercity.com' for updates${idsCL[Default]}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
/opt/idssys/dsmon/dsmon.sh $1 $2 $3 $4
|
||||||
|
|
||||||
|
exit 0
|
||||||
Reference in New Issue
Block a user