Commit 9996f03d authored by Ryan Lee's avatar Ryan Lee

initial plugin import, largely derived from slack-notification bot without...

initial plugin import, largely derived from slack-notification bot without having correctly set up the command portion
parents
object NotificationCommand "statuspage-notifications-command" {
import "plugin-notification-command"
command = {{
log(LogDebug, "statuspage-notifications", "Sending notification...reading user configuration")
var statuspage_api_url = macro("$statuspage_notifications_api_url$")
var statuspage_api_key = macro("$statuspage_notifications_api_key$")
var component_map = macro("$statuspage_notifications_component_dictionary$")
var configuration = {
"vars.statuspage_notifications_api_url" = statuspage_api_url,
"vars.statuspage_notifications_api_key" = statuspage_api_key,
"vars.statuspage_notifications_component_dictionary" = component_map
}
log(LogDebug, "statuspage-notifications", "Sending notification...read user configuration successfully: " + Json.encode(configuration))
log(LogDebug, "statuspage-notifications", "Sending notification...reading notification data")
var notification_type = macro("$notification.type$")
var notification_author = macro("$notification.author$")
var notification_comment = macro("$notification.comment$")
var icinga_long_date_time = macro("$icinga.long_date_time$")
var service_name = macro("$service.name$")
var service_display_name = macro("$service.display_name$")
var service_state = macro("$service.state$")
var service_check_attempt = macro("$service.check_attempt$")
var service_last_state = macro("$service.last_state$")
var service_output = macro("$service.output$")
var host_name = macro("$host.name$")
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 = {
"notification.type" = notification_type,
"notification.author" = notification_author,
"notification.comment" = notification_comment,
"icinga.long_date_time" = icinga_long_date_time,
"service.name" = service_name,
"service.display_name" = service_display_name,
"service.state" = service_state,
"service.check_attempt" = service_check_attempt,
"service.last_state" = service_last_state,
"service.output" = service_output,
"host.name" = host_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...generating notification text")
var short_host_output = host_output.substr(0, plugin_output_max_length)
var host_name_with_link = "<" + icinga2_base_url + "/monitoring/host/show?host=" + host_name + "|" + host_display_name + ">"
var text = "error crafting payload"
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)
log(LogDebug, "statuspage-notifications", "Generating notification command")
var payload_dictionary = {
"channel" = slack_channel,
"username" = slack_botname,
"text" = text
}
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 = [
"curl",
"--fail",
"--connect-timeout", "30",
"--max-time", "60",
"--silent", "--show-error",
"-X", "POST",
"-H", "'Authorization: OAuth " + statuspage_api_key + "'",
"--data-urlencode", payload_argument,
statuspage_api_url
]
var notification_command = cmd.join(" ")
log(LogDebug, "statuspage-notifications", "Generated notification command successfully: " + notification_command)
return notification_command
}}
}
template Notification "statuspage-notifications-default-configuration" {
types = [ Problem, Acknowledgement, Recovery, Custom,
FlappingStart, FlappingEnd,
DowntimeStart, DowntimeEnd, DowntimeRemoved ]
user_groups = [ "icingaadmins" ]
period = "24x7"
interval = 5m
vars.statuspage_notifications_api_url = "https://api.statuspage.io/v1/pages/your-pageid"
vars.statuspage_notifications_api_key = "your-api-key"
vars.statuspage_notifications_component_dictionary = {}
}
template Notification "statuspage-notifications-configuration" {
import "statuspage-notifications-user-configuration"
command = "statuspage-notifications-command"
}
template Notification "slack-notifications-default-configuration-services" {
import "statuspage-notifications-configuration"
states = [ OK, Warning, Critical, Unknown ]
}
template Notification "statuspage-notifications-default-configuration-hosts" {
import "statuspage-notifications-configuration"
states = [ Up, Down ]
}
apply Notification "statuspage-notifications-notification-hosts" to Host {
import "statuspage-notifications-user-configuration-hosts"
assign where host.vars.statuspage_notifications == "enabled"
}
apply Notification "statuspage-notifications-notification-services" to Service {
import "statuspage-notifications-user-configuration-services"
assign where service.vars.statuspage_notifications == "enabled"
}
template Notification "statuspage-notifications-user-configuration" {
import "statuspage-notifications-default-configuration"
vars.statuspage_notifications_api_url = "<YOUR STATUSPAGE.IO API URL>, e.g. https://api.statuspage.io/v1/pages/PAGE_ID"
vars.statuspage_notifications_api_key = "<YOUR STATUSPAGE.IO API KEY>, e.g. some-long-hash"
vars.statuspage_notifications_component_dictionary = { "component-name": "component-id" }
vars.statuspage_notifications_icinga2_base_url = "<YOUR ICINGA2 BASE URL>, e.g. http://icinga-web.yourcompany.com/icingaweb2"
}
template Notification "statuspage-notifications-user-configuration-hosts" {
import "statuspage-notifications-default-configuration-hosts"
}
template Notification "statuspage-notifications-user-configuration-services" {
import "statuspage-notifications-default-configuration-services"
}
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