Skip to content

Conversation

@acdha
Copy link

@acdha acdha commented Sep 8, 2025

This avoids crashing on the GuardDuty sidecars which do not have the managed agents.

Closes #67

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

This avoids crashing on the GuardDuty sidecars which do not have the managed agents.

Closes aws-containers#67
@bassmanitram
Copy link

bassmanitram commented Oct 30, 2025

That doesn't QUITE do it, because then the indices of the tasks get off and you end up with misleading info later on

THIS is my block for the same issue:

# 6. Check the managed agents' status
printf "${COLOR_DEFAULT}  Container-Level Checks | \n"
printf "${COLOR_DEFAULT}    ----------\n"
printf "${COLOR_DEFAULT}      Managed Agent Status"
if [[ "${executeCommandEnabled}" = "false" ]]; then
  printf " - ${COLOR_YELLOW}SKIPPED\n"
  printf "${COLOR_DEFAULT}    ----------\n"
else
  printf "\n"
  printf "${COLOR_DEFAULT}    ----------\n"
  agentsStatus=$(echo "${describedTaskJson}" | jq -r '.tasks[0].containers[] |
  if has("managedAgents") and (.managedAgents | length) > 0 then
    .managedAgents[] .status
  else
    "ABSENT"
  end
  ')
  idx=0
  for S in $agentsStatus; do
    containerName=$(echo "${describedTaskJson}" | jq -r ".tasks[0].containers[${idx}].name")
	if [[ "$S" != ABSENT ]]; then
        status=$(echo "${describedTaskJson}" | jq -r ".tasks[0].containers[${idx}].managedAgents[0].lastStatus")
        reason=$(echo "${describedTaskJson}" | jq -r ".tasks[0].containers[${idx}].managedAgents[0].reason")
        lastStartedAt=$(echo "${describedTaskJson}" | jq -r ".tasks[0].containers[${idx}].managedAgents[0].lastStartedAt")
	else
		status="ABSENT"
	fi
    printf "         $((idx+1)). "
    case "${status}" in
      *STOPPED* ) printf "${COLOR_RED}STOPPED (Reason: ${reason})";;
      *ABSENT* ) printf "${COLOR_YELLOW}NOT PRESENT";;
      *PENDING* ) printf "${COLOR_YELLOW}PENDING";;
      * ) printf "${COLOR_GREEN}RUNNING";;
    esac
    printf "${COLOR_DEFAULT} for \"${containerName}\""
    if [[ "${status}" = "STOPPED" ]]; then
      printf " - LastStartedAt: ${lastStartedAt}"
    fi
    printf "\n"
    idx=$((idx+1))
  done
fi

# 7. Check the "initProcessEnabled" flag added in the task definition (yellow)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jq: error (at <stdin>:173): Cannot iterate over null (null)

2 participants