nginx_utils 0.0.6 → 0.0.7

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.
data/README.md CHANGED
@@ -24,18 +24,18 @@ Or install it yourself as:
24
24
 
25
25
  From console:
26
26
 
27
- $ nginx_logrotate -h
28
- Usage: nginx_logrotate [options]
29
- -d, --[no-]debug Debug mode. Run only log output to STDOUT.
30
- --script_log=VAL Log file for script.
31
- --log_level=VAL Log level of script log.
32
- --root_dir=VAL Root directory of Nginx.
33
- --target_logs=VAL Specify logs of target.
34
- --retention=VAL Specify in days the retention period of log.
35
- --pid_file=VAL PID file of Nginx
36
- $ nginx_status -h
37
- Usage: nginx_status [options]
38
- --only-value The output only the value.
27
+ $ nginx_utils [status|logrotate] [options]
28
+ Commands:
29
+ nginx_utils help [COMMAND] # Describe available commands or one specific command
30
+ nginx_utils logrotate -d # Nginx logrotate
31
+ nginx_utils status example.com # Print status of Nginx
32
+
33
+ $ nginx_utils status
34
+ Active Connections: 1
35
+ Accepts: 4 Handled: 5 Requests: 51
36
+ Reading: 1 Writing: 3 Waiting: 2
37
+
38
+ $ nginx_utils logrotate
39
39
 
40
40
  From ruby:
41
41
 
@@ -12,7 +12,7 @@ module NginxUtils
12
12
  if options[:only_value]
13
13
  puts result.values.join("\t")
14
14
  else
15
- puts "Active Connections: #{result[:active_connection]}"
15
+ puts "Active Connections: #{result[:active_connections]}"
16
16
  puts "Accepts: #{result[:accepts]} Handled: #{result[:handled]} Requests: #{result[:requests]}"
17
17
  puts "Reading: #{result[:reading]} Writing: #{result[:writing]} Waiting: #{result[:waiting]}"
18
18
  end
@@ -29,15 +29,12 @@ module NginxUtils
29
29
  def parse(line)
30
30
  case @format.to_sym
31
31
  when :ltsv then
32
- row = line.split("\t").map do |f|
33
- c = f.split(":")
34
- if c == 2
35
- [c[0].to_sym, c[1]]
36
- else
37
- [c[0].to_sym, c[1..-1].join(":")]
32
+ Hash[
33
+ line.split("\t").map do |f|
34
+ a = f.split(":")
35
+ a.size > 2 ? [a[0].to_sym, a[1..-1].join(":")] : [a[0].to_sym, a[1]]
38
36
  end
39
- end
40
- Hash[row]
37
+ ]
41
38
  when :combined then
42
39
  if /([0-9.]+)\s-\s([^\s]+)\s\[(.*?)\]\s"(.*?)"\s([0-9]+)\s([0-9]+)\s"(.*?)"\s"(.*?)".*/ =~ line
43
40
  {
@@ -1,3 +1,3 @@
1
1
  module NginxUtils
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -29,7 +29,7 @@ describe "NginxUtils::CLI" do
29
29
  }
30
30
  }
31
31
 
32
- before(:each) {NginxUtils::Status.should_receive(:get).and_return(result)}
32
+ before {NginxUtils::Status.should_receive(:get).and_return(result)}
33
33
 
34
34
  it "default output" do
35
35
  args = ["status"]
@@ -37,10 +37,10 @@ describe "NginxUtils::CLI" do
37
37
  capture(:stdout) {
38
38
  NginxUtils::CLI.start(args)
39
39
  }
40
- ).to eq("Active Connections: \nAccepts: 4 Handled: 5 Requests: 51\nReading: 1 Writing: 3 Waiting: 2\n")
40
+ ).to eq("Active Connections: 1\nAccepts: 4 Handled: 5 Requests: 51\nReading: 1 Writing: 3 Waiting: 2\n")
41
41
  end
42
42
 
43
- it "only value output" do
43
+ it "only value output" do
44
44
  args = ["status", "--only_value"]
45
45
  expect(
46
46
  capture(:stdout) {
@@ -51,62 +51,63 @@ describe "NginxUtils::CLI" do
51
51
  end
52
52
 
53
53
  describe "#logrotate" do
54
- before(:each) do
55
- @rotate = double("lotate mock")
56
- @rotate.should_receive(:execute).and_return(true)
57
- end
54
+ let!(:rotate) {
55
+ rotate = double("lotate mock")
56
+ rotate.should_receive(:execute).and_return(true)
57
+ rotate
58
+ }
58
59
 
59
60
  it "logrotate should be execute" do
60
- NginxUtils::Logrotate.should_receive(:new).and_return(@rotate)
61
+ NginxUtils::Logrotate.should_receive(:new).and_return(rotate)
61
62
  args = ["logrotate"]
62
63
  NginxUtils::CLI.start(args)
63
64
  end
64
65
 
65
66
  it "debug option" do
66
67
  options = {"debug" => true}
67
- NginxUtils::Logrotate.should_receive(:new).with(options).and_return(@rotate)
68
+ NginxUtils::Logrotate.should_receive(:new).with(options).and_return(rotate)
68
69
  args = ["logrotate", "-d"]
69
70
  NginxUtils::CLI.start(args)
70
71
  end
71
72
 
72
73
  it "script_log option" do
73
74
  options = {"script_log" => "/var/log/nginx_rotate.log"}
74
- NginxUtils::Logrotate.should_receive(:new).with(options).and_return(@rotate)
75
+ NginxUtils::Logrotate.should_receive(:new).with(options).and_return(rotate)
75
76
  args = ["logrotate", "--script_log", "/var/log/nginx_rotate.log"]
76
77
  NginxUtils::CLI.start(args)
77
78
  end
78
79
 
79
80
  it "log_level option" do
80
81
  options = {"log_level" => "warn"}
81
- NginxUtils::Logrotate.should_receive(:new).with(options).and_return(@rotate)
82
+ NginxUtils::Logrotate.should_receive(:new).with(options).and_return(rotate)
82
83
  args = ["logrotate", "--log_level", "warn"]
83
84
  NginxUtils::CLI.start(args)
84
85
  end
85
86
 
86
87
  it "root_dir option" do
87
88
  options = {"root_dir" => "/usr/local/nginx_other"}
88
- NginxUtils::Logrotate.should_receive(:new).with(options).and_return(@rotate)
89
+ NginxUtils::Logrotate.should_receive(:new).with(options).and_return(rotate)
89
90
  args = ["logrotate", "--root_dir", "/usr/local/nginx_other"]
90
91
  NginxUtils::CLI.start(args)
91
92
  end
92
93
 
93
94
  it "target_logs option" do
94
95
  options = {"target_logs" => "*_log"}
95
- NginxUtils::Logrotate.should_receive(:new).with(options).and_return(@rotate)
96
+ NginxUtils::Logrotate.should_receive(:new).with(options).and_return(rotate)
96
97
  args = ["logrotate", "--target_logs", "*_log"]
97
98
  NginxUtils::CLI.start(args)
98
99
  end
99
100
 
100
101
  it "retention option" do
101
102
  options = {"retention" => "30"}
102
- NginxUtils::Logrotate.should_receive(:new).with(options).and_return(@rotate)
103
+ NginxUtils::Logrotate.should_receive(:new).with(options).and_return(rotate)
103
104
  args = ["logrotate", "--retention", "30"]
104
105
  NginxUtils::CLI.start(args)
105
106
  end
106
107
 
107
108
  it "pid_file option" do
108
109
  options = {"pid_file" => "/var/run/nginx.pid"}
109
- NginxUtils::Logrotate.should_receive(:new).with(options).and_return(@rotate)
110
+ NginxUtils::Logrotate.should_receive(:new).with(options).and_return(rotate)
110
111
  args = ["logrotate", "--pid_file", "/var/run/nginx.pid"]
111
112
  NginxUtils::CLI.start(args)
112
113
  end
@@ -25,7 +25,7 @@ describe "NginxUtils::Logreader" do
25
25
  end
26
26
 
27
27
  it "default parser should be nil" do
28
- expect(reader.instance_eval{@parser}).to eq(nil)
28
+ expect(reader.instance_eval{@parser}).to be_nil
29
29
  end
30
30
  end
31
31
 
@@ -32,7 +32,7 @@ describe "NginxUtils::Logrotate" do
32
32
  let(:execute) {rotate.instance_eval{@execute}}
33
33
 
34
34
  it "@execute should be true" do
35
- expect(execute).to eq(true)
35
+ expect(execute).to be_true
36
36
  end
37
37
 
38
38
  it "@logger should be created" do
@@ -77,11 +77,11 @@ describe "NginxUtils::Logrotate" do
77
77
  end
78
78
 
79
79
  it "@rename_logs should be created" do
80
- expect(rotate.rename_logs).not_to eq(nil)
80
+ expect(rotate.rename_logs).not_to be_nil
81
81
  end
82
82
 
83
83
  it "@delete_logs should be created" do
84
- expect(rotate.delete_logs).not_to eq(nil)
84
+ expect(rotate.delete_logs).not_to be_nil
85
85
  end
86
86
  end
87
87
 
@@ -91,7 +91,7 @@ describe "NginxUtils::Logrotate" do
91
91
  let(:execute) {debug_rotate.instance_eval{@execute}}
92
92
 
93
93
  it "@execute should be false" do
94
- expect(execute).to eq(false)
94
+ expect(execute).to be_false
95
95
  end
96
96
 
97
97
  it "@logger should be created with STDOUT" do
@@ -113,7 +113,7 @@ describe "NginxUtils::Logrotate" do
113
113
  context "with custom params" do
114
114
  it "@logger should be false if script_log is false" do
115
115
  rotate = NginxUtils::Logrotate.new(script_log: false)
116
- expect(rotate.logger).to eq(false)
116
+ expect(rotate.logger).to be_false
117
117
  end
118
118
 
119
119
  it "@logger.level should be a specified level" do
@@ -154,18 +154,18 @@ describe "NginxUtils::Logrotate" do
154
154
  it "@execute should be a false if debug is true" do
155
155
  Logger.should_receive(:new).with(STDOUT)
156
156
  rotate.config debug: true
157
- expect(execute).to eq(false)
157
+ expect(execute).to be_false
158
158
  end
159
159
 
160
160
  it "@execute should be a true if debug is false" do
161
161
  rotate = NginxUtils::Logrotate.new(debug: true)
162
162
  rotate.config debug: false
163
- expect(rotate.instance_eval{@execute}).to eq(true)
163
+ expect(rotate.instance_eval{@execute}).to be_true
164
164
  end
165
165
 
166
166
  it "@logger should be a false if script_log is false" do
167
167
  rotate.config script_log: false
168
- expect(rotate.logger).to eq(false)
168
+ expect(rotate.logger).to be_false
169
169
  end
170
170
 
171
171
  it "@logger.level should be a specified level" do
@@ -205,7 +205,7 @@ describe "NginxUtils::Logrotate" do
205
205
  end
206
206
 
207
207
  describe "#rename" do
208
- before(:each) do
208
+ before do
209
209
  Dir.should_receive(:glob).exactly(2).times.and_return(files)
210
210
  File.stub(:rename).and_return(true)
211
211
  end
@@ -241,7 +241,7 @@ describe "NginxUtils::Logrotate" do
241
241
  end
242
242
 
243
243
  describe "#delete" do
244
- before(:each) do
244
+ before do
245
245
  Dir.should_receive(:glob).exactly(2).times.and_return(files)
246
246
  delete_time = Time.now - ((default[:retention] + 1) * 3600 * 24)
247
247
  File.stub(:stat).and_return(double("time mock", mtime: delete_time))
@@ -272,7 +272,7 @@ describe "NginxUtils::Logrotate" do
272
272
  end
273
273
 
274
274
  describe "#restart" do
275
- before(:each) do
275
+ before do
276
276
  File.stub(:exists?).and_return(true)
277
277
  File.stub(:read).and_return("2000")
278
278
  Process.stub(:kill).and_return(1)
@@ -320,7 +320,7 @@ describe "NginxUtils::Logrotate" do
320
320
  end
321
321
 
322
322
  describe "#execute" do
323
- before(:each) do
323
+ before do
324
324
  NginxUtils::Logrotate.any_instance.stub(:rename).and_return(true)
325
325
  NginxUtils::Logrotate.any_instance.stub(:delete).and_return(true)
326
326
  NginxUtils::Logrotate.any_instance.stub(:restart).and_return(true)
@@ -343,5 +343,5 @@ describe "NginxUtils::Logrotate" do
343
343
  rotate.config script_log: false
344
344
  rotate.execute
345
345
  end
346
- end
346
+ end
347
347
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nginx_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-26 00:00:00.000000000 Z
12
+ date: 2013-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -117,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  segments:
119
119
  - 0
120
- hash: -2092966652116304776
120
+ hash: -574939535063558817
121
121
  required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  none: false
123
123
  requirements:
@@ -126,10 +126,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  segments:
128
128
  - 0
129
- hash: -2092966652116304776
129
+ hash: -574939535063558817
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 1.8.23
132
+ rubygems_version: 1.8.25
133
133
  signing_key:
134
134
  specification_version: 3
135
135
  summary: Nginx utilities