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 + init/configure_ipmi.sh | 18 +++ lib/adei/adei.sh | 287 +++++++++++++++++++++++++++++++++++++++++++++ lib/adei/adei_error.sh | 74 ++++++++++++ lib/adei/adei_print.sh | 25 ++++ lib/adei/adei_version.sh | 51 ++++++++ lib/helpers.sh | 9 ++ lib/nagios/nagios.sh | 125 ++++++++++++++++++++ lib/remote/README.txt | 34 ++++++ lib/remote/print.sh | 168 ++++++++++++++++++++++++++ lib/remote/report.sh | 51 ++++++++ lib/remote/run.sh | 13 ++ lib/remote/status.sh | 196 +++++++++++++++++++++++++++++++ nagios/check_ | 6 + nagios/check_adei | 6 + nagios/check_adei_control | 1 + nagios/check_adei_source | 1 + nagios/check_adei_status | 1 + nagios/check_by_ssh | 12 ++ nagios/check_mysql | 1 + nagios/check_ntp | 1 + nagios/check_ntp_win | 1 + nagios/check_ping | 1 + nagios/lib | 1 + nagios/scripts | 1 + nagios/security | 1 + nagios/setup | 1 + netstat.conf | 18 +-- remote/adei.sh | 10 +- remote/check_all.sh | 2 +- remote/check_kit.sh | 2 +- remote/darksoft.sh | 2 +- remote/ipeserv.sh | 2 +- remote/kaas.sh | 2 +- remote/lib | 1 + remote/lib/README.txt | 34 ------ remote/lib/parameters.sh | 10 -- remote/lib/print.sh | 168 -------------------------- remote/lib/report.sh | 51 -------- remote/lib/run.sh | 13 -- remote/lib/status.sh | 196 ------------------------------- remote/logs.sh | 2 +- remote/netstat.sh | 2 +- remote/news.sh | 2 +- remote/setup | 1 + remote/todo.sh | 2 +- scripts/run_conky.sh | 2 +- service/check_adei.sh | 130 +------------------- service/check_distcc.sh | 37 ++++++ service/lib | 1 + service/scripts | 1 + service/security | 1 + service/setup | 1 + setup/adei.txt | 6 + setup/domains.txt | 2 + setup/parameters.sh | 5 + setup/remote.sh | 10 ++ setup/ssh_ports.txt | 1 + setup/ssh_users.txt | 1 + 66 files changed, 1523 insertions(+), 623 deletions(-) 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 create mode 100644 init/configure_ipmi.sh create mode 100644 lib/adei/adei.sh create mode 100644 lib/adei/adei_error.sh create mode 100644 lib/adei/adei_print.sh create mode 100644 lib/adei/adei_version.sh create mode 100644 lib/helpers.sh create mode 100755 lib/nagios/nagios.sh create mode 100644 lib/remote/README.txt create mode 100644 lib/remote/print.sh create mode 100644 lib/remote/report.sh create mode 100644 lib/remote/run.sh create mode 100644 lib/remote/status.sh create mode 100755 nagios/check_ create mode 100755 nagios/check_adei create mode 120000 nagios/check_adei_control create mode 120000 nagios/check_adei_source create mode 120000 nagios/check_adei_status create mode 100755 nagios/check_by_ssh create mode 120000 nagios/check_mysql create mode 120000 nagios/check_ntp create mode 120000 nagios/check_ntp_win create mode 120000 nagios/check_ping create mode 120000 nagios/lib create mode 120000 nagios/scripts create mode 120000 nagios/security create mode 120000 nagios/setup create mode 120000 remote/lib delete mode 100644 remote/lib/README.txt delete mode 100644 remote/lib/parameters.sh delete mode 100644 remote/lib/print.sh delete mode 100644 remote/lib/report.sh delete mode 100644 remote/lib/run.sh delete mode 100644 remote/lib/status.sh create mode 120000 remote/setup mode change 100755 => 120000 service/check_adei.sh create mode 100755 service/check_distcc.sh create mode 120000 service/lib create mode 120000 service/scripts create mode 120000 service/security create mode 120000 service/setup create mode 100644 setup/adei.txt create mode 100644 setup/domains.txt create mode 100644 setup/parameters.sh create mode 100644 setup/remote.sh create mode 100644 setup/ssh_ports.txt create mode 100644 setup/ssh_users.txt 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 diff --git a/init/configure_ipmi.sh b/init/configure_ipmi.sh new file mode 100644 index 0000000..b0dc0fa --- /dev/null +++ b/init/configure_ipmi.sh @@ -0,0 +1,18 @@ +function configure_ipmi_user { + host="$1" + pass="$2" + echo "Configuring: $host" + /usr/bin/ipmitool -I lanplus -H "$host" -U ADMIN -P "$pass" user set name 3 nagios + /usr/bin/ipmitool -I lanplus -H "$host" -U ADMIN -P "$pass" user set password 3 _iosnag_ + /usr/bin/ipmitool -I lanplus -H "$host" -U ADMIN -P "$pass" user priv 3 4 + /usr/bin/ipmitool -I lanplus -H "$host" -U ADMIN -P "$pass" user enable 3 + /usr/bin/ipmitool -I lanplus -H "$host" -U ADMIN -P "$pass" user list 1 +} + +#for host in 192.168.26.{152,155,156}; do +# configure_ipmi_user "$host" 'ipepdv' +#done + +for host in 192.168.26.160; do + configure_ipmi_user "$host" '$ipepdv$' +done diff --git a/lib/adei/adei.sh b/lib/adei/adei.sh new file mode 100644 index 0000000..3a0aeb6 --- /dev/null +++ b/lib/adei/adei.sh @@ -0,0 +1,287 @@ +cd $(dirname $0) + +MAX_SOURCE_OFFSET=3600 +MAX_MASTER_OFFSET=300 +MAX_SLAVE_OFFSET=300 + +adei_default_timeout=${default_timeout:-120} + +. lib/adei/adei_version.sh +. lib/adei/adei_print.sh +. lib/adei/adei_error.sh +. lib/nagios/nagios.sh + +shopt -s nocasematch; + +# Auth with redirect (-L/--location-trusted) not working. Credentials are lost on hops. +function adei_query { + local resp + local timeout=${3:-$adei_default_timeout} + + local err=0 + if [ "$2" == "ecode" ]; then + url="$1&mysql=master" +# resp=$(curl --proxy "" -f -m "$timeout" "$url" 2>&1 | grep "returned error") + resp=$(curl --proxy "" --location-trusted -sf -m "$timeout" -w "%{http_code}" -o /dev/null "$url" 2>&1); + [ -z "$resp" -o "$resp" = "000" ] && resp="10" # error code 1 + elif [ "$2" == "emsg" ]; then + url="$1&mysql=master" + resp=$(curl --proxy "" --location-trusted -f -m "$timeout" "$url" 2>&1 | grep -o "curl.*") + [ -z "$resp" ] && resp="No response from" + else + if [ "$2" == "slave" ]; then + url="$1&mysql=slave" + else + url="$1&mysql=master" + fi + + + resp=$(curl --proxy "" --location-trusted -sf -m "$timeout" "$url"); err=$? + if [ $err -ne 0 ]; then + resp=$(adei_query "$1" "ecode" "$timeout") + err=$(($(($resp / 10)) + $(($resp % 10)))) + + resp=$(adei_query "$1" "emsg" "$timeout") + + [ -n "$debug" ] && echo "$(date) $timeout Failed $url" >> /tmp/adei.log + else + [ -n "$debug" ] && echo "$(date) $timeout OK $url" >> /tmp/adei.log + fi + fi + + echo -n $resp + return $err +} + +function adei_format_query { + local with_auth="${1:-1}" + local query="$2" + local timeout=${3:-$adei_default_timeout} + local source=${4:-"$adei_source"} + local url="${5:-$adei_url}" + + auth="" + [ $with_auth -gt 0 ] && auth="$adei_auth" + if [[ "$query" =~ \? ]]; then + echo "http://${auth}${url}/${query}${source}" + else + echo "http://${auth}${url}/${query}?xxxxx${source}" + fi +} + +function adei_simple_query { + local req=$(adei_format_query 1 "$@") + adei_query "$req" "master" "$timeout"; err=$? + return $err +} + +function adei_text_query { + local out # Local on the same string breaks error reporting + out="$(adei_simple_query "$@")"; local err=$? + + if [ $err -gt 0 -o -z "$out" ]; then +# echo "Error sending ADEI request: $(adei_format_query 0 "$@")" + [ $err -eq 0 ] && local err=1 + [ -n "$out" ] && echo -n "$out" + return $err + elif [[ "$out" =~ "Error:" ]]; then + echo -n "$out" + return 7 + else + echo -n "$out" + return 0 + fi +} + +function adei_xml_query { + local out # Local on the same string breaks error reporting + out="$(adei_simple_query "$@")"; local err=$? + + if [ $err -ne 0 -o -z "$out" ]; then +# echo "Error sending ADEI request: $(adei_format_query 0 '$@')" + [ $err -eq 0 ] && err=1 + [ -n "$out" ] && echo "$out" + return $err + fi + + local xml="$(echo "$out" | xmllint --format - 2>/dev/null)" + if [ $err -ne 0 -o -z "$out" ]; then + echo "$out" + if [[ "$out" =~ "Error:" ]]; then + return 7 + else + return 4 + fi + fi + + error=$(echo "$xml" | grep "") + if [ -n "$error" ]; then + echo $error | sed -e "s|||g" + return 7 + fi + + echo "$xml" + return $err +} + +function adei_value_query { + local out # Local on the same string breaks error reporting + out="$(adei_xml_query "$@")"; local err=$? + [ $err -ne 0 ] && { echo "$out"; return $err; } + + local values + values="$(echo "$out" | grep "Value")"; err=$? + [ $err -ne 0 ] && return 6 + + echo "$values" +} + + +function adei_get_databases { + local out + out="$(adei_xml_query "list.php?target=databases" "$@")" + [ $err -gt 0 ] && { echo -n "$out"; return $err; } + echo "$out" | grep "Value" | sed -e "s/^.*db_name=\"\([^\"]*\)\".*$/\\1/" | sed -e "s/ /::space::/" +} + +function adei_query_version { + local version # Local on the same string breaks error reporting + + version="$(adei_text_query "info.php?target=version&encoding=text" "$@")"; local err=$? + [ $err -gt 0 ] && { echo "$version"; return $err; } + + adei_version="$version" + + adei_revision=$(echo $adei_version | cut -d '-' -f 1) + if [ "$adei_revision" == "$adei_version" ]; then + adei_date="" + else + adei_date=$(echo $adei_version | cut -d '-' -f 2) + fi +} + +function adei_resolve_id { + fn="$1" + id="$2" + host="$3" + setup="$4" + + local var=$(cat "$fn" | grep "^$id" | awk '{ print $2 }') + [ -z "$var" -a -n "$host" ] && var=$(cat "$fn" | grep "^$host" | awk '{ print $2 }') + [ -z "$var" -a -n "$setup" ] && var=$(cat "$fn" | grep "^$setup" | awk '{ print $2 }') + + [ -n "$debug" ] && echo "$(date) resolved ($var) from $fn (id=$id, host=$host, setup=$setup) pwd ($(pwd))" >> /tmp/resolv.log + echo "$var" +} + +function adei_init_ { + local id="$1" && shift # Either URL or [setup]@[host] +# local url="$1" && shift + local server="$1" && shift + local database="$1" && [[ ! "$server" =~ \&|= ]] && shift + adei_args=( "$@" ) + + [ -z "$id" ] && { echo "ADEI ID is not specified" && exit 8 ; } + + + local url + local host + local setup + if [[ $id =~ http.*:// ]]; then # url + url="$id" + host="$(echo ${url#http*://} | cut -d '/' -f 1)" # parse port, maybe + + unset $setup + elif [[ $id =~ : ]]; then # [setup@]host + local seho + IFS='@' read -ra seho <<< "$id" && shift + host="${seho[1]:-${seho[0]}}" # parse port, for sure + setup="${seho[1]:+${seho[0]}}" + + unset $url + else # [setup]@[host] or both, no port + local seho + IFS='@' read -ra seho <<< "$id" && shift # techincally we can try to resolve to decide which is which + + host="${seho[1]:-${seho[0]}}" # This could be mixed up, but it is either not important, or correct, or misconfigured anyway + setup="${seho[1]:+${seho[0]}}" # Only error if only setup is provided. But we handle it in resolution code which agnostic and treats them as ids + + url=$(adei_resolve_id "setup/adei.txt" "$id" "$host" "$setup") + + if [ -n "$url" ]; then # Get URL, now we can determine host correctly and ignore the ids. + host="$(echo ${url#http*://} | cut -d '/' -f 1)" + unset $setup + else # only 'setup' is not allowed if URL is not configured, so it should be host (or error in configuration) + unset $url # so either we have both (correctly) or only host (correctly) + fi + fi + + local hopo + IFS=':' read -ra hopo <<< "$host" && shift + host="${hopo[0]}" # only non fqdn if also url not set + port=":${hopo[1]:-80}" + [ $port = ":80" ] && port="" + + local fqdn + if [ -z "$url" ]; then + url=$(adei_resolve_id "setup/adei.txt" "$id" "$host" "$setup") + if [ -n "$url" ]; then + fqdn="$(echo ${url#http*://} | cut -d '/' -f 1)" + + IFS=':' read -ra hopo <<< "$fqdn" && shift + host="${hopo[0]}" # again fqdn + port=":${hopo[1]:-80}" + [ $port = ":80" ] && port="" + else + fqdn=$(resolve_fqdn "$host") # this may be not fqdn + [ -n "$fqdn" ] && host="$fqdn" + url="${host}${port}/adei" + fi + fi + + # In some case we miss here "setup", but surely then the password is resolved host-based + adei_auth=$(adei_resolve_id "security/adei.txt" "$id" "$host" "$setup") + [ -n "$adei_auth" ] && adei_auth="$adei_auth@" + + # Now check port + adei_online=$(scripts/ping.pl "$host" "$port") + [ $adei_online -ne 1 ] && return 2 + + # Now build ADEI url + + adei_setup="$setup" + adei_host="$host" + adei_port="$port" + adei_url="${url#http*://}/services" + + + adei_query_version; local err=$? + [ $err -gt 0 ] && return $err + + + if [[ "$server" =~ \&|= ]]; then + adei_source="&$server" + else + adei_source="" + [ -n "$adei_setup" -a "$adei_setup" != "*" ] && adei_source+="&setup=$adei_setup" + [ -n "$server" -a "$server" != "-" ] && adei_source+="&db_server=$server" + + if [ "$database" == "#1" ]; then + databases="$(adei_get_databases)"; err=$? + [ $err -gt 0 ] && { echo "Failed to query ADEI databases: $databases"; return $err; } + [ -z "$databases" ] && { echo "No databases reported by ADEI"; return 6; } + database=$(echo "$databases" | head -n 1) + fi + + [ -n "$database" -a "$database" != "-" ] && adei_source+="&db_name=$database" + fi + + return 0 +} + +function adei_init { + adei_init_ "$@"; local code=$? + + adei_healthy=$(($code == 0)) + adei_process_error "$code" "" "*" "$(adei_print_status "$0" $adei_online $adei_healthy)" +} diff --git a/lib/adei/adei_error.sh b/lib/adei/adei_error.sh new file mode 100644 index 0000000..9de4795 --- /dev/null +++ b/lib/adei/adei_error.sh @@ -0,0 +1,74 @@ +# Error codes: 1 - unknown network, 2 - unreachable, 3 - timeout, 4 - invalid XML/JSON, 5 - parsing error, 6 - set is empty, 7 - service reported error, 8 - parameter error, 9 - unknown, 10-59 - HTTP errors +# http code (xyz) is converted to error code (xz), e.g. 404 -> 44 + +function adei_format_http_error { + err=$1 + echo -n "$(($err / 10))0$(($err % 10))" +} + +# Returns 1 if printing text is recommended +function adei_print_error { + local ret=0 + local code=${1:-0} + local text="$2" + + local service="${3#\*}" + service="${service:-ADEI}" + + local msg + if [ $code -ge 30 -a $code -lt 60 ]; then + msg="HTTP Error: $(adei_format_http_error $code)" + [ $code -eq 41 ] && msg+=" (Authentication Requested)" + [ $code -eq 43 ] && msg+=" (Access Denied)" + elif [ $code -ge 20 -a $code -lt 30 ]; then + msg="HTTP Status: $(adei_format_http_error $code)" + ret=1 + elif [ $code -eq 1 ]; then + msg="Error communicating with $service" + ret=1 + elif [ $code -eq 2 ]; then + msg="ADEI host ($adei_host:$adei_port) unreachable" + elif [ $code -eq 3 ]; then + msg="Timeout waiting for $service" + elif [ $code -eq 4 ]; then + msg="Non-XML response from $service" + ret=1 + elif [ $code -eq 5 ]; then + msg="Error parsing response from $service" + ret=1 + elif [ $code -eq 6 ]; then + msg="Empty response from $service" + ret=1 + elif [ $code -eq 7 ]; then + rep="$(echo "$text" | head -n 1 | sed 's/Error:\?[[:space:]]\+//i')" + if [ ${#rep} -lt 40 ]; then + msg="$service Error: $rep" + else + msg="$service returned a error" + ret=1 + fi + elif [ $code -eq 8 ]; then + msg="Invalid parameter" + else + msg="Unknown Error $code while accessing $service" + fi + + echo -n "$msg" + return $ret +} + +function adei_process_error { + local code=${1:-0}; shift + local text="$1"; shift + local service="$1"; shift + local status="${1:-0}" + + if [ $code -ne 0 ]; then + local msg # local on the same line break error reporting + msg="$(adei_print_error $code "$text" "$service")" + [ $? -eq 1 ] && echo "$text" + echo "$status $msg" + exit + fi +} + diff --git a/lib/adei/adei_print.sh b/lib/adei/adei_print.sh new file mode 100644 index 0000000..aca7735 --- /dev/null +++ b/lib/adei/adei_print.sh @@ -0,0 +1,25 @@ +function adei_print_status { + cmd="$1" + online="$2" + healthy="$3" + + if [[ "$cmd" =~ check_adei_ ]]; then + echo "$healthy" + else + echo "$online $healthy" + fi +} + +function format_time { + offset=$1 + if [ $offset -ge 86400 ]; then + echo "$((offset / 86400))d" + elif [ $offset -ge 3600 ]; then + echo "$((offset / 3600))h" + elif [ $offset -ge 60 ]; then + echo "$((offset / 60))m" + else + echo "${offset}s" + fi +} + diff --git a/lib/adei/adei_version.sh b/lib/adei/adei_version.sh new file mode 100644 index 0000000..b71b1e1 --- /dev/null +++ b/lib/adei/adei_version.sh @@ -0,0 +1,51 @@ +vercomp() { + if [[ $1 == $2 ]] + then + return 0 + fi + local IFS=. + local i ver1=($1) ver2=($2) + # fill empty fields in ver1 with zeros + for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) + do + ver1[i]=0 + done + for ((i=0; i<${#ver1[@]}; i++)) + do + if [[ -z ${ver2[i]} ]] + then + # fill empty fields in ver2 with zeros + ver2[i]=0 + fi + if ((10#${ver1[i]} > 10#${ver2[i]})) + then + return 1 + fi + if ((10#${ver1[i]} < 10#${ver2[i]})) + then + return 2 + fi + done + return 0 +} + +adei_version_check() { + vercomp $adei_revision $1 + res=$? + if [ $res -eq 1 ]; then + return 0 + elif [ $res -eq 2 ]; then + return 1; + fi + + if [ -z "$2" -o -z "$adei_date" ]; then + return 0 + fi + + if [ $adei_date -ge $2 ]; then + return 0 + fi + + return 1 +} + diff --git a/lib/helpers.sh b/lib/helpers.sh new file mode 100644 index 0000000..b562eb6 --- /dev/null +++ b/lib/helpers.sh @@ -0,0 +1,9 @@ +function in_array() { + local hay needle=$1 + shift + for hay; do + [[ $hay == $needle ]] && return 0 + done + + return 1 +} diff --git a/lib/nagios/nagios.sh b/lib/nagios/nagios.sh new file mode 100755 index 0000000..40631c1 --- /dev/null +++ b/lib/nagios/nagios.sh @@ -0,0 +1,125 @@ +cd $(dirname "$0") + +. setup/parameters.sh + +function nagios_find_host { + echo "$@" | grep -oP '\-H\s*\K[^\s]*' +} + +function find_host_param { + local id="$1" && shift + local pname="$1" && shift + local defval="$1" && shift + + local val=$(cat setup/${pname}.txt | grep -P "^$id" | awk '{ print $2 }') + [ -n "$val" ] || val="$defval" + + echo -n "$val" +} + +function nagios_find_host_param { + local pname="$1" && shift + local defval="$1" && shift + local host=$(nagios_find_host "$@") + + find_host_param "$host" "$pname" "$defval" +} + +function resolve_fqdn { + local host="$1" && shift + + if [[ ! $host =~ \. ]]; then + local domain=$(find_host_param "$host" domains "$default_domain") + host+=".$domain" + fi + + echo -n $host +} + +function resolve_ip { + local host="$1" && shift + + if [[ ! "$host" =~ ^[[:digit:]] ]]; then + local fqdn=$(resolve_fqdn "$host") + host=$(dig +short "$fqdn" A | head -n 1 | tr -d '\n') + if [ $? -ne 0 -o -z "$host" ]; then + echo "DNS resolution for host ($fqdn) failed: $(dig +short "$fqdn" A 2>&1)" + exit 2 + fi + fi + + echo -n "$host" +} + +function nagios_run { + if [[ "$1" =~ ^- ]]; then + cmd=${nagios_plugins}/$(basename $0) + else + cmd=$1 && shift + [[ "$cmd" =~ ^/ ]] || cmd="${nagios_plugins}/$cmd" + fi + + ARGS="" + while [[ $# -gt 0 ]]; do + key="$1" && shift + + case "$key" in + -H) + host="$1" && shift + ip=$(resolve_ip "$host") + if [ $? -eq 0 -a -n "$ip" ]; then + ARGS+=" ${key} $ip" + else + echo "$ip" + exit $? + fi + ;; + *) + ARGS+=" $key" + esac + done + + [ -n "$debug" ] && echo "$(date) $cmd" "$ARGS" >> /tmp/nagios.log + eval "$cmd" "$ARGS" +} + +function nagios_parse { + cmd="$1"; shift + + output=$($cmd "$@") + exit_code=$? + + if [ $exit_code -eq 0 ]; then + last_line=$(echo "$output" | tail -1) + + status=$(echo $last_line | cut -d ' ' -f 1) + [[ "$status" =~ ^[0-9]$ ]] || status=0 + echo -n ${last_line#$status} + else + status=0 + fi + + if [ $status -ne 1 ]; then + echo -n " -- " + + lines=$(echo "$output" | sed '/^[[:space:]]*$/d' | wc -l) + if [ $lines -gt 1 ]; then + echo "$output" | sed '/^[[:space:]]*$/d' | head -n 1 | tr -d '\n' + echo " ... " + echo "------------------" + echo "$output" | head -n -1 + else + echo "$output" | sed '/^[[:space:]]*$/d' | head -n -1 + fi + else + echo + fi + + if [ "$status" -eq 0 ]; then + exit "2" + elif [ "$status" -eq 1 ]; then + exit "0" + else + exit "1" + fi +} diff --git a/lib/remote/README.txt b/lib/remote/README.txt new file mode 100644 index 0000000..c5998f8 --- /dev/null +++ b/lib/remote/README.txt @@ -0,0 +1,34 @@ +conky format +============ + - Server status + * ping works + * no output from 'check_server_status.sh' and additional listed checks + [*] Checks for additional listed services 'check__status.sh'. + - The optional status is in the beginning of first line (0 - red, 1 - green, 2 - yellow). Otherwise, 'red' if any output (also if first word is non-number on the first string). + - If first line starts from the status, the rest of the line is considered a header and reported on the status line. Everything else goes to textual section bellow. + [headers] + + ... Textual information reported by 'check_server_status.sh' and check_*_status.sh scripts. The format + server:port[:service] text.... + + - Extra info for DarkSoft servers + * VPN to the server is working (checked with the ping). This not included in the scripted version, instead server traffic reported directly here. + # # Traffic on VPN interface from/to + + - Server traffic + in/out/forw. Yellow/Red if above specified threshold. No additional errors are reported here. + + - Services (operated by local scripts in 'services' directory) + * Online + * Healthy + [headers] Information about service operation + [errors] Short information on critical errors are reported here (in conky, we push everything in the text section) + + ... Larger textual information about the problems. + + + Service format is following (status is on the last line and mandatory): + * Critical Lines starting with '*' contain critical errors and highlighted (remote) / reported in the service table (conky) + Text This is normal problem description reported in the textual area + # # [header] Two statuses (0 - error, 1 - ok, 2 - warning) and optional header with information about service operation + \ No newline at end of file diff --git a/lib/remote/print.sh b/lib/remote/print.sh new file mode 100644 index 0000000..a0fdcbe --- /dev/null +++ b/lib/remote/print.sh @@ -0,0 +1,168 @@ +# underlines 4;30,... blinking 5:30,... +# backgrounds: 40,... + +declare -A colors=( + [black]='0;30' + [red]='0;31' + [green]='0;32' + [orange]='0;33' + [blue]='0;34' + [purple]='0;35' + [cyan]='0;36' + [lightgray]='0;37' + [gray]='1;30' + [lightred]='1;31' + [lightgreen]='1;32' + [yellow]='1;33' + [lightblue]='1;34' + [lightpurple]='1;35' + [lightcyan]='1;36' + [white]='1;37' +) + +background="" +foreground="" + + + + +# Fixing color map +#echo -ne "\e[44m" +#echo -ne '\x1B[K' + +function set_background { + if [ -n "$background" ]; then + echo -ne "$background" + echo -ne '\x1B[K' + fi +} + +function set_color { + local color=${1:-""} + local effect=${2:-""} + + c=${colors[$color]} + + + case "$effect" in + 'u') + c=$(echo $c | sed -r "s/^0/4/ ; s/^1/1;4/") + ;; + esac + + [ -n "$color" ] && echo -ne "\033[${c}m" + set_background +} + +function reset_color { + echo -ne "\033[0m" + + set_background + [ -n "$foreground" ] && set_color "$foreground" +} + +function finish { + echo -ne "\033[0m" + echo +} + +function configure_palete { + case $1 in + blue) + background="\e[1;44m" + foreground="white" + ;; + *) + # Lightgray and Yellow are almost invisible on white + colors[yellow]=${colors[orange]} + colors[white]=${colors[black]} + colors[lightgray]=${colors[gray]} + colors[cyan]=${colors[blue]} + ;; + esac + + set_background + reset_color +} + +function decorate { + local output="$1" + local color=${2:-""} + local effect=${3:-""} + + if [ -n "$color" ]; then + set_color $color $effect + echo -ne "${output}" + reset_color + else + echo -ne "$output" + fi +} + +function eol { + sed 's/$/\x1B[K/' +} + +function print_eol { + echo -e '\x1B[K' +} + + + +function print { + local output="$1" + local color=${2:-""} + local char_limit=${3:-$fold} + local line_limit=${4:-0} + + local cmd="decorate \"${output}\" \"$color\" | fold -s -w $char_limit" + [ $line_limit -gt 0 ] && cmd="$cmd | head -n $line_limit" + + eval "$cmd" | eol +} + + +function print_hline { + local color=${1:-"gray"} + local cols=${COLUMNS:-$(tput cols)} + + decorate $(printf '%*s' $cols '' | tr ' ' -) "$color" + echo | eol +} + +function print_table { + # The problem here is that all escapes for colors are treated as normal visible symbols + sed "s/ ::: /@/g" | column -t -s "@" -o " " | eol +} + +function decorate_table { + print_hline + cat - + print_hline +} + +function print_status { + local status="$1" + + if [[ $status =~ ^.$ ]]; then + case $status in + 0) + decorate "*" "red" + ;; + 1) + decorate "*" "green" + ;; + 2) + decorate "*" "yellow" + ;; + *) + decorate "$status" "red" + ;; + esac + else + decorate "?" "red" + fi + echo -n " " +} + +clear diff --git a/lib/remote/report.sh b/lib/remote/report.sh new file mode 100644 index 0000000..e6766a4 --- /dev/null +++ b/lib/remote/report.sh @@ -0,0 +1,51 @@ +function simple_report { + local generator="$1" + local filter="${2:-cat}" + { + eval "$generator 12>/dev/fd/12 | $filter" + report=$(cat<&12) + } 12<&1 ) + + case "$service" in + 'traffic') + check_server_traffic "$result" "$@" + ;; + *) + print "$result" + esac + +} + + +function check_server_status { + local hopo + IFS=':' read -ra hopo <<< $1 && shift + local host=${hopo[0]} + local port=${hopo[1]:-22} + local services="$@" + + local ping_output=$(scripts/ping.pl $host $port $timeout) + print_status "$ping_output" + + if [ "$services" == "-" ]; then return; fi + + if [ "$ping_output" == "1" ]; then + local output=$(ssh $ssh_params -p $port root@$host /opt/scripts/check_server_status.sh 2>&1) + + local status=1 + [ -n "$output" ] && status=0 && output="\n$(decorate "$host:$port" "cyan" "u")\n$output\n" + print_status $status + + # Check Additional services, error is reported if anything provides information + local headers="" + if [ -n "$services" ]; then + for service in "$services"; do + if [[ "$service" =~ ^vpn/(.*)$ ]]; then + local ip=${BASH_REMATCH[1]} + [ $(hostname) == "styx" ] && check_server_status "$ip" "-" + else + local service_status=1 + local service_output=$(ssh $ssh_params -p $port root@$host /opt/scripts/check_${service}_status.sh 2>&1 | sed 's/^[[:space:]]*//;/^$/d') + if [ -n "$service_output" ]; then + first_line=$(echo "$service_output" | head -n 1) + if [[ "$first_line" =~ ^([0-9]+)[[:space:]](.*)$ ]]; then + service_status=${BASH_REMATCH[1]} + service_output=$(sed "1 d" <<< "$service_output") + if [ -n "${BASH_REMATCH[2]}" ]; then + service_header=$(sed -r "s/\\$\{color\s+([^}]*)\}/\$(set_color \\1)/g" <<< "${BASH_REMATCH[2]}") #" + headers="$headers $service_header" + fi + else + service_status=0 + fi + + if [ -n "$service_output" ]; then + [ -z "$output" ] && output="\n$(decorate "$host:$port" "cyan" "u")" + output="${output}\n $(decorate "$service" "gray" "u")\n$(echo ${service_output} | sed 's/^/ /')" + fi + fi + fi + + done + fi + + print " ::: ${headers}" + #report="$report
$output" + if [ -n "$output" ]; then + flock -x $0 echo "${output}" >&12 + fi + else + print_status "x" + for service in "$services"; do + print_status "x" + done + fi +} + +function check_service { + local service="$1" && shift + local id="$1" && shift + local args="$@" + + local output=$(service/check_${service}.sh ${id} "$@" 2>&1 | sed 's/^[[:space:]]*//;/^$/d') + + local info=$(echo "$output" | tail -n 1) + + local online=0 + local health=0 + local header="" + if [[ "$info" =~ ^([0-9]+)[[:space:]]+([0-9]+)[[:space:]]+(.*)$ ]]; then + online=${BASH_REMATCH[1]} + health=${BASH_REMATCH[2]} + header=${BASH_REMATCH[3]} + + output=$(sed '$ d' <<< "$output") + fi + + print_status "$online" + print_status "$health" + + header=$(sed -r "s/\\$\{color\s+([^}]*)\}/\$(set_color \\1)/g" <<< "$header") # " + print " ::: ${header}" + + + important=$(grep "^\*" <<< "$output") + messages=$(grep -v "^\*" <<< "$output") + + if [ -n "$output" ]; then + output="\n$(decorate "$service:$id" "cyan" "u")\n$important\n$(set_color gray)$messages$(reset_color)\n" + flock -x $0 echo "${output}" >&12 + fi +} + + +function check__ { + local args + local title="$1" && shift + read -ra args <<< "$1" && shift + local host=${args[0]}; + + print "$(decorate $title "purple") ::: " | sed -r "s/\\$\{color\s+([^}]*)\}/\$(set_color \\1)/g; " + + local service + for service in "$@"; do + service=$(sed -r "s/<([0-9]+)>/\${args[\\1]}/g; s/<([^>]+)>/\${\\1}/g" <<< "$service") # " + ( eval "$service" ) + done + print_eol +} + +function check_ { + # Buffer the output + local output=$(check__ "$@") + echo -e "$output" +} + +function check { + if [ $parallel -gt 0 ]; then + check_ "$@" & + else + check_ "$@" + fi +} diff --git a/nagios/check_ b/nagios/check_ new file mode 100755 index 0000000..839e9c1 --- /dev/null +++ b/nagios/check_ @@ -0,0 +1,6 @@ +#! /bin/bash + +. $(dirname $0)/lib/nagios/nagios.sh + +nagios_run "$@" + diff --git a/nagios/check_adei b/nagios/check_adei new file mode 100755 index 0000000..ba0a34f --- /dev/null +++ b/nagios/check_adei @@ -0,0 +1,6 @@ +#!/bin/bash + +. $(dirname $0)/lib/nagios/nagios.sh + +[ -n "$debug" ] && echo "$(date) adei/$(basename $0).sh" "$@" >> /tmp/nagios.log +nagios_parse "adei/$(basename $0).sh" "$@" diff --git a/nagios/check_adei_control b/nagios/check_adei_control new file mode 120000 index 0000000..c07768e --- /dev/null +++ b/nagios/check_adei_control @@ -0,0 +1 @@ +check_adei \ No newline at end of file diff --git a/nagios/check_adei_source b/nagios/check_adei_source new file mode 120000 index 0000000..c07768e --- /dev/null +++ b/nagios/check_adei_source @@ -0,0 +1 @@ +check_adei \ No newline at end of file diff --git a/nagios/check_adei_status b/nagios/check_adei_status new file mode 120000 index 0000000..c07768e --- /dev/null +++ b/nagios/check_adei_status @@ -0,0 +1 @@ +check_adei \ No newline at end of file diff --git a/nagios/check_by_ssh b/nagios/check_by_ssh new file mode 100755 index 0000000..1a488b2 --- /dev/null +++ b/nagios/check_by_ssh @@ -0,0 +1,12 @@ +#! /bin/bash + +. $(dirname $0)/lib/nagios/nagios.sh + + +port=$(nagios_find_host_param "ssh_ports" 22 "$@") +user=$(nagios_find_host_param "ssh_users" root "$@") + +local port=$(cat setup/ssh_ports.txt | grep -P "^$host" | awk '{ print $2 }') + +#echo "$@" -o " -p $port -l $user UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" >> /tmp/xxx +nagios_run "$@" -p $port -l $user -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" diff --git a/nagios/check_mysql b/nagios/check_mysql new file mode 120000 index 0000000..74fe9a3 --- /dev/null +++ b/nagios/check_mysql @@ -0,0 +1 @@ +check_ \ No newline at end of file diff --git a/nagios/check_ntp b/nagios/check_ntp new file mode 120000 index 0000000..74fe9a3 --- /dev/null +++ b/nagios/check_ntp @@ -0,0 +1 @@ +check_ \ No newline at end of file diff --git a/nagios/check_ntp_win b/nagios/check_ntp_win new file mode 120000 index 0000000..74fe9a3 --- /dev/null +++ b/nagios/check_ntp_win @@ -0,0 +1 @@ +check_ \ No newline at end of file diff --git a/nagios/check_ping b/nagios/check_ping new file mode 120000 index 0000000..74fe9a3 --- /dev/null +++ b/nagios/check_ping @@ -0,0 +1 @@ +check_ \ No newline at end of file diff --git a/nagios/lib b/nagios/lib new file mode 120000 index 0000000..5bf80bf --- /dev/null +++ b/nagios/lib @@ -0,0 +1 @@ +../lib/ \ No newline at end of file diff --git a/nagios/scripts b/nagios/scripts new file mode 120000 index 0000000..adb0a1d --- /dev/null +++ b/nagios/scripts @@ -0,0 +1 @@ +../scripts/ \ No newline at end of file diff --git a/nagios/security b/nagios/security new file mode 120000 index 0000000..9ab7f9c --- /dev/null +++ b/nagios/security @@ -0,0 +1 @@ +../security/ \ No newline at end of file diff --git a/nagios/setup b/nagios/setup new file mode 120000 index 0000000..f4c6f52 --- /dev/null +++ b/nagios/setup @@ -0,0 +1 @@ +../setup/ \ No newline at end of file diff --git a/netstat.conf b/netstat.conf index 54c1b24..96bb9f6 100644 --- a/netstat.conf +++ b/netstat.conf @@ -40,7 +40,7 @@ template8 900 #template0 ${if_match ${execi $template8 /etc/conky/scripts/ping.pl \1:3389} > 0}${color green}${else}${color red}${endif}*${color} #template0 ${lua_parse check_server_status \1 3389 -} template0 ${lua_parse check_server_status \1 22 -} -template1 ${lua_parse check_server_status \1 3306 -} +template1 ${lua_parse check_server_status \1 3632 -} lua_load /etc/conky/support.lua @@ -58,14 +58,18 @@ ${color white}ipekatrin2 ${goto 160}${lua_parse check_server_status ipekatrin2.i ${color white}ipekatrin3 ${goto 160}${lua_parse check_server_status ipekatrin3.ipe.kit.edu 22 uptime} ${color yellow}ADEI ${hr}${lua set_width $template2}${lua set_timeout $template3} -${color white}KaaS ${goto 160}${lua_parse check_service_ adei kaas adei-katrin.kaas.kit.edu/adei 'db_server=fpd&db_name=katrin_rep&db_group=0'}${color white} -# ${color white}ipekatrinadei ${goto 160}${lua_parse check_service_ adei katrin katrin.kit.edu/adei-katrin-orig 'db_server=fpd&db_name=katrin_rep&db_group=0'}${color white} -${color white}pcebessadei ${goto 160}${lua_parse check_service_ adei pcebess pcebessadei.competence-e.kit.edu/adei-battery}${color white} -${color white}ipemkmastadei ${goto 160}${lua_parse check_service_ adei imkmast imkmastadei.ka.fzk.de/adei}${color white} -# ${color white}itepmtadei ${goto 160}${lua_parse check_service_ adei itepmt itepmtadei.itep.kit.edu/adei}${color white} -${color white}CRD ${goto 160}${lua_parse check_service_ adei crd adei.crd.yerphi.am/adei}${color white} +${color white}KaaS ${goto 160}${lua_parse check_service_ adei kaas 'db_server=fpd&db_name=katrin_rep&db_group=0'}${color white} +${color white}pcebessadei ${goto 160}${lua_parse check_service_ adei pcebess}${color white} +${color white}ipemkmastadei ${goto 160}${lua_parse check_service_ adei imkmast}${color white} +${color white}CRD ${goto 160}${lua_parse check_service_ adei crd}${color white} + +${color yellow}Build Farm ${hr}${lua set_width $template2}${lua set_timeout $template3} +#${color white}Compute4 ${goto 160}${template0 192.168.21.1} ${template1 192.168.21.1}${color white} +${color white}Compute4 ${goto 160}${lua_parse check_service_ distcc ipepdvcompute4}${color white} + ${lua_parse print_server_errors $template8 conky_netstat} + ${color yellow}Network Connections ${hr} ${color white}Incomming connections${color gray}: ${execpi $template5 /etc/conky/scripts/netstat-in.sh | grep -v "android-d855cbd1c9f827d" | grep -v "pdv-time-capsule-2.ipe.kit.edu" | awk -e '{ print "${goto 18}", $1, "${goto 720} to", $2 }' } diff --git a/remote/adei.sh b/remote/adei.sh index 0b5c42d..c4ba109 100644 --- a/remote/adei.sh +++ b/remote/adei.sh @@ -1,12 +1,12 @@ #! /bin/bash -[ -z $report ] && source lib/status.sh +[ -z $report ] && source lib/remote/status.sh function check_adei { - check "KaaS" "kaas" "check_service adei adei-katrin.kaas.kit.edu/adei 'db_server=fpd&db_name=katrin_rep&db_group=0'" - check "BESS" "pcebess" "check_service adei pcebessadei.competence-e.kit.edu/adei-battery" - check "IMK" "imkmast" "check_service adei imkmastadei.ka.fzk.de/adei" - check "CRD" "crd" "check_service adei adei.crd.yerphi.am/adei" + check "KaaS" "kaas" "check_service adei 'db_server=fpd&db_name=katrin_rep&db_group=0'" + check "BESS" "pcebess" "check_service adei " + check "IMK" "imkmast" "check_service adei " + check "CRD" "crd" "check_service adei " } diff --git a/remote/check_all.sh b/remote/check_all.sh index da2b83f..a506c82 100755 --- a/remote/check_all.sh +++ b/remote/check_all.sh @@ -1,6 +1,6 @@ #! /bin/bash -. lib/status.sh +. lib/remote/status.sh report="short_report" diff --git a/remote/check_kit.sh b/remote/check_kit.sh index 9bdbeae..b50d5ce 100755 --- a/remote/check_kit.sh +++ b/remote/check_kit.sh @@ -1,6 +1,6 @@ #! /bin/bash -. lib/status.sh +. lib/remote/status.sh run kaas.sh run adei.sh diff --git a/remote/darksoft.sh b/remote/darksoft.sh index f8f6949..09823fa 100644 --- a/remote/darksoft.sh +++ b/remote/darksoft.sh @@ -1,6 +1,6 @@ #! /bin/bash -[ -z $report ] && source lib/status.sh +[ -z $report ] && source lib/remote/status.sh function check_darksoft { check "DarkSoft" "darksoft.org" "check_server_status vpn/192.168.21.1" "check_server_ traffic 20 50" diff --git a/remote/ipeserv.sh b/remote/ipeserv.sh index 9f314a1..a737912 100644 --- a/remote/ipeserv.sh +++ b/remote/ipeserv.sh @@ -1,6 +1,6 @@ #! /bin/bash -[ -z $report ] && source lib/status.sh +[ -z $report ] && source lib/remote/status.sh function check_ipe { check "katrin" "katrin.kit.edu" "check_server_status " diff --git a/remote/kaas.sh b/remote/kaas.sh index 5fc1b4a..37d6a5a 100644 --- a/remote/kaas.sh +++ b/remote/kaas.sh @@ -1,6 +1,6 @@ #! /bin/bash -[ -z $report ] && source lib/status.sh +[ -z $report ] && source lib/remote/status.sh function check_kaas { diff --git a/remote/lib b/remote/lib new file mode 120000 index 0000000..dc598c5 --- /dev/null +++ b/remote/lib @@ -0,0 +1 @@ +../lib \ No newline at end of file diff --git a/remote/lib/README.txt b/remote/lib/README.txt deleted file mode 100644 index c5998f8..0000000 --- a/remote/lib/README.txt +++ /dev/null @@ -1,34 +0,0 @@ -conky format -============ - - Server status - * ping works - * no output from 'check_server_status.sh' and additional listed checks - [*] Checks for additional listed services 'check__status.sh'. - - The optional status is in the beginning of first line (0 - red, 1 - green, 2 - yellow). Otherwise, 'red' if any output (also if first word is non-number on the first string). - - If first line starts from the status, the rest of the line is considered a header and reported on the status line. Everything else goes to textual section bellow. - [headers] - - ... Textual information reported by 'check_server_status.sh' and check_*_status.sh scripts. The format - server:port[:service] text.... - - - Extra info for DarkSoft servers - * VPN to the server is working (checked with the ping). This not included in the scripted version, instead server traffic reported directly here. - # # Traffic on VPN interface from/to - - - Server traffic - in/out/forw. Yellow/Red if above specified threshold. No additional errors are reported here. - - - Services (operated by local scripts in 'services' directory) - * Online - * Healthy - [headers] Information about service operation - [errors] Short information on critical errors are reported here (in conky, we push everything in the text section) - - ... Larger textual information about the problems. - - - Service format is following (status is on the last line and mandatory): - * Critical Lines starting with '*' contain critical errors and highlighted (remote) / reported in the service table (conky) - Text This is normal problem description reported in the textual area - # # [header] Two statuses (0 - error, 1 - ok, 2 - warning) and optional header with information about service operation - \ No newline at end of file diff --git a/remote/lib/parameters.sh b/remote/lib/parameters.sh deleted file mode 100644 index c172415..0000000 --- a/remote/lib/parameters.sh +++ /dev/null @@ -1,10 +0,0 @@ -# Configurable -timeout=2 -fold=120 -palete='blue' -parallel=0 -report="standart_report" - - -# Helpers -ssh_params="-x -q -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -o ConnectTimeout=$timeout" diff --git a/remote/lib/print.sh b/remote/lib/print.sh deleted file mode 100644 index a0fdcbe..0000000 --- a/remote/lib/print.sh +++ /dev/null @@ -1,168 +0,0 @@ -# underlines 4;30,... blinking 5:30,... -# backgrounds: 40,... - -declare -A colors=( - [black]='0;30' - [red]='0;31' - [green]='0;32' - [orange]='0;33' - [blue]='0;34' - [purple]='0;35' - [cyan]='0;36' - [lightgray]='0;37' - [gray]='1;30' - [lightred]='1;31' - [lightgreen]='1;32' - [yellow]='1;33' - [lightblue]='1;34' - [lightpurple]='1;35' - [lightcyan]='1;36' - [white]='1;37' -) - -background="" -foreground="" - - - - -# Fixing color map -#echo -ne "\e[44m" -#echo -ne '\x1B[K' - -function set_background { - if [ -n "$background" ]; then - echo -ne "$background" - echo -ne '\x1B[K' - fi -} - -function set_color { - local color=${1:-""} - local effect=${2:-""} - - c=${colors[$color]} - - - case "$effect" in - 'u') - c=$(echo $c | sed -r "s/^0/4/ ; s/^1/1;4/") - ;; - esac - - [ -n "$color" ] && echo -ne "\033[${c}m" - set_background -} - -function reset_color { - echo -ne "\033[0m" - - set_background - [ -n "$foreground" ] && set_color "$foreground" -} - -function finish { - echo -ne "\033[0m" - echo -} - -function configure_palete { - case $1 in - blue) - background="\e[1;44m" - foreground="white" - ;; - *) - # Lightgray and Yellow are almost invisible on white - colors[yellow]=${colors[orange]} - colors[white]=${colors[black]} - colors[lightgray]=${colors[gray]} - colors[cyan]=${colors[blue]} - ;; - esac - - set_background - reset_color -} - -function decorate { - local output="$1" - local color=${2:-""} - local effect=${3:-""} - - if [ -n "$color" ]; then - set_color $color $effect - echo -ne "${output}" - reset_color - else - echo -ne "$output" - fi -} - -function eol { - sed 's/$/\x1B[K/' -} - -function print_eol { - echo -e '\x1B[K' -} - - - -function print { - local output="$1" - local color=${2:-""} - local char_limit=${3:-$fold} - local line_limit=${4:-0} - - local cmd="decorate \"${output}\" \"$color\" | fold -s -w $char_limit" - [ $line_limit -gt 0 ] && cmd="$cmd | head -n $line_limit" - - eval "$cmd" | eol -} - - -function print_hline { - local color=${1:-"gray"} - local cols=${COLUMNS:-$(tput cols)} - - decorate $(printf '%*s' $cols '' | tr ' ' -) "$color" - echo | eol -} - -function print_table { - # The problem here is that all escapes for colors are treated as normal visible symbols - sed "s/ ::: /@/g" | column -t -s "@" -o " " | eol -} - -function decorate_table { - print_hline - cat - - print_hline -} - -function print_status { - local status="$1" - - if [[ $status =~ ^.$ ]]; then - case $status in - 0) - decorate "*" "red" - ;; - 1) - decorate "*" "green" - ;; - 2) - decorate "*" "yellow" - ;; - *) - decorate "$status" "red" - ;; - esac - else - decorate "?" "red" - fi - echo -n " " -} - -clear diff --git a/remote/lib/report.sh b/remote/lib/report.sh deleted file mode 100644 index e6766a4..0000000 --- a/remote/lib/report.sh +++ /dev/null @@ -1,51 +0,0 @@ -function simple_report { - local generator="$1" - local filter="${2:-cat}" - { - eval "$generator 12>/dev/fd/12 | $filter" - report=$(cat<&12) - } 12<&1 ) - - case "$service" in - 'traffic') - check_server_traffic "$result" "$@" - ;; - *) - print "$result" - esac - -} - - -function check_server_status { - local hopo - IFS=':' read -ra hopo <<< $1 && shift - local host=${hopo[0]} - local port=${hopo[1]:-22} - local services="$@" - - local ping_output=$(scripts/ping.pl $host $port $timeout) - print_status "$ping_output" - - if [ "$services" == "-" ]; then return; fi - - if [ "$ping_output" == "1" ]; then - local output=$(ssh $ssh_params -p $port root@$host /opt/scripts/check_server_status.sh 2>&1) - - local status=1 - [ -n "$output" ] && status=0 && output="\n$(decorate "$host:$port" "cyan" "u")\n$output\n" - print_status $status - - # Check Additional services, error is reported if anything provides information - local headers="" - if [ -n "$services" ]; then - for service in "$services"; do - if [[ "$service" =~ ^vpn/(.*)$ ]]; then - local ip=${BASH_REMATCH[1]} - [ $(hostname) == "styx" ] && check_server_status "$ip" "-" - else - local service_status=1 - local service_output=$(ssh $ssh_params -p $port root@$host /opt/scripts/check_${service}_status.sh 2>&1 | sed 's/^[[:space:]]*//;/^$/d') - if [ -n "$service_output" ]; then - first_line=$(echo "$service_output" | head -n 1) - if [[ "$first_line" =~ ^([0-9]+)[[:space:]](.*)$ ]]; then - service_status=${BASH_REMATCH[1]} - service_output=$(sed "1 d" <<< "$service_output") - if [ -n "${BASH_REMATCH[2]}" ]; then - service_header=$(sed -r "s/\\$\{color\s+([^}]*)\}/\$(set_color \\1)/g" <<< "${BASH_REMATCH[2]}") #" - headers="$headers $service_header" - fi - else - service_status=0 - fi - - if [ -n "$service_output" ]; then - [ -z "$output" ] && output="\n$(decorate "$host:$port" "cyan" "u")" - output="${output}\n $(decorate "$service" "gray" "u")\n$(echo ${service_output} | sed 's/^/ /')" - fi - fi - fi - - done - fi - - print " ::: ${headers}" - #report="$report
$output" - if [ -n "$output" ]; then - flock -x $0 echo "${output}" >&12 - fi - else - print_status "x" - for service in "$services"; do - print_status "x" - done - fi -} - -function check_service { - local service="$1" && shift - local id="$1" && shift - local args="$@" - - local output=$(service/check_${service}.sh ${id} "$@" 2>&1 | sed 's/^[[:space:]]*//;/^$/d') - - local info=$(echo "$output" | tail -n 1) - - local online=0 - local health=0 - local header="" - if [[ "$info" =~ ^([0-9]+)[[:space:]]+([0-9]+)[[:space:]]+(.*)$ ]]; then - online=${BASH_REMATCH[1]} - health=${BASH_REMATCH[2]} - header=${BASH_REMATCH[3]} - - output=$(sed '$ d' <<< "$output") - fi - - print_status "$online" - print_status "$health" - - header=$(sed -r "s/\\$\{color\s+([^}]*)\}/\$(set_color \\1)/g" <<< "$header") # " - print " ::: ${header}" - - - important=$(grep "^\*" <<< "$output") - messages=$(grep -v "^\*" <<< "$output") - - if [ -n "$output" ]; then - output="\n$(decorate "$service:$id" "cyan" "u")\n$important\n$(set_color gray)$messages$(reset_color)\n" - flock -x $0 echo "${output}" >&12 - fi -} - - -function check__ { - local args - local title="$1" && shift - read -ra args <<< "$1" && shift - local host=${args[0]}; - - print "$(decorate $title "purple") ::: " | sed -r "s/\\$\{color\s+([^}]*)\}/\$(set_color \\1)/g; " - - local service - for service in "$@"; do - service=$(sed -r "s/<([0-9]+)>/\${args[\\1]}/g; s/<([^>]+)>/\${\\1}/g" <<< "$service") # " - ( eval "$service" ) - done - print_eol -} - -function check_ { - # Buffer the output - local output=$(check__ "$@") - echo -e "$output" -} - -function check { - if [ $parallel -gt 0 ]; then - check_ "$@" & - else - check_ "$@" - fi -} diff --git a/remote/logs.sh b/remote/logs.sh index 91257c0..e619e78 100755 --- a/remote/logs.sh +++ b/remote/logs.sh @@ -1,6 +1,6 @@ #! /bin/bash -. lib/status.sh +. lib/remote/status.sh function filter_syslog { log="$1" diff --git a/remote/netstat.sh b/remote/netstat.sh index c6c9561..68ca9db 100755 --- a/remote/netstat.sh +++ b/remote/netstat.sh @@ -1,6 +1,6 @@ #! /bin/bash -. lib/status.sh +. lib/remote/status.sh decorate "Incomming:" purple; echo scripts/netstat-in.sh | grep -v "android-d855cbd1c9f827d" | grep -v "pdv-time-capsule-2.ipe.kit.edu" | column -t diff --git a/remote/news.sh b/remote/news.sh index ea24458..844e2ea 100755 --- a/remote/news.sh +++ b/remote/news.sh @@ -1,6 +1,6 @@ #! /bin/bash -. lib/status.sh +. lib/remote/status.sh decorate "Security:" purple; echo rsstail -n 8 -1 -u https://security.gentoo.org/glsa/feed.rss | cut -d ':' -f 2- | cut -c 2- | fmt -t -w $fold diff --git a/remote/setup b/remote/setup new file mode 120000 index 0000000..f4c6f52 --- /dev/null +++ b/remote/setup @@ -0,0 +1 @@ +../setup/ \ No newline at end of file diff --git a/remote/todo.sh b/remote/todo.sh index 863498a..0a6d80d 100755 --- a/remote/todo.sh +++ b/remote/todo.sh @@ -1,6 +1,6 @@ #! /bin/bash -. lib/status.sh +. lib/remote/status.sh diff --git a/scripts/run_conky.sh b/scripts/run_conky.sh index abdea35..7648259 100755 --- a/scripts/run_conky.sh +++ b/scripts/run_conky.sh @@ -7,7 +7,7 @@ if [ "$1" != "start" ]; then fi if [ "$1" != "stop" ]; then - python /opt/scripts/unlock.py gui || exit + python2 /opt/scripts/unlock.py gui || exit killall -9 gpg-agent pass test diff --git a/service/check_adei.sh b/service/check_adei.sh deleted file mode 100755 index 5ef1ebf..0000000 --- a/service/check_adei.sh +++ /dev/null @@ -1,129 +0,0 @@ -#! /bin/bash - -MAX_SOURCE_OFFSET=3600 -MAX_MASTER_OFFSET=300 -MAX_SLAVE_OFFSET=300 - -function query { - if [ "$2" == "ecode" ]; then - url="$1&mysql=master" - resp=$(curl -f "$url" 2>&1 | grep "returned error") - else - if [ "$2" == "slave" ]; then - url="$1&mysql=slave" - else - url="$1&mysql=master" - fi - - resp=$(curl -sf "$url") - err=$? - [ $err -eq 0 ] || resp="" - fi - echo $resp -} - -function format_time { - offset=$1 - if [ $offset -ge 86400 ]; then - echo "$((offset / 86400))d" - elif [ $offset -ge 3600 ]; then - echo "$((offset / 3600))h" - elif [ $offset -ge 60 ]; then - echo "$((offset / 60))m" - else - echo "${offset}s" - fi -} - - -cd "$(dirname "$0")" -id=$1 - -auth=$(cat ../security/adei.txt | grep -P "^$id" | awk '{ print $2 }') -[ -n $auth ] && auth="$auth@" - -host=$(echo $2 | cut -d '/' -f 1) -url="http://$auth$2/services" - -src=$3 - -# Check if online -online=$(../scripts/ping.pl "$host") -healthy=$online - -# Check if healthy and find version -version=$(query "$url/info.php?target=version&encoding=text") -if [ -z "$version" ]; then - err=$(query "$url/info.php?target=version&encoding=text" "ecode") - echo $err - healthy=0 -else - if [[ "$version" =~ "Error:" ]]; then - echo $version - healthy=0 - version="" - else - version="ADEI $version" - fi -fi - -# Get current database size -size=$(query "$url/info.php?target=size&encoding=text") -[[ "$size" =~ "Error:" ]] && size="" -[ -n "$size" ] && msg="\${color gray}/ $((size / 1024 / 1024 / 1024)) GB" - -# Check pending administrative scripts -if [ $healthy -ne 0 ]; then - scripts=$(query "$url/info.php?target=scripts") - waiting=$(echo $scripts | xmllint --format - | grep "Value" | sed -e "s/^\(.*mtime=\"\([^\"]*\)\".*\)$/\\2\\1/" | awk -v date="$(date +%s)" '{duration=date - $1} duration > 3600 { print duration }' | sort -rn) - if [ -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 [ $healthy -ne 0 -a -n "$src" ]; then - now=$(date +%s) - sdate=$(query "$url/getdata.php?$src&db_mask=0&format=csv&window=-1&rt=1&cache=1&time_format=U" slave | cut -d ',' -f 1 | cut -d '.' -f 1) - mdate=$(query "$url/getdata.php?$src&db_mask=0&format=csv&window=-1&rt=1&cache=1&time_format=U" | cut -d ',' -f 1 | cut -d '.' -f 1) - - if [ -z "$sdate" -o -z "$mdate" ]; then - echo "Error querying data from '$src'" - healthy=2 - else - master_offset=$(($now - $mdate)) - slave_offset=$(($mdate - $sdate)) - - if [ $master_offset -gt $MAX_SOURCE_OFFSET ]; then - rdate=$(query "$url/getdata.php?$src&db_mask=0&format=csv&window=-1&rt=1&time_format=U" | 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 - 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 "$online $healthy $version $msg" diff --git a/service/check_adei.sh b/service/check_adei.sh new file mode 120000 index 0000000..d1f9b8f --- /dev/null +++ b/service/check_adei.sh @@ -0,0 +1 @@ +../adei/check_adei.sh \ No newline at end of file diff --git a/service/check_distcc.sh b/service/check_distcc.sh new file mode 100755 index 0000000..1862b52 --- /dev/null +++ b/service/check_distcc.sh @@ -0,0 +1,37 @@ +#! /bin/bash + +cd "$(dirname "$0")" +. opts.sh + +name=distccd + +[ -z "$host" ] && { echo "Host should be specified"; exit 1; } + +online=$(../scripts/ping.pl "$host") +healthy=$(../scripts/ping.pl "$host" 3364) + +function qssh { + ssh "root@$host" "$@" +} + + +if [ $online -eq 1 ]; then + id=$(qssh docker ps -f "'name=$name'" --format "'{{ .ID }}'" 2>/dev/null) + status=$(qssh docker ps -f "'name=$name'" --format "'{{ .Status }}'" 2>/dev/null) + [ $? -ne 0 ] && status="" +fi + + +if [ -n "$id" -a $healthy -eq 1 ]; then + stat=$(qssh docker stats --no-stream $id | sed '1d' | awk '{ print $2 " " $3 " " $4 }') +fi + +if [ -n "$status" -o -n "$stat" ]; then + msg="DistCC: " + [ -n "$stat" ] && msg+=" $stat" + [ -n "$status" ] && msg+=" $status" +else + msg="" +fi + +echo "$online $healthy $msg" diff --git a/service/lib b/service/lib new file mode 120000 index 0000000..5bf80bf --- /dev/null +++ b/service/lib @@ -0,0 +1 @@ +../lib/ \ No newline at end of file diff --git a/service/scripts b/service/scripts new file mode 120000 index 0000000..a339954 --- /dev/null +++ b/service/scripts @@ -0,0 +1 @@ +../scripts \ No newline at end of file diff --git a/service/security b/service/security new file mode 120000 index 0000000..872fbdf --- /dev/null +++ b/service/security @@ -0,0 +1 @@ +../security \ No newline at end of file diff --git a/service/setup b/service/setup new file mode 120000 index 0000000..8376d48 --- /dev/null +++ b/service/setup @@ -0,0 +1 @@ +../setup \ No newline at end of file diff --git a/setup/adei.txt b/setup/adei.txt new file mode 100644 index 0000000..9c95888 --- /dev/null +++ b/setup/adei.txt @@ -0,0 +1,6 @@ +katrin http://adei-katrin.kaas.kit.edu/adei/ +kaas http://adei-katrin.kaas.kit.edu/adei/ +detector http://192.168.110.67/adei/ +crd http://adei.crd.yerphi.am/adei/ +pcebessadei.competence-e.kit.edu http://pcebessadei.competence-e.kit.edu/adei-battery/ +imkmastadei.ka.fzk.de http://imkmastadei.ka.fzk.de/adei/ diff --git a/setup/domains.txt b/setup/domains.txt new file mode 100644 index 0000000..4c119ab --- /dev/null +++ b/setup/domains.txt @@ -0,0 +1,2 @@ +imkmastadei ka.fzk.de +pcebessadei competence-e.kit.edu diff --git a/setup/parameters.sh b/setup/parameters.sh new file mode 100644 index 0000000..ce5b930 --- /dev/null +++ b/setup/parameters.sh @@ -0,0 +1,5 @@ +debug=1 +default_domain="ipe.kit.edu" +nagios_plugins="/usr/lib/nagios/plugins" + +default_timeout=120 diff --git a/setup/remote.sh b/setup/remote.sh new file mode 100644 index 0000000..c172415 --- /dev/null +++ b/setup/remote.sh @@ -0,0 +1,10 @@ +# Configurable +timeout=2 +fold=120 +palete='blue' +parallel=0 +report="standart_report" + + +# Helpers +ssh_params="-x -q -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -o ConnectTimeout=$timeout" diff --git a/setup/ssh_ports.txt b/setup/ssh_ports.txt new file mode 100644 index 0000000..148bb5b --- /dev/null +++ b/setup/ssh_ports.txt @@ -0,0 +1 @@ +ufosrv1.ka.fzk.de 24 diff --git a/setup/ssh_users.txt b/setup/ssh_users.txt new file mode 100644 index 0000000..e7f75ea --- /dev/null +++ b/setup/ssh_users.txt @@ -0,0 +1 @@ +ufosrv1.ka.fzk.de csa -- cgit v1.2.1