This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurisequencestrategy.py
57 lines (42 loc) · 1.83 KB
/
urisequencestrategy.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
55
56
57
from searchstrategy import SearchStrategy
class UriSequenceStrategy(SearchStrategy):
def __init__(self, strategy, campaign, elasticSearch):
SearchStrategy.__init__(self, strategy, campaign, elasticSearch)
def execute(self):
print("Executing UriSequenceStrategy")
query = self.createQuery(self.strategy["sequence"]["entry"]["uri"], "now-10m")
result = self.search(query)
print("Found {} {}".format(len(result["hits"]["hits"]), self.strategy["sequence"]["entry"]["uri"]))
for hit in result["hits"]["hits"]:
gte = hit["_source"]["@timestamp"]
lte = "{}||+{}".format(hit["_source"]["@timestamp"], self.strategy["sequence"]["next"]["timeSpan"])
query = self.createQuery(self.strategy["sequence"]["next"]["uri"], gte, lte)
result = result = self.search(query)
print("Found {} {}".format(len(result["hits"]["hits"]), self.strategy["sequence"]["next"]["uri"]))
if result["hits"]["hits"]:
self.handleResult(result)
def getTemplateQuery(self):
return {
"query": {
"bool": {
"must": {
"term": {
}
},
"filter": {
"range": {
"@timestamp": {
}
}
}
}
}
}
def createQuery(self, uri, gte, lte=None):
query = self.getTemplateQuery()
query["query"]["bool"]["must"]["term"]["uri"] = uri
if gte:
query["query"]["bool"]["filter"]["range"]["@timestamp"]["gte"] = gte
if lte:
query["query"]["bool"]["filter"]["range"]["@timestamp"]["lte"] = lte
return query