diff --git a/app/models/host/base.rb b/app/models/host/base.rb index 2398ef8d42f4..01a0a511002e 100644 --- a/app/models/host/base.rb +++ b/app/models/host/base.rb @@ -115,6 +115,7 @@ def dup :domain=, :domain_id=, :domain_name=, :to => :primary_interface attr_writer :updated_virtuals + def updated_virtuals @updated_virtuals ||= [] end @@ -351,6 +352,14 @@ def render_template(template:, **params) template.render(host: self, **params) end + def to_label + if Setting[:append_domain_name_for_hosts] + name.to_s + else + name.to_s.split('.')[0] + end + end + private def parse_ip_address(address, ignore_link_local: true) diff --git a/app/views/api/v2/hosts/base.json.rabl b/app/views/api/v2/hosts/base.json.rabl index 417623b70925..b3412d283e0e 100644 --- a/app/views/api/v2/hosts/base.json.rabl +++ b/app/views/api/v2/hosts/base.json.rabl @@ -1,3 +1,11 @@ object @host -attributes :name, :id +attributes :id + +node :name do |name| + if Setting[:append_domain_name_for_hosts] + name.split('.')[0] + else + name + end +end \ No newline at end of file