diff options
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | debian/changelog | 6 | ||||
-rw-r--r-- | debian/compat | 1 | ||||
-rw-r--r-- | debian/control | 18 | ||||
-rw-r--r-- | debian/copyright | 2 | ||||
-rw-r--r-- | debian/fswarn.postinst | 18 | ||||
-rw-r--r-- | debian/fswarn.postrm | 15 | ||||
-rwxr-xr-x | debian/rules | 4 | ||||
-rw-r--r-- | debian/source/format | 1 | ||||
-rwxr-xr-x | etc/cron.hourly/fswarn | 42 | ||||
-rw-r--r-- | etc/default/fswarn | 12 |
11 files changed, 127 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..35307f5 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +build: + +install: + install -o root -g root -m 755 -d $(DESTDIR)/etc/cron.hourly + install -o root -g root -m 755 -d $(DESTDIR)/etc/default + install -o root -g root -m 755 etc/cron.hourly/fswarn $(DESTDIR)/etc/cron.hourly + install -o root -g root -m 644 etc/default/fswarn $(DESTDIR)/etc/default/fswarn +clean: diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..4bd9095 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,6 @@ +fswarn (0.1) unstable; urgency=low + + * Initial release. + + -- Joe Rayhawk <jrayhawk@omgwallhack.org> Sat, 08 Sep 2012 11:01:59 -0700 + diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +7 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..06e1e6a --- /dev/null +++ b/debian/control @@ -0,0 +1,18 @@ +Source: fswarn +Maintainer: Joe Rayhawk <jrayhawk@omgwallhack.org> +Section: admin +Build-depends: debhelper (>= 7) +Priority: extra +Homepage: http://piny.be/fswarn/ +Standards-version: 3.9.1 + +Package: fswarn +Architecture: all +Depends: ${misc:Depends} +Recommends: mail-transport-agent, cron +Description: cron.hourly filesystem utilization check + Prints warnings of utilization of total blocks or inodes over a configurable + percentage threshold. + . + fswarn relies on the MAILTO function of cron. An MTA should probably be + present and operational for this to do anything useful. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..f626d21 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,2 @@ +Copyright © 2010 Joe Rayhawk <jrayhawk@omgwallhack.org> +Licensed under the BSD 3-clause license. diff --git a/debian/fswarn.postinst b/debian/fswarn.postinst new file mode 100644 index 0000000..3e859e2 --- /dev/null +++ b/debian/fswarn.postinst @@ -0,0 +1,18 @@ +#!/bin/sh + +set -e + +case "$1" in + + configure) + + if [ "$2" = "" ]; then + mkdir /var/lib/fswarn || true + fi + + ;; + + *) + ;; + +esac diff --git a/debian/fswarn.postrm b/debian/fswarn.postrm new file mode 100644 index 0000000..1c31ccd --- /dev/null +++ b/debian/fswarn.postrm @@ -0,0 +1,15 @@ +#!/bin/sh + +set -e + +case "$1" in + + purge) + rm -r /var/lib/fswarn/ || true + ;; + + *) + ;; + +esac + diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..2d33f6a --- /dev/null +++ b/debian/rules @@ -0,0 +1,4 @@ +#!/usr/bin/make -f + +%: + dh $@ diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native) diff --git a/etc/cron.hourly/fswarn b/etc/cron.hourly/fswarn new file mode 100755 index 0000000..82fe6df --- /dev/null +++ b/etc/cron.hourly/fswarn @@ -0,0 +1,42 @@ +#!/bin/sh +# statf() warning system intended for use with cron + +#set -x + +if ! grep -q /usr/bin/lckdo /proc/$PPID/cmdline; then + exec /usr/bin/lckdo /run/fswarn $0 "$@"; +fi + +THRESHOLD=90 +STATEFILE=/var/lib/fswarn/state + +[ -s /etc/default/fswarn ] && . /etc/default/fswarn + +trap 'rm ${STATETEMP}' EXIT +STATETEMP=$(mktemp fswarn.XXXXXXXX) + +for i in $( grep -E ' ('$( for FSTYPE in $( grep -v ^nodev /proc/filesystems ); do echo -n "$FSTYPE|"; done; echo -n "ramfs|tmpfs" )') ' /proc/mounts | cut -f 2 -d ' ' | sort -u ); do + BLOCKFREE=$( stat -f -c %a $i ) + BLOCKTOTAL=$( stat -f -c %b $i ) + BLOCKALLOC=$(( ${BLOCKTOTAL} - ${BLOCKFREE} )) + BLOCKPERCENT=$(( 100 * ${BLOCKALLOC} / ${BLOCKTOTAL} )) + BLOCKOLDPERCENT=$( grep "^${i} " ${STATEFILE} | cut -f 4 -d ' ' | grep . ) 2>/dev/null || BLOCKOLDPERCENT=0 + if [ ${BLOCKPERCENT} -gt ${BLOCKOLDPERCENT} ] && [ ${BLOCKPERCENT} -gt ${THRESHOLD} ] ; then + echo "WARNING: $i is at %${BLOCKPERCENT} block utilization!" > /dev/stderr + fi + echo -n "$i ${BLOCKALLOC} ${BLOCKTOTAL} ${BLOCKPERCENT}" + INODEFREE=$( stat -f -c %d $i ) + INODETOTAL=$( stat -f -c %c $i ) + if [ $INODETOTAL -gt 0 ]; then + INODEALLOC=$(( ${INODETOTAL} - ${INODEFREE} )) + INODEPERCENT=$(( 100 * ${INODEALLOC} / ${INODETOTAL} )) + INODEOLDPERCENT=$( grep "^${i} " ${STATEFILE} | cut -f 7 -d ' ' | grep . ) 2>/dev/null || INODEOLDPERCENT=0 + if [ ${INODEPERCENT} -gt ${INODEOLDPERCENT} ] && [ ${INODEPERCENT} -gt ${THRESHOLD} ] ; then + echo "WARNING: $i is at %${INODEPERCENT} inode utilization!" > /dev/stderr + fi + echo -n " ${INODEALLOC} ${INODETOTAL} ${INODEPERCENT}" + fi + echo +done > ${STATETEMP} +cp ${STATETEMP} ${STATEFILE} + diff --git a/etc/default/fswarn b/etc/default/fswarn new file mode 100644 index 0000000..90608ac --- /dev/null +++ b/etc/default/fswarn @@ -0,0 +1,12 @@ +## Defaults for the fswarn cron script, sourced by /etc/cron.hourly/fswarn on +## Debian systems. Uncomment (remove the leading '#') and change values as +## needed. + +## Percentage of filesystem utilization (block and inode) above which fswarn +## will generate output. Defaults to 90. +# THRESHOLD=90 + +## The state file used to store previous runs so as to avoid repeated warnings. +## Defaults to /var/lib/fswarn/state +## Disable redundant warning suppression with /dev/null +# STATEFILE=/var/lib/fswarn/state |