|
|
|
|
@ -31,7 +31,7 @@ APIinfo["config/service"]=""
|
|
|
|
|
APIinfo["config/hostgroup"]=".[]"
|
|
|
|
|
APIinfo["config/servicegroup"]=".[]"
|
|
|
|
|
APIinfo["config/command"]=".[]"
|
|
|
|
|
APIinfo["config/contact"]=".contact[]"
|
|
|
|
|
APIinfo["config/contact"]=".[]"
|
|
|
|
|
APIinfo["config/contactgroup"]=".[]"
|
|
|
|
|
APIinfo["config/timeperiod"]=".[]"
|
|
|
|
|
|
|
|
|
|
@ -59,6 +59,8 @@ APIinfo["objects/serviceavailability"]=".serviceavailability[]"
|
|
|
|
|
APIinfo["objects/sla"]=""
|
|
|
|
|
APIinfo["objects/bpi"]=""
|
|
|
|
|
|
|
|
|
|
APIinfo["system/user"]=".users[]"
|
|
|
|
|
|
|
|
|
|
do_debug() {
|
|
|
|
|
[ "$verbose" -ge "$1" ] && echo "$2" >&2
|
|
|
|
|
}
|
|
|
|
|
@ -195,11 +197,15 @@ print_help() {
|
|
|
|
|
-s|--service service_description=<value>
|
|
|
|
|
--start For things that have date selectors, this is a "show me after" selector: YYYYMMDDHHMMSS
|
|
|
|
|
--end For things that have date selectors, this is a "show me before" selector: YYYYMMDDHHMMSS
|
|
|
|
|
--users Lists XI users
|
|
|
|
|
--usersa Lists XI users (advanced)
|
|
|
|
|
--useradd Switches to add user mode (MUST SPECIFY --users AS WELL!!!)
|
|
|
|
|
--status Quick select for showing similar things that you would see on main servicestatus page in the GUI
|
|
|
|
|
--bstatus Same as --status but only show things that are not in an OK state
|
|
|
|
|
--state 0, 1, or 2 (or other, I suppose)
|
|
|
|
|
--stype 0, 1 (SOFT or HARD)
|
|
|
|
|
--test Don't call the API, just show what would happen
|
|
|
|
|
--raw Just get the raw API JSON, ignore everything else (except --file and host/key info)
|
|
|
|
|
-v|--verbose verbose=\$((\$verbose + 1))
|
|
|
|
|
HELP_EOF
|
|
|
|
|
exit
|
|
|
|
|
@ -275,6 +281,9 @@ while [ -n "$1" ]; do
|
|
|
|
|
--disable) myOptions[Disable]="true"; shift 1;;
|
|
|
|
|
--enable) myOptions[Enable]="true"; shift 1;;
|
|
|
|
|
--addvar) myOptions[AddVar]="$2"; shift 1;;
|
|
|
|
|
--users) myOptions[Users]="0"; shift 1;;
|
|
|
|
|
--usersa) myOptions[Users]="1"; shift 1;;
|
|
|
|
|
--useradd) myOptions[UserAdd]="$2"; shift 2;;
|
|
|
|
|
-f|--fields) myOptions[Fields]="$2"; shift 2;;
|
|
|
|
|
--file) myOptions[File]="$2"; shift 2;;
|
|
|
|
|
-j|--jq) myOptions[MoreJQ]="$2"; shift 2;;
|
|
|
|
|
@ -289,6 +298,7 @@ while [ -n "$1" ]; do
|
|
|
|
|
--start) myOptions[Start]="$2"; shift 2;;
|
|
|
|
|
--status) myOptions[Status]="true"; shift 1;;
|
|
|
|
|
--bstatus) myOptions[Status]="true"; myOptions[BStatus]="true"; shift 1;;
|
|
|
|
|
--raw) myOptions[Raw]="true"; shift 1;;
|
|
|
|
|
--test) myOptions[TestMode]="true"; shift 1;;
|
|
|
|
|
*) shift 1;;
|
|
|
|
|
esac
|
|
|
|
|
@ -318,23 +328,29 @@ if [ -n "${myOptions[Status]}" ]; then
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# If we're listing users, then set things accordingly
|
|
|
|
|
if [ -n "${myOptions[Users]}" ]; then
|
|
|
|
|
myOptions[API]="system"
|
|
|
|
|
myOptions[APIep]="user"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Get our API key
|
|
|
|
|
if [ -n "$APIkeyFile" -a -r "$APIkeyFile" ]; then
|
|
|
|
|
do_debug 1 "Looking for url=$url in $APIkeyFile"
|
|
|
|
|
do_debug 1 "Looking for url=$url in $APIkeyFile"
|
|
|
|
|
while read url key; do
|
|
|
|
|
if [ -z "$XI_URL" ]; then
|
|
|
|
|
XI_URL="$url"
|
|
|
|
|
APIKEY="$key"
|
|
|
|
|
do_debug 1 "Found url=$url key=$key"
|
|
|
|
|
do_debug 1 "Found url=$url key=$key"
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
do_debug 2 "-> Looking for url=$url XI_URL=$XI_URL"
|
|
|
|
|
do_debug 2 "-> Looking for url=$url XI_URL=$XI_URL"
|
|
|
|
|
if [[ "$url" =~ "$XI_URL" ]]; then
|
|
|
|
|
XI_URL="$url"
|
|
|
|
|
APIKEY="$key"
|
|
|
|
|
fi
|
|
|
|
|
done < "$APIkeyFile"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
do_debug 1 "Final URL=$XI_URL and key=$APIKEY"
|
|
|
|
|
[ -z "$XI_URL" -o -z "$APIKEY" ] && echo "Empty URL or Key." && exit
|
|
|
|
|
|
|
|
|
|
@ -346,6 +362,7 @@ do_api() {
|
|
|
|
|
[ -n "${myOptions[End]}" ] && url+="&endtime=${myOptions[End]}"
|
|
|
|
|
[ -n "${myOptions[Records]}" ] && url+="&records=${myOptions[Records]}"
|
|
|
|
|
[ -n "${myOptions[OrderBy]}" ] && url+="&orderby=${myOptions[OrderBy]}"
|
|
|
|
|
[ "${myOptions[Users]}" == "1" ] && url+="&advanced=1"
|
|
|
|
|
if [ -n "${myOptions[Column]}" ]; then
|
|
|
|
|
colName=`echo "${myOptions[Column]}" | cut -d= -f 1 | tr " " "+"`
|
|
|
|
|
colVal=`echo "${myOptions[Column]}" | cut -d= -f 2 | tr " " "+"`
|
|
|
|
|
@ -560,8 +577,9 @@ jqString=${APIinfo[${myOptions[API]}/${myOptions[APIep]}]}
|
|
|
|
|
do_debug 2 " Before: jqString=$jqString"
|
|
|
|
|
for thing in "${!myDir[@]}"; do
|
|
|
|
|
[ -n "${myDir[$thing]}" ] && jqString+="| select(.$thing $(jq_check_case ${myDir[$thing]}))"
|
|
|
|
|
do_debug 2 " After: jqString=$jqString"
|
|
|
|
|
do_debug 2 " During: jqString=$jqString"
|
|
|
|
|
done
|
|
|
|
|
do_debug 2 " After: jqString=$jqString"
|
|
|
|
|
|
|
|
|
|
# endpoint specific things
|
|
|
|
|
case "${myOptions[API]}/${myOptions[APIep]}" in
|
|
|
|
|
@ -592,6 +610,7 @@ case "${myOptions[API]}/${myOptions[APIep]}" in
|
|
|
|
|
[ -n "${myDir[service_description]}" ] && jqString+="| select(.service_description $(jq_check_case ${myDir[service_description]}))"
|
|
|
|
|
;;
|
|
|
|
|
config/host) tmpQuick=".host_name,.address,.check_command";;
|
|
|
|
|
config/contact) tmpQuick=".contact_name,.email";;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
do_debug 1 "myOptions[Options]=${myOptions[Options]}"
|
|
|
|
|
@ -611,6 +630,11 @@ if [ -n "${myOptions[TestMode]}" ]; then
|
|
|
|
|
echo "### TEST MODE - Here is what would have been done (testMode=${myOptions[TestMode]}) ###"
|
|
|
|
|
echo "cat <tmpfile> | jq -r \"$jqString\""
|
|
|
|
|
else
|
|
|
|
|
if [ -n "${myOptions[Raw]}" ]; then
|
|
|
|
|
do_debug 1 "*** RAW specified *** Overriding all other options"
|
|
|
|
|
cat $tmpJSON
|
|
|
|
|
else
|
|
|
|
|
cat $tmpJSON | jq -r "$jqString"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
[ -z "${myOptions[File]}" ] && rm $tmpJSON
|
|
|
|
|
|