From c4e5bbe146eccf7d42194b29164870cf79286cd2 Mon Sep 17 00:00:00 2001 From: Pavan Gudiwada <25551553+pavangudiwada@users.noreply.github.com> Date: Tue, 6 Aug 2024 13:16:02 +0530 Subject: [PATCH 1/2] Adding HolmesGPT plugin --- plugins/README.md | 2 +- plugins/ai-incident-investigaton.yaml | 59 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 plugins/ai-incident-investigaton.yaml diff --git a/plugins/README.md b/plugins/README.md index 4afe2cf166..8d48715471 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -15,6 +15,6 @@ Following is an example of some of plugin files in this directory. Other files a | log_stern.yml | View resource logs using stern | pods | Ctrl-l | | | log_jq.yml | View resource logs using jq | pods | Ctrl-j | kubectl-plugins/kubectl-jq | | log_full.yml | get full logs from pod/container | pods/containers | Ctrl-l | | - +| ai-incident-investigation.yaml | Run AI investigation on application issues to find the root cause in seconds | all | Shift-h/o | [HolmesGPT](https://github.com/robusta-dev/holmesgpt) | [1]: https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/#ephemeral-container [2]: https://github.com/nicolaka/netshoot diff --git a/plugins/ai-incident-investigaton.yaml b/plugins/ai-incident-investigaton.yaml new file mode 100644 index 0000000000..dfba583063 --- /dev/null +++ b/plugins/ai-incident-investigaton.yaml @@ -0,0 +1,59 @@ +plugins: +# Author: Pavan Gudiwada +# Investigate incidents in your cluster to quickly find the root cause using HolmesGPT +# Requires HolmesGPT to be installed and configured (https://github.com/robusta-dev/holmesgpt) on your system +# Open any K9s view, then: +# Shift+H to run an investigation with default ask command +# Shift+O to customize the question before running an investigation. + holmesgpt: + shortCut: Shift-H + description: Ask HolmesGPT + scopes: + - all + command: bash + background: false + confirm: false + args: + - -c + - | + holmes ask "why is $NAME of $RESOURCE_NAME in -n $NAMESPACE not working as expected" + + echo "Press 'q' to exit" + while : ; do + read -n 1 k <&1 + if [[ $k = q ]] ; then + break + fi + done + custom-holmesgpt: + shortCut: Shift-Q + description: Custom HolmesGPT Ask + scopes: + - all + command: bash + background: false + confirm: false + args: + - -c + - | + INSTRUCTIONS="# Edit the line below. Lines starting with '#' will be ignored." + DEFAULT_ASK_COMMAND="why is $NAME of $RESOURCE_NAME in -n $NAMESPACE not working as expected" + + echo "$INSTRUCTIONS" > temp-ask.txt + echo "$DEFAULT_ASK_COMMAND" >> temp-ask.txt + + # Open the line in the default text editor + ${EDITOR:-nano} temp-ask.txt + + # Read the modified line, ignoring lines starting with '#' + user_input=$(grep -v '^#' temp-ask.txt) + + echo running: holmes ask "\"$user_input\"" + holmes ask "$user_input" + echo "Press 'q' to exit" + while : ; do + read -n 1 k <&1 + if [[ $k = q ]] ; then + break + fi + done \ No newline at end of file From 87012f7ea0eea9229e92ce2b94d3025d4fda9ffb Mon Sep 17 00:00:00 2001 From: Pavan Gudiwada <25551553+pavangudiwada@users.noreply.github.com> Date: Sat, 10 Aug 2024 06:45:44 +0530 Subject: [PATCH 2/2] Updated to use a temporary file --- plugins/ai-incident-investigaton.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/ai-incident-investigaton.yaml b/plugins/ai-incident-investigaton.yaml index dfba583063..eed0a1df30 100644 --- a/plugins/ai-incident-investigaton.yaml +++ b/plugins/ai-incident-investigaton.yaml @@ -39,14 +39,16 @@ plugins: INSTRUCTIONS="# Edit the line below. Lines starting with '#' will be ignored." DEFAULT_ASK_COMMAND="why is $NAME of $RESOURCE_NAME in -n $NAMESPACE not working as expected" - echo "$INSTRUCTIONS" > temp-ask.txt - echo "$DEFAULT_ASK_COMMAND" >> temp-ask.txt + QUESTION_FILE=$(mktemp) + + echo "$INSTRUCTIONS" > "$QUESTION_FILE" + echo "$DEFAULT_ASK_COMMAND" >> "$QUESTION_FILE" # Open the line in the default text editor - ${EDITOR:-nano} temp-ask.txt + ${EDITOR:-nano} "$QUESTION_FILE" # Read the modified line, ignoring lines starting with '#' - user_input=$(grep -v '^#' temp-ask.txt) + user_input=$(grep -v '^#' "$QUESTION_FILE") echo running: holmes ask "\"$user_input\"" holmes ask "$user_input"