1 (edited by kaipanoi 2014-12-24 06:42:18)

Topic: [contribution] A check_mk local-check-script for iRedmail

Returns OK if all 14 indicated ports are listening according to a locally ran netstat, otherwise critical. (Assumes mysql version, adjust as needed.) Tested on CentOS 6.


#!/bin/sh
#PUPPET MANAGED FILE
#/usr/lib/check_mk_agent/local/mailportchecker.sh
PORTS="25 443 80 993 995 3306 10024 10025 587 9998 110 143"
TOTALCOUNT=`netstat -aunt|grep LISTEN|grep -E '25|80|443|993|995|3306|10024|10025|587|9998|110|143' -c`

if [ $TOTALCOUNT -ne 14 ] ; then
        status=2
        statustxt=CRITICAL
else
        status=0
        statustxt=OK
fi

for thisport in $PORTS; do
        netstat -aunt|grep LISTEN | grep $thisport > /dev/null 2>&1
        if [ $? -eq 0 ] ; then
                listeners="$listeners $thisport"
        fi
done

echo "$status iRedmail_ports iRedmail_ports=$TOTALCOUNT;13;12;14;14 $listeners"

Post's attachments

iredmailcheckmk.png 44.49 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: [contribution] A check_mk local-check-script for iRedmail

Good idea.
Could you help write a script to check mail services with proper sasl authentication? e.g. POP3/IMAP/SMTP.

3

Re: [contribution] A check_mk local-check-script for iRedmail

Good idea. I'll try.

4

Re: [contribution] A check_mk local-check-script for iRedmail

Feel free to contact me if you need help.

5

Re: [contribution] A check_mk local-check-script for iRedmail

I made a slight improvement to the original so it outputs the missing ports. I'll work on the auth checks next:

#!/bin/sh
#PUPPET MANAGED FILE
PORTS="25 443 80 993 995 3306 10024 10025 587 9998 110 143"
TOTALCOUNT=`netstat -aunt|grep LISTEN|grep -E '25|80|443|993|995|3306|10024|10025|587|9998|110|143' -c`

if [ $TOTALCOUNT -ne 14 ] ; then
        status=2
        statustxt=CRITICAL
else
        status=0
        statustxt=OK
fi

for thisport in $PORTS; do
        netstat -aunt|grep LISTEN | grep $thisport > /dev/null 2>&1
        if [ $? -eq 0 ] ; then
                listeners="$listeners $thisport"
        else
                missingports="$missingports $thisport"
        fi
done

if [ $status -eq 2 ] ; then
        textmessage="MISSING PORTS:$missingports"
else
        textmessage="LISTENERS:$listeners"
fi

echo "$status iRedmail_ports iRedmail_ports=$TOTALCOUNT;13;12;14;14 $textmessage"

6

Re: [contribution] A check_mk local-check-script for iRedmail

Personally, i think Python is a better choice in this case, it will be easier to handle SQL connection or user authentication.
Shell script is not good at this.

7

Re: [contribution] A check_mk local-check-script for iRedmail

I'm sure you're right. It was easiest for me to simply re-parse the output of the already made nagios check_smtp plugin:

#!/bin/sh
#requires package nagios-plugins-smtp
PLUGINLOCATION=/usr/lib64/nagios/plugins/
USERNAME="CHANGEME.EMAILADDRESS@DOMAIN.COM"
PASSWORD="CHANGEME_THAT_ACCOUNTS_PASSWORD"
RUNCHECK=$( $PLUGINLOCATION/check_smtp -H localhost -A LOGIN -U $USERNAME -P $PASSWORD -S | tail -n1| awk -F 'SMTP ' '{print $2}' )
statustxt=$( echo $RUNCHECK|awk '{print $1}' )
metrics=$( echo $RUNCHECK|awk -F '|' '{print$2}'|sed s/time=//g )
textmessage=$( echo $RUNCHECK|awk -F '- ' '{print $2}' |awk -F '|' '{print $1}'  )

if [ "$statustxt" == "CRITICAL" ] ; then
        status=2
elif [ "$statustxt" == "OK" ] ; then
        status=0
else
        status=1
fi

echo "$status smtp smtp=$metrics $textmessage"

Example output

Good:
0 smtp smtp=0.162907s;;;0.000000 0.163 sec. response time

Bad creds:
2 smtp smtp=1.513475s;;;0.000000 invalid response received after authpass, 1.513 sec. response time

SMTP unreachable
2 smtp smtp=0.000254s;;;0.000000 0.000 sec. response time

checkmk