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

Monday, February 6, 2017

Docker container monitoring script for Nagios

#!/bin/bash

CONTAINER=ubuntu

RUNNING=$(docker inspect --format="{{ .State.Running }}" $CONTAINER 2> /dev/null)

if [ "$RUNNING" == "false" ]; then
  echo "CRITICAL - $CONTAINER is not running."
  exit 2
else
echo "OK - $CONTAINER is running."
exit  0

fi

Docker service failed to start

I  installed docker-engine on RHEL 7 and  when i tried to run docker service i got following error

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Solution:
#systemctl stop docker.service
#rm -rf /var/lib/docker
#systemctl start docker.service