From 4e194016e736a4dd38a7855ee3683e72a9a9f1e6 Mon Sep 17 00:00:00 2001 From: muppeth Date: Mon, 2 Aug 2021 15:11:25 +0200 Subject: [PATCH 1/2] initial commit --- ethercalc-check.sh | 9 +++++ etherpad-check.sh | 13 +++++++ framadate-check.sh | 17 +++++++++ lufi-check.sh | 15 ++++++++ nextcloud_stats.sh | 24 +++++++++++++ nginx-check.sh | 74 +++++++++++++++++++++++++++++++++++++++ postfix-zabbix-stats.bash | 44 +++++++++++++++++++++++ privatebin-check.sh | 11 ++++++ zabbix-scripts.cfg | 33 +++++++++++++++++ 9 files changed, 240 insertions(+) create mode 100644 ethercalc-check.sh create mode 100644 etherpad-check.sh create mode 100644 framadate-check.sh create mode 100644 lufi-check.sh create mode 100644 nextcloud_stats.sh create mode 100755 nginx-check.sh create mode 100755 postfix-zabbix-stats.bash create mode 100644 privatebin-check.sh create mode 100644 zabbix-scripts.cfg diff --git a/ethercalc-check.sh b/ethercalc-check.sh new file mode 100644 index 0000000..d0c2778 --- /dev/null +++ b/ethercalc-check.sh @@ -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 diff --git a/etherpad-check.sh b/etherpad-check.sh new file mode 100644 index 0000000..ce846e2 --- /dev/null +++ b/etherpad-check.sh @@ -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 diff --git a/framadate-check.sh b/framadate-check.sh new file mode 100644 index 0000000..095a099 --- /dev/null +++ b/framadate-check.sh @@ -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 diff --git a/lufi-check.sh b/lufi-check.sh new file mode 100644 index 0000000..93a786d --- /dev/null +++ b/lufi-check.sh @@ -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 + diff --git a/nextcloud_stats.sh b/nextcloud_stats.sh new file mode 100644 index 0000000..6aa12a9 --- /dev/null +++ b/nextcloud_stats.sh @@ -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 diff --git a/nginx-check.sh b/nginx-check.sh new file mode 100755 index 0000000..268377b --- /dev/null +++ b/nginx-check.sh @@ -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 diff --git a/postfix-zabbix-stats.bash b/postfix-zabbix-stats.bash new file mode 100755 index 0000000..3c18635 --- /dev/null +++ b/postfix-zabbix-stats.bash @@ -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} diff --git a/privatebin-check.sh b/privatebin-check.sh new file mode 100644 index 0000000..926cb8f --- /dev/null +++ b/privatebin-check.sh @@ -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 + diff --git a/zabbix-scripts.cfg b/zabbix-scripts.cfg new file mode 100644 index 0000000..be4333d --- /dev/null +++ b/zabbix-scripts.cfg @@ -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_" + -- 2.30.2 From 85609ad702d5e4c9f969d0724f35f1e6d57dbf1d Mon Sep 17 00:00:00 2001 From: muppeth Date: Thu, 5 Aug 2021 17:39:11 +0200 Subject: [PATCH 2/2] added simple dovecot scripts --- dovecot-check.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 dovecot-check.sh diff --git a/dovecot-check.sh b/dovecot-check.sh new file mode 100644 index 0000000..9cd5c7d --- /dev/null +++ b/dovecot-check.sh @@ -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 -- 2.30.2