forked from openshift/origin-aggregated-logging
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-viaq-data-model.py
More file actions
118 lines (111 loc) · 3.41 KB
/
Copy pathtest-viaq-data-model.py
File metadata and controls
118 lines (111 loc) · 3.41 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import sys
import json
test = sys.argv[1]
check_for_empty = True
if len(sys.argv) > 1:
check_for_empty = False
def empty(thing):
if isinstance(thing,str) and not thing:
return True
if isinstance(thing,unicode) and not thing:
return True
items = []
if isinstance(thing,list):
if not thing:
return True
items = thing
if isinstance(thing,dict):
if not thing:
return True
items = thing.values()
for ii in items:
if empty(ii):
return True
return False
obj = json.loads(sys.stdin.read())
if check_for_empty and empty(obj):
print "Error: input has one or more empty fields"
sys.exit(1)
test2match = {
"test1": {"undefined1": "undefined1",
"undefined11": 1111,
"undefined12": True,
"undefined2": {
"undefined2": "undefined2",
"undefined22": 2222,
"undefined23": False
},
"undefined4": "undefined4",
"undefined5": "undefined5"
},
"test2": {"undefined":
{"undefined1": "undefined1",
"undefined11": 1111,
"undefined12": True,
"undefined2": {
"undefined2": "undefined2",
"undefined22": 2222,
"undefined23": False
},
"undefined4": "undefined4",
"undefined5": "undefined5"
}
},
"test3": {"undefined":
{"undefined1": "undefined1",
"undefined11": 1111,
"undefined12": True,
"undefined2": {
"undefined2": "undefined2",
"undefined22": 2222,
"undefined23": False
}
},
"undefined4": "undefined4",
"undefined5": "undefined5"
},
"test4": {"myname":
{"undefined1": "undefined1",
"undefined11": 1111,
"undefined12": True,
"undefined2": {
"undefined2": "undefined2",
"undefined22": 2222,
"undefined23": False
}
},
"undefined4": "undefined4",
"undefined5": "undefined5"
},
"test5": {"myname":
{"undefined1": "undefined1",
"undefined11": 1111,
"undefined12": True,
"undefined2": {
"undefined2": "undefined2",
"undefined22": 2222,
"undefined23": False
}
},
"undefined4": "undefined4",
"undefined5": "undefined5",
"empty1": "",
"undefined3": {"emptyvalue": ""}
}
}
for dd in obj['hits']['hits']:
if dd['_score'] < 1.0:
print "ignoring spurious hit"
continue
if not '@timestamp' in dd['_source']:
print "Error: missing @timestamp field"
sys.exit(1)
match = test2match[test]
for xx in match:
if xx not in dd['_source']:
print "Error: input does not have the field [%s]" % xx
sys.exit(1)
if not match[xx] == dd['_source'][xx]:
print "Error: input field [%s] expected value [%s] does not match actual value [%s]" % (xx, match[xx], dd['_source'][xx])
sys.exit(1)
sys.exit(0)