Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,10 @@ Gather logs using the following command:
./collect-logs.sh
```

The following environment variables are supported for log collection:
The following environment parameters are supported for log collection:

| Environment variable | Description | Default |
| ------------------------- |:----------------------------------------|:-----------------------------------------------------------------------------------------------|
| RELEASE | Helm release name | `trendmicro` |
| NAMESPACE | The namespace that the helm chart is deployed in | Current namespace declared in `kubeconfig`. If no namespace setting exists in `kubeconfig`, then `trendmicro-system` will be used. |
| Parameters | Description | Default |
|------------|:-------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------------------------|
| -release | Helm release name | `trendmicro` |
| -namespace | The namespace that the helm chart is deployed in | Current namespace declared in `kubeconfig`. If no namespace setting exists in `kubeconfig`, then `trendmicro-system` will be used. |
| -context | The Kluster context that the helm chart is deployed in | Current cluster declared in `kubeconfig`. |
60 changes: 59 additions & 1 deletion collect-logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,30 @@
# a helper script to fetch Kubernetes settings and Trend Micro Cloud One container security logs.
#

RELEASE=${RELEASE:-trendmicro}
RELEASE="trendmicro"
KUBECTL=kubectl
HELM=helm
CONTEXT=""

help()
{
cat << EOF
Helper script to fetch Kubernetes setting and DTrend Micro Cloud One container security logs.
Options:
-release [Optional] Specifies the Trend Micro Cloud One container security release name. The default is trendmicro
-namespace [Optional] Specifies the the namespace of Trend Micro Cloud One container security deployment.
The default is the current namespace or default.
-corefilepattern [Optional] Specifies the core dump file name prefix pattern. The default value is 'core'.
-resultdir [Optional] Specifies the directory to save the logs.
Usage examples:
# Display this help
./collect-logs.sh -h | H
# Collect logs for the default release, namespace and context
./collect-logs.sh
# Collect logs for the named release, namespace and context
./collect-logs.sh -release deepsecurity-smartcheck -namespace trendmicro -context kubernetes-cluster
EOF
}

#####
# check prerequisites
Expand All @@ -24,11 +45,48 @@ if ! command_exists $HELM; then
exit 1
fi

while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|-H)
help
exit 0
;;
-release)
RELEASE=$2
shift
shift
;;
-namespace)
NAMESPACE=$2
shift
shift
;;
-context)
CONTEXT=$2
shift
shift
;;
*)
echo "Unrecognized options are specified: $1"
echo "Use option -h for help."
exit 1
;;
esac
done

CURRENT_NS=$(kubectl config view --minify --output 'jsonpath={..namespace}')
CURRENT_NS=${CURRENT_NS:-trendmicro-system}
NAMESPACE=${NAMESPACE:-$CURRENT_NS}
NAMESPACE_PARAM="--namespace=$NAMESPACE"

CURRENT_CONTEXT=$(kubectl config view --minify --output 'jsonpath={.current-context}')
CONTEXT=${CONTEXT:-$CURRENT_CONTEXT}
CONTEXT_PARAM="--context=$CONTEXT"

KUBECTL="$KUBECTL $CONTEXT_PARAM"

PODS=$($KUBECTL get pods "$NAMESPACE_PARAM" -o=jsonpath='{range .items[*]}{.metadata.name}{";"}{end}' -l app.kubernetes.io/instance=$RELEASE)
if [ -z "${PODS}" ]; then
echo "No container security pods are found in release '$RELEASE' in namespace '$NAMESPACE'. You can use RELEASE and NAMESPACE environment variable to change its default settings."
Expand Down