Skip to content

Commit fce9937

Browse files
authored
Merge pull request #234 from draios/scanning-endpoints
2 parents 541c7cb + ac052d4 commit fce9937

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

support_bundle/get_support_bundle.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,12 @@ main() {
166166
echo "The API_KEY supplied is Unauthorized. Please check and try again. Return Code: ${RETVAL}"
167167
exit 1
168168
fi
169+
169170
curl -ks -H "Authorization: Bearer ${API_KEY}" -H "Content-Type: application/json" "${API_URL}/api/admin/customer/1/fastPathSettings" >> ${LOG_DIR}/fastPath_settings.json
170171
curl -ks -H "Authorization: Bearer ${API_KEY}" -H "Content-Type: application/json" "${API_URL}/api/admin/customer/1/indexSettings" >> ${LOG_DIR}/index_settings.json
172+
else
173+
echo "We could not determine the backend version. Exiting."
174+
exit 1
171175
fi
172176

173177
curl -ks -H "Authorization: Bearer ${API_KEY}" -H "Content-Type: application/json" "${API_URL}/api/license" >> ${LOG_DIR}/license.json
@@ -182,6 +186,52 @@ main() {
182186
curl -ks -H "Authorization: Bearer ${API_KEY}" -H "Content-Type: application/json" "${API_URL}/api/admin/auth/settings" >> ${LOG_DIR}/sso_settings.json
183187
curl -ks -H "Authorization: Bearer ${API_KEY}" -H "Content-Type: application/json" "${API_URL}/api/alerts" >> ${LOG_DIR}/alerts.json
184188

189+
# If Secure API key is supplied, collect settings
190+
if [[ ! -z ${SECURE_API_KEY} ]]; then
191+
BACKEND_VERSION=$(kubectl ${CONTEXT_OPTS} ${KUBE_OPTS} get deployment sysdigcloud-api -ojsonpath='{.spec.template.spec.containers[0].image}' | awk 'match($0, /[0-9]\.[0-9]\.[0-9](\.[0-9]+)?/) {print substr($0, RSTART, RLENGTH)}') || true
192+
if [[ "$BACKEND_VERSION" =~ ^(6) ]]; then
193+
API_URL=$(kubectl ${KUBE_OPTS} get cm sysdigcloud-collector-config -ojsonpath='{.data.collector-config\.conf}' | awk 'p&&$0~/"/{gsub("\"","");print} /{/{p=0} /sso/{p=1}' | grep serverName | awk '{print $3}')
194+
# Check that the SECURE_API_KEY for the Super User is valid and exit
195+
CURL_OUT=$(curl -fks -H "Authorization: Bearer ${SECURE_API_KEY}" -H "Content-Type: application/json" "${API_URL}/api/license" >/dev/null 2>&1) && RETVAL=$? && error=0 || { RETVAL=$? && error=1; }
196+
if [[ ${error} -eq 1 ]]; then
197+
echo "The SECURE_API_KEY supplied is Unauthorized. Please check and try again. Return Code: ${RETVAL}"
198+
exit 1
199+
fi
200+
elif [[ "$BACKEND_VERSION" =~ ^(5) ]] || [[ "$BACKEND_VERSION" =~ ^(4) ]] || [[ "$BACKEND_VERSION" =~ ^(3) ]]; then
201+
API_URL=$(kubectl ${KUBE_OPTS} get cm sysdigcloud-config -o yaml | grep -i api.url: | head -1 | awk '{print $2}')
202+
# Check that the API_KEY for the Super User is valid and exit
203+
CURL_OUT=$(curl -fks -H "Authorization: Bearer ${API_KEY}" -H "Content-Type: application/json" "${API_URL}/api/license" >/dev/null 2>&1) && RETVAL=$? && error=0 || { RETVAL=$? && error=1; }
204+
if [[ ${error} -eq 1 ]]; then
205+
echo "The API_KEY supplied is Unauthorized. Please check and try again. Return Code: ${RETVAL}"
206+
exit 1
207+
fi
208+
else
209+
echo "We cannot determine the backend version. Exiting."
210+
exit 1
211+
fi
212+
213+
# Check if ScanningV1 is enabled, and if so, do ...
214+
SCANNING_V1_ENABLED=$(curl -ks ${API_URL}/api/secure/customerSettings -H "Authorization: Bearer ${SECURE_API_KEY}" 2>&1 | grep -Eo "\"scanningV1Enabled\":true") || true
215+
if [[ ${SCANNING_V1_ENABLED} == "\"scanningV1Enabled\":true" ]]; then
216+
echo "Scanning v1 is enabled. Continuing..."
217+
# CURL COMMANDS GO HERE
218+
mkdir -p ${LOG_DIR}/scanning
219+
curl -ks ${API_URL}/api/scanning/v1/resultsDirect?limit=1 -H "Authorization: Bearer ${SECURE_API_KEY}" >> ${LOG_DIR}/scanning/scanningv1.txt
220+
else
221+
echo "Scanning V1 not detected. Continuing..."
222+
fi
223+
224+
# Check if ScanningV2 is enabled, and if so, do ...
225+
SCANNING_V2_ENABLED=$(curl -ks ${API_URL}/api/secure/customerSettings -H "Authorization: Bearer ${SECURE_API_KEY}" 2>&1 | grep -Eo "\"scanningV2Enabled\":true") || true
226+
if [[ ${SCANNING_V2_ENABLED} == "\"scanningV2Enabled\":true" ]]; then
227+
echo "Scanning v2 is enabled. Continuing..."
228+
curl -ks ${API_URL}/api/scanning/scanresults/v2/results -H "Authorization: Bearer ${SECURE_API_KEY}" >> ${LOG_DIR}/scanning/scanningv2.txt
229+
# CURL COMMANDS GO HERE
230+
else
231+
echo "Scanning V2 not detected. Continuing..."
232+
fi
233+
fi
234+
185235
if [[ $OSTYPE == 'darwin'* ]]; then
186236
TO_EPOCH_TIME=$(date -jf "%H:%M:%S" $(date +%H):00:00 +%s)
187237
else

0 commit comments

Comments
 (0)