Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timezone reporting #1311

Merged
merged 5 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Adapted Wazuh icon for multiple browsers where it was gone ([#1208](https://github.com/wazuh/wazuh-kibana-app/pull/1208)).
- Do not fetch data from tables twice when resize window ([#1303](https://github.com/wazuh/wazuh-kibana-app/pull/1303)).
- Agent syncrhonization status is updated as we browse the configuration section ([#1305](https://github.com/wazuh/wazuh-kibana-app/pull/1305))
- Using the browser timezone for reporting documents ([#1311](https://github.com/wazuh/wazuh-kibana-app/pull/1311)).

## Wazuh v3.8.2 - Kibana v6.6.0 / v6.6.1 - Revision 419

Expand Down
8 changes: 6 additions & 2 deletions public/services/reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

import $ from 'jquery';
import moment from 'moment';

export class ReportingService {
constructor(
Expand Down Expand Up @@ -55,7 +56,9 @@ export class ReportingService {
const array = await this.vis2png.checkArray(idArray);
const name = `wazuh-${
isAgents ? 'agents' : 'overview'
}-${tab}-${(Date.now() / 1000) | 0}.pdf`;
}-${tab}-${(Date.now() / 1000) | 0}.pdf`;

const browserTimezone = moment.tz.guess(true);

const data = {
array,
Expand All @@ -67,7 +70,8 @@ export class ReportingService {
tables: appliedFilters.tables,
tab,
section: isAgents ? 'agents' : 'overview',
isAgents
isAgents,
browserTimezone
};

await this.genericReq.request('POST', '/reports', data);
Expand Down
3 changes: 1 addition & 2 deletions public/templates/overview/overview-general.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@
<span class="wz-text-link" ng-click="octrl.expand(5)"><i class="fa fa-fw fa-expand"></i></span>
</div>
<md-divider class="wz-margin-top-10"></md-divider>
<kbn-vis id="Wazuh-App-Overview-General-Commonly-fired-rules"
vis-id="'Wazuh-App-Overview-General-Commonly-fired-rules'"></kbn-vis>
<kbn-vis vis-id="'Wazuh-App-Overview-General-Commonly-fired-rules'"></kbn-vis>
</md-card-content>
</md-card>
</div>
Expand Down
51 changes: 34 additions & 17 deletions server/controllers/wazuh-reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class WazuhReportingCtrl {
return {
columns: [
{
text: 'Copyright © 2018 Wazuh, Inc.',
text: 'Copyright © 2019 Wazuh, Inc.',
color: '#1EA5C8',
margin: [40, 40, 0, 0]
},
Expand Down Expand Up @@ -236,14 +236,37 @@ export class WazuhReportingCtrl {
}
}

/**
* Format Date to string YYYY-mm-ddTHH:mm:ss
* @param {*} date JavaScript Date
*/
formatDate(date) {
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const hours = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
const str = `${year}-${month < 10 ? '0' + month : month}-${
day < 10 ? '0' + day : day
}T${hours < 10 ? '0' + hours : hours}:${
minutes < 10 ? '0' + minutes : minutes
}:${seconds < 10 ? '0' + seconds : seconds}`;
return str;
}

/**
* This performs the rendering of given time range and filters
* @param {Number} from Timestamp (ms) from
* @param {Number} to Timestamp (ms) to
* @param {String} filters E.g: cluster.name: wazuh AND rule.groups: vulnerability
*/
renderTimeRangeAndFilters(from, to, filters) {
const str = `${from} to ${to}`;
renderTimeRangeAndFilters(from, to, filters, timeZone) {
const fromDate = new Date(
new Date(from).toLocaleString('en-US', { timeZone })
);
const toDate = new Date(new Date(to).toLocaleString('en-US', { timeZone }));
const str = `${this.formatDate(fromDate)} to ${this.formatDate(toDate)}`;

this.dd.content.push({
fontSize: 8,
Expand Down Expand Up @@ -1370,20 +1393,14 @@ export class WazuhReportingCtrl {
}

if (req.payload && req.payload.array) {
const name = req.payload.name;
const tab = req.payload.tab;
const section = req.payload.section;
const apiId = req.headers && req.headers.id ? req.headers.id : false;
const pattern =
req.headers && req.headers.pattern ? req.headers.pattern : false;
const payload = (req || {}).payload || {};
const headers = (req || {}).headers || {};
const { name, tab, section, isAgents, browserTimezone } = payload;
const apiId = headers.id || false;
const pattern = headers.pattern || false;
const from = (payload.time || {}).from || false;
const to = (payload.time || {}).to || false;
const kfilters = req.payload.filters;
const isAgents = req.payload.isAgents;
const from =
req.payload.time && req.payload.time.from
? req.payload.time.from
: false;
const to =
req.payload.time && req.payload.time.to ? req.payload.time.to : false;

if (!tab)
throw new Error(
Expand Down Expand Up @@ -1582,7 +1599,7 @@ export class WazuhReportingCtrl {
}

if (!isSycollector && req.payload.time && filters) {
this.renderTimeRangeAndFilters(from, to, filters);
this.renderTimeRangeAndFilters(from, to, filters, browserTimezone);
}

if (req.payload.time || isSycollector) {
Expand Down