[icinga-checkins] icinga.org: icinga2/next: Use hostname if fqdn is empty for NodeName.

git at icinga.org git at icinga.org
Wed Jun 4 11:30:38 CEST 2014


Module: icinga2
Branch: next
Commit: 1d048462a211cb83e18e296f94c9b73720fdd856
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=1d048462a211cb83e18e296f94c9b73720fdd856

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Wed Jun  4 11:29:29 2014 +0200

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 9d428cb..de8ee47 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);



More information about the icinga-checkins mailing list