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

notify on failures #1617

Merged
merged 3 commits into from
May 7, 2021
Merged
Changes from 2 commits
Commits
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
26 changes: 20 additions & 6 deletions plugins/brimcap/brimcap-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,16 @@ export default class BrimcapPlugin {
// )

const tsString = ts.toString()
const dur = log.get("duration") as zed.Duration
const dur = log.try("duration") as zed.Duration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try can return null. In the returned object, check for null before calling isSet().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@mason-fish mason-fish May 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait I misunderstood, disregard last message. Just pushed a fix.

const dest = join(
this.api.getTempDir(),
`packets-${ts.toString()}.pcap`.replaceAll(":", "_")
`packets-${tsString}.pcap`.replaceAll(":", "_")
)

return {
dstIp: log.get("id.resp_h").toString(),
dstPort: log.get("id.resp_p").toString(),
duration: dur.isSet() ? dur.toString() : "0s",
duration: dur?.isSet() ? dur.toString() : "0s",
proto: log.get("proto").toString(),
root: this.brimcapDataRoot,
srcIp: log.get("id.orig_h").toString(),
Expand All @@ -197,10 +197,24 @@ export default class BrimcapPlugin {
}

private async downloadPcap(log: zed.Record) {
const searchOpts = this.logToSearchOpts(log)
let searchOpts
try {
searchOpts = this.logToSearchOpts(log)
} catch (e) {
console.error(e)
this.api.toast.error("Missing 5-tuple from log")
return
}

const searchAndOpen = async () => {
this.cli.search(searchOpts)
const res = await this.cli.search(searchOpts)
if (res.status > 0) {
const err = res.stderr.toString()
const msg = JSON.parse(err)?.error || `brimcap search failed: ${err}`

throw new Error(msg)
}

return await open(searchOpts.write, {newWindow: true})
}

Expand All @@ -211,7 +225,7 @@ export default class BrimcapPlugin {
success: "Preparation Complete",
error: (err) => {
console.error(err)
return "Error Preparing PCAP"
return "Error Preparing PCAP: " + err.message
}
},
this.toastConfig
Expand Down