-
Notifications
You must be signed in to change notification settings - Fork 0
/
awslogviewer
executable file
·91 lines (71 loc) · 1.88 KB
/
awslogviewer
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
#!/usr/bin/env python3
import subprocess as s
import json
import datetime
from sys import argv,exit
nlg, nls = None, None
if len(argv) >= 3:
_, nlg, nls = argv[:3]
nlg = int(nlg)
nls = int(nls)
def execute(cmd):
x = s.check_output(cmd.split(" "))
x = x.decode("utf-8")
x = json.loads(x)
return x
def etime(x):
if x.get("timestamp") and type(x.get("timestamp")) == int:
ts = x.get("timestamp")/1000
s = str(datetime.datetime.fromtimestamp(ts))
print("time : ",s)
def print_evts(e):
if e:
for i in e:
print("=== event ===")
etime(i)
for j in i:
print(j,":",i[j])
def load_next(nt):
cmd = f"aws logs get-log-events --log-group-name {log_group_name} --log-stream-name {log_stream_name} --start-from-head --next-token {nt}"
x = execute(cmd)
e = x.get("events")
print_evts(e)
nft = x.get("nextForwardToken")
return nft
cmd = "aws logs describe-log-groups"
x = execute(cmd).get("logGroups")
print("=======")
print("groups:")
for n,i in enumerate(x):
print(n+1,"->",i.get("logGroupName"))
print("=======")
if nlg:
p = nlg - 1
else:
p = int(input("enter number of log group: ")) - 1
log_group_name = x[p].get("logGroupName")
cmd = f"aws logs describe-log-streams --log-group-name {log_group_name}"
x = execute(cmd).get("logStreams")
print("=======")
print("streams:")
print("=======")
for n,i in enumerate(x):
print(n+1,"->", i.get("logStreamName"), "# created at: ", str(datetime.datetime.fromtimestamp(i.get("creationTime")/1000)) )
print("=======")
if nls:
p = nls - 1
else:
p = int(input("enter number of log stream: ")) - 1
log_stream_name = x[p].get("logStreamName")
print("=======")
cmd = f"aws logs get-log-events --log-group-name {log_group_name} --log-stream-name {log_stream_name} --start-from-head"
x = execute(cmd)
print_evts(x.get("events"))
sft = x.get("nextForwardToken")
ft = sft
while True:
nft = load_next(ft)
if nft == ft:
break
else:
ft = nft