- initial commit (#1)

Co-authored-by: muppeth <muppeth@disroot.org>
Reviewed-on: #1
Co-authored-by: muppeth <muppeth@no-reply@disroot.org>
Co-committed-by: muppeth <muppeth@no-reply@disroot.org>
This commit is contained in:
muppeth 2021-10-31 13:39:19 +00:00
parent 43ab2d4451
commit 8191a5f167
10 changed files with 246 additions and 0 deletions

6
dovecot-check.sh Normal file
View File

@ -0,0 +1,6 @@
#!/bin/bash
doveadm who |wc -l > /tmp/dovecot_user_count
chown zabbix:zabbix /tmp/dovecot_user_count
doveadm who |awk '{print $2}' |paste -sd+ | bc > /tmp/dovecot_device_count
chown zabbix:zabbix /tmp/dovecot_device_count

9
ethercalc-check.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
#This script checks the amount of calcs and amount of connected people
source /var/local/container-scripts/zabbix-scripts.cfg
#all calcs
CALC_ALL=$(redis-cli KEYS "snapshot-*" |wc -l)
#save to a file
echo "calc_all ${CALC_ALL}" > /tmp/ethercalc_stats

13
etherpad-check.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
#This script checks the amount of calcs and amount of connected people
source /var/local/container-scripts/zabbix-scripts.cfg
#statistics
PAD_TOTALPADS=$(mysql -h "${PAD_HOST}" -u "${PADDB_USER}" -p "${PADDB_PASSWD}" "${PADDB_NAME}" -s -r -N -e \
"select count(distinct substring(store.key,5,locate(':',store.key,5)-5)) as 'pads' from store where store.key like 'pad:%';")
PAD_ACTIVEUSERS=$(curl http://${PAD_LISTEN}:${PAD_PORT}/stats |jq .totalUsers)
PAD_ACTIVEPADS=$(curl http://${PAD_LISTEN}:${PAD_PORT}/stats |jq .activePads)
echo "pad_totalpads ${PAD_TOTALPADS}" > /tmp/pad_stats
echo "pad_activeusers ${PAD_ACTIVEUSERS}" >> /tmp/pad_stats
echo "pad_activepads ${PAD_ACTIVEPADS}" >> /tmp/pad_stats

17
framadate-check.sh Normal file
View File

@ -0,0 +1,17 @@
#!/bin/bash
#This script checks the amount of polls
source /var/local/container-scripts/zabbix-scripts.cfg
#all polls
POLLS_ALL=$(mysql -h "${POLLDB_HOST}" -u "${POLLDB_USER}" -p${POLLDB_PASSWD}" -s -r -N -e "SELECT COUNT(*) from ${POLLDB_PREFIX}_poll;)
#poll type event
POLLS_EVENTS=$(mysql -h "${POLLDB_HOST}" -u "${POLLDB_USER}" -p${POLLDB_PASSWD}" -s -r -N -e "SELECT COUNT(*) from ${POLLDB_PREFIX}_poll where format = 'D';)
#poll type standard
POLLS_STANDARD=$(mysql -h "${POLLDB_HOST}" -u "${POLLDB_USER}" -p${POLLDB_PASSWD}" -s -r -N -e "SELECT COUNT(*) from ${POLLDB_PREFIX}_poll where format = 'A';)
#save onto a file
echo "polls_all ${POLLS_ALL}" > /tmp/framadate_stats
echo "polls_events ${POLLS_EVENTS}" >> /tmp/framadate_stats
echo "polls_standard ${POLLS_STANDARD}" >> /tmp/framadate_stats

15
lufi-check.sh Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
#This script checks the amount of polls
source /var/local/container-scripts/zabbix-scripts.cfg
#all files
LUFI_ALLFILES=$(psql postgresql://${LUFIDB_USER}:${LUFIDB_PASSWD}@${LUFIDB_HOST}:${LUFIDB_PORT} -t -c "SELECT COUNT(filename) FROM files WHERE filename IS NOT NULL;")
LUFI_DELETED=$( psql postgresql://${LUFIDB_USER}:${LUFIDB_PASSWD}@${LUFIDB_HOST}:${LUFIDB_PORT} -t -c "SELECT COUNT(filename) FROM files WHERE filename IS NOT NULL and deleted = '1';")
LUFI_ACTIVE=$( psql postgresql://${LUFIDB_USER}:${LUFIDB_PASSWD}@${LUFIDB_HOST}:${LUFIDB_PORT} -t -c "SELECT COUNT(filename) FROM files WHERE filename IS NOT NULL and deleted = '0';")
LUFI_SIZE=$(du -s ${LUFI_PATH} | cut -f1)
echo "lufi_allfiles ${LUFI_ALLFILES}" > /tmp/lufi_stats
echo "lufi_deleted ${LUFI_DELETED}" >> /tmp/lufi_stats
echo "lufi_active ${LUFI_ACTIVE}" >> /tmp/lufi_stats
echo "lufi_size ${LUFI_SIZE}" >> /tmp/lufi_size

24
nextcloud_stats.sh Normal file
View File

@ -0,0 +1,24 @@
#!/bin/bash
#This is script that collects nextlcoud statistics
source /var/local/container-scripts/zabbix-scripts.cfg
#!/bin/bash
curl -s https://"${NC_ADMIN_USER}":"${NC_ADMIN_PW}"@"${NC_HOST}"/ocs/v2.php/apps/serverinfo/api/v1/info > /tmp/cloudstats
NC_DECK_BOARDS=$(mysql -h "${CLOUDDB_HOST}" -u "${CLOUDDB_USER}" -p"${CLOUDDB_PASSWORD}" "${CLOUDDB_NAME}" -s -r -N -e "select count(*) from ${NC_PREFIX}deck_boards;")
NC_FORMS=$(mysql -h "${CLOUDDB_HOST}" -u "${CLOUDDB_USER}" -p"${CLOUDDB_PASSWORD}" "${CLOUDDB_NAME}" -s -r -N -e "select count(*) from ${NC_PREFIX}forms_v2_forms;")
NC_TALK_ROOMS=$(mysql -h "${CLOUDDB_HOST}" -u "${CLOUDDB_USER}" -p"${CLOUDDB_PASSWORD}" "${CLOUDDB_NAME}" -s -r -N -e "select count(*) from ${NC_PREFIX}talk_rooms where last_activity is not null;")
NC_CIRCLES=$(mysql -h "${CLOUDDB_HOST}" -u "${CLOUDDB_USER}" -p"${CLOUDDB_PASSWORD}" "${CLOUDDB_NAME}" -s -r -N -e "select count(*) from ${NC_PREFIX}circle_circles;")
NC_CALENDARS=$(mysql -h "${CLOUDDB_HOST}" -u "${CLOUDDB_USER}" -p"${CLOUDDB_PASSWORD}" "${CLOUDDB_NAME}" -s -r -N -e "select count(*) from ${NC_PREFIX}calendars;")
NC_CONTACTS=$(mysql -h "${CLOUDDB_HOST}" -u "${CLOUDDB_USER}" -p"${CLOUDDB_PASSWORD}" "${CLOUDDB_NAME}" -s -r -N -e "select count(*) from ${NC_PREFIX}cards;")
NC_BOOKMARKS=$(mysql -h "${CLOUDDB_HOST}" -u "${CLOUDDB_USER}" -p"${CLOUDDB_PASSWORD}" "${CLOUDDB_NAME}" -s -r -N -e "select count(*) from ${NC_PREFIX}bookmarks;")
NC_COSPEND=$(mysql -h "${CLOUDDB_HOST}" -u "${CLOUDDB_USER}" -p"${CLOUDDB_PASSWORD}" "${CLOUDDB_NAME}" -s -r -N -e "select count(*) from ${NC_PREFIX}cospend_projects;")
NC_APPOINTMENTS=$(mysql -h "${CLOUDDB_HOST}" -u "${CLOUDDB_USER}" -p"${CLOUDDB_PASSWORD}" "${CLOUDDB_NAME}" -s -r -N -e "select count(*) from ${NC_PREFIX}appointments_hash;")
echo "nc_deck_boards " "${NC_DECK_BOARDS}" >> /tmp/nc_stats
echo "nc_talk_rooms" "${NC_TALK_ROOMS}" >> /tmp/nc_stats
echo "nc_circles" "${NC_CIRCLES}" >> /tmp/nc_stats
echo "nc_calendars" "${NC_CALENDARS}" >> /tmp/nc_stats
echo "nc_contacts" "${NC_CONTACTS}" >> /tmp/nc_stats
echo "nc_bookmarks" "${NC_BOOKMARKS}" >> /tmp/nc_stats
echo "nc_cospend" "${NC_COSPEND}" >> /tmp/nc_stats
echo "nc_appointments" "${NC_APPOINTMENTS}" >> /tmp/nc_stats

74
nginx-check.sh Executable file
View File

@ -0,0 +1,74 @@
#!/bin/bash
##################################
# Zabbix monitoring script
#
# nginx:
# - anything available via nginx stub-status module
#
##################################
# Contact:
# vincent.viallet@gmail.com
##################################
# ChangeLog:
# 20100922 VV initial creation
##################################
# Zabbix requested parameter
ZBX_REQ_DATA="$1"
ZBX_REQ_DATA_URL="$2"
# Nginx defaults
NGINX_STATUS_DEFAULT_URL="http://localhost:80/nginx_status"
WGET_BIN="/usr/bin/wget"
CURL_BIN="/usr/bin/curl"
if [ ! -f $WGET_BIN ];
then
USE_CURL=true
fi
#
# Error handling:
# - need to be displayable in Zabbix (avoid NOT_SUPPORTED)
# - items need to be of type "float" (allow negative + float)
#
ERROR_NO_ACCESS_FILE="-0.9900"
ERROR_NO_ACCESS="-0.9901"
ERROR_WRONG_PARAM="-0.9902"
ERROR_DATA="-0.9903" # either can not connect / bad host / bad port
# Handle host and port if non-default
if [ ! -z "$ZBX_REQ_DATA_URL" ]; then
URL="$ZBX_REQ_DATA_URL"
else
URL="$NGINX_STATUS_DEFAULT_URL"
fi
# save the nginx stats in a variable for future parsing
if [ ! $USE_CURL = true ]; then
NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null)
else
NGINX_STATS=$($CURL_BIN -S -s $URL)
fi
# error during retrieve
if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then
echo $ERROR_DATA
exit 1
fi
#
# Extract data from nginx stats
#
case $ZBX_REQ_DATA in
active_connections) echo "$NGINX_STATS" | head -1 | cut -f3 -d' ';;
accepted_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f2 -d' ';;
handled_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f3 -d' ';;
handled_requests) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f4 -d' ';;
reading) echo "$NGINX_STATS" | tail -1 | cut -f2 -d' ';;
writing) echo "$NGINX_STATS" | tail -1 | cut -f4 -d' ';;
waiting) echo "$NGINX_STATS" | tail -1 | cut -f6 -d' ';;
*) echo $ERROR_WRONG_PARAM; exit 1;;
esac
exit 0

44
postfix-zabbix-stats.bash Executable file
View File

@ -0,0 +1,44 @@
#!/bin/bash
MAILLOG=/var/log/mail.log
PFOFFSETFILE=/tmp/zabbix-postfix-offset.dat
PFSTATSFILE=/tmp/postfix_statsfile.dat
TEMPFILE=$(mktemp)
PFLOGSUMM=/usr/sbin/pflogsumm
LOGTAIL=/usr/sbin/logtail
PFVALS=( 'received' 'delivered' 'forwarded' 'deferred' 'bounced' 'rejected' 'held' 'discarded' 'reject_warnings' 'bytes_received' 'bytes_delivered' )
[ ! -e "${PFSTATSFILE}" ] && touch "${PFSTATSFILE}" && chown zabbix:zabbix "${PFSTATSFILE}"
printvalues() {
key=$1
pfkey=$(echo "$1" | tr '_' ' ')
value=$(grep -m 1 "${pfkey}" $TEMPFILE | awk '{print $1}' | awk '/k|m/{p = /k/?1:2}{printf "%d\n", int($1) * 1024 ^ p}')
old_value=$(grep -e "^${key};" "${PFSTATSFILE}" | cut -d ";" -f2)
if [ -n "${old_value}" ]; then
sed -i -e "s/^${key};${old_value}/${key};$((${old_value}+${value}))/" "${PFSTATSFILE}"
else
echo "${key};${value}" >> "${PFSTATSFILE}"
fi
}
if [ -n "$1" ]; then
key=$(echo ${PFVALS[@]} | grep -wo $1)
if [ -n "${key}" ]; then
value=$(grep -e "^${key};" "${PFSTATSFILE}" | cut -d ";" -f2)
echo "${value}"
else
rm "${TEMPFILE}"
exit 2
fi
else
"${LOGTAIL}" -f"${MAILLOG}" -o"${PFOFFSETFILE}" | "${PFLOGSUMM}" -h 0 -u 0 --bounce_detail=0 --deferral_detail=0 --reject_detail=0 --no_no_msg_size --smtpd_warning_detail=0 > "${TEMPFILE}"
for i in "${PFVALS[@]}"; do
printvalues "$i"
done
fi
rm "${TEMPFILE}"
chown zabbix:zabbix ${PFOFFSETFILE}
chown zabbix:zabbix ${PFSTATSFILE}

11
privatebin-check.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/
#This script checks the amount of calcs and amount of connected people
source /var/local/container-scripts/zabbix-scripts.cfg
#statistics
BIN_TOTAL=$(find ${BIN_PATH} -mindepth 2 -name *.php | wc -l)
BIN_SIZE=$(du -s ${BIN_PATH} | cut -f1)
echo "bin_total ${BIN_TOTAL}" > /tmp/bin_stats
echo "bin_size ${BIN_SIZE}" >> /tmp/bin_stats

33
zabbix-scripts.cfg Normal file
View File

@ -0,0 +1,33 @@
# Zabbix Scripts variables
# PrivateBin
BIN_PATH="/srv/privatebin"
#Framadate
POLLDB_HOST="localhost"
POLLDB_USER="admin"
POLLDB_PASSWD="changeme"
POLLDB_PREFIX="fd"
#Etherpad
PADDB_HOST="localhost"
PADDB_USER="admin"
PADDB_PASSWD="changeme"
PADDB_NAME="etherpad"
PAD_LISTEN="127.0.0.1"
PAD_PORT="9001"
#Lufi
LUFIDB_USER="lufi"
LUFIDB_PASSWD="changeme"
LUFIDB_HOST="localhost"
LUFIDB_PORT="5432"
LUFI_PATH="/var/lufi"
#nextcloud
NC_ADMIN_USER="admin"
NC_ADMIN_PW="changeme"
NC_HOST="localhost"
CLOUDDB_HOST="localhost"
NC_PREFIX="nc_"