Skip to content

Commit

Permalink
- client: find clients by client_id
Browse files Browse the repository at this point in the history
  • Loading branch information
IldarKamalov committed Jan 27, 2021
1 parent 71c9593 commit 0c33058
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion client/src/actions/queryLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { addErrorToast, addSuccessToast } from './toasts';

const enrichWithClientInfo = async (logs) => {
const clientsParams = getParamsForClientsSearch(logs, 'client');
const clientsParams = getParamsForClientsSearch(logs, 'client', 'client_id');

if (Object.keys(clientsParams).length > 0) {
const clients = await apiClient.findClients(clientsParams);
Expand Down
27 changes: 18 additions & 9 deletions client/src/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import dateFormat from 'date-fns/format';
import round from 'lodash/round';
import axios from 'axios';
import i18n from 'i18next';
import uniqBy from 'lodash/uniqBy';
import ipaddr from 'ipaddr.js';
import queryString from 'query-string';
import React from 'react';
Expand Down Expand Up @@ -417,14 +416,21 @@ export const getPathWithQueryString = (path, params) => {
return `${path}?${searchParams.toString()}`;
};

export const getParamsForClientsSearch = (data, param) => {
const uniqueClients = uniqBy(data, param);
return uniqueClients
.reduce((acc, item, idx) => {
const key = `ip${idx}`;
acc[key] = item[param];
return acc;
}, {});
export const getParamsForClientsSearch = (data, param, additionalParam) => {
const clients = new Set();
data.forEach((e) => {
clients.add(e[param]);
if (e[additionalParam]) {
clients.add(e[additionalParam]);
}
});
const params = {};
const ids = Array.from(clients.values());
ids.forEach((id, i) => {
params[`ip${i}`] = id;
});

return params;
};

/**
Expand Down Expand Up @@ -595,6 +601,9 @@ export const countClientsStatistics = (ids, autoClients) => {
const cidrsCount = Object.entries(autoClients)
.reduce((acc, curr) => {
const [id, count] = curr;
if (R_CLIENT_ID.test(id)) {
return false;
}
if (cidrs.some((cidr) => isIpInCidr(id, cidr))) {
// eslint-disable-next-line no-param-reassign
acc += count;
Expand Down

0 comments on commit 0c33058

Please sign in to comment.