Class: Zabbirc::Zabbix::Maintenance
Class Method Summary
collapse
Instance Method Summary
collapse
#[], api, #api, #id, id_attr_name, #initialize, #method_missing, model_name, set_id_attr_name, set_model_name
#has_many, #has_one
#find, #get
Class Method Details
.create(*options) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/zabbirc/zabbix/maintenance.rb', line 15
def self.create *options
default_options = {
host_ids: [],
host_group_ids: []
}
options = options.
options = options.reverse_merge(default_options)
duration = options[:duration]
name = options[:name]
host_ids = options[:host_ids]
host_group_ids = options[:host_group_ids]
maint_start = Time.current
maint_end = maint_start + duration
r = api.maintenance.create(
name: name,
active_since: maint_start.to_i,
active_till: maint_end.to_i,
hostids: host_ids,
groupids: host_group_ids,
timeperiods: [
{
timeperiod_type: 0,
start_time: maint_start.to_i,
period: duration
}
]
)
r["maintenanceids"].first
end
|
.find(id, *options) ⇒ Object
8
9
10
11
12
13
|
# File 'lib/zabbirc/zabbix/maintenance.rb', line 8
def self.find id, *options
options = options.
options[:selectHosts] = :extend
options[:selectGroups] = :extend
super(id, options)
end
|
Instance Method Details
#active? ⇒ Boolean
61
62
63
|
# File 'lib/zabbirc/zabbix/maintenance.rb', line 61
def active?
(active_since..active_till).cover? Time.current
end
|
#active_since ⇒ Object
53
54
55
|
# File 'lib/zabbirc/zabbix/maintenance.rb', line 53
def active_since
Time.at(super.to_i)
end
|
#active_till ⇒ Object
57
58
59
|
# File 'lib/zabbirc/zabbix/maintenance.rb', line 57
def active_till
Time.at(super.to_i)
end
|
#destroy ⇒ Object
88
89
90
|
# File 'lib/zabbirc/zabbix/maintenance.rb', line 88
def destroy
api.maintenance.delete [id]
end
|
69
70
71
72
73
74
75
76
|
# File 'lib/zabbirc/zabbix/maintenance.rb', line 69
def format_label fmt
fmt.gsub("%start", "#{active_since.to_formatted_s(:short)}").
gsub("%end", "#{active_till.to_formatted_s(:short)}").
gsub("%name", "#{name}").
gsub("%id", "#{id}").
gsub("%sid", "#{shorten_id}").
gsub("%targets", "#{target_labels}")
end
|
#label ⇒ Object
65
66
67
|
# File 'lib/zabbirc/zabbix/maintenance.rb', line 65
def label
format_label "|%sid| %start -> %end >> %name %targets"
end
|
#target_labels ⇒ Object
78
79
80
81
82
83
84
85
86
|
# File 'lib/zabbirc/zabbix/maintenance.rb', line 78
def target_labels
host_names = hosts.collect(&:name)
group_names = groups.collect(&:name)
r = ""
r << "Hosts: #{host_names.join(", ")}" if host_names.present?
r << "Host Groups: #{group_names.join(", ")}" if group_names.present?
r
end
|