From: Michael Friedrich Date: Wed, 4 Jun 2014 09:29:29 +0000 (+0200) Subject: Use hostname if fqdn is empty for NodeName. X-Git-Tag: v2.0.0-beta2~25 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1d048462a211cb83e18e296f94c9b73720fdd856;p=icinga2 Use hostname if fqdn is empty for NodeName. Refs #6393 --- diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index 9d428cb09..de8ee47e6 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -45,7 +45,20 @@ void IcingaApplication::StaticInitialize(void) ScriptVariable::Set("EnableHostChecks", true); ScriptVariable::Set("EnableServiceChecks", true); ScriptVariable::Set("EnablePerfdata", true); - ScriptVariable::Set("NodeName", Utility::GetFQDN()); + + String node_name = Utility::GetFQDN(); + + if (node_name.IsEmpty()) { + Log(LogNotice, "IcingaApplication", "No FQDN available. Trying Hostname."); + node_name = Utility::GetHostName(); + + if (node_name.IsEmpty()) { + Log(LogWarning, "IcingaApplication", "No FQDN nor Hostname available. Setting Nodename to 'localhost'."); + node_name = "localhost"; + } + } + + ScriptVariable::Set("NodeName", node_name); } REGISTER_STATSFUNCTION(IcingaApplicationStats, &IcingaApplication::StatsFunc);