From 02617bfc8e8596176bc47d89659760d6669e9aa7 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Tue, 14 Jun 2022 07:51:37 +0200 Subject: [PATCH] added search for cname; debug comments to stderr --- dns-api.sh | 3 ++- dns-search.sh | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/dns-api.sh b/dns-api.sh index 7f9b395..7f6f210 100755 --- a/dns-api.sh +++ b/dns-api.sh @@ -16,6 +16,7 @@ # 2021-01-20 v0.0 <axel.hahn@iml.unibe.ch> # 2022-01-14 v1.0 <axel.hahn@iml.unibe.ch> 1st public version # 2022-03-03 v1.1 <axel.hahn@iml.unibe.ch> colored output if jq is found +# 2022-06-14 v1.2 <axel.hahn@iml.unibe.ch> debug comments are written to stderr # ====================================================================== @@ -40,7 +41,7 @@ fi relUrl="$1" # ----- make curl request -echo "; === DNS API :: $method ${relUrl}" +>&2 echo "; === DNS API :: $method ${relUrl}" curl -u $myauth -X $method "${mybaseurl}${relUrl}" 2>/dev/null \ | ( if which jq >/dev/null 2>&1; then jq; else cat; echo ; fi ) diff --git a/dns-search.sh b/dns-search.sh index 5e3a17f..cf445d9 100755 --- a/dns-search.sh +++ b/dns-search.sh @@ -8,6 +8,7 @@ # 2022-01-14 v1.0 <axel.hahn@iml.unibe.ch> 1st public version # 2022-03-01 v1.1 <axel.hahn@iml.unibe.ch> fix usage with 1st param "name" # 2022-03-03 v1.2 <axel.hahn@iml.unibe.ch> no param: 2 searches in name and alias +# 2022-06-14 v1.3 <axel.hahn@iml.unibe.ch> added search for cname objects; debug comments are written to stderr # ====================================================================== @@ -20,7 +21,7 @@ cat <<EOH Search for hostnames or aliases in Infoblox API It uses dns-api.sh and adds the return field for aliases. -SYNTAX: dns-search.sh [name|alias] REGEX +SYNTAX: dns-search.sh [name|alias|cname] REGEX EXAMPLES: @@ -38,8 +39,8 @@ The search supports regex: dns-search.sh name "^(connector|examinator).*measured.stage" (4) -Lazy mode: do not add name or alias to start 2 requests to search in name and -alias fields +Lazy mode: do not add name or alias or cname to start 3 requests to search +in all object types dns-search.sh ufive EOH @@ -50,7 +51,7 @@ fi # MAIN # ---------------------------------------------------------------------- mytype= -if echo "$1" | grep -E '^(name|alias)$' >/dev/null +if echo "$1" | grep -E '^(name|alias|cname)$' >/dev/null then mytype=$1 shift 1 @@ -61,15 +62,16 @@ mysearch=$1 # ---------------------------------------------------------------------- -echo "; === DNS SEARCH" -echo "; search for type : $mytype" -echo "; search regex : $mysearch" -echo ";" +>&2 echo "; === DNS SEARCH" +>&2 echo "; search for type : $mytype" +>&2 echo "; search regex : $mysearch" +>&2 echo ";" if [ -n "$mytype" ]; then "$( dirname $0 )"/dns-api.sh GET "/record:host?${mytype}~=${mysearch}&_return_fields%2B=aliases" else "$( dirname $0 )"/dns-api.sh GET "/record:host?name~=${mysearch}&_return_fields%2B=aliases" "$( dirname $0 )"/dns-api.sh GET "/record:host?alias~=${mysearch}&_return_fields%2B=aliases" + "$( dirname $0 )"/dns-api.sh GET "/record:cname?name~=${mysearch}" fi # ---------------------------------------------------------------------- \ No newline at end of file -- GitLab