Skip to content
Snippets Groups Projects
Select Git revision
  • 995466654bc35ca67790d1082dcf6d057bf8b212
  • master default protected
  • simple-task/7248-eol-check-add-node-22
  • 6877_check_iml_deployment
4 results

check_haproxy_health

Blame
  • user avatar
    Hahn Axel (hahn) authored
    6df364dc
    History
    check_haproxy_health 2.24 KiB
    #!/bin/bash
    # ======================================================================
    #
    # NAGIOS CLIENT CHECK :: haproxy healthcheck
    #
    # ----------------------------------------------------------------------
    # 
    # ----------------------------------------------------------------------
    # 2020-04-27  v1.0  <axel.hahn@iml.unibe.ch>
    # 2020-05-04  v1.1  <axel.hahn@iml.unibe.ch>  show message if monitor-uri was not set
    # ======================================================================
    
    . `dirname $0`/inc_pluginfunctions
    
    cfgfile=/etc/haproxy/haproxy.cfg
    tmpfile=/tmp/check_haproxy_healthcheck_$$
    
    
    
    # ----------------------------------------------------------------------
    # pre checks
    # ----------------------------------------------------------------------
    ph.reqire wget
    
    cat $cfgfile >/dev/null
    if [ $? -ne 0 ]; then
      ph.abort "UNKNOWN: unable to read ha proxy config $cfgfile ... `ls -l $cfgfile`"
    fi
    
    cat $cfgfile | grep "\ mode\ .*http" >/dev/null
    if [ $? -ne 0 ]; then
      ph.abort "UNKNOWN: haproxy is not in http mode"
    fi
    
    
    # ----------------------------------------------------------------------
    # build url
    # ----------------------------------------------------------------------
    
    proto=http
    auth=
    host=localhost
    port=80
    uri=
    
    uri=` cat $cfgfile | grep "\ monitor-uri\ " | awk '{ print $2 }'`
    
    if [ -z "$uri" ]; then
      ph.abort "UNKNOWN: no monitor-uri setting was found in the config $cfgfile."
    fi
    
    cat $cfgfile | grep "bind\ .*\ ssl\ " >/dev/null && proto=https
    port=`cat $cfgfile | grep "\ bind\ "        | awk '{ print $2 }' | cut -f 2 -d ':'`
    
    url="$proto://${host}:${port}${uri}"
    
    
    # ----------------------------------------------------------------------
    # check output
    # ----------------------------------------------------------------------
    
    # --- get status page
    wget --no-check-certificate -O $tmpfile $url 2>/dev/null
    if [ $? -ne 0 ]; then
      rm -f $tmpfile
      ph.abort "UNKNOWN: url $url did not respond. `wget --no-check-certificate -O - -S $url`"
    fi
    
    grep "200 OK" $tmpfile >/dev/null
    if [ $? -ne 0 ]; then
      ph.setStatus "error"
      ph.status "url did not contain 200 OK. `wget --no-check-certificate -O - -S $url`"
    else
      ph.status "HA Proxy is up and running."
    fi
    
    rm -f $tmpfile
    
    ph.exit
    
    # ----------------------------------------------------------------------