blertr 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/blertr +5 -175
- data/config/blacklist.yaml +1 -0
- data/lib/blertr/bin.rb +207 -0
- data/lib/blertr/blacklist.rb +21 -3
- data/lib/blertr/version.rb +1 -1
- data/spec/bin_spec.rb +77 -0
- data/spec/blacklist_spec.rb +11 -2
- metadata +15 -12
data/bin/blertr
CHANGED
@@ -2,180 +2,10 @@
|
|
2
2
|
|
3
3
|
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
4
4
|
|
5
|
-
require 'blertr'
|
5
|
+
require 'blertr/bin'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
puts services
|
12
|
-
end
|
13
|
-
|
14
|
-
def help
|
15
|
-
help_string = <<EOS
|
16
|
-
-=[ Welcome to Blertr - Notifications for Bash commands ]=-
|
17
|
-
|
18
|
-
Usage: blertr [command] [command parameters]
|
19
|
-
|
20
|
-
Commands:
|
21
|
-
help Output this help message
|
22
|
-
|
23
|
-
install Add symlinks to your system to allow
|
24
|
-
Blertr to function properly
|
25
|
-
|
26
|
-
uninstall Remove symlinks and other setup process
|
27
|
-
Effectively uninstalling Blertr
|
28
|
-
|
29
|
-
upgrade Updates current copy of blertr to latest version
|
30
|
-
|
31
|
-
info Pass in a notifier name to get the
|
32
|
-
information it is using to send notifications
|
33
|
-
Example: blertr info email
|
34
|
-
|
35
|
-
status For each notifier, Blertr lists if it currently can
|
36
|
-
send notifications and then lists any error messages
|
37
|
-
if it cannot. Useful for debuggin problems with notifiers
|
38
|
-
|
39
|
-
exclude Pass in a shell command to prevent Blertr from
|
40
|
-
sending notifications when that command is
|
41
|
-
executed
|
42
|
-
Example: blertr exclude ssh
|
43
|
-
|
44
|
-
time Pass in a notifier name and a time string to
|
45
|
-
set the time required to pass before the
|
46
|
-
notifier sends a message for a command
|
47
|
-
Example: blertr time email 5 minutes
|
48
|
-
This would make blertr send an email only if
|
49
|
-
the command executing took longer than 5 mins
|
50
|
-
|
51
|
-
set Pass in the notifier name, a configuration key, and
|
52
|
-
a value. Blertr will add this key / value to the
|
53
|
-
notifiers config file.
|
54
|
-
Example: blertr set mail to user@gmail.com
|
55
|
-
EOS
|
56
|
-
puts help_string
|
57
|
-
end
|
58
|
-
|
59
|
-
def take_action action, parameters
|
60
|
-
blertr_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
61
|
-
blertr_local_dir = File.expand_path("~/.blertr")
|
62
|
-
blertr_symlink = File.join(blertr_local_dir, "app")
|
63
|
-
case action
|
64
|
-
when "help"
|
65
|
-
help
|
66
|
-
when "install"
|
67
|
-
if File.exists? blertr_symlink
|
68
|
-
puts "ERROR: Blertr appears to already be installed.\nUninstall with blertr uninstall"
|
69
|
-
else
|
70
|
-
puts "creating #{blertr_local_dir} directory"
|
71
|
-
system("mkdir -p #{blertr_local_dir}")
|
72
|
-
|
73
|
-
puts "creating symlink from #{blertr_path} to #{blertr_symlink}"
|
74
|
-
system("ln -s #{blertr_path} #{blertr_symlink}")
|
75
|
-
|
76
|
-
config_dir = File.expand_path(Blertr::CONFIG_DIR_PATH)
|
77
|
-
if !File.exists?(config_dir)
|
78
|
-
blertr_config_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "config"))
|
79
|
-
puts "copying config files to #{blertr_path}"
|
80
|
-
system("cp -r #{blertr_config_dir} #{blertr_local_dir}")
|
81
|
-
end
|
82
|
-
puts "Blertr is now (almost) installed!\nPut this at the bottom of your .bashrc file:"
|
83
|
-
puts "[[ -s \"$HOME/.blertr/app/scripts/blertr\" ]] && . \"$HOME/.blertr/app/scripts/blertr\""
|
84
|
-
end
|
85
|
-
when "uninstall"
|
86
|
-
if File.exists? blertr_symlink
|
87
|
-
puts "Removing #{blertr_symlink}"
|
88
|
-
system("rm #{blertr_symlink}")
|
89
|
-
puts "Blertr is now (almost) uninstalled.\nRemove from .bashrc file:"
|
90
|
-
puts "[[ -s \"$HOME/.blertr/scripts/blertr\" ]] && . \"$HOME/.blertr/scripts/blertr\""
|
91
|
-
else
|
92
|
-
puts "ERROR: it doesn't look like Blertr is installed"
|
93
|
-
end
|
94
|
-
when "upgrade"
|
95
|
-
commands = ["gem install blertr", "blertr uninstall", "blertr install"]
|
96
|
-
puts "Right now the upgrade process is very basic. Blertr will run:"
|
97
|
-
commands.each {|c| puts "$ #{c}"}
|
98
|
-
puts "This assumes that blertr is installed using rvm and doesn't require"
|
99
|
-
puts " sudo access."
|
100
|
-
puts "That ok? (y/n)"
|
101
|
-
response = gets
|
102
|
-
if ["y","Y","yes","Yes","YES"].include?(response.chomp)
|
103
|
-
puts "Ok, running commands now."
|
104
|
-
commands.each {|c| system(c)}
|
105
|
-
else
|
106
|
-
puts "You're the boss, exiting now."
|
107
|
-
end
|
108
|
-
when "info"
|
109
|
-
raw_name = parameters.shift
|
110
|
-
if Blertr::Control::is_notifier? raw_name
|
111
|
-
name = Blertr::Control::notifier_with_name(raw_name).name
|
112
|
-
info_hash = Blertr::Options.options_for name
|
113
|
-
puts "Configuration for: #{name}"
|
114
|
-
if info_hash.empty?
|
115
|
-
puts "No configuration file for #{name} or config file is empty"
|
116
|
-
else
|
117
|
-
info_hash.each do |key,value|
|
118
|
-
puts "#{key}: #{value}"
|
119
|
-
end
|
120
|
-
end
|
121
|
-
else
|
122
|
-
if !raw_name or (raw_name and raw_name.empty?)
|
123
|
-
puts "info requires the name of a notifier"
|
124
|
-
else
|
125
|
-
puts "Sorry, #{raw_name} is not a notifier"
|
126
|
-
end
|
127
|
-
end
|
128
|
-
when "status"
|
129
|
-
Blertr::Control::notifiers.each do |notifier|
|
130
|
-
notify_message = notifier.can_alert? ? "can alert" : "cannot alert"
|
131
|
-
puts "#{notifier.name}: #{notify_message}"
|
132
|
-
if !notifier.error_messages.empty?
|
133
|
-
notifier.error_messages.each {|err| puts " #{err}"}
|
134
|
-
end
|
135
|
-
end
|
136
|
-
when "exclude"
|
137
|
-
name = parameters.join(" ")
|
138
|
-
puts "Excluding #{name} from Blertr alerts"
|
139
|
-
Blertr::Blacklist.new.add(name)
|
140
|
-
when "set"
|
141
|
-
notifier_name = parameters.shift
|
142
|
-
if Blertr::Control::is_notifier? notifier_name
|
143
|
-
key = parameters.shift
|
144
|
-
value = parameters.shift
|
145
|
-
if key and value
|
146
|
-
puts "Setting #{notifier_name}'s #{key} to #{value}"
|
147
|
-
Blertr::Control::notifier_with_name(notifier_name).set_option(key,value)
|
148
|
-
else
|
149
|
-
puts "set command requires a key and a value to set it to"
|
150
|
-
puts "example blertr set email to user@gmail.com"
|
151
|
-
end
|
152
|
-
else
|
153
|
-
puts "Sorry, #{action} isn't a notifier."
|
154
|
-
puts "Use blertr status for a list of all notifiers"
|
155
|
-
end
|
156
|
-
when "time"
|
157
|
-
notifier_found = false
|
158
|
-
notifiers = parameters.shift.split(",")
|
159
|
-
notifiers.each do |notifier|
|
160
|
-
if Blertr::Control::is_notifier? notifier
|
161
|
-
notifier_found = true
|
162
|
-
new_time = parameters.join(" ")
|
163
|
-
Blertr::Control::change_time notifier, new_time
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
if !notifier_found
|
168
|
-
puts "Sorry, #{action} isn't a notifier."
|
169
|
-
puts "Use blertr status for a list of all notifiers"
|
170
|
-
end
|
171
|
-
else
|
172
|
-
puts "Sorry, #{action} isn't a recognized command"
|
173
|
-
puts "use blertr help to get a list of availible commands."
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
if action
|
178
|
-
take_action action.downcase, parameters
|
179
|
-
else
|
180
|
-
puts "usage blertr [command] [command parameters]"
|
7
|
+
if __FILE__ == $0
|
8
|
+
action = ARGV.shift
|
9
|
+
parameters = ARGV
|
10
|
+
Blertr::Bin::take_action action, parameters
|
181
11
|
end
|
data/config/blacklist.yaml
CHANGED
data/lib/blertr/bin.rb
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
|
2
|
+
require 'blertr'
|
3
|
+
|
4
|
+
module Blertr
|
5
|
+
class Bin
|
6
|
+
|
7
|
+
def self.add_services services, time
|
8
|
+
puts services
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.help
|
12
|
+
help_string = <<EOS
|
13
|
+
-=[ Welcome to Blertr - Notifications for Bash commands ]=-
|
14
|
+
|
15
|
+
Usage: blertr [command] [command parameters]
|
16
|
+
|
17
|
+
Commands:
|
18
|
+
help Output this help message
|
19
|
+
|
20
|
+
install Add symlinks to your system to allow
|
21
|
+
Blertr to function properly
|
22
|
+
|
23
|
+
uninstall Remove symlinks and other setup process
|
24
|
+
Effectively uninstalling Blertr
|
25
|
+
|
26
|
+
upgrade Updates current copy of blertr to latest version
|
27
|
+
|
28
|
+
info Pass in a notifier name to get the
|
29
|
+
information it is using to send notifications
|
30
|
+
Example: blertr info email
|
31
|
+
|
32
|
+
status For each notifier, Blertr lists if it currently can
|
33
|
+
send notifications and then lists any error messages
|
34
|
+
if it cannot. Useful for debuggin problems with notifiers
|
35
|
+
|
36
|
+
exclude Pass in a shell command to prevent Blertr from
|
37
|
+
sending notifications when that command is
|
38
|
+
executed
|
39
|
+
Example: blertr exclude ssh
|
40
|
+
|
41
|
+
time Pass in a notifier name and a time string to
|
42
|
+
set the time required to pass before the
|
43
|
+
notifier sends a message for a command
|
44
|
+
Example: blertr time email 5 minutes
|
45
|
+
This would make blertr send an email only if
|
46
|
+
the command executing took longer than 5 mins
|
47
|
+
|
48
|
+
set Pass in the notifier name, a configuration key, and
|
49
|
+
a value. Blertr will add this key / value to the
|
50
|
+
notifiers config file.
|
51
|
+
Example: blertr set mail to user@gmail.com
|
52
|
+
EOS
|
53
|
+
puts help_string
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.take_action action, parameters
|
57
|
+
parameters = [parameters].flatten.compact
|
58
|
+
blertr_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
59
|
+
blertr_local_dir = File.expand_path("~/.blertr")
|
60
|
+
blertr_symlink = File.join(blertr_local_dir, "app")
|
61
|
+
case action
|
62
|
+
when "help",nil
|
63
|
+
help
|
64
|
+
when "install"
|
65
|
+
if File.exists? blertr_symlink
|
66
|
+
puts "ERROR: Blertr appears to already be installed.\nUninstall with blertr uninstall"
|
67
|
+
else
|
68
|
+
puts "creating #{blertr_local_dir} directory"
|
69
|
+
system("mkdir -p #{blertr_local_dir}")
|
70
|
+
|
71
|
+
puts "creating symlink from #{blertr_path} to #{blertr_symlink}"
|
72
|
+
system("ln -s #{blertr_path} #{blertr_symlink}")
|
73
|
+
|
74
|
+
config_dir = File.expand_path(Blertr::CONFIG_DIR_PATH)
|
75
|
+
if !File.exists?(config_dir)
|
76
|
+
blertr_config_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "config"))
|
77
|
+
puts "copying config files to #{blertr_path}"
|
78
|
+
system("cp -r #{blertr_config_dir} #{blertr_local_dir}")
|
79
|
+
end
|
80
|
+
puts "Blertr is now (almost) installed!\nPut this at the bottom of your .bashrc file:"
|
81
|
+
puts "[[ -s \"$HOME/.blertr/app/scripts/blertr\" ]] && . \"$HOME/.blertr/app/scripts/blertr\""
|
82
|
+
end
|
83
|
+
when "uninstall"
|
84
|
+
if File.exists? blertr_symlink
|
85
|
+
puts "Removing #{blertr_symlink}"
|
86
|
+
system("rm #{blertr_symlink}")
|
87
|
+
puts "Blertr is now (almost) uninstalled.\nRemove from .bashrc file:"
|
88
|
+
puts "[[ -s \"$HOME/.blertr/scripts/blertr\" ]] && . \"$HOME/.blertr/scripts/blertr\""
|
89
|
+
else
|
90
|
+
puts "ERROR: it doesn't look like Blertr is installed"
|
91
|
+
end
|
92
|
+
when "upgrade"
|
93
|
+
commands = ["gem install blertr", "blertr uninstall", "blertr install"]
|
94
|
+
puts "Right now the upgrade process is very basic. Blertr will run:"
|
95
|
+
commands.each {|c| puts "$ #{c}"}
|
96
|
+
puts "This assumes that blertr is installed using rvm and doesn't require"
|
97
|
+
puts " sudo access."
|
98
|
+
puts "That ok? (y/n)"
|
99
|
+
response = gets
|
100
|
+
if ["y","Y","yes","Yes","YES"].include?(response.chomp)
|
101
|
+
puts "Ok, running commands now."
|
102
|
+
commands.each {|c| system(c)}
|
103
|
+
else
|
104
|
+
puts "You're the boss, exiting now."
|
105
|
+
end
|
106
|
+
when "info"
|
107
|
+
raw_name = parameters.shift
|
108
|
+
raw_name = raw_name ? raw_name.strip : nil
|
109
|
+
raw_name = (raw_name and raw_name.empty?) ? nil : raw_name
|
110
|
+
|
111
|
+
names = []
|
112
|
+
if !raw_name
|
113
|
+
Blertr::Control::notifiers.each { |notifier| names << notifier.name}
|
114
|
+
else
|
115
|
+
if Blertr::Control::is_notifier? raw_name
|
116
|
+
names << Blertr::Control::notifier_with_name(raw_name).name
|
117
|
+
else
|
118
|
+
puts "Error: #{raw_name} is not a notifier"
|
119
|
+
puts "use blertr status to list all notifiers"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
names.each do |name|
|
124
|
+
info_hash = Blertr::Options.options_for name
|
125
|
+
puts "Configuration for: #{name}"
|
126
|
+
if info_hash.empty?
|
127
|
+
puts " No configuration file for #{name} or config file is empty"
|
128
|
+
else
|
129
|
+
info_hash.each do |key,value|
|
130
|
+
puts " #{key}: #{value}"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
when "status"
|
135
|
+
Blertr::Control::notifiers.each do |notifier|
|
136
|
+
notify_message = notifier.can_alert? ? "can alert" : "cannot alert"
|
137
|
+
puts "#{notifier.name}: #{notify_message}"
|
138
|
+
if !notifier.error_messages.empty?
|
139
|
+
notifier.error_messages.each {|err| puts " #{err}"}
|
140
|
+
end
|
141
|
+
end
|
142
|
+
when "exclude"
|
143
|
+
name = parameters.join(" ").strip
|
144
|
+
unless !name or name.empty?
|
145
|
+
puts "Excluding #{name} from Blertr alerts"
|
146
|
+
Blertr::Blacklist.new.add(name)
|
147
|
+
else
|
148
|
+
puts "Error: excluding requires a command to exclude"
|
149
|
+
puts "Example: blertr exclude ssh"
|
150
|
+
end
|
151
|
+
when "set"
|
152
|
+
notifier_name = parameters.shift
|
153
|
+
if Blertr::Control::is_notifier? notifier_name
|
154
|
+
key = parameters.shift
|
155
|
+
value = parameters.shift
|
156
|
+
if key and value
|
157
|
+
puts "Setting #{notifier_name}'s #{key} to #{value}"
|
158
|
+
Blertr::Control::notifier_with_name(notifier_name).set_option(key,value)
|
159
|
+
else
|
160
|
+
puts "Error: set command requires a key and a value to set it to"
|
161
|
+
puts "Example: blertr set email to user@gmail.com"
|
162
|
+
end
|
163
|
+
else
|
164
|
+
puts "Error: #{notifier_name} isn't a notifier."
|
165
|
+
puts "Use blertr status for a list of all notifiers"
|
166
|
+
end
|
167
|
+
when "time"
|
168
|
+
if !parameters.empty?
|
169
|
+
notifier_found = false
|
170
|
+
notifiers = parameters.shift.strip.split(",")
|
171
|
+
notifiers.each do |notifier|
|
172
|
+
if Blertr::Control::is_notifier? notifier
|
173
|
+
notifier_found = true
|
174
|
+
new_time = parameters.join(" ").strip
|
175
|
+
unless new_time.empty?
|
176
|
+
Blertr::Control::change_time notifier, new_time
|
177
|
+
else
|
178
|
+
puts "Error: setting time requires a new time"
|
179
|
+
puts "Example: blertr time #{notifier} 5 minutes"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
if !notifier_found
|
185
|
+
puts "Sorry, #{notifiers.join(",")} isn't a notifier."
|
186
|
+
puts "Use blertr status for a list of all notifiers"
|
187
|
+
puts "Example: blertr time mail 5 minutes"
|
188
|
+
end
|
189
|
+
else
|
190
|
+
puts "All Notifier Times:"
|
191
|
+
Blertr::Control::notifiers.each do |notifier|
|
192
|
+
notifier_time = "#{notifier.name}".ljust(20)
|
193
|
+
notifier_time += notifier.options[:time] ? "#{notifier.options[:time]} seconds" : "not set"
|
194
|
+
puts notifier_time
|
195
|
+
end
|
196
|
+
puts ""
|
197
|
+
puts "Use blertr time [notifier] [time]"
|
198
|
+
puts " to set time for notifier."
|
199
|
+
puts "Example: blertr time mail 5 minutes"
|
200
|
+
end
|
201
|
+
else
|
202
|
+
puts "Sorry, #{action} isn't a recognized command"
|
203
|
+
puts "use blertr help to get a list of availible commands."
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
data/lib/blertr/blacklist.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'blertr/constants'
|
2
3
|
|
3
4
|
module Blertr
|
4
5
|
class Blacklist
|
5
6
|
attr_accessor :path, :list
|
6
7
|
|
7
8
|
def self.path
|
8
|
-
File.expand_path(
|
9
|
+
base_path = File.expand_path(CONFIG_DIR_PATH)
|
10
|
+
if File.exists?(base_path)
|
11
|
+
File.join(base_path, "blacklist.yaml")
|
12
|
+
else
|
13
|
+
File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config", "blacklist.yaml"))
|
14
|
+
end
|
9
15
|
end
|
10
16
|
|
11
17
|
def initialize path = Blacklist::path
|
@@ -31,8 +37,20 @@ module Blertr
|
|
31
37
|
|
32
38
|
def blacklisted? command
|
33
39
|
rtn = false
|
34
|
-
|
35
|
-
|
40
|
+
command_fields = command.split(/ /)
|
41
|
+
list_matches = @list.collect {|name| name.split(/ /).zip(command_fields)}
|
42
|
+
|
43
|
+
list_matches.each do |match_set|
|
44
|
+
match = true
|
45
|
+
match_set.each do |excluded_section, command_section|
|
46
|
+
if (excluded_section and command_section) and
|
47
|
+
(excluded_section != command_section) and
|
48
|
+
(File.basename(excluded_section) != File.basename(command_section))
|
49
|
+
match = false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
if match
|
36
54
|
rtn = true
|
37
55
|
return rtn
|
38
56
|
end
|
data/lib/blertr/version.rb
CHANGED
data/spec/bin_spec.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
BIN = File.expand_path(File.join(File.dirname(__FILE__), "..", "bin", "blertr"))
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
4
|
+
require 'blertr/bin'
|
5
|
+
|
6
|
+
describe Blertr::Bin do
|
7
|
+
describe "blertr" do
|
8
|
+
before(:each) do
|
9
|
+
@bin = BIN
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should exist" do
|
13
|
+
File.exists?(@bin).should == true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be executable" do
|
17
|
+
File.executable?(@bin).should == true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "bin" do
|
22
|
+
before(:each) do
|
23
|
+
@bin = Blertr::Bin
|
24
|
+
@invalid_notifiers = ["", "maill", "mad", nil, "gr0wl", "ddd", " dd "]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should print help with no action or help action" do
|
28
|
+
actions = [nil, "help"]
|
29
|
+
actions.each do |action|
|
30
|
+
output = capture(:stdout) {@bin.take_action action, nil}
|
31
|
+
output.should match(/Welcome to Blertr/)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should print time for all notifiers with no time parameters" do
|
36
|
+
output = capture(:stdout) {@bin.take_action "time", nil}
|
37
|
+
output.should match(/All Notifier Times/)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should indicate notifier is invalid for invalid notifiers" do
|
41
|
+
output = capture(:stdout) {@bin.take_action "time", "not_notifier"}
|
42
|
+
output.should match(/isn't a notifier/)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should error if no time is given to set for notifier" do
|
46
|
+
output = capture(:stdout) {@bin.take_action "time", "mail"}
|
47
|
+
output.should match(/Error/)
|
48
|
+
output.should match(/requires a new time/)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should not set configs for invalid notifier" do
|
52
|
+
@invalid_notifiers.each do |notifier|
|
53
|
+
output = capture(:stdout) {@bin.take_action "set", notifier }
|
54
|
+
output.should match(/Error/)
|
55
|
+
output.should match(/isn't a notifier/)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should not exclude empty commands" do
|
60
|
+
invalid_exclusions = [nil, "", " "]
|
61
|
+
invalid_exclusions.each do |ex|
|
62
|
+
output = capture(:stdout) {@bin.take_action "exclude", ex }
|
63
|
+
output.should match(/Error/)
|
64
|
+
output.should match(/requires .* command .* exclude/)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should show info of all notifiers if no notifier name given" do
|
69
|
+
output = capture(:stdout) {@bin.take_action "info", nil }
|
70
|
+
output.should match(/Configuration for: mail/)
|
71
|
+
output.should match(/Configuration for: twitter/)
|
72
|
+
output = capture(:stdout) {@bin.take_action "info", " " }
|
73
|
+
output.should match(/Configuration for: mail/)
|
74
|
+
output.should match(/Configuration for: twitter/)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/spec/blacklist_spec.rb
CHANGED
@@ -49,7 +49,16 @@ describe Blertr::Blacklist do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should handle full commands" do
|
52
|
-
commands = [["git diff","git diff"], ["ssh", "ssh 123@123.com"], ["cp", "cp /ma/da ./da/ma"]]
|
52
|
+
commands = [["git diff","git diff"], ["ssh", "ssh 123@123.com"], ["cp", "cp /ma/da ./da/ma"], ["cp", "cp "]]
|
53
|
+
|
54
|
+
commands.each do |name, command|
|
55
|
+
@blacklist.add name
|
56
|
+
@blacklist.blacklisted?(command).should == true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should handle relative commands" do
|
61
|
+
commands = [["git diff","../../git diff"], ["ssh", "/usr/bin/ssh 123@123.com"], ["cp", "/dev/../null/cp /ma/da ./dd/mz"]]
|
53
62
|
|
54
63
|
commands.each do |name, command|
|
55
64
|
@blacklist.add name
|
@@ -58,7 +67,7 @@ describe Blertr::Blacklist do
|
|
58
67
|
end
|
59
68
|
|
60
69
|
it "should not exclude similar commands" do
|
61
|
-
commands = [["git diff","git diff", "git log"], ["ssh", "ssh 123@123.com", "scp 123@123.com"], ["cp", "cp /ma/da ./da/ma"]]
|
70
|
+
commands = [["git diff","git diff", "git log"], ["ssh", "ssh 123@123.com", "scp 123@123.com"], ["cp", "cp /ma/da ./da/ma", "cpy /ma/da ./da/ma"], ["git diff", "../git diff", "../git log"], ["git diff", "git diff", "git dif"]]
|
62
71
|
commands.each do |name, command, similar_command|
|
63
72
|
@blacklist.add name
|
64
73
|
@blacklist.blacklisted?(command).should == true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blertr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-08 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &2650200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2650200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rdoc
|
27
|
-
requirement: &
|
27
|
+
requirement: &2649890 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '2.5'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2649890
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &2649630 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '2.3'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2649630
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: simplecov
|
49
|
-
requirement: &
|
49
|
+
requirement: &2649380 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0.4'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2649380
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: twitter
|
60
|
-
requirement: &
|
60
|
+
requirement: &2649130 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 1.6.0
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2649130
|
69
69
|
description: Automatic alerts for when bash scripts and commands complete
|
70
70
|
email: vvv@gmail.com
|
71
71
|
executables:
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- config/mail_config.yaml
|
90
90
|
- config/notify_send_config.yaml
|
91
91
|
- lib/blertr.rb
|
92
|
+
- lib/blertr/bin.rb
|
92
93
|
- lib/blertr/blacklist.rb
|
93
94
|
- lib/blertr/constants.rb
|
94
95
|
- lib/blertr/control.rb
|
@@ -105,6 +106,7 @@ files:
|
|
105
106
|
- scripts/cli
|
106
107
|
- scripts/preexec
|
107
108
|
- scripts_bin/blert_now.rb
|
109
|
+
- spec/bin_spec.rb
|
108
110
|
- spec/blacklist_spec.rb
|
109
111
|
- spec/control_spec.rb
|
110
112
|
- spec/growl_notifier_spec.rb
|
@@ -140,6 +142,7 @@ signing_key:
|
|
140
142
|
specification_version: 3
|
141
143
|
summary: Automatic alerts for when bash scripts and commands complete
|
142
144
|
test_files:
|
145
|
+
- spec/bin_spec.rb
|
143
146
|
- spec/blacklist_spec.rb
|
144
147
|
- spec/control_spec.rb
|
145
148
|
- spec/growl_notifier_spec.rb
|