sh Nagios的Bash脚本检查Docker容器的状态
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Nagios的Bash脚本检查Docker容器的状态相关的知识,希望对你有一定的参考价值。
#!/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_
#
# The script checks if a container is running.
# OK - running
# WARNING - container is ghosted
# CRITICAL - container is stopped
# UNKNOWN - does not exist
CONTAINER=$1
RUNNING=$(docker inspect --format="{{ .State.Running }}" $CONTAINER 2> /dev/null)
if [ $? -eq 1 ]; then
echo "UNKNOWN - $CONTAINER does not exist."
exit 3
fi
if [ "$RUNNING" == "false" ]; then
echo "CRITICAL - $CONTAINER is not running."
exit 2
fi
GHOST=$(docker inspect --format="{{ .State.Ghost }}" $CONTAINER)
if [ "$GHOST" == "true" ]; then
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 is running. IP: $NETWORK, StartedAt: $STARTED"
以上是关于sh Nagios的Bash脚本检查Docker容器的状态的主要内容,如果未能解决你的问题,请参考以下文章
sh 用于将所有docker镜像备份到文件的bash脚本
nagios自定义监控硬盘脚本
nagios监控脚本(自定义监控系统磁盘)
用于Nagios中监控elasticsearch健康状态脚本
sh 主机操作系统满足检查bash脚本的要求
docker第三次任务bash脚本,chomd权限