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

Zed JS #1603

Merged
merged 44 commits into from
May 4, 2021
Merged

Zed JS #1603

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
444d841
WIP
jameskerr Apr 14, 2021
3022764
Updated to most recent branch
jameskerr Apr 15, 2021
1aeaebf
Work in progress
jameskerr Apr 19, 2021
d2b3edf
Zed is done
jameskerr Apr 19, 2021
a7b447e
No typescript errors
jameskerr Apr 20, 2021
d144e80
Tests green
jameskerr Apr 20, 2021
95db2db
Removed most of cell.ts only need to guess width
jameskerr Apr 21, 2021
918dc13
Started zed types implementation
jameskerr Apr 22, 2021
b4de42d
got a test passing
jameskerr Apr 23, 2021
afacc2d
Snapshot
jameskerr Apr 28, 2021
f362eda
20 errors left
jameskerr Apr 28, 2021
26a9d42
Zero errors
jameskerr Apr 28, 2021
ebd916d
Fixed viewer-search test
jameskerr Apr 29, 2021
7c6b089
Need to rebase
jameskerr Apr 29, 2021
587e59d
Merge branch 'main' into zed-js-draft
jameskerr Apr 29, 2021
0378309
TS Errors Fixed
jameskerr Apr 29, 2021
8658ad1
All tests pass
jameskerr Apr 29, 2021
068f037
Fixed api tests
jameskerr Apr 29, 2021
6d8d196
Guessing widths again
jameskerr Apr 29, 2021
ba73876
Working on itests
jameskerr Apr 30, 2021
0642a34
Fixed ingest itest
jameskerr May 3, 2021
d4b768c
Fixed query test
jameskerr May 3, 2021
2170253
Refactor context menu integration tests
jameskerr May 3, 2021
59ce8ff
Fix pcap integration tests
jameskerr May 3, 2021
3234691
Fixed unit tests
jameskerr May 3, 2021
58b7248
Fix lint
jameskerr May 3, 2021
172a691
Added array renderer
jameskerr May 3, 2021
486fdf3
Merge branch 'main' into zed-js
jameskerr May 3, 2021
23e3c62
Update zed branch
jameskerr May 3, 2021
f9c49fb
Clean up straggler files
jameskerr May 4, 2021
2fc56db
No colons in pcap names
jameskerr May 4, 2021
19545f9
Update zed to master
jameskerr May 4, 2021
6d3f120
Merge remote-tracking branch 'origin/main' into zed-js
jameskerr May 4, 2021
c370cba
Cleanup commented out code
jameskerr May 4, 2021
b5f8166
Remove unused test file
jameskerr May 4, 2021
49f45cc
Remove old reference files
jameskerr May 4, 2021
23274d2
Remove unused file
jameskerr May 4, 2021
1df4971
Handle 64 bit integers
jameskerr May 4, 2021
788b991
Delete old script
jameskerr May 4, 2021
ed67242
Remove old scaffold file
jameskerr May 4, 2021
5845d88
Remove extra null check
jameskerr May 4, 2021
badbe8b
Revert "Handle 64 bit integers"
jameskerr May 4, 2021
dc21f59
Removed unused file
jameskerr May 4, 2021
914e47c
Put the zeek and suricata colors back in
jameskerr May 4, 2021
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
10 changes: 10 additions & 0 deletions app/core/formatters/format-zed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import brim from "src/js/brim"
import {withCommas} from "src/js/lib/fmt"
import {zed} from "zealot"

export function formatPrimitive(data: zed.Primitive) {
if (data.isUnset()) return "⦻"
if (zed.isInt(data)) return withCommas(data.toString())
if (zed.isTime(data)) return brim.time(data.toDate()).format()
return data.toString()
}
8 changes: 4 additions & 4 deletions app/core/hooks/useSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import {useEffect, useState} from "react"
import {useDispatch} from "react-redux"
import {search} from "src/js/flows/search/mod"
import {AppDispatch} from "src/js/state/types"
import {zng} from "zealot"
import {zed} from "zealot"

type R = [zng.Record[], boolean]
type R = [zed.Record[], boolean]

export default function useSearch(query: string, deps?: any[]): R {
const dispatch = useDispatch<AppDispatch>()
const [records, setRecords] = useState<zng.Record[]>([])
const [records, setRecords] = useState<zed.Record[]>([])
const [isFetching, setIsFetching] = useState<boolean>(true)

useEffect(() => {
setIsFetching(true)
const {response, abort} = dispatch(search({query}))
response.chan(0, (records) => setRecords(records))
response.chan(0, ({rows}) => setRecords(rows))
response.status((status) => setIsFetching(status === "FETCHING"))
return abort
}, deps)
Expand Down
4 changes: 3 additions & 1 deletion app/core/hooks/useStoreExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import {useEffect} from "react"
import {useDispatch, useSelector} from "react-redux"
import LogDetails from "src/js/state/LogDetails"
import Viewer from "src/js/state/Viewer"
import {ZealotContext} from "zealot"
import {executeCommand} from "../../../src/js/flows/executeCommand"

const useStoreExport = () => {
const currentData = useSelector(LogDetails.build)
const dispatch = useDispatch()
const zjson = currentData ? ZealotContext.encodeRecord(currentData) : null

useEffect(() => {
dispatch(executeCommand("data-detail:current", currentData?.serialize()))
dispatch(executeCommand("data-detail:current", zjson))
}, [currentData])

const selectedData = useSelector(Viewer.getSelectedRecords)
Expand Down
10 changes: 10 additions & 0 deletions app/core/utils/type-class-names.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {zed} from "zealot"

export function typeClassNames(data: zed.AnyValue) {
const classNames = []
if (data instanceof zed.Primitive) {
classNames.push(data.type.name)
}
if (data.isUnset()) classNames.push("null")
return classNames.join(" ")
}
29 changes: 14 additions & 15 deletions app/detail/Fields.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import {useDispatch} from "react-redux"
import React, {memo, useCallback, useMemo, useState} from "react"

import {zng} from "zealot"
import {Data, Name, Value} from "app/core/Data"
import {createCell} from "src/js/brim/cell"
import {formatPrimitive} from "app/core/formatters/format-zed"
import {typeClassNames} from "app/core/utils/type-class-names"
import React, {memo, useCallback, useMemo, useState} from "react"
import {useDispatch} from "react-redux"
import BrimTooltip from "src/js/components/BrimTooltip"
import ColumnDescription from "src/js/components/LogDetails/ColumnDescription"

import PanelHeading from "./PanelHeading"
import Panel from "./Panel"
import {zed} from "zealot"
import contextMenu from "./flows/contextMenu"
import Panel from "./Panel"
import PanelHeading from "./PanelHeading"

type Props = {
record: zng.Record
record: zed.Record
}

type DTProps = {
fields: zng.Field[]
onRightClick: (f: zng.Field) => void
onHover: (f: zng.Field) => void
fields: zed.Field[]
onRightClick: (f: zed.Field) => void
onHover: (f: zed.Field) => void
}

const DataPanel = React.memo<DTProps>(function DataTable({
Expand All @@ -34,10 +33,10 @@ const DataPanel = React.memo<DTProps>(function DataTable({
<TooltipAnchor>{field.name}</TooltipAnchor>
</Name>
<Value
className={field.data.getType()}
className={typeClassNames(field.data)}
onContextMenu={() => onRightClick(field)}
>
{createCell(field).display()}
{formatPrimitive(field.data as zed.Primitive)}
</Value>
</Data>
))}
Expand Down Expand Up @@ -85,7 +84,7 @@ export default memo(function Fields({record}: Props) {

const fields = useMemo(() => {
if (!record) return []
else return record.flatten().getFields()
else return record.flatten().fields
}, [record])

return (
Expand Down
6 changes: 3 additions & 3 deletions app/detail/Pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import ConnPanel from "src/js/components/LogDetails/ConnPanel"
import {Md5Panel} from "src/js/components/LogDetails/Md5Panel"
import LogDetails from "src/js/state/LogDetails"
import styled from "styled-components"
import {zng} from "zealot"
import Fields from "./Fields"
import NoSelection from "./NoSelection"
import {zed} from "zealot"

const BG = styled.div`
padding: 12px;
Expand All @@ -24,15 +24,15 @@ const BG = styled.div`
`

type Props = {
record: zng.Record
record: zed.Record
}

const Content = memo<Props>(function Content({record}) {
const event = useMemo(() => BrimEvent.build(record), [record])
const isZeek = event instanceof ZeekEvent
const isSuricata = event instanceof SuricataEvent
const {uid, cid} = new Correlation(record).getIds()
const isConn = isZeek && record.try("_path").toString() === "conn"
const isConn = isZeek && record.try("_path")?.toString() === "conn"
const hasMd5 = isZeek && record.has("md5")

return (
Expand Down
21 changes: 7 additions & 14 deletions app/detail/flows/contextMenu.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import detailFieldContextMenu from "ppl/menus/detailFieldContextMenu"
import searchFieldContextMenu from "ppl/menus/searchFieldContextMenu"
import {showContextMenu} from "src/js/lib/System"
import Columns from "src/js/state/Columns"
import SearchBar from "src/js/state/SearchBar"
import {zng} from "zealot"
import {zed} from "zealot"

const contextMenu = (field: zng.Field, record: zng.Record) => (_, getState) => {
const program = SearchBar.getSearchProgram(getState())
const tableColumns = Columns.getCurrentTableColumns(getState())
const columns = tableColumns.getColumns().map((c) => c.name)
const builder =
global.windowName === "detail"
? detailFieldContextMenu
: searchFieldContextMenu

showContextMenu(builder(program, columns)(field, record, false))
const contextMenu = (field: zed.Field, record: zed.Record) => (dispatch) => {
if (global.windowName === "detail") {
dispatch(detailFieldContextMenu({field, record, value: field.value}))
} else {
dispatch(searchFieldContextMenu({field, record, value: field.value}))
}
}

export default contextMenu
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Object {
"keys": Array [
"capture_loss",
"conn",
"files",
"x509",
"ssl",
"files",
"dns",
"weird",
"stats",
Expand Down
Loading