[Zabbix] Add simple Zabbix scripts

This commit is contained in:
Simon Cornet 2023-08-22 09:16:23 +02:00
parent 950941b5e7
commit 3edb48e453
3 changed files with 80 additions and 0 deletions

27
Linux/zabbix/check_service.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/bash
# Find service name from argument
monitorService=$1
# Check if $monitorService is empty
if [ -z "$monitorService" ]; then
read -p "Please pass me the service name: " monitorService
fi
# Define the check_service function
function check_service {
# Check if the service is active and report so
if systemctl is-active --quiet $monitorService; then
echo "$monitorService is running"
# If the service is not running, exit with an error.
else
echo "$monitorService is not running"
exit 1
fi
}
# Excecute the check_service function
check_service

View File

@ -0,0 +1,43 @@
#!/bin/bash
# Prune container images
if [ -x "$(command -v docker)" ]; then
echo "Pruning using Docker"
sudo docker image prune -af
elif [ -x "$(command -v podman)" ]; then
echo "Pruning using Podman"
sudo podman image prune -af
else
echo "No container images to prune"
fi
# Remove all disabled snaps
if [ -x "$(command -v snap)" ]; then
echo "Remove all deactivated snaps"
sudo snap list --all | \
awk '/disabled/{print $1, $3}' | \
while read snapname revision; do \
sudo snap remove "$snapname" --revision="$revision";
done
else
echo "No snaps found"
fi
# Flush and rotate all logs
if [ -x "$(command -v journalctl)" ]; then
echo "Vacuuming logs using journalctl"
sudo journalctl \
--flush \
--rotate \
--vacuum-time=1s
else
echo "JournalCTL not found"
fi
# remove zipped logs
echo "Delete zipped logs"
sudo rm -rf /var/log/*.gz

View File

@ -0,0 +1,10 @@
# Clear swapusage
free_memory=`free -m | awk 'NR==2{print $7}'`
used_swap=`free -m | awk 'NR==3{print $3}'`
if [ $free_memory -gt $used_swap ]; then
sudo swapoff -a && sudo swapon -a
echo "Swap usage cleared!"
else
echo "Cannot clear swapusage, not enough memory!"
fi2