GithubHelp home page GithubHelp logo

k2works / zabbix-mattermost-alertscript Goto Github PK

View Code? Open in Web Editor NEW

This project forked from muokata/zabbix-mattermost-alertscript

0.0 2.0 0.0 27 KB

Zabbix AlertScript for Mattermost chat

License: MIT License

Shell 100.00%

zabbix-mattermost-alertscript's Introduction

Zabbix Mattermost AlertScript

About

This is simply a Bash script that uses the custom alert script functionality within Zabbix along with the incoming web-hook feature of Mattermost.

Versions

This works with Zabbix 1.8.x or greater - including 2.2, 2.4 and 3.x!

Huge thanks and appreciation to:

Installation

The script itself

This mattermost.sh script needs to be placed in the AlertScriptsPath directory that is specified within the Zabbix servers' configuration file (zabbix_server.conf) and must be executable by the user running the zabbix_server binary (usually "zabbix") on the Zabbix server before restarting the Zabbix server software:

[root@zabbix ~]# grep AlertScriptsPath /etc/zabbix/zabbix_server.conf
### Option: AlertScriptsPath
AlertScriptsPath=/usr/lib/zabbix/alertscripts

[root@zabbix ~]# ls -lh /usr/lib/zabbix/alertscriptsmattermost.sh
-rwxr-xr-x 1 root root 1.6K Nov 19 20:04 /usr/lib/zabbix/alertscripts/mattermost.sh

Configuration

mattermost web-hook

An incoming web-hook integration must be created within your Mattermost account which can be done at https:///chattr/integrations/incoming_webhooks:

the incoming web-hook URL would be something like:

https://<your mattermost uri>/hooks/ere5h9gfbbbk8gdxsdsduwuicsd

Make sure that you specify your correct Mattermost incoming web-hook URL and feel free to edit the sender user name at the top of the script:

# Mattermost incoming web-hook URL and user name
url='https://<your mattermost uri>/hooks/ere5h9gfbbbk8gdxsdsduwuicsd'
username='zabbix'

Within the Zabbix web interface

When logged in to the Zabbix servers web interface with super-administrator privileges, navigate to the "Administration" tab, access the "Media Types" sub-tab, and click the "Create media type" button.

You need to create a media type as follows:

  • Name: Mattermost
  • Type: Script
  • Script name: mattermost.sh

...and ensure that it is enabled before clicking "Save".

However, on Zabbix 3.x and greater, media types are configured slightly differently and you must explicity define the parameters sent to the mattermost.sh script. On Zabbix 3.x, three script parameters should be added as follows:

  • {ALERT.SENDTO}
  • {ALERT.SUBJECT}
  • {ALERT.MESSAGE}

Then, create a "Mattermost" user on the "Users" sub-tab of the "Administration" tab within the Zabbix servers web interface and specify this users "Media" as the "Mattermost" media type that was just created with the Mattermost.com channel ("#alerts" in the example) or user name (such as "@ericoc") that you want messages to go to in the "Send to" field as seen below:

Finally, an action can then be created on the "Actions" sub-tab of the "Configuration" tab within the Zabbix servers web interface to notify the Zabbix "Mattermost" user ensuring that the "Subject" is "PROBLEM" for "Default message" and "RECOVERY" should you choose to send a "Recovery message".

Keeping the messages short is probably a good idea; use something such as the following for the contents of each message:

{TRIGGER.NAME} - {HOSTNAME} ({IPADDRESS})

Additionally, you can have multiple different Zabbix users each with "Mattermost" media types that notify unique Mattermost users or channels upon different triggered Zabbix actions.

Testing

Assuming that you have set a valid Mattermost web-hook URL within your "mattermost.sh" file, you can execute the script manually (as opposed to via Zabbix) from Bash on a terminal:

$ bash mattermost.sh '#alerts' PROBLEM 'Oh no! Something is wrong!'

Alerting a specific user name results in the message actually coming from the "mattermostbot" user using a sort-of "spoofed" user name within the message. A channel alert is sent as you would normally expect from whatever user name you specify in "mattermost.sh":

More Information

zabbix-mattermost-alertscript's People

Contributors

ericoc avatar muokata avatar hiromu avatar

Watchers

James Cloos avatar Katuyuki Kakigi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.