Skip to content
Snippets Groups Projects
Commit 02617bfc authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

added search for cname; debug comments to stderr

parent e34d4d73
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
# 2021-01-20 v0.0 <axel.hahn@iml.unibe.ch> # 2021-01-20 v0.0 <axel.hahn@iml.unibe.ch>
# 2022-01-14 v1.0 <axel.hahn@iml.unibe.ch> 1st public version # 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-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 ...@@ -40,7 +41,7 @@ fi
relUrl="$1" relUrl="$1"
# ----- make curl request # ----- make curl request
echo "; === DNS API :: $method ${relUrl}" >&2 echo "; === DNS API :: $method ${relUrl}"
curl -u $myauth -X $method "${mybaseurl}${relUrl}" 2>/dev/null \ curl -u $myauth -X $method "${mybaseurl}${relUrl}" 2>/dev/null \
| ( if which jq >/dev/null 2>&1; then jq; else cat; echo ; fi ) | ( if which jq >/dev/null 2>&1; then jq; else cat; echo ; fi )
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
# 2022-01-14 v1.0 <axel.hahn@iml.unibe.ch> 1st public version # 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-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-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 ...@@ -20,7 +21,7 @@ cat <<EOH
Search for hostnames or aliases in Infoblox API Search for hostnames or aliases in Infoblox API
It uses dns-api.sh and adds the return field for aliases. 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: EXAMPLES:
...@@ -38,8 +39,8 @@ The search supports regex: ...@@ -38,8 +39,8 @@ The search supports regex:
dns-search.sh name "^(connector|examinator).*measured.stage" dns-search.sh name "^(connector|examinator).*measured.stage"
(4) (4)
Lazy mode: do not add name or alias to start 2 requests to search in name and Lazy mode: do not add name or alias or cname to start 3 requests to search
alias fields in all object types
dns-search.sh ufive dns-search.sh ufive
EOH EOH
...@@ -50,7 +51,7 @@ fi ...@@ -50,7 +51,7 @@ fi
# MAIN # MAIN
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
mytype= mytype=
if echo "$1" | grep -E '^(name|alias)$' >/dev/null if echo "$1" | grep -E '^(name|alias|cname)$' >/dev/null
then then
mytype=$1 mytype=$1
shift 1 shift 1
...@@ -61,15 +62,16 @@ mysearch=$1 ...@@ -61,15 +62,16 @@ mysearch=$1
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
echo "; === DNS SEARCH" >&2 echo "; === DNS SEARCH"
echo "; search for type : $mytype" >&2 echo "; search for type : $mytype"
echo "; search regex : $mysearch" >&2 echo "; search regex : $mysearch"
echo ";" >&2 echo ";"
if [ -n "$mytype" ]; then if [ -n "$mytype" ]; then
"$( dirname $0 )"/dns-api.sh GET "/record:host?${mytype}~=${mysearch}&_return_fields%2B=aliases" "$( dirname $0 )"/dns-api.sh GET "/record:host?${mytype}~=${mysearch}&_return_fields%2B=aliases"
else else
"$( dirname $0 )"/dns-api.sh GET "/record:host?name~=${mysearch}&_return_fields%2B=aliases" "$( 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:host?alias~=${mysearch}&_return_fields%2B=aliases"
"$( dirname $0 )"/dns-api.sh GET "/record:cname?name~=${mysearch}"
fi fi
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment