-
Notifications
You must be signed in to change notification settings - Fork 27
/
zabbix-docker-info.py
executable file
·55 lines (42 loc) · 1.08 KB
/
zabbix-docker-info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python
import sys
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)