|
|
|
|
@ -5,6 +5,7 @@ XI_URL=""
|
|
|
|
|
curl="curl -k -s"
|
|
|
|
|
# curl -XGET "https://192.168.1.19/nagiosxi/api/v1/objects/service?apikey=<key>"
|
|
|
|
|
|
|
|
|
|
doCreate=""
|
|
|
|
|
myHost=""
|
|
|
|
|
myService=""
|
|
|
|
|
myHG=""
|
|
|
|
|
@ -20,6 +21,7 @@ api_command=""
|
|
|
|
|
|
|
|
|
|
while [ -n "$1" ]; do
|
|
|
|
|
case "$1" in
|
|
|
|
|
--create) doCreate="true"; shift 1;;
|
|
|
|
|
--key) APIKEY="$2"; shift 2;;
|
|
|
|
|
--url) XI_URL="$2"; shift 2;;
|
|
|
|
|
--save) mySave="$2"; shift 2;;
|
|
|
|
|
@ -43,12 +45,36 @@ do_api() {
|
|
|
|
|
$curl -XGET -k "$url"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# curl -XPOST "http://192.168.1.128/nagiosxi/api/v1/config/hostgroup?apikey=fsZZ4pXaKaVjSG7IYcjMRYhK8NqcqN2NGPck8gPhFoZMJGKj4YUjZCF8qSqsK7Ln&pretty=1" -d "hostgroup_name=testapihostgroup&alias=HostGroup&applyconfig=1"
|
|
|
|
|
do_api_post() {
|
|
|
|
|
api_start="$1"
|
|
|
|
|
api_command="$2"
|
|
|
|
|
url="${XI_URL}/nagiosxi/api/v1/${api_start}/${api_command}?apikey=${APIKEY}&pretty=0"
|
|
|
|
|
$curl -XPOST -k "$url" -d "hostgroup_name=$myHG&alias=$myHG&applyconfig=0"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# If we were given specific API start/commands, then let's do that and exit
|
|
|
|
|
if [ -n "$api_start" -a -n "$api_command" ]; then
|
|
|
|
|
do_api ${api_start} ${api_command}
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# At this time, all we can create ia a hostgroup
|
|
|
|
|
create_hostgroup() {
|
|
|
|
|
do_api_post config hostgroup
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do_create() {
|
|
|
|
|
[ -n "$myHG" ] && create_hostgroup
|
|
|
|
|
exit
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# If we said "--create" then we want to make something
|
|
|
|
|
if [ -n "$doCreate" ]; then
|
|
|
|
|
do_create
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Grab a copy of the JSON data so we don't have to keep making calls over and over
|
|
|
|
|
# If we used an existing file, then just use that
|
|
|
|
|
if [ -z "$myFile" ]; then
|
|
|
|
|
|