-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from rpsedlak/development-1.0.3
Development 1.0.3
- Loading branch information
Showing
5 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|