nagios qmail current log alert check 

here is a real dirty way for counting and monitoring how many "alerts" are in qmails current log using bash:
#!/bin/bash
# this script requires Date::Parse module in CPAN

TMP_TIME=/tmp/tmp_time
TMP_FILE=/tmp/tmp_file
TMP_FILE2=/tmp/tmp_file2

if [ -f ${TMP_FILE2} ]; then
rm -f ${TMP_FILE2} && touch ${TMP_FILE2}
fi

# CURTIME is present time in epoch
perl -MDate::Parse -le'print str2time(`date`)' > ${TMP_TIME}
CURTIME=`cat ${TMP_TIME}`

# CURTIMEM2 is CURTIME minus 60 (1 minutes)
let CURTIMEM2=${CURTIME}-60

# tai64n2tai -- http://www.qmailrocks.org/downloads/qlo ... i64n2tai.c
tail -n 14000 /var/log/qmail/qmail-send/current | tai64n2tai | egrep alert | cut -b-10,21- > ${TMP_FILE}
FOR_TEST=`cat ${TMP_FILE} | awk '{print $1}'`

for OUTL in ${FOR_TEST}
do
if [ ${OUTL} -ge ${CURTIMEM2} ]; then
echo ${OUTL} >>${TMP_FILE2}
fi
done

if [ -s ${TMP_FILE2} ]; then
# if [ ${COUNT} -le 10 -a ${COUNT} -gt 0 ]; then
COUNT=`cat ${TMP_FILE2} | wc -l`
if [ ${COUNT} -le 10 ]; then
printf "OK - ${COUNT} alert occurences\n"
exit 0
else
printf "WARNING - ${COUNT} alert occurences\n"
exit 1
fi
else
printf "OK - 0 alert occurences\n"
exit 0
fi
all this script is doing is tail -n of /var/log/qmail/qmail-send/current and using tai64n2tai, turning the hex stamp to epoch. from there we are checking for all "alerts" for lines where the epoch is less than 60 seconds from the point that this script is run.

messy but works
[ add comment ] ( 41 views ) [ 0 trackbacks ] permalink ( 3 / 7 )
why i hate life 

there is nothing worse in life than deleting someone from your life because of your own stupidities:
root@sol:~# userdel ssmith


:(
[ add comment ] ( 10 views ) [ 0 trackbacks ] permalink ( 0 / 0 )
9th Annual System Administrator Appreciation Day 

sysadmin day!!

If you can read this, thank your sysadmin....
[ add comment ] ( 19 views ) [ 0 trackbacks ] permalink ( 0 / 0 )
another scene from a favorite movie 

this one needs to be explained a little:

Jaime Miravilles (gauche) et Salvador Dali (droite) as the two confused priests
in "Un Chien Andalou (Andalusian Dog)" 1929
Un Film De Luis Bunuel Et Salvador Dali

[ add comment ] ( 10 views ) [ 0 trackbacks ] permalink ( 0 / 0 )
my love for the mystical and magical cURL 

begin snippet:
function port {
if [ $? -ne 0 ] ; then
printf "warning: "
if [ $? -eq 6 ]; then
echo "cant resolve host"
fi
if [ $? -eq 7 ]; then
echo "cant connect to host"
fi
printf "site may be down\n"
else
printf "site is up\n"
fi
}

curl -s ${1} | egrep 30[0-9] >/dev/null
port;
so for the one or two of you that actually read this site, you may recognize that snippet from a few posts ago.
but i have learned to love cURL and errorlevels when used in conjunction. that function above (a crude one at that) has already saved my ass because of the errorlevel output.

it sounds lame, i know. but you are reading this site so it must have peaked your interest regardless of the lame factor.

[ add comment ] ( 13 views ) [ 0 trackbacks ] permalink ( 0 / 0 )
sql dump adder 

this script looks in a specific directory for sql dumps labeled xxx_20080101_xxx_alumn.sql.gz, xxx_20080101_xxx_const.sql.gz & xxx_20080101_xxx_log.sql.gz to ungzip and dump back into sql (assuming the db is there already). change as needed.
#!/bin/bash
# this script assumes that you have the sql backups gzipped
FILE_DIR=/export/tmp/backup/temp

if [ $# -lt 2 ]; then
printf "\nneeds date of backup and switch: $0 <switch> xxxxyyzz\n"
printf "ex: $0 test 200x0101\n"
if [ $# -lt 1 ]; then
printf "list of switches:\n----------\n"
printf "alumn - gzip alumn backup then load to mysql\n"
printf "log - gzip logs backup then load to mysql\n"
printf "const - gzip const backup then load to mysql\n"
printf "all - gzip all backups then load to mysql\n\n"
fi
exit
fi

case $1 in

'const'|'log'|'alumn')
cd $FILE_DIR
SQL_FILES=`ls *$2*$1.sql.gz`
if [ $? -ne 0 ] ; then
printf "date format either wrong or non-existant\n"
exit
fi
#gzip -d *$2*$1.sql.gz
printf "\nLoading databases:\n"
for file in $SQL_FILES ; do
abbr=`echo $file | awk '{gsub(/\./," ");print $2}'`
printf "\n$abbr\n$file\n"
#mysql -uroot $abbr < $file
done
exit
;;

'all')
cd $FILE_DIR
gzip -d *$2*.sql.gz
SQL_FILES=`ls *$2*.sql`
if [ $? -ne 0 ] ; then
printf "date format either wrong or non-existant\n"
exit
fi
printf "\nLoading databases:\n"
for file in $SQL_FILES ; do
abbr=`echo $file | awk '{gsub(/\./," ");print $2}'`
printf "\n$abbr\n$file\n"
# printf "mysql $abbr < $file\n"
mysql -uroot $abbr < $file
done
exit
;;

esac


[ add comment ] ( 45 views ) [ 0 trackbacks ] permalink ( 2.3 / 3 )
boredom 

boredom led me to write a command that does the same thing but three different ways;

assume that the file that is being cat to use for this example contains:
line 1
line 2
<form id="form_login" name="form_login" method="post" action="session_id=XXXXXx.xxxxx.NAM1&locid=0&lf=0&i>
and i need NAM1 only. well, i actually need the three letter code and number. it remains in the same location in every file but changes depending on the file.
grep "form id" | awk '{print $5}' | cut -b35-200 | cut -d. -f2 | cut -d"&" -f1
awk '/form id/ {print $5}' | awk '{gsub(/\.|\&/," ");print $3}'
awk '/form id/ {print $5}' | cut -d. -f3 | cut -d"&" -f1
the first line probably makes zero sense since the first cut command is calling bytes 35-200 and with this example it does not quite fit, but trust me, it works with the actual file (had to change as requested)


i know that there are still a ton of different ways (some more effective and efficient) but these were just quick bursts and these are just snippets of the original commands (i was processing the output from another command).

i love boredom.....

p.s. - i know that it might not work properly, ill get around to posting a better example file to use.
[ add comment ] ( 36 views ) [ 0 trackbacks ] permalink ( 0 / 0 )
another stupid nagios process checker 

here is another in the long line of stupid scripts for nagios.

this script finds specific process, then counts them and spits out an error level according to setting

enjoy!!
#!/bin/bash

## replace "ORA_" with some other unique identifier
## from vi :1,$s/ORA_/"unique"/g
ORA_TEMP=/tmp/ora_procs.tmp
## replace "ora_" with what you need grep'ed
ps -ef | awk '/ora_/ && !/awk/ {print $8}' >${ORA_TEMP}
ORA_COUNT=`cat ${ORA_TEMP} | wc -l`

if [ ${ORA_COUNT} -gt 0 ]; then
## change ge & le to what is needed
if [ ${ORA_COUNT} -ge 6 ] && [ ${ORA_COUNT} -le 15 ]; then
printf "${ORA_COUNT} proc(s) counted\n"
echo exit 1
## change ge & le to what is needed
if [ ${ORA_COUNT} -ge 1 ] && [ ${ORA_COUNT} -le 5 ]; then
printf "${ORA_COUNT} proc(s) counted\n"
## exit 0 - ok for nagios
echo exit 2
fi
else
printf "${ORA_COUNT} proc(s) counted\n"
## exit 0 - ok for nagios
echo exit 0
fi
else
## replace the word "ORACLE" with whatever it is you are monitoring
printf "${ORA_COUNT} proc(s) counted\n - ORACLE is not running!!!"
## exit 2 - critical for nagios
echo exit 2
fi

[ add comment ] ( 31 views ) [ 0 trackbacks ] permalink ( 3 / 5 )

| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next> Last>>