Monday, February 20, 2017

Nagios plugin for Docker Container Https monitoring

#!/bin/bash
CONTAINER=my_ubuntu
ENV=`hostname -d | cut -f2 -d.`
PORT=$(docker inspect --format '{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $CONTAINER  | awk -F '[>]' '{print $2}' )
HOST=$(hostname)

#you can specify env like qa,stage,prod

while [ $ENV = qa ];
 do
        if [ $PORT == 443 ] && [ `curl -LIk  https://${HOST} -o /dev/null -w '%{http_code}\n' -s` = 200 ];
     
        then
            echo "OK - $CONTAINER port 443 is up"
            exit 0
        else
            echo "CRITICAL - $CONTAINER port 443 is down"
            exit 2
        fi
 done

No comments:

Post a Comment