zabbirc 0.0.11 → 0.1.0
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.
- checksums.yaml +4 -4
- data/lib/zabbirc/irc/base_command.rb +120 -0
- data/lib/zabbirc/irc/event_command.rb +72 -0
- data/lib/zabbirc/irc/help_command.rb +20 -0
- data/lib/zabbirc/irc/host_command.rb +65 -0
- data/lib/zabbirc/irc/plugin.rb +6 -20
- data/lib/zabbirc/irc/plugin_methods.rb +16 -194
- data/lib/zabbirc/irc/settings_command.rb +159 -0
- data/lib/zabbirc/op.rb +16 -6
- data/lib/zabbirc/setting.rb +49 -12
- data/lib/zabbirc/version.rb +3 -0
- data/lib/zabbirc/zabbix/event.rb +23 -0
- data/lib/zabbirc/zabbix/host.rb +1 -0
- data/lib/zabbirc/zabbix/host_group.rb +8 -0
- data/lib/zabbirc/zabbix/resource/associations.rb +12 -6
- data/lib/zabbirc/zabbix/resource/base.rb +10 -2
- data/lib/zabbirc/zabbix/resource/finders.rb +1 -1
- data/lib/zabbirc.rb +2 -1
- data/spec/event_command_spec.rb +114 -0
- data/spec/host_command_spec.rb +106 -0
- data/spec/settings_command_spec.rb +125 -0
- data/spec/support/ops_builder.rb +23 -0
- data/tmp/playground.rb +22 -0
- data/tmp/stopwatch.rb +52 -0
- metadata +18 -7
- data/spec/bot_spec.rb +0 -212
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
describe Zabbirc::Irc::SettingsCommand do
|
|
2
|
+
let(:ops_builder) { Zabbirc::OpsBuilder.new }
|
|
3
|
+
let(:mock_nick) { "op1" }
|
|
4
|
+
let(:mock_op) { ops_builder.build_op(mock_nick, mock_user_settings) }
|
|
5
|
+
let(:mock_message) { double("Cinch::Message", user: mock_op.irc_user) }
|
|
6
|
+
let(:mock_user_settings) { nil }
|
|
7
|
+
let(:settings_command) { Zabbirc::Irc::SettingsCommand.new ops_builder.ops, mock_message, cmd }
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
describe "#show_settings" do
|
|
11
|
+
let(:mock_user_settings) { {primary_channel: "#channel-1", events_priority: "high", notify: false } }
|
|
12
|
+
let(:expected_msg) { "#{mock_nick}: Default settings: notify: false, notify_recoveries: true, primary_channel: #channel-1, events_priority: high" }
|
|
13
|
+
let(:cmd) { "show" }
|
|
14
|
+
it "should show settings" do
|
|
15
|
+
expect(mock_message).to receive(:reply).with(expected_msg)
|
|
16
|
+
settings_command.run
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "#set_setting" do
|
|
21
|
+
shared_examples "set_setting" do |key, value, expected_setting_value|
|
|
22
|
+
let(:expected_msg) { "#{mock_nick}: setting `#{key}` has been set to `#{expected_setting_value}`" }
|
|
23
|
+
let(:cmd) { "set #{key} #{value}"}
|
|
24
|
+
it "should set #{key} setting to #{value}" do
|
|
25
|
+
expect(mock_message).to receive(:reply).with(expected_msg)
|
|
26
|
+
settings_command.run
|
|
27
|
+
expect(mock_op.setting.get(key)).to eq expected_setting_value
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
context "notify" do
|
|
33
|
+
it_should_behave_like "set_setting", "notify", "false", false
|
|
34
|
+
it_should_behave_like "set_setting", "notify", "true", true
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context "events_priority" do
|
|
38
|
+
it_should_behave_like "set_setting", "events_priority", "high", :high
|
|
39
|
+
it_should_behave_like "set_setting", "events_priority", "5", :disaster
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context "primary_channel" do
|
|
43
|
+
before do
|
|
44
|
+
mock_op.add_channel double("#channel1", name: "#channel1")
|
|
45
|
+
mock_op.add_channel double("#channel2double", name: "#channel2")
|
|
46
|
+
end
|
|
47
|
+
it_should_behave_like "set_setting", "primary_channel", "#channel1", "#channel1"
|
|
48
|
+
it_should_behave_like "set_setting", "primary_channel", "#channel2", "#channel2"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context "group specific" do
|
|
52
|
+
let(:group1) { double "HostGroup", id: 1, name: "Group1" }
|
|
53
|
+
let(:group2) { double "HostGroup", id: 2, name: "Group2" }
|
|
54
|
+
let(:groups) { [group1, group2] }
|
|
55
|
+
before do
|
|
56
|
+
allow(Zabbirc::Zabbix::HostGroup).to receive(:get) { groups }
|
|
57
|
+
allow(Zabbirc::Zabbix::HostGroup).to receive(:get).with(hash_including(search: { name: anything })) do |params|
|
|
58
|
+
groups.select{|g| g.name =~ /#{params[:search][:name]}/ }
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
shared_examples "set_group_setting" do |key, value, expected_setting_value|
|
|
63
|
+
let(:expected_msg) { "#{mock_nick}: setting `#{key}` has been set to `#{expected_setting_value}` for host groups: #{affected_host_group.name}" }
|
|
64
|
+
let(:cmd) { "set #{key} #{value} hostgroups #{affected_host_group.name}"}
|
|
65
|
+
it "should set #{key} setting to #{value} for host group" do
|
|
66
|
+
old_global_value = mock_op.setting.get(key)
|
|
67
|
+
|
|
68
|
+
expect(mock_message).to receive(:reply).with(expected_msg)
|
|
69
|
+
settings_command.run
|
|
70
|
+
expect(mock_op.setting.get(key, host_group_id: affected_host_group.id)).to eq expected_setting_value
|
|
71
|
+
|
|
72
|
+
expect(mock_op.setting.get(key)).to eq old_global_value
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
shared_examples "set_all_groups_setting" do |key, value, expected_setting_value|
|
|
77
|
+
let(:settings_command1) { Zabbirc::Irc::SettingsCommand.new ops_builder.ops, mock_message, cmd1 }
|
|
78
|
+
let(:settings_command2) { Zabbirc::Irc::SettingsCommand.new ops_builder.ops, mock_message, cmd2 }
|
|
79
|
+
|
|
80
|
+
let!(:old_global_value) { mock_op.setting.get(key, host_group_id: affected_host_group.id) }
|
|
81
|
+
let(:expected_msg1) { "#{mock_nick}: setting `#{key}` has been set to `#{expected_setting_value}` for host groups: #{affected_host_group.name}" }
|
|
82
|
+
let(:expected_msg2) { "#{mock_nick}: setting `#{key}` has been set to `#{old_global_value}` for all host groups" }
|
|
83
|
+
let(:cmd1) { "set #{key} #{value} hostgroups #{affected_host_group.name}"}
|
|
84
|
+
let(:cmd2) { "set #{key} #{old_global_value} hostgroups-all"}
|
|
85
|
+
it "should set #{key} setting to #{value} for all host groups" do
|
|
86
|
+
# sets host group specific setting
|
|
87
|
+
expect(mock_message).to receive(:reply).with(expected_msg1)
|
|
88
|
+
settings_command1.run
|
|
89
|
+
expect(mock_op.setting.get(key, host_group_id: affected_host_group.id)).to eq expected_setting_value
|
|
90
|
+
expect(mock_op.setting.get(key)).to eq old_global_value
|
|
91
|
+
|
|
92
|
+
expect(mock_message).to receive(:reply).with(expected_msg2)
|
|
93
|
+
settings_command2.run
|
|
94
|
+
expect(mock_op.setting.get(key, host_group_id: affected_host_group.id)).to eq old_global_value
|
|
95
|
+
expect(mock_op.setting.get(key)).to eq old_global_value
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it_should_behave_like "set_group_setting", "notify", "false", false do
|
|
100
|
+
let(:affected_host_group) { group1 }
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it_should_behave_like "set_group_setting", "events_priority", "high", :high do
|
|
104
|
+
let(:affected_host_group) { group1 }
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it_should_behave_like "set_group_setting", "events_priority", "5", :disaster do
|
|
108
|
+
let(:affected_host_group) { group1 }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it_should_behave_like "set_all_groups_setting", "notify", "false", false do
|
|
112
|
+
let(:affected_host_group) { group1 }
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it_should_behave_like "set_all_groups_setting", "events_priority", "high", :high do
|
|
116
|
+
let(:affected_host_group) { group1 }
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it_should_behave_like "set_all_groups_setting", "events_priority", "5", :disaster do
|
|
120
|
+
let(:affected_host_group) { group1 }
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Zabbirc
|
|
2
|
+
class OpsBuilder
|
|
3
|
+
include RSpec::Mocks::ExampleMethods
|
|
4
|
+
|
|
5
|
+
attr_reader :ops
|
|
6
|
+
def initialize
|
|
7
|
+
@ops = OpList.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def build_op name, settings=nil
|
|
11
|
+
@op_ids ||= 0
|
|
12
|
+
zabbix_user = Zabbix::User.new(alias: name, userid: (@op_ids+=1))
|
|
13
|
+
irc_user = double "Cinch::User", nick: name, user: name
|
|
14
|
+
op = Op.new(zabbix_user)
|
|
15
|
+
op.set_irc_user irc_user
|
|
16
|
+
settings.each do |key, value|
|
|
17
|
+
op.setting.set key, value
|
|
18
|
+
end if settings
|
|
19
|
+
@ops.add op
|
|
20
|
+
op
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/tmp/playground.rb
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# tulak:
|
|
2
|
+
# notify: true
|
|
3
|
+
# notify_recoveries: true
|
|
4
|
+
# primary_channel: "#zabbirc-test"
|
|
5
|
+
# events_priority: :high
|
|
6
|
+
# host_groups:
|
|
7
|
+
# 1:
|
|
8
|
+
# events_priority: :disaster
|
|
9
|
+
|
|
10
|
+
!settings set notify false hostgroups Linux servers, Zabbix servers
|
|
11
|
+
|
|
12
|
+
setting.get(:notify) => default
|
|
13
|
+
setting.get(:notify, "Linux servers") => hostgroup-setting || default
|
|
14
|
+
|
|
15
|
+
include Zabbirc
|
|
16
|
+
s = Setting.new
|
|
17
|
+
s.set :events_priority, :average, host_group_id: 1
|
|
18
|
+
s.set :events_priority, :warning, host_group_id: 2
|
|
19
|
+
s.set :events_priority, :high, host_group_id: 1
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
c = SettingsCommand.new
|
data/tmp/stopwatch.rb
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Stopwatch
|
|
2
|
+
def self.catch formatted=true
|
|
3
|
+
start_time = Time.now
|
|
4
|
+
yield
|
|
5
|
+
end_time = Time.now
|
|
6
|
+
duration = end_time - start_time
|
|
7
|
+
if formatted
|
|
8
|
+
duration.to_dot_time(true)
|
|
9
|
+
else
|
|
10
|
+
duration
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class Integer
|
|
17
|
+
def to_dot_time mili=false
|
|
18
|
+
s = self
|
|
19
|
+
h = s / 3600
|
|
20
|
+
s -= h * 3600
|
|
21
|
+
|
|
22
|
+
m = s / 60
|
|
23
|
+
s -= m * 60
|
|
24
|
+
|
|
25
|
+
h = "%02d" % h
|
|
26
|
+
m = "%02d" % m
|
|
27
|
+
s = "%02#{mili ? "f" : "d"}" % s
|
|
28
|
+
|
|
29
|
+
[h, m, s].join(":")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def dec2bin
|
|
33
|
+
"0b%b" % self
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class Float
|
|
38
|
+
def to_dot_time mili=false
|
|
39
|
+
s = self
|
|
40
|
+
h = (s / 3600.0).floor
|
|
41
|
+
s -= h * 3600.0
|
|
42
|
+
|
|
43
|
+
m = (s / 60.0).floor
|
|
44
|
+
s -= m * 60.0
|
|
45
|
+
|
|
46
|
+
h = "%02d" % h
|
|
47
|
+
m = "%02d" % m
|
|
48
|
+
s = "%02#{mili ? "f" : "d"}" % s
|
|
49
|
+
|
|
50
|
+
[h, m, s].join(":")
|
|
51
|
+
end
|
|
52
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zabbirc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Filip Zachar
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-11-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -16,20 +16,20 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 4.
|
|
19
|
+
version: 4.2.4
|
|
20
20
|
- - ">="
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: 4.
|
|
22
|
+
version: 4.2.4
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
26
|
requirements:
|
|
27
27
|
- - "~>"
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: 4.
|
|
29
|
+
version: 4.2.4
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 4.
|
|
32
|
+
version: 4.2.4
|
|
33
33
|
- !ruby/object:Gem::Dependency
|
|
34
34
|
name: dotenv
|
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -118,9 +118,14 @@ files:
|
|
|
118
118
|
- lib/zabbirc.rb
|
|
119
119
|
- lib/zabbirc/configuration.rb
|
|
120
120
|
- lib/zabbirc/id_shortener.rb
|
|
121
|
+
- lib/zabbirc/irc/base_command.rb
|
|
122
|
+
- lib/zabbirc/irc/event_command.rb
|
|
121
123
|
- lib/zabbirc/irc/help.rb
|
|
124
|
+
- lib/zabbirc/irc/help_command.rb
|
|
125
|
+
- lib/zabbirc/irc/host_command.rb
|
|
122
126
|
- lib/zabbirc/irc/plugin.rb
|
|
123
127
|
- lib/zabbirc/irc/plugin_methods.rb
|
|
128
|
+
- lib/zabbirc/irc/settings_command.rb
|
|
124
129
|
- lib/zabbirc/logger.rb
|
|
125
130
|
- lib/zabbirc/op.rb
|
|
126
131
|
- lib/zabbirc/op_list.rb
|
|
@@ -131,21 +136,27 @@ files:
|
|
|
131
136
|
- lib/zabbirc/services/ops.rb
|
|
132
137
|
- lib/zabbirc/setting.rb
|
|
133
138
|
- lib/zabbirc/stop_error.rb
|
|
139
|
+
- lib/zabbirc/version.rb
|
|
134
140
|
- lib/zabbirc/zabbix/connection.rb
|
|
135
141
|
- lib/zabbirc/zabbix/event.rb
|
|
136
142
|
- lib/zabbirc/zabbix/host.rb
|
|
143
|
+
- lib/zabbirc/zabbix/host_group.rb
|
|
137
144
|
- lib/zabbirc/zabbix/resource/associations.rb
|
|
138
145
|
- lib/zabbirc/zabbix/resource/base.rb
|
|
139
146
|
- lib/zabbirc/zabbix/resource/finders.rb
|
|
140
147
|
- lib/zabbirc/zabbix/trigger.rb
|
|
141
148
|
- lib/zabbirc/zabbix/user.rb
|
|
142
|
-
- spec/
|
|
149
|
+
- spec/event_command_spec.rb
|
|
150
|
+
- spec/host_command_spec.rb
|
|
143
151
|
- spec/id_shortener_spec.rb
|
|
152
|
+
- spec/settings_command_spec.rb
|
|
144
153
|
- spec/spec_helper.rb
|
|
145
154
|
- spec/support/mock_bot.rb
|
|
155
|
+
- spec/support/ops_builder.rb
|
|
146
156
|
- templates/zabbirc_config.rb
|
|
147
157
|
- tmp/module_test.rb
|
|
148
158
|
- tmp/playground.rb
|
|
159
|
+
- tmp/stopwatch.rb
|
|
149
160
|
- tmp/thread_test.rb
|
|
150
161
|
homepage: https://github.com/tulak/zabbirc
|
|
151
162
|
licenses:
|
data/spec/bot_spec.rb
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
describe Zabbirc::Irc::PluginMethods do
|
|
2
|
-
# let(:service) { Zabbirc::ServiceMock.new }
|
|
3
|
-
let(:mock_message) { double("Cinch::Message", user: mock_user) }
|
|
4
|
-
let(:mock_user) { double("Cinch::User", nick: mock_nick, login: mock_login) }
|
|
5
|
-
let(:bot) { Zabbirc::MockBot.new }
|
|
6
|
-
let(:mock_nick) { "op1" }
|
|
7
|
-
let(:mock_login) { "op1" }
|
|
8
|
-
let(:mock_user_settings) { nil }
|
|
9
|
-
|
|
10
|
-
before do
|
|
11
|
-
bot.setup_op mock_nick, mock_user_settings
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "#acknowledge_event" do
|
|
15
|
-
let(:event) { double "Event", id: 1, label: "Event 1 label" }
|
|
16
|
-
let(:message) { "ack message" }
|
|
17
|
-
before do
|
|
18
|
-
allow(event).to receive(:acknowledge).and_return(true)
|
|
19
|
-
allow(Zabbirc::Zabbix::Event).to receive(:find).and_return(event)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "should acknowledge event" do
|
|
23
|
-
shorten_id = Zabbirc.events_id_shortener.get_shorten_id event.id
|
|
24
|
-
expect(mock_message).to receive(:reply).with("#{mock_nick}: Event `#{event.label}` acknowledged with message: #{message}")
|
|
25
|
-
bot.acknowledge_event mock_message, shorten_id, message
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe "#host_status" do
|
|
30
|
-
before do
|
|
31
|
-
allow(Zabbirc::Zabbix::Host).to receive(:get).and_return(hosts)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context "reporting" do
|
|
35
|
-
before do
|
|
36
|
-
allow(Zabbirc::Zabbix::Trigger).to receive(:get).and_return(problem_triggers)
|
|
37
|
-
end
|
|
38
|
-
let(:host) { double "Host", id: 1, name: "Host-1" }
|
|
39
|
-
let(:hosts) { [host] }
|
|
40
|
-
let(:problem_trigger) { double "Trigger", priority: Zabbirc::Priority.new(1), label: "problem_trigger", value: 1 }
|
|
41
|
-
context "problem trigger" do
|
|
42
|
-
let(:problem_triggers) { [problem_trigger] }
|
|
43
|
-
let(:expected_msg) do
|
|
44
|
-
msg = ["#{mock_nick}: Host: #{host.name} - status: #{problem_triggers.size} problems"]
|
|
45
|
-
problem_triggers.each do |trigger|
|
|
46
|
-
msg << "#{mock_nick}: status: #{trigger.label}"
|
|
47
|
-
end
|
|
48
|
-
msg.join("\n")
|
|
49
|
-
end
|
|
50
|
-
it "should report problem" do
|
|
51
|
-
expect(mock_message).to receive(:reply).with(expected_msg)
|
|
52
|
-
bot.host_status mock_message, host.name
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
context "ok trigger" do
|
|
57
|
-
let(:problem_triggers) { [] }
|
|
58
|
-
let(:expected_msg) { "#{mock_nick}: Host: #{host.name} - status: OK" }
|
|
59
|
-
it "should report problem" do
|
|
60
|
-
expect(mock_message).to receive(:reply).with(expected_msg)
|
|
61
|
-
bot.host_status mock_message, host.name
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end # context reporting
|
|
65
|
-
|
|
66
|
-
context "host identification" do
|
|
67
|
-
context "no hosts" do
|
|
68
|
-
let(:hosts) { [] }
|
|
69
|
-
let(:host_name) { "undefined_host_name" }
|
|
70
|
-
it "should not found host" do
|
|
71
|
-
expect(mock_message).to receive(:reply).with("#{mock_nick}: Host not found `#{host_name}`")
|
|
72
|
-
bot.host_status mock_message, host_name
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
context "2 - 10 hosts" do
|
|
77
|
-
let(:host1) { double "Host1", id: 1, name: "host-1" }
|
|
78
|
-
let(:host2) { double "Host2", id: 2, name: "host-2" }
|
|
79
|
-
let(:hosts) { [host1, host2] }
|
|
80
|
-
let(:expected_msg) { "#{mock_nick}: Found #{hosts.size} hosts: #{hosts.collect(&:name).join(', ')}. Be more specific" }
|
|
81
|
-
it "should print host names" do
|
|
82
|
-
expect(mock_message).to receive(:reply).with(expected_msg)
|
|
83
|
-
bot.host_status mock_message, "host"
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
context "more than 10 hosts" do
|
|
88
|
-
let(:hosts) { double "HostsArray", size: 11 }
|
|
89
|
-
let(:expected_msg) { "#{mock_nick}: Found #{hosts.size} Be more specific" }
|
|
90
|
-
it "should print host names" do
|
|
91
|
-
expect(mock_message).to receive(:reply).with(expected_msg)
|
|
92
|
-
bot.host_status mock_message, "host"
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end # context host identification
|
|
96
|
-
end # context #host_status
|
|
97
|
-
|
|
98
|
-
context "#host_latest" do
|
|
99
|
-
let(:host) { double "Host", id: 1, name: "Host1" }
|
|
100
|
-
let(:hosts) { [host] }
|
|
101
|
-
let(:event1) { double "Event", label: "Event 1 label" }
|
|
102
|
-
let(:events) { [event1] }
|
|
103
|
-
let(:expected_msg) do
|
|
104
|
-
msg = ["#{mock_nick}: Host: #{host.name} - showing last #{events.size} events"]
|
|
105
|
-
events.each do |event|
|
|
106
|
-
msg << "#{mock_nick}: !latest: #{event.label}"
|
|
107
|
-
end
|
|
108
|
-
msg.join("\n")
|
|
109
|
-
end
|
|
110
|
-
before do
|
|
111
|
-
allow(Zabbirc::Zabbix::Host).to receive(:get).and_return(hosts)
|
|
112
|
-
allow(Zabbirc::Zabbix::Event).to receive(:get).and_return(events)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it "should print latest events" do
|
|
116
|
-
expect(mock_message).to receive(:reply).with(expected_msg)
|
|
117
|
-
bot.host_latest mock_message, "Host1", nil
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
describe "#list_events" do
|
|
122
|
-
before do
|
|
123
|
-
allow(Zabbirc::Zabbix::Event).to receive(:recent).and_return(recent_events)
|
|
124
|
-
end
|
|
125
|
-
context "no last events" do
|
|
126
|
-
let(:recent_events) { [] }
|
|
127
|
-
|
|
128
|
-
it "should report no last events" do
|
|
129
|
-
expect(mock_message).to receive(:reply).with("#{mock_nick}: No last events for priority `#{Zabbirc::Priority.new(0)}`")
|
|
130
|
-
bot.list_events mock_message
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
context "some last events" do
|
|
135
|
-
let(:event1_information) { double "Event1", label: "Event 1 label", priority: Zabbirc::Priority.new(:information) }
|
|
136
|
-
let(:event2_information) { double "Event2", label: "Event 2 label", priority: Zabbirc::Priority.new(:information) }
|
|
137
|
-
let(:event3_high) { double "Event3", label: "Event 3 label", priority: Zabbirc::Priority.new(:high) }
|
|
138
|
-
let(:recent_events) { [event1_information, event2_information, event3_high] }
|
|
139
|
-
let(:expected_msg) { recent_events.collect{|e| "#{mock_nick}: #{e.label}"}.join("\n") }
|
|
140
|
-
|
|
141
|
-
before do
|
|
142
|
-
recent_events.each do |e|
|
|
143
|
-
allow(e).to receive(:any_host_matches?).and_return(false)
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it "should report all last events" do
|
|
148
|
-
expect(mock_message).to receive(:reply).with(expected_msg)
|
|
149
|
-
bot.list_events mock_message
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
context "with high priority filtered" do
|
|
153
|
-
let(:expected_msg) { [event3_high].collect{|e| "#{mock_nick}: #{e.label}"}.join("\n") }
|
|
154
|
-
it "should report high priority last events" do
|
|
155
|
-
expect(mock_message).to receive(:reply).with(expected_msg)
|
|
156
|
-
bot.list_events mock_message, "high"
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
context "with host filtered" do
|
|
161
|
-
let(:expected_msg) { [event1_information].collect{|e| "#{mock_nick}: #{e.label}"}.join("\n") }
|
|
162
|
-
it "should report host matched last events" do
|
|
163
|
-
allow(event1_information).to receive(:any_host_matches?).and_return(true )
|
|
164
|
-
expect(mock_message).to receive(:reply).with(expected_msg)
|
|
165
|
-
bot.list_events mock_message, "information", "host1"
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
describe "#show_settings" do
|
|
172
|
-
let(:mock_user_settings) { {primary_channel: "#channel-1", events_priority: "high", notify: false } }
|
|
173
|
-
let(:expected_msg) { "#{mock_nick}: notify: false, notify_recoveries: true, primary_channel: #channel-1, events_priority: high" }
|
|
174
|
-
it "should show settings" do
|
|
175
|
-
expect(mock_message).to receive(:reply).with(expected_msg)
|
|
176
|
-
bot.show_settings mock_message
|
|
177
|
-
end
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
describe "#set_setting" do
|
|
181
|
-
shared_examples "set_setting" do |key, value, expected_setting_value|
|
|
182
|
-
let(:expected_msg) { "#{mock_nick}: setting `#{key}` has been set to `#{expected_setting_value}`" }
|
|
183
|
-
let(:op) { bot.get_op mock_nick }
|
|
184
|
-
it "should set #{key} setting to #{value}" do
|
|
185
|
-
expect(mock_message).to receive(:reply).with(expected_msg)
|
|
186
|
-
bot.set_setting mock_message, key, value
|
|
187
|
-
expect(op.setting.get(key)).to eq expected_setting_value
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
context "notify" do
|
|
193
|
-
it_should_behave_like "set_setting", "notify", "false", false
|
|
194
|
-
it_should_behave_like "set_setting", "notify", "true", true
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
context "events_priority" do
|
|
198
|
-
it_should_behave_like "set_setting", "events_priority", "high", :high
|
|
199
|
-
it_should_behave_like "set_setting", "events_priority", "5", :disaster
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
context "primary_channel" do
|
|
203
|
-
before do
|
|
204
|
-
op.add_channel double("#channel1", name: "#channel1")
|
|
205
|
-
op.add_channel double("#channel2double", name: "#channel2")
|
|
206
|
-
end
|
|
207
|
-
it_should_behave_like "set_setting", "primary_channel", "#channel1", "#channel1"
|
|
208
|
-
it_should_behave_like "set_setting", "primary_channel", "#channel2", "#channel2"
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
end
|
|
212
|
-
end
|