Skip to content

Bash script which allows to send messages to Slack via Incoming Webhooks app. You can use it to send messages directly from console or from Zabbix 3.x+

Notifications You must be signed in to change notification settings

yuri-karpovich/slack-alert-from-bash-and-zabbix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slack-alert-from-bash-and-zabbix

Bash script which allows to send messages to Slack via Incoming Webhooks app. You can use it to send messages directly from console or from Zabbix.

Preconditions

  1. Zabbix version >= 3.X
  2. curl is installed in your system: which curl

How to use

./slack.sh --webhook https://hooks.slack.com/services/XXX/YYYY/ZZZZ --message "Message" --severity 3 --title 'Title' --description 'Some Description' --username 'James Bond'

MessagePreview1

Parameters list: --webhook (-w) Web-hook URL --message (-m) Message text (optional) --severity (-s) Numerical trigger severity. Possible values: 0 - Not classified, 1 - Information, 2 - Warning, 3 - Average, 4 - High, 5 - Disaster (optional) --title (-t) Message title (optional) --description (-d) Message description (optional) --username (-u) Username to be displayed (optional) --color (-c) Message color: blue, yellow, orange, light_red, red, green (optional)

How to configure Zabbix

  1. Install Incoming Webhooks app to your channel in Slack
    1. After installation you will get a webhook URL. You will need it later
  2. Deploy slack.sh script to AlertScripts folder

    If you are using Docker you can install Zabbix from Docker Image: https://hub.docker.com/r/spoonest/zabbix-appliance-with-slack/

    1. By default the folder path is /usr/local/share/zabbix/alertscripts
    2. Make sure the script is executable: chmod +x /path/to/slack.sh
  3. Create new Media Type in Zabbix: Administration > Media Types
    • Name: Slack
    • Type: Script
    • Script name: slack.sh
    • Script parameters:
      • -w
      • {ALERT.SENDTO}
      • --title
      • {ALERT.SUBJECT}
      • --description
      • {ALERT.MESSAGE}
      • --username
      • Zabbix
    • Enabled: true media_type_1
  4. Create new User Group in Zabbix: Administration > User groups
    • User Group Tab:
      • Group name: Read-Only Group
      • Enabled: true user_group_1
    • Permissions Tab:
      • Select Host Groups and specify Read permission fot them. user_group_2
  5. Create new User in Zabbix: Administration > Users

    I prefer to create 2 users: slack_critical - for important notifications from Zabbix (Average, High, Disaster), and slack_not_important - for others (Not classified, Information, Warning).

    • User tab:
      • Alias: slack_critical
      • Name: Slack Critical
      • Groups: Read-Only Group
    • Media Tab > Add:
      • Type: Slack
      • Send to: Your webhook url from Step 1
      • Enable: true user_media
  6. Create new Action in Zabbix: Configuration > Actions
    • Action tab:

      • Name: Report problems to Slack (Disaster, High, Average)
      • Conditions:
        • Trigger severity = Disaster
        • Trigger severity = High
        • Trigger severity = Average
      • Enabled: true action_1
    • Operations Tab:

      • Default subject: {TRIGGER.SEVERITY}: {HOSTNAME}: {TRIGGER.NAME}
      • Default message:

        Problem started at {EVENT.TIME} on {EVENT.DATE} Problem name: {TRIGGER.NAME} Host: {HOST.NAME} ({IPADDRESS}) Severity: {TRIGGER.SEVERITY}

        Original problem ID: {EVENT.ID} {TRIGGER.URL}

      • Operations:
        • Send to Users: slack_critical action_2
    • Recovery Operations Tab:

      • Default subject: Resolved: {HOSTNAME}: {TRIGGER.NAME}
      • Default message:

        Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE} Problem name: {TRIGGER.NAME} Host: {HOST.NAME} ({IPADDRESS}) Severity: {TRIGGER.SEVERITY}

        Original problem ID: {EVENT.ID} {TRIGGER.URL}

      • Operations:
        • Send to Users: slack_critical action_3
    • Acknowledgement Operations Tab:

      • Default subject: Acknowledged: {HOSTNAME}: {TRIGGER.NAME}
      • Default message:

        {USER.FULLNAME} acknowledged problem at {ACK.DATE} {ACK.TIME} with the following message: {ACK.MESSAGE}

        Current problem status is {EVENT.STATUS}

      • Operations:
        • Send to Users: slack_critical action_4
  7. Done! You will receive notifications from Zabbix to Slack message1

About

Bash script which allows to send messages to Slack via Incoming Webhooks app. You can use it to send messages directly from console or from Zabbix 3.x+

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages