Skip to content
Snippets Groups Projects
Commit 61a26c77 authored by void's avatar void
Browse files

icinga matrix notification

parent 23d51aff
No related branches found
No related tags found
No related merge requests found
...@@ -189,9 +189,7 @@ ...@@ -189,9 +189,7 @@
basedir: /srv/icinga, basedir: /srv/icinga,
domain: icinga.warpzone.ms, domain: icinga.warpzone.ms,
api_port: 5665, api_port: 5665,
mysql_port: 33306, mysql_port: 33306
matrix_notification_domain: "matrix.warpzone.ms",
matrix_notification_room: "!iYefxbySFEfFQfUGEK:matrix.warpzone.ms"
} }
- { - {
role: webserver/docker_hackmd, tags: hackmd, role: webserver/docker_hackmd, tags: hackmd,
......
...@@ -13,9 +13,10 @@ RUN apt-get update \ ...@@ -13,9 +13,10 @@ RUN apt-get update \
libnet-dns-perl \ libnet-dns-perl \
libnet-ip-perl \ libnet-ip-perl \
perl \ perl \
python3-requests \
python3 \ python3 \
python3-paho-mqtt \ python3-pip \
python3-requests \
virtualenv \
&& apt-get autoremove -y \ && apt-get autoremove -y \
&& apt-get clean \ && apt-get clean \
&& rm -rf /tmp/* /var/lib/apt/lists/* /var/cache/debconf/*-old && rm -rf /tmp/* /var/lib/apt/lists/* /var/cache/debconf/*-old
...@@ -49,8 +50,16 @@ RUN cd /opt/ \ ...@@ -49,8 +50,16 @@ RUN cd /opt/ \
&& cd /opt/check_metric_value/ \ && cd /opt/check_metric_value/ \
&& git checkout b94d3c3e78497a05e3b4520d33421f37e4d77985 && git checkout b94d3c3e78497a05e3b4520d33421f37e4d77985
# icinga2-matrix_notification - commit from 15.04.2012 # icinga2-matrix-bot - commit from 10.06.2018
# create a symlink to emulate virtualenv
# patch matrix-service-notification.sh
RUN cd /opt/ \ RUN cd /opt/ \
&& git clone https://github.com/linuxmail/icinga2-matrix_notification \ && git clone https://github.com/symptog/icinga2-matrix-bot.git \
&& cd /opt/icinga2-matrix_notification/ \ && cd /opt/icinga2-matrix-bot/ \
&& git checkout 99d2174a3b00e9a88648fe58bcd975368f69837d && git checkout 86d03ed8884950eb2b883a9a94ecf93460b8e0bb \
&& pip install -r requirements.txt \
&& mkdir /opt/icinga2-matrix-bot/.venv \
&& mkdir /opt/icinga2-matrix-bot/.venv/bin \
&& ln -s /usr/bin/python3 /opt/icinga2-matrix-bot/.venv/bin/python \
&& sed -i 's/matrix-host-state/matrix-service-state/' icinga2/matrix-service-notification.sh
\ No newline at end of file
...@@ -80,131 +80,49 @@ object CheckCommand "check_metric_value" { ...@@ -80,131 +80,49 @@ object CheckCommand "check_metric_value" {
*/ */
object NotificationCommand "matrix-host-notification" { object NotificationCommand "matrix-host-notification" {
import "plugin-notification-command" import "plugin-notification-command"
command = [ "/opt/icinga2-matrix_notification/scripts/matrix-host-notification.sh" ]
arguments += { command = [ "/opt/icinga2-matrix-bot/icinga2/matrix-host-notification.sh" ]
"-4" = "$notification_address$"
"-6" = "$notification_address6$" env = {
"-b" = "$notification_author$" "NOTIFICATIONTYPE" = "$notification.type$"
"-c" = "$notification_comment$" "HOSTALIAS" = "$host.display_name$",
"-d" = { "HOSTADDRESS" = "$address$",
required = true "HOSTNAME" = "$host.name$",
value = "$notification_date$" "HOSTSTATE" = "$host.state$",
} "LONGDATETIME" = "$icinga.long_date_time$",
"-i" = "$notification_icingaweb2url$" "HOSTOUTPUT" = "$host.output$",
"-l" = { "NOTIFICATIONAUTHORNAME" = "$notification.author$",
required = true "NOTIFICATIONCOMMENT" = "$notification.comment$",
value = "$notification_hostname$" "HOSTDISPLAYNAME" = "$host.display_name$",
} "ICINGA_WEBURL" = "$notification_icingaweb2url$",
"-m" = { "MATRIX_SERVER" = "$user.vars.matrix.server$",
required = true "MATRIX_TOKEN" = "$user.vars.matrix.token$",
value = "$notification_matrix_room_id$" "MATRIX_CHANNEL" = "$user.vars.matrix.channel$",
} }
"-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" { object NotificationCommand "matrix-service-notification" {
import "plugin-notification-command" import "plugin-notification-command"
command = [ "/opt/icinga2-matrix_notification/scripts/matrix-service-notification.sh" ]
arguments += { command = [ "/opt/icinga2-matrix-bot/icinga2/matrix-service-notification.sh" ]
"-4" = {
required = true env = {
value = "$notification_address$" "NOTIFICATIONTYPE" = "$notification.type$"
} "SERVICEDESC" = "$service.name$"
"-6" = "$notification_address6$" "HOSTALIAS" = "$host.display_name$",
"-b" = "$notification_author$" "HOSTNAME" = "$host.name$",
"-c" = "$notification_comment$" "HOSTADDRESS" = "$address$",
"-d" = { "SERVICESTATE" = "$service.state$",
required = true "LONGDATETIME" = "$icinga.long_date_time$",
value = "$notification_date$" "SERVICEOUTPUT" = "$service.output$",
} "NOTIFICATIONAUTHORNAME" = "$notification.author$",
"-e" = { "NOTIFICATIONCOMMENT" = "$notification.comment$",
required = true "HOSTDISPLAYNAME" = "$host.display_name$",
value = "$notification_servicename$" "SERVICEDISPLAYNAME" = "$service.display_name$",
} "ICINGA_WEBURL" = "$notification_icingaweb2url$",
"-i" = "$notification_icingaweb2url$" "MATRIX_SERVER" = "$user.vars.matrix.server$",
"-l" = { "MATRIX_TOKEN" = "$user.vars.matrix.token$",
required = true "MATRIX_CHANNEL" = "$user.vars.matrix.channel$",
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$"
} }
// https://github.com/linuxmail/icinga2-matrix_notification apply Notification "matrix" to Host {
/** import "matrix-host-notification"
* Example Matrix.org apply rules.
* The "!<id>: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 { users = [ "matrix" ]
import "matrix-host-notification"
user_groups = [ "icingaadmins" ] interval = 4h
vars.notification_matrix_server = "https://{{ matrix_notification_domain }}" assign where host.address
vars.notification_matrix_room_id = "{{ matrix_notification_room }}"
vars.notification_matrix_token = "{{ matrix_notification_access_token }}"
# Assign to all hosts
assign where host.address
} }
apply Notification "Matrix service problems" to Service {
import "matrix-service-notification"
user_groups = [ "icingaadmins" ] apply Notification "matrix" to Service {
import "matrix-service-notification"
users = [ "matrix" ]
vars.notification_matrix_server = "https://{{ matrix_notification_domain }}" interval = 4h
vars.notification_matrix_room_id = "{{ matrix_notification_room }}"
vars.notification_matrix_token = "{{ matrix_notification_access_token }}"
# Assign to all services assign where service.name
assign where service.name
} }
...@@ -87,32 +87,24 @@ template Notification "mail-service-notification" { ...@@ -87,32 +87,24 @@ template Notification "mail-service-notification" {
*/ */
template Notification "matrix-host-notification" { template Notification "matrix-host-notification" {
command = "matrix-host-notification" command = "matrix-host-notification"
states = [ Up, Down ] states = [ Up, Down ]
types = [ Problem, Acknowledgement, Recovery, Custom, types = [ Problem, Acknowledgement, Custom, FlappingStart, FlappingEnd ]
FlappingStart, FlappingEnd,
DowntimeStart, DowntimeEnd, DowntimeRemoved ]
vars += {
// notification_icingaweb2url = "https://{{ domain }}/icingaweb2"
notification_logtosyslog = false
}
// interval = 0s
period = "24x7" period = "24x7"
vars += {
notification_icingaweb2url = "https://{{ domain }}/icingaweb2"
}
} }
template Notification "matrix-service-notification" { template Notification "matrix-service-notification" {
command = "matrix-service-notification" command = "matrix-service-notification"
states = [ OK, Warning, Critical, Unknown ]
types = [ Problem, Acknowledgement, Recovery, Custom,
FlappingStart, FlappingEnd,
DowntimeStart, DowntimeEnd, DowntimeRemoved ]
vars += { states = [ OK, Critical, Unknown ]
// notification_icingaweb2url = "https://{{ domain }}/icingaweb2" types = [ Problem, Acknowledgement, Custom, FlappingStart, FlappingEnd ]
notification_logtosyslog = false
}
// interval = 0s
period = "24x7" period = "24x7"
vars += {
notification_icingaweb2url = "https://{{ domain }}/icingaweb2"
}
} }
...@@ -3,3 +3,18 @@ object UserGroup "icingaadmins" { ...@@ -3,3 +3,18 @@ object UserGroup "icingaadmins" {
display_name = "Icinga 2 Admin Group" display_name = "Icinga 2 Admin Group"
} }
object User "matrix" {
import "generic-user"
display_name = "Matrix User"
vars.matrix = {
token = "{{ matrix_notification_access_token }}"
channel = "!iYefxbySFEfFQfUGEK:matrix.warpzone.ms"
server = "https://matrix.warpzone.ms"
}
}
object UserGroup "matrix" {
display_name = "Matrix Group"
assign where user.vars.matrix
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment