Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

Commit 69a2131

Browse files
authored
0.1.7 (#21)
* Change from 'dont_block' to 'blocking_mode' * added metric for calls to iprepd * Fix statsd metrics err; submit dns_timeout metric * Added --no-cache flag to docker build command * Added dns_timeout to metrics table in README * Add logging for not being able to send error metric
1 parent 5cab782 commit 69a2131

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
IMAGE_NAME := "iprepd-nginx"
22

33
build: Dockerfile
4-
docker build -t $(IMAGE_NAME) .
4+
docker build --no-cache -t $(IMAGE_NAME) .
55

66
run_dev: Dockerfile
77
docker run \

README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ violations for your environment.
9292
-- statsd_max_buffer_count - Max number of metrics in buffer before metrics should be submitted
9393
-- to statsd (defaults to 100)
9494
-- statsd_flush_timer - Interval for attempting to flush the stats in seconds. (defaults to 5)
95-
-- dont_block - Enables (1) or disables (0) not blocking within nginx by returning
96-
-- a 403. (defaults to disabled)
95+
-- blocking_mode - Enables (1) or disables (0) blocking within nginx by returning a
96+
-- 403. (defaults to disabled)
9797
-- verbose - Enables (1) or disables (0) verbose logging. Messages are logged with a
9898
-- severity of "ERROR" so that nginx log levels do not need to be changed. (defaults
9999
-- to disabled)
@@ -111,7 +111,7 @@ client = require("resty.iprepd").new({
111111
statsd_port = 8125,
112112
statsd_max_buffer_count = 100,
113113
statsd_flush_timer = 10,
114-
dont_block = 0,
114+
blocking_mode = 0,
115115
verbose = 0,
116116
whitelist = {"127.0.0.1", "10.10.10.0/24", "192.168.0.0/16"}
117117
})
@@ -124,11 +124,13 @@ client = require("resty.iprepd").new({
124124
| name | type | description |
125125
|---|---|---|
126126
| iprepd.status.below_threshold | count | The reputation for the client ip is below the configured threshold. |
127-
| iprepd.status.rejected | count | The request was blocked (won’t be sent if `dont_block` is enabled). |
128-
| iprepd.status.accepted | count | The reputation for the client ip is above the configured threshold and was accepted. |
127+
| iprepd.status.rejected | count | The request was blocked (won’t be sent if `blocking_mode` is disabled). |
128+
| iprepd.status.accepted | count | The request was accepted. The reputation can still be below the threshold if `blocking_mode` is disabled.
129+
| iprepd.get_reputation | count | Request to iprepd |
129130
| iprepd.err.timeout | count | Request to iprepd timed out |
130131
| iprepd.err.500 | count | Got a 500 response from iprepd |
131132
| iprepd.err.401 | count | Got a 401 response from iprepd, usually means the API key in use is invalid or being sent incorrectly by nginx. |
133+
| iprepd.err.dns_timeout | count | DNS resolution of the iprepd URL's domain name timed out. Make sure to check nginx's [resolver_timeout](https://nginx.org/en/docs/http/ngx_http_core_module.html#resolver_timeout) setting |
132134
| iprepd.err.* | count | Got an error while sending a request to iprepd. This could be other 4xx or 5xx status codes for example. |
133135

134136

@@ -226,5 +228,5 @@ STATSD_HOST=127.0.0.1
226228
STATSD_PORT=8125
227229
STATSD_MAX_BUFFER_COUNT=200
228230
STATSD_FLUSH_TIMER=2
229-
DONT_BLOCK=0
231+
BLOCKING_MODE=0
230232
```

dist.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = iprepd-nginx
22
abstract = iprepd openresty module
33
author = AJ Bahnken (ajvb)
4-
version = 0.1.6
4+
version = 0.1.7
55
is_original = yes
66
license = mozilla2
77
lib_dir = lib

etc/conf.d/server.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ init_by_lua_block {
1010
statsd_port = tonumber(os.getenv("STATSD_PORT")) or 8125,
1111
statsd_max_buffer_count = tonumber(os.getenv("STATSD_MAX_BUFFER_COUNT")) or 100,
1212
statsd_flush_timer = tonumber(os.getenv("STATSD_FLUSH_TIMER")) or 5,
13-
dont_block = tonumber(os.getenv("DONT_BLOCK")) or 0,
13+
blocking_mode = tonumber(os.getenv("BLOCKING_MODE")) or 0,
1414
verbose = tonumber(os.getenv("VERBOSE")) or 0,
1515
whitelist = {},
1616
})

lib/resty/iprepd.lua

+12-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function _M.new(options)
5555
statsd_port = options.statsd_port or 8125,
5656
statsd_max_buffer_count = options.statsd_max_buffer_count or 100,
5757
statsd_flush_timer = options.statsd_flush_timer or 5,
58-
dont_block = options.dont_block or 0,
58+
blocking_mode = options.blocking_mode or 0,
5959
verbose = options.verbose or 0,
6060
whitelist = whitelist,
6161
}
@@ -86,7 +86,7 @@ function _M.check(self, ip)
8686
self.statsd.incr("iprepd.status.below_threshold")
8787
end
8888

89-
if self.dont_block == 1 then
89+
if self.blocking_mode == 0 then
9090
ngx.log(ngx.ERR, string.format("%s is below threshold with a reputation of %d", ip, reputation))
9191
else
9292
ngx.log(ngx.ERR, string.format("%s rejected with a reputation of %d", ip, reputation))
@@ -95,8 +95,6 @@ function _M.check(self, ip)
9595
end
9696
ngx.exit(ngx.HTTP_FORBIDDEN)
9797
end
98-
99-
return
10098
end
10199
end
102100

@@ -116,9 +114,18 @@ function _M.get_reputation(self, ip)
116114
method = "GET",
117115
headers = self.api_key_hdr,
118116
})
117+
self.statsd.incr("iprepd.get_reputation")
119118
if err then
120119
if self.statsd then
121-
self.statsd.incr("iprepd.err." .. err)
120+
if string.find(err, " ") then
121+
if string.find(err, "could not be resolved") and string.find(err, "Operation timed out") then
122+
self.statsd.incr("iprepd.err.dns_timeout")
123+
else
124+
ngx.log(ngx.ERR, string.format("Could not send metric with error: %s", err))
125+
end
126+
else
127+
self.statsd.incr("iprepd.err." .. err)
128+
end
122129
end
123130
ngx.log(ngx.ERR, string.format("Error with request to iprepd: %s", err))
124131
return nil

0 commit comments

Comments
 (0)