├── .gitignore ├── images ├── nagios_128.png └── screenshot.png ├── docker-compose.yml ├── Makefile ├── LICENSE ├── README.md └── rocketchat.py /.gitignore: -------------------------------------------------------------------------------- 1 | url.txt 2 | -------------------------------------------------------------------------------- /images/nagios_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrefreitas/rocketchat-nagios/HEAD/images/nagios_128.png -------------------------------------------------------------------------------- /images/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrefreitas/rocketchat-nagios/HEAD/images/screenshot.png -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | mongo: 4 | image: mongo 5 | 6 | rocketchat: 7 | image: rocketchat/rocket.chat 8 | links: 9 | - mongo 10 | ports: 11 | - 3000 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: test-unknown test-ok test-critical test-warning 2 | 3 | URL=$(shell cat url.txt) 4 | 5 | test-unknown: 6 | ./rocketchat.py \ 7 | --url $(URL) \ 8 | --hostalias alfredo \ 9 | --notificationtype RECOVERY \ 10 | --servicestate UNKNOWN \ 11 | --serviceoutput "PING 100% LOSS" \ 12 | --servicedesc counter 13 | 14 | test-ok: 15 | ./rocketchat.py \ 16 | --url $(URL) \ 17 | --hostalias alfredo \ 18 | --notificationtype RECOVERY \ 19 | --servicestate OK \ 20 | --serviceoutput "PING 100% LOSS" \ 21 | --servicedesc counter 22 | 23 | test-critical: 24 | ./rocketchat.py \ 25 | --url $(URL) \ 26 | --hostalias alfredo \ 27 | --notificationtype RECOVERY \ 28 | --servicestate CRITICAL \ 29 | --serviceoutput "PING 100% LOSS" \ 30 | --servicedesc counter 31 | 32 | test-warning: 33 | ./rocketchat.py \ 34 | --url $(URL) \ 35 | --hostalias alfredo \ 36 | --notificationtype RECOVERY \ 37 | --servicestate WARNING \ 38 | --serviceoutput "PING 100% LOSS" \ 39 | --servicedesc counter 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 André Freitas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rocketchat Nagios Plugin 2 | Send notifications to a Rocketchat channel from Nagios. 3 | 4 |  5 | 6 | # Usage 7 | Assuming you are using Nagios 4, the steps are: 8 | 9 | 1. Copy _rocketchat.py_ to /usr/local/nagios/libexec. 10 | 2. Create the notification command __(replace WEBHOOK_URL)__: 11 | 12 | define command { 13 | command_name notify-service-by-rocketchat 14 | command_line /usr/local/nagios/libexec/rocketchat.py --url WEBHOOK_URL --hostalias "$HOSTNAME$" --servicedesc "$SERVICEDESC$" --servicestate "$SERVICESTATE$" --serviceoutput "$SERVICEOUTPUT$" 15 | } 16 | 17 | define command { 18 | command_name notify-host-by-rocketchat 19 | command_line /usr/local/nagios/libexec/rocketchat.py --url WEBHOOK_URL --hostalias "$HOSTNAME$" --hoststate "$HOSTSTATE$" --hostoutput "$HOSTOUTPUT$" 20 | } 21 | 22 | You can also specify a Nagios URL parameter in order to get a valid URL to your alert in the Rocket Chat message __(replace NAGIOS_URL)__: 23 | 24 | define command { 25 | command_name notify-service-by-rocketchat 26 | command_line /usr/local/nagios/libexec/rocketchat.py --url WEBHOOK_URL --hostalias "$HOSTNAME$" --servicedesc "$SERVICEDESC$" --servicestate "$SERVICESTATE$" --serviceoutput "$SERVICEOUTPUT$" --nagiosurl "NAGIOS_URL" 27 | } 28 | 29 | 3. Create the contact: 30 | 31 | define contact { 32 | contact_name rocketchat 33 | alias Rocketchat 34 | service_notification_period 24x7 35 | host_notification_period 24x7 36 | service_notification_options w,u,c,r 37 | host_notification_options d,r 38 | service_notification_commands notify-service-by-rocketchat 39 | host_notification_commands notify-host-by-rocketchat 40 | } 41 | 42 | 4. Add the contact to a contact group: 43 | 44 | 45 | define contactgroup{ 46 | contactgroup_name network-admins 47 | alias Network Administrators 48 | members email, rocketchat 49 | } 50 | 51 | # Contributing 52 | 1. Launch a development instance of Rocket with Docker: 53 | 54 | docker-compose up -d 55 | 56 | 57 | 2. Create a new user and channel by accessing Rocket Chat in your browser. 58 | 59 | 3. Create a new channel called _nagios_. 60 | 61 | 4. Create a new incoming webhook integration for that channel. 62 | 63 | 5. Create a file url.txt with the complete url of the webhook: 64 | 65 | http://192.168.99.100:32769/hooks/jyfgPbsat6cKYxXWS/rocket.cat/O1%2B5u6L2OzvJJYyH6wcfEYifcbbUvoOVsP37Zd%2Fc3b0%3D 66 | 67 | 6. Test a notification: 68 | 69 | make test-ok test-critical test-unknown test-warning 70 | -------------------------------------------------------------------------------- /rocketchat.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # Copyright (c) 2015 Andre Freitas