|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
| 3 | +import json |
3 | 4 | import os |
4 | 5 | from datetime import datetime, timezone |
5 | 6 |
|
6 | 7 | REBOOT_CAUSE_DIR = "/host/reboot-cause/" |
7 | | -REBOOT_LC_BY_SUPERVISOR_FILE = os.path.join(REBOOT_CAUSE_DIR, "reboot-lc-by-supervisor.txt") |
| 8 | +REBOOT_CAUSE_PLATFORM_DIR = "/host/reboot-cause/platform" |
| 9 | +REBOOT_EXTRA_INFO_FILE = os.path.join(REBOOT_CAUSE_PLATFORM_DIR, "reboot-extra-info.json") |
8 | 10 |
|
9 | 11 | def main(): |
10 | | - reboot_time = datetime.now(timezone.utc).strftime("%a %b %d %I:%M:%S %p %Z %Y") |
11 | | - |
12 | | - if os.path.exists(REBOOT_LC_BY_SUPERVISOR_FILE): |
13 | | - os.remove(REBOOT_LC_BY_SUPERVISOR_FILE) |
14 | | - with open(os.path.join(REBOOT_CAUSE_DIR, "reboot-cause.txt"), 'w') as reboot_cause_file: |
15 | | - reboot_msg = "User issued 'Reboot from Supervisor' command [User: Supervisor, Time: {}]".format(reboot_time) |
16 | | - reboot_cause_file.write(reboot_msg) |
| 12 | + if os.path.exists(REBOOT_EXTRA_INFO_FILE): |
| 13 | + with open(REBOOT_EXTRA_INFO_FILE, 'r', encoding='utf-8') as f: |
| 14 | + data = json.load(f) |
| 15 | + os.remove(REBOOT_EXTRA_INFO_FILE) |
| 16 | + who = data.get('from', None) |
| 17 | + when = data.get('when', None) |
| 18 | + if who is not None: |
| 19 | + who = who.capitalize() |
| 20 | + with open(os.path.join(REBOOT_CAUSE_DIR, "reboot-cause.txt"), 'w') as reboot_cause_file: |
| 21 | + reboot_msg = f"User issued 'Reboot from {who}' command [User: {who}, Time: {when}]" |
| 22 | + reboot_cause_file.write(reboot_msg) |
17 | 23 |
|
18 | 24 | if __name__ == "__main__": |
19 | 25 | main() |
0 commit comments