From d976feef80d8d79006fd12f5a0a8cdf7420e9eb0 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Thu, 26 Sep 2024 14:44:31 +0200 Subject: [PATCH] Add adapted Icinga2 configuration files --- cfg/command.cfg | 131 ++++++++++++++++++++++++++++++++++++++++++++++ cfg/services.cfg | 29 ++++++++++ cfg/templates.cfg | 36 +++++++++++++ 3 files changed, 196 insertions(+) create mode 100644 cfg/command.cfg create mode 100644 cfg/services.cfg create mode 100644 cfg/templates.cfg diff --git a/cfg/command.cfg b/cfg/command.cfg new file mode 100644 index 0000000..4ae895f --- /dev/null +++ b/cfg/command.cfg @@ -0,0 +1,131 @@ +// https://git.dittberner.info/jan/icinga2-matrix-notification + +object NotificationCommand "matrix-host-notification" { + import "plugin-notification-command" + command = [ SysconfDir + "/icinga2/scripts/matrix-host-notification" ] + arguments += { + "-4" = "$notification_address$" + "-6" = "$notification_address6$" + "-b" = "$notification_author$" + "-c" = "$notification_comment$" + "-d" = { + required = true + value = "$notification_date$" + } + "-i" = "$notification_icingaweb2url$" + "-l" = { + required = true + value = "$notification_hostname$" + } + "-m" = { + required = true + value = "$notification_matrix_room_id$" + } + "-n" = { + required = true + value = "$notification_hostdisplayname$" + } + "-o" = { + required = true + value = "$notification_hostoutput$" + } + "-s" = { + required = true + value = "$notification_hoststate$" + } + "-t" = { + required = true + value = "$notification_type$" + } + "-x" = { + required = true + value = "$notification_matrix_server$" + } + "-y" = { + required = true + value = "$notification_matrix_token$" + } + } + vars.notification_address = "$address$" + vars.notification_address6 = "$address6$" + vars.notification_author = "$notification.author$" + vars.notification_comment = "$notification.comment$" + vars.notification_date = "$icinga.long_date_time$" + vars.notification_hostdisplayname = "$host.display_name$" + vars.notification_hostname = "$host.name$" + vars.notification_hostoutput = "$host.output$" + vars.notification_hoststate = "$host.state$" + vars.notification_type = "$notification.type$" +} + + +object NotificationCommand "matrix-service-notification" { + import "plugin-notification-command" + command = [ SysconfDir + "/icinga2/scripts/matrix-service-notification" ] + arguments += { + "-4" = { + required = true + value = "$notification_address$" + } + "-6" = "$notification_address6$" + "-b" = "$notification_author$" + "-c" = "$notification_comment$" + "-d" = { + required = true + value = "$notification_date$" + } + "-e" = { + required = true + value = "$notification_servicename$" + } + "-i" = "$notification_icingaweb2url$" + "-l" = { + required = true + value = "$notification_hostname$" + } + "-m" = { + required = true + value = "$notification_matrix_room_id$" + } + "-n" = { + required = true + value = "$notification_hostdisplayname$" + } + "-o" = { + required = true + value = "$notification_serviceoutput$" + } + "-s" = { + required = true + value = "$notification_servicestate$" + } + "-t" = { + required = true + value = "$notification_type$" + } + "-u" = { + required = true + value = "$notification_servicedisplayname$" + } + "-x" = { + required = true + value = "$notification_matrix_server$" + } + "-y" = { + required = true + value = "$notification_matrix_token$" + } + } + vars.notification_address = "$address$" + vars.notification_address6 = "$address6$" + vars.notification_author = "$notification.author$" + vars.notification_comment = "$notification.comment$" + vars.notification_date = "$icinga.long_date_time$" + vars.notification_hostdisplayname = "$host.display_name$" + vars.notification_hostname = "$host.name$" + vars.notification_servicedisplayname = "$service.display_name$" + vars.notification_serviceoutput = "$service.output$" + vars.notification_servicestate = "$service.state$" + vars.notification_type = "$notification.type$" + vars.notification_servicename = "$service.name$" +} diff --git a/cfg/services.cfg b/cfg/services.cfg new file mode 100644 index 0000000..c38e52d --- /dev/null +++ b/cfg/services.cfg @@ -0,0 +1,29 @@ +// https://git.dittberner.info/jan/icinga2-matrix-notification +/** + * Example Matrix.org apply rules. + * The "!:matrix.org" needs to be replaced with the room ID + * for example "!SDFfskjfdszhdaslasdkjhdasd:matrix.org". + * Also a Matrix access token is required too. + */ + +apply Notification "Matrix host problems" to Host { + import "matrix-host-notification" + + user_groups = host.vars.notification.matrix.groups + users = host.vars.notification.matrix.users + vars.notification_matrix_server = "https://matrix.org" + vars.notification_matrix_room_id = "!:matrix.org" + // vars.notification_matrix_token = "" + assign where host.vars.notification.matrix +} + +apply Notification "Matrix service problems" to Service { + import "matrix-service-notification" + + user_groups = host.vars.notification.matrix.groups + users = host.vars.notification.matrix.users + vars.notification_matrix_server = "https://matrix.org" + vars.notification_matrix_room_id = "!:matrix.org" + // vars.notification_matrix_token = "" + assign where host.vars.notification.matrix +} diff --git a/cfg/templates.cfg b/cfg/templates.cfg new file mode 100644 index 0000000..cad7d06 --- /dev/null +++ b/cfg/templates.cfg @@ -0,0 +1,36 @@ +// https://git.dittberner.info/jan/icinga2-matrix-notification + +/** + * Provides default settings for Matrix.org service notifications. + */ + +template Notification "matrix-host-notification" { + command = "matrix-host-notification" + + states = [ Up, Down ] + types = [ Problem, Acknowledgement, Recovery, Custom, + FlappingStart, FlappingEnd, + DowntimeStart, DowntimeEnd, DowntimeRemoved ] + vars += { + // notification_icingaweb2url = "https://www.example.com/icingaweb2" + notification_logtosyslog = false + } + // interval = 0s + period = "24x7" +} + +template Notification "matrix-service-notification" { + command = "matrix-service-notification" + + states = [ OK, Warning, Critical, Unknown ] + types = [ Problem, Acknowledgement, Recovery, Custom, + FlappingStart, FlappingEnd, + DowntimeStart, DowntimeEnd, DowntimeRemoved ] + + vars += { + // notification_icingaweb2url = "https://www.example.com/icingaweb2" + notification_logtosyslog = false + } + // interval = 0s + period = "24x7" +}