fix small issues in update scripts + end services script + add redmine script

This commit is contained in:
obitanz 2023-08-18 04:13:57 +02:00 committed by root
parent 21bac5a139
commit a765b6e4ab
6 changed files with 129 additions and 19 deletions

View File

@ -0,0 +1,65 @@
#!/bin/bash
#
# Nagios plugin to check paste version
#
# Author : Obitanz <hb+chapril@unenieme.eu>
# Date : 18 Jul 2023
#
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
function usage {
echo "Usage : $0"
echo "This script check if minetest services are UP (except test instance)"
echo " and if UDP ports are listening"
result=${UNKNOWN}
}
if [ "$#" -ne 0 ]; then
usage
else
nb_problem=0
for instance in $(ls -1d /srv/minetest.chapril.org/instances/* | grep -v "30000-test");
do
shortname=$(echo ${instance} | cut -d "/" -f 5)
instance_port=$(echo ${shortname} | cut -d "-" -f 1)
is_active=$(systemctl is-active minetest-server@${shortname}.service)
check_if_port_is_listening="netstat -l | grep udp | grep ${instance_port} > /dev/null 2>&1"
eval $check_if_port_is_listening
port_is_listening=$?
if [ "${is_active}" = "active" ]; then
result_msg="${result_msg}\n${shortname} service is UP"
else
result_msg="${result_msg}\n${shortname} service is DOWN"
((nb_problem++))
fi
if [ ${port_is_listening} -eq 0 ]; then
result_msg="${result_msg}\n${shortname}'s port (${instance_port}) is listening"
else
result_msg="${result_msg}\n${shortname}'s port (${instance_port}) has a problem (not listening)"
((nb_problem++))
fi
done
if [ ${nb_problem} -eq 0 ]; then
echo "OK - all minetest services are UP and all minetest ports are listening"
result=${OK}
elif [ ${nb_problem} -eq 1 ]; then
echo -e "WARNING - there is one problem with minetest services or ports${result_msg}"
result=${WARNING}
elif [ ${nb_problem} -ge 2 ]; then
echo -e "CRITICAL - there are at least two problems with minetest services or ports${result_msg}"
result=${CRITICAL}
else
echo "UNKNOWN - script failed"
result=${UNKNOWN}
fi
fi
exit $result

View File

@ -1,4 +1,3 @@
#!/bin/bash
#
# Nagios plugin to check paste version
@ -12,17 +11,16 @@ WARNING=1
CRITICAL=2
UNKNOWN=3
function usage() {
function usage {
echo "Usage : $0"
echo "This script check if minetest games are up to date"
result=${UNKNOWN}
}
if [ "$#" -ne 0 ]; then
usage
else
game_outdated=0
game_outdated=-1
for game in $(ls -1d /srv/minetest.chapril.org/home/.minetest/games/*);
do
shortname=$(echo ${game} | cut -d "/" -f 7)
@ -31,6 +29,9 @@ else
if [ "${currentVersion}" = "${lastVersion}" ]; then
result_msg=${result_msg}"\n${shortname} is up to date"
if [ ${game_outdated} -eq -1 ]; then
game_outdated=0
fi
else
result_msg=${result_msg}"\nnew version available for ${shortname}, current is ${currentVersion}, last is ${lastVersion}"
game_outdated=1
@ -39,6 +40,9 @@ else
if [ ${game_outdated} -eq 0 ]; then
echo "OK - all games are up to date"
result=${OK}
elif [ ${game_outdated} -eq -1 ]; then
echo "UNKNWON - error during script execution"
result=${UNKNOWN}
else
echo -e "WARNING - all games aren't up to date${result_msg}"
result=${WARNING}

View File

@ -1,4 +1,3 @@
#!/bin/bash
#
# Nagios plugin to check paste version
@ -12,23 +11,16 @@ WARNING=1
CRITICAL=2
UNKNOWN=3
function usage() {
function usage {
echo "Usage : $0"
echo "This script check if minetest mods are up to date"
result=${UNKNOWN}
}
# INFO
# 3 mods actuels : filter, xban2, whitelist
# les 2 premiers n'utilisent pas les tags ==> possible d'utiliser les commit pour déterminer si du nouveau
# le 3e utilise les tags, ça semble se coller aux derniers commit
# git rev-parse HEAD pour avoir le hash du dernier commit local
# git ls-remote origin | head -1 | cut -d " " -f 1
if [ "$#" -ne 0 ]; then
usage
else
mod_outdated=0
mod_outdated=-1
for mod in $(ls -1d /srv/minetest.chapril.org/home/.minetest/mods/*);
do
shortname=$(echo ${mod} | cut -d "/" -f 7)
@ -37,6 +29,9 @@ else
if [ "${currentVersion}" = "${lastVersion}" ]; then
result_msg=${result_msg}"\n${shortname} is up to date"
if [ ${mod_outdated} -eq -1 ]; then
mod_outdated=0
fi
else
result_msg=${result_msg}"\nnew version available for ${shortname}, current is ${currentVersion}, last is ${lastVersion}"
mod_outdated=1
@ -45,6 +40,9 @@ else
if [ ${mod_outdated} -eq 0 ]; then
echo "OK - all mods are up to date"
result=${OK}
elif [ ${mod_outdated} -eq -1 ]; then
echo "UNKNWON - error during script execution"
result=${UNKNOWN}
else
echo -e "WARNING - all mods aren't up to date${result_msg}"
result=${WARNING}

View File

@ -1 +1,2 @@
5 0 1 * * root /srv/minetest.chapril.org/tools/rapport_activite/rapport_activite_mineclone2.sh -p >> /srv/minetest.chapril.org/exploitation/rapport_minetest_mineclone2.log 2>&1
20 0 1 * * root /srv/minetest.chapril.org/tools/rapport_activite/update_redmine_ticket.sh >> /var/log/mineclone2_stats.log

View File

@ -40,7 +40,7 @@ generateReport()
connectionCount=$(zgrep " joins game" /var/log/minetest/30009-mineclone2.log-${month}* | wc -l)
echo "Nombre de connexions à Mineclone2 = $connectionCount"
uniqConnectionCount=$(zgrep " joins game" /var/log/minetest/30009-mineclone2.log-${month}* | uniq | wc -l)
uniqConnectionCount=$(zgrep " joins game" /var/log/minetest/30009-mineclone2.log-${month}* | cut -d " " -f 4 | sort | uniq | wc -l)
echo "Nombre de connexions \"uniques\" à Mineclone2 = $uniqConnectionCount"
voxelPut=$(zgrep " places node " /var/log/minetest/30009-mineclone2.log-${month}* | wc -l)
@ -53,12 +53,12 @@ generateReport()
echo "Nombre d'objets créés = $voxelCrafted"
awardsGot=$(zgrep " has gotten award " /var/log/minetest/30009-mineclone2.log-${month}* | wc -l)
echo "Nombre de haut-faits débloqué = $awardsGot"
echo "Nombre de haut-faits débloqués = $awardsGot"
deadCount=$(zgrep " died at " /var/log/minetest/30009-mineclone2.log-${month}* | wc -l)
echo "Nombre de morts = $deadCount"
accountTotalCount=$(su -c "psql -U postgres -d minetest-auth --tuples-only -c \"SELECT COUNT(*) FROM auth\"" postgres | xargs)
accountTotalCount=$(su -c "psql -U postgres -d minetest-auth --tuples-only -c \"SELECT COUNT(*) FROM auth\"" postgres | xargs 2> /dev/null)
echo "Nombre de comptes total = $accountTotalCount"
warningCount=$(zgrep "WARNING" /var/log/minetest/30009-mineclone2.log-${month}* | wc -l)
@ -67,8 +67,8 @@ generateReport()
errorCount=$(zgrep "ERROR" /var/log/minetest/30009-mineclone2.log-${month}* | wc -l)
echo "Nombre d'erreurs = $errorCount"
mcl2_databasesSize=$(su -c "psql -U postgres --tuples-only -c \"SELECT ROUND((CAST(SUM(pg_database_size(datname)) AS decimal) / 1024 / 1024)::numeric, 2) FROM pg_database WHERE datname LIKE 'minetest%mineclone2'\"" postgres | xargs)
echo "Taile des bases de données mineclone2 = $mcl2_databasesSize MB"
mcl2_databasesSize=$(su -c "psql -U postgres --tuples-only -c \"SELECT ROUND((CAST(SUM(pg_database_size(datname)) AS decimal) / 1024 / 1024)::numeric, 2) FROM pg_database WHERE datname LIKE 'minetest%mineclone2'\"" postgres | xargs 2> /dev/null)
echo "Taille des bases de données mineclone2 = $mcl2_databasesSize MB"
echo -e "\n"
}

View File

@ -0,0 +1,42 @@
#! /bin/bash
# Lecture configuration
CONFIG="/etc/minetest.chapril.org/mineclone2.conf"
CONFIG_KEY="/etc/chagirbot/agiraprilorg.conf"
source ${CONFIG}
source ${CONFIG_KEY}
REDMINE_API_KEY=${key}
main() {
post_report
}
post_report() {
datafile=$(mktemp /tmp/report_stats_$(date +%Y-%m-%d_%H%M)_XXXX.json)
cat <<EOF > "${datafile}"
{
"issue": {
"notes": "$(/srv/minetest.chapril.org/tools/rapport_activite/rapport_activite.sh -p| sed -z 's/\n/\\n/g')"
}
}
EOF
curl -s \
-H "Content-Type: application/json" \
-H "X-Redmine-API-Key: ${REDMINE_API_KEY}" \
-X PUT --data-binary "@${datafile}" \
"${REDMINE_BASE_URL}/issues/${REDMINE_TICKET_ID}.json"
rm "${datafile}"
}
last_comment_date() {
curl -H "X-Redmine-API-Key: ${REDMINE_API_KEY}" -s "${REDMINE_BASE_URL}/issues/${REDMINE_TICKET_ID}.json?include=journals" \
| jq '.issue.journals | last | .created_on'
}
list() {
curl -H "X-Redmine-API-Key: ${REDMINE_API_KEY}" -s "${REDMINE_BASE_URL}/issues/${REDMINE_TICKET_ID}.json?include=journals" \
| jq '.issue.journals[] | [.user.name, .notes]'
}
main