Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Icinga2 integration into backupninja
function generate_post_data() {
cat <<EOF
{
"exit_status": $EXIT_STATUS,
"plugin_output": "$PLUGIN_OUTPUT"
}
EOF
}
function generate_post_reschedule() {
#TODO: Make the check time configurable
RESCHEDULE_TIME=$(date -d "tomorrow 6am" "+%s")
cat <<EOF
{
"next_check": "$RESCHEDULE_TIME"
}
EOF
}
function icinga_exit_status() {
EXIT_STATUS=3
[ $warnings == 0 ] && [ $errors == 0 ] && [ $fatals == 0 ] && EXIT_STATUS=0
[ $warnings == 0 ] || EXIT_STATUS=1
[ $errors == 0 ] || EXIT_STATUS=2
[ $fatals == 0 ] || EXIT_STATUS=2
}
function icinga_plugin_output() {
for ((i=0; i < ${#messages[@]} ; i++)); do
PLUGIN_OUTPUT+="${messages[$i]}\n"
done
}
setfile $conffile
getconf ICINGA2_API_USER
getconf ICINGA2_API_PASSWORD
getconf ICINGA2_SERVER_ADDRESS
getconf ICINGA2_API_PORT
getconf ICINGA2_HOSTNAME
if [ -n "$ICINGA2_SERVER_ADDRESS" ] && [ $actions_run != 0 ]; then
icinga_exit_status
icinga_plugin_output
curl -k -s -u $ICINGA2_API_USER:$ICINGA2_API_PASSWORD -H 'Accept: application/json' -X POST "https://$ICINGA2_SERVER_ADDRESS:$ICINGA2_API_PORT/v1/actions/process-check-result?service=${ICINGA2_HOSTNAME}!backupninja" --data "$(generate_post_data)" > /dev/null
# Reschedule the next dummy backupninja check
curl -k -s -u $ICINGA2_API_USER:$ICINGA2_API_PASSWORD -H 'Accept: application/json' -X POST "https://$ICINGA2_SERVER_ADDRESS:$ICINGA2_API_PORT/v1/actions/reschedule-check?service=${ICINGA2_HOSTNAME}!backupninja" --data "$(generate_post_reschedule)" > /dev/null
fi
@MegaphoneJon

This comment has been minimized.

Copy link
Owner Author

@MegaphoneJon MegaphoneJon commented Feb 13, 2017

Automatically reschedule the dummy check when reporting in to tomorrow at 6am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment