예제 #1
0
def linux_lsblk(archive):
    out, err, rc = execute('lsblk -V')
    version = out.split()[-1]
    if version.startswith('2.1'):
        cmd = 'lsblk -PbnDo name,maj:min,kname,type,label,size,fstype,sched'
    else:
        cmd = 'lsblk -PbnDo name,maj:min,kname,type,label,size,fstype,sched,wwn,hctl,pkname'
    zipexec(archive, cmd)
예제 #2
0
def aix_info(archive, args):
    """System/SAR info for AIX (pSeries)"""
    logging.info('Collecting AIX System info')
    for cmd in aix_cmds:
        zipexec(archive, cmd)
    disks, err, rc = execute('lsdev -Cc disk -Fname')
    nics, err, rc = execute('ifconfig -l')
    vgs, err, rc =  execute('lsvg')
    logging.info('Collecting AIX Disk info')
    for disk in disks.splitlines():
        prefix = 'disk/{0}'.format(disk)
        zipexec(archive, 'getconf DISK_SIZE /dev/{0}'.format(disk), prefix=prefix, tag='disksize')
        zipexec(archive, 'lscfg -vpl %s' % disk, prefix=prefix, tag='lscfg')
        zipexec(archive, 'lspath -l %s -F parent,status' % disk, prefix=prefix, tag='lspath')
        zipexec(archive, 'lsattr -El %s' % disk, prefix=prefix, tag='lsattr')
    logging.info('Collecting AIX Network info')
    for nic in nics.split():
        if nic.startswith('lo'): continue
        prefix = 'nic/{0}'.format(nic)
        zipexec(archive, 'lsattr -E -l %s -F description,value' % nic, prefix=prefix, tag='lsattr')
        zipexec(archive, 'entstat -d %s' % nic, prefix=prefix, tag='entstat')
    logging.info('Collecting AIX LVM info')
    for vg in vgs.splitlines():
        prefix = 'lvm/{0}'.format(vg)
        zipexec(archive, 'lsvg -l %s' % vg, prefix=prefix, tag='lvs')
        zipexec(archive, 'lsvg -p %s' % vg, prefix=prefix, tag='pvs')
    if not args.no_sar:
        logging.info('Collecting UNIX SAR reports')
        for sarfile in listdir('/var/adm/sa'):
            path = os.path.join('/var/adm/sa', sarfile)
            if sarfile.startswith('sa'):
                if sarfile.startswith('sar'):
                    continue
                prefix = 'sar/{0}'.format(sarfile)
                zipexec(archive, 'sar -uf %s' % path, prefix=prefix, tag='cpu')
                zipexec(archive, 'sar -bf %s' % path, prefix=prefix, tag='block')
                zipexec(archive, 'sar -df %s' % path, prefix=prefix, tag='disk')
                zipexec(archive, 'sar -rf %s' % path, prefix=prefix, tag='swap')
예제 #3
0
def get_instances():
    """Get all detected instances by searching ORACLE_HOME/dbs for files named hc_<sid>.dat
    If more hc_*.dat files are detected, the one with the latest mtime will be used.
    Check if the instance is running by looking for ora_pmon_<sid> processes.
    """
    runlist = dict()
    downlist = dict()
    info = dict()
    detected = []
    # Build list of running instances
    out, err, rc = execute('ps -eo user,group,args')
    for user, group, cmd in re.findall(r'(\w+)\s+(\w+)\s+(.*)', out):
        r = re.match(r'ora_pmon_(\w+)', cmd)
        if r:
            sid = r.group(1)
            runlist[sid] = dict(user=user, group=group)
    # Build list of detected instances from hc_*.dat
    for home in orahomes():
        logging.debug('ORACLE_HOME detected: %s', home)
        dir = os.path.join(home, 'dbs')
        try:
            for f in os.listdir(dir):
                r = re.match('hc_(.*).dat', f)
                if r:
                    sid = r.group(1)
                    if sid[0] in ('+', '-'):
                        continue
                    stat = os.stat(os.path.join(dir, f))
                    mtime = datetime(1970, 1,
                                     1) + timedelta(seconds=int(stat.st_mtime))
                    detected.append((mtime, sid, home))
        except OSError as e:
            # Happens if for example we can't read the dbs dir. Just ignore.
            logging.debug('{0}: {1}'.format(dir, os.strerror(e.errno)))
    # Sort by date, most recent first
    detected.sort(key=lambda x: x[0], reverse=True)
    # build lists of running and stopped instances
    for mtime, sid, orahome in detected:
        running = sid in runlist
        if not running:
            downlist[sid] = None
        user = runlist[sid]['user'] if running else None
        ts = mtime.strftime("%Y-%m-%d %H:%M")
        logging.info('Instance detected: %s, %s, %s', sid, ts, orahome)
        if running and sid not in info:
            if not sid[0] in ('+', '-'):
                info[sid] = dict(orahome=orahome, user=user)
    logging.info('Stopped instances: %s', ', '.join(downlist.keys()))
    logging.info('Running instances: %s', ', '.join(info.keys()))
    return info
예제 #4
0
def linux_info(archive, args):
    """System/SAR info for Linux"""
    for cmd in linux_cmds:
        zipexec(archive, cmd)
    linux_lsblk(archive)
    for file in linux_files:
        zipfile(archive, file)
    for f in listdir('/etc/udev/rules.d/'):
        path = os.path.join('/etc/udev/rules.d/', f)
        if os.path.isfile(path) and f.endswith('.rules'):
            zipfile(archive, path)
    # TODO:
    # numa?
    # powerpath / scaleio? -> Need root?

    out, err, rc = execute('lsblk -dno name')
    for dev in out.rstrip().splitlines():
        for var in  ['model','rev','dev','queue_depth','vendor','serial']:
            path = os.path.join('/sys/class/block/{0}/device/{1}'.format(dev, var))
            if os.path.isfile(path):
                zipfile(archive, path)
        zipexec(archive, 'udevadm info -q symlink -n {0}'.format(dev), prefix='disks', tag='{0}-links'.format(dev))

    for dev in listdir('/sys/class/net'):
        if dev == 'lo':
            continue
        dir = os.path.join('/sys/class/net', dev)
        if not os.path.isdir(dir):
            continue
        for var in ['mtu', 'speed', 'address']:
            path = os.path.join(dir, var)
            if os.path.isfile(path):
                zipfile(archive, path)
    if not args.no_sar:
        logging.info('Collecting Linux SAR files')
        for sarfile in listdir('/var/log/sa'):
            path = os.path.join('/var/log/sa', sarfile)
            if sarfile.startswith('sa'):
                if sarfile.startswith('sar'):
                    continue
                if sarfile.endswith('.xz'):
                    continue
                archive.store(path)
예제 #5
0
 def execute(self, cmd):
     """Execute a command and return the output with the header.
     Also record status and errors"""
     self.info['mediatype'] = 'command'
     self.info['format'] = 'text'
     self.info['command'] = cmd
     out, err = None, None
     try:
         out, err, rc = execute(cmd)
         self.info['status'] = 'OK'
         self.info['returncode'] = rc
     except OSError as e:
         self.info['status'] = os.strerror(e.errno)
         self.info['returncode'] = None
         raise
     finally:
         self.header(err)
         if out:
             self.write(out)
         self.buf.seek(0)
         return self.buf.read()