HP Proliant Server SNMP via ESXi Agent

Für das Monitoring von HL Proliant Server ist das Simple Network Management Protocol (SNMP) notwendig. Wenn man auf dem Server ein ESXi Host installiert hat, so bringt das HP Image den Agent schon mit.

Zuerst fragen wir den SNMP ab.

# esxcli system snmp get

   Authentication: 
   Communities: 
   Enable: false
   Engineid: 
   Hwsrc: indications
   Largestorage: true
   Loglevel: info
   Notraps: 
   Port: 161
   Privacy: 
   Remoteusers: 
   Syscontact: 
   Syslocation: 
   Targets: 
   Users: 
   V3targets:

Jetzt müssen wir den SNMP Agent in VMware ESXi aktivieren.

# esxcli system snmp set -c public -e true

Die Ausgabe sieht jetzt anders aus.

# esxcli system snmp get

   Authentication: 
   Communities: public
   Enable: true
   Engineid: 00000063000000a100000000
   Hwsrc: indications
   Largestorage: true
   Loglevel: info
   Notraps: 
   Port: 161
   Privacy: 
   Remoteusers: 
   Syscontact: 
   Syslocation: 
   Targets: 
   Users: 
   V3targets:

SNMP MIB module file download

Check_MK Raw Server Edition installation

Diese Anleitung beschreibt die Installation von Check_MK Raw Server Version 1.2.8 auf Ubuntu Server 16.04 LTE.

Die Installation von Ubuntu Server 16.04 wird einfach mit Standardvorgaben installiert.

Zusätzlich installieren wird ein extra Tool, welcher alle Abhängigkeiten zu Check_mk installiert.

sudo apt-get install gdebi-core

Auf der Download Seite von Check_mk finden wir die Version 1.2.8 Raw, welche 100% kostenlos ist.

Wir laden die 64bit Version für Ubuntu 16.04 runter.

wget https://mathias-kettner.de/support/1.2.8p18/check-mk-raw-1.2.8p18_0.xenial_amd64.deb

Jetzt können wir Check_mk mit allen Abhängigkeiten installieren.

sudo gdebi check-mk-raw-1.2.8p18_0.xenial_amd64.deb

Check_mk verwendet den Apache mit mod_proxy, welches aktiviert werden sollte.

sudo a2enmod proxy_http

Nach einem Neustart ist die Installation schon fast abgeschlossen.

sudo service apache2 restart

Wir können die installierte Version ausgeben.

omd version

Check_mk bietet die Möglichkeit unterschiedliche Seiten gleichzeitig zu betreiben. Wir erstellen eine Beispielseite „mysite“.

sudo omd create mysite
sudo omd start mysite

Jetzt kann man die Seite im Browser erreichen. http://HOSTNAME/mysite/ Der Login lautet „omdadmin“ und das Password ist „omd“.

Ein Update auf eine neue Check_mk Version ist immer möglich. Das Versionsupdate wird in Schritten durchgeführt.

Pfsense 2.3 mit Check_MK Agent

Leider wird das Check_mk Agent Paket für Pfsense nicht weiter entwickelt. Deshalb muss man die Installation vom Check_mk Agent von Hand vornehmen.

Für den Check_mk Agent ist die Installation von Bash notwendig.

pkg install bash

Ausführen über Diagnostics Command Prompt.

Jetzt werden zwei Verzeichnisse erstellt.

mkdir -p /opt/bin
mkdir -p /opt/etc/xinetd.d

Darin wird der Check_mk Agent von Git geladen.

curl --output /opt/bin/check_mk_agent 'https://git.mathias-kettner.de/git/?p=check_mk.git;a=blob_plain;f=agents/check_mk_agent.freebsd;hb=HEAD'

Die Datei wird ausführbar gemacht.

chmod +x /opt/bin/check_mk_agent

Führt man den Check_mk agent aus, sieht man schon das Ergebnis.

/opt/bin/check_mk_agent

Unter Diagnostics Edit File kann man die Konfiguration anpassen.

/opt/etc/xinetd.d/check_mk

# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk 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 in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# ails.  You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.
 
service check_mk
{
	type           = UNLISTED
	port           = 6556
	socket_type    = stream
	protocol       = tcp
	wait           = no
	user           = root
	server         = /opt/bin/check_mk_agent
 
	# If you use fully redundant monitoring and poll the client
	# from more then one monitoring servers in parallel you might
	# want to use the agent cache wrapper:<br />
 
	#server         = /usr/bin/check_mk_caching_agent
 
	# configure the IP address(es) of your Nagios server here:
	#only_from      = 127.0.0.1 10.0.20.1 10.0.20.2
 
	# Don't be too verbose. Don't log every check. This might be
	# commented out for debugging. If this option is commented out
	# the default options will be used for this service.
	log_on_success =
 
	disable        = no
}

Jetzt müssen wir die Filer-Einstellungen anpassen.

/etc/inc/filter.inc

In der Zeile 2375 muss noch eine Zeit eingefügt werden.

fwrite($xinetd_fd, "includedir /opt/etc/xinetd.d");
 
fclose($xinetd_fd);             // Close file handle

Man kann die Änderung auch von einem Skript „/opt/filter_check_mk_cron“ durchführen lassen.

#!/bin/sh
 
grep includedir /etc/inc/filter.inc
if [ $? -eq 0 ]
then
        exit 0
else
        awk '/fclose\(\$xinetd_fd\)\;/{print "fwrite($xinetd_fd, \"includedir /opt/etc/xinetd.d\");"}1' /etc/inc/filter.inc > /etc/inc/filter.inc.temp
        mv /etc/inc/filter.inc.temp /etc/inc/filter.inc
fi
exit 0

Das Script braucht auch Ausführungsrechte.

chmod +x /opt/filter_check_mk_cron

Nach dem Speichern der Datei /etc/inc/filter.inc müssen die Änderungen geladen werden. Das geschieht unter Status Filter Reload.

Jetzt kann man die Funktion prüfen.

telnet localhost 6556

Diese Anleitung ist eine Zusammenfassung von einem Forum Beitrag. Weiter Information zum Check_mk Agent gibt es in der Dokumentation.

Design Patterns

Eine beliebte Frage bei einem Einstellungstest als Softwareentwickler ist nach Design Patterns (Entwurfsmuster). Gut, wenn man dann einige Namen kennt und vielleicht deren Funktionsweise.

Entwurfsmuster

  • Abstract Factory (Abstrakte Fabrik)
  • Builder (Erbauer)
  • Factory Method(Fabrikmethode)
  • Prototype (Prototyp)
  • Singleton (Singleton)

Strukturmuster

  • Adapter (Adapter)
  • Bridge (Brücke)
  • Composite (Komposition)
  • Decorator (Dekorierer)
  • Facade (Fassade)
  • Flyweight (Fliegengewicht)
  • Proxy (Proxy)

Verhaltensmuster

  • Chain of Responsibility (Zuständigkeitskette)
  • Command (Befehl)
  • Interpreter (Interpreter)
  • Iterator (Iterator)
  • Mediator (Vermittler)
  • Memento (Memento)
  • Observer (Beobachter)
  • State (Zustand)
  • Strategy (Strategie)
  • Template Method (Schablonenmethode)
  • Visitor (Besucher)

VMware ESXi Verwaltung ohne Client

VMware ESXi ermöglicht die Verwaltung von Einstellungen ohne den Windows Client.

Wenn man den SSH Zugang aktiviert, kann man sich auch Remote verbinden.

Zuerst müssen wir die Nummer [vmid] der Viruellen Maschine (VM) ermitteln.

vim-cmd vmsvc/getallvms

Jetzt kann man die VM runter fahren.

vim-cmd vmsvc/power.shutdown [vmid]

Den Status der VM kann man erfragen mit…

vim-cmd vmsvc/power.getstate [vmid]

Jetzt kann man im Verzeichnis der VM die Einstellungen ändern.

vi /vmfs/volumes/datastore/vmfolder/name.vmx

Den RAM Speicher wird gesetzt mit der Einstellung memsize = „5120“.

Mit einem Reload wird die Einstellung geladen.

vim-cmd vmsvc/releoad [vmid]

Jetzt kann man die VM wieder einschalten.

vim-cmd vmsvc/power.on [vmid]

HP Tools unter VMware ESXi

Um ein HP Smart Array unter VMware ESXi zu verwalten, braucht man die HP Tools.

Nach dem Download von VMware überträgt man die VIB Datei auf den ESXi Host. Die Installation erfolgt mit dem ESXCLI Tool.

esxcli software vib install -v /tmp/scsi-hpsa-5.0.0.x86_64.vib

Die erfolgteiche Installation kann man auch prüfen.

esxcli software vib list |grep Hewlett

Jetzt kann man die HPacuCli mit dem ganzen Verzeichnis starten.

/opt/hp/hpacucli/bin/hpacucli

Die Anzeige der Einstellungen erhält man hier mit.

hpacucli> ctrl all show config

Den Status einer Festplatte kann man hiermit anzeigen.

hpacucli> ctrl slot=0 pd 1I:1:3 show status

Jede Festplatte hat eine Status LED welche man nutzen kann, um eine defekte Festplatte zu finden.

hpacucli> ctrl slot=0 pd 1I:1:3 modify led=on

http://www.datadisk.co.uk/html_docs/redhat/hpacucli.htm

VMware ESXi Disk verkleinern

Wird wollen eine Disk von einer Virtual Maschine (VM) von einem VMware ESXi Server verkleinern.

Zuerst müssen wir die Sektoren mit Nullen füllen.

Unter Windows gibt es das Tool SDelete.

sdelete.exe -z c:

Unter Linux können wir mit DD oder CAT arbeiten.

dd bs=1M count=8192 if=/dev/zero of=zero.fill;sync;rm -f zero.fill

cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill

Jetzt fahren wir die VM runter und verbinden uns mit dem VMware Host per SSH.

Jetzt können wir den Speicherplatz eine Thin Provisioning Disk wieder verkleinern.

vmkfstools -K /vmfs/volumes/Datastore2/vm1/vm1.vmdk

Sollten wir kein Thin Provisioning verwenden oder die Disk weiter verkeinern wollen, so ist eine Änderung in den Einstellungen notwendig.

Wir öffnen die Einstellungen von der Disk.

vi /vmfs/volumes/Datastore/vm1/vm1.vmdk

Wir suchen den Eintrag mit der Zahl 83886080.

RW 83886080 VMFS "vm1-flat.vmdk"

Die Zahl 83886080 ist die Größe von 40 GB und errechnet sich wie folgt.

40 GB => 40 * 1024 * 1024 * 1024 / 512 = 83886080

Wollen wird die Disk auf 20 GB verringern, so ergibt sich folgede Rechnung.

20 GB => 20 * 1024 * 1024 * 1024 / 512 = 41943040

Zuvor müssen wir sicher gestellt haben, das alle Daten mit einem Partitionstool in die erste Hälte verschoben wurden. Sonst besteht die Möglichkeit, mit der Änderung die Daten im zweiten Teil der Disk zu verlieren.

Jetzt kann die Konvertierung beginnen.

vmkfstools -i "/vmfs/volumes/Datastore2/vm1/vm1.vmdk" "/vmfs/volumes/Datastore2/vm1/vm1-new.vmdk" -d thin -a lsilogic

Check_MK Agent – JSON Daten auslesen

Mit diesem lokalen Check kann man zwei Messwerte (Temperatur und Luftfeuchtigkeit) von einer Messstation per JSON auslesen und an den Check_MK Agent übergeben. Die Daten werden von Check_MK ausgelesen und als Statistik angezeigt.

Für die Verarbeitung von JSON brauchen wir ein kleines Tool mit dem Namen JSON Query, kurz JQ.

sudo apt-get install jq

Die Messwerte haben folgendes JSON Format.

{"sensor":{"temperature":24,"humidity":33},"timestamp":1464340616}

Jetzt erstellen wir ein Shell Script im Verzeichnis /usr/lib/check_mk_agent/local/.

#!/bin/sh
NAME="Sensor"
URL="http://hostname/sensor.json"
 
RESULT=$(curl -s $URL)
TEMP=$(echo $RESULT | jq '.sensor.temperature')
HUMI=$(echo $RESULT | jq '.sensor.humidity')
TIME=$(echo $RESULT | jq '.timestamp')
DATE=$(date -d @$TIME)
 
#TEMP-WARNING=30
#TEMP-CRITICAL=40
#HUMI-WARNING=(Min=20/Max=40)
#HUMI-CRITICAL=(Min=10/Max=60)
 
echo "P ${NAME} Temperature=${TEMP};30;40|Humidity=${HUMI};20:40;10:60;0;100; ${DATE}"

Will man die Daten für 120 Sekunden vom Check_MK Agent zwischen speichern, so erstellt man das Script im Verzeichnis /usr/lib/check_mk_agent/local/120/. Die Daten werden dann im Verzeichnis /etc/check_mk/cache/ für 120 Sekunden gespeichert und erst nach Ablauf der Zeit von einem Hintergrundprozess aktualisiert.

Nach der Inventarisierung in Check_MK, wird ein neue Service „Sensor“ mit zwei Statistiken erzeugt.

Pfsense 2.2 mit Check_MK Agent

Seit Pfsense 2.2 funkioniert das Plugin für den Check_MK Agent nicht mehr, da bei FreeBSD die Bash entfernt wurde.

1. Inet Daemon erstellen

1.1. Datei /etc/rc.d/inetd erstellen

1.2. Quellecode einfügen

#!/bin/sh
#
# $FreeBSD$
#
 
# PROVIDE: inetd
# REQUIRE: DAEMON LOGIN cleanvar
# KEYWORD: shutdown
 
. /etc/rc.subr
 
name="inetd"
rcvar="inetd_enable"
command="/usr/sbin/${name}"
pidfile="/var/run/${name}.pid"
required_files="/etc/${name}.conf"
extra_commands="reload"
 
load_rc_config $name
run_rc_command "$1"

1.3. Ausführerechte ändern

chmod +x /etc/rc.d/inetd

1.4. Starten

/etc/rc.d/inetd start

2. Check_MK Agenten ersetzen

2.1 Quellcode ersetzen in Datei /usr/local/bin/check_mk_agent

2.2 Restart daemon

# service inetd restart

#!/bin/sh
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk 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 in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# ails.  You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.
 
# Author: Lars Michelsen <lm@mathias-kettner.de>
#         Florian Heigl <florian.heigl@gmail.com>
#           (Added sections: df mount mem netctr ipmitool)
 
# NOTE: This agent has beed adapted from the Check_MK linux agent.
#       The most sections are commented out at the moment because
#       they have not been ported yet. We will try to adapt most
#       sections to print out the same output as the linux agent so
#       that the current checks can be used.
 
# This might be a good source as description of sysctl output:
# http://people.freebsd.org/~hmp/utilities/satbl/_sysctl.html
 
# Remove locale settings to eliminate localized outputs where possible
export LC_ALL=C
unset LANG
 
export MK_LIBDIR="/usr/lib/check_mk_agent"
export MK_CONFDIR="/etc/check_mk"
export MK_TMPDIR="/var/run/check_mk"
 
 
# Make sure, locally installed binaries are found
PATH=$PATH:/usr/local/bin
 
# All executables in PLUGINSDIR will simply be executed and their
# ouput appended to the output of the agent. Plugins define their own
# sections and must output headers with '<<<' and '>>>'
PLUGINSDIR=$MK_LIBDIR/plugins
 
# All executables in LOCALDIR will by executabled and their
# output inserted into the section <<<local>>>. Please refer
# to online documentation for details.
LOCALDIR=$MK_LIBDIR/local
 
 
# close standard input (for security reasons) and stderr
#if [ "$1" = -d ]
#then
#    set -xv
#else
#    exec </dev/null 2>/dev/null
#fi
 
# Runs a command asynchronous by use of a cache file
 
echo '<<<check_mk>>>'
echo Version: 1.2.7i1
echo AgentOS: freebsd
 
 
 
osver="$(uname -r)"
is_jailed="$(sysctl -n security.jail.jailed)"
 
 
# Partitionen (-P verhindert Zeilenumbruch bei langen Mountpunkten)
# Achtung: NFS-Mounts werden grundsaetzlich ausgeblendet, um
# Haenger zu vermeiden. Diese sollten ohnehin besser auf dem
# Server, als auf dem Client ueberwacht werden.
 
echo '<<<df>>>'
# no special zfs handling so far, the ZFS.pools plugin has been tested to
# work on FreeBSD
if df -T > /dev/null ; then
    df -kTP -t ufs | egrep -v '(Filesystem|devfs|procfs|fdescfs|basejail)'
else
    df -kP -t ufs | egrep -v '(Filesystem|devfs|procfs|fdescfs|basejail)' | awk '{ print $1,"ufs",$2,$3,$4,$5,$6 }'
fi
 
# Check NFS mounts by accessing them with stat -f (System
# call statfs()). If this lasts more then 2 seconds we
# consider it as hanging. We need waitmax.
#if type waitmax >/dev/null
#then
#    STAT_VERSION=$(stat --version | head -1 | cut -d" " -f4)
#    STAT_BROKE="5.3.0"
#
#    echo '<<<nfsmounts>>>'
#    sed -n '/ nfs /s/[^ ]* \([^ ]*\) .*/\1/p' < /proc/mounts |
#        while read MP
#  do
#   if [ $STAT_VERSION != $STAT_BROKE ]; then
#      waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" || \
#    echo "$MP hanging 0 0 0 0"
#   else
#      waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" && \
#      printf '\n'|| echo "$MP hanging 0 0 0 0"
#   fi
#  done
#fi
 
# Check mount options.
# FreeBSD doesn't do remount-ro on errors, but the users might consider
# security related mount options more important.
echo '<<<mounts>>>'
mount -p -t ufs
 
# processes including username, without kernel processes
echo '<<<ps>>>'
COLUMNS=10000
if [ is_jailed = 0 ]; then
    ps ax -o state,user,vsz,rss,pcpu,command | sed -e 1d  -e '/\([^ ]*J\) */d' -e 's/*\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) */(\2,\3,\4,\5) /'
else
    ps ax -o user,vsz,rss,pcpu,command | sed -e 1d -e 's/ *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) */(\1,\2,\3,\4) /'
fi
 
 
# Produce compatible load/cpu output to linux agent. Not so easy here.
echo '<<<cpu>>>'
echo `sysctl -n vm.loadavg | tr -d '{}'` `top -b -n 1 | grep -E '^[0-9]+ processes' | awk '{print $3"/"$1}'` `sysctl -n kern.lastpid` `sysctl -n hw.ncpu`
 
# Calculate the uptime in seconds since epoch compatible to /proc/uptime in linux
echo '<<<uptime>>>'
  up_seconds=$(( `date +%s` - `sysctl -n kern.boottime  | cut -f1 -d\, | awk '{print $4}'`))
idle_seconds=$(ps axw | grep idle | grep -v grep | awk '{print $4}' | cut -f1 -d\: )
 
# second value can be grabbed from "idle" process cpu time / num_cores
echo "$idle_seconds $up_seconds"
 
 
# Platten- und RAID-Status von LSI-Controlleren, falls vorhanden
#if which cfggen > /dev/null ; then
#   echo '<<<lsi>>>'
#   cfggen 0 DISPLAY | egrep '(Target ID|State|Volume ID|Status of volume)[[:space:]]*:' | sed -e 's/ *//g' -e 's/:/ /'
#fi
 
 
# Multipathing is supported in FreeBSD by now
# http://www.mywushublog.com/2010/06/freebsd-and-multipath/
if kldstat -v | grep g_multipath > /dev/null ; then
    echo '<<<freebsd_multipath>>>'
    gmultipath status | grep -v ^Name
fi
 
 
# Soft-RAID
echo '<<<freebsd_geom_mirrors>>>'
gmirror status | grep -v ^Name
 
# Performancecounter Kernel
echo "<<<kernel>>>"
date +%s
forks=`sysctl -n vm.stats.vm.v_forks`
vforks=`sysctl -n vm.stats.vm.v_vforks`
rforks=`sysctl -n vm.stats.vm.v_rforks`
kthreads=`sysctl -n vm.stats.vm.v_kthreads`
echo "cpu" `sysctl -n kern.cp_time | awk ' { print $1" "$2" "$3" "$5" "$4 } '`
echo "ctxt" `sysctl -n vm.stats.sys.v_swtch`
echo "processes" `expr $forks + $vforks + $rforks + $kthreads`
 
# Network device statistics (Packets, Collisions, etc)
# only the "Link/Num" interface has all counters.
echo '<<<lnx_if:sep(58)>>>'
date +%s
if [ "$(echo $osver | cut -f1 -d\. )" -gt "8" ]; then
    netstat -inb | egrep -v '(^Name|plip|enc|pfsync|pflog|ovpns)' | grep Link | awk '{print"\t"$1":\t"$8"\t"$5"\t"$6"\t"$7"\t0\t0\t0\t0\t"$11"\t"$9"\t"$10"\t0\t0\t0\t0\t0"}'
else
    # pad output for freebsd 7 and before
    netstat -inb | egrep -v '(^Name|lo|plip)' | grep Link | awk '{print $1" "$7" "$5" "$6" 0 0 0 0 0 "$10" "$8" "$9" 0 0 "$11" 0 0"}'
fi
 
 
# State of LSI MegaRAID controller via MegaCli.
# To install: pkg install megacli
if which MegaCli >/dev/null ; then
    echo '<<<megaraid_pdisks>>>'
    MegaCli -PDList -aALL -NoLog < /dev/null | egrep 'Enclosure|Raw Size|Slot Number|Device Id|Firmware state|Inquiry'
    echo '<<<megaraid_ldisks>>>'
    MegaCli -LDInfo -Lall -aALL -NoLog < /dev/null | egrep 'Size|State|Number|Adapter|Virtual'
    echo '<<<megaraid_bbu>>>'
    MegaCli -AdpBbuCmd -GetBbuStatus -aALL -NoLog < /dev/null | grep -v Exit
fi
 
 
# OpenVPN Clients. 
# Correct log location unknown, sed call might also be broken
if [ -e /var/log/openvpn/openvpn-status.log ] ; then
    echo '<<<openvpn_clients:sep(44)>>>'
    sed -n -e '/CLIENT LIST/,/ROUTING TABLE/p' < /var/log/openvpn/openvpn-status.log  | sed -e 1,3d -e '$d' 
fi
 
 
if which ntpq > /dev/null 2>&1 ; then
   echo '<<<ntp>>>'
   # remote heading, make first column space separated
   ntpq -np | sed -e 1,2d -e 's/^\(.\)/\1 /' -e 's/^ /%/'
fi
 
 
# Checks for cups monitoring
#if which lpstat > /dev/null 2>&1; then
#  echo '<<<cups_queues>>>'
#  lpstat -p
#  echo '---'
#  for i in $(lpstat -p | grep -E "^(printer|Drucker)" | awk '{print $2}' | grep -v "@"); do
#    lpstat -o "$i"
#  done
#fi
 
# Heartbeat monitoring
#if which cl_status > /dev/null 2>&1; then
#  # Different handling for heartbeat clusters with and without CRM
#  # for the resource state
#  if [ -S /var/run/heartbeat/crm/cib_ro ]; then
#    echo '<<<heartbeat_crm>>>'
#    crm_mon -1 -r | grep -v ^$ | sed 's/^\s/_/g'
#  else
#    echo '<<<heartbeat_rscstatus>>>'
#    cl_status rscstatus
#  fi
#
#  echo '<<<heartbeat_nodes>>>'
#  for NODE in $(cl_status listnodes); do
#    if [ $NODE != $HOSTNAME ]; then
#      STATUS=$(cl_status nodestatus $NODE)
#      echo -n "$NODE $STATUS"
#      for LINK in $(cl_status listhblinks $NODE 2>/dev/null); do
#        echo -n " $LINK $(cl_status hblinkstatus $NODE $LINK)"
#      done
#      echo
#    fi
#  done
#fi
 
# Number of TCP connections in the various states
echo '<<<tcp_conn_stats>>>'
netstat -na | awk ' /^tcp/ { c[$6]++; } END { for (x in c) { print x, c[x]; } }'
 
 
# Postfix mailqueue monitoring
#
# Only handle mailq when postfix user is present. The mailq command is also
# available when postfix is not installed. But it produces different outputs
# which are not handled by the check at the moment. So try to filter out the
# systems not using postfix by searching for the postfix user.
#
# Cannot take the whole outout. This could produce several MB of agent output
# on blocking queues.
# Only handle the last 6 lines (includes the summary line at the bottom and
# the last message in the queue. The last message is not used at the moment
# but it could be used to get the timestamp of the last message.
#if which mailq >/dev/null 2>&1 && getent passwd postfix >/dev/null 2>&1; then
#  echo '<<<postfix_mailq>>>'
#  mailq | tail -n 6
#fi
 
#Check status of qmail mailqueue
#if type qmail-qstat >/dev/null
#then
#   echo "<<<qmail_stats>>>"
#   qmail-qstat
#fi
 
# check zpool status
#if [ -x /sbin/zpool ]; then
#   echo "<<<zpool_status>>>"
#   /sbin/zpool status -x | grep -v "errors: No known data errors"
#fi
 
# Memory Usage
# currently we'll need sysutils/muse for this.
if [ -x /usr/local/bin/muse ]
then
echo '<<<mem>>>'
# yes, i don't know sed well.
muse -k 2>/dev/null | sed 's/Total/MemTotal/' | sed 's/Free/MemFree/'
swapinfo -k 1K | tail -n 1 | awk '{ print "SwapTotal: "$2" kB\nSwapFree: "$4" kB" }'
fi
 
 
 
# Fileinfo-Check: put patterns for files into /etc/check_mk/fileinfo.cfg
if [ -r "$MK_CONFDIR/fileinfo.cfg" ] ; then
    echo '<<<fileinfo:sep(124)>>>'
    date +%s
    stat -f "%N|%z|%m" $(cat "$MK_CONFDIR/fileinfo.cfg")
fi