diff --git a/bot.sh b/bot.sh index 3845909..dfaeba9 100755 --- a/bot.sh +++ b/bot.sh @@ -1,19 +1,27 @@ #!/bin/bash # the main bot script +. config.sh . func.sh #hdd usage -used=$(df --output=pcent /dev/sda3 | tail -1 | grep -Po "(\\d+)" --color=never) -if [ "$used" -gt 50 ]; then +used=$(df --output=pcent $hdd | tail -1 | grep -Po "(\\d+)" --color=never) +if [ "$used" -gt "$hddlimit" ]; then echo "warn!" send "warnung%20server%20used%20$used%25%20of%20the%20storage!" fi #services . services.sh -notrunning=$(checkServices "nginx,mysql") +notrunning=$(checkServices "$services") if [ "$notrunning" != "" ]; then echo "Serive warn!" send "warnung%20the%20following%20services%20are%20not%20running%20$notrunning" fi + +. cpu.sh +cpu=$(cpuUsage) +if [ "$cpu" -gt "$cpulimit" ]; then + echo "cpu limit!" + send "warnung%20CPU%20Usage%20is%20high%20$cpu" +fi diff --git a/config.sh b/config.sh new file mode 100755 index 0000000..284e106 --- /dev/null +++ b/config.sh @@ -0,0 +1,17 @@ +#!/bin/bash +#services that should be running +services="nginx,mysql" + +#cpu usage limit (not divided by core count) +cpulimit="150" + +#telegram api-token +token="123456:ABCDEFGH" +#telegram user to notify +userid="123456" + +#harddrive usage percentage +hddlimit="50" + +#harddrive +hdd="/dev/sda1" diff --git a/cpu.sh b/cpu.sh new file mode 100755 index 0000000..11732e1 --- /dev/null +++ b/cpu.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +function cpuUsage { + ps -A -o pcpu | tail -n+2 | paste -sd+ | bc | awk '{print int($1)}' +} diff --git a/func.sh b/func.sh index fd06586..0ea2fae 100755 --- a/func.sh +++ b/func.sh @@ -1,7 +1,4 @@ #!/bin/bash -token="APItoken" -userid="usernameorid" - #1. arg = text send() { echo "Sending $1 to ${userid}"