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

[SECURITY SOLUTION] Task/endpoint details to fleet #68710

Merged
merged 20 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 18 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,22 @@ interface ServerFailedToReturnHostPolicyResponse {
payload: ServerApiError;
}

interface ServerReturnedEndpointPackageVersion {
type: 'serverReturnedEndpointPackageVersion';
payload: string;
}

interface ServerFailedToReturnEndpointPackageVersion {
type: 'serverFailedToReturnEndpointPackageVersion';
payload: ServerApiError;
}

export type HostAction =
| ServerReturnedHostList
| ServerFailedToReturnHostList
| ServerReturnedHostDetails
| ServerFailedToReturnHostDetails
| ServerReturnedHostPolicyResponse
| ServerFailedToReturnHostPolicyResponse;
| ServerFailedToReturnHostPolicyResponse
| ServerReturnedEndpointPackageVersion
| ServerFailedToReturnEndpointPackageVersion;
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const initialHostListState: Immutable<HostState> = {
policyResponse: undefined,
policyResponseLoading: false,
policyResponseError: undefined,
endpointPackageVersion: undefined,
endpointPackageVersionError: undefined,
location: undefined,
};

Expand Down Expand Up @@ -78,6 +80,18 @@ export const hostListReducer: ImmutableReducer<HostState, AppAction> = (
policyResponseError: action.payload,
policyResponseLoading: false,
};
} else if (action.type === 'serverReturnedEndpointPackageVersion') {
return {
...state,
endpointPackageVersion: action.payload,
endpointPackageVersionError: undefined,
};
} else if (action.type === 'serverFailedToReturnEndpointPackageVersion') {
return {
...state,
endpointPackageError: action.payload,
endpointPackageVersion: undefined,
};
} else if (action.type === 'userChangedUrl') {
const newState: Immutable<HostState> = {
...state,
Expand All @@ -97,6 +111,7 @@ export const hostListReducer: ImmutableReducer<HostState, AppAction> = (
loading: true,
error: undefined,
detailsError: undefined,
endpointVersionError: undefined,
};
}
} else if (isCurrentlyOnDetailsPage) {
Expand All @@ -110,6 +125,7 @@ export const hostListReducer: ImmutableReducer<HostState, AppAction> = (
error: undefined,
detailsError: undefined,
policyResponseError: undefined,
endpointVersionError: undefined,
};
} else {
// if previous page was not host list or host details, load both list and details
Expand All @@ -122,6 +138,7 @@ export const hostListReducer: ImmutableReducer<HostState, AppAction> = (
error: undefined,
detailsError: undefined,
policyResponseError: undefined,
endpointVersionError: undefined,
};
}
}
Expand All @@ -132,6 +149,7 @@ export const hostListReducer: ImmutableReducer<HostState, AppAction> = (
error: undefined,
detailsError: undefined,
policyResponseError: undefined,
endpointVersionError: undefined,
};
}
return state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export interface HostState {
policyResponseLoading: boolean;
/** api error from retrieving the policy response */
policyResponseError?: ServerApiError;
/** latest endpoint package version */
endpointPackageVersion?: string;
/** api error from retrieving endpoint package version */
endpointPackageVersionError?: ServerApiError;
/** current location info */
location?: Immutable<AppLocation>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import {
EuiLink,
EuiListGroup,
EuiListGroupItem,
EuiIcon,
EuiText,
} from '@elastic/eui';
import React, { memo, useMemo } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { HostMetadata } from '../../../../../../common/endpoint/types';
import { useHostSelector, useHostLogsUrl } from '../hooks';
import { useHostSelector, useHostLogsUrl, useHostIngestUrl } from '../hooks';
import { policyResponseStatus, uiQueryParams } from '../../store/selectors';
import { POLICY_STATUS_TO_HEALTH_COLOR } from '../host_constants';
import { FormattedDateAndTime } from '../../../../../common/components/endpoint/formatted_date_time';
Expand All @@ -32,8 +34,19 @@ const HostIds = styled(EuiListGroupItem)`
}
`;

const LinkToExternalApp = styled.div`
margin-top: ${(props) => props.theme.eui.ruleMargins.marginMedium};
.linkToAppIcon {
margin-right: ${(props) => props.theme.eui.ruleMargins.marginXSmall};
}
.linkToAppPopoutIcon {
margin-left: ${(props) => props.theme.eui.ruleMargins.marginXSmall};
}
`;

export const HostDetails = memo(({ details }: { details: HostMetadata }) => {
const { appId, appPath, url } = useHostLogsUrl(details.host.id);
const { url: logsUrl, appId: logsAppId, appPath: logsAppPath } = useHostLogsUrl(details.host.id);
const { url: ingestUrl, appId: ingestAppId, appPath: ingestAppPath } = useHostIngestUrl();
const queryParams = useHostSelector(uiQueryParams);
const policyStatus = useHostSelector(
policyResponseStatus
Expand Down Expand Up @@ -80,7 +93,7 @@ export const HostDetails = memo(({ details }: { details: HostMetadata }) => {

const policyStatusClickHandler = useNavigateByRouterEventHandler(policyResponseRoutePath);

const detailsResultsLower = useMemo(() => {
const detailsResultsPolicy = useMemo(() => {
return [
{
title: i18n.translate('xpack.securitySolution.endpoint.host.details.policy', {
Expand All @@ -103,15 +116,21 @@ export const HostDetails = memo(({ details }: { details: HostMetadata }) => {
href={policyResponseUri}
onClick={policyStatusClickHandler}
>
<FormattedMessage
id="xpack.securitySolution.endpoint.host.details.policyStatusValue"
defaultMessage="{policyStatus, select, success {Success} warning {Warning} failure {Failed} other {Unknown}}"
values={{ policyStatus }}
/>
<EuiText size="m">
<FormattedMessage
id="xpack.securitySolution.endpoint.host.details.policyStatusValue"
defaultMessage="{policyStatus, select, success {Success} warning {Warning} failure {Failed} other {Unknown}}"
values={{ policyStatus }}
/>
</EuiText>
</EuiLink>
</EuiHealth>
),
},
];
}, [details, policyResponseUri, policyStatus, policyStatusClickHandler]);
const detailsResultsLower = useMemo(() => {
return [
{
title: i18n.translate('xpack.securitySolution.endpoint.host.details.ipAddress', {
defaultMessage: 'IP Address',
Expand All @@ -137,15 +156,8 @@ export const HostDetails = memo(({ details }: { details: HostMetadata }) => {
description: details.agent.version,
},
];
}, [
details.agent.version,
details.endpoint.policy.applied.id,
details.host.hostname,
details.host.ip,
policyStatus,
policyResponseUri,
policyStatusClickHandler,
]);
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this disable rule?

}, [details.agent.version, details.host.hostname, details.host.ip]);

return (
<>
Expand All @@ -154,26 +166,49 @@ export const HostDetails = memo(({ details }: { details: HostMetadata }) => {
listItems={detailsResultsUpper}
data-test-subj="hostDetailsUpperList"
/>
<EuiHorizontalRule margin="s" />
<EuiHorizontalRule margin="m" />
<EuiDescriptionList
type="column"
listItems={detailsResultsPolicy}
data-test-subj="hostDetailsPolicyList"
/>
<LinkToExternalApp>
<LinkToApp
appId={ingestAppId}
appPath={ingestAppPath}
href={ingestUrl}
data-test-subj="hostDetailsLinkToIngest"
>
<EuiIcon type="savedObjectsApp" className="linkToAppIcon" />
<FormattedMessage
id="xpack.securitySolution.endpoint.host.details.linkToIngestTitle"
defaultMessage="Reassign Policy"
/>
<EuiIcon type="popout" className="linkToAppPopoutIcon" />
</LinkToApp>
</LinkToExternalApp>
<EuiHorizontalRule margin="m" />
<EuiDescriptionList
type="column"
listItems={detailsResultsLower}
data-test-subj="hostDetailsLowerList"
/>
<EuiHorizontalRule margin="s" />
<p>
<EuiHorizontalRule margin="m" />
<LinkToExternalApp>
<LinkToApp
appId={appId}
appPath={appPath}
href={url}
appId={logsAppId}
appPath={logsAppPath}
href={logsUrl}
data-test-subj="hostDetailsLinkToLogs"
>
<EuiIcon type="logsApp" className="linkToAppIcon" />
<FormattedMessage
id="xpack.securitySolution.endpoint.host.details.linkToLogsTitle"
defaultMessage="Endpoint Logs"
/>
<EuiIcon type="popout" className="linkToAppPopoutIcon" />
</LinkToApp>
</p>
</LinkToExternalApp>
</>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

import { useSelector } from 'react-redux';
import { useMemo } from 'react';
import { useKibana } from '../../../../common/lib/kibana';
import { HostState } from '../types';
import {
MANAGEMENT_STORE_ENDPOINTS_NAMESPACE,
MANAGEMENT_STORE_GLOBAL_NAMESPACE,
} from '../../../common/constants';
import { useKibana } from '../../../../common/lib/kibana';
import { State } from '../../../../common/store';

export function useHostSelector<TSelected>(selector: (state: HostState) => TSelected) {
return useSelector(function (state: State) {
return selector(
Expand All @@ -37,3 +36,18 @@ export const useHostLogsUrl = (hostId: string): { url: string; appId: string; ap
};
}, [hostId, services.application]);
};

/**
* Returns an object that contains Ingest app and URL information
*/
export const useHostIngestUrl = (): { url: string; appId: string; appPath: string } => {
const { services } = useKibana();
return useMemo(() => {
const appPath = `#/fleet`;
return {
url: `${services.application.getUrlForApp('ingestManager')}${appPath}`,
appId: 'ingestManager',
appPath,
};
}, [services.application]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export const ConfigureEndpointDatasource = memo<CustomConfigureDatasourceContent
<p>
{from === 'edit' ? (
<LinkToApp
appId="siem"
appId="securitySolution"
appPath={policyUrl}
href={`${services.application.getUrlForApp('siem')}${policyUrl}`}
href={`${services.application.getUrlForApp('securitySolution')}${policyUrl}`}
>
<FormattedMessage
id="xpack.securitySolution.endpoint.ingestManager.editDatasource.stepConfigure"
Expand Down