Nagios

Aus MHC-Wiki

Wechseln zu: Navigation, Suche

Inhaltsverzeichnis

check_mk

apt Source

Es gibt kein offizeielles Repository, deshalb pflege ich mein eigens:

deb http://www.mhcsoftware.de/debian lenny contrib

(Der jeweils aktuelle Kerio-Mailserver liegt auch dort.)

PNP4Nagios Daten upgraden

Script für den User der OMD-Site:

SITE=`id -un`
for i in `./lib/pnp4nagios/rrd_convert.pl --cfg_dir=/opt/omd/sites/$SITE/etc/pnp4nagios --list_command | grep "|" | cut -d " " -f 3`
do
  ./lib/pnp4nagios/rrd_convert.pl --cfg_dir=/opt/omd/sites/$SITE/etc/pnp4nagios --check_command=$i
done

Check Relay

Szenario:

Bild:Checkrelay.png

Ziel: Vom Nagios Server aus soll per check_mk der Server B überwacht werden.

Vorgehensweise:

  • Port (6522) auf dem Router auf Server A Port 22 weiterleiten
  • Hinterlegen des Public-Key des Nagios-Users auf Server A
  • Abfragen der Daten über SSH


/omd/sites/site-name/bin/check_mk_relay

#!/bin/sh

ssh -q -p 6522 -i /omd/sites/mhc/etc/id_rsa -l root $1 "nc $2 6556"

Der Private-Key für den Nagios-User liegt im Ordner "/omd/sites/mhc/etc".


main.mk

all_hosts = [
  "server-B|site-A",
]

ipaddresses = {
  "server-B" : "127.0.0.1",
}

datasource_programs = [
 ( 'check_mk_relay router-ip <HOST>', [ 'site-A'], ALL_HOSTS ),
]

Wobei "router-ip" die externe IP des Routers ist und "server-B" der interne Name under dem Server A, Server B kennt oder eben die IP von Server B.

Wenn SSH-Strict-Mode aktiv ist muss der Hostkey bei der ersten Verbindung bestätigt werden. Am besten bei einem ersten manuellen Test:

check_mk_relay router-ip server-B

Dies sollte dann den normalen "check_mk"-Output von server-B liefern.

Siehe: http://mathias-kettner.de/checkmk_datasource_programs.html

Checks per CRON

Ich habe oft das Problem, dass meine selbst geschriebenen Checks zu langsam ablaufen, was aber immer an den Tools der Hardwarehersteller liegt. Deshalb benutze ich dieses System um Checks per Cron, unabhängig von check_mk laufen zu lassen. Folgende neue Ordner werden im Ordner /usr/lib/check_mk_agent benötigt:

cron
cron/scripts
cron/scripts/plugins
cron/scripts/local
data
data/plugins
data/local

In den Ordner cron/scripts kommt nur das Script "cron.sh" welches man dann im gewünschten Intervall, z.b. jede Minuten, per Cron laufen lässt:

#!/bin/bash

# cron kennt nur volle Minuten - 10 Sekunden Offset aus der vollen Minute
sleep 10

SCRIPTS=/usr/lib/check_mk_agent/cron/scripts
OUTPUT=/usr/lib/check_mk_agent/data

for i in `ls -1 $SCRIPTS/plugins`
do
	$SCRIPTS/plugins/$i > $OUTPUT/plugins/$i
	mv $OUTPUT/plugins/$i $OUTPUT/plugins/cmk_$i
done

for i in `ls -1 $SCRIPTS/local`
do
	$SCRIPTS/local/$i > $OUTPUT/local/$i
	mv $OUTPUT/local/$i $OUTPUT/local/cmk_$i
done

Die Ordner "cron/scripts/plugins" und "cron/scripts/local" enthalten dann die eigentlichen Checks die sonst in den Ordnern "plugins" bzw. "local" stehen würden. An stelle der eigentlichen Checks stehen dann in diesen beiden Ordnern nur folgende Scripte:

Ordner "plugins":

#!/bin/bash

cat /usr/lib/check_mk_agent/data/plugins/cmk_*

Ordner "local":

#!/bin/bash

cat /usr/lib/check_mk_agent/data/local/cmk_*

Check für LSI Controller

Benötigt mpt-status

Bild:Check_mk_lsi.png

Client-Check

/usr/lib/check_mk_agent/plugins/mh_lsi

#!/bin/sh

# check_mk check f. LSI Controller
#
# 10/2010 Matthias Henze
# Lizenz: GPL v2


if which mpt-status >/dev/null ; then
    echo '<<<lsi_phys>>>'
    mpt-status -n | grep phys_id
    echo '<<<lsi_vols>>>'
    mpt-status -n | grep vol_id
fi

Plugins

/omd/versions/0.44/share/check_mk/checks/lsi_phys

#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-

# check_mk check f. LSI Controller
#
# 10/2010 Matthias Henze
# Lizenz: GPL v2


# Example output from agent:
# <<<lsi_phys>>>
# ioc:0 phys_id:1 scsi_id:10 vendor:ATA      product_id:ST31500341AS     revision:CC1H size(GB):1397 state: ONLINE flags: NONE sync_state: 100 ASC/ASCQ:0xff/0xff SMART ASC/ASCQ:0xff/0xff
# ioc:0 phys_id:0 scsi_id:1 vendor:ATA      product_id:ST31500341AS     revision:CC1H size(GB):1397 state: ONLINE flags: NONE sync_state: 100 ASC/ASCQ:0xff/0xff SMART ASC/ASCQ:0xff/0xff



# inventory
def inventory_lsi_phys(checkname, info):
    inventory = []
    for line in info:
	x = line[1].split(":")
	unit = x[1]
	inventory.append( (unit, None) )
    return inventory

# check
def check_lsi_phys(item, param, info):
    for line in info:
	x = line[1].split(":")
        if x[1] == item:
            status = line[8]
	    x = line[4].split(":")
            unit_type = x[1]
	    x = line[6].split(":")
            size = x[1]
            sync = line[12]
            infotext = "%s  (type: %s, size: %s GB, sync: %s)" % (status, unit_type, size, sync)
            if status == "ONLINE":
                return (0, "OK - unit status is " + infotext)
            else:
                return (2, "CRITICAL - unit status is " + infotext)
    return (3, "UNKNOWN - unit %s not found in agent output" % item) 

# declare the check to Check_MK
check_info['lsi_phys'] = \
	(check_lsi_phys, "RAID LSI phys %s", 0, inventory_lsi_phys)

/omd/versions/0.44/share/check_mk/checks/lsi_vols

#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-

# check_mk check f. LSI Controller
#
# 10/2010 Matthias Henze
# Lizenz: GPL v2


# Example output from agent:
# <<<lsi_vols>>>
# ioc:0 vol_id:0 type:IM raidlevel:RAID-1 num_disks:2 size(GB):1396 state: OPTIMAL flags: ENABLED


# inventory
def inventory_lsi_vols(checkname, info):
    inventory = []
    for line in info:
	x = line[1].split(":")
	unit = x[1]
	inventory.append( (unit, None) )
    return inventory

# check
def check_lsi_vols(item, param, info):
    for line in info:
            status = line[7]
            x = line[3].split(":")
            unit_type = x[1]
            x = line[5].split(":")
            size = x[1]
            infotext = "%s  (type: %s, size: %s GB)" % (status, unit_type, size)
            if status == "OPTIMAL":
                return (0, "OK - volume status is " + infotext)
            else:
                return (2, "CRITICAL - volume status is " + infotext)
    return (3, "UNKNOWN - volume %s not found in agent output" % item) 

# declare the check to Check_MK
check_info['lsi_vols'] = \
	(check_lsi_vols, "RAID LSI unit %s", 0, inventory_lsi_vols)

Check für Linux KVM/qemu auf Basis von Proxmox

Die Idee dabei ist, dass das überwacht wird was WÄHREND des Inventory an VMs läuft. Kommt eine VM dazu dann wird ein "-II" nötig. Ausserdem werden Perfomancedaten für CPU-Last und Ram gesammelt.

Bild:Check_mk_quemu.png

Client-Check

/usr/lib/check_mk_agent/plugins/mh_qemu

#!/bin/sh

# check_mk check f. LSI Controller
#
# 10/2010 Matthias Henze
# Lizenz: GPL v2

# sampel output
#       101 oracle               stopped    1024               8.00 0         
#       102 server               running    3072              50.00 2634      
#       103 monitoring           running    2048              32.00 5139      
#       104 nagios               running    1024              32.00 9030

if which qm >/dev/null ; then
    echo '<<<qemu>>>'
    qm list | grep -v VMID | while read L
    do
        PID=$(echo $L | awk -- '{print $6}')
        if [ $PID -gt 0 ]; then
            DATA=$(top -p $PID -n 1 -b | tail -n 2 | head -n 1 | awk -- '{print $9" "$10}')
        else
            DATA=""
        fi
        echo $L" "$DATA
    done
fi

Plugin

/omd/versions/0.44/share/check_mk/checks/qemu

#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-

# check_mk check f. LSI Controlle
#
# 12/2010 Matthias Henze
# Lizenz: GPL v2


# Example output from agent:
#<<<qemu>>>
#      VMID NAME                 STATUS     MEM(MB)    BOOTDISK(GB) PID      CUP  RAM
#       101 oracle               stopped    1024               8.00 0         0    0
#       102 server               running    3072              50.00 2634      0    0
#       103 monitoring           running    2048              32.00 5139      0    0
#       104 nagios               running    1024              32.00 9030      0    0



# inventory
def inventory_qemu(checkname, info):
    inventory = []
    for line in info:
        if line[2] == "running":  # only VM's running while inventory are monitored !
            vm = line[0]
            inventory.append( (vm, None) )
    return inventory

# check
def check_qemu(item, param, info):
    for line in info:
        perfdata = []
        if line[0] == item:
            name = line[1]
            status = line[2]
            ram = line[4]
            infotext = "%s  (id: %s, name: %s)" % (status, item, name)
            if status == "running":
                perfdata.append( ( "CPU%", int(round(float(line[6]))) ) )
                perfdata.append( ( "RAM%", int(round(float(line[7]))) ) )
                return (0, "OK - status is " + infotext, perfdata)
            else:
                return (2, "CRITICAL - status is " + infotext, perfdata)
    return (3, "UNKNOWN - VM %s not found in agent output" % item) 

# declare the check to Check_MK
check_info['qemu'] = \
        (check_qemu, "QEMU VM %s", 1, inventory_qemu)

Check für HP Smart Array Controller

Benötigt hpacucli und läuft nur als Bash-Script.

Getestet mit: P410, P410i

Download: http://downloads.linux.hp.com/SDR/downloads/ProLiantSupportPack/

Bild:Check_mk_hpsa.png

Client Check

/usr/lib/check_mk_agent/plugins/mh_hpsa

#!/bin/bash

# check_mk check f. HP Smart Array Controller
#
# 01/2011 Matthias Henze
# Lizenz: GPL v2

# sample output - requires hpacucli
#
#
# hpacucli controller all show 
#
#Smart Array P410 in Slot 4                (sn: PACCR9SY0AXY  )
#
#
# hpacucli controller slot=4 array all show 
#
#Smart Array P410 in Slot 4
#
#   array A (SATA, Unused Space: 0 MB)
#
#
# hpacucli controller slot=4 array A physicaldrive all show
#
#Smart Array P410 in Slot 4
#
#   array A
#
#      physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SATA, 500 GB, OK)
#      physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SATA, 500 GB, OK)
#      physicaldrive 1I:1:3 (port 1I:box 1:bay 3, SATA, 500 GB, OK)
#      physicaldrive 1I:1:4 (port 1I:box 1:bay 4, SATA, 500 GB, OK, spare)
#

function is_integer() {
    [ "$1" -eq "$1" ] > /dev/null 2>&1
    return $?
}

if [ -e  /proc/driver/cciss ] ; then

  echo '<<<hpsa_controller>>>'
  cc=-1
  CMD="hpacucli controller all show"
  while read -a cont; do
    if is_integer ${cont[5]}; then
      cc=$(($cc+1))
      read -a cstat <<< $(hpacucli controller slot=${cont[5]} show | grep "Controller Status")
      if [ "${cstat[2]}" = "OK" ]; then
        echo "${cont[5]} OK ${cont[2]}"
      else
        echo "${cont[5]} CRIT ${cont[2]}"
      fi
      controllers[$cc]=${cont[5]}
    fi
  done < <( $CMD )

  echo '<<<hpsa_array>>>'
  for c in $(seq 0 $cc)
  do
    ac=-1
    CMD="hpacucli controller slot=${controllers[$c]} array all show"
    while read -a cary; do
      if [ "X${cary[0]}X" = "XarrayX" ]; then
        ac=$(($ac+1))
        # collect lines
        read -d + -a x <<< $(hpacucli controller slot=${controllers[$c]} array ${cary[1]} show | sed 's/(Embedded)//')
        # collect words
        read -a ary <<< ${x[*]}
        echo "${controllers[$c]}:${cary[1]} ${ary[16]} ${ary[10]} ${ary[13]} ${ary[14]}"
        arrays[$ac]=${cary[1]}
      fi
    done < <( $CMD )
  done

  echo '<<<hpsa_drive>>>'
  for c in $(seq 0 $cc)
  do
    for a in $(seq 0 $ac)
    do
      CMD="hpacucli controller slot=${controllers[$c]} array ${arrays[$a]} physicaldrive all show"
      while read -a pdrv; do
        if [ "X${pdrv[0]}X" = "XphysicaldriveX" ]; then
          echo -n "${controllers[$c]}:${arrays[$a]}:${pdrv[1]} ${pdrv[9]/[),]/} ${pdrv[6]/,/} ${pdrv[7]} ${pdrv[8]/,/} "
          if [ ${pdrv[10]} ]; then 
            echo ${pdrv[10]/)/}
          else
            echo "assigned"
          fi
        fi
      done < <( $CMD )
    done
  done
fi

Plugins

/omd/sites/mhc/share/check_mk/checks/hpsa_controller

#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-

# check_mk check f. HP Smart Array Controller
#
# 01/2011 Matthias Henze
# Lizenz: GPL v2


# Example output from agent:
# <<<hpsa>>>
# 4 OK PACCR9SY0AXY P410

# inventory
def inventory_hpsa_controller(checkname, info):
    inventory = []
    for line in info:
 	item = line[0]
	inventory.append( (item, None) )
    return inventory

# check
def check_hpsa_controller(item, param, info):
    for line in info:
        if line[0] == item:
            status = line[1]
            type = line[2]
            infotext = "status is %s  (slot: %s, type: %s)" % (status, item, type)
            if status == "OK":
                return (0, "OK - " + infotext)
            else:
                return (2, "CRITICAL - " + infotext)
    return (3, "UNKNOWN - Controller %s not found in agent output" % item) 

# declare the check to Check_MK
check_info['hpsa_controller'] = \
	(check_hpsa_controller, "HP Smart Array Controller Slot %s", 1, inventory_hpsa_controller)

/omd/sites/mhc/share/check_mk/checks/hpsa_array

#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-

# check_mk check f. HP Smart Array Controller
#
# 01/2011 Matthias Henze
# Lizenz: GPL v2


# Example output from agent:
# <<<hpsa_array>>>
# 4:A OK SATA 0 MB


# inventory
def inventory_hpsa_array(checkname, info):
    inventory = []
    for line in info:
 	item = line[0]
	inventory.append( (item, None) )
    return inventory

# check
def check_hpsa_array(item, param, info):
    for line in info:
        if line[0] == item:
            hw = item.split(":")
            slot = hw[0]
            array = hw[1]
            status = line[1]
            type = line[2]
            free = line[3]
            unit = line[4]
            infotext = "status is %s  (slot: %s, array: %s, type: %s free: %s %s)" % (status, slot, array, type, free, unit)
            if status == "OK":
                return (0, "OK - " + infotext)
            else:
                return (2, "CRITICAL - " + infotext)
    return (3, "UNKNOWN - Array %s not found in agent output" % item) 

# declare the check to Check_MK
check_info['hpsa_array'] = \
	(check_hpsa_array, "HP Smart Array Controller Array %s", 1, inventory_hpsa_array)

/omd/sites/mhc/share/check_mk/checks/hpsa_drive

#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-

# check_mk check f. HP Smart Array Controller
#
# 01/2011 Matthias Henze
# Lizenz: GPL v2


# Example output from agent:
# <<<hpsa_drive>>>
# 4:A:1I:1:1 OK SATA 500 GB assigned
# 4:A:1I:1:2 OK SATA 500 GB assigned
# 4:A:1I:1:3 OK SATA 500 GB assigned
# 4:A:1I:1:4 OK SATA 500 GB spare



# inventory
def inventory_hpsa_drive(checkname, info):
    inventory = []
    for line in info:
 	item = line[0]
	inventory.append( (item, None) )
    return inventory

# check
def check_hpsa_drive(item, param, info):
    for line in info:
        if line[0] == item:
            hw = item.split(":")
            slot = hw[0]
            array = hw[1]
            port = hw[2]
            box = hw[3]
            bay = hw[4]
            status = line[1]
            type = line[2]
            free = line[3]
            unit = line[4]
            usage = line[5]
            infotext = "status is %s  (slot: %s, array: %s, port: %s, box: %s, bay: %s, type: %s size: %s %s, usage: %s)" % (status, slot, array, port, box, bay, type, free, unit, usage)
            if status == "OK":
                return (0, "OK - " + infotext)
            else:
                return (2, "CRITICAL - " + infotext)
    return (3, "UNKNOWN - Array %s not found in agent output" % item) 

# declare the check to Check_MK
check_info['hpsa_drive'] = \
	(check_hpsa_drive, "HP Smart Array Controller Drive %s", 1, inventory_hpsa_drive)

OperStatus unabhaengiger SNMP-Interface Check

Der Check kann hier heruntergeladen werden und kommt (mit OMD) nach local/share/check_mk/checks

Der Check ist dann interessant wenn man alle Interfaces an einem Switch überwachen möchte aber der OperStatus, also ob das Interface Link hat oder nicht, uninteressant ist. Dies ist in der Regel bei Switches der Fall an denen z.B. PCs von Endanwendern angeschlossen sind die i.d.R. abends abgeschaltet werden. Der Verlust des Links ist hier kein Fehler. Dennoch ist es ggf. interessant Performancedaten und Fehler zu sammeln.

Der Check inventarisiert alle Interfaces mit AdminStatus UP und ignoritert den OperStatus des interfaces in so fern, als dass er für den Status des Interfaces ignoriert wird. Der OperStatus wird lediglich zur Information in der Spalte "Status Detail" wiedergegeben. Der Check ist schlicht vom normalen "if"-Check abgeleitet.

APT

Benötigt: python-apt

Client

#!/usr/bin/env python
#
# Check_MK APT Plugin - Check for upgradeable packages.
#
# Copyright 2010, Stefan Schlesinger <sts@ono.at>
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
# Mod damit es mit Debian UND Ubuntu funktioniert  03/2011 Matthias Henze <mh@mhcsoftware.de>
# Mod damit Packages die auf "keep" stehen ignoriert werden 08/2011 Matthias Henze <mh@mhcsoftware.de>

import sys
import os
import datetime
import warnings
warnings.filterwarnings("ignore")

from pprint import pprint

try:
    import apt
except ImportError:
    sys.exit


class AptCache(apt.Cache):

    # apt-cache update interval in seconds
    update_interval = 3600

    # file to check against
    update_last_file = "/var/tmp/checkmk_apt_timestamp"

    def __init__(self):
        apt.Cache.__init__(self)
        self.update_cache()

    # automatically update the apt cache once a hour
    def update_cache(self):
        delta = self.last_cache_update(self.update_last_file)
        if not delta or delta.seconds > self.update_interval:
            self.update()
            self.open(None)
            # update the timestamp
            self.update_timestamp(self.update_last_file)

    def last_cache_update(self, file):
        # return false, if we don't have the file yet
        if not os.path.isfile(file):
            return False

        now     = datetime.datetime.now()
        mtime   = datetime.datetime.fromtimestamp(os.path.getmtime(file))
        delta   = now - mtime

        return delta

    def update_timestamp(self, file):
        open(file, 'w').close()
        return True


def get_upgradeable():
    pkgs_to_upgrade     = []
    pkgs_to_sec_upgrade = []
    cache = AptCache()

    for pkg in cache:
        if not pkg.markedKeep:
           if pkg.isUpgradable:
               name      = pkg.name
               candidate = pkg.candidateOrigin[0]
               if candidate.label == "Debian-Security":
                   pkgs_to_sec_upgrade.append(name)
               elif candidate.archive.find("security") > -1:
                   pkgs_to_sec_upgrade.append(name)
               else:
                   pkgs_to_upgrade.append(name)

    return [pkgs_to_upgrade, pkgs_to_sec_upgrade]



def main():
    upgrades, secupgrades = get_upgradeable()

    # print the beginning of the plugin header
    print "<<<apt>>>"

    if len(upgrades) > 0:
	print "upgrades \"%s\"" % ",".join(upgrades)
    else:
	print "upgrades"

    if len(secupgrades) > 0:
	print "secupgrades \"%s\"" % ",".join(secupgrades)
    else:
	print "secupgrades"


if __name__ == "__main__":
    main()


Server

#!/usr/bin/env python
#
# Check_MK APT Plugin - Check for upgradeable packages.
#
# Copyright 2010, Stefan Schlesinger <sts@ono.at>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
# Mod damit es mit Debian UND Ubuntu funktioniert  03/2011 Matthias Henze <mh@mhcsoftware.de>
#



def inventory_apt_upgrades(checkname, info):
    if len(info) >= 1:
        return [(None, "", None)]

    return []

def check_apt_upgrades(item, params, info):

    level   = 0 # 0:OK, 1:WARNING 2:CRITICAL, 3: UNKNOWN
    updates = []

    for line in info:

	# if we don't have any upgrades listed, the line list
	# will only contain one element, eg. "upgrades\n"
	if len(line) < 2:
	    continue

	# there are upgrades availiable, evaluate the importency.
	# secupgrades return CRITICAL, normal upgrades only WARNING.
        type = line[0]
        pkgs = line[1].strip("\"").split(",")

        if len(pkgs) > 0:
            if level < 2 and type == "secupgrades":
                level = 2

            if level < 1 and type == "upgrades":
                level = 1

            updates.extend(pkgs)

    # Construct a the status message.
    if level == 0:
        msg = "OK - All packages are up to date."
    elif level == 1:
        msg = "%s packages available for upgrade: %s" % (len(updates), ",".join(updates))
    elif level == 2:
        msg = "%s packages available for upgrade: %s" % (len(updates), ",".join(updates))

    return (level, msg)

# declare the check to Check_MK. Dict format:
#  ( check_function, "service name", perf_data_provided?(0:1), inventory_function)
check_info['apt.upgrades'] = \
      (check_apt_upgrades, "apt.upgrades", 0, inventory_apt_upgrades)

SEP Sesam

Lokaler Check, kopieren nach: /usr/lib/check_mk_agent/local/sesam

#!/bin/bash
#
# 08/2011 Matthias Henze
# Lizenz: GPL v2
#
# Check für SEP Sesam auf Basis des "prot" des Vortages


read_ini()
{
  source `grep -i '^sm_ini=' /etc/sesam2000.ini|cut -d"=" -f2` 2>/dev/null
}
read_ini
source ${gv_rw_ini}/sesam2000.profile > /dev/null 2>&1

F=`ls -tr $gv_rw_prot/*.status | tail -n2 | head -n1`

STATUS=0
TEXT=""

while read S N
do
	if [ "*${TEXT}*" != "**" ]; then
		TEXT=$TEXT", "
	fi
	case "$S" in
	  0) # erfolgreich
		TEXT=$TEXT"OK:"$N
		;;
	  1) # erfolgrich mir warnung
		if [ $STATUS -lt 1 ]; then
			STATUS=1
		fi
		TEXT=$TEXT"WARN:"$N
		;;
	  2) # listing unvollstänig
		if [ $STATUS -lt 2 ]; then
			STATUS=2
		fi
		TEXT=$TEXT"INCOMP:"$N
		;;
	  3) # abgebrochen
		if [ $STATUS -lt 2 ]; then
			STATUS=2
		fi
		TEXT=$TEXT"ABBORT:"$N
		;;
	  c) # abbruch durch benutzer
		if [ $STATUS -lt 2 ]; then
			STATUS=2
		fi
		TEXT=$TEXT"USER:"$N
		;;
	  X) # fataler fehler
		if [ $STATUS -lt 2 ]; then
			STATUS=2
		fi
		TEXT=$TEXT"FATAL:"$N
		;;
	  *) # gibt es nicht
		STATUS=3
		TEXT=$TEXT"UNKNOWN:"$N
		;;
	esac
done < <( cat $F | egrep -v "^Start|^-----" | cut -d " " -f 1,2 )

echo $STATUS" SEP-Sesam - Day:"`grep "^Start" $F | cut -d " " -f 7,8,9`", "$TEXT

ONLINE-USV

Lokaler Check, kopieren nach: /usr/lib/check_mk_agent/local/onlineusv

#!/bin/bash
#
# 08/2011 Matthias Henze
# Lizenz: GPL v2
#
# Check für ONLINE USVs auf Basis der mitgeliefereten Software "upsman"

PASSWORD=passwort # upsman Passwort
CRIT=5            # Minuten f. Status CRITICAL
WARN=1            # Minuten f. Status WARNING
MAX=40            # Maximale Minuten f. Performancedaten

read -a USV_STATUS <<< $(/usr/ups/upsmon -v $PASSWORD | grep "UPS-Status:")
read -a USV_CTIME <<< $(/usr/ups/upsmon -i autonom $PASSWORD | grep "ups answer:")
read -d "." -a USV_TIME <<< $(echo ${USV_CTIME[2]})

#echo ${USV_STATUS[1]}
#echo ${USV_CTIME[2]}
#echo ${USV_TIME[0]}

case ${USV_STATUS[1]} in
  "ok")
	STATUS=0
	TEXT="OK, autonomy time: "${USV_TIME[0]}" minutes"
	;;
  "powerfail")
	TEXT="PROBLEM: Poerfail, time remaining "${USV_TIME[0]}" minutes"
	if [ ${USV_TIME[0]} -lt $CRIT ]; then
		STATUS=1
	elif [ ${USV_TIME[0]} -lt $WARN ]; then
		STATUS=1
	fi
	;;
  *)
	STATUS=3
	TEXT="UNKNOWN"
	;;
esac


echo $STATUS" ONLINE-USV time=${USV_TIME[0]};$WARN;$CRIT;0;$MAX "$TEXT

Check für Adaptec-Controller die von arcconf unterstützt werden

Lokaler Check, kopieren nach: /usr/lib/check_mk_agent/local/adaptec

#!/bin/bash
#
# 08/2011 Matthias Henze
# Lizenz: GPL v2
#
# Check für Adaptec-Controlleer die von "arcconf" unterstützt werden


# basis01:~# arcconf GETCONFIG 1 AD | grep Status
#   Controller Status                        : Optimal
#   Status                                   : ZMM Optimal
# basis01:~# arcconf GETCONFIG 1 AD | grep Model
#   Controller Model                         : Adaptec 6405

get_model () {
        MODEL=$(arcconf GETCONFIG $1 AD | grep Model | cut -d ":" -f 2)
        MODEL=${MODEL/ /}
        MODEL=${MODEL// /-}
}

for C in $(arcconf GETVERSION | grep "Controller #" | cut -d "#" -f 2)
do
        get_model $C
        STATUS=$(arcconf GETCONFIG $C AD | grep "Controller Status" | cut -d ":" -f 2)
        TEXT="Controller: $C, Status: $STATUS"
        if [ "$STATUS" != "${STATUS/Optimal}" ]; then
                ST=0
        else
                ST=2
        fi
        arcconf GETCONFIG $C AD | grep -q "ZMM" >/dev/null
        if [ $? ]; then
                ZMM=$(arcconf GETCONFIG $C AD | grep "ZMM" | grep "Status" | cut -d ":" -f 2)
                TEXT="$TEXT, $ZMM"
                if [ "$STATUS" != "${STATUS/Optimal}" ]; then
                        ST=$ST
                else
                        ST=2
                fi
        fi
        echo "$ST $MODEL - $TEXT"
done


#basis01:~# arcconf GETCONFIG 1 LD
#Logical device number 0
#   Logical device name                      : a1
#   RAID level                               : 5
#   Status of logical device                 : Optimal
#   Size                                     : 5713910 MB

for C in $(arcconf GETVERSION | grep "Controller #" | cut -d "#" -f 2)
do
        get_model $C
        arcconf GETCONFIG $C LD | awk -v M=$MODEL -v C=$C -- '
BEGIN { N=0 }
/Logical device number/    { N=N+1
                             LD[N,1]=$4 }
/Logical device name/      { LD[N,2]=$5 }
/RAID level/               { LD[N,3]=$4 }
/Status of logical device/ { LD[N,4]=$6 }
/Size/                     { LD[N,5]=$3;
                             LD[N,6]=$4 }
END {
for ( i=1; i<=N; i++ ) {
   if ( LD[i,4] == "Optimal" ) ST=0; else ST=2;
   printf("%s %s-LD-%s - Controller: %s, Logicaldrive: %s, Name: %s, RaidLevel: %s, Status: %s, Size: %s %s\n", ST,M,LD[i,1],C,LD[i,1],LD[i,2],LD[i,3],LD[i,4],LD[i,5],LD[i,6])
}
}'
done



#basis01:~# arcconf GETCONFIG 1 PD
#      Device #0
#         State                              : Online
#         Transfer Speed                     : SATA 6.0 Gb/s
#         Model                              : ST2000DL003-9VT1
#         Size                               : 1907729 MB

for C in $(arcconf GETVERSION | grep "Controller #" | cut -d "#" -f 2)
do
        get_model $C
        arcconf GETCONFIG $C PD | awk -v M=$MODEL -v C=$C -- '
BEGIN { N=0 }
/Device #/       { N=N+1;
                   split($0,a,"#");
                   DR[N,1]=a[2] }
/  State  /      { DR[N,2]=$3 }
/Transfer Speed/ { split($0,a,": ");
                   DR[N,3]=a[2] }
/Model/          { DR[N,4]=$3 }
/Size/           { DR[N,5]=$3;
                   DR[N,6]=$4 }
END {
for ( i=1; i<=N; i++ ) {
   if ( DR[i,2] == "Online" ) ST=0; else ST=2;
   printf("%s %s-DR-%s - Controller: %s, Drive: %s, State: %s, Speed: %s, Model: %s, Size: %s %s\n", ST,M,DR[i,1],C,DR[i,1],DR[i,2],DR[i,3],DR[i,4],DR[i,5],DR[i,6])
}
}
'
done
Persönliche Werkzeuge
Navigation