Skip to content
Snippets Groups Projects
Commit 2c14a978 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

add check check_onehost

parent 8fb66b23
No related branches found
No related tags found
1 merge request!996435 check onehost
#!/bin/bash
# ======================================================================
#
# Check ONEHOST
#
# requirements:
# - sudo onehost
#
# ----------------------------------------------------------------------
# 2023-06-09 v1.0 <axel.hahn@unibe.ch> initial version
# ======================================================================
. $(dirname $0)/inc_pluginfunctions
self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] )
self_APPVERSION=1.0
# ----------------------------------------------------------------------
# functions
# ----------------------------------------------------------------------
function showHelp(){
cat <<EOF
______________________________________________________________________
$self_APPNAME
v$self_APPVERSION
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
______________________________________________________________________
show count of hosts in OpenNebula and warn if a host is down.
SYNTAX:
$(basename $0) [ -w value -c value -h ]
-w VALUE cpu usage warning level (default: 1)
-c VALUE cpu usage critical level (default: 2)
-h or --help show this help.
PARAMETERS:
None.
EXAMPLE:
$(basename $0) -c 1 set to critical if the 1st host is off.
EOF
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
# --- check required tools
ph.require onehost
# --- check param -h
case "$1" in
"--help"|"-h")
showHelp
exit 0
;;
*)
esac
# --- set optional limits
typeset -i iWarnLimit=$( ph.getValueWithParam 1 w "$@")
typeset -i iCriticalLimit=$( ph.getValueWithParam 2 c "$@")
# --- get data
cmdout=$( onehost list --csv 2>&1 )
if ! grep "ID,NAME" <<< "$cmdout" >/dev/null; then
ph.setStatus "unknown"
echo "$cmdout"
ph.exit
fi
# header=$( head -1 <<< "$cmdout" )
csvdata=$( echo "$cmdout" | sed -n '2,$p' )
# --- get result
out=""
typeset -i iTotal; iTotal=$( echo "$csvdata" | wc -l )
typeset -i iOn; iOn=$( echo "$csvdata" | grep -c "on$" )
typeset -i iOther; iOther=$iTotal-$iOn
ph.perfadd "total" "${iTotal}"
ph.perfadd "on" "${iOn}"
ph.perfadd "other" "${iOther}"
if [ $iOther -ge $iCriticalLimit ]; then
out="ERROR: not all hosts are up - count $iOther reached critical value $iCriticalLimit"
ph.setStatus "critical"
elif [ $iOther -ge $iWarnLimit ]; then
out="ERROR: not all hosts are up - count $iOther reached critical value $iWarnLimit"
ph.setStatus "warning"
fi
ph.status "ONEHOST - Total: $iTotal .. on: $iOn .. other: $iOther"
echo "$cmdout"
echo "$out"
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment