napi now does user generation

dev
Eric Loyd 10 months ago
parent 9713c09f9f
commit 73eafb12c8

@ -27,3 +27,10 @@ cp servicetemplates.cfg /usr/local/nagios/etc/import
cp servicegroups.cfg services/*.cfg /usr/local/nagios/etc/import cp servicegroups.cfg services/*.cfg /usr/local/nagios/etc/import
/usr/local/nagiosxi/scripts/reconfigure_nagios.sh /usr/local/nagiosxi/scripts/reconfigure_nagios.sh
``` ```
## Useful software:
apt install htop iostat sysstat
or
yum install htop iostat sysstat

30
napi

@ -31,7 +31,7 @@ APIinfo["config/service"]=""
APIinfo["config/hostgroup"]=".[]" APIinfo["config/hostgroup"]=".[]"
APIinfo["config/servicegroup"]=".[]" APIinfo["config/servicegroup"]=".[]"
APIinfo["config/command"]=".[]" APIinfo["config/command"]=".[]"
APIinfo["config/contact"]=".contact[]" APIinfo["config/contact"]=".[]"
APIinfo["config/contactgroup"]=".[]" APIinfo["config/contactgroup"]=".[]"
APIinfo["config/timeperiod"]=".[]" APIinfo["config/timeperiod"]=".[]"
@ -59,6 +59,8 @@ APIinfo["objects/serviceavailability"]=".serviceavailability[]"
APIinfo["objects/sla"]="" APIinfo["objects/sla"]=""
APIinfo["objects/bpi"]="" APIinfo["objects/bpi"]=""
APIinfo["system/user"]=".users[]"
do_debug() { do_debug() {
[ "$verbose" -ge "$1" ] && echo "$2" >&2 [ "$verbose" -ge "$1" ] && echo "$2" >&2
} }
@ -195,11 +197,15 @@ print_help() {
-s|--service service_description=<value> -s|--service service_description=<value>
--start For things that have date selectors, this is a "show me after" selector: YYYYMMDDHHMMSS --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 --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 --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 --bstatus Same as --status but only show things that are not in an OK state
--state 0, 1, or 2 (or other, I suppose) --state 0, 1, or 2 (or other, I suppose)
--stype 0, 1 (SOFT or HARD) --stype 0, 1 (SOFT or HARD)
--test Don't call the API, just show what would happen --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)) -v|--verbose verbose=\$((\$verbose + 1))
HELP_EOF HELP_EOF
exit exit
@ -275,6 +281,9 @@ while [ -n "$1" ]; do
--disable) myOptions[Disable]="true"; shift 1;; --disable) myOptions[Disable]="true"; shift 1;;
--enable) myOptions[Enable]="true"; shift 1;; --enable) myOptions[Enable]="true"; shift 1;;
--addvar) myOptions[AddVar]="$2"; 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;; -f|--fields) myOptions[Fields]="$2"; shift 2;;
--file) myOptions[File]="$2"; shift 2;; --file) myOptions[File]="$2"; shift 2;;
-j|--jq) myOptions[MoreJQ]="$2"; shift 2;; -j|--jq) myOptions[MoreJQ]="$2"; shift 2;;
@ -289,6 +298,7 @@ while [ -n "$1" ]; do
--start) myOptions[Start]="$2"; shift 2;; --start) myOptions[Start]="$2"; shift 2;;
--status) myOptions[Status]="true"; shift 1;; --status) myOptions[Status]="true"; shift 1;;
--bstatus) myOptions[Status]="true"; myOptions[BStatus]="true"; shift 1;; --bstatus) myOptions[Status]="true"; myOptions[BStatus]="true"; shift 1;;
--raw) myOptions[Raw]="true"; shift 1;;
--test) myOptions[TestMode]="true"; shift 1;; --test) myOptions[TestMode]="true"; shift 1;;
*) shift 1;; *) shift 1;;
esac esac
@ -318,6 +328,13 @@ if [ -n "${myOptions[Status]}" ]; then
fi fi
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 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 while read url key; do
@ -334,7 +351,6 @@ do_debug 2 "-> Looking for url=$url XI_URL=$XI_URL"
fi fi
done < "$APIkeyFile" done < "$APIkeyFile"
fi fi
do_debug 1 "Final URL=$XI_URL and key=$APIKEY" do_debug 1 "Final URL=$XI_URL and key=$APIKEY"
[ -z "$XI_URL" -o -z "$APIKEY" ] && echo "Empty URL or Key." && exit [ -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[End]}" ] && url+="&endtime=${myOptions[End]}"
[ -n "${myOptions[Records]}" ] && url+="&records=${myOptions[Records]}" [ -n "${myOptions[Records]}" ] && url+="&records=${myOptions[Records]}"
[ -n "${myOptions[OrderBy]}" ] && url+="&orderby=${myOptions[OrderBy]}" [ -n "${myOptions[OrderBy]}" ] && url+="&orderby=${myOptions[OrderBy]}"
[ "${myOptions[Users]}" == "1" ] && url+="&advanced=1"
if [ -n "${myOptions[Column]}" ]; then if [ -n "${myOptions[Column]}" ]; then
colName=`echo "${myOptions[Column]}" | cut -d= -f 1 | tr " " "+"` colName=`echo "${myOptions[Column]}" | cut -d= -f 1 | tr " " "+"`
colVal=`echo "${myOptions[Column]}" | cut -d= -f 2 | 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" do_debug 2 " Before: jqString=$jqString"
for thing in "${!myDir[@]}"; do for thing in "${!myDir[@]}"; do
[ -n "${myDir[$thing]}" ] && jqString+="| select(.$thing $(jq_check_case ${myDir[$thing]}))" [ -n "${myDir[$thing]}" ] && jqString+="| select(.$thing $(jq_check_case ${myDir[$thing]}))"
do_debug 2 " After: jqString=$jqString" do_debug 2 " During: jqString=$jqString"
done done
do_debug 2 " After: jqString=$jqString"
# endpoint specific things # endpoint specific things
case "${myOptions[API]}/${myOptions[APIep]}" in 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]}))" [ -n "${myDir[service_description]}" ] && jqString+="| select(.service_description $(jq_check_case ${myDir[service_description]}))"
;; ;;
config/host) tmpQuick=".host_name,.address,.check_command";; config/host) tmpQuick=".host_name,.address,.check_command";;
config/contact) tmpQuick=".contact_name,.email";;
esac esac
do_debug 1 "myOptions[Options]=${myOptions[Options]}" do_debug 1 "myOptions[Options]=${myOptions[Options]}"
@ -610,7 +629,12 @@ do_debug 1 "jqString=$jqString"
if [ -n "${myOptions[TestMode]}" ]; then if [ -n "${myOptions[TestMode]}" ]; then
echo "### TEST MODE - Here is what would have been done (testMode=${myOptions[TestMode]}) ###" echo "### TEST MODE - Here is what would have been done (testMode=${myOptions[TestMode]}) ###"
echo "cat <tmpfile> | jq -r \"$jqString\"" echo "cat <tmpfile> | jq -r \"$jqString\""
else
if [ -n "${myOptions[Raw]}" ]; then
do_debug 1 "*** RAW specified *** Overriding all other options"
cat $tmpJSON
else else
cat $tmpJSON | jq -r "$jqString" cat $tmpJSON | jq -r "$jqString"
fi fi
fi
[ -z "${myOptions[File]}" ] && rm $tmpJSON [ -z "${myOptions[File]}" ] && rm $tmpJSON

Loading…
Cancel
Save