Mattermost Notification

I checked this command

/usr/lib64/nagios/plugins/icinga2-mattermost/mattermost.py --url https://example.com/hooks/xxxxxxxxxx --channel icinga2 --notificationtype "some-alarm" --hostalias test

And I get a notification

image

I think there is a problem with sending notification here, it seems like the icingaweb can’t send notification. If I try it here manually it does not send any notificition and still write “for this problem was not notification send”. I think somewhere are the notification disabled but I can’t find where?

Hi again.

  1. When you manually sent the notification via icingaweb2, did you enable “force”?
  2. Icingaweb2 -> System -> Monitoring Health -> Feature Commands:
    Are notifications enabled?
  3. Does:
icinga2 object list --type notification

Show your dummy-host1 with the host alert?


Greetings.

  1. yes I did and nothing happened
  2. enabled
  3. the list is way too long so I did it with " | grep dummy " and I get this

image

[root@xxxx~]# icinga2 object list --type notification | grep -A 30 dummy
Object 'dummy-host2!mattermost_host' of type 'Notification':
  % declared in '/etc/icinga2/conf.d/notifications.conf', lines 50:1-50:44
  * __name = "dummy-host2!mattermost_host"
  * command = "mattermost_host"
    % = modified in '/etc/icinga2/conf.d/notifications.conf', lines 52:3-52:29
  * command_endpoint = ""
  * host_name = "dummy-host2"
    % = modified in '/etc/icinga2/conf.d/notifications.conf', lines 50:1-50:44
  * interval = 1800
  * name = "mattermost_host"
  * package = "_etc"
    % = modified in '/etc/icinga2/conf.d/notifications.conf', lines 50:1-50:44
  * period = "24x7"
    % = modified in '/etc/icinga2/conf.d/notifications.conf', lines 54:3-54:17
  * service_name = ""
  * source_location
    * first_column = 1
    * first_line = 50
    * last_column = 44
    * last_line = 50
    * path = "/etc/icinga2/conf.d/notifications.conf"
  * states = [ "Up", "Down" ]
    % = modified in '/etc/icinga2/conf.d/notifications.conf', lines 56:3-56:23
  * templates = [ "mattermost_host" ]
    % = modified in '/etc/icinga2/conf.d/notifications.conf', lines 50:1-50:44
  * times = null
  * type = "Notification"
  * types = [ "Problem", "Acknowledgement", "Recovery", "Custom", "FlappingStart", "FlappingEnd", "DowntimeStart", "DowntimeEnd", "DowntimeRemoved" ]
    % = modified in '/etc/icinga2/conf.d/notifications.conf', lines 55:3-55:129
  * user_groups = null
  * users = [ "mattermost" ]
    % = modified in '/etc/icinga2/conf.d/notifications.conf', lines 53:3-53:26
  * vars = null
  * zone = ""

Did you execute the CLI command as root or icinga/nagios user (depending on your OS) ?

I am running the command
./mattermost.py --url https://mattermost.xxxxxxxxxx.com/hooks/xxxxxxxxxxxx --notificationtype CUSTOM --hostalias myexample.com
as root
in the folder
/usr/lib64/nagios/plugins/icinga2-mattermost

and my OS is linux

does the command work if it’s the icinga/nagios user? i’ve had problems with check scripts not being executable by nagios user in the past.

I can’t change the user with su icinga ? I tried but I get an error. This seems not the problem because on my second icinga istance it works fine with the root user. I can’t even send a notification manually when I am on the icinga webinterface. Or how do I run a command as a different user?

without knowing what the error is, here’s some things to look at:

  • check the permissions on the icinga2-mattermost script
  • is icinga2 running as icinga user or nagios user (even if running as root you may need to do sudo su - icinga
  • check the path in the icinga constants.conf
  • check notifications.conf for path and command

I checked

  • the script has ( -rwxr-xr-x / 0755 ) permission
    and the folder has the same ( drwxr-xr-x )
    like all other plugins.

  •  su - icinga
    

Last login: Wed Jan 27 12:11:55 CET 2021 on pts/0
This account is currently not available.

but this shouldnt be the problem because i have the same issue on my second icinga and there is the mattermost plugin working

  • the path in constants.conf is /usr/lib64/nagios/plugins which is the right one, alls plugins are stored here

  • regarding the notifcation.conf I dont know where I should put a path in here? and the command is also right

1 Like

Hi again.

Since the “icinga” user does not have a login shell, you can not directly login.
As a workaround, you can use sudo here:

sudo -u icinga /path/to/the/script   # Directly executing the script
# alternatively to get a shell: sudo -u icinga bash 
# or whatever shell instead of bash (/bin/sh, ...)

Assuming that you are using RedHat/CentOS (because the user is “icinga”):
Did you check for SELinux related problems?


Greetings

1 Like

I just checked I can run the command as icinga user manually and it works, I get a notification in my mattermost channel. I will check for SELinux problems and let you know what I find.

Can’t find anything in SELinux. What could be related to this problem.

Hi.

Maybe this helps:
link

SELinux was often mentioned in this forum, so maybe a search gives you further hints.


Greetings.

Okay Thank you. I checked that SELinux is disabled could this cause the Problem?

Hi again.

If SELinux is disabled, this does not cause the problem.

Sorry, I am out of ideas. At this point, it may be helpful to check on the Mattermost side (if possible) what is happening when you manually send a notification from icingaweb2.

  • Is the request even arriving?
  • What’s happening?

Greetings.

okay thank you. I will check what I can do with mattermost. If I run the command the notificaiton arrives in mattermost. Its just confusing because I cant send a manual notification from icinga web interface.

Hey there :slight_smile:
I would like to ask you to mark an answer as the solution, if it resolves your topic.

okay I will but unfortunately there is no solution