Skip to content

Commit

Permalink
Added comments!
Browse files Browse the repository at this point in the history
  • Loading branch information
zapalotta committed Jan 26, 2016
1 parent 108d8d9 commit afccc9b
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 10 deletions.
102 changes: 92 additions & 10 deletions checks/local/zpoolmac
Original file line number Diff line number Diff line change
@@ -1,16 +1,93 @@
#!/bin/sh
# Based on: NRPE check for zpool
# Written by: Søren Klintrup <soren at klintrup.dk>
# http://soren.klintrup.dk/zpool/
# version 1.1


#echo '<<<zpool>>>'
#calc(){ awk "BEGIN { print "$*" }" }
#
# ============================== SUMMARY =====================================
#
# Program : zpoolmac
# Version : 0.1
# Date : January 26 2016
# Author : Dirk Doerflinger - dirk(at)doerflinger(dot)org
# Summary : This is a local check for check_mk to check zfs pools on mac
#
# Licence : MIT
#
# =========================== PROGRAM LICENSE =================================
#
# Copyright (C) 2016 Dirk Doerflinger
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# ===================== INFORMATION ABOUT THIS PLUGIN =========================
#
# This local chekc for check_mk uses the zpool command to check the health of
# a zpool on OS X (tested on El Capitan using OpenZFS on OS X).
# It also provides performance data.
#
# This program is written and maintained by:
# Dirk Doerflinger - dirk(at)doerflinger(dot)org
#
# ============================= SETUP NOTES ====================================
#
# Set up check_mk_agent on OS X. I put the agent in /usr/local/bin and adjust
# its path settings like this:
#
# export MK_LIBDIR="/usr/local/lib/check_mk_agent"
# export MK_CONFDIR="/etc/check_mk"
# export MK_VARDIR="/var/lib/check_mk_agent"
#
# Also set up either xinetd or a LaunchDaemon and test from your monitor host
#
# Copy the file to /usr/local/lib/check_mk_agent/local
# Make sure it is executable
#
# In order to test do the following steps:
#
# 1.) On your mac run
# $> /usr/local/lib/check_mk_agent/local/zpoolmac
#
# The result should be something like
# 0 zpool_Pool2 size=7645041786|free=7645041786|usedpercent=0;95;98 online
#
# 2.) Also on your mac run
# $> /usr/local/bin/check_mk_agent
#
# If you search for <<<local>>> in the output, the same lines as above should
# appear.
#
# 3.) Test on the monitor host:
# First reinventarize the host
# $> check_mk -I machost
# Then run a manual check:
# $> check_mk -d machost
#
# The same lines should appear unter <<<local>>>
#
# ================================ REVISION ==================================
#
# 0.1 Initial release
#
# ============================================================================

PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin"
# check if we have the necessary binaries, otherwise return 3, UNKNOWN
if [ -x "/usr/local/bin/zpool" ]
then
# Create a list of all pools
DEVICES="$(zpool list -H -o name)"
else
echo "3 $DEVICESTRING zpool executable not found"
Expand All @@ -19,9 +96,12 @@ unset ERRORSTRING
unset OKSTRING
unset ERR

# Iterate over all pools
for DEVICE in ${DEVICES}
do
# Get the health status of the pool
HEALTHSTRING="$(zpool list -H -o health ${DEVICE})"
# Normalize Size, Allocation and Free values
SIZESTRING="$(zpool list -H -o size ${DEVICE})"
SIZEUNIT="${SIZESTRING: -1}"
S=${SIZESTRING%?}
Expand Down Expand Up @@ -56,7 +136,6 @@ do
FREE=$(echo "$F * 1024 * 1024 * 1024 * 1024" | bc -l)
;;
esac

ALLOCSTRING="$(zpool list -H -o alloc ${DEVICE})"
ALLOCUNIT="${ALLOCSTRING: -1}"
A=${ALLOCSTRING%?}
Expand All @@ -74,9 +153,11 @@ do
ALLOC=$(echo "$A * 1024 * 1024 * 1024 * 1024" | bc -l)
;;
esac

# Calculate percentage of used space
USEDPERCENTAGE=$(echo "scale=1;(($ALLOC / $SIZE)*100)/1" | bc -l)
# Create a String with the device indicator (zpool_), the Pool name and usage data
DEVICESTRING="zpool_$DEVICE size=$SIZE|free=$FREE|usedpercent=$USEDPERCENTAGE;95;98"
# Check the health status and react. You could also eg. send a mail on error etc.
if [ "$(echo ${HEALTHSTRING}|tr [:upper:] [:lower:]|sed -Ee 's/.*(degraded|faulted|offline|online|removed|unavail).*/\1/')" = "" ]
then
echo "3 $DEVICESTRING unknown state"
Expand Down Expand Up @@ -115,3 +196,4 @@ do
unset ALLOCSTRING
unset A
done
exit 0
60 changes: 60 additions & 0 deletions checks/plugins/zfsmac
Original file line number Diff line number Diff line change
@@ -1,4 +1,64 @@
#!/bin/sh
#
# ============================== SUMMARY =====================================
#
# Program : zfsmac (plugin)
# Version : 0.1
# Date : January 26 2016
# Author : Dirk Doerflinger - dirk(at)doerflinger(dot)org
# Summary : This is a check_mk plugin for monitoring zfs datasets on OS X
#
# Licence : MIT
#
# =========================== PROGRAM LICENSE =================================
#
# Copyright (C) 2016 Dirk Doerflinger
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# ===================== INFORMATION ABOUT THIS PLUGIN =========================
#
# Local (client) plugin for sending zfs data on OS X (Testet on El Capitan)
# Requires a server check provided in this package, too
#
# This program is written and maintained by:
# Dirk Doerflinger - dirk(at)doerflinger(dot)org
#
# ============================= SETUP NOTES ====================================
#
# Set up check_mk_agent on OS X. I put the agent in /usr/local/bin and adjust
# its path settings like this:
#
# export MK_LIBDIR="/usr/local/lib/check_mk_agent"
# export MK_CONFDIR="/etc/check_mk"
# export MK_VARDIR="/var/lib/check_mk_agent"
#
# Also set up either xinetd or a LaunchDaemon and test from your monitor host
#
# Copy the file to /usr/local/lib/check_mk_agent/plugins
# Make sure it is executable
#
# ================================ REVISION ==================================
#
# 0.1 Initial release
#
# ============================================================================
echo '<<<zfsmac>>>'
/usr/local/bin/zfs list -p | tail -n +2

61 changes: 61 additions & 0 deletions checks/server/zfsmac
Original file line number Diff line number Diff line change
@@ -1,4 +1,63 @@
#!/usr/bin/python
#
# ============================== SUMMARY =====================================
#
# Program : zfsmac (server side check)
# Version : 0.1
# Date : January 26 2016
# Author : Dirk Doerflinger - dirk(at)doerflinger(dot)org
# Summary : This is a check_mk check for zfs datasets provided from the
# OS X plugin
#
# Licence : MIT
#
# =========================== PROGRAM LICENSE =================================
#
# Copyright (C) 2016 Dirk Doerflinger
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# ===================== INFORMATION ABOUT THIS PLUGIN =========================
#
# This check_mk check parses data provided by the zfsmac plugin for checking
# dtaatsets on OS X (Tested on EL Capitan).
# It also sends performance data, though that must be handled with care due to
# wrong calculations. Use the performance data from zpoolmac rather.
#
# This program is written and maintained by:
# Dirk Doerflinger - dirk(at)doerflinger(dot)org
#
# ============================= SETUP NOTES ====================================
#
# Copy this file to the checks folder of your check_mk installation. I am using
# OMD and have it in /opt/omd/versions/1.30/share/check_mk/checks/
# Make sure it is executable for the check_mk user
# You also need to have bc installed on the monitoring host!
#
# ================================ REVISION ==================================
#
# 0.1 Initial release
#
# ============================================================================

# Some default values for warning and critical. These can be overwritten in
# check_mk
zfsmac_default_values = (95, 98)

# the inventory function
Expand All @@ -10,6 +69,7 @@ def inventory_zfsmac(info):
# the check function
def check_zfsmac(item, params, info):
warn, crit = params
# Iterate over each line
for line in info:
# is this our line?
if line[0] == item:
Expand All @@ -24,6 +84,7 @@ def check_zfsmac(item, params, info):
spaceGB = space/1024/1024/1024
spaceTB = spaceGB/1024
percentage = used/space*100
# Don't take this for granted!
perfdata = [ ( "used", int( usedGB ) ), ("sum", spaceGB ) ]
if percentage > crit:
return 2, "Capacity used: %dGB (%d%%), Available: %dGB" % (usedGB, percentage, availableGB), perfdata
Expand Down

0 comments on commit afccc9b

Please sign in to comment.