Skip to content

Commit

Permalink
Add HTTP POST 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
nsano-rururu committed Nov 23, 2021
1 parent 795b385 commit 5ce2ef5
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/components/config/alert/ConfigAlert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@
Email
</el-checkbox>
<el-checkbox id="destinationPost" label="post" border>
HTTP
HTTP POST
</el-checkbox>
<el-checkbox id="destinationPost2" label="post2" border>
HTTP POST 2
</el-checkbox>
<el-checkbox id="destinationTelegram" label="telegram" border>
Telegram
Expand All @@ -124,10 +127,10 @@
Gitter
</el-checkbox>
<el-checkbox id="destinationSns" label="sns" border>
Amazon SNS
AWS SNS (Amazon Simple Notification Service)
</el-checkbox>
<el-checkbox id="destinationSes" label="ses" border>
Amazon SES
AWS SES (Amazon Simple Email Service)
</el-checkbox>
<el-checkbox id="destinationZabbix" label="zabbix" border>
Zabbix
Expand All @@ -145,7 +148,7 @@
Stomp
</el-checkbox>
<el-checkbox id="destinationVictorOps" label="victorops" border>
VictorOps
Splunk On-Call (Formerly VictorOps)
</el-checkbox>
<el-checkbox id="destinationServiceNow" label="servicenow" border>
ServiceNow
Expand Down Expand Up @@ -183,7 +186,8 @@
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('rocketchat') || alert.includes('pagerduty') || alert.includes('tencentsms')">
alert.includes('rocketchat') || alert.includes('pagerduty') || alert.includes('tencentsms') ||
alert.includes('post2')">
<template slot="label">
<icon :icon="['fa', 'bell']" size="1x" /> Alert
</template>
Expand All @@ -209,10 +213,16 @@

<!-- HTTP POST -->
<el-tab-pane v-if="alert.includes('post')" label="HTTP">
<span slot="label"><icon icon="globe" /> HTTP</span>
<span slot="label"><icon icon="globe" /> HTTP POST</span>
<ConfigAlertHttpPost ref="post" :view-only="viewOnly" />
</el-tab-pane>

<!-- HTTP POST 2 -->
<el-tab-pane v-if="alert.includes('post2')" label="HTTP2">
<span slot="label"><icon icon="globe" /> HTTP POST 2</span>
<ConfigAlertHttpPost2 ref="post2" :view-only="viewOnly" />
</el-tab-pane>

<!-- MS Teams -->
<el-tab-pane v-if="alert.includes('ms_teams')">
<template slot="label">
Expand Down Expand Up @@ -430,6 +440,7 @@ import ConfigAlertExotel from './ConfigAlertExotel';
import ConfigAlertGitter from './ConfigAlertGitter';
import ConfigAlertGoogleChat from './ConfigAlertGoogleChat';
import ConfigAlertHttpPost from './ConfigAlertHttpPost';
import ConfigAlertHttpPost2 from './ConfigAlertHttpPost2';
import ConfigAlertJira from './ConfigAlertJira';
import ConfigAlertLineNotify from './ConfigAlertLineNotify';
import ConfigAlertMattermost from './ConfigAlertMattermost';
Expand Down Expand Up @@ -462,6 +473,7 @@ export default {
ConfigAlertGitter,
ConfigAlertGoogleChat,
ConfigAlertHttpPost,
ConfigAlertHttpPost2,
ConfigAlertJira,
ConfigAlertLineNotify,
ConfigAlertMattermost,
Expand Down
159 changes: 159 additions & 0 deletions src/components/config/alert/ConfigAlertHttpPost2.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<template>
<div>
<el-form-item label="HTTP POST URL" prop="httpPost2Url" required>
<el-input v-model="httpPost2Url" :disabled="viewOnly" />
<label>JSON results will be POSTed to this URL</label>
</el-form-item>

<el-form-item label="CA Certs" prop="httpPost2CaCerts">
<el-switch
id="httpPost2CaCerts"
v-model="httpPost2CaCerts"
:disabled="viewOnly"
@change="changeHttpPost2CaCerts" />
</el-form-item>

<el-form-item label="Ignore SSL Errors" prop="httpPost2IgnoreSslErrors">
<el-switch
id="httpPost2IgnoreSslErrors"
v-model="httpPost2IgnoreSslErrors"
:disabled="viewOnly"
@change="changeHttpPost2IgnoreSslErrors" />
</el-form-item>

<el-form-item label="Timeout" prop="httpPost2Timeout">
<el-input-number id="httpPost2Timeout" v-model="httpPost2Timeout" :disabled="viewOnly" />
<label>
The timeout value, in seconds, for making the post.
The default is 10.
If a timeout occurs, the alert will be retried next time ElastAlert 2 cycles.
</label>
</el-form-item>

<el-form-item label="Proxy" prop="httpPost2Proxy">
<el-input id="httpPost2Proxy" v-model="httpPost2Proxy" :disabled="viewOnly" />
<label>URL of proxy, if required.</label>
</el-form-item>
</div>
</template>

<script>
import validUrl from 'valid-url';
let validateUrl = (rule, value, callback) => {
if (validUrl.isUri(value)) {
try {
let url = new URL(value);
if (['http:', 'https:'].includes(url.protocol)) {
callback();
} else {
callback(new Error('Invalid URL'));
}
} catch (error) {
callback(new Error('Invalid URL'));
}
} else {
callback(new Error('Invalid URL'));
}
};
export default {
components: {
},
props: ['viewOnly'],
data() {
return {
rules: {
httpPost2Url: [
{
validator: validateUrl,
trigger: ['change', 'blur']
}
]
}
};
},
computed: {
httpPost2Url: {
get() {
return this.$store.state.config.alert.httpPost2Url;
},
set(value) {
this.$store.commit('config/alert/UPDATE_HTTP_POST2_URL', value);
}
},
httpPost2IgnoreSslErrors: {
get() {
return this.$store.state.config.alert.httpPost2IgnoreSslErrors;
},
set(value) {
this.$store.commit(
'config/alert/UPDATE_HTTP_POST2_IGNORE_SSL_ERRORS',
value
);
}
},
httpPost2CaCerts: {
get() {
return this.$store.state.config.alert.httpPost2CaCerts;
},
set(value) {
this.$store.commit(
'config/alert/UPDATE_HTTP_POST2_CA_CERTS',
value
);
}
},
httpPost2Timeout: {
get() {
return this.$store.state.config.alert.httpPost2Timeout;
},
set(value) {
this.$store.commit(
'config/alert/UPDATE_HTTP_POST2_TIMEOUT',
value
);
}
},
httpPost2Proxy: {
get() {
return this.$store.state.config.alert.httpPost2Proxy;
},
set(value) {
this.$store.commit(
'config/alert/UPDATE_HTTP_POST2_PROXY',
value
);
}
}
},
methods: {
changeHttpPost2IgnoreSslErrors(val) {
if (val) {
this.httpPost2IgnoreSslErrors = true;
} else {
this.httpPost2IgnoreSslErrors = false;
}
},
changeHttpPost2CaCerts(val) {
if (val) {
this.httpPost2CaCerts = true;
} else {
this.httpPost2CaCerts = false;
}
}
}
};
</script>

<style lang="scss">
</style>
2 changes: 2 additions & 0 deletions src/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import ConfigAlertExotel from '@/components/config/alert/ConfigAlertExotel.vue';
import ConfigAlertGitter from '@/components/config/alert/ConfigAlertGitter.vue';
import ConfigAlertGoogleChat from '@/components/config/alert/ConfigAlertGoogleChat.vue';
import ConfigAlertHttpPost from '@/components/config/alert/ConfigAlertHttpPost.vue';
import ConfigAlertHttpPost2 from '@/components/config/alert/ConfigAlertHttpPost2.vue';
import ConfigAlertJira from '@/components/config/alert/ConfigAlertJira.vue';
import ConfigAlertLineNotify from '@/components/config/alert/ConfigAlertLineNotify.vue';
import ConfigAlertMattermost from '@/components/config/alert/ConfigAlertMattermost.vue';
Expand Down Expand Up @@ -68,6 +69,7 @@ Vue.component('ConfigAlertExotel', ConfigAlertExotel);
Vue.component('ConfigAlertGitter', ConfigAlertGitter);
Vue.component('ConfigAlertGoogleChat', ConfigAlertGoogleChat);
Vue.component('ConfigAlertHttpPost', ConfigAlertHttpPost);
Vue.component('ConfigAlertHttpPost2', ConfigAlertHttpPost2);
Vue.component('ConfigAlertJira', ConfigAlertJira);
Vue.component('ConfigAlertLineNotify', ConfigAlertLineNotify);
Vue.component('ConfigAlertMattermost', ConfigAlertMattermost);
Expand Down
28 changes: 28 additions & 0 deletions src/store/config/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,13 @@ function initialState() {
httpPostCaCerts: false,
httpPostTimeout: '',
httpPostProxy: '',

/* HTTP POST 2 */
httpPost2Url: '',
httpPost2IgnoreSslErrors: false,
httpPost2CaCerts: false,
httpPost2Timeout: '',
httpPost2Proxy: '',
};
}

Expand Down Expand Up @@ -390,6 +397,27 @@ export default {
state.httpPostProxy = httpPostProxy;
},

/* HTTP POST 2 */
UPDATE_HTTP_POST2_URL(state, httpPost2Url) {
state.httpPost2Url = httpPost2Url;
},

UPDATE_HTTP_POST2_IGNORE_SSL_ERRORS(state, httpPost2IgnoreSslErrors) {
state.httpPost2IgnoreSslErrors = httpPost2IgnoreSslErrors;
},

UPDATE_HTTP_POST2_CA_CERTS(state, httpPost2CaCerts) {
state.httpPost2CaCerts = httpPost2CaCerts;
},

UPDATE_HTTP_POST2_TIMEOUT(state, httpPost2Timeout) {
state.httpPost2Timeout = httpPost2Timeout;
},

UPDATE_HTTP_POST2_PROXY(state, httpPost2Proxy) {
state.httpPost2Proxy = httpPost2Proxy;
},

/* EMail */
UPDATE_FROM_ADDR(state, fromAddr) {
state.fromAddr = fromAddr;
Expand Down
50 changes: 50 additions & 0 deletions src/store/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,25 @@ export default {

commit('alert/UPDATE_HTTP_POST_PROXY', config.http_post_proxy);

/* HTTP POST 2 */
commit('alert/UPDATE_HTTP_POST2_URL', config.http_post2_url);

if (config.http_post2_ignore_ssl_errors) {
commit('alert/UPDATE_HTTP_POST2_IGNORE_SSL_ERRORS', config.http_post2_ignore_ssl_errors);
}

if (config.http_post2_ca_certs) {
commit('alert/UPDATE_HTTP_POST2_CA_CERTS', config.http_post2_ca_certs);
}

if (config.http_post2_timeout) {
commit('alert/UPDATE_HTTP_POST2_TIMEOUT', config.http_post2_timeout);
} else {
commit('alert/UPDATE_HTTP_POST2_TIMEOUT', 10);
}

commit('alert/UPDATE_HTTP_POST2_PROXY', config.http_post2_proxy);

/* EMail */
commit('alert/UPDATE_FROM_ADDR', config.from_addr);
commit('alert/UPDATE_REPLY_TO', config.email_reply_to);
Expand Down Expand Up @@ -1230,6 +1249,32 @@ export default {
return config;
},

http2(state) {
let config = {};

if (state.alert.httpPost2Url) {
config.http_post2_url = state.alert.httpPost2Url;
}

if (state.alert.httpPost2IgnoreSslErrors) {
config.http_post2_ignore_ssl_errors = state.alert.httpPost2IgnoreSslErrors;
}

if (state.alert.httpPost2CaCerts) {
config.http_post2_ca_certs = state.alert.httpPost2CaCerts;
}

if (state.alert.httpPost2Timeout) {
config.http_post2_timeout = state.alert.httpPost2Timeout;
}

if (state.alert.httpPost2Proxy) {
config.http_post2_proxy = state.alert.httpPost2Proxy;
}

return config;
},

aggregation(state) {
let config = {};

Expand Down Expand Up @@ -2467,6 +2512,10 @@ export default {
config = { ...config, ...getters.http };
}

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

if (state.alert.alert.includes('email')) {
config = { ...config, ...getters.email };
}
Expand Down Expand Up @@ -2576,6 +2625,7 @@ export default {
}

if (state.alert.alert.includes('email')
|| state.alert.alert.includes('post2')
|| state.alert.alert.includes('slack')
|| state.alert.alert.includes('ms_teams')
|| state.alert.alert.includes('telegram')
Expand Down

0 comments on commit 5ce2ef5

Please sign in to comment.