Add sysmon to Proxmox scripts, added CPU temp monitoring, and fixed some of the shell logic, plus made the server hostname a part of the email.
This commit is contained in:
parent
d3d3498d0b
commit
0cfc61f7da
|
@ -0,0 +1,144 @@
|
|||
#!/bin/bash
|
||||
# Josh's Automatic System Monitor
|
||||
# Written by Josh Mudge
|
||||
# Ad Mejorem Dei Glorium
|
||||
|
||||
DSSSOURCE=https://git.coolaj86.com/josh/proxmox-scripts/raw/branch/main/dss/
|
||||
update=1
|
||||
version=v1.6.0a
|
||||
alpha=0
|
||||
dfh=$(df -h | grep '8[0-9]%')
|
||||
dfh2=$(df -h | grep '9[0-9]%')
|
||||
# This requires sensors, grep, awk, sed, sort, and tail to be installed.
|
||||
temp=$(sensors | grep Core | awk '{print $3}' | sed 's/+//g' | sed 's/°C//g' | sort -n | tail -n 1 | sed 's/[^0123456789].*//')
|
||||
|
||||
while [[ $# -gt 0 ]]
|
||||
do
|
||||
key="$1"
|
||||
|
||||
case $key in
|
||||
--setup)
|
||||
shift # past argument
|
||||
setup=1
|
||||
;;
|
||||
--no-update)
|
||||
update=0
|
||||
shift # past argument
|
||||
;;
|
||||
--audit)
|
||||
audit=1
|
||||
shift # past argument
|
||||
;;
|
||||
--email)
|
||||
email="$2"
|
||||
shift # past argument
|
||||
;;
|
||||
-h|help)
|
||||
echo "dss-mon $version"
|
||||
echo "Usage: dss --monitor --email user@mailprovider.com"
|
||||
exit 1
|
||||
;;
|
||||
-v|version)
|
||||
echo "dss $version"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
# unknown option
|
||||
if test -z "${unknown}"
|
||||
then
|
||||
unknown=$1
|
||||
else
|
||||
echo "dss-mon $version"
|
||||
echo "Usage: dss --monitor --email user@mailprovider.com"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
shift # past argument or value
|
||||
done
|
||||
|
||||
if test $update = 1
|
||||
then
|
||||
|
||||
sudo apt-get update
|
||||
sudo apt-get upgrade
|
||||
sudo apt-get install sysstat # Check if installed, then do this
|
||||
curl -s "$DSSSOURCE/setup.sh" | bash
|
||||
|
||||
fi
|
||||
|
||||
# Cleanup
|
||||
|
||||
sudo apt-get clean
|
||||
|
||||
# Security Audit (Tackled by dss init before setting this up.)
|
||||
|
||||
# if test ! -f /home/.dssv1.7
|
||||
# then
|
||||
#
|
||||
# dss init
|
||||
#
|
||||
# fi
|
||||
|
||||
auth=$(sudo cat /var/log/auth.log | grep "Invalid user")
|
||||
#auth2=$(sudo cat /var/log/auth.log | grep "Connection closed")
|
||||
|
||||
if test $alpha = 1;
|
||||
then
|
||||
|
||||
sudo apt-get autoremove
|
||||
|
||||
fi
|
||||
|
||||
# To setup email, point a domain name to your server using DNS.
|
||||
# Disable any firewall rules that block port 25 (You may have to go to a server admin panel or contact your system administrator)
|
||||
# Then run: sudo apt-get install mailutils
|
||||
# Open up /etc/hosts and make sure it has:
|
||||
# 127.0.1.1 mydomain.com myserverHOSTNAME
|
||||
# Select "Internet Site" and enter the domain you want it to send email from.
|
||||
# Then you can send email like this: echo "Body of email" | mail -s "subject" EMAILADDRESS
|
||||
|
||||
if test ! -z "$auth" # If set to run automatically, don't run this check every time.
|
||||
then
|
||||
echo "Attacks found. Sending authentication log to $email"
|
||||
sudo cat /var/log/auth.log | grep "Invalid user" | mail -s "Invalid User Login on $(hostname)" $email
|
||||
fi
|
||||
|
||||
if test ! -z "$dfh"
|
||||
then
|
||||
echo "Disk usage is high, sending disk usage to $email"
|
||||
echo "$dfh" | mail -s "High Disk Usage on $(hostname)" $email
|
||||
fi
|
||||
|
||||
if test ! -z "$dfh2"
|
||||
then
|
||||
echo "Disk usage is critical, sending disk usage to $email"
|
||||
echo "$dfh2" | mail -s "Critical Disk Usage on $(hostname)" $email
|
||||
fi
|
||||
|
||||
for i in {1..300} # Do this 300 times.
|
||||
do
|
||||
CPU=$(mpstat 1 1 | awk '$3 ~ /CPU/ { for(i=1;i<=NF;i++) { if ($i ~ /%idle/) field=i } } $3 ~ /all/ { printf("%d",100 - $field) }') # Find CPU usage for the last 10 seconds. Code credit: Stackoverflow
|
||||
CPUT=$(($CPUT + $CPU)) # Add each 1 second record to the total.
|
||||
done
|
||||
CPURESULT=$(($CPUT / 300)) # Divide the total by 300 seconds to find average CPU usage over the last 5 minutes.
|
||||
|
||||
|
||||
if test $CPURESULT -gt 90
|
||||
then
|
||||
echo "CPU usage is quite high, sending report to $email"
|
||||
echo "$CPURESULT %" | mail -s "High CPU Usage on $(hostname)" $email
|
||||
fi
|
||||
|
||||
USEDRAM=$(free | grep Mem | awk '{print ($2 -$7) / $2 * 100.0}')
|
||||
|
||||
if test $USEDRAM -gt 80
|
||||
then
|
||||
echo "RAM usage is quite high, sending report to $email"
|
||||
echo "$USEDRAM %" | mail -s "High RAM Usage on $(hostname)" $email
|
||||
fi
|
||||
|
||||
if test $temp -gt 80
|
||||
then
|
||||
echo "CPU temp is over 80C, sending report to $email"
|
||||
echo "$temp" | mail -s "High CPU Temperature on $(hostname)" $email
|
Loading…
Reference in New Issue