3 from json
import loads, dumps
4 from types
import GeneratorType
10 "Convert given timestamp into human readable format"
11 if isinstance(val, int)
or isinstance(val, float):
12 return time.strftime(
'%d/%b/%Y_%H:%M:%S_GMT', time.gmtime(val))
17 Format file size utility, it converts file size into KB, MB, GB, TB, PB units
23 except Exception
as _exc:
27 xlist = [
'',
'KiB',
'MiB',
'GiB',
'TiB',
'PiB']
30 xlist = [
'',
'KB',
'MB',
'GB',
'TB',
'PB']
33 return "%3.1f%s" % (num, xxx)
37 """Generator which extracts row[key] value"""
38 if isinstance(row, dict)
and key
in row:
39 if key ==
'creation_time':
46 if isinstance(row, list)
or isinstance(row, GeneratorType):
52 """Filter data from a row for given list of filters"""
54 if ftr.find(
'>') != -1
or ftr.find(
'<') != -1
or ftr.find(
'=') != -1:
62 values += [dumps(i)
for i
in val]
70 def get_data(query, limit=None, threshold=None, idx=None, host=None, cmd=None):
71 cmd_opts =
"--format=json"
72 if threshold
is not None: cmd_opts +=
" --threshold=%s" % threshold
73 if limit
is not None: cmd_opts +=
" --limit=%s" % limit
74 if idx
is not None: cmd_opts +=
" --idx=%s" % idx
75 if host
is not None: cmd_opts +=
" --host=%s" % host
78 for path
in os.getenv(
'PATH').
split(
':'):
79 if os.path.isfile(os.path.join(path,
'dasgoclient')):
83 p = subprocess.Popen(
"%s %s --query '%s'" % (cmd, cmd_opts, query),shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
84 stdout, stderr = p.communicate()
85 if not p.returncode:
return loads(stdout)
86 return {
'status' :
'error',
'reason' : stdout}