From 8cc08eb59ddd87e32b67be4551f29af56f359eda Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Mon, 4 Jun 2012 12:28:08 -0500 Subject: NagiosGen: Create empty config.xml when missing This allows new users to get setup more quickly without having to worry about the tweaking capabilities available in config.xml. Signed-off-by: Sol Jerome --- doc/server/plugins/generators/nagiosgen.txt | 12 ++++-------- src/lib/Bcfg2/Server/Plugins/NagiosGen.py | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/doc/server/plugins/generators/nagiosgen.txt b/doc/server/plugins/generators/nagiosgen.txt index db0a06d9f..f722909fc 100644 --- a/doc/server/plugins/generators/nagiosgen.txt +++ b/doc/server/plugins/generators/nagiosgen.txt @@ -18,13 +18,9 @@ Create the NagiosGen directory:: $ mkdir /var/lib/bcfg2/NagiosGen -Create an empty config.xml:: - - $ echo "" >> /var/lib/bcfg2/NagiosGen/config.xml - Create default host, and group specs in: -* /var/lib/bcfg2/NagiosGen/default-host.cfg:: +``/var/lib/bcfg2/NagiosGen/default-host.cfg``:: define host{ name default @@ -48,7 +44,7 @@ Create default host, and group specs in: retry_interval 1 } -* /var/lib/bcfg2/NagiosGen/default-group.cfg:: +``/var/lib/bcfg2/NagiosGen/default-group.cfg``:: define service{ name default-service @@ -77,7 +73,7 @@ Create default host, and group specs in: Create group configuration files (Named identical to Bcfg2 groups) and add services, and commands specific to the hostgroup (Bcfg2 group) in -* /var/lib/bcfg2/NagiosGen/base-group.cfg:: +``/var/lib/bcfg2/NagiosGen/base-group.cfg``:: define hostgroup{ hostgroup_name base @@ -104,7 +100,7 @@ add services, and commands specific to the hostgroup (Bcfg2 group) in hostgroup_name base } -* /var/lib/bcfg2/NagiosGen/web-server-group.cfg:: +``/var/lib/bcfg2/NagiosGen/web-server-group.cfg``:: define hostgroup{ hostgroup_name web-server diff --git a/src/lib/Bcfg2/Server/Plugins/NagiosGen.py b/src/lib/Bcfg2/Server/Plugins/NagiosGen.py index d132b0ff4..0c7b1daf7 100644 --- a/src/lib/Bcfg2/Server/Plugins/NagiosGen.py +++ b/src/lib/Bcfg2/Server/Plugins/NagiosGen.py @@ -17,7 +17,21 @@ line_fmt = '\t%-32s %s' class NagiosGenConfig(Bcfg2.Server.Plugin.SingleXMLFileBacked, Bcfg2.Server.Plugin.StructFile): def __init__(self, filename, fam): - Bcfg2.Server.Plugin.SingleXMLFileBacked.__init__(self, filename, fam) + # create config.xml if missing + if not os.path.exists(filename): + LOGGER.warning("NagiosGen: %s missing. " + "Creating empty one for you." % filename) + f = open(filename, "w") + f.write("") + f.close() + + try: + Bcfg2.Server.Plugin.SingleXMLFileBacked.__init__(self, + filename, + fam) + except OSError: + LOGGER.error("NagiosGen: Failed to read configuration file: %s" % err) + raise Bcfg2.Server.Plugin.PluginInitError(msg) Bcfg2.Server.Plugin.StructFile.__init__(self, filename) -- cgit v1.2.3-1-g7c22