#!/usr/bin/bash

export PATH=$PATH:/usr/local/sbin:/usr/local/bin

cd ~ # make UcliEvt.log and UcliErr.log in ~

arcconf getconfig $1 | awk -F' *: *' '
  {
    k=$1
    gsub(/^ */,"",k)
    v=$2
    gsub(/ *$/,"",v)
    a[k]=v
  }
  END {
    es=0
    split(a["Temperature"], temp, "[ ()/]+")
    if (temp[5]=="Abnormal") { es=1 }
    if (a["Controller Status"]=="Optimal" \
        && a["Status of logical device"]=="Optimal" \
        && a["Logical devices/Failed/Degraded"]~/^[0-9]+\/0\/0$/) \
    {
      if (es==0) {
        printf "RAID OK - "
      } else {
        printf "RAID WARNING - "
      }
    } else {
      printf "RAID CRITICAL - "
      es=2
    }
    printf "controller_status=%s, ", a["Controller Status"]
    printf "logical_device_status=%s, ", a["Status of logical device"]
    printf "logical_devices_failed_degraded=%s, ", a["Logical devices/Failed/Degraded"]
    printf "temperature=%s", a["Temperature"]
    printf "|temperature=%s;100;150;0", temp[1]
    print ""
    exit(es)
  }
'
