예제 #1
0
def parse_perf_objects(filer, svr_name, output, name_reg, step,
                       StorageClass, filter_invalid=True):
    pat = reco('^"(\d+/\d+/\d+\s+\d+:\d+:\d+)')
    head_line = None
    value_line = None
    timestamp = None
    perfs = []

    for lin in output.split("\n"):
        if lin.startswith('"Timestamp",'):
            head_line = lin
        elif head_line:
            m = pat.search(lin)
            if m:
                value_line = lin.strip()
                timestamp = m.group(1)
                break

    if not head_line or not value_line:
        _logger.debug("Ignore data from %s for %s: %s"
                % (filer.ip, StorageClass.__name__, output))
        return perfs

    heads = head_line.split('","')
    values = value_line.split('","')
    name_pat = reco(name_reg)
    fields_cnt = len(heads)
    assert fields_cnt % step == 1
    if fields_cnt == len(values) and fields_cnt > step:
        for i, j in izip(range(1, fields_cnt, step),
                         range(step + 1, fields_cnt + step, step)):
            m = name_pat.search(heads[i])
            if not m:
                _logger.warn("Didn't find a name, %s: %s"
                             % (heads[i], name_reg))
                continue
            perf = StorageClass(filer, svr_name, timestamp,
                                m.group(1), values[i:j])
            if filter_invalid:
                if perf.is_valid():
                    perfs.append(perf)
                else:
                    _logger.debug("Ignore data from %s for %s: %s"
                            % (filer.ip, StorageClass.__name__, values[i:j]))
            else:
                perfs.append(perf)
    else:
        _logger.debug("Ignore data from %s for %s: %s"
                % (self.ip, StorageClass.__name__, output))
    return perfs
예제 #2
0
def parse_cfg(cf, data):
    cfg = configparser.ConfigParser()
    cfg.read(cf)
    vpn = {
        "name" : cfg["general"]["name"],
        "locales" : {}
    }
    cap = reco(cfg["capture"]["regex"])
    af = [x for x in cf.parent.rglob("*") if x.is_file()]
    for f in af:
        m = cap.search(f.name)
        if m != None:
            ml = m.group( cfg["capture"].getint("location") )
            mp = m.group( cfg["capture"].getint("protocol") )
            if not ml in vpn["locales"].keys():
                vpn["locales"][ml] = {
                    "name" : cfg["locales"][ml],
                    "files" : []
                }
            vf = {
                "path" : str(f),
                "protocol" : mp,
            }
            vpn["locales"][ml]["files"].append(vf)
    data.append(vpn)
예제 #3
0
    def _do_collect(self, ip, batch_cmd, handlers, timeout=60):
        res = {}
        start_pat = reco(r'<<(\w+)>>')
        end_pat = reco(r'<</(\w+)>>')
        cmd = [self.SSH, "%s@%s" % (self._username, ip), batch_cmd]
        output = timed_popen(cmd, timeout)
        if output.count(None) == 2:
            self._timed_out_count += 1
            _logger.error(self._log_template % (ip, batch_cmd, "timed_out"))
            return res

        self._timed_out_count = 0
        current_cmd = None
        cmd_output = []
        for lin in output[0].split("\n"):
            lin = lin.rstrip()
            m = end_pat.search(lin)
            if m:
                if current_cmd and cmd_output:
                    if current_cmd in handlers:
                        (objname, objs) = handlers[current_cmd](cmd_output)
                        res.setdefault(objname, []).extend(objs)
                    else:
                        _logger.warn("I don't understand this cmd: %s"
                                     % current_cmd)
                del cmd_output[:]
                current_cmd = None
                continue

            m = start_pat.search(lin)
            if m:
                current_cmd = m.group(1)
                continue

            if current_cmd:
                cmd_output.append(lin)
        self._dump(batch_cmd, output[0])
        return res
예제 #4
0
def _parse(storage_object, names, output):
        output = output.split("\n")
        pat = reco('^"\d+/\d+/\d+\s+\d+:\d+:\d+')
        for lin in output:
            if pat.search(lin):
                break
        else:
            return

        values = lin.split(",")
        for name, value in izip(names, values):
            if value == '""':
                value = "0"
            setattr(storage_object, name, value.strip('"'))
예제 #5
0
    def _do_parse(self, output, rex):
        for name in rex:
            rex[name] = reco(rex[name])

        for lin in output:
            for name, value in self.__dict__.iteritems():
                if value is None:
                    m = rex[name].search(lin)
                    if m:
                        setattr(self, name, "_".join(m.groups()).strip())
                        break
                elif isinstance(value, list):
                    m = rex[name].search(lin)
                    if m:
                        val = "_".join(m.groups()).strip()
                        getattr(self, name).append(val)
                        break
예제 #6
0
def parse_block_objects(agent, output, start_tag, StorageClass,
                        filter_invalid=True):
    container = []
    section_info = []
    start_collect = False
    pat = reco(start_tag)

    for lin in output.split("\n"):
        m = pat.search(lin)
        if m:
            if section_info:
                c = StorageClass(agent, section_info)
                if filter_invalid:
                    if c.is_valid():
                        container.append(c)
                    else:
                        _logger.debug("%s Ignore: %s"
                            % (StorageClass.__name__, "\n".join(section_info)))
                else:
                    container.append(c)
                del section_info[:]
            start_collect = True
            section_info.append(lin)
        elif start_collect:
            section_info.append(lin)

    if section_info:
        c = StorageClass(agent, section_info)
        if filter_invalid:
            if c.is_valid():
                container.append(c)
            else:
                _logger.debug("%s Ignore: %s"
                        % (StorageClass.__name__, "\n".join(section_info)))
        else:
            container.append(c)
    return container