Skip to content
Snippets Groups Projects
check_opencpu 2.40 KiB
#!/bin/bash
# ======================================================================
#
# NAGIOS CLIENT CHECK :: test if opencpu is available
#
# REQUIREMENTS
# - wget
#
# It returns
# - OK if http request was successful
# - CRITICAL if http request fails
# - unknown if wget is not available
#
# ----------------------------------------------------------------------
#
# ah=axel.hahn@iml.unibe.ch
# ds=daniel.schueler@iml.unibe.ch
#
# 2019-05-10  v1.0  ah,ds
# 2019-05-22  v1.1  show built date
# 2020-03-05  v1.2  <axel.hahn@iml.unibe.ch> switch to ph.* helper functions
# ======================================================================


. `dirname $0`/inc_pluginfunctions

tmpOk=/tmp/check_opencpu-ok
tmpErr=/tmp/check_opencpu-error
ocpuUrl=http://localhost/ocpu

packages="eosceGLM eosceLinReg eosceReliability eosceReporter msrdAnalytics"

# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------


function checkOpenCpuPackage(){
  package=$1
  pkgUrl=$ocpuUrl/library/$package/info
  tmpfile=/tmp/check_opencpu-$package

  wget -O $tmpfile $pkgUrl 2>/dev/null
  if [ $? -ne 0 ]; then
    echo "ERROR: package is NOT available [$package]" >>$tmpErr
  else
    echo "OK: package is available [$mypackage] .. Build: `cat $tmpfile | grep "^Built" | cut -c 21-`" >>$tmpOk
  fi
  rm -f $tmpfile 2>/dev/null
}

# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------

rm -f $tmpOk 2>/dev/null

echo -n "OpenCpu: "


# ----- check if WGET exists
wget --version >/dev/null 2>&1
if [ $? -ne 0 ]; then
  ph.abort "UNKNOWN (wget was not found)"
fi

# ----- check if openCpu is running
wget -O /dev/null $ocpuUrl 2>/dev/null
if [ $? -ne 0 ]; then
  echo "ERROR: unable to connect to openCpu with $ocpuUrl"
  wget -O /dev/null -S $ocpuUrl
  ph.setStatus "error"
  ph.exit
fi

echo "OK: openCpu is running and reachable with http" >>$tmpOk

# ----- check custom modules
for mypackage in $packages
do
  checkOpenCpuPackage $mypackage
done

# ----- result
ph.setStatus "ok"
if [ -f $tmpErr ]; then
  echo "ERROR: openCpu is available but not all packages"
  cat $tmpErr && rm -f $tmpErr
  echo
  ph.setStatus "critical"
else
  echo "OK"
fi
cat $tmpOk 2>/dev/null && rm -f $tmpOk

ph.exit

# ----------------------------------------------------------------------