Added --addvar to napi

dev
Eric Loyd 1 year ago
parent c93d3059f8
commit dc76ee1fc9

16
napi

@ -271,6 +271,7 @@ while [ -n "$1" ]; do
--ctrace) myOptions[CommandTrace]="true"; shift 1;;
--create) myOptions[Create]="true"; shift 1;;
--delete) myOptions[Delete]="true"; shift 1;;
--addvar) myOptions[AddVar]="$2"; shift 1;;
-f|--fields) myOptions[Fields]="$2"; shift 2;;
--file) myOptions[File]="$2"; shift 2;;
-j|--jq) myOptions[MoreJQ]="$2"; shift 2;;
@ -439,6 +440,21 @@ do_apply() {
do_api_post system applyconfig
}
### curl -XPUT "http://X.X.X.X/nagiosxi/api/v1/config/host/$x?apikey=KEY&pretty=1&old_host_name=testapihost&_foo=bartoo"
# If we used --addvar then we want to add a custom macro to a host. Other options available later
if [ -n "${myOptions[AddVar]}" ]; then
if [ -z "${myDir[host_name]}" ]; then
echo "If using --addvar then you must specify -h for the host to add to"
exit 1
fi
hname=`echo "${myDir[host_name]}" | tr " " "+"`
varName=`echo "${myOptions[AddVar]}" | cut -d= -f 1 | tr " " "+" | sed -e "s/^_//"`
varVal=`echo "${myOptions[AddVar]}" | cut -d= -f 2 | tr " " "+"`
do_debug 1 "varName=$varName varVal=$varVal"
do_api_put config "host/$hname" "_${varName}=${varVal}"
exit
fi
# If we said "--create" then we want to make something
if [ -n "${myOptions[Create]}" ]; then
do_create

Loading…
Cancel
Save