Task/host isolation status pending (#103549) (#103604)

This commit is contained in:
Candace Park 2021-06-29 00:04:34 -04:00 committed by GitHub
parent 0fd977acc8
commit 225bc22a68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 7 deletions

View file

@ -183,7 +183,7 @@ const AlertSummaryViewComponent: React.FC<{
return endpointAlertCheck({ data });
}, [data]);
const agentId = useMemo(() => {
const endpointId = useMemo(() => {
const findAgentId = find({ category: 'agent', field: 'agent.id' }, data)?.values;
return findAgentId ? findAgentId[0] : '';
}, [data]);
@ -194,7 +194,7 @@ const AlertSummaryViewComponent: React.FC<{
contextId: timelineId,
eventId,
fieldName: 'agent.status',
value: agentId,
value: endpointId,
linkValue: undefined,
},
};

View file

@ -42,3 +42,8 @@ export const ISOLATION_STATUS_FAILURE = i18n.translate(
'xpack.securitySolution.endpoint.hostIsolation.isolationStatus.title',
{ defaultMessage: 'Failed to retrieve current isolation status' }
);
export const ISOLATION_PENDING_FAILURE = i18n.translate(
'xpack.securitySolution.endpoint.hostIsolation.isolationPending.title',
{ defaultMessage: 'Failed to retrieve isolation pending statuses' }
);

View file

@ -9,7 +9,8 @@ import { isEmpty } from 'lodash';
import { useEffect, useState } from 'react';
import { useAppToasts } from '../../../../common/hooks/use_app_toasts';
import { getHostMetadata } from './api';
import { ISOLATION_STATUS_FAILURE } from './translations';
import { ISOLATION_STATUS_FAILURE, ISOLATION_PENDING_FAILURE } from './translations';
import { fetchPendingActionsByAgentId } from '../../../../common/lib/endpoint_pending_actions';
import { isEndpointHostIsolated } from '../../../../common/utils/validators';
import { HostStatus } from '../../../../../common/endpoint/types';
@ -17,6 +18,8 @@ interface HostIsolationStatusResponse {
loading: boolean;
isIsolated: boolean;
agentStatus: HostStatus;
pendingIsolation: number;
pendingUnisolation: number;
}
/*
@ -28,6 +31,8 @@ export const useHostIsolationStatus = ({
}): HostIsolationStatusResponse => {
const [isIsolated, setIsIsolated] = useState<boolean>(false);
const [agentStatus, setAgentStatus] = useState<HostStatus>(HostStatus.UNHEALTHY);
const [pendingIsolation, setPendingIsolation] = useState(0);
const [pendingUnisolation, setPendingUnisolation] = useState(0);
const [loading, setLoading] = useState(false);
const { addError } = useAppToasts();
@ -35,16 +40,29 @@ export const useHostIsolationStatus = ({
useEffect(() => {
// isMounted tracks if a component is mounted before changing state
let isMounted = true;
let fleetAgentId: string;
const fetchData = async () => {
try {
const metadataResponse = await getHostMetadata({ agentId });
if (isMounted) {
setIsIsolated(isEndpointHostIsolated(metadataResponse.metadata));
setAgentStatus(metadataResponse.host_status);
fleetAgentId = metadataResponse.metadata.elastic.agent.id;
}
} catch (error) {
addError(error.message, { title: ISOLATION_STATUS_FAILURE });
}
try {
const { data } = await fetchPendingActionsByAgentId(fleetAgentId);
if (isMounted) {
setPendingIsolation(data[0].pending_actions?.isolate ?? 0);
setPendingUnisolation(data[0].pending_actions?.unisolate ?? 0);
}
} catch (error) {
addError(error.message, { title: ISOLATION_PENDING_FAILURE });
}
if (isMounted) {
setLoading(false);
}
@ -64,5 +82,5 @@ export const useHostIsolationStatus = ({
isMounted = false;
};
}, [addError, agentId]);
return { loading, isIsolated, agentStatus };
return { loading, isIsolated, agentStatus, pendingIsolation, pendingUnisolation };
};

View file

@ -24,7 +24,12 @@ export const AgentStatuses = React.memo(
eventId: string;
value: string;
}) => {
const { isIsolated, agentStatus } = useHostIsolationStatus({ agentId: value });
const {
isIsolated,
agentStatus,
pendingIsolation,
pendingUnisolation,
} = useHostIsolationStatus({ agentId: value });
const isolationFieldName = 'host.isolation';
return (
<EuiFlexGroup gutterSize="none">
@ -45,7 +50,11 @@ export const AgentStatuses = React.memo(
tooltipContent={isolationFieldName}
value={`${isIsolated}`}
>
<EndpointHostIsolationStatus isIsolated={isIsolated} />
<EndpointHostIsolationStatus
isIsolated={isIsolated}
pendingIsolate={pendingIsolation}
pendingUnIsolate={pendingUnisolation}
/>
</DefaultDraggable>
</EuiFlexItem>
</EuiFlexGroup>

View file

@ -126,7 +126,7 @@ const FormattedFieldValueComponent: React.FC<{
contextId={contextId}
eventId={eventId}
fieldName={fieldName}
value={value as string}
value={typeof value === 'string' ? value : ''}
/>
);
} else if (