check_mk local Bash Script Auswertung SQLPlus DB-FULL Logfiles

#!/bin/bash
#
# Skript Logfiles auszuwerten
# speziell RMAN DB FULL Status
#
# Bsp. Format zur Analyse generiert mit SQLPlus
# ===== 09.06.2017 11:23:56 =====
#
# START_TIME END_TIME STATUS INPUT_TYPE INPUT_BYTE OUTPUT_BYT RANG
# ——————– ——————– ——————– ———- ———- ———- ———-
# 08.06.2017 23:00:04 08.06.2017 23:39:09 COMPLETED DB FULL 75.75G 12.36G 1
# 07.06.2017 23:00:04 07.06.2017 23:45:23 COMPLETED DB FULL 75.12G 12.10G 2
# 06.06.2017 23:00:03 06.06.2017 23:46:06 COMPLETED DB FULL 74.57G 11.88G 3
#
# ===== 16.06.2017 10:16:38 =====
#
# START_TIME END_TIME STATUS INPUT_TYPE INPUT_BYTE OUTPUT_BYT RANG
# ——————– ——————– ——————– ———- ———- ———- ———-
# 15.06.2017 23:00:06 15.06.2017 23:42:01 COMPLETED DB FULL 76.19G 12.46G 1
# 14.06.2017 23:00:06 14.06.2017 23:40:42 COMPLETED DB FULL 75.83G 12.38G 2
# 13.06.2017 23:00:04 13.06.2017 23:42:13 COMPLETED DB FULL 75.15G 12.14G 3
#
# End Comments
#

files=./datastore/rman/check_rman*.log

for file in $files
do

  service=`echo „$file“ | cut -d / -f4`
  linecount=`cat $file | awk ‚/\=\=\=\=\=/ {if (count) print count; print; count=0; next} {count++} END {print count}‘ | tail -n1`
  linecount_noheadline=$((linecount – 3))
  lastoutput=`tail -n $linecount_noheadline $file | sed ‚1!G;h;$!d‘ | tail -n1`
  enddate=`echo „$lastoutput“ | cut -d \ -f4`
  state_raw=`echo „$lastoutput“ | cut -d \ -f7`
  day=`echo „$enddate“ | cut -d \. -f1`
  month=`echo „$enddate“ | cut -d \. -f2`
  year=`echo „$enddate“ | cut -d \. -f3`
  date_normalized=`date -d $year-$month-$day +’%Y%m%d’`
  today=`date +’%Y%m%d’`

  if [ $today = $date_normalized ]
    then
      if [ $state_raw = „COMPLETED“ ]
      then
        echo „0 DB-FULL-$service – OK DB-FULL hat den Status COMPLETED! OK“
      elif [ $state_raw = „RUNNING“ ]
      then
        echo „1 DB-FULL-$service – WARN DB-FULL hat den Status RUNNING! WARN“
      elif [ $state_raw = „FAILED“ ]
      then
        echo „2 DB-FULL-$service – CRIT DB-FULL hat den Status FAILED! CRIT“
      fi
    else
    echo „2 DB-FULL-$service – CRIT DB-FULL Letzer Logeintrag zu alt! Logalter: $date_normalized State: $state_raw“
  fi

done

Schreibe einen Kommentar