From 1d048462a211cb83e18e296f94c9b73720fdd856 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Wed, 4 Jun 2014 11:29:29 +0200 Subject: [PATCH] Use hostname if fqdn is empty for NodeName. Refs #6393 --- lib/icinga/icingaapplication.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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); -- 2.49.0