Browse Source

examples/tests/workflow

batman
boB Rudis 2 months ago
parent
commit
c01888a9a1
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
9 changed files with 65 additions and 18 deletions
  1. +3
    -1
      .github/workflows/R-CMD-check.yaml
  2. +1
    -0
      NAMESPACE
  3. +13
    -4
      R/pcap_to_zeek.R
  4. +9
    -3
      R/read-zeek-logs.R
  5. +1
    -1
      R/zeekr-package.R
  6. +16
    -2
      inst/tinytest/test_zeekr.R
  7. +4
    -1
      man/find_zeek.Rd
  8. +9
    -3
      man/pcap_to_zeek.Rd
  9. +9
    -3
      man/read_zeek_logs.Rd

+ 3
- 1
.github/workflows/R-CMD-check.yaml View File

@ -6,7 +6,7 @@ on:
- batman
pull_request:
branches:
- batmsn
- batman
name: R-CMD-check
@ -16,6 +16,8 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-r@master
- name: Install Zeek
uses: brew install zeek
- name: Install dependencies
run: |
install.packages(c("remotes", "rcmdcheck"))


+ 1
- 0
NAMESPACE View File

@ -12,3 +12,4 @@ import(ndjson)
importFrom(tools,file_ext)
importFrom(tools,file_path_sans_ext)
importFrom(utils,browseURL)
importFrom(utils,help)

+ 13
- 4
R/pcap_to_zeek.R View File

@ -15,9 +15,15 @@
#' look for the `zeek` binary.
#' @export
#' @examples
#' loc <- pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr"))
#' read_zeek_logs(loc)
#' unlink(loc) # don't do this IRL until you're done working with or saving.
#' loc <- tryCatch(
#' pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr")),
#' error = function(e) message("No Zeek")
#' )
#'
#' if (!is.null(loc)) {
#' read_zeek_logs(loc)
#' unlink(loc) # don't do this IRL until you're done working with or saving.
#' }
pcap_to_zeek <- function(pcap, out_dir = tempfile(pattern = "zeek"), zeek_opts = c(), ...) {
pcap <- path.expand(pcap[1])
@ -84,7 +90,10 @@ pcap_to_zeek <- function(pcap, out_dir = tempfile(pattern = "zeek"), zeek_opts =
#' @export
#' @return length 1 character vector of the path to the zeek binary or `""`
#' @examples
#' find_zeek()
#' loc <- tryCatch(
#' find_zeek(),
#' error = function(e) message("No Zeek")
#' )
find_zeek <- function(path = Sys.getenv("ZEEK_PATH", "")) {
if (path != "") {


+ 9
- 3
R/read-zeek-logs.R View File

@ -4,9 +4,15 @@
#' @param log_dir directory of zeek logs
#' @export
#' @examples
#' loc <- pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr"))
#' read_zeek_logs(loc)
#' unlink(loc) # don't do this IRL until you're done working with or saving.
#' loc <- tryCatch(
#' pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr")),
#' error = function(e) message("No Zeek")
#' )
#'
#' if (!is.null(loc)) {
#' read_zeek_logs(loc)
#' unlink(loc) # don't do this IRL until you're done working with or saving.
#' }
read_zeek_logs <- function(log_dir) {
log_dir <- path.expand(log_dir[1])


+ 1
- 1
R/zeekr-package.R View File

@ -10,6 +10,6 @@
#' @author Bob Rudis (bob@@rud.is)
#' @import arrow
#' @import ndjson
#' @importFrom utils browseURL
#' @importFrom utils browseURL help
#' @importFrom tools file_path_sans_ext file_ext
"_PACKAGE"

+ 16
- 2
inst/tinytest/test_zeekr.R View File

@ -1,4 +1,18 @@
library(zeekr)
# Placeholder with simple test
expect_equal(1 + 1, 2)
if (Sys.info()["sysname"] == "Darwin") {
Sys.setenv(ZEEK_PATH = "/opt/homebrew/bin:/usr/local/bin")
loc <- tryCatch(
pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr")),
error = function(e) message("No Zeek")
)
if (!is.null(loc)) {
read_zeek_logs(loc)
unlink(loc)
}
}

+ 4
- 1
man/find_zeek.Rd View File

@ -17,5 +17,8 @@ Use the environment variable \code{ZEEK_PATH} or specify the directory in
the call to this function.
}
\examples{
find_zeek()
loc <- tryCatch(
find_zeek(),
error = function(e) message("No Zeek")
)
}

+ 9
- 3
man/pcap_to_zeek.Rd View File

@ -32,7 +32,13 @@ environment variable \code{ZEEK_PATH} as a hint where \code{\link[=find_zeek]{fi
look for the \code{zeek} binary.
}
\examples{
loc <- pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr"))
read_zeek_logs(loc)
unlink(loc) # don't do this IRL until you're done working with or saving.
loc <- tryCatch(
pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr")),
error = function(e) message("No Zeek")
)
if (!is.null(loc)) {
read_zeek_logs(loc)
unlink(loc) # don't do this IRL until you're done working with or saving.
}
}

+ 9
- 3
man/read_zeek_logs.Rd View File

@ -16,7 +16,13 @@ Read zeek logs from a processed PCAP into a list
Logs must be in Parquet or JSON format.
}
\examples{
loc <- pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr"))
read_zeek_logs(loc)
unlink(loc) # don't do this IRL until you're done working with or saving.
loc <- tryCatch(
pcap_to_zeek(system.file("pcap/ssh.pcap", package = "zeekr")),
error = function(e) message("No Zeek")
)
if (!is.null(loc)) {
read_zeek_logs(loc)
unlink(loc) # don't do this IRL until you're done working with or saving.
}
}

Loading…
Cancel
Save