]>
Commit | Line | Data |
---|---|---|
ac1087fa MW |
1 | #!/usr/bin/env python |
2 | ||
3 | """ | |
4 | exa-receive.py: Save received routes form ExaBGP into file | |
5 | """ | |
6 | ||
787e7624 | 7 | from sys import stdin, argv |
ac1087fa MW |
8 | from datetime import datetime |
9 | ||
10 | # 1st arg is peer number | |
11 | peer = int(argv[1]) | |
12 | ||
13 | # When the parent dies we are seeing continual newlines, so we only access so many before stopping | |
14 | counter = 0 | |
15 | ||
787e7624 | 16 | routesavefile = open("/tmp/peer%s-received.log" % peer, "w") |
ac1087fa MW |
17 | |
18 | while True: | |
19 | try: | |
20 | line = stdin.readline() | |
787e7624 | 21 | timestamp = datetime.now().strftime("%Y%m%d_%H:%M:%S - ") |
ac1087fa MW |
22 | routesavefile.write(timestamp + line) |
23 | routesavefile.flush() | |
24 | ||
25 | if line == "": | |
26 | counter += 1 | |
27 | if counter > 100: | |
28 | break | |
29 | continue | |
30 | ||
31 | counter = 0 | |
32 | except KeyboardInterrupt: | |
33 | pass | |
34 | except IOError: | |
35 | # most likely a signal during readline | |
36 | pass | |
37 | ||
38 | routesavefile.close() |