Skip to content

Commit

Permalink
Merge pull request #377 from sirensolutions/multi-fix_report-and-alar…
Browse files Browse the repository at this point in the history
…m-message

Multi fix for report and alarm message and spy button
  • Loading branch information
sergibondarenko committed Mar 26, 2018
2 parents b881b3c + bc7cabe commit 81b78ec
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export default function (kibana) {
'Option "report.tmp_path" is not needed anymore. Just delete it from config!'
)),
active: Joi.boolean().default(false),
executable_path: Joi.string().default('/usr/bin/chromium'),
authentication: Joi.object({
enabled: Joi.boolean().default(false),
mode: Joi.object({
Expand Down
4 changes: 2 additions & 2 deletions public/dashboard_spy_button/alarm_spy.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div ng-show="spy.mode.name === 'setalarm'" class="fill visualize-spy-nav">
<div class="fill visualize-spy-nav" style="padding-top:10px">
<div class="form-group">
<a class="btn btn-success" ng-click="createWatcher()" target="_sentinl" ng-href="./sentinl">
<a class="kuiButton kuiButton--primary" ng-click="createWatcher()" target="_sentinl" ng-href="./sentinl">
Set Alarm
</a>
</div>
Expand Down
13 changes: 7 additions & 6 deletions server/lib/actions/actions/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import url from 'url';
import path from 'path';
import fs from 'fs';
import os from 'os';
import { resolve, promisify, reject } from 'bluebird';
import { delay } from 'bluebird';
import { includes, isObject } from 'lodash';
import { delay } from '../../helpers';
import getConfiguration from '../../get_configuration';
import logHistory from '../../log_history';
import uuid from 'uuid/v4';
Expand Down Expand Up @@ -61,11 +60,12 @@ class Reporter {
this.config = config;
}

async openPage(url) {
async openPage(url, executablePath) {
this.url = url;

try {
this.browser = await puppeteer.launch({
executablePath,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
ignoreHTTPSErrors: true,
});
Expand Down Expand Up @@ -172,6 +172,7 @@ const createReportAttachment = function (filename, file, type = 'png') {
*
* @param {object} server - Kibana hapi server
* @param {object} email - instance of emailjs server
* @param {object} task - watcher
* @param {object} action - current watcher action
* @param {string} actionName - name of the action
* @param {object} payload - ES response
Expand All @@ -186,7 +187,7 @@ export default async function doReport(server, email, task, action, actionName,
}

if (!action.snapshot.url.length) {
reject('Report Disabled: No URL Settings!');
log.info('Report Disabled: No URL Settings!');
}

let formatterSubject = action.subject;
Expand Down Expand Up @@ -226,7 +227,7 @@ export default async function doReport(server, email, task, action, actionName,

try {
const report = new Reporter(config);
await report.openPage(action.snapshot.url);
await report.openPage(action.snapshot.url, config.executable_path);

let file;
if (action.snapshot.type !== 'pdf') {
Expand Down Expand Up @@ -276,6 +277,6 @@ export default async function doReport(server, email, task, action, actionName,
log.debug('stateless report does not save data to Elasticsearch');
return {message: 'stateless report does not save data to Elasticsearch'};
} catch (err) {
throw err;
log.error(err);
}
}
38 changes: 22 additions & 16 deletions server/lib/actions/do_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ import Log from '../log';
// actions
import reportAction from './actions/report';

const toString = function (message) {
if (typeof message !== 'string') {
return JSON.stringify(message);
}
return message;
};

export default function (server, actions, payload, task) {
const config = getConfiguration(server);
const log = new Log(config.app_name, server, 'action');
Expand Down Expand Up @@ -107,7 +114,7 @@ export default function (server, actions, payload, task) {
esHistory({
title: task._source.title,
actionType: actionName,
message,
message: toString(message),
level: priority,
payload: !action.console.save_payload ? {} : payload,
report: false
Expand Down Expand Up @@ -145,7 +152,7 @@ export default function (server, actions, payload, task) {
* "body" : "Series Alarm {{ payload._id}}: {{payload.hits.total}}",
* "stateless" : false,
* "save_payload" : false
* }
* }
*/

var formatterSubject;
Expand Down Expand Up @@ -180,7 +187,7 @@ export default function (server, actions, payload, task) {
esHistory({
title: task._source.title,
actionType: actionName,
message: text,
message: toString(text),
level: priority,
payload: !action.email.save_payload ? {} : payload,
report: false
Expand All @@ -200,7 +207,7 @@ export default function (server, actions, payload, task) {
* "html" : "<p>Series Alarm {{ payload._id}}: {{payload.hits.total}}</p>",
* "stateless" : false,
* "save_payload" : false
* }
* }
*/
var html;
if (_.has(action, 'email_html')) {
Expand Down Expand Up @@ -241,7 +248,7 @@ export default function (server, actions, payload, task) {
esHistory({
title: task._source.title,
actionType: actionName,
message: text,
message: toString(text),
level: priority,
payload: !action.email_html.save_payload ? {} : payload,
report: false
Expand All @@ -258,13 +265,13 @@ export default function (server, actions, payload, task) {
* "priority" : "high",
* "body" : "Series Report {{ payload._id}}: {{payload.hits.total}}",
* "snapshot" : {
* "res" : "1280,900",
* "res" : "1280,900",
* "url" : "http://127.0.0.1/app/kibana#/dashboard/Alerts",
* "path" : "/tmp/",
* "params" : {
* "username" : "username",
* "password" : "password",
* "delay" : 15,
* "username" : "username",
* "password" : "password",
* "delay" : 15,
* "crop" : false
* }
* },
Expand Down Expand Up @@ -318,7 +325,7 @@ export default function (server, actions, payload, task) {
esHistory({
title: task._source.title,
actionType: actionName,
message,
message: toString(message),
level: priority,
payload: !action.slack.save_payload ? {} : payload,
report: false
Expand Down Expand Up @@ -366,7 +373,7 @@ export default function (server, actions, payload, task) {
esHistory({
title: task._source.title,
actionType: actionName,
message: action.webhook.message,
message: toString(action.webhook.message),
level: action.webhook.priority,
payload: !action.webhook.save_payload ? {} : payload,
report: false
Expand Down Expand Up @@ -400,17 +407,17 @@ export default function (server, actions, payload, task) {
*/

if (_.has(action, 'elastic')) {
let esMessage;
let message;
let esFormatter;
esFormatter = action.local.message ? action.local.message : '{{ payload }}';
esMessage = mustache.render(esFormatter, {payload: payload});
message = mustache.render(esFormatter, {payload: payload});
priority = action.local.priority ? action.local.priority : 'INFO';
log.debug(`logged message to elastic: ${esMessage}`);
log.debug(`logged message to elastic: ${message}`);
// Log Event
esHistory({
title: task._source.title,
actionType: actionName,
message: esMessage,
message: toString(message),
level: priority,
payload: !action.local.save_payload ? {} : payload,
report: false
Expand Down Expand Up @@ -472,4 +479,3 @@ export default function (server, actions, payload, task) {
}
});
}

7 changes: 0 additions & 7 deletions server/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ const isKibi = function (server) {
return server.plugins.saved_objects_api ? true : false;
};

const delay = function (timeout) {
return new Promise((resolve) => {
setTimeout(resolve, timeout);
});
};

module.exports = {
isKibi,
delay,
};

0 comments on commit 81b78ec

Please sign in to comment.