- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathelastalert_lambda.py
More file actions
Latest commit
69 lines (55 loc) · 1.67 KB
/
Copy pathelastalert_lambda.py
File metadata and controls
69 lines (55 loc) · 1.67 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
importos
importsys
importdatetime
importshlex
fromelastalertimportelastalert
fromelastalertimportcreate_index
classTmpSysArgv(object):
def__enter__(self):
self.orig_argv=sys.argv
def__exit__(self, *args, **kwargs):
sys.argv=self.orig_argv
defhandler(event, context):
print("Starting up ElastAlert")
args=shlex.split(event.get('ARGS', os.getenv('ARGS', '')))
if'--end'notinargs:
args.extend([
'--end',
datetime.datetime.utcnow().isoformat(),
])
if'--config'notinargs:
args.extend(['--config', 'config.yaml'])
print("Using arguments: `%s`"%args)
if"EA_CREATE_INDEX"inos.environ:
if"EA_CREATE_INDEX_ARGS"inos.environ:
ci_args= ["elastalert-create-index"] +shlex.split(
os.getenv("EA_CREATE_INDEX_ARGS"))
else:
config_index=args.index("--config")
ci_args= [
"elastalert-create-index",
args[config_index],
args[config_index+1]
]
print("Creating index for elastalert with args: %s"% (ci_args, ))
withTmpSysArgv():
sys.argv=ci_args
create_index.main()
try:
elastalert.main(args)
exceptSystemExitasexc:
ifexc.args[0] ==0:
print("ElastAlert run successfully!")
return
raise
if__name__=="__main__":
"""
Purely for local testing
"""
importjson
importsys
importselect
event= {}
ifselect.select([sys.stdin,], [], [], 0.0)[0]:
event=json.loads(sys.stdin.read())
handler(event, None)