From 64298c35efe70243e2f518de3a49610463f5265b Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 28 Oct 2014 19:46:10 +0100 Subject: [PATCH] Cli: Add agents.conf w/ default agent templates for 'agent update-config' refs #7248 --- etc/CMakeLists.txt | 1 + etc/icinga2/conf.d/agent.conf | 23 +++++++++++++++++++++++ lib/cli/agentupdateconfigcommand.cpp | 12 ++++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 etc/icinga2/conf.d/agent.conf diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt index b4dbe57e0..03906863e 100644 --- a/etc/CMakeLists.txt +++ b/etc/CMakeLists.txt @@ -26,6 +26,7 @@ install_if_not_exists(${CMAKE_CURRENT_BINARY_DIR}/icinga2/init.conf ${CMAKE_INST install_if_not_exists(icinga2/icinga2.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2) install_if_not_exists(${CMAKE_CURRENT_BINARY_DIR}/icinga2/constants.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2) install_if_not_exists(icinga2/zones.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2) +install_if_not_exists(icinga2/conf.d/agent.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) install_if_not_exists(icinga2/conf.d/commands.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) install_if_not_exists(icinga2/conf.d/downtimes.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) install_if_not_exists(icinga2/conf.d/groups.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d) diff --git a/etc/icinga2/conf.d/agent.conf b/etc/icinga2/conf.d/agent.conf new file mode 100644 index 000000000..b69913a21 --- /dev/null +++ b/etc/icinga2/conf.d/agent.conf @@ -0,0 +1,23 @@ +/* + * Host and Service templates for the Agent Setup. + */ + + +/** + * Provides settings for agent hosts managed by 'icinga2 repository'. + * Define your global agent attributes here, for example custom + * attributes used for notifications, etc. + */ +template Host "agent-host" { + +} + +/** + * Provides settings for agent services managed by 'icinga2 repository'. + * Define your global agent attributes here, for example custom + * attributes used for notifications, etc. + */ +template Service "agent-service" { + +} + diff --git a/lib/cli/agentupdateconfigcommand.cpp b/lib/cli/agentupdateconfigcommand.cpp index 018c7997c..e76b161b9 100644 --- a/lib/cli/agentupdateconfigcommand.cpp +++ b/lib/cli/agentupdateconfigcommand.cpp @@ -118,9 +118,13 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v Dictionary::Ptr host_attrs = make_shared(); host_attrs->Set("__name", host); host_attrs->Set("name", host); - host_attrs->Set("check_command", "dummy"); //TODO: add a repository-host template + host_attrs->Set("check_command", "dummy"); host_attrs->Set("zone", zone); + Array::Ptr host_imports = make_shared(); + host_imports->Add("agent-host"); //default host agent template + host_attrs->Set("import", host_imports); + if (!RepositoryUtility::AddObject(host, "Host", host_attrs)) { Log(LogCritical, "cli") << "Cannot add agent host '" << host << "' to the config repository!\n"; @@ -159,9 +163,13 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v service_attrs->Set("__name", long_name); service_attrs->Set("name", service); service_attrs->Set("host_name", host); //Required for host-service relation - service_attrs->Set("check_command", "dummy"); //TODO: add a repository-service template + service_attrs->Set("check_command", "dummy"); service_attrs->Set("zone", zone); + Array::Ptr service_imports = make_shared(); + service_imports->Add("agent-service"); //default service agent template + service_attrs->Set("import", service_imports); + if (!RepositoryUtility::AddObject(service, "Service", service_attrs)) { Log(LogCritical, "cli") << "Cannot add agent host '" << host << "' to the config repository!\n"; -- 2.40.0