diff --git a/monkey/monkey_island/cc/ui/src/components/pages/TelemetryPage.js b/monkey/monkey_island/cc/ui/src/components/pages/TelemetryPage.js index 85913b432..e0ea0221e 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/TelemetryPage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/TelemetryPage.js @@ -1,58 +1,24 @@ import React from 'react'; import {Button, Col} from 'react-bootstrap'; -import JSONTree from 'react-json-tree'; -import MUIDataTable from 'mui-datatables'; -import AuthComponent from '../AuthComponent'; +import AuthService from '../../services/AuthService'; import download from 'downloadjs'; +import TelemetryLogTable from '../ui-components/TelemetryLogTable' import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import '../../styles/pages/TelemetryPage.scss'; import {faDownload} from '@fortawesome/free-solid-svg-icons/faDownload'; -const renderJson = (val) => ; -const renderTime = (val) => val.split('.')[0]; -const columns = [ - {label: 'Time', name: 'timestamp'}, - {label: 'Monkey', name: 'monkey'}, - {label: 'Type', name: 'telem_category'}, - {label: 'Details', name: 'data', options: { setCellProps: () => ({ style: { width: '40%' }})}} -]; - -const table_options = { - filterType: 'textField', - sortOrder: { - name: 'timestamp', - direction: 'desc' - }, - print: false, - download: false, - rowHover: false, - rowsPerPage: 20, - rowsPerPageOptions: [20, 50, 100], - selectableRows: 'none' - }; - -class TelemetryPageComponent extends AuthComponent { +class TelemetryPageComponent extends React.Component { constructor(props) { super(props); + this.auth = new AuthService(); + this.authFetch = this.auth.authFetch; this.state = { - data: [], - isFetching: false + data: [] }; } - componentDidMount = () => { - this.authFetch('/api/telemetry') - .then(res => res.json()) - .then(res => {this.setState({data: res.objects}) - }) - .catch(e => { - console.log(e); - this.setState({...this.state}); - }); - }; - downloadIslandLog = () => { this.authFetch('/api/log/island/download') .then(res => res.json()) @@ -70,21 +36,7 @@ class TelemetryPageComponent extends AuthComponent { className={'main'}>

Logs

-
- { - return [ - renderTime(item.timestamp), - item.monkey, - item.telem_category, - renderJson(item.data) - ] - }) - } - options={table_options} - /> -
+

Monkey Island Logs

diff --git a/monkey/monkey_island/cc/ui/src/components/ui-components/TelemetryLogTable.js b/monkey/monkey_island/cc/ui/src/components/ui-components/TelemetryLogTable.js new file mode 100644 index 000000000..9823f7ffb --- /dev/null +++ b/monkey/monkey_island/cc/ui/src/components/ui-components/TelemetryLogTable.js @@ -0,0 +1,75 @@ +import React from 'react'; +import JSONTree from 'react-json-tree'; +import MUIDataTable from 'mui-datatables'; +import AuthService from '../../services/AuthService'; +import '../../styles/pages/TelemetryPage.scss'; + +const renderJson = (val) => ; +const renderTime = (val) => val.split('.')[0]; + +const columns = [ + {label: 'Time', name: 'timestamp'}, + {label: 'Monkey', name: 'monkey'}, + {label: 'Type', name: 'telem_category'}, + {label: 'Details', + name: 'data', + options: { + setCellProps: () => ({ style: { width: '40%' }}), + filter:false, + sort:false + } + } +]; + +const table_options = { + filterType: 'textField', + sortOrder: { + name: 'timestamp', + direction: 'desc' + }, + print: false, + download: false, + rowHover: false, + rowsPerPageOptions: [10, 20, 50, 100], + selectableRows: 'none' +}; + +class TelemetryLogTable extends React.Component { + constructor(props) { + super(props); + this.auth = new AuthService(); + this.authFetch = this.auth.authFetch; + this.state = { + data: [] + }; + } + + componentDidMount = () => { + this.authFetch('/api/telemetry') + .then(res => res.json()) + .then(res => {this.setState({data: res.objects}) + }) + }; + + render() { + return ( + <> +
+ { + return [ + renderTime(item.timestamp), + item.monkey, + item.telem_category, + renderJson(item.data) + ]})} + options={table_options} + /> +
+ + ); + } +} + +export default TelemetryLogTable;