bash - How can I setup monitoring of Docker Container from Nagios -


i trying set monitoring of docker container nagios.my nagios on 1 vm , docker on vm . monitor docker trying use the shell script below:

#!/bin/bash  # author: erik kristensen # email: erik@erikkristensen.com # license: mit # nagios usage: check_nrpe!check_docker_container!_container_id_ # usage: ./check_docker_container.sh _container_id_ # # script checks if container running. #   ok - running #   warning - container ghosted #   critical - container stopped #   unknown - not exist  container=$1  running=$(docker inspect --format="{{ .state.running }}" $container 2> /dev/null)  if [ $? -eq 1 ];   echo "unknown - $container not exist."   exit 3 fi  if [ "$running" == "false" ];   echo "critical - $container not running."   exit 2 fi  ghost=$(docker inspect --format="{{ .state.ghost }}" $container)  if [ "$ghost" == "true" ];   echo "warning - $container has been ghosted."   exit 1 fi  started=$(docker inspect --format="{{ .state.startedat }}" $container) network=$(docker inspect --format="{{ .networksettings.ipaddress }}" $container)  echo "ok - $container running. ip: $network, startedat: $started" 

and placed file on location /usr/lib64/nagios/plugins/ in when run script tends throw error.

error:

check_docker: line 40: syntax error: unexpected end of file

being java guy dont know of

so please tell how can achieve task of monitoring docker have wasted time on this

thanks in advance.

the problem unexpected eol char copy / paste.

this bash issue, or more specific... it's special character @ end can't see because copy/pasted website.

reason issue:

lots of sites mention eol issues, look here short , point.

dos uses carriage return , line feed ("\r\n") line ending, unix uses line feed ("\n"). need careful transferring files between windows machines , unix machines make sure line endings translated properly.

solution:

to fix line endings unix style eol, run dos2unix file.sh might need install utility first. in ubuntu sudo apt-get install dos2unix. depending upon environment, same you.

alternatives:

if you'd find out @ end, can @ notepad++ on windows understands eol chars of various formats. need enable chars in menu.

notepad++ eol setting

on linux, emacs whitespace mode show same thing:

toggle locally m-x whitespace-mode ret or see link (many) details , examples.


Comments