mirror of
https://github.com/ghndrx/prowler.git
synced 2026-02-10 23:05:05 +00:00
Fix log metric filter check3x with multiple trails @bridgecrewio
Fix log metric filter check3x with multiple trails @bridgecrewio
This commit is contained in:
@@ -17,16 +17,19 @@ check3x(){
|
||||
# In order to make all these checks work properly logs and alarms have to
|
||||
# be based only on CloudTrail tail with CloudWatchLog configuration.
|
||||
DESCRIBE_TRAILS_CACHE=$($AWSCLI cloudtrail describe-trails $PROFILE_OPT --region "$REGION" --query 'trailList[?CloudWatchLogsLogGroupArn != `null`]')
|
||||
TRAIL_LIST=$(echo $DESCRIBE_TRAILS_CACHE | jq -r '. |@base64')
|
||||
TRAIL_LIST=$(echo $DESCRIBE_TRAILS_CACHE | jq -r -c '.[] |@base64') # this treats each array element as its own line
|
||||
CURRENT_ACCOUNT_ID=$($AWSCLI sts $PROFILE_OPT get-caller-identity --region "$REGION" --query Account --output text)
|
||||
CLOUDWATCH_LOGGROUP=$($AWSCLI cloudtrail describe-trails $PROFILE_OPT --region "$REGION" --query 'trailList[*].CloudWatchLogsLogGroupArn' --output text| tr '\011' '\012' | awk -F: '{print $7}')
|
||||
|
||||
if [[ $CLOUDWATCH_LOGGROUP != "" ]]; then
|
||||
for group_obj_enc in $TRAIL_LIST; do
|
||||
|
||||
group_obj_raw=$(echo $group_obj_enc | decode_report)
|
||||
CLOUDWATCH_LOGGROUP_NAME=$(echo $group_obj_raw | jq -r '.[] | .CloudWatchLogsLogGroupArn|split(":")[6]')
|
||||
CLOUDWATCH_LOGGROUP_REGION=$(echo $group_obj_raw | jq -r '.[] | .CloudWatchLogsLogGroupArn|split(":")[3]')
|
||||
CLOUDWATCH_LOGGROUP_ACCOUNT=$(echo $group_obj_raw | jq -r '.[] | .CloudWatchLogsLogGroupArn|split(":")[4]')
|
||||
|
||||
CLOUDWATCH_LOGGROUP_NAME=$(echo $group_obj_raw | jq -r '.CloudWatchLogsLogGroupArn|split(":")[6]')
|
||||
CLOUDWATCH_LOGGROUP_REGION=$(echo $group_obj_raw | jq -r '.CloudWatchLogsLogGroupArn|split(":")[3]')
|
||||
CLOUDWATCH_LOGGROUP_ACCOUNT=$(echo $group_obj_raw | jq -r '.CloudWatchLogsLogGroupArn|split(":")[4]')
|
||||
|
||||
if [ "$CLOUDWATCH_LOGGROUP_ACCOUNT" == "$CURRENT_ACCOUNT_ID" ];then
|
||||
# Filter control and whitespace from .metricFilters[*].filterPattern for easier matching later
|
||||
METRICFILTER_CACHE=$($AWSCLI logs describe-metric-filters --log-group-name "$CLOUDWATCH_LOGGROUP_NAME" $PROFILE_OPT --region "$CLOUDWATCH_LOGGROUP_REGION"|jq '.metricFilters|=map(.filterPattern|=gsub("[[:space:]]+"; " "))')
|
||||
@@ -69,7 +72,7 @@ check3x(){
|
||||
fi
|
||||
if [[ $CHECK_CROSS_ACCOUNT_WARN ]]; then
|
||||
for group in $CHECK_CROSS_ACCOUNT_WARN; do
|
||||
textInfo "CloudWatch group $group is not in this account"
|
||||
textInfo "CloudWatch group $group is not in this account"
|
||||
done
|
||||
fi
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user