-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #604 from SquirrelCorporation/598-feature-history-…
…of-output-for-ansible-playbook-executions [CHORE] Add task event logs retrieval and display in the UI
- Loading branch information
Showing
10 changed files
with
210 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import TerminalCoreModal, { | ||
PlaybookExecutionTerminalModalHandles, | ||
} from '@/components/PlaybookExecutionModal/PlaybookExecutionTerminalModal'; | ||
import TerminalCore, { | ||
TerminalCoreHandles, | ||
} from '@/components/Terminal/TerminalCore'; | ||
import { getTaskEventsLogs } from '@/services/rest/logs'; | ||
import { Modal } from 'antd'; | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
import { API } from 'ssm-shared-lib'; | ||
|
||
type TaskLogsTerminalModalProps = { | ||
task: API.Task; | ||
}; | ||
|
||
const TaskLogsTerminalModal: React.FC<TaskLogsTerminalModalProps> = ({ | ||
task, | ||
}) => { | ||
const terminalRef = useRef<TerminalCoreHandles>(null); | ||
const [isOpen, setIsOpen] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
if (isOpen) { | ||
terminalRef?.current?.resetTerminalContent(); | ||
getTaskEventsLogs(task.ident).then((res) => { | ||
if (!res.data || res.data.length === 0) { | ||
terminalRef?.current?.onDataIn( | ||
'No logs to show.\nSelected a higher retention period for "Ansible tasks & statuses retention in seconds" in Settings > General Settings', | ||
true, | ||
); | ||
return; | ||
} | ||
terminalRef?.current?.onDataIn( | ||
'---\n' + | ||
'# ,;;:;,\n' + | ||
'# ;;;;;\n' + | ||
"# ,:;;:; ,'=.\n" + | ||
"# ;:;:;' .=\" ,'_\\\n" + | ||
"# ':;:;,/ ,__:=@\n" + | ||
"# ';;:; =./)_\n" + | ||
'# `"=\\_ )_"`\n' + | ||
'# ``\'"`\n' + | ||
'# Squirrel Servers Manager Playbook Executor\n' + | ||
'---\n', | ||
); | ||
for (const line of res.data) { | ||
if (line.stdout) { | ||
terminalRef?.current?.onDataIn(line.stdout, true); | ||
} | ||
} | ||
}); | ||
} | ||
}, [isOpen, task.ident]); | ||
|
||
return ( | ||
<> | ||
<a | ||
key="view" | ||
onClick={() => { | ||
setIsOpen(true); | ||
}} | ||
> | ||
Show logs | ||
</a> | ||
<Modal | ||
open={isOpen} | ||
title={''} | ||
onOk={() => { | ||
setIsOpen(false); | ||
}} | ||
onCancel={() => { | ||
setIsOpen(false); | ||
}} | ||
width={1000} | ||
> | ||
<div style={{ height: '500px' }}> | ||
<TerminalCore | ||
ref={terminalRef} | ||
disableStdin={true} | ||
rows={35} | ||
cols={130} | ||
convertEol={true} | ||
/> | ||
</div> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
export default TaskLogsTerminalModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { param } from 'express-validator'; | ||
import validator from '../../../middlewares/Validator'; | ||
|
||
export const getTaskEventsValidator = [param('id').exists().notEmpty().isUUID(), validator]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import express from 'express'; | ||
import passport from 'passport'; | ||
import { getServerLogs } from '../controllers/rest/logs/server'; | ||
import { getTaskLogs } from '../controllers/rest/logs/task'; | ||
import { getTaskEvents, getTaskLogs } from '../controllers/rest/logs/task'; | ||
import { getTaskEventsValidator } from '../controllers/rest/logs/task.validator'; | ||
|
||
const router = express.Router(); | ||
|
||
router.use(passport.authenticate('jwt', { session: false })); | ||
|
||
router.get(`/server`, getServerLogs); | ||
router.get(`/tasks`, getTaskLogs); | ||
router.get(`/tasks/:id/events`, getTaskEventsValidator, getTaskEvents); | ||
|
||
export default router; |