Skip to content

Instantly share code, notes, and snippets.

@MegaphoneJon
Last active February 16, 2017 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MegaphoneJon/322a4fea5707013433d9763972e4d414 to your computer and use it in GitHub Desktop.
Save MegaphoneJon/322a4fea5707013433d9763972e4d414 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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