Exemple #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
Exemple #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
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(1)

        uniq_id = time.strftime("%Y%m%d%H%M%S", time.localtime())

        if opts.pre_command is not None:
            if opts.pre_command[0:4] == "b64:":
                command = base64_decode(opts.pre_command[4:])
            else:
                command = opts.pre_command
            self.logger.info("execute command - %s" % command)

            if opts.dry_run is True:
                print ""
                print ">>>Execute pre command: %s" % command
                print ""
            else:
                (_ret,_res) = execute_command(command.split())
                if _ret != 0:
                    error_msg = "execute error - %s" % command
                    self.logger.error(error_msg)
                    #raise KssCommandOptException("ERROR: %s" % error_msg)

        self.up_progress(5)

        from karesansui.lib.parser.collectd       import collectdParser
        from karesansui.lib.parser.collectdplugin import collectdpluginParser
        dop = DictOp()

        collectd_parser       = collectdParser()
        dop.addconf("collectd",collectd_parser.read_conf())

        collectdplugin_parser = collectdpluginParser()
        extra_args = {"include":"^(%s)$" % "|".join(COLLECTD_PLUGINS)}
        dop.addconf("collectdplugin",collectdplugin_parser.read_conf(extra_args=extra_args))

        initialize_collectd_settings(dop=dop,force=opts.force,reverse=opts.reverse)

        retval = collectd_parser.write_conf(dop.getconf("collectd"),dryrun=opts.dry_run)
        retval = collectdplugin_parser.write_conf(dop.getconf("collectdplugin"),extra_args=extra_args,dryrun=opts.dry_run)

        self.up_progress(30)

        if opts.post_command is not None:
            if opts.post_command[0:4] == "b64:":
                command = base64_decode(opts.post_command[4:])
            else:
                command = opts.post_command
            self.logger.info("execute command - %s" % command)

            if opts.dry_run is True:
                print ""
                print ">>>Execute post command: %s" % command
                print ""
            else:
                (_ret,_res) = execute_command(command.split())
                if _ret != 0:
                    error_msg = "execute error - %s" % command
                    self.logger.error(error_msg)
                    raise KssCommandOptException("ERROR: %s" % error_msg)

        self.up_progress(10)
        return True
Exemple #4
0
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(1)

        uniq_id = time.strftime("%Y%m%d%H%M%S", time.localtime())

        if opts.pre_command is not None:
            if opts.pre_command[0:4] == "b64:":
                command = base64_decode(opts.pre_command[4:])
            else:
                command = opts.pre_command
            self.logger.info("execute command - %s" % command)

            if opts.dry_run is True:
                print ""
                print ">>>Execute pre command: %s" % command
                print ""
            else:
                (_ret,_res) = execute_command(command.split())
                if _ret != 0:
                    error_msg = "execute error - %s" % command
                    self.logger.error(error_msg)
                    #raise KssCommandOptException("ERROR: %s" % error_msg)

        self.up_progress(5)

        from karesansui.lib.parser.collectd       import collectdParser
        from karesansui.lib.parser.collectdplugin import collectdpluginParser
        dop = DictOp()

        collectd_parser       = collectdParser()
        dop.addconf("collectd",collectd_parser.read_conf())

        collectdplugin_parser = collectdpluginParser()
        extra_args = {"include":"^(%s)$" % "|".join(COLLECTD_PLUGINS)}
        dop.addconf("collectdplugin",collectdplugin_parser.read_conf(extra_args=extra_args))

        initialize_collectd_settings(dop=dop,force=opts.force,reverse=opts.reverse)

        retval = collectd_parser.write_conf(dop.getconf("collectd"),dryrun=opts.dry_run)
        retval = collectdplugin_parser.write_conf(dop.getconf("collectdplugin"),extra_args=extra_args,dryrun=opts.dry_run)

        self.up_progress(30)

        if opts.post_command is not None:
            if opts.post_command[0:4] == "b64:":
                command = base64_decode(opts.post_command[4:])
            else:
                command = opts.post_command
            self.logger.info("execute command - %s" % command)

            if opts.dry_run is True:
                print ""
                print ">>>Execute post command: %s" % command
                print ""
            else:
                (_ret,_res) = execute_command(command.split())
                if _ret != 0:
                    error_msg = "execute error - %s" % command
                    self.logger.error(error_msg)
                    raise KssCommandOptException("ERROR: %s" % error_msg)

        self.up_progress(10)
        return True