示例#1
0
    def __init__(self):
        self.dop = DictOp()
        self.dop.addconf(self._module,{})

        self.parser = Parser()
        self.parser.set_delim("[ \t]+")
        self.parser.set_new_delim("\t")
        self.parser.set_comment("#")
        self.base_parser_name = self.parser.__class__.__name__

        from karesansui.lib.parser.collectd import collectdParser
        collectdp = collectdParser()

        self.parser.set_opt_uni(collectdp.opt_uni)
        self.parser.set_opt_multi(collectdp.opt_multi)
        self.parser.set_opt_sect(collectdp.opt_sect)

        pass
示例#2
0
    def __init__(self):
        self.dop = DictOp()
        self.dop.addconf(self._module, {})

        self.parser = Parser()
        self.parser.set_delim("[ \t]+")
        self.parser.set_new_delim("\t")
        self.parser.set_comment("#")
        self.base_parser_name = self.parser.__class__.__name__

        from karesansui.lib.parser.collectd import collectdParser
        collectdp = collectdParser()

        self.parser.set_opt_uni(collectdp.opt_uni)
        self.parser.set_opt_multi(collectdp.opt_multi)
        self.parser.set_opt_sect(collectdp.opt_sect)

        pass
示例#3
0
    def __init__(self):
        self.dop = DictOp()
        self.dop.addconf(self._module,{})

        self.parser = Parser()
        self.parser.set_delim("[ \t]+")
        self.parser.set_new_delim("\t")
        self.parser.set_comment("#")
        self.base_parser_name = self.parser.__class__.__name__

        self.opt_uni   = ['Hostname',
                          'FQDNLookup',
                          'BaseDir',
                          'PIDFile',
                          'Target',
                          'Host',
                          'Key',
                          'LogLevel',
                          'Plugin',
                          'Subject',
                          'SMTPPort',
                          'SMTPServer',
                          'URL',
                          'Type',
                          'Chain']
        self.opt_multi = ['Include',
                          'LoadPlugin',
                          'Collect',
                          'DriverOption',
                          'GetCapacity',
                          'GetSnapshot',
                          'Irq',
                          'JVMArg',
                          'Listen',
                          'PreCacheChain',
                          'PostCacheChain',
                          'Query',
                          'Recipient',
                          'Sensor',
                          'Server',
                          'WatchAdd']
        self.opt_sect  = ['Plugin',
                          'LoadPlugin',
                          'Threshold',
                          'Type',
                          'Chain',
                          'Data',
                          'Database',
                          'Directory',
                          'Disks',
                          'File',
                          'Host',
                          'Key',
                          'Match',
                          'Metric',
                          'Module',
                          'Page',
                          'Query',
                          'Recursor',
                          'Result',
                          'Router',
                          'Rule',
                          'Server',
                          'System',
                          'Table',
                          'Target',
                          'URL',
                          'View',
                          'VolumePerf',
                          'VolumeUsage',
                          'WAFL']

        self.parser.set_opt_uni(self.opt_uni)
        self.parser.set_opt_multi(self.opt_multi)
        self.parser.set_opt_sect(self.opt_sect)

        pass
示例#4
0
class collectdParser:

    _module = "collectd"

    def __init__(self):
        self.dop = DictOp()
        self.dop.addconf(self._module,{})

        self.parser = Parser()
        self.parser.set_delim("[ \t]+")
        self.parser.set_new_delim("\t")
        self.parser.set_comment("#")
        self.base_parser_name = self.parser.__class__.__name__

        self.opt_uni   = ['Hostname',
                          'FQDNLookup',
                          'BaseDir',
                          'PIDFile',
                          'Target',
                          'Host',
                          'Key',
                          'LogLevel',
                          'Plugin',
                          'Subject',
                          'SMTPPort',
                          'SMTPServer',
                          'URL',
                          'Type',
                          'Chain']
        self.opt_multi = ['Include',
                          'LoadPlugin',
                          'Collect',
                          'DriverOption',
                          'GetCapacity',
                          'GetSnapshot',
                          'Irq',
                          'JVMArg',
                          'Listen',
                          'PreCacheChain',
                          'PostCacheChain',
                          'Query',
                          'Recipient',
                          'Sensor',
                          'Server',
                          'WatchAdd']
        self.opt_sect  = ['Plugin',
                          'LoadPlugin',
                          'Threshold',
                          'Type',
                          'Chain',
                          'Data',
                          'Database',
                          'Directory',
                          'Disks',
                          'File',
                          'Host',
                          'Key',
                          'Match',
                          'Metric',
                          'Module',
                          'Page',
                          'Query',
                          'Recursor',
                          'Result',
                          'Router',
                          'Rule',
                          'Server',
                          'System',
                          'Table',
                          'Target',
                          'URL',
                          'View',
                          'VolumePerf',
                          'VolumeUsage',
                          'WAFL']

        self.parser.set_opt_uni(self.opt_uni)
        self.parser.set_opt_multi(self.opt_multi)
        self.parser.set_opt_sect(self.opt_sect)

        pass

    def set_footer(self, footer=""):
        self.parser.set_footer(footer)

    def source_file(self):
        retval = [PARSER_COLLECTD_CONF]

        return retval

    def read_conf(self,extra_args=None):
        retval = {}

        self.parser.set_source_file([PARSER_COLLECTD_CONF])
        conf_arr = self.parser.read_conf()
        try:
            self.dop.addconf(self._module,conf_arr[PARSER_COLLECTD_CONF]['value'])
        except:
            pass

        self.dop.set(self._module,['@BASE_PARSER'],self.base_parser_name)
        #self.dop.preprint_r(self._module)
        return self.dop.getconf(self._module)

    def write_conf(self,conf_arr={},extra_args=None,dryrun=False):
        retval = True

        try:
            self.dop.addconf("parser",{})
            self.dop.set("parser",[PARSER_COLLECTD_CONF],conf_arr)
            #self.dop.preprint_r("parser")
            arr = self.dop.getconf("parser")
            self.parser.write_conf(arr,dryrun=dryrun)
        except:
            pass

        return retval
示例#5
0
class collectdpluginParser:

    _module = "collectdplugin"

    def __init__(self):
        self.dop = DictOp()
        self.dop.addconf(self._module,{})

        self.parser = Parser()
        self.parser.set_delim("[ \t]+")
        self.parser.set_new_delim("\t")
        self.parser.set_comment("#")
        self.base_parser_name = self.parser.__class__.__name__

        from karesansui.lib.parser.collectd import collectdParser
        collectdp = collectdParser()

        self.parser.set_opt_uni(collectdp.opt_uni)
        self.parser.set_opt_multi(collectdp.opt_multi)
        self.parser.set_opt_sect(collectdp.opt_sect)

        pass

    def set_footer(self, footer=""):
        self.parser.set_footer(footer)

    def source_file(self):
        retval = []

        glob_str = "%s/*.conf" % (PARSER_COLLECTD_PLUGIN_DIR,)
        for _afile in glob.glob(glob_str):
            retval.append(_afile)

        return retval

    def read_conf(self,extra_args=None):
        retval = {}

        for _afile in self.source_file():

            plugin_name = re.sub("\.conf$","",os.path.basename(_afile))

            try:
                extra_args['include']
                if not re.search(extra_args['include'],plugin_name):
                    continue
            except:
                pass

            self.parser.set_source_file([_afile])
            conf_arr = self.parser.read_conf()
            try:
                self.dop.set(self._module,[plugin_name],conf_arr[_afile]['value'])
            except:
                pass

        self.dop.set(self._module,['@BASE_PARSER'],self.base_parser_name)
        #self.dop.preprint_r(self._module)
        return self.dop.getconf(self._module)

    def _pre_write_conf(self,conf_arr={}):

        # Change permission to be able to read/write data kss group.
        if os.path.exists(COLLECTD_DATA_DIR):
            if os.getuid() == 0:
                r_chgrp(COLLECTD_DATA_DIR,KARESANSUI_GROUP)
                r_chmod(COLLECTD_DATA_DIR,"g+rwx")
                r_chmod(COLLECTD_DATA_DIR,"o-rwx")

        dop = DictOp()
        dop.addconf("__",conf_arr)

        if dop.isset("__",["python"]) is True:
            dop.cdp_unset("__",["python","Plugin","python","@ORDERS"],multiple_file=True)
            orders = []
            orders.append(['Encoding'])
            orders.append(['LogTraces'])
            orders.append(['Interactive'])
            orders.append(['ModulePath'])
            orders.append(['Import'])
            orders.append(['Module'])
            dop.cdp_set("__",["python","Plugin","python","@ORDERS"],orders,is_opt_multi=True,multiple_file=True)

        return dop.getconf("__")

    def write_conf(self,conf_arr={},extra_args=None,dryrun=False):
        retval = True

        conf_arr = self._pre_write_conf(conf_arr)

        for plugin_name,_v in conf_arr.iteritems():

            _afile = "%s/%s.conf" % (PARSER_COLLECTD_PLUGIN_DIR,plugin_name,)
            try:
                _v['action']
                if _v['action'] == "delete":
                    if os.path.exists(_afile):
                        os.unlink(_afile)
                        continue
            except:
                pass
                #continue

            try:
                _v['value']

                self.dop.addconf("parser",{})
                self.dop.set("parser",[_afile],_v['value'])
                #self.dop.preprint_r("parser")
                arr = self.dop.getconf("parser")
                self.parser.write_conf(arr,dryrun=dryrun)
            except:
                pass

        return retval
示例#6
0
class collectdpluginParser:

    _module = "collectdplugin"

    def __init__(self):
        self.dop = DictOp()
        self.dop.addconf(self._module, {})

        self.parser = Parser()
        self.parser.set_delim("[ \t]+")
        self.parser.set_new_delim("\t")
        self.parser.set_comment("#")
        self.base_parser_name = self.parser.__class__.__name__

        from karesansui.lib.parser.collectd import collectdParser
        collectdp = collectdParser()

        self.parser.set_opt_uni(collectdp.opt_uni)
        self.parser.set_opt_multi(collectdp.opt_multi)
        self.parser.set_opt_sect(collectdp.opt_sect)

        pass

    def set_footer(self, footer=""):
        self.parser.set_footer(footer)

    def source_file(self):
        retval = []

        glob_str = "%s/*.conf" % (PARSER_COLLECTD_PLUGIN_DIR, )
        for _afile in glob.glob(glob_str):
            retval.append(_afile)

        return retval

    def read_conf(self, extra_args=None):
        retval = {}

        for _afile in self.source_file():

            plugin_name = re.sub("\.conf$", "", os.path.basename(_afile))

            try:
                extra_args['include']
                if not re.search(extra_args['include'], plugin_name):
                    continue
            except:
                pass

            self.parser.set_source_file([_afile])
            conf_arr = self.parser.read_conf()
            try:
                self.dop.set(self._module, [plugin_name],
                             conf_arr[_afile]['value'])
            except:
                pass

        self.dop.set(self._module, ['@BASE_PARSER'], self.base_parser_name)
        #self.dop.preprint_r(self._module)
        return self.dop.getconf(self._module)

    def _pre_write_conf(self, conf_arr={}):

        # Change permission to be able to read/write data kss group.
        if os.path.exists(COLLECTD_DATA_DIR):
            if os.getuid() == 0:
                r_chgrp(COLLECTD_DATA_DIR, KARESANSUI_GROUP)
                r_chmod(COLLECTD_DATA_DIR, "g+rwx")
                r_chmod(COLLECTD_DATA_DIR, "o-rwx")

        dop = DictOp()
        dop.addconf("__", conf_arr)

        if dop.isset("__", ["python"]) is True:
            dop.cdp_unset("__", ["python", "Plugin", "python", "@ORDERS"],
                          multiple_file=True)
            orders = []
            orders.append(['Encoding'])
            orders.append(['LogTraces'])
            orders.append(['Interactive'])
            orders.append(['ModulePath'])
            orders.append(['Import'])
            orders.append(['Module'])
            dop.cdp_set("__", ["python", "Plugin", "python", "@ORDERS"],
                        orders,
                        is_opt_multi=True,
                        multiple_file=True)

        return dop.getconf("__")

    def write_conf(self, conf_arr={}, extra_args=None, dryrun=False):
        retval = True

        conf_arr = self._pre_write_conf(conf_arr)

        for plugin_name, _v in conf_arr.iteritems():

            _afile = "%s/%s.conf" % (
                PARSER_COLLECTD_PLUGIN_DIR,
                plugin_name,
            )
            try:
                _v['action']
                if _v['action'] == "delete":
                    if os.path.exists(_afile):
                        os.unlink(_afile)
                        continue
            except:
                pass
                #continue

            try:
                _v['value']

                self.dop.addconf("parser", {})
                self.dop.set("parser", [_afile], _v['value'])
                #self.dop.preprint_r("parser")
                arr = self.dop.getconf("parser")
                self.parser.write_conf(arr, dryrun=dryrun)
            except:
                pass

        return retval