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 @@
# 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 )
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment