Skip to content

Commit

Permalink
iis log file reader, closes ##23
Browse files Browse the repository at this point in the history
  • Loading branch information
almartin82 committed Nov 30, 2017
1 parent df43836 commit 041cd35
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.Rhistory
.RData
inst/doc
*.DS_Store
4 changes: 2 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

internal_split_clf <- function(requests) {
.Call(webreadr_internal_split_clf, requests)
.Call(`_webreadr_internal_split_clf`, requests)
}

internal_split_squid <- function(requests) {
.Call(webreadr_internal_split_squid, requests)
.Call(`_webreadr_internal_split_squid`, requests)
}

23 changes: 22 additions & 1 deletion R/readers.R
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,25 @@ read_s3 <- function(file){
data <- readr::read_log(file = file, col_types = types, col_names = names)
data$request_time <- readr::parse_datetime(data$request_time, format = "%d/%b/%Y:%H:%M:%S %z")
return(data)
}
}

#'@title Read Microsoft IIS Logs
#'@description \code{read_iis} provides a reader for Microsoft IIS access logs.
#'
#'@param file the full path to the IIS log file you want to read.
#'
#'@examples
#'# Using the inbuilt testing dataset
#'iis_data <- read_iis(system.file(file.path("extdata", "iis.log"), package = "webreadr"))
#'
#'@export

read_iis <- function(file){
names <- c("date", "time", "s-ip", "cs-method", "cs-uri-stem", "cs-uri-query", "s-port",
"cs-username", "c-ip", "cs(User-Agent)", "sc-status", "sc-substatus",
"sc-win32-status", "time-taken")
types <- "cccccciccciiii"
data <- readr::read_log(file = file, col_types = types, col_names = names, skip = 4)
data$date <- as.POSIXct(paste(data$date, data$time), format = "%Y-%m-%dT%H:%M:%S %z", tz = "UTC")
return(data[,!names(data) == "time"])
}
5 changes: 5 additions & 0 deletions inst/extdata/iis.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Software: Microsoft Internet Information Services 8.0
#Version: 1.0
#Date: 2016-02-15 23:44:42
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2016-02-15 23:44:42 10.10.2.18 GET / - 443 - 198.20.69.74 - - 200 0 995 29761
4 changes: 2 additions & 2 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using namespace Rcpp;

// internal_split_clf
DataFrame internal_split_clf(CharacterVector requests);
RcppExport SEXP webreadr_internal_split_clf(SEXP requestsSEXP) {
RcppExport SEXP _webreadr_internal_split_clf(SEXP requestsSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Expand All @@ -18,7 +18,7 @@ END_RCPP
}
// internal_split_squid
DataFrame internal_split_squid(CharacterVector requests);
RcppExport SEXP webreadr_internal_split_squid(SEXP requestsSEXP) {
RcppExport SEXP _webreadr_internal_split_squid(SEXP requestsSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test_readers.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ test_that("S3 files can be read",{
expect_equal(ncol(data), 18)
expect_equal(nrow(data), 6)
expect_equal(class(data$request_time), c("POSIXct","POSIXt"))
})

test_that("iis files can be read",{
data <- read_iis(system.file(file.path("extdata", "iis.log"), package = "webreadr"))
expect_equal(ncol(data), 14)
expect_equal(nrow(data), 1)
expect_equal(class(data$date), c("POSIXct","POSIXt"))
})

0 comments on commit 041cd35

Please sign in to comment.