From 6db35a5230578e296d9f493b28e6330e22569c8f Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Wed, 4 Sep 2019 22:06:01 +0200 Subject: Integrate also nagios-based monitoring here --- adei/check_adei.sh | 97 ++++++++++++++++++++ adei/check_adei_control.sh | 16 ++++ adei/check_adei_source.sh | 224 +++++++++++++++++++++++++++++++++++++++++++++ adei/check_adei_status.sh | 1 + adei/lib | 1 + adei/scripts | 1 + adei/security | 1 + adei/setup | 1 + 8 files changed, 342 insertions(+) create mode 100755 adei/check_adei.sh create mode 100755 adei/check_adei_control.sh create mode 100755 adei/check_adei_source.sh create mode 120000 adei/check_adei_status.sh create mode 120000 adei/lib create mode 120000 adei/scripts create mode 120000 adei/security create mode 120000 adei/setup (limited to 'adei') diff --git a/adei/check_adei.sh b/adei/check_adei.sh new file mode 100755 index 0000000..58ce49c --- /dev/null +++ b/adei/check_adei.sh @@ -0,0 +1,97 @@ +#! /bin/bash + +. $(dirname "$0")/lib/adei/adei.sh + +adei_init "$@"; code=$? + +online=${adei_online} +healthy=$(( $code == 0 )) + +adei_version_check "0.0.10" +[ $? -eq 0 ] && adei10=1 + +msg="" +[ -n "$adei_version" ] && msg+="ADEI $adei_version" + +# Get current database size +[ -n "$adei10" ] && size=$(adei_text_query "info.php?target=size&encoding=text") + +[[ "$size" =~ "Error:" ]] && size="" +[ -n "$size" ] && msg+=" \${color gray}/ $((size / 1024 / 1024 / 1024)) GB" + +# Check pending administrative scripts +if [ -n "$adei10" -a $healthy -ne 0 ]; then + scripts=$(adei_xml_query "info.php?target=scripts"); err=$? + [ $err -eq 0 ] && waiting="$(echo $scripts | grep "Value" | sed -e "s/^\(.*mtime=\"\([^\"]*\)\".*\)$/\\2\\1/" | awk -v date="$(date +%s)" '{duration=date - $1} duration > 3600 { print duration }' | sort -rn)" #" + + if [ $err -ne 0 ]; then + adei_print_error $err "ScriptInfo" "$waiting" + healthy=0 + elif [ -n "$waiting" ]; then + num_waiting="$(echo $waiting | tr ' ' '\n' | wc -l)" + long_waiting="$(echo $waiting | cut -d ' ' -f 1)" + if [ $num_waiting -gt 0 ]; then + healthy=2 + echo "$num_waiting pending scripts, longest for $(format_time $long_waiting)" + fi + fi +fi + +# Verify offset (for selected database) +if [ -n "$adei10" -a $healthy -ne 0 -a -n "$adei_source" ]; then + now=$(date +%s) + sdate="$(adei_text_query "getdata.php?db_mask=0&format=csv&window=-1&rt=1&cache=1&time_format=U&mysql=slave")"; err_slave=$? + [ $err_slave -eq 0 ] && sdate="$(echo "$sdate" | cut -d ',' -f 1 | cut -d '.' -f 1)" + mdate="$(adei_text_query "getdata.php?db_mask=0&format=csv&window=-1&rt=1&cache=1&time_format=U&mysql=master")"; err_master=$? + [ $err_master -eq 0 ] && mdate="$(echo "$mdate" | cut -d ',' -f 1 | cut -d '.' -f 1)" + + src="$adei_source" + if [ $err_slave -ne 0 -o $err_master -ne 0 -o -z "$sdate" -o -z "$mdate" ]; then + + echo -n "Error querying (${err_master:+master} ${err_slave:+slave}) data from cache of '$src': " + if [ $err_master -ne 0 ]; then + echo "$(adei_print_error $err_master "$mdate")" + elif [ $err_slave -ne 0 ]; then + echo "$(adei_print_error $err_slave "$sdate")" + else + echo "Unexpected response from getdata service" + fi + healthy=0 + else + master_offset=$(($now - $mdate)) + slave_offset=$(($mdate - $sdate)) + + if [ $master_offset -gt $MAX_SOURCE_OFFSET ]; then + rdate=$(adei_text_query "getdata.php?db_mask=0&format=csv&window=-1&rt=1&time_format=U&mysql=master"); err=$? + if [ $err -eq 0 ]; then + rdate="$(echo "$rdate" | cut -d ',' -f 1 | cut -d '.' -f 1)" + cache_offset=$(($rdate - $mdate)) + + if [ $cache_offset -gt $MAX_MASTER_OFFSET ]; then + echo "ADEI cache is off by $(format_time $cache_offset) for '$src'" + healthy=2 + else + offset=$(($now - $rdate)) +# echo "Source '$src' is not updated for $(format_time $offset)" + fi + else + echo -n "Error querying data from '$src' primary database: " + echo "$(adei_print_error $err_master "$rdate")" + healthy=0 + fi + fi + + if [ $slave_offset -gt $MAX_SLAVE_OFFSET ]; then + echo "MySQL slave is off by $(format_time $slave_offset) for '$src'" + healthy=2 + fi + + [ -n "$msg" ] && msg="${msg}, " + [ -z "$msg" ] && msg="\${color gray}/ " + msg="${msg}cache $(format_time $master_offset)" + [ $slave_offset -gt 0 ] && msg="$msg & slave $(format_time $slave_offset)" + msg="$msg off" + fi +fi + +echo "$(adei_print_status "$0" $online $healthy) $msg" diff --git a/adei/check_adei_control.sh b/adei/check_adei_control.sh new file mode 100755 index 0000000..f6570e1 --- /dev/null +++ b/adei/check_adei_control.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +. $(dirname "$0")/adei.sh + +status=1 + + +adei_init "$@"; code=$? +adei_process_error $code + + +cgroup="${adei_args[0]}" +resp=$(adei_value_query "control.php?target=get&control_group=$cgroup"); code=$? +adei_process_error "$code" "$resp" "ADEI/Control" + +echo "$status" diff --git a/adei/check_adei_source.sh b/adei/check_adei_source.sh new file mode 100755 index 0000000..dcec5bf --- /dev/null +++ b/adei/check_adei_source.sh @@ -0,0 +1,224 @@ +#!/bin/bash + +. $(dirname "$0")/adei.sh + + +adei_init "$@"; code=$? +adei_process_error $code + +filter="${adei_args[0]}" + +#echo "$adei_url" +#echo "$adei_source" +#echo "$filter" +#exit + +status=1 +n_groups=0 +cache_size=0 +cur=`date -u +%s` + +group_mode=0 +#groups=`curl -s -m 3 --proxy "" "$adei_url/services/list.php?target=groups&info=1&setup=$2&db_server=$3&db_name=$db_name" | xmllint --format - | grep "Value" | sed -e "s/^.*db_group=\"\([^\"]*\)\".*$/\\1/" | sed -e "s/ /::space::/"` +groups=$(adei_value_query "list.php?target=groups&info=1" 12); err=$? +if [ $err -ge 1 -a $err -le 3 ]; then + groups=$(adei_value_query "list.php?target=groups" 5); err=$? + adei_process_error $err "$groups" "GroupList" + + echo "Data queries are too slow, check database indexes" + group_mode=1 + status=0 +elif [ $err -gt 0 ]; then + adei_process_error $err "$groups" "GroupList" +fi + +if [ $group_mode -eq 0 ]; then + groups=`echo "$groups" | sed -e "s/ /::space::/g"` +else + groups=`echo "$groups" | sed -e "s/^.*db_group=\"\([^\"]*\)\".*$/\\1/" | sed -e "s/ /::space::/"` +fi + +for group in $groups; do + n_groups=$(($n_groups + 1)) + + nodata=0 + if [ $group_mode -eq 0 ]; then + group=`echo "$group" | sed -e "s/::space::/ /g"` + gid=`echo "$group" | sed -e "s/^.*db_group=\"\([^\"]*\)\".*$/\\1/"` + [ "$gid" == "$group" ] && gid=`echo "$group" | sed -e "s/^.*gid=\"\([^\"]*\)\".*$/\\1/"` + + if [ "$gid" == "$group" ]; then + echo "Invalid group specification received from ADEI server: $group" + status=0 + continue + fi + urlgid=`echo $gid | sed -e "s/ /+/g"` + last=$group + else + urlgid=`echo $group | sed -e "s/::space::/+/"` + gid=`echo $group | sed -e "s/::space::/ /"` + last=$(adei_simple_query "list.php?target=groups&info=1&db_group=$urlgid" 3) + if [ $? -ne 0 ]; then + echo "Queries to $gid are too slow, check database indexes" + status=0 + nodata=1 + else + error=${last#ERROR: } + if [ "$error" != "$last" ]; then + echo "$gid: $error" + status=0 + nodata=1 + fi + last=`echo $last | grep "Value"` + fi + + fi + + if [ $nodata -eq 0 ]; then + echo "$last" | grep "last=" &> /dev/null + if [ $? -eq 0 ]; then + ts=`echo $last | sed -e "s/^.*last=\"\([^\"]*\)\".*$/\\1/" | cut -d '.' -f 1` + if [ -z "$ts" ]; then + nodata=1 +# echo "$gid: contains no data" +# if [ $status -eq 1 ]; then status=2; fi + fi + else + ts="" + nodata=1 +# echo "$gid: contains no data" +# if [ $status -eq 1 ]; then status=2; fi + fi + else + ts=$cur + fi + + + if [ $nodata -eq 0 ]; then + since=$((($cur - $ts) / 3600)) + if [ $since -gt 0 ]; then + if [ -n "$filter" ]; then + echo "$gid" | grep -P "$filter" &>/dev/null + accept=$? + else + accept=1 + fi + + if [ $accept -ne 0 ]; then + last=`date -u -d "@$ts" "+%F %R:%S"` + echo "$gid: Last updated on $last" + if [ $status -eq 1 ]; then + status=2 + fi +# continue + fi + fi + fi + + + info=$(adei_value_query "info.php?target=cache&db_group=$urlgid"); err=$? + [ $err -eq 0 ] && dbsize=`echo $info | sed -e "s/^.*dbsize=\"\([^\"]*\)\".*$/\\1/"` + + if [ $err -ne 0 ]; then + echo "$gid: Cache query has failed" + status=0 + elif [ ${#dbsize} -gt 16 ]; then + # Otherwise both cache & data are missing. We think it is tolerable + if [ $nodata -eq 0 ]; then + echo "$gid: Cache is empty" + if [ $status -eq 1 ]; then status=2; fi + fi + continue + else + cache_size=$(($cache_size + `echo $info | sed -e "s/^.*dbsize=\"\([^\"]*\)\".*$/\\1/"`)) + + last_cache=`echo $info | sed -e "s/^.*last=\"\([^\"]*\)\".*$/\\1/"` + if [ "$info" == "$last_cache" ]; then + # There is data in the source, but cache is empty (but we should detect this earlier) + # Otherwise, - no cache, no data (which is OK) or we already reported about troublesome source + if [ $nodata -eq 0 ]; then + last_cache=0 + echo "$gid: Cache is empty (but non-zero size is reported)" + if [ $status -eq 1 ]; then status=2; fi + fi + continue + else + if [ -z "$ts" ]; then + echo -n "$gid: contains no data, but cached until " + date -u -d "@$last_cache" "+%F %R:%S" + if [ $status -eq 1 ]; then status=2; fi + continue + else + since=$((($ts - $last_cache) / 3600)) + fi + fi + + if [ $since -gt 0 ]; then + real_width=$(adei_xml_query "list.php?target=items&db_group=$urlgid"); err=$? + + if [ $err -ne 0 ]; then + status=0 + echo "$gid: item list service failed" + else + real_width=$((`echo "$real_width" | wc -l` - 3)) + fi + + if [ $real_width -le 0 ]; then + echo "$gid: Invalid number of items reported by list sevice ($real_width)" + status=0 + continue + fi + + width=`echo $info | grep width=` + if [ -z "$width" ]; then + echo "$gid: Invalid cache information from ADEI server, width parameter missing" + status=0 + continue + fi + + width=`echo $info | sed -e "s/^.*width=\"\([^\"]*\)\".*$/\\1/"` + if [ $width -eq 0 ]; then + echo "$gid: Invalid cache information from ADEI server, width parameter is zero" + status=0 + continue + fi + + found_reason=0 + + if [ "$real_width" -ne "$width" ]; then + found_reason=1 + status=0 + echo "$gid: Channel mistmatch $width (cache) and $real_width (reader)" + fi + + +# if [ $nodata -eq 0 ]; then +# if [ $found_reason -eq 0 ]; then +# # Using current version, we are not able to handle properly limit & filtering together +# adei_version_check "0.0.10" +# if [ $? -eq 0 ]; then +# last_data=$(adei_simple_query "getdata.php?db_group=$urlgid&window=0,1") +# if [ $? -ne 0 ]; then +# found_reason=1 +# status=0 +# echo -n "$gid: No valid data in database, but there is (filtered?) records. Last one from " +# date -u -d "@$ts" "+%F %R:%S" +# fi +# fi +# fi +# fi + + if [ $found_reason -eq 0 ]; then + status=0 + echo "$gid: Last $since hours are not cached" + fi + fi + fi +done + +if [ $n_groups -eq 0 ]; then + status=0 +fi + +cache_size=$(($cache_size / 1073741824)) +echo "$status $n_groups groups, $cache_size GB" diff --git a/adei/check_adei_status.sh b/adei/check_adei_status.sh new file mode 120000 index 0000000..9d6920c --- /dev/null +++ b/adei/check_adei_status.sh @@ -0,0 +1 @@ +check_adei.sh \ No newline at end of file diff --git a/adei/lib b/adei/lib new file mode 120000 index 0000000..5bf80bf --- /dev/null +++ b/adei/lib @@ -0,0 +1 @@ +../lib/ \ No newline at end of file diff --git a/adei/scripts b/adei/scripts new file mode 120000 index 0000000..adb0a1d --- /dev/null +++ b/adei/scripts @@ -0,0 +1 @@ +../scripts/ \ No newline at end of file diff --git a/adei/security b/adei/security new file mode 120000 index 0000000..9ab7f9c --- /dev/null +++ b/adei/security @@ -0,0 +1 @@ +../security/ \ No newline at end of file diff --git a/adei/setup b/adei/setup new file mode 120000 index 0000000..f4c6f52 --- /dev/null +++ b/adei/setup @@ -0,0 +1 @@ +../setup/ \ No newline at end of file -- cgit v1.2.3