Skip to content

Commit

Permalink
Add agent unenrolling status
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Jul 2, 2020
1 parent 4d62509 commit 2574779
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 8 deletions.
33 changes: 31 additions & 2 deletions x-pack/plugins/ingest_manager/common/openapi/spec_oas3.json
Original file line number Diff line number Diff line change
Expand Up @@ -3520,7 +3520,17 @@
]
}
},
"/fleet/agents/unenroll": {
"/fleet/agents/{agentId}/unenroll": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "agentId",
"in": "path",
"required": true
}
],
"post": {
"summary": "Fleet - Agent - Unenroll",
"tags": [],
Expand All @@ -3530,7 +3540,26 @@
{
"$ref": "#/components/parameters/xsrfHeader"
}
]
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"force": { "type": "boolean" }
}
},
"examples": {
"example-1": {
"value": {
"force": true
}
}
}
}
}
}
}
},
"/fleet/config/{configId}/agent-status": {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/ingest_manager/common/services/agent_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export function getAgentStatus(agent: Agent, now: number = Date.now()): AgentSta
if (!agent.active) {
return 'inactive';
}
if (agent.unenrollement_started_at && !agent.unenrolled_at) {
return 'unenrolling';
}
if (agent.current_error_events.length > 0) {
return 'error';
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ingest_manager/common/types/models/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type AgentType =
| typeof AGENT_TYPE_PERMANENT
| typeof AGENT_TYPE_TEMPORARY;

export type AgentStatus = 'offline' | 'error' | 'online' | 'inactive' | 'warning';
export type AgentStatus = 'offline' | 'error' | 'online' | 'inactive' | 'warning' | 'unenrolling';
export type AgentActionType = 'CONFIG_CHANGE' | 'DATA_DUMP' | 'RESUME' | 'PAUSE' | 'UNENROLL';
export interface NewAgentAction {
type: AgentActionType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
},
{
field: 'active',
width: '100px',
width: '120px',
name: i18n.translate('xpack.ingestManager.agentList.statusColumnTitle', {
defaultMessage: 'Status',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ const Status = {
/>
</EuiHealth>
),
Unenrolling: (
<EuiHealth color="warning">
<FormattedMessage
id="xpack.ingestManager.agentHealth.unenrollingStatusText"
defaultMessage="Unenrolling"
/>
</EuiHealth>
),
};

function getStatusComponent(agent: Agent): React.ReactElement {
Expand All @@ -65,6 +73,8 @@ function getStatusComponent(agent: Agent): React.ReactElement {
return Status.Offline;
case 'warning':
return Status.Warning;
case 'unenrolling':
return Status.Unenrolling;
default:
return Status.Online;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const AgentUnenrollProvider: React.FunctionComponent<Props> = ({ children
const successMessage = i18n.translate(
'xpack.ingestManager.unenrollAgents.successSingleNotificationTitle',
{
defaultMessage: "Unenrolled agent '{id}'",
defaultMessage: "Unenrolling agent '{id}'",
values: { id: agentId },
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export const postAgentsUnenrollHandler: RequestHandler<
const soClient = context.core.savedObjects.client;
try {
if (request.body?.force === true) {
await AgentService.unenrollAgent(soClient, request.params.agentId);
} else {
await AgentService.forceUnenrollAgent(soClient, request.params.agentId);
} else {
await AgentService.unenrollAgent(soClient, request.params.agentId);
}

const body: PostAgentUnenrollResponse = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const PostAgentUnenrollRequestSchema = {
params: schema.object({
agentId: schema.string(),
}),
body: schema.maybe(
body: schema.nullable(
schema.object({
force: schema.boolean(),
})
Expand Down

0 comments on commit 2574779

Please sign in to comment.