├── .github ├── CODEOWNERS └── FUNDING.yml ├── .gitignore ├── res ├── avatar.png ├── screenshot.png └── rocketchat-uptimerobot.png ├── CHANGELOG.md ├── payloads ├── up.json └── down.json ├── .editorconfig ├── LICENSE ├── src └── uptimerobot-incoming.js └── README.md /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @crazy-max 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Intellij 2 | /.idea 3 | /*.iml 4 | 5 | # Dev 6 | /.dev 7 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: crazy-max 2 | custom: https://www.paypal.me/crazyws 3 | -------------------------------------------------------------------------------- /res/avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazy-max/rocketchat-uptimerobot/HEAD/res/avatar.png -------------------------------------------------------------------------------- /res/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazy-max/rocketchat-uptimerobot/HEAD/res/screenshot.png -------------------------------------------------------------------------------- /res/rocketchat-uptimerobot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crazy-max/rocketchat-uptimerobot/HEAD/res/rocketchat-uptimerobot.png -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.2 (2018/10/14) 4 | 5 | * Username and avatar are embedded 6 | * Review post content 7 | 8 | ## 0.1 (2017/11/29) 9 | 10 | * Initial version 11 | -------------------------------------------------------------------------------- /payloads/up.json: -------------------------------------------------------------------------------- 1 | { 2 | "monitorID": "1234567890", 3 | "monitorURL": "neard.io", 4 | "monitorFriendlyName": "HTTP", 5 | "alertType": "2", 6 | "alertTypeFriendlyName": "Up", 7 | "alertDetails": "HTTP 200 - OK", 8 | "alertDuration": "169" 9 | } 10 | -------------------------------------------------------------------------------- /payloads/down.json: -------------------------------------------------------------------------------- 1 | { 2 | "monitorID": "1234567890", 3 | "monitorURL": "neard.io", 4 | "monitorFriendlyName": "HTTP", 5 | "alertType": "1", 6 | "alertTypeFriendlyName": "Down", 7 | "alertDetails": "HTTP 404 - Not Found", 8 | "alertDuration": "*alertDuration*" 9 | } 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs. 2 | # More information at http://editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | indent_size = 2 9 | indent_style = space 10 | end_of_line = lf 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2018 CrazyMax 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 | -------------------------------------------------------------------------------- /src/uptimerobot-incoming.js: -------------------------------------------------------------------------------- 1 | /** 2 | * uptimerobot-incoming.js 3 | * Add Uptime Robot notifications via a new WebHook in Rocket.Chat 4 | * @license MIT 5 | * @version 0.2 6 | * @author CrazyMax, https://github.com/crazy-max 7 | * @updated 2018-10-14 8 | * @link https://github.com/crazy-max/rocketchat-uptimerobot 9 | */ 10 | 11 | /* globals console, _, s */ 12 | 13 | const USERNAME = 'Uptime Robot'; 14 | const AVATAR_URL = 'https://raw.githubusercontent.com/crazy-max/rocketchat-uptimerobot/master/res/avatar.png'; 15 | 16 | const convertAlertDuration = (seconds) => { 17 | let days = Math.floor(seconds / (3600 * 24)); 18 | seconds -= days * 3600 * 24; 19 | let hours = Math.floor(seconds / 3600); 20 | seconds -= hours * 3600; 21 | let minutes = Math.floor(seconds / 60); 22 | seconds -= minutes * 60; 23 | 24 | let result = ""; 25 | if (days > 0) { 26 | result += " " + days + " days"; 27 | } 28 | if (hours > 0) { 29 | result += " " + hours + " hours"; 30 | } 31 | if (minutes > 0) { 32 | result += " " + minutes + " minutes"; 33 | } 34 | if (seconds > 0) { 35 | result += " " + seconds + " seconds"; 36 | } 37 | 38 | return result; 39 | }; 40 | 41 | /* exported Script */ 42 | class Script { 43 | /** 44 | * @params {object} request 45 | */ 46 | process_incoming_request({ request }) { 47 | let data = request.content; 48 | let attachmentColor = `#A63636`; 49 | let statusText = `DOWN`; 50 | let isUp = data.alertType === `2`; 51 | if (isUp) { 52 | attachmentColor = `#36A64F`; 53 | statusText = `UP`; 54 | } 55 | 56 | let attachmentText = `[${data.monitorFriendlyName}](https://uptimerobot.com/dashboard.php#${data.monitorID}) is ${statusText} (${data.monitorURL}).\n`; 57 | if (isUp) { 58 | attachmentText += `It was down for ${convertAlertDuration(data.alertDuration)}`; 59 | } else { 60 | attachmentText += `Reason: ${data.alertDetails}`; 61 | } 62 | 63 | return { 64 | content:{ 65 | username: USERNAME, 66 | icon_url: AVATAR_URL, 67 | text: `Monitor [${data.monitorFriendlyName}](https://uptimerobot.com/dashboard.php#${data.monitorID}) status has changed.`, 68 | attachments: [{ 69 | text: attachmentText, 70 | color: attachmentColor 71 | }] 72 | } 73 | }; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | Become a sponsor 5 | Donate Paypal 6 |

7 | 8 | ## :warning: Abandoned project 9 | 10 | This project is not maintained anymore and is abandoned. Feel free to fork and make your own changes if needed. 11 | 12 | Thanks to everyone for their valuable feedback and contributions. 13 | 14 | ## About 15 | 16 | Add [Uptime Robot](https://uptimerobot.com) notifications via a new WebHook in Rocket.Chat. 17 | 18 | ## Receive alerts 19 | 20 | - Create a new **Incoming WebHook** in Administration > Integrations 21 | - Select the channel where you will receive the alerts. You may wish to create a dedicated channel for your notifications. 22 | - Select an account from which the alerts will be posted. You may wish to create a dedicated account just for notifications. 23 | - Set the "Enable Scripts" option to `True`. 24 | - Copy content of [uptimerobot-incoming.js](src/uptimerobot-incoming.js) in Script field. 25 | - Save the integration. This will generate a webhook URL and secret for you. 26 | - Go to [Uptime Robot -> MySettings](https://uptimerobot.com/dashboard.php#mySettings), add a **new Alert Contact** and select type **Web-Hook** 27 | - Add the Rocket.Chat webhook URL generated in **URL to notify** field and add a **?** at the end of the URL. 28 | - Paste the following in the **POST Value (JSON Format)** field : 29 | 30 | ```json 31 | { 32 | "monitorID": "*monitorID*", 33 | "monitorURL": "*monitorURL*", 34 | "monitorFriendlyName": "*monitorFriendlyName*", 35 | "alertType": "*alertType*", 36 | "alertTypeFriendlyName": "*alertTypeFriendlyName*", 37 | "alertDetails": "*alertDetails*", 38 | "alertDuration": "*alertDuration*" 39 | } 40 | ``` 41 | 42 | - And check **Send as JSON (application/json)** 43 | 44 | ![Screenshot of messages generated by Uptime Robot integration script](res/screenshot.png) 45 | 46 | *Note:* If status is UP, message color is green otherwise it is red. 47 | 48 | ## How can I help ? 49 | 50 | All kinds of contributions are welcome :raised_hands:! The most basic way to show your support is to star :star2: the project, or to raise issues :speech_balloon: You can also support this project by [**becoming a sponsor on GitHub**](https://github.com/sponsors/crazy-max) :clap: or by making a [Paypal donation](https://www.paypal.me/crazyws) to ensure this journey continues indefinitely! :rocket: 51 | 52 | Thanks again for your support, it is much appreciated! :pray: 53 | 54 | ## License 55 | 56 | MIT. See `LICENSE` for more details. 57 | --------------------------------------------------------------------------------