Commit b8b8b80f authored by Ryan Lee's avatar Ryan Lee

guessing at options for building out function

parent 99e55274
...@@ -25,12 +25,7 @@ object NotificationCommand "statuspage-notifications-command" { ...@@ -25,12 +25,7 @@ object NotificationCommand "statuspage-notifications-command" {
var service_check_attempt = macro("$service.check_attempt$") var service_check_attempt = macro("$service.check_attempt$")
var service_last_state = macro("$service.last_state$") var service_last_state = macro("$service.last_state$")
var service_output = macro("$service.output$") var service_output = macro("$service.output$")
var host_name = macro("$host.name$") var service_component_name = macro("$service.vars.statuspage_notifications_component$")
var host_display_name = macro("$host.display_name$")
var host_state = macro("$host.state$")
var host_check_attempt = macro("$host.check_attempt$")
var host_last_state = macro("$host.last_state$")
var host_output = macro("$host.output$")
var notification_data = { var notification_data = {
"notification.type" = notification_type, "notification.type" = notification_type,
"notification.author" = notification_author, "notification.author" = notification_author,
...@@ -42,56 +37,33 @@ object NotificationCommand "statuspage-notifications-command" { ...@@ -42,56 +37,33 @@ object NotificationCommand "statuspage-notifications-command" {
"service.check_attempt" = service_check_attempt, "service.check_attempt" = service_check_attempt,
"service.last_state" = service_last_state, "service.last_state" = service_last_state,
"service.output" = service_output, "service.output" = service_output,
"host.name" = host_name, "service.vars.statuspage_notifications_component" = service_component_name,
"host.display_name" = host_display_name,
"host.state" = host_state,
"host.check_attempt" = host_check_attempt,
"host.last_state" = host_last_state,
"host.output" = host_output,
} }
log(LogDebug, "statuspage-notifications", "Sending notification...read notification data successfully: " + Json.encode(notification_data)) log(LogDebug, "statuspage-notifications", "Sending notification...read notification data successfully: " + Json.encode(notification_data))
log(LogDebug, "statuspage-notifications", "Sending notification...generating notification text") log(LogDebug, "statuspage-notifications", "Sending notification...generating component state")
var short_host_output = host_output.substr(0, plugin_output_max_length) var component_status = "operational"
var host_name_with_link = "<" + icinga2_base_url + "/monitoring/host/show?host=" + host_name + "|" + host_display_name + ">" if(service_state != '') {
var text = "error crafting payload" component_status = "major_outage"
if(service_name != null) {
var service_name_with_link = "<" + icinga2_base_url + "/monitoring/service/show?host=" + host_name + "&service=" + service_name + "|" + service_display_name + ">"
var short_service_output = service_output.substr(0, plugin_output_max_length)
var service_state_text = " transitioned from state " + service_last_state + " to state " + service_state
if(service_last_state == service_state) {
service_state_text = " is still in state " + service_state
}
text = ":" + icon + ": " + notification_type + notification_type_custom_text + ": Service " + service_name_with_link + service_state_text + " on host " + host_name_with_link + ". Plugin output: ```" + short_service_output + "```"
} else {
var host_state_text = " transitioned from state " + host_last_state + " to state " + host_state
if(host_last_state == host_state) {
host_state_text = " is still in state " + host_state
}
text = ":" + icon + ": " + notification_type + notification_type_custom_text + ": Host " + host_name_with_link + host_state_text + ". Plugin output: ```" + short_host_output + "```"
} }
log(LogDebug, "statuspage-notifications", "Sending notification...generated notification text successfully: " + text) var component_id = component_map[service_component_name]
log(LogDebug, "statuspage-notifications", "Sending notification...generated component successfully: " + component_status)
log(LogDebug, "statuspage-notifications", "Generating notification command") log(LogDebug, "statuspage-notifications", "Generating notification command")
var payload_dictionary = { var statuspage_payload = "component[status]=" + component_status
"channel" = slack_channel, var payload_argument = escape_shell_arg(statuspage_payload)
"username" = slack_botname, var statuspage_api_key_argument = escape_shell_arg(statuspage_api_key)
"text" = text var statuspage_api_url_argument = escape_shell_arg(statuspage_api_url + "/components/" + component_id + ".json")
}
var payload_json = Json.encode(payload_dictionary)
var slack_payload = "payload=" + payload_json
var payload_argument = escape_shell_arg(slack_payload)
var slack_webhook_url_argument = escape_shell_arg(slack_webhook_url)
var cmd = [ var cmd = [
"curl", "curl",
"--fail", "--fail",
"--connect-timeout", "30", "--connect-timeout", "30",
"--max-time", "60", "--max-time", "60",
"--silent", "--show-error", "--silent", "--show-error",
"-X", "POST", "-X", "PATCH",
"-H", "'Authorization: OAuth " + statuspage_api_key + "'", "-H", "'Authorization: OAuth " + statuspage_api_key_argument + "'",
"--data-urlencode", payload_argument, "-d", "component[status]=" + payload_argument,
statuspage_api_url statuspage_api_url_agrument
] ]
var notification_command = cmd.join(" ") var notification_command = cmd.join(" ")
log(LogDebug, "statuspage-notifications", "Generated notification command successfully: " + notification_command) log(LogDebug, "statuspage-notifications", "Generated notification command successfully: " + notification_command)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment