Skip to content

Commit

Permalink
Add Rocket.Chat support
Browse files Browse the repository at this point in the history
  • Loading branch information
nsano-rururu committed Jun 9, 2021
1 parent 4f63a29 commit e3aa072
Show file tree
Hide file tree
Showing 5 changed files with 263 additions and 14 deletions.
180 changes: 168 additions & 12 deletions src/components/config/alert/ConfigAlert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@
<el-checkbox id="destinationDatadog" label="datadog" border>
Datadog
</el-checkbox>
<el-checkbox id="destinationRocketChat" label="rocketchat" border>
Rocket.Chat
</el-checkbox>
</el-checkbox-group>
</el-form-item>

Expand All @@ -162,7 +165,8 @@
alert.includes('telegram') || alert.includes('jira') || alert.includes('mattermost') ||
alert.includes('sns') || alert.includes('ses') || alert.includes('pagertree') || alert.includes('gitter') ||
alert.includes('googlechat') || alert.includes('chatwork') || alert.includes('discord') ||
alert.includes('hivealerter') || alert.includes('alerta') || alert.includes('datadog')">
alert.includes('hivealerter') || alert.includes('alerta') || alert.includes('datadog') ||
alert.includes('rocketchat')">
<template slot="label">
<icon :icon="['fa', 'bell']" size="1x" /> Alert
</template>
Expand Down Expand Up @@ -1537,6 +1541,63 @@
<label>Datadog application key.</label>
</el-form-item>
</el-tab-pane>

<el-tab-pane v-if="alert.includes('rocketchat')">
<template slot="label">
<icon :icon="['fab', 'rocketchat']" size="1x" /> Rocket.Chat
</template>
<el-form-item label="Channel or username" prop="rocketChatChannelOverride" required>
<el-input id="rocketChatChannelOverride" v-model="rocketChatChannelOverride" :disabled="viewOnly" />
<label>
The @username or #channel to send the alert. Tip: Create new channels
for your alerts, to have fine-grained control of Slack notifications.
</label>
</el-form-item>

<praeco-form-item label="Post as" prop="rocketChatUsernameOverride" required>
<el-input id="rocketChatUsernameOverride" v-model="rocketChatUsernameOverride" :disabled="viewOnly" />
<label>This is the username that will appear in Slack for the alert</label>
</praeco-form-item>

<praeco-form-item
v-if="!(viewOnly && !rocketChatEmojiOverride)"
:class="{ 'disabled': viewOnly }"
label="Icon"
prop="rocketChatEmojiOverride">
<picker
:emoji="rocketChatEmojiOverride || 'arrow_up'"
:title="rocketChatEmojiOverride || 'Pick your icon...'"
color="#189acc"
@select="addEmoji" />
</praeco-form-item>

<el-form-item label="Message color" prop="rocketChatMsgColor" required>
<el-radio-group v-model="rocketChatMsgColor" :disabled="viewOnly">
<el-radio id="rocketChatMsgColorDanger" label="danger" border class="rocketChat-danger">
Danger
</el-radio>
<el-radio id="rocketChatMsgColorWarning" label="warning" border class="rocketChat-warning">
Warning
</el-radio>
<el-radio id="rocketChatMsgColorGood" label="good" border class="rocketChat-good">
Good
</el-radio>
</el-radio-group>
</el-form-item>

<el-form-item label="Text String" prop="rocketChatTextString">
<el-input id="rocketChatTextString" v-model="rocketChatTextString" :disabled="viewOnly" />
<label>Notification message you want to add.</label>
</el-form-item>

<el-form-item label="Proxy" prop="rocketChatProxy">
<el-input id="rocketChatProxy" v-model="rocketChatProxy" :disabled="viewOnly" />
<label>
By default ElastAlert2 will not use a network proxy to send notifications to Slack.
Set this option using hostname:port if you need to use a proxy.
</label>
</el-form-item>
</el-tab-pane>
</el-tabs>
</el-form>
</template>
Expand All @@ -1558,16 +1619,6 @@ let validateSlackDestination = (rule, value, callback) => {
}
};
let validateMattermostDestination = (rule, value, callback) => {
if (value.length < 2) {
callback(new Error('Please enter a @username or #channel'));
} else if (!value.startsWith('@') && !value.startsWith('#')) {
callback(new Error('Please enter a @username or #channel'));
} else {
callback();
}
};
let validateEmail = (rule, value, callback) => {
if (!value || EmailValidator.validate(value)) {
callback();
Expand Down Expand Up @@ -1696,7 +1747,13 @@ export default {
],
mattermostChannelOverride: [
{
validator: validateMattermostDestination,
validator: validateSlackDestination,
trigger: 'change'
}
],
rocketChatChannelOverride: [
{
validator: validateSlackDestination,
trigger: 'change'
}
],
Expand Down Expand Up @@ -3373,6 +3430,69 @@ export default {
}
},
rocketChatChannelOverride: {
get() {
return this.$store.state.config.alert.rocketChatChannelOverride;
},
set(value) {
this.$store.commit('config/alert/UPDATE_ROCKET_CHAT_CHANNEL_OVERRIDE', value);
}
},
rocketChatUsernameOverride: {
get() {
return this.$store.state.config.alert.rocketChatUsernameOverride;
},
set(value) {
this.$store.commit(
'config/alert/UPDATE_ROCKET_CHAT_USERNAME_OVERRIDE',
value
);
}
},
rocketChatEmojiOverride: {
get() {
return this.$store.state.config.alert.rocketChatEmojiOverride;
},
set(value) {
this.$store.commit('config/alert/UPDATE_ROCKET_CHAT_EMOJI_OVERRIDE', value);
}
},
rocketChatTextString: {
get() {
return this.$store.state.config.alert.rocketChatTextString;
},
set(value) {
this.$store.commit(
'config/alert/UPDATE_ROCKET_CHAT_TEXT_STRING',
value
);
}
},
rocketChatMsgColor: {
get() {
return this.$store.state.config.alert.rocketChatMsgColor;
},
set(value) {
this.$store.commit('config/alert/UPDATE_ROCKET_CHAT_MSG_COLOR', value);
}
},
rocketChatProxy: {
get() {
return this.$store.state.config.alert.rocketChatProxy;
},
set(value) {
this.$store.commit(
'config/alert/UPDATE_ROCKET_CHAT_PROXY',
value
);
}
},
ms_teamsWebhookUrl: {
get() {
return this.$store.state.config.alert.ms_teamsWebhookUrl;
Expand Down Expand Up @@ -4005,6 +4125,42 @@ export default {
color: green !important;
border-color: green !important;
}
&.rocketChat-danger .el-radio__inner:hover {
border-color: red;
}
&.rocketChat-danger .el-radio__input.is-checked .el-radio__inner {
border-color: red;
background: red;
}
&.rocketChat-danger .el-radio__input.is-checked + .el-radio__label,
&.rocketChat-danger {
color: red !important;
border-color: red !important;
}
&.rocketChat-warning .el-radio__inner:hover {
border-color: orange;
}
&.rocketChat-warning .el-radio__input.is-checked .el-radio__inner {
border-color: orange;
background: orange;
}
&.rocketChat-warning .el-radio__input.is-checked + .el-radio__label,
&.rocketChat-warning {
color: orange !important;
border-color: orange !important;
}
&.rocketChat-good .el-radio__inner:hover {
border-color: green;
}
&.rocketChat-good .el-radio__input.is-checked .el-radio__inner {
border-color: green;
background: green;
}
&.rocketChat-good .el-radio__input.is-checked + .el-radio__label,
&.rocketChat-good {
color: green !important;
border-color: green !important;
}
&.gitter-error .el-radio__inner:hover {
border-color: red;
}
Expand Down
3 changes: 2 additions & 1 deletion src/contrib.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
faExclamationCircle
} from '@fortawesome/free-solid-svg-icons';
import {
faSlack, faMicrosoft, faGitter, faAws, faLine, faTelegram, faJira
faSlack, faMicrosoft, faGitter, faAws, faLine, faTelegram, faJira, faRocketchat
} from '@fortawesome/free-brands-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import 'element-ui/lib/theme-chalk/index.css';
Expand All @@ -38,6 +38,7 @@ library.add(
faFile,
faFileAlt,
faSlack,
faRocketchat,
faMicrosoft,
faGitter,
faAws,
Expand Down
33 changes: 33 additions & 0 deletions src/store/config/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ function initialState() {
mattermostKibanaDiscoverColor: '#ec4b98',
mattermostKibanaDiscoverTitle: 'Discover in Kibana',

/* Rocket.Chat */
rocketChatChannelOverride: '',
rocketChatUsernameOverride: 'Praeco',
rocketChatEmojiOverride: ':ghost:',
rocketChatMsgColor: 'danger',
rocketChatTextString: '',
rocketChatProxy: '',

/* TheHive */
hiveAlertConfigTitle: '',
hiveAlertConfigType: '',
Expand Down Expand Up @@ -827,6 +835,31 @@ export default {
state.mattermostKibanaDiscoverTitle = mattermostKibanaDiscoverTitle;
},

/* Rocket.Chat */
UPDATE_ROCKET_CHAT_CHANNEL_OVERRIDE(state, rocketChatChannelOverride) {
state.rocketChatChannelOverride = rocketChatChannelOverride;
},

UPDATE_ROCKET_CHAT_USERNAME_OVERRIDE(state, rocketChatUsernameOverride) {
state.rocketChatUsernameOverride = rocketChatUsernameOverride;
},

UPDATE_ROCKET_CHAT_EMOJI_OVERRIDE(state, rocketChatEmojiOverride) {
state.rocketChatEmojiOverride = rocketChatEmojiOverride;
},

UPDATE_ROCKET_CHAT_MSG_COLOR(state, rocketChatMsgColor) {
state.rocketChatMsgColor = rocketChatMsgColor;
},

UPDATE_ROCKET_CHAT_TEXT_STRING(state, rocketChatTextString) {
state.rocketChatTextString = rocketChatTextString;
},

UPDATE_ROCKET_CHAT_PROXY(state, rocketChatProxy) {
state.rocketChatProxy = rocketChatProxy;
},

/* Slack */
UPDATE_SLACK_CHANNEL_OVERRIDE(state, slackChannelOverride) {
state.slackChannelOverride = slackChannelOverride;
Expand Down
59 changes: 59 additions & 0 deletions src/store/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,30 @@ export default {
commit('alert/UPDATE_MATTERMOST_KIBANA_DISCOVER_TITLE', config.mattermost_kibana_discover_title);
}

/* Rocket.Chat */
if (config.rocket_chat_username_override) {
commit('alert/UPDATE_ROCKET_CHAT_USERNAME_OVERRIDE', config.rocket_chat_username_override);
} else {
commit('alert/UPDATE_ROCKET_CHAT_USERNAME_OVERRIDE', 'elastalert2');
}

commit('alert/UPDATE_ROCKET_CHAT_CHANNEL_OVERRIDE', config.rocket_chat_channel_override);

if (config.rocket_chat_emoji_override) {
commit('alert/UPDATE_ROCKET_CHAT_EMOJI_OVERRIDE', config.rocket_chat_emoji_override);
} else {
commit('alert/UPDATE_ROCKET_CHAT_EMOJI_OVERRIDE', ':ghost:');
}

if (config.rocket_chat_msg_color) {
commit('alert/UPDATE_ROCKET_CHAT_MSG_COLOR', config.rocket_chat_msg_color);
} else {
commit('alert/UPDATE_ROCKET_CHAT_MSG_COLOR', 'danger');
}

commit('alert/UPDATE_ROCKET_CHAT_TEXT_STRING', config.rocket_chat_text_string);
commit('alert/UPDATE_ROCKET_CHAT_PROXY', config.rocket_chat_proxy);

/* TheHive */
if (config.hive_alert_config && config.hive_alert_config.title) {
commit('alert/UPDATE_HIVE_ALERT_CONFIG_TITLE', config.hive_alert_config.title);
Expand Down Expand Up @@ -1865,6 +1889,36 @@ export default {
return config;
},

rocketchat(state) {
let config = {};

if (state.alert.rocketChatUsernameOverride) {
config.rocket_chat_username_override = state.alert.rocketChatUsernameOverride;
}

if (state.alert.rocketChatChannelOverride) {
config.rocket_chat_channel_override = state.alert.rocketChatChannelOverride;
}

if (state.alert.rocketChatEmojiOverride) {
config.rocket_chat_emoji_override = state.alert.rocketChatEmojiOverride;
}

if (state.alert.rocketChatMsgColor) {
config.rocket_chat_msg_color = state.alert.rocketChatMsgColor;
}

if (state.alert.rocketChatTextString) {
config.rocket_chat_text_string = state.alert.rocketChatTextString;
}

if (state.alert.rocketChatProxy) {
config.rocket_chat_proxy = state.alert.rocketChatProxy;
}

return config;
},

hivealerter(state) {
let config = {};
config.hive_alert_config = {};
Expand Down Expand Up @@ -2162,6 +2216,10 @@ export default {
config = { ...config, ...getters.mattermost };
}

if (state.alert.alert.includes('rocketchat')) {
config = { ...config, ...getters.rocketchat };
}

if (state.alert.alert.includes('hivealerter')) {
config = { ...config, ...getters.hivealerter };
}
Expand Down Expand Up @@ -2197,6 +2255,7 @@ export default {
|| state.alert.alert.includes('sns')
|| state.alert.alert.includes('ses')
|| state.alert.alert.includes('mattermost')
|| state.alert.alert.includes('rocketchat')
|| state.alert.alert.includes('hivealerter')
|| state.alert.alert.includes('alerta')
|| state.alert.alert.includes('datadog')
Expand Down
2 changes: 1 addition & 1 deletion src/views/RuleView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
<div class="text-muted m-s-lg">
This YAML is generated by Praeco and run in its internal
<a href="https://github.com/jertel/elastalert2" target="_blank">Elastalert 2</a> server.
You may copy/paste this yaml and run it in any outside Elastalert instance.
You may copy/paste this yaml and run it in any outside Elastalert 2 instance.
</div>
<prism language="javascript">
{{ yaml }}
Expand Down

0 comments on commit e3aa072

Please sign in to comment.