Nagios check mk

From Proxmox VE
Jump to navigation Jump to search

This is a check for the Nagios check addon "check_mk" (http://mathias-kettner.de/check_mk.html). The idea is that only VM's that are running while doing the inventory are getting monitored. If a VM is added or removed do a:

check_mk -II tcp proxmoxservername

The check also collects performance data for %CPU load caused by the VM and % of memory consumption of the VM.

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

The path asumes the usage of OMD (Open source Monitoring Distribution)

#!/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 ram: %s MB)" % (status, item, name, ram)
            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)