diff --git a/lib/cli/nodesetupcommand.cpp b/lib/cli/nodesetupcommand.cpp index c452c2267..60bdef143 100644 --- a/lib/cli/nodesetupcommand.cpp +++ b/lib/cli/nodesetupcommand.cpp @@ -159,7 +159,12 @@ int NodeSetupCommand::SetupMaster(const boost::program_options::variables_map& v /* write zones.conf and update with zone + endpoint information */ Log(LogInformation, "cli", "Generating zone and object configuration."); - NodeUtility::GenerateNodeMasterIcingaConfig(); + std::vector globalZones; + + globalZones.push_back("global-templates"); + globalZones.push_back("director-global"); + + NodeUtility::GenerateNodeMasterIcingaConfig(globalZones); /* update the ApiListener config - SetupMaster() will always enable it */ Log(LogInformation, "cli", "Updating the APIListener feature."); @@ -419,7 +424,12 @@ int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm, Log(LogInformation, "cli", "Generating zone and object configuration."); - NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as >()); + std::vector globalZones; + + globalZones.push_back("global-templates"); + globalZones.push_back("director-global"); + + NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as >(), globalZones); /* update constants.conf with NodeName = CN */ if (cn != Utility::GetFQDN()) { diff --git a/lib/cli/nodeutility.cpp b/lib/cli/nodeutility.cpp index 21c0e815a..945ef0d3b 100644 --- a/lib/cli/nodeutility.cpp +++ b/lib/cli/nodeutility.cpp @@ -47,7 +47,7 @@ using namespace icinga; * Node Setup helpers */ -int NodeUtility::GenerateNodeIcingaConfig(const std::vector& endpoints) +int NodeUtility::GenerateNodeIcingaConfig(const std::vector& endpoints, const std::vector& globalZones) { Array::Ptr my_config = new Array(); @@ -111,6 +111,16 @@ int NodeUtility::GenerateNodeIcingaConfig(const std::vector& endpoi my_zone->Set("endpoints", my_zone_members); + for (const String& globalzone : globalZones) { + Dictionary::Ptr myGlobalZone = new Dictionary(); + + myGlobalZone->Set("__name", globalzone); + myGlobalZone->Set("__type", "Zone"); + myGlobalZone->Set("global", true); + + my_config->Add(myGlobalZone); + } + /* store the local config */ my_config->Add(my_endpoint); my_config->Add(my_zone); @@ -123,13 +133,14 @@ int NodeUtility::GenerateNodeIcingaConfig(const std::vector& endpoi return 0; } -int NodeUtility::GenerateNodeMasterIcingaConfig(void) +int NodeUtility::GenerateNodeMasterIcingaConfig(const std::vector& globalZones) { Array::Ptr my_config = new Array(); /* store the local generated node master configuration */ Dictionary::Ptr my_master_endpoint = new Dictionary(); Dictionary::Ptr my_master_zone = new Dictionary(); + Array::Ptr my_master_zone_members = new Array(); my_master_endpoint->Set("__name", new ConfigIdentifier("NodeName")); @@ -145,6 +156,16 @@ int NodeUtility::GenerateNodeMasterIcingaConfig(void) my_config->Add(my_master_endpoint); my_config->Add(my_master_zone); + for (const String& globalzone : globalZones) { + Dictionary::Ptr myGlobalZone = new Dictionary(); + + myGlobalZone->Set("__name", globalzone); + myGlobalZone->Set("__type", "Zone"); + myGlobalZone->Set("global", true); + + my_config->Add(myGlobalZone); + } + /* write the newly generated configuration */ String zones_path = Application::GetSysconfDir() + "/icinga2/zones.conf"; diff --git a/lib/cli/nodeutility.hpp b/lib/cli/nodeutility.hpp index ba3be55c2..be345d3b8 100644 --- a/lib/cli/nodeutility.hpp +++ b/lib/cli/nodeutility.hpp @@ -44,8 +44,8 @@ public: static void UpdateConstant(const String& name, const String& value); /* node setup helpers */ - static int GenerateNodeIcingaConfig(const std::vector& endpoints); - static int GenerateNodeMasterIcingaConfig(void); + static int GenerateNodeIcingaConfig(const std::vector& endpoints, const std::vector& globalZones); + static int GenerateNodeMasterIcingaConfig(const std::vector& globalZones); private: NodeUtility(void); diff --git a/lib/cli/nodewizardcommand.cpp b/lib/cli/nodewizardcommand.cpp index c3c003204..905e4084a 100644 --- a/lib/cli/nodewizardcommand.cpp +++ b/lib/cli/nodewizardcommand.cpp @@ -498,7 +498,12 @@ wizard_ticket: /* apilistener config */ Log(LogInformation, "cli", "Generating local zones.conf."); - NodeUtility::GenerateNodeIcingaConfig(endpoints); + std::vector globalZones; + + globalZones.push_back("global-templates"); + globalZones.push_back("director-global"); + + NodeUtility::GenerateNodeIcingaConfig(endpoints, globalZones); if (cn != Utility::GetFQDN()) { Log(LogWarning, "cli") @@ -594,7 +599,12 @@ int NodeWizardCommand::MasterSetup(void) const else std::cout << "'api' feature already enabled.\n"; - NodeUtility::GenerateNodeMasterIcingaConfig(); + std::vector globalZones; + + globalZones.push_back("global-templates"); + globalZones.push_back("director-global"); + + NodeUtility::GenerateNodeMasterIcingaConfig(globalZones); /* apilistener config */ std::cout << ConsoleColorTag(Console_Bold)