apache-log-geo 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/apache-log-geo +3 -0
  4. data/lib.rb +1 -0
  5. data/mmdb-lookup +13 -9
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b688bc33811dda59d01daba379846ea91eca0e7b2d125739f0e7f98c327985d6
4
- data.tar.gz: 1e69c302666c3b5f38458af38f0a4094f82a9e12fe3f52bd1008a91cac4bae96
3
+ metadata.gz: 34da9d9d49ed08a9b3c0fc01aafd3051de023dc0632909d804cb4640d5cbff00
4
+ data.tar.gz: fb5d34390295623bfacfb093f28cd4ccf794dc6bd34f0fb65b4c3f042230f085
5
5
  SHA512:
6
- metadata.gz: '0184047e4a91342815ddbf89dd4bf0cc2745b4aeb0f6ecb82416d498c9363f46566f0b423d16ac71c60d29f04accef9069ab12590542ecd553491956f96f29cc'
7
- data.tar.gz: 3ce1c92a2d35de14ec126193b9196332cdba6a1b67ca173fceaf0483e346ddd7b1b655d9ab0e5c1277b98414e9c69ded4fe06a3500a1cc02c958c8aeaacef707
6
+ metadata.gz: 1b90aea1bf592f196d8573b41f8e938163d78411c13246847d126f5e231c5653a41614df5168efbccda596ea9f5b122b3fa3e79c1a5d528a88cac70448b81a31
7
+ data.tar.gz: ff158b0ad399224776055d414c7b84fc52fee9c08ee3b500e20bfa19ecb6ae0d032257487e19d48ee392291381b351ad762394a028757faabfdbae5c8be0c28d
data/README.md CHANGED
@@ -79,8 +79,8 @@ $ cat test/access.log | ./apache-log-geo --cc 'ie|de' | wc -l
79
79
 
80
80
  ### mmdb-lookup
81
81
 
82
- Renders the data about ip addresses in json (default) or a suitable
83
- for a shell script formats:
82
+ Renders data about ip addresses in newline-delimited json (default) or
83
+ in a shell script ready format:
84
84
 
85
85
  ~~~
86
86
  $ ./mmdb-lookup -h
@@ -104,7 +104,7 @@ Kyiv City
104
104
  Replicate `apache-log-geo` util--print only the requests from the Irish
105
105
  (the example requires `npm -g json`):
106
106
 
107
- $ cat test/access.log | ./mmdb-lookup | json -c 'this.country_code == "IE"' -a ip | grep -h -f - test/access.log
107
+ $ cat test/access.log | ./mmdb-lookup | json -g -c 'this.country_code == "IE"' -a ip | grep -h -f - test/access.log
108
108
 
109
109
  ## Exit status
110
110
 
@@ -54,6 +54,9 @@ rescue
54
54
  errx 2, $!
55
55
  end
56
56
 
57
+ Signal.trap 'SIGINT', sigint_handler
58
+ Signal.trap 'SIGPIPE', sigint_handler
59
+
57
60
  found_anything = false
58
61
  $stdin.each_line do |line|
59
62
  next if line =~ /^\s*$/
data/lib.rb CHANGED
@@ -19,6 +19,7 @@ module ApacheLogGeo
19
19
  end
20
20
 
21
21
  def warnx msg; $stderr.puts "#{File.basename $0} warning: #{msg}"; end
22
+ def sigint_handler; proc {|s| puts ""; exit 128+s }; end
22
23
 
23
24
  # https://datahub.io/core/country-list
24
25
  COUNTRY_CODES = {
@@ -5,8 +5,8 @@ require_relative 'lib'
5
5
  include ApacheLogGeo
6
6
 
7
7
  class FMT
8
- def initialize input, geo
9
- @input = input; @geo = geo
8
+ def initialize input, geo, callback
9
+ @input = input; @geo = geo; @cb = method(callback)
10
10
  @errors = 0
11
11
  end
12
12
  attr_accessor :errors
@@ -24,7 +24,7 @@ class FMT
24
24
  "#{k}=#{(v.is_a?(Array) ? v.join(',') : v.to_s).shellescape}"
25
25
  end
26
26
  end
27
- r.join "\n"
27
+ @cb.call r.join "\n"
28
28
  end
29
29
 
30
30
  def json
@@ -36,11 +36,12 @@ class FMT
36
36
  end
37
37
 
38
38
  if @input.is_a?(IO) # stdin, in which we expect an apache log
39
- @input.map { |line| trans.call line.split[0] }.to_json
39
+ @input.each_line do |line|
40
+ next if line =~ /^\s*$/
41
+ @cb.call trans.call(line.split[0]).to_json
42
+ end
40
43
  else # argv
41
- @input.map do |list|
42
- list.split.map { |ip| trans.call ip }
43
- end.flatten.to_json
44
+ @input.map {|ip| @cb.call trans.call(ip).to_json }
44
45
  end
45
46
  end
46
47
  end
@@ -66,6 +67,9 @@ rescue
66
67
  errx 2, $!
67
68
  end
68
69
 
69
- fmt = FMT.new (ARGV.size > 0 ? ARGV : $stdin), geo
70
- puts fmt.send opt[:fmt]
70
+ Signal.trap 'SIGINT', sigint_handler
71
+ Signal.trap 'SIGPIPE', sigint_handler
72
+
73
+ fmt = FMT.new (ARGV.size > 0 ? ARGV : $stdin), geo, :puts
74
+ fmt.send opt[:fmt]
71
75
  exit fmt.errors > 0 ? 1 : 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apache-log-geo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Gromnitsky
8
8
  autorequire:
9
9
  bindir: "."
10
10
  cert_chain: []
11
- date: 2020-03-10 00:00:00.000000000 Z
11
+ date: 2020-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: maxmind-db