zabbirc 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zabbirc.rb +4 -0
- data/lib/zabbirc/irc/base_command.rb +34 -7
- data/lib/zabbirc/irc/maintenance_command.rb +103 -0
- data/lib/zabbirc/irc/plugin.rb +4 -0
- data/lib/zabbirc/irc/plugin_methods.rb +5 -0
- data/lib/zabbirc/irc/settings_command.rb +1 -20
- data/lib/zabbirc/version.rb +1 -1
- data/lib/zabbirc/zabbix/maintenance.rb +94 -0
- data/lib/zabbirc/zabbix/resource/associations.rb +1 -1
- data/spec/maintenance_command_spec.rb +92 -0
- data/spec/settings_command_spec.rb +24 -15
- data/tmp/playground.rb +10 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc13d87c01a24f572c2335c3b833a67bd69ac32e
|
4
|
+
data.tar.gz: f52a51ece4b4cadbccf80667bc0318ef49200624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dce36ab81b1e7ec021e638a3df1a005ecd028031bb882823cfc86a50f10f905156c191de858cb121ab3ae69741313d3be0187a2a16e77b352cfe97a91193d1b
|
7
|
+
data.tar.gz: 0bd55518c88310f0d03ba5bff6308a19bd8a657690dfcc324a673850e898af0efad0e99a8956625fea044888cab047a0f0b8bc53cab1f3e1215d9cec46670df8
|
data/lib/zabbirc.rb
CHANGED
@@ -16,8 +16,14 @@ module Zabbirc
|
|
16
16
|
@ops = ops
|
17
17
|
@message = message
|
18
18
|
@op = get_op @message
|
19
|
-
@cmd = cmd.to_s.strip.gsub(/\s{2,}/," ")
|
20
|
-
@args = @cmd
|
19
|
+
@cmd = cmd.to_s.strip.gsub(/\s{2,}/," ").freeze
|
20
|
+
@args = parse_arguments @cmd
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_arguments cmd
|
24
|
+
cmd.scan(/'[a-zA-Z0-9_\-,# ]+'|[a-zA-Z0-9_\-,#]+/).collect do |x|
|
25
|
+
x.match(/[a-zA-Z0-9_\-,# ]+/)[0]
|
26
|
+
end
|
21
27
|
end
|
22
28
|
|
23
29
|
def run
|
@@ -68,18 +74,39 @@ module Zabbirc
|
|
68
74
|
end
|
69
75
|
|
70
76
|
def find_host host
|
71
|
-
hosts = Zabbix::Host.get(search: {
|
77
|
+
hosts = Zabbix::Host.get(search: {name: host})
|
72
78
|
case hosts.size
|
73
79
|
when 0
|
74
|
-
|
80
|
+
raise UserInputError, "Host not found `#{host}`"
|
75
81
|
when 1
|
76
82
|
return hosts.first
|
77
83
|
when 2..10
|
78
|
-
|
84
|
+
raise UserInputError, "Found #{hosts.size} hosts: #{hosts.collect(&:name).join(', ')}. Be more specific"
|
79
85
|
else
|
80
|
-
|
86
|
+
raise UserInputError, "Found #{hosts.size} Be more specific"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def find_hosts names
|
91
|
+
names.collect{|name| find_host name }
|
92
|
+
end
|
93
|
+
|
94
|
+
def find_host_group name
|
95
|
+
host_group = Zabbix::HostGroup.get(search: { name: name })
|
96
|
+
case host_group.size
|
97
|
+
when 0
|
98
|
+
raise UserInputError, "Cannot find hostgroup with name: `#{name}`"
|
99
|
+
when 1
|
100
|
+
host_group.first
|
101
|
+
when 2..10
|
102
|
+
raise UserInputError, "Found #{host_group.size} host groups using name: `#{name}` be more specific. Host groups: #{host_group.collect(&:name).join(", ")}"
|
103
|
+
else
|
104
|
+
raise UserInputError, "Found #{host_group.size} host groups using name: `#{name}` be more specific"
|
81
105
|
end
|
82
|
-
|
106
|
+
end
|
107
|
+
|
108
|
+
def find_host_groups names
|
109
|
+
names.collect{ |name| find_host_group(name) }
|
83
110
|
end
|
84
111
|
|
85
112
|
def find_event short_eventid
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Zabbirc
|
2
|
+
module Irc
|
3
|
+
class MaintenanceCommand < BaseCommand
|
4
|
+
register_help "maint", [
|
5
|
+
"Show active maintenances: !maint",
|
6
|
+
"Schedule a maintenance: !maint [hostgroups] '<host_name>|<hostgroup_name>[, <host_name>|<hostgroup_name>]' <duration> <reason>",
|
7
|
+
" - duration format: 1h, 30m, 1h30m. h - hour, m - minute.",
|
8
|
+
"Delete a maintenance: !maint delete <maintenance-id>"
|
9
|
+
]
|
10
|
+
private
|
11
|
+
def perform
|
12
|
+
first_arg = @args.first
|
13
|
+
case first_arg
|
14
|
+
when nil
|
15
|
+
perform_list
|
16
|
+
when "delete"
|
17
|
+
@args.shift
|
18
|
+
perform_delete
|
19
|
+
else
|
20
|
+
perform_create
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def perform_list
|
25
|
+
maintenances = Zabbix::Maintenance.get(selectHosts: :extend, selectGroups: :extend, selectTimePeriods: :extend)
|
26
|
+
active_maintenances = maintenances.select(&:active?)
|
27
|
+
if active_maintenances.empty?
|
28
|
+
reply "No active maintenances at this moment."
|
29
|
+
else
|
30
|
+
reply active_maintenances.collect(&:label)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def perform_create
|
36
|
+
params = {}
|
37
|
+
hostgroups_flag = @args.shift
|
38
|
+
if hostgroups_flag == "hostgroups"
|
39
|
+
target_names = @args.shift
|
40
|
+
raise UserInputError, help_features["maint"] unless target_names
|
41
|
+
target_names = target_names.split(/,/).collect(&:strip)
|
42
|
+
params[:host_group_ids] = find_host_groups(target_names).collect(&:id)
|
43
|
+
else
|
44
|
+
target_names = hostgroups_flag.split(/,/).collect(&:strip)
|
45
|
+
params[:host_ids] = find_hosts(target_names).collect(&:id)
|
46
|
+
end
|
47
|
+
|
48
|
+
params[:duration] = parse_duration @args.shift
|
49
|
+
params[:name] = @args.join(" ")
|
50
|
+
raise raise UserInputError, "no reason specified" if params[:name].blank?
|
51
|
+
|
52
|
+
id = Zabbix::Maintenance.create params
|
53
|
+
maintenance = Zabbix::Maintenance.find(id)
|
54
|
+
reply [
|
55
|
+
"maintenance scheduled since #{maintenance.active_since.to_formatted_s(:short)} till #{maintenance.active_till.to_formatted_s(:short)}",
|
56
|
+
maintenance.label
|
57
|
+
]
|
58
|
+
end
|
59
|
+
|
60
|
+
def perform_delete
|
61
|
+
maintenance = find_maintenance @args.shift
|
62
|
+
|
63
|
+
begin
|
64
|
+
maintenance.destroy
|
65
|
+
reply "maintenance with id #{maintenance.shorten_id} has been deleted"
|
66
|
+
rescue ::Zabbix::Client::Error => e
|
67
|
+
reply "an error occured while deleting maintenance with id #{maintenance.shorten_id}: #{e}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def find_maintenance shorten_id
|
72
|
+
maintenance_id = Zabbirc.maintenances_id_shortener.get_id shorten_id
|
73
|
+
raise UserInputError, "Bad maintenance id `#{shorten_id}`" unless maintenance_id
|
74
|
+
|
75
|
+
maintenance = Zabbix::Maintenance.find(maintenance_id)
|
76
|
+
raise UserInputError, "Could not find maintenance with id `#{shorten_id}`" if maintenance.nil?
|
77
|
+
maintenance
|
78
|
+
|
79
|
+
rescue Zabbix::IDNotUniqueError => e
|
80
|
+
raise UserInputError, "Could not find maintenance: #{e}"
|
81
|
+
end
|
82
|
+
|
83
|
+
def find_targets names, hostgroups_flag
|
84
|
+
names = names.split(/,/).collect(&:strip)
|
85
|
+
if hostgroups_flag
|
86
|
+
find_host_groups names
|
87
|
+
else
|
88
|
+
find_hosts names
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def parse_duration duration_str
|
93
|
+
raise UserInputError, help_features["maint"] unless duration_str
|
94
|
+
match_data = duration_str.match(/(?:(?<minutes>[0-9]+[mM])|(?:(?<hours>[0-9]+)[hH](?<minutes>[0-9]+[mM])?))/)
|
95
|
+
raise UserInputError, ["cannot parse duration `#{duration_str}`", help_features["maint"]].flatten unless match_data
|
96
|
+
duration = 0
|
97
|
+
duration += match_data[:hours].to_i.hours if match_data[:hours]
|
98
|
+
duration += match_data[:minutes].to_i.minutes if match_data[:minutes]
|
99
|
+
duration
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/zabbirc/irc/plugin.rb
CHANGED
@@ -135,25 +135,6 @@ module Zabbirc
|
|
135
135
|
end
|
136
136
|
[key, value, host_groups_flag, host_groups]
|
137
137
|
end
|
138
|
-
|
139
|
-
def find_host_groups names
|
140
|
-
names.collect do |name|
|
141
|
-
host_group = Zabbix::HostGroup.get(search: { name: name })
|
142
|
-
case host_group.size
|
143
|
-
when 0
|
144
|
-
raise UserInputError, "Cannot find hostgroup with name: `#{name}`"
|
145
|
-
when 1
|
146
|
-
host_group.first
|
147
|
-
when 2..10
|
148
|
-
raise UserInputError, "Found #{host_group.size} host groups using name: `#{name}` be more specific. Host groups: #{host_group.collect(&:name).join(", ")}"
|
149
|
-
else
|
150
|
-
raise UserInputError, "Found #{host_group.size} host groups using name: `#{name}` be more specific"
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
138
|
end
|
156
139
|
end
|
157
|
-
end
|
158
|
-
|
159
|
-
# TODO filtrovanie eventov podla hostgroup
|
140
|
+
end
|
data/lib/zabbirc/version.rb
CHANGED
@@ -0,0 +1,94 @@
|
|
1
|
+
module Zabbirc
|
2
|
+
module Zabbix
|
3
|
+
class Maintenance < Resource::Base
|
4
|
+
|
5
|
+
has_many :hosts
|
6
|
+
has_many :groups, class_name: "HostGroup"
|
7
|
+
|
8
|
+
def self.find id, *options
|
9
|
+
options = options.extract_options!
|
10
|
+
options[:selectHosts] = :extend
|
11
|
+
options[:selectGroups] = :extend
|
12
|
+
super(id, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.create *options
|
16
|
+
default_options = {
|
17
|
+
host_ids: [],
|
18
|
+
host_group_ids: []
|
19
|
+
}
|
20
|
+
|
21
|
+
options = options.extract_options!
|
22
|
+
options = options.reverse_merge(default_options)
|
23
|
+
|
24
|
+
duration = options[:duration]
|
25
|
+
name = options[:name]
|
26
|
+
host_ids = options[:host_ids]
|
27
|
+
host_group_ids = options[:host_group_ids]
|
28
|
+
maint_start = Time.current
|
29
|
+
maint_end = maint_start + duration
|
30
|
+
|
31
|
+
r = api.maintenance.create(
|
32
|
+
name: name,
|
33
|
+
active_since: maint_start.to_i,
|
34
|
+
active_till: maint_end.to_i,
|
35
|
+
hostids: host_ids,
|
36
|
+
groupids: host_group_ids,
|
37
|
+
timeperiods: [
|
38
|
+
{
|
39
|
+
timeperiod_type: 0,
|
40
|
+
start_time: maint_start.to_i,
|
41
|
+
period: duration
|
42
|
+
}
|
43
|
+
]
|
44
|
+
)
|
45
|
+
|
46
|
+
r["maintenanceids"].first
|
47
|
+
end
|
48
|
+
|
49
|
+
def shorten_id
|
50
|
+
@shorten_id ||= Zabbirc.maintenances_id_shortener.get_shorten_id id
|
51
|
+
end
|
52
|
+
|
53
|
+
def active_since
|
54
|
+
Time.at(super.to_i)
|
55
|
+
end
|
56
|
+
|
57
|
+
def active_till
|
58
|
+
Time.at(super.to_i)
|
59
|
+
end
|
60
|
+
|
61
|
+
def active?
|
62
|
+
(active_since..active_till).cover? Time.current
|
63
|
+
end
|
64
|
+
|
65
|
+
def label
|
66
|
+
format_label "|%sid| %start -> %end >> %name %targets"
|
67
|
+
end
|
68
|
+
|
69
|
+
def format_label fmt
|
70
|
+
fmt.gsub("%start", "#{active_since.to_formatted_s(:short)}").
|
71
|
+
gsub("%end", "#{active_till.to_formatted_s(:short)}").
|
72
|
+
gsub("%name", "#{name}").
|
73
|
+
gsub("%id", "#{id}").
|
74
|
+
gsub("%sid", "#{shorten_id}").
|
75
|
+
gsub("%targets", "#{target_labels}")
|
76
|
+
end
|
77
|
+
|
78
|
+
def target_labels
|
79
|
+
host_names = hosts.collect(&:name)
|
80
|
+
group_names = groups.collect(&:name)
|
81
|
+
|
82
|
+
r = ""
|
83
|
+
r << "Hosts: #{host_names.join(", ")}" if host_names.present?
|
84
|
+
r << "Host Groups: #{group_names.join(", ")}" if group_names.present?
|
85
|
+
r
|
86
|
+
end
|
87
|
+
|
88
|
+
def destroy
|
89
|
+
api.maintenance.delete [id]
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -16,7 +16,7 @@ module Zabbirc
|
|
16
16
|
hash_data = @attrs[options[:zabbix_attribute]]
|
17
17
|
if hash_data.blank?
|
18
18
|
this = self.class.find id, extend_key => :extend
|
19
|
-
raise StandardError, "zabbix response does not contain #{options[:zabbix_attribute]}" if this[options[:zabbix_attribute]].
|
19
|
+
raise StandardError, "zabbix response does not contain #{options[:zabbix_attribute]}" if this[options[:zabbix_attribute]].nil?
|
20
20
|
hash_data = this[options[:zabbix_attribute]]
|
21
21
|
end
|
22
22
|
|
@@ -0,0 +1,92 @@
|
|
1
|
+
describe Zabbirc::Irc::MaintenanceCommand 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(:maintenance_command) { Zabbirc::Irc::MaintenanceCommand.new ops_builder.ops, mock_message, cmd }
|
8
|
+
|
9
|
+
|
10
|
+
describe "list maintenances" do
|
11
|
+
let(:cmd) { "" }
|
12
|
+
|
13
|
+
before do
|
14
|
+
allow(Zabbirc::Zabbix::Maintenance).to receive(:get).and_return(maintenances)
|
15
|
+
end
|
16
|
+
|
17
|
+
context "no active maintenances" do
|
18
|
+
let(:maintenances) { [] }
|
19
|
+
let(:expected_message) { "#{mock_nick}: No active maintenances at this moment." }
|
20
|
+
|
21
|
+
it "should print active maintenances" do
|
22
|
+
expect(mock_message).to receive(:reply).with(expected_message)
|
23
|
+
maintenance_command.run
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "active maintenances exist" do
|
28
|
+
let(:maint1) { double("Maintenance", label: "maint 1 label", active?: true) }
|
29
|
+
let(:maint2) { double("Maintenance", label: "maint 2 label", active?: true) }
|
30
|
+
let(:maintenances) { [maint1, maint2] }
|
31
|
+
|
32
|
+
let(:expected_message) do
|
33
|
+
maintenances.collect do |maintenance|
|
34
|
+
"#{mock_nick}: #{maintenance.label}"
|
35
|
+
end.join("\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
it "should print active maintenances" do
|
40
|
+
expect(mock_message).to receive(:reply).with(expected_message)
|
41
|
+
maintenance_command.run
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "create maintenance" do
|
47
|
+
let(:host1) { double("Host", id: 1, name: "Host1") }
|
48
|
+
let(:host2) { double("Host", id: 2, name: "Host2") }
|
49
|
+
let(:hosts) { [host1, host2] }
|
50
|
+
|
51
|
+
let(:host_group1) { double("HostGroup", id: 11, name: "HostGroup1") }
|
52
|
+
let(:host_group2) { double("HostGroup", id: 12, name: "HostGroup2") }
|
53
|
+
let(:host_groups) { [host_group1, host_group2] }
|
54
|
+
|
55
|
+
let(:duration) { "1h30m" }
|
56
|
+
let(:duration_int) { (1.hour + 30.minutes).to_i }
|
57
|
+
let(:reason) { "some reason" }
|
58
|
+
|
59
|
+
let(:created_maintenance) { double("Maintenance", label: "maintenance label", active_since: Time.now, active_till: Time.now) }
|
60
|
+
|
61
|
+
before do
|
62
|
+
allow(Zabbirc::Zabbix::Maintenance).to receive(:create).with(any_args).and_return(true)
|
63
|
+
allow(Zabbirc::Zabbix::Host).to receive(:get).with(hash_including(search: { name: anything })) do |params|
|
64
|
+
hosts.select{|g| g.name =~ /#{params[:search][:name]}/ }
|
65
|
+
end
|
66
|
+
allow(Zabbirc::Zabbix::HostGroup).to receive(:get).with(hash_including(search: { name: anything })) do |params|
|
67
|
+
host_groups.select{|g| g.name =~ /#{params[:search][:name]}/ }
|
68
|
+
end
|
69
|
+
allow(Zabbirc::Zabbix::Maintenance).to receive(:find).and_return(created_maintenance)
|
70
|
+
end
|
71
|
+
|
72
|
+
context "hosts" do
|
73
|
+
let(:cmd) { "'#{host1.name},#{host2.name}' #{duration} #{reason}" }
|
74
|
+
it "should create maintenance" do
|
75
|
+
expect(Zabbirc::Zabbix::Maintenance).to receive(:create).with(duration: duration_int, host_ids: hosts.collect(&:id), name: reason)
|
76
|
+
expect(mock_message).to receive(:reply)
|
77
|
+
maintenance_command.run
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "host groups" do
|
82
|
+
let(:cmd) { "hostgroups '#{host_group1.name},#{host_group2.name}' #{duration} #{reason}" }
|
83
|
+
it "should create maintenance" do
|
84
|
+
expect(Zabbirc::Zabbix::Maintenance).to receive(:create).with(duration: duration_int, host_group_ids: host_groups.collect(&:id), name: reason)
|
85
|
+
expect(mock_message).to receive(:reply)
|
86
|
+
maintenance_command.run
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
@@ -51,7 +51,8 @@ describe Zabbirc::Irc::SettingsCommand do
|
|
51
51
|
context "group specific" do
|
52
52
|
let(:group1) { double "HostGroup", id: 1, name: "Group1" }
|
53
53
|
let(:group2) { double "HostGroup", id: 2, name: "Group2" }
|
54
|
-
let(:
|
54
|
+
let(:group3) { double "HostGroup", id: 3, name: "Group3" }
|
55
|
+
let(:groups) { [group1, group2, group3] }
|
55
56
|
before do
|
56
57
|
allow(Zabbirc::Zabbix::HostGroup).to receive(:get) { groups }
|
57
58
|
allow(Zabbirc::Zabbix::HostGroup).to receive(:get).with(hash_including(search: { name: anything })) do |params|
|
@@ -60,64 +61,72 @@ describe Zabbirc::Irc::SettingsCommand do
|
|
60
61
|
end
|
61
62
|
|
62
63
|
shared_examples "set_group_setting" do |key, value, expected_setting_value|
|
63
|
-
let(:
|
64
|
-
let(:
|
64
|
+
let(:affected_host_groups_names) { affected_host_groups.collect(&:name).join(", ") }
|
65
|
+
let(:expected_msg) { "#{mock_nick}: setting `#{key}` has been set to `#{expected_setting_value}` for host groups: #{affected_host_groups_names}" }
|
66
|
+
let(:cmd) { "set #{key} #{value} hostgroups '#{affected_host_groups_names}'"}
|
65
67
|
it "should set #{key} setting to #{value} for host group" do
|
66
68
|
old_global_value = mock_op.setting.get(key)
|
67
69
|
|
68
70
|
expect(mock_message).to receive(:reply).with(expected_msg)
|
69
71
|
settings_command.run
|
70
|
-
|
72
|
+
affected_host_groups.each do |group|
|
73
|
+
expect(mock_op.setting.get(key, host_group_id: group.id)).to eq expected_setting_value
|
74
|
+
end
|
71
75
|
|
72
76
|
expect(mock_op.setting.get(key)).to eq old_global_value
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
76
80
|
shared_examples "set_all_groups_setting" do |key, value, expected_setting_value|
|
81
|
+
let(:affected_host_groups_names) { affected_host_groups.collect(&:name).join(", ") }
|
77
82
|
let(:settings_command1) { Zabbirc::Irc::SettingsCommand.new ops_builder.ops, mock_message, cmd1 }
|
78
83
|
let(:settings_command2) { Zabbirc::Irc::SettingsCommand.new ops_builder.ops, mock_message, cmd2 }
|
79
84
|
|
80
|
-
let!(:old_global_value) { mock_op.setting.get(key
|
81
|
-
let(:expected_msg1) { "#{mock_nick}: setting `#{key}` has been set to `#{expected_setting_value}` for host groups: #{
|
85
|
+
let!(:old_global_value) { mock_op.setting.get(key) }
|
86
|
+
let(:expected_msg1) { "#{mock_nick}: setting `#{key}` has been set to `#{expected_setting_value}` for host groups: #{affected_host_groups_names}" }
|
82
87
|
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 #{
|
88
|
+
let(:cmd1) { "set #{key} #{value} hostgroups #{affected_host_groups_names}"}
|
84
89
|
let(:cmd2) { "set #{key} #{old_global_value} hostgroups-all"}
|
85
90
|
it "should set #{key} setting to #{value} for all host groups" do
|
86
91
|
# sets host group specific setting
|
87
92
|
expect(mock_message).to receive(:reply).with(expected_msg1)
|
88
93
|
settings_command1.run
|
89
|
-
|
94
|
+
affected_host_groups.each do |group|
|
95
|
+
expect(mock_op.setting.get(key, host_group_id: group.id)).to eq expected_setting_value
|
96
|
+
end
|
90
97
|
expect(mock_op.setting.get(key)).to eq old_global_value
|
91
98
|
|
92
99
|
expect(mock_message).to receive(:reply).with(expected_msg2)
|
93
100
|
settings_command2.run
|
94
|
-
|
101
|
+
affected_host_groups.each do |group|
|
102
|
+
expect(mock_op.setting.get(key, host_group_id: group.id)).to eq old_global_value
|
103
|
+
end
|
95
104
|
expect(mock_op.setting.get(key)).to eq old_global_value
|
96
105
|
end
|
97
106
|
end
|
98
107
|
|
99
108
|
it_should_behave_like "set_group_setting", "notify", "false", false do
|
100
|
-
let(:
|
109
|
+
let(:affected_host_groups) { [group1, group2] }
|
101
110
|
end
|
102
111
|
|
103
112
|
it_should_behave_like "set_group_setting", "events_priority", "high", :high do
|
104
|
-
let(:
|
113
|
+
let(:affected_host_groups) { [group1, group2] }
|
105
114
|
end
|
106
115
|
|
107
116
|
it_should_behave_like "set_group_setting", "events_priority", "5", :disaster do
|
108
|
-
let(:
|
117
|
+
let(:affected_host_groups) { [group1, group2] }
|
109
118
|
end
|
110
119
|
|
111
120
|
it_should_behave_like "set_all_groups_setting", "notify", "false", false do
|
112
|
-
let(:
|
121
|
+
let(:affected_host_groups) { [group1, group2] }
|
113
122
|
end
|
114
123
|
|
115
124
|
it_should_behave_like "set_all_groups_setting", "events_priority", "high", :high do
|
116
|
-
let(:
|
125
|
+
let(:affected_host_groups) { [group1, group2] }
|
117
126
|
end
|
118
127
|
|
119
128
|
it_should_behave_like "set_all_groups_setting", "events_priority", "5", :disaster do
|
120
|
-
let(:
|
129
|
+
let(:affected_host_groups) { [group1, group2] }
|
121
130
|
end
|
122
131
|
|
123
132
|
end
|
data/tmp/playground.rb
CHANGED
@@ -20,3 +20,13 @@ s.set :events_priority, :high, host_group_id: 1
|
|
20
20
|
|
21
21
|
|
22
22
|
c = SettingsCommand.new
|
23
|
+
|
24
|
+
|
25
|
+
def get_event short_id
|
26
|
+
Zabbirc.events_id_shortener.get_id(short_id)
|
27
|
+
Event.get(
|
28
|
+
event_ids: short_id,
|
29
|
+
selectRelatedObject: :extend,
|
30
|
+
selectHosts: :extend
|
31
|
+
)
|
32
|
+
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.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/zabbirc/irc/help.rb
|
124
124
|
- lib/zabbirc/irc/help_command.rb
|
125
125
|
- lib/zabbirc/irc/host_command.rb
|
126
|
+
- lib/zabbirc/irc/maintenance_command.rb
|
126
127
|
- lib/zabbirc/irc/plugin.rb
|
127
128
|
- lib/zabbirc/irc/plugin_methods.rb
|
128
129
|
- lib/zabbirc/irc/settings_command.rb
|
@@ -141,6 +142,7 @@ files:
|
|
141
142
|
- lib/zabbirc/zabbix/event.rb
|
142
143
|
- lib/zabbirc/zabbix/host.rb
|
143
144
|
- lib/zabbirc/zabbix/host_group.rb
|
145
|
+
- lib/zabbirc/zabbix/maintenance.rb
|
144
146
|
- lib/zabbirc/zabbix/resource/associations.rb
|
145
147
|
- lib/zabbirc/zabbix/resource/base.rb
|
146
148
|
- lib/zabbirc/zabbix/resource/finders.rb
|
@@ -149,6 +151,7 @@ files:
|
|
149
151
|
- spec/event_command_spec.rb
|
150
152
|
- spec/host_command_spec.rb
|
151
153
|
- spec/id_shortener_spec.rb
|
154
|
+
- spec/maintenance_command_spec.rb
|
152
155
|
- spec/settings_command_spec.rb
|
153
156
|
- spec/spec_helper.rb
|
154
157
|
- spec/support/mock_bot.rb
|