Browse Source

Insert in db using R

master
Maxime Wack 6 years ago
parent
commit
7d955b8162
1 changed files with 10 additions and 10 deletions
  1. +10
    -10
      geoip.R

+ 10
- 10
geoip.R View File

@@ -3,16 +3,16 @@ library(RSQLite)
library(ipapi)
library(leaflet)

# sqlite3 access.db
# create table access(ip, null1, user, timestamp, zone, req, status, size, referer, agent, null2);
# .separator " "
# .import access.log access
dbConnect(SQLite(), "access.db") %>%
dbGetQuery("delete from access where ip = '192.168.0.254' or user = 'maxx' or agent like '%bot%' or ip = '164.2.255.244';")
dbConnect(SQLite(), "access.db") %>%
dbGetQuery("vacuum;")
dbConnect(SQLite(), "access.db") -> db
read_delim("access.log", delim = " ", col_names = c("ip", "null1", "user", "timestamp", "zone", "req", "status", "size", "referer", "agent", "null2")) %>%
mutate_all(na_if, "-") %>%
filter(user %>% is.na) %>%
filter(!ip %in% c("192.168.0.254", "164.2.255.244")) %>%
mutate(timestamp = timestamp %>% as.POSIXct(format = "[%d/%b/%Y:%H:%M:%S")) %>%
separate(req, into = c("method", "url", "version"), sep = " ") %>%
select(ip, timestamp, url, status, referer, agent) %>%
dbWriteTable(conn = db, name = "access", value = ., append = T)

known_ips <- character(0)



Loading…
Cancel
Save