#!/bin/bash

# 使用 AWS CLI profile 名称
profile="dbaas"
# 获取所有有效的 AWS 区域
regions=$(aws ec2 describe-regions --query 'Regions[*].RegionName' --output text --profile $profile)
echo "Checking GuardDuty status in all regions:"
# 检查每个区域的 GuardDuty 状态
for region in $regions; do
  echo -n "Region $region: "
  
  # 检查 GuardDuty 的检测器状态
  detector_id=$(aws guardduty list-detectors --region $region --profile $profile --query 'DetectorIds[0]' --output text 2>/dev/null)
  
  if [ "$detector_id" == "None" ]; then
    echo "GuardDuty is not enabled"
  else
    echo "GuardDuty is enabled with Detector ID: $detector_id"
  fi
done
