You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.3 KiB
Bash

#!/bin/bash
key="9RTG9Aq2NTfefE3XeAiDUbacmNvOJPWfRV3Vbs5DS8ZCCAr6XrIUDLqZeBCceQUo"
host="http://192.168.1.15"
declare -A myOpts
user=""
pass=""
name=""
email=""
go=""
opts=""
while [ -n "$1" ]; do
case "$1" in
--user) user="$2"; shift 2;;
--pass) pass="$2"; shift 2;;
--name) name="$2"; shift 2;;
--email) email="$2"; shift 2;;
--go) go="true"; shift 1;;
*) shift 1;;
esac
done
if [ -z "$user" -o -z "$pass" -o -z "$name" -o -z "$email" ]; then
echo "Must specify all of --user --pass --email and --name"
exit
fi
opts+="&force_pw_change=0"
opts+="&email_info=0"
opts+="&monitoring_contact=1"
opts+="&enable_notifications=1"
opts+="&auth_level=user"
opts+="&can_see_all_hs=1" # Default is 0
opts+="&can_control_all_hs=0"
opts+="&can_reconfigure_hs=0"
opts+="&can_control_engine=0"
opts+="&can_use_advanced=0"
opts+="&read_only=1" # Default is 0
opts+="&auth_type=local"
name=$(echo "$name" | sed -e "s/ /%20/g")
echo curl -XPOST "\"${host}/nagiosxi/api/v1/system/user?apikey=${key}&pretty=1\"" \
-d "\"username=${user}&password=${pass}&name=${name}&email=${email}${opts}\""
[ -n "$go" ] && curl -XPOST "${host}/nagiosxi/api/v1/system/user?apikey=${key}&pretty=1" \
-d "username=${user}&password=${pass}&name=${name}&email=${email}${opts}"