From: Sven Hoexter Date: Mon, 17 Jan 2011 16:45:46 +0000 (+0100) Subject: Import zabbix helper X-Git-Url: https://git.sven.stormbind.net/?p=sven%2Fscripts.git;a=commitdiff_plain;h=8e9fb924b34bb14a0ce4475b03853d4b526abc33 Import zabbix helper --- diff --git a/zabbixhelper/hpcheck.sh b/zabbixhelper/hpcheck.sh new file mode 100644 index 0000000..d3d06ac --- /dev/null +++ b/zabbixhelper/hpcheck.sh @@ -0,0 +1,114 @@ +#!/bin/sh +# Script to parse and rewrite the hpacucli output so we can feed it to Zabbix. +# sven@timegate.de - 2010-05-13 + +#set -x +VERSION=0.5 + +cleanup() { + if [ -e $clog ]; then + rm $clog + fi +} + +check_ok() { + if [ $rawv -eq 1 ]; then + echo 0 + else + echo 1 + fi +} + +controllerstat() { + sudo hpacucli ctrl all show status > $clog + + #Check if another hpacucli has been active, sleep and try again + if [ $(grep -c '^Another' $clog) -eq 1 ]; then + sleep 10 + controllerstat + cleanup + exit + fi + + constat=1 + chachestat=1 + battstat=1 + + #Check Controller overall status + rawv=$(grep Controller $clog|awk '{print $3}'|grep -c OK) + constat=$(check_ok) + + #Check Cache Status + rawv=$(grep Cache $clog|awk '{print $3}'|grep -c OK) + cachestat=$(check_ok) + + #Check for a battery and it's status if available + if [ $(grep -c Battery $clog) -eq 0 ]; then + battstat=0 + else + rawv=$(grep Battery $clog|awk '{print $3}'|grep -c OK) + battstat=$(check_ok) + fi + + #Calculate overall status and return it + allstat=$(( $constat + $cachestat + $battstat )) + if [ $allstat -eq '0' ]; then + echo 0 + else + echo 1 + fi +} + +diskstat() { + sudo hpacucli ctrl slot=0 pd all show > $clog + + #Check if another hpacucli has been active, sleep and try again + if [ $(grep -c '^Another' $clog) -eq 1 ]; then + sleep 10 + diskstat + cleanup + exit + fi + + drivecount=$(grep -c physicaldrive $clog) + driveok=$(grep -c OK $clog) + + if [ $driveok -eq $drivecount ]; then + echo 0 + else + echo 1 + fi +} + + +### Main script ### +while getopts ":cdh" opt; do + case $opt in + c) + #Create a save tempfile with mktemp + clog=$(mktemp /var/tmp/clog.XXXXXXXXXXXX) + controllerstat + cleanup + ;; + d) + #Create a save tempfile with mktemp + clog=$(mktemp /var/tmp/clog.XXXXXXXXXXXX) + diskstat + cleanup + ;; + h) + echo "HP disk and controller check version $VERSION" + echo "Usage:" + echo "-c Outputs controler overall status as 0 or 1" + echo "-d Outputs disk overall status as 0 or 1" + echo "-h Print this help" + echo "Output legend: 0 equals OK, 1 indicates something went wrong" + exit 1 + ;; + \?) + echo "Unknown option: -$OPTARG" + echo "Try -h to get help" + exit 1 + ;; + esac +done diff --git a/zabbixhelper/mailstat.sh b/zabbixhelper/mailstat.sh new file mode 100644 index 0000000..f1a1c6f --- /dev/null +++ b/zabbixhelper/mailstat.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# Collect some mail stats from Postfix for Zabbix. +# sven@timegate.de - 2010-05-17 + +VERSION=0.2 + +qdir=`/usr/sbin/postconf -h queue_directory` + +while getopts ":idsh" opt; do + case $opt in + d) + find $qdir/deferred -type f -print | wc -l | awk '{print $1}' + ;; + i) + find $qdir/incoming $qdir/active $qdir/maildrop -type f -print|wc -l|awk '{print $1}' + ;; + s) + echo $(( \ + $(du -bs /var/opt/mailhome|cut -f1) + \ + $(du -bs /home/sven/Maildir|cut -f1) + \ + )) + ;; + h) + echo "Mailq stats $VERSION" + echo "Usage:" + echo "-d Outputs number of mails in the deferred queue" + echo "-i Outputs number of mails in the incoming, active and maildrop queue" + echo "-s Total size of the most used Maildir folders in bytes" + echo "-h Print this help" + exit 1 + ;; + \?) + echo "Unknown option: -$OPTARG" + echo "Try -h to get help" + exit 1 + ;; + esac +done