Module: DefaultHostgroupBaseHostPatch
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/default_hostgroup_base_host_patch.rb
Defined Under Namespace
Modules: ManagedOverrides, Overrides
Instance Method Summary
collapse
Instance Method Details
#find_match(facts_map) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/default_hostgroup_base_host_patch.rb', line 50
def find_match(facts_map)
facts_map.each do |group_name, facts|
hg = Hostgroup.find_by(title: group_name)
return hg if hg.present? && group_matches?(facts)
end
Rails.logger.info 'No match ...'
false
end
|
#group_matches?(facts) ⇒ Boolean
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/default_hostgroup_base_host_patch.rb', line 59
def group_matches?(facts)
facts.each do |fact_name, fact_regex|
fact_regex.gsub!(%r{(\A/|/\z)}, '')
host_fact_value = host.facts[fact_name]
Rails.logger.info "Fact = #{fact_name}"
Rails.logger.info "Regex = #{fact_regex}"
return true if Regexp.new(fact_regex).match?(host_fact_value)
end
false
end
|
#host_has_no_hostgroup_or_forced? ⇒ Boolean
90
91
92
93
94
95
96
|
# File 'lib/default_hostgroup_base_host_patch.rb', line 90
def host_has_no_hostgroup_or_forced?
if !Setting[:force_hostgroup_match] && host.hostgroup.present?
Rails.logger.debug 'DefaultHostgroupMatch: skipping, host has hostgroup'
return false
end
true
end
|
#host_new_or_forced? ⇒ Boolean
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/default_hostgroup_base_host_patch.rb', line 78
def host_new_or_forced?
if Setting[:force_hostgroup_match_only_new]
new_host = ((Time.current - host.created_at) < 300)
unless new_host && host.hostgroup.nil? && host.reports.empty?
Rails.logger.debug 'DefaultHostgroupMatch: skipping, host exists'
return false
end
end
true
end
|
#settings_exist? ⇒ Boolean
70
71
72
73
74
75
76
|
# File 'lib/default_hostgroup_base_host_patch.rb', line 70
def settings_exist?
unless SETTINGS[:default_hostgroup] && SETTINGS[:default_hostgroup][:facts_map]
Rails.logger.warn 'DefaultHostgroupMatch: Could not load :default_hostgroup map from Settings.'
return false
end
true
end
|