Icinga2 - Check erstellen: Unterschied zwischen den Versionen

Aus QBWiki
Zur Navigation springenZur Suche springen
(Die Seite wurde neu angelegt: „{{#css: .mw-highlight { padding-left: 25px; border-left: 5px solid #F50; } .mw-highlight > pre { border-left: 1px dotted #999; border-top: none; line…“)
 
Zeile 1: Zeile 1:
 
{{#css:
 
{{#css:
 
.mw-highlight {
 
.mw-highlight {
   padding-left: 25px;
+
   padding-left: 30px;
 
   border-left: 5px solid #F50;
 
   border-left: 5px solid #F50;
 
}
 
}
Zeile 11: Zeile 11:
  
 
.mw-highlight > pre > .lineno {
 
.mw-highlight > pre > .lineno {
   margin-left: -30px;
+
   margin-left: -40px;
 
   color: #666;
 
   color: #666;
 
}
 
}
Zeile 28: Zeile 28:
 
: Vorteil: kein Zugriff über den Root account notwendig
 
: Vorteil: kein Zugriff über den Root account notwendig
 
: Nachteil: allerdings einen Eintrag in der sudoers Datei
 
: Nachteil: allerdings einen Eintrag in der sudoers Datei
 +
 +
 +
 +
Beispielskript: check_yum
 +
<syntaxhighlight lang="bash" line="1">
 +
#!/bin/bash
 +
while getopts ":c:w:" opt ; do
 +
  case $opt in
 +
    c)
 +
      crit_days="$OPTARG"  ;;
 +
    w)
 +
      warn_days="$OPTARG"  ;;
 +
    \?)
 +
      echo "Invalid Option -$OPTARG" >&2
 +
  esac
 +
done
 +
 +
# Centos , YYYY-MM-DD
 +
last_update="$(yum history list all | egrep ' U |Update' | head -n1 |awk '{print $6}')"
 +
last_update_unix_time="$(date -d "${last_update}" +%s)"
 +
 +
cur_date="$(date +%s)"
 +
 +
timediff_s="$((${cur_date} - ${last_update_unix_time}))"
 +
timediff_m="$((${timediff_s} / 60))"
 +
timediff_h="$((${timediff_m} / 60))"
 +
timediff_d="$((${timediff_h} / 24))"
 +
timediff_w="$((${timediff_d} / 7))"
 +
 +
diff_msg="Last update was ${timediff_d} days ago"
 +
 +
 +
if [[ ${timediff_d} -ge ${crit_days} ]] ; then
 +
  echo "Critical: ${diff_msg}"
 +
  exit 2
 +
fi
 +
 +
if [[ ${timediff_d} -ge ${warn_days} ]] ; then
 +
  echo "Warning: ${diff_msg}"
 +
  exit 1
 +
fi
 +
 +
if [[ ${timediff_d} -lt ${warn_days} ]] ; then
 +
  echo "OK: ${diff_msg}"
 +
  exit 0
 +
fi
 +
 +
echo "Unknown: ${diff_msg}"
 +
</syntaxhighlight>

Version vom 25. Februar 2019, 16:07 Uhr


Beispiel: Tage seit dem letzten Update mit Paketmanager YUM

Um z.B. zu überprüfen, wann auf einem Server mit Yum als Paketmanager das letzte mal geupdatet wurde, haben wir zwei Möglichkeiten:

Als root-user direkt über einen Befehl
Nachteil: Authentifizierung als Root Benutzer
Vorteil: Kein Skript auf dem Zielrechner notwendig
Als icinga-user über ein selbstgeschriebenes Plugin
Vorteil: kein Zugriff über den Root account notwendig
Nachteil: allerdings einen Eintrag in der sudoers Datei


Beispielskript: check_yum

 1 #!/bin/bash
 2 while getopts ":c:w:" opt ; do
 3   case $opt in
 4     c)
 5       crit_days="$OPTARG"  ;;
 6     w)
 7       warn_days="$OPTARG"  ;;
 8     \?)
 9       echo "Invalid Option -$OPTARG" >&2
10   esac
11 done
12 
13 # Centos , YYYY-MM-DD
14 last_update="$(yum history list all | egrep ' U |Update' | head -n1 |awk '{print $6}')"
15 last_update_unix_time="$(date -d "${last_update}" +%s)"
16 
17 cur_date="$(date +%s)"
18 
19 timediff_s="$((${cur_date} - ${last_update_unix_time}))"
20 timediff_m="$((${timediff_s} / 60))"
21 timediff_h="$((${timediff_m} / 60))"
22 timediff_d="$((${timediff_h} / 24))"
23 timediff_w="$((${timediff_d} / 7))"
24 
25 diff_msg="Last update was ${timediff_d} days ago"
26 
27 
28 if [[ ${timediff_d} -ge ${crit_days} ]] ; then
29   echo "Critical: ${diff_msg}"
30   exit 2
31 fi
32 
33 if [[ ${timediff_d} -ge ${warn_days} ]] ; then
34   echo "Warning: ${diff_msg}"
35   exit 1
36 fi
37 
38 if [[ ${timediff_d} -lt ${warn_days} ]] ; then
39   echo "OK: ${diff_msg}"
40   exit 0
41 fi
42 
43 echo "Unknown: ${diff_msg}"