|
|
|
@ -18,6 +18,7 @@ myOptions[API]="objects"
|
|
|
|
myOptions[APIep]="servicestatus"
|
|
|
|
myOptions[APIep]="servicestatus"
|
|
|
|
myOptions[TestMode]=""
|
|
|
|
myOptions[TestMode]=""
|
|
|
|
myOptions[Create]=""
|
|
|
|
myOptions[Create]=""
|
|
|
|
|
|
|
|
myOptions[Apply]=""
|
|
|
|
myOptions[Options]=""
|
|
|
|
myOptions[Options]=""
|
|
|
|
verbose="0"
|
|
|
|
verbose="0"
|
|
|
|
tmpJSON=""
|
|
|
|
tmpJSON=""
|
|
|
|
@ -125,12 +126,14 @@ print_help() {
|
|
|
|
-cn|--configname config_name=<value>
|
|
|
|
-cn|--configname config_name=<value>
|
|
|
|
... comment | downtime | contact | host | service | hostgroup | ...
|
|
|
|
... comment | downtime | contact | host | service | hostgroup | ...
|
|
|
|
--create doCreate="true"
|
|
|
|
--create doCreate="true"
|
|
|
|
|
|
|
|
--apply If we're creating something, then Apply Configuration
|
|
|
|
-D <Nagios Config Directive>=<value>
|
|
|
|
-D <Nagios Config Directive>=<value>
|
|
|
|
-f|--fields JQ-valid list of fields to show=<value>
|
|
|
|
-f|--fields JQ-valid list of fields to show=<value>
|
|
|
|
--file load JSON from=<value>
|
|
|
|
--file load JSON from=<value>
|
|
|
|
--helpopt Show help for command options
|
|
|
|
--helpopt Show help for command options
|
|
|
|
--help This text
|
|
|
|
--help This text
|
|
|
|
-hg|--hostgroup hostgroup=<value>
|
|
|
|
-hg|--hostgroup hostgroup=<value>
|
|
|
|
|
|
|
|
-hgm hostgroup_members (mainly for creating hostgroups)
|
|
|
|
-h|--host host_name=<value>
|
|
|
|
-h|--host host_name=<value>
|
|
|
|
... hostgroupmembers | servicegroupmembers >
|
|
|
|
... hostgroupmembers | servicegroupmembers >
|
|
|
|
-j|--jq additional valid JQ=<value>
|
|
|
|
-j|--jq additional valid JQ=<value>
|
|
|
|
@ -143,6 +146,7 @@ print_help() {
|
|
|
|
-qq Same as --quick but add -o c but also print the first line of the CSV output (fields)
|
|
|
|
-qq Same as --quick but add -o c but also print the first line of the CSV output (fields)
|
|
|
|
--save save JSON to=<value>
|
|
|
|
--save save JSON to=<value>
|
|
|
|
-sg|--servicegroup servicegroup=<value>
|
|
|
|
-sg|--servicegroup servicegroup=<value>
|
|
|
|
|
|
|
|
-sgm servicegroup_members (mainly for creating servicegroups)
|
|
|
|
-s|--service service_description=<value>
|
|
|
|
-s|--service service_description=<value>
|
|
|
|
--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)
|
|
|
|
@ -182,12 +186,14 @@ while [ -n "$1" ]; do
|
|
|
|
-cg|--contactgroup) myDir[contact_groups]="$2"; shift 2;;
|
|
|
|
-cg|--contactgroup) myDir[contact_groups]="$2"; shift 2;;
|
|
|
|
-cn|--configname) myDir[config_name]="$2"; shift 2;;
|
|
|
|
-cn|--configname) myDir[config_name]="$2"; shift 2;;
|
|
|
|
--create) myOptions[Create]="true"; shift 1;;
|
|
|
|
--create) myOptions[Create]="true"; shift 1;;
|
|
|
|
|
|
|
|
--apply) myOptions[Apply]="true"; shift 1;;
|
|
|
|
-D) myDir[$2]="$3"; shift 3;;
|
|
|
|
-D) myDir[$2]="$3"; shift 3;;
|
|
|
|
-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;;
|
|
|
|
--helpopt) print_helpopt;;
|
|
|
|
--helpopt) print_helpopt;;
|
|
|
|
--help) print_help;;
|
|
|
|
--help) print_help;;
|
|
|
|
-hg|--hostgroup) myDir[hostgroup_name]="$2"; shift 2;;
|
|
|
|
-hg|--hostgroup) myDir[hostgroup_name]="$2"; shift 2;;
|
|
|
|
|
|
|
|
-hgm) myDir[hostgroup_members]="$2"; shift 2;;
|
|
|
|
-h|--host) myDir[host_name]="$2"; shift 2;;
|
|
|
|
-h|--host) myDir[host_name]="$2"; shift 2;;
|
|
|
|
-j|--jq) myOptions[MoreJQ]="$2"; shift 2;;
|
|
|
|
-j|--jq) myOptions[MoreJQ]="$2"; shift 2;;
|
|
|
|
--key) APIKEY="$2"; shift 2;;
|
|
|
|
--key) APIKEY="$2"; shift 2;;
|
|
|
|
@ -199,6 +205,7 @@ while [ -n "$1" ]; do
|
|
|
|
-Q|--quick) myOptions[Quick]="true"; shift 1;;
|
|
|
|
-Q|--quick) myOptions[Quick]="true"; shift 1;;
|
|
|
|
--save) myOptions[Save]="$2"; shift 2;;
|
|
|
|
--save) myOptions[Save]="$2"; shift 2;;
|
|
|
|
-sg|--servicegroup) myDir[servicegroup_name]="$2"; shift 2;;
|
|
|
|
-sg|--servicegroup) myDir[servicegroup_name]="$2"; shift 2;;
|
|
|
|
|
|
|
|
-sgm) myDir[servicegroup_members]="$2"; shift 2;;
|
|
|
|
-s|--service) myDir[service_description]="$2"; shift 2;;
|
|
|
|
-s|--service) myDir[service_description]="$2"; shift 2;;
|
|
|
|
--stats) do_stats; shift 2;;
|
|
|
|
--stats) do_stats; shift 2;;
|
|
|
|
--state) myDir[current_state]="$2"; shift 2;;
|
|
|
|
--state) myDir[current_state]="$2"; shift 2;;
|
|
|
|
@ -241,27 +248,46 @@ do_api() {
|
|
|
|
do_api_post() {
|
|
|
|
do_api_post() {
|
|
|
|
api_start="$1"
|
|
|
|
api_start="$1"
|
|
|
|
api_command="$2"
|
|
|
|
api_command="$2"
|
|
|
|
|
|
|
|
api_data=""
|
|
|
|
|
|
|
|
[ -n "$3" ] && api_data="$3&applyconfig=0"
|
|
|
|
url="${XI_URL}/api/v1/${api_start}/${api_command}?apikey=${APIKEY}&pretty=0"
|
|
|
|
url="${XI_URL}/api/v1/${api_start}/${api_command}?apikey=${APIKEY}&pretty=0"
|
|
|
|
do_debug 2 "start=$1 command=$2"
|
|
|
|
do_debug 2 "start=$1 command=$2"
|
|
|
|
do_debug 1 "Executing: $url"
|
|
|
|
do_debug 1 "Executing: $curl -XPOST -k \"$url\" -d \"$api_data\""
|
|
|
|
$curl -XPOST -k "$url" -d "hostgroup_name=${myDir[HG]}&alias=${myDir[HG]}&applyconfig=0"
|
|
|
|
[ -z "${myOptions[TestMode]}" ] && $curl -XPOST -k "$url" -d "$api_data"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# At this time, all we can create ia a hostgroup
|
|
|
|
# At this time, all we can create ia a hostgroup
|
|
|
|
create_hostgroup() {
|
|
|
|
create_hostgroup() {
|
|
|
|
do_debug 1 "about to do an API post call"
|
|
|
|
do_debug 1 "about to do an API post call"
|
|
|
|
do_api_post config hostgroup
|
|
|
|
api_data="hostgroup_name=${myDir[hostgroup_name]}&alias=${myDir[hostgroup_name]}"
|
|
|
|
|
|
|
|
[ -n "${myDir[host_name]}" ] && api_data+="&members=${myDir[host_name]}"
|
|
|
|
|
|
|
|
[ -n "${myDir[hostgroup_members]}" ] && api_data+="&hostgroup_members=${myDir[hostgroup_members]}"
|
|
|
|
|
|
|
|
do_api_post config hostgroup "$api_data"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
create_servicegroup() {
|
|
|
|
|
|
|
|
do_debug 1 "about to do an API post call"
|
|
|
|
|
|
|
|
api_data="servicegroup_name=${myDir[servicegroup_name]}&alias=${myDir[servicegroup_name]}"
|
|
|
|
|
|
|
|
[ -n "${myDir[service_description]}" ] && api_data+="&members=${myDir[service_description]}"
|
|
|
|
|
|
|
|
[ -n "${myDir[servicegroup_members]}" ] && api_data+="&servicegroup_members=${myDir[servicegroup_members]}"
|
|
|
|
|
|
|
|
do_api_post config servicegroup "$api_data"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
do_create() {
|
|
|
|
do_create() {
|
|
|
|
do_debug 1 "about to do a create_command"
|
|
|
|
do_debug 1 "about to do a create_command"
|
|
|
|
[ -n "${myDir[HG]}" ] && create_hostgroup
|
|
|
|
[ -n "${myDir[hostgroup_name]}" ] && create_hostgroup
|
|
|
|
exit
|
|
|
|
[ -n "${myDir[servicegroup_members]}" ] && create_servicegroup
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do_apply() {
|
|
|
|
|
|
|
|
do_debug 1 "About to Apply Configuration..."
|
|
|
|
|
|
|
|
do_api_post system applyconfig
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# If we said "--create" then we want to make something
|
|
|
|
# If we said "--create" then we want to make something
|
|
|
|
if [ -n "${myOptions[Create]}" ]; then
|
|
|
|
if [ -n "${myOptions[Create]}" ]; then
|
|
|
|
do_create
|
|
|
|
do_create
|
|
|
|
|
|
|
|
[ -n "${myOptions[Apply]}" -a -z "${myOptions[TestMode]}" ] && do_apply
|
|
|
|
exit
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|