def __init__(self, filename, should_monitor=False): StructFile.__init__(self, filename, should_monitor=should_monitor) if self.name.endswith(".genshi"): self.logger.warning("Bundler: %s: Bundle filenames ending with " ".genshi are deprecated; add the Genshi XML " "namespace to a .xml bundle instead" % self.name)
def __init__(self, fname): CfgCreator.__init__(self, fname) StructFile.__init__(self, fname) pubkey_path = os.path.dirname(self.name) + ".pub" pubkey_name = os.path.join(pubkey_path, os.path.basename(pubkey_path)) self.pubkey_creator = CfgPublicKeyCreator(pubkey_name)
def __init__(self, core): Plugin.__init__(self, core) Generator.__init__(self) self.config = \ StructFile(os.path.join(self.data, 'config.xml'), should_monitor=True, create=self.name) self.Entries = { 'Path': { '/etc/nagiosgen.status': self.createhostconfig, '/etc/nagios/conf.d/bcfg2.cfg': self.createserverconfig } } self.client_attrib = { 'encoding': 'ascii', 'owner': 'root', 'group': 'root', 'type': 'file', 'mode': '0400' } self.server_attrib = { 'encoding': 'ascii', 'owner': 'nagios', 'group': 'nagios', 'type': 'file', 'mode': '0440' }
def __init__(self, fname): CfgCreator.__init__(self, fname) StructFile.__init__(self, fname) pubkey_path = os.path.dirname(self.name) + ".pub" pubkey_name = os.path.join(pubkey_path, os.path.basename(pubkey_path)) self.pubkey_creator = CfgPublicKeyCreator(pubkey_name) self.setup = get_option_parser() self.cmd = Executor()
class NagiosGen(Plugin, Generator): """ NagiosGen is a Bcfg2 plugin that dynamically generates Nagios configuration file based on Bcfg2 data. """ __author__ = '*****@*****.**' line_fmt = '\t%-32s %s' def __init__(self, core): Plugin.__init__(self, core) Generator.__init__(self) self.config = \ StructFile(os.path.join(self.data, 'config.xml'), should_monitor=True, create=self.name) self.Entries = { 'Path': {'/etc/nagiosgen.status': self.createhostconfig, '/etc/nagios/conf.d/bcfg2.cfg': self.createserverconfig}} self.client_attrib = {'encoding': 'ascii', 'owner': 'root', 'group': 'root', 'type': 'file', 'mode': '0400'} self.server_attrib = {'encoding': 'ascii', 'owner': 'nagios', 'group': 'nagios', 'type': 'file', 'mode': '0440'} def createhostconfig(self, entry, metadata): """Build host specific configuration file.""" try: host_address = socket.getaddrinfo(metadata.hostname, None)[0][4][0] except socket.error: self.logger.error() raise PluginExecutionError("Failed to find IP address for %s" % metadata.hostname) host_groups = [grp for grp in metadata.groups if os.path.isfile('%s/%s-group.cfg' % (self.data, grp))] host_config = ['define host {', self.line_fmt % ('host_name', metadata.hostname), self.line_fmt % ('alias', metadata.hostname), self.line_fmt % ('address', host_address)] if host_groups: host_config.append(self.line_fmt % ("hostgroups", ",".join(sorted(host_groups)))) # read the config xtra = dict() for el in self.config.Match(metadata): if el.tag == 'Option': xtra[el.get("name")] = el.text if xtra: host_config.extend([self.line_fmt % (opt, val) for opt, val in list(xtra.items())]) if 'use' not in xtra: host_config.append(self.line_fmt % ('use', 'default')) host_config.append('}') entry.text = "%s\n" % "\n".join(host_config) for (key, value) in list(self.client_attrib.items()): entry.attrib.__setitem__(key, value) fname = os.path.join(self.data, metadata.hostname + "-host.cfg") try: open(fname, 'w').write(entry.text) except OSError: err = sys.exc_info()[1] self.logger.error("Failed to write %s: %s" % (fname, err)) def createserverconfig(self, entry, _): """Build monolithic server configuration file.""" host_configs = glob.glob(os.path.join(self.data, '*-host.cfg')) group_configs = glob.glob(os.path.join(self.data, '*-group.cfg')) host_data = [] group_data = [] for host in host_configs: host_data.append(open(host, 'r').read()) group_list = [] for line in "\n".join(host_data).splitlines(): # only include those groups which are actually used if "hostgroup" in line: group_list += line.split()[1].split(',') group_list = list(set(group_list)) for group in group_configs: group_name = re.sub("(-group.cfg|.*/(?=[^/]+))", "", group) if group_name in group_list: groupfile = open(group, 'r') group_data.append(groupfile.read()) groupfile.close() entry.text = "%s\n\n%s" % ("\n".join(group_data), "\n".join(host_data)) for (key, value) in list(self.server_attrib.items()): entry.attrib.__setitem__(key, value) fname = os.path.join(self.data, "nagiosgen.cfg") try: open(fname, 'w').write(entry.text) except OSError: err = sys.exc_info()[1] self.logger.error("Failed to write %s: %s" % (fname, err))
def handle_event(self, event): CfgCreator.handle_event(self, event) StructFile.HandleEvent(self, event)
def __init__(self, fname): CfgCreator.__init__(self, fname) StructFile.__init__(self, fname) self.cfg = CFG
def handle_event(self, event): CfgGenerator.handle_event(self, event) StructFile.HandleEvent(self, event) self.cache = dict()
def __init__(self, fname): CfgGenerator.__init__(self, fname, None) StructFile.__init__(self, fname) self.cache = dict() self.core = get_cfg().core
def __init__(self, fname): CfgCreator.__init__(self, fname) StructFile.__init__(self, fname) self.cfg = get_cfg() self.core = self.cfg.core self.cmd = Executor()
def Index(self): StructFile.Index(self) if self.xdata.get("name"): self.logger.warning("Bundler: %s: Explicitly specifying bundle " "names is deprecated" % self.name)
def __init__(self, fname): CfgGenerator.__init__(self, fname, None, None) StructFile.__init__(self, fname) self.cache = dict() self.core = CFG.core