aboutsummaryrefslogtreecommitdiff
path: root/modules/pkgs/check_aws_rds/check_aws_rds
blob: d4fd9650fb6da9115c6d7c2d3365821e21f01e86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash

set -euo pipefail

cmd=( pmp-check-aws-rds )

getId () {
  local endpoint="$1"
  local c=0
  while [[ "$endpoint" != *.*.*.rds.amazonaws.com* ]]; do
    endpoint=$(dig "$endpoint" CNAME +short)
    (( ++c ))
    if (( c > 10 )); then
      echo "failed to resolve '$1'" >&2
      exit 255
    fi
  done

  cmd+=( -r $(echo "$endpoint" | cut -d. -f3) )
  cmd+=( -i $(echo "$endpoint" | cut -d. -f1) )
}

while [ $# -gt 0 ]; do
  case "$1" in
    -m|-w|-c) cmd+=( $1 $2 ); shift 2;;
    -f) export BOTO_CONFIG="$2"; shift 2;;
    -h) getId "$2"; shift 2;;
    *) echo "$0: unsupported argument: $1" >&2; exit 1;;
  esac
done
exec "${cmd[@]}"