summaryrefslogtreecommitdiff
path: root/openwrt/check_mk_agent
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-11-24 22:04:16 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-11-24 22:04:16 (GMT)
commit091f0037abe7ac3144199956d943c1537a95cdd9 (patch)
tree798738e6e5d50fb2e34b4b6eab24cf7c2357ad27 /openwrt/check_mk_agent
parent6e9ad0a47bfb642ee032b907c79364055a655b40 (diff)
added check-mk agent package for openwrt
Diffstat (limited to 'openwrt/check_mk_agent')
-rw-r--r--openwrt/check_mk_agent/Makefile54
-rw-r--r--openwrt/check_mk_agent/files/check_mk.xinetd44
-rwxr-xr-xopenwrt/check_mk_agent/files/check_mk_agent441
3 files changed, 539 insertions, 0 deletions
diff --git a/openwrt/check_mk_agent/Makefile b/openwrt/check_mk_agent/Makefile
new file mode 100644
index 0000000..6d17910
--- /dev/null
+++ b/openwrt/check_mk_agent/Makefile
@@ -0,0 +1,54 @@
+#
+# Copyright (C) 2016 Christian Pointner,
+# <equinox@helsinki.at>
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+# This Makefile builds check_mk_agent Package for OpenWRT
+#
+# $Id: $
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=check_mk_agent
+PKG_VERSION:=2016-11-24
+PKG_RELEASE:=1
+
+PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/check_mk_agent
+ SECTION:=utils
+ CATEGORY:=Utilities
+ TITLE:=check-mk agent
+ URL:=http://www.helsinki.at
+ MAINTAINER:=Christian Pointner <equinox@helsinki.at>
+ DEPENDS:=+xinetd
+endef
+
+define Package/check_mk_agent/conffiles
+/etc/xinetd.d/check_mk
+endef
+
+define Package/check_mk_agent/description
+Agent for the check-mk monitoring service.
+endef
+
+define Build/Configure
+endef
+
+define Build/Compile
+endef
+
+define Package/check_mk_agent/install
+ $(INSTALL_DIR) $(1)/usr/lib/check_mk_agent/local
+ $(INSTALL_DIR) $(1)/usr/lib/check_mk_agent/plugins
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) ./files/check_mk_agent $(1)/usr/bin/
+ $(INSTALL_DIR) $(1)/etc/xinetd.d/
+ $(INSTALL_BIN) ./files/check_mk.xinetd $(1)/etc/xinetd.d/check_mk
+endef
+
+$(eval $(call BuildPackage,check_mk_agent))
diff --git a/openwrt/check_mk_agent/files/check_mk.xinetd b/openwrt/check_mk_agent/files/check_mk.xinetd
new file mode 100644
index 0000000..6cd2276
--- /dev/null
+++ b/openwrt/check_mk_agent/files/check_mk.xinetd
@@ -0,0 +1,44 @@
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2013 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 = /usr/bin/check_mk_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 = yes
+}
diff --git a/openwrt/check_mk_agent/files/check_mk_agent b/openwrt/check_mk_agent/files/check_mk_agent
new file mode 100755
index 0000000..bd5fca9
--- /dev/null
+++ b/openwrt/check_mk_agent/files/check_mk_agent
@@ -0,0 +1,441 @@
+#!/bin/sh
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2013 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.
+
+# 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"
+
+# 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 about local checks.
+LOCALDIR=$MK_LIBDIR/local
+
+# All files in SPOOLDIR will simply appended to the agent
+# output if they are not outdated (see below)
+SPOOLDIR=$MK_CONFDIR/spool
+
+
+# close standard input (for security reasons) and stderr
+if [ "$1" = -d ]
+then
+ set -xv
+else
+ exec </dev/null 2>/dev/null
+fi
+
+echo '<<<check_mk>>>'
+echo Version: 1.2.4p5
+echo AgentOS: linux
+echo PluginsDirectory: $PLUGINSDIR
+echo LocalDirectory: $LOCALDIR
+echo SpoolDirectory: $SPOOLDIR
+echo AgentDirectory: $MK_CONFDIR
+
+# If we are called via xinetd, try to find only_from configuration
+if [ -n "$REMOTE_HOST" ]
+then
+ echo -n 'OnlyFrom: '
+ echo $(sed -n '/^service[[:space:]]*check_mk/,/}/s/^[[:space:]]*only_from[[:space:]]*=[[:space:]]*\(.*\)/\1/p' /etc/xinetd.d/* | head -n1)
+fi
+
+# Print out Partitions / Filesystems. (-P gives non-wrapped POSIXed output)
+# Heads up: NFS-mounts are generally supressed to avoid agent hangs.
+# If hard NFS mounts are configured or you have too large nfs retry/timeout
+# settings, accessing those mounts from the agent would leave you with
+# thousands of agent processes and, ultimately, a dead monitored system.
+# These should generally be monitored on the NFS server, not on the clients.
+
+echo '<<<df>>>'
+# The exclusion list is getting a bit of a problem. -l should hide any remote FS but seems
+# to be all but working.
+excludefs="-x smbfs -x tmpfs -x cifs -x iso9660 -x udf -x nfsv4 -x nfs -x mvfs -x zfs"
+df -PTlk $excludefs | sed 1d
+
+# Filesystem usage for ZFS
+if type zfs > /dev/null 2>&1 ; then
+ echo '<<<zfsget>>>'
+ zfs get -Hp name,quota,used,avail,mountpoint,type
+ echo '[df]'
+ df -PTlk -t zfs | sed 1d
+fi
+
+# Check mount options. Filesystems may switch to 'ro' in case
+# of a read error.
+echo '<<<mounts>>>'
+grep ^/dev < /proc/mounts
+
+### TODO: openwrt ps does not work with this...
+# processes including username, without kernel processes
+#echo '<<<ps>>>'
+#ps ax -o user,vsz,rss,pcpu,command --columns 10000 | sed -e 1d -e 's/ *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) */(\1,\2,\3,\4) /'
+
+
+# Memory usage
+echo '<<<mem>>>'
+egrep -v '^Swap:|^Mem:|total:' < /proc/meminfo
+
+# Load and number of processes
+echo '<<<cpu>>>'
+echo "$(cat /proc/loadavg) $(grep -E '^CPU|^processor' < /proc/cpuinfo | wc -l)"
+
+# Uptime
+echo '<<<uptime>>>'
+cat /proc/uptime
+
+
+# New variant: Information about speed and state in one section
+echo '<<<lnx_if:sep(58)>>>'
+sed 1,2d /proc/net/dev
+if type ethtool > /dev/null
+then
+ for eth in $(sed -e 1,2d < /proc/net/dev | cut -d':' -f1 | sort)
+ do
+ echo "[$eth]"
+ ethtool $eth | egrep '(Speed|Duplex|Link detected|Auto-negotiation):'
+ echo -en "\tAddress: " ; cat /sys/class/net/$eth/address
+ done
+fi
+
+
+# Current state of bonding interfaces
+if [ -e /proc/net/bonding ] ; then
+ echo '<<<lnx_bonding:sep(58)>>>'
+ pushd /proc/net/bonding > /dev/null ; head -v -n 1000 * ; popd
+fi
+
+# Same for Open vSwitch bonding
+if type ovs-appctl > /dev/null ; then
+ echo '<<<ovs_bonding:sep(58)>>>'
+ for bond in $(ovs-appctl bond/list | sed -e 1d | cut -f2) ; do
+ echo "[$bond]"
+ ovs-appctl bond/show $bond
+ done
+fi
+
+
+# Number of TCP connections in the various states
+echo '<<<tcp_conn_stats>>>'
+# waitmax 10 netstat -nt | awk ' /^tcp/ { c[$6]++; } END { for (x in c) { print x, c[x]; } }'
+# New implementation: netstat is very slow for large TCP tables
+cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | awk ' /:/ { c[$4]++; } END { for (x in c) { print x, c[x]; } }'
+
+# Platten- und RAID-Status von LSI-Controlleren, falls vorhanden
+if type 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
+
+# Multipathgeraete
+if type multipath >/dev/null ; then
+ echo '<<<multipath>>>'
+ multipath -l
+fi
+
+# Soft-RAID
+echo '<<<md>>>'
+cat /proc/mdstat
+
+# Performancecounter Platten
+echo '<<<diskstat>>>'
+date +%s
+egrep ' (x?[shv]d[a-z]*|cciss/c[0-9]+d[0-9]+|emcpower[a-z]+|dm-[0-9]+|VxVM.*|mmcblk.*) ' < /proc/diskstats
+if type dmsetup >/dev/null ; then
+ echo '[dmsetup_info]'
+ dmsetup info -c --noheadings --separator ' ' -o name,devno,vg_name,lv_name
+fi
+if [ -d /dev/vx/dsk ] ; then
+ echo '[vx_dsk]'
+ stat -c "%t %T %n" /dev/vx/dsk/*/*
+fi
+
+
+# Performancecounter Kernel
+echo '<<<kernel>>>'
+date +%s
+cat /proc/vmstat /proc/stat
+
+
+# State of LSI MegaRAID controller via MegaCli. You can download that tool from:
+# http://www.lsi.com/downloads/Public/MegaRAID%20Common%20Files/8.02.16_MegaCLI.zip
+
+if type MegaCli >/dev/null ; then
+ echo '<<<megaraid_pdisks>>>'
+ for part in $(MegaCli -EncInfo -aALL -NoLog < /dev/null \
+ | sed -rn 's/:/ /g; s/[[:space:]]+/ /g; s/^ //; s/ $//; s/Number of enclosures on adapter ([0-9]+).*/adapter \1/g; /^(Enclosure|Device ID|adapter) [0-9]+$/ p'); do
+ [ $part = adapter ] && echo ""
+ [ $part = 'Enclosure' ] && echo -ne "\ndev2enc"
+ echo -n " $part"
+ done
+ echo
+ MegaCli -PDList -aALL -NoLog < /dev/null | egrep 'Enclosure|Raw Size|Slot Number|Device Id|Firmware state|Inquiry|Adapter'
+ 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
+
+# 3WARE disk controller (by Radoslaw Bak)
+if type tw_cli > /dev/null ; then
+ for C in $(tw_cli show | awk 'NR < 4 { next } { print $1 }'); do
+ echo '<<<3ware_info>>>'
+ tw_cli /$C show all | egrep 'Model =|Firmware|Serial'
+ echo '<<<3ware_disks>>>'
+ tw_cli /$C show drivestatus | egrep 'p[0-9]' | sed "s/^/$C\//"
+ echo '<<<3ware_units>>>'
+ tw_cli /$C show unitstatus | egrep 'u[0-9]' | sed "s/^/$C\//"
+ done
+fi
+
+# VirtualBox Guests. Section must always been output. Otherwise the
+# check would not be executed in case no guest additions are installed.
+# And that is something the check wants to detect
+echo '<<<vbox_guest>>>'
+if type VBoxControl > /dev/null 2>&1 ; then
+ VBoxControl -nologo guestproperty enumerate | cut -d, -f1,2
+ [ ${PIPESTATUS[0]} = 0 ] || echo "ERROR"
+fi
+
+# OpenVPN Clients. Currently we assume that the configuration # is in
+# /etc/openvpn. We might find a safer way to find the configuration later.
+if [ -e /etc/openvpn/openvpn-status.log ] ; then
+ echo '<<<openvpn_clients:sep(44)>>>'
+ sed -n -e '/CLIENT LIST/,/ROUTING TABLE/p' < /etc/openvpn/openvpn-status.log | sed -e 1,3d -e '$d'
+fi
+
+if type ntpq > /dev/null 2>&1 ; then
+ # remove heading, make first column space separated
+ ntpq -n -p | sed -e 1,2d -e 's/^\(.\)/\1 /' -e 's/^ /%/'
+fi
+
+if [ -e /proc/drbd ]; then
+ echo '<<<drbd>>>'
+ cat /proc/drbd
+fi
+
+# Status of CUPS printer queues
+if type lpstat > /dev/null 2>&1; then
+ if pgrep cups > /dev/null 2>&1; then
+ echo '<<<cups_queues>>>'
+ CPRINTCONF=/etc/cups/printers.conf
+ if [ -r "$CPRINTCONF" ] ; then
+ LOCAL_PRINTERS=$(grep -E "<(Default)?Printer .*>" $CPRINTCONF | awk '{print $2}' | sed -e 's/>//')
+ lpstat -p | while read LINE
+ do
+ PRINTER=$(echo $LINE | awk '{print $2}')
+ if echo "$LOCAL_PRINTERS" | grep -q "$PRINTER"; then
+ echo $LINE
+ fi
+ done
+ echo '---'
+ lpstat -o | while read LINE
+ do
+ PRINTER=$(echo $LINE | awk '{print $2}')
+ if echo "$LOCAL_PRINTERS" | grep -q "$PRINTER"; then
+ echo $LINE
+ fi
+ done
+ else
+ lpstat -p
+ echo '---'
+ lpstat -o | sort
+ fi
+ fi
+fi
+
+# Heartbeat monitoring
+# Different handling for heartbeat clusters with and without CRM
+# for the resource state
+if [ -S /var/run/heartbeat/crm/cib_ro -o -S /var/run/crm/cib_ro ] || pgrep crmd > /dev/null 2>&1; then
+ echo '<<<heartbeat_crm>>>'
+ crm_mon -1 -r | grep -v ^$ | sed 's/^ //; /^\sResource Group:/,$ s/^\s//; s/^\s/_/g'
+fi
+if type cl_status > /dev/null 2>&1; then
+ echo '<<<heartbeat_rscstatus>>>'
+ cl_status rscstatus
+
+ echo '<<<heartbeat_nodes>>>'
+ for NODE in $(cl_status listnodes); do
+ if [ $NODE != $(echo $HOSTNAME | tr 'A-Z' 'a-z') ]; 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
+
+# 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.a
+#
+# 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 type mailq >/dev/null 2>&1 && [ -x /usr/sbin/postfix ] && getent passwd postfix >/dev/null 2>&1; then
+ echo '<<<postfix_mailq>>>'
+ mailq | tail -n 6
+elif [ -x /usr/sbin/ssmtp ] ; then
+ echo '<<<postfix_mailq>>>'
+ mailq 2>&1 | sed 's/^[^:]*: \(.*\)/\1/' | tail -n 6
+fi
+
+#Check status of qmail mailqueue
+if type qmail-qstat >/dev/null
+then
+ echo "<<<qmail_stats>>>"
+ qmail-qstat
+fi
+
+
+# Welcome the ZFS check on Linux
+# We do not endorse running ZFS on linux if your vendor doesnt support it ;)
+# check zpool status
+if type zpool >/dev/null; then
+ echo "<<<zpool_status>>>"
+ zpool status -x
+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 -c "%n|%s|%Y" $(cat "$MK_CONFDIR/fileinfo.cfg")
+fi
+
+# Get statistics about monitored jobs. Below the job directory there
+# is a sub directory per user that ran a job. That directory must be
+# owned by the user so that a symlink or hardlink attack for reading
+# arbitrary files can be avoided.
+if pushd /var/lib/check_mk_agent/job >/dev/null; then
+ echo '<<<job>>>'
+ for username in *
+ do
+ if [ -d "$username" ] && cd "$username" ; then
+ su "$username" -c "head -n -0 -v *"
+ cd ..
+ fi
+ done
+ popd > /dev/null
+fi
+
+# Gather thermal information provided e.g. by acpi
+# At the moment only supporting thermal sensors
+if ls /sys/class/thermal/thermal_zone* >/dev/null 2>&1; then
+ echo '<<<lnx_thermal>>>'
+ for F in /sys/class/thermal/thermal_zone*; do
+ echo -n "${F##*/} "
+ cat $F/{mode,type,temp,trip_point_*} | tr \\n " "
+ echo
+ done
+fi
+
+# MK's Remote Plugin Executor
+if [ -e "$MK_CONFDIR/mrpe.cfg" ]
+then
+ echo '<<<mrpe>>>'
+ grep -Ev '^[[:space:]]*($|#)' "$MK_CONFDIR/mrpe.cfg" | \
+ while read descr cmdline
+ do
+ PLUGIN=${cmdline%% *}
+ OUTPUT=$(eval "$cmdline")
+ echo -n "(${PLUGIN##*/}) $descr $? $OUTPUT" | tr \\n \\1
+ echo
+ done
+fi
+
+
+# Local checks
+echo '<<<local>>>'
+if cd $LOCALDIR ; then
+ for skript in $(ls) ; do
+ if [ -f "$skript" -a -x "$skript" ] ; then
+ ./$skript
+ fi
+ done
+fi
+
+# Plugins
+if cd $PLUGINSDIR ; then
+ for skript in $(ls) ; do
+ if [ -f "$skript" -a -x "$skript" ] ; then
+ ./$skript
+ fi
+ done
+fi
+
+# Agent output snippets created by cronjobs, etc.
+if [ -d "$SPOOLDIR" ]
+then
+ pushd "$SPOOLDIR" > /dev/null
+ now=$(date +%s)
+
+ for file in *
+ do
+ # output every file in this directory. If the file is prefixed
+ # with a number, then that number is the maximum age of the
+ # file in seconds. If the file is older than that, it is ignored.
+ maxage=""
+ part="$file"
+
+ # Each away all digits from the front of the filename and
+ # collect them in the variable maxage.
+ while [ "${part/#[0-9]/}" != "$part" ]
+ do
+ maxage=$maxage${part:0:1}
+ part=${part:1}
+ done
+
+ # If there is at least one digit, than we honor that.
+ if [ "$maxage" ] ; then
+ mtime=$(stat -c %Y "$file")
+ if [ $((now - mtime)) -gt $maxage ] ; then
+ continue
+ fi
+ fi
+
+ # Output the file
+ cat "$file"
+ done
+ popd > /dev/null
+fi