Skip to content

Commit

Permalink
Wrote new zabbix-docker-info.py command to parse data properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpsedlak committed Dec 22, 2015
1 parent 9ee11a4 commit a7f67ef
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
13 changes: 11 additions & 2 deletions ZabbixDockerTemplate.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>2.0</version>
<date>2015-12-22T01:04:01Z</date>
<date>2015-12-22T22:18:09Z</date>
<groups>
<group>
<name>Templates</name>
Expand Down Expand Up @@ -5543,6 +5543,15 @@ last(&quot;docker.containers.running&quot;)</params>
<description/>
<type>0</type>
</trigger_prototype>
<trigger_prototype>
<expression>{Template App Docker:docker.container.inspect.boolean[{#ZD_ID},State.Running].last(0)}=0</expression>
<name>Docker Container {#ZD_NAME} ({#ZD_ID}) is not running</name>
<url/>
<status>0</status>
<priority>3</priority>
<description/>
<type>0</type>
</trigger_prototype>
<trigger_prototype>
<expression>{Template App Docker:docker.container.stats[{#ZD_ID},pmem].avg(300)}&gt;70</expression>
<name>Docker Container {#ZD_NAME} ({#ZD_ID}) memory exceeding 70% for over 5 minutes</name>
Expand Down Expand Up @@ -5571,7 +5580,7 @@ last(&quot;docker.containers.running&quot;)</params>
<type>0</type>
</trigger_prototype>
<trigger_prototype>
<expression>{Template App Docker:docker.container.inspect.boolean[{#ZD_ID},State.OOMKilled].last(0)}=1</expression>
<expression>{Template App Docker:docker.container.inspect.boolean[{#ZD_ID},State.OOMKilled].last(0)}=1 &amp; {Template App Docker:docker.container.inspect.boolean[{#ZD_ID},State.Running].last(0)}=0</expression>
<name>Docker Container {#ZD_NAME} ({#ZD_ID}) Out of memory (killed)</name>
<url/>
<status>0</status>
Expand Down
5 changes: 2 additions & 3 deletions userparameter_zabbixdocker.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
UserParameter=docker.version, docker -v

UserParameter=docker.running.centos, ps -ef | grep 'docker -d' | grep -v grep | wc -l

UserParameter=docker.running.ubuntu, ps -ef | grep 'docker daemon' | grep -v grep | wc -l

UserParameter=docker.containers.running, docker ps -q | wc -l

UserParameter=docker.discovery, /usr/local/bin/zabbix-docker-discover.py

UserParameter=docker.info[*], docker info | grep "$1" | cut -f2 -d: | cut -c2-
UserParameter=docker.info[*], /usr/local/bin/zabbix-docker-info.py "$1"

UserParameter=docker.info.boolean[*], docker info | grep "$1" | cut -f2 -d: | cut -c2- | grep -i true | wc -l
UserParameter=docker.info.boolean[*], /usr/local/bin/zabbix-docker-info.py "$1" | grep -i true | wc -l

UserParameter=docker.info.convert[*], docker info | grep "$1" | cut -f2 -d: | cut -c2- | /usr/local/bin/zabbix-docker-convert.py

Expand Down
56 changes: 56 additions & 0 deletions zabbix-docker-info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/python

import sys
import subprocess
import os
import time

errorString="***NOT FOUND***"

def local_run_command(cmd,file):
cmd = cmd + " | tee > " + file
if os.path.isfile(file) == False:
os.system(cmd)
else:
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(file)
ticks=int(time.time())
delta=ticks-mtime
if (delta > 60):
os.system(cmd)

strings = open(file,"r").readlines()
return strings

def findString(strings,term):
found=-1
ndx=0
maxNdx=len(strings)
while (found==-1) and (ndx<maxNdx):
if term in strings[ndx]:
found=ndx
else:
ndx+=1
retval=errorString
if found>=0:
retval=strings[found]
return retval

def getValue(string):
pos=string.index(":")
return string[pos+2:-1]


search_for=sys.argv[1]

cmd="docker info"
filename="/tmp/zabbix-docker-info.out"

strings = local_run_command(cmd,filename)

line=findString(strings,search_for)

if errorString in line:
print search_for, " ", errorString
else:
print getValue(line)

0 comments on commit a7f67ef

Please sign in to comment.