Skip to content

Commit

Permalink
differentiate btwn normal and non-normal shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-ass committed Nov 1, 2023
1 parent ba6fc16 commit f314e20
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,31 @@ module.exports = {

container_die: e => {
const exitCode = e.Actor.Attributes.exitCode;
const exitCodeMap = {
"0": "Success: Container exited with code 0",
"1": "General error: Container exited with code 1",
"2": "Misuse of shell builtins: Container exited with code 2",
"126": "Command invoked cannot execute: Container exited with code 126",
"127": "Command not found: Container exited with code 127",
"128": "Invalid argument to exit: Container exited with code 128",
"130": "Container terminated by user: Container exited with code 130",
"137": "Container received a SIGKILL: Container exited with code 137",
"139": "Segmentation fault: Container exited with code 139",
"143": "Container received a SIGTERM: Container exited with code 143",
// Add more exit codes as needed
const normalMap = {
"0": "Successful shutdown: Exit code 0",
"143": "Graceful termination (SIGTERM): Exit code 143",
// Add more normal exit codes as needed
};
const nonNormalMap = {
"1": "Application error: Exit code 1",
"2": "Misuse of shell builtins: Exit code 2",
"126": "Command invoked cannot execute: Exit code 126",
"127": "File or directory not found: Exit code 127",
"128": "Invalid argument used on exit: Exit code 128",
"130": "Container terminated by user: Exit code 130",
"134": "Abnormal termination (SIGABRT): Exit code 134",
"137": "Immediate termination (SIGKILL): Exit code 137",
"139": "Segmentation fault: Exit code 139",
"255": "Unknown error. Exit code 255",
// Add more non-normal exit codes as needed
}

if (exitCode in exitCodeMap) {
return `&#128308; <b>${e.Actor.Attributes.name}</b> stopped!\n${e.Actor.Attributes.image}\n${exitCodeMap[exitCode]}`;
if (exitCode in normalMap) {
return `&#9209; <b>${e.Actor.Attributes.name}</b> stopped!\n${e.Actor.Attributes.image}\n${normalMap[exitCode]}`;
} else if (exitCode in nonNormalMap) {
return `&#128308; <b>${e.Actor.Attributes.name}</b> stopped!\n${e.Actor.Attributes.image}\n${nonNormalMap[exitCode]}`;
} else {
return `&#128308; <b>${e.Actor.Attributes.name}</b> stopped with an unknown exit code (${exitCode})!\n${e.Actor.Attributes.image}`;
return `&#128308; <b>${e.Actor.Attributes.name}</b> stopped with exit code (${exitCode})!\n${e.Actor.Attributes.image}`;
}
},

Expand Down

0 comments on commit f314e20

Please sign in to comment.