Ejemplo n.º 1
0
hostname = 'localhost'
convert = 1024 * 1024               # This will convert bytes to Megabytes
                                    #   in base 1024.
unit = 'M'                          # The unit notation (if any)
path = '/opt/sc4/repositories'      # Base path for repositories

# Here we will instantiate the Security Center module
sc = SecurityCenter(hostname, username, password)

# Before we do anything, lets print the header information.
print ' ' * 40 + 'IP Count\t Raw Size\t NSR Size'
print ' ' * 40 + '--------\t---------\t---------'

# First we will get the list of repositories that SC4 is aware of, then
# iterate through them.
for repo in sc.repositories()['repositories']:
    # First we get the filesize of the raw database in bytes.
    raw_size = os.path.getsize('%s/%s/hdb.raw' % (path, repo['id']))

    # Next is the filesize of the nsr file in bytes.  As it is possible for the
    # NSR file to not exist, if there is no file, we will just set it to 0 bytes
    try:
        nsr_size = os.path.getsize('%s/%s/hdb.nsr' % (path, repo['id']))
    except OSError:
        nsr_size = 0

    # Lastly, lets print this stuff out to stdout ;)
    print '%3d: %-30s\t%6d\t\t%8s%s\t%8s%s' % (
        int(repo['id']), repo['name'], int(repo['ipCount']),
        '%.2f' % float(float(raw_size) / convert), unit,
        '%.2f' % float(float(nsr_size) / convert), unit)
Ejemplo n.º 2
0
hostname = 'localhost'
convert = 1024 * 1024  # This will convert bytes to Megabytes
#   in base 1024.
unit = 'M'  # The unit notation (if any)
path = '/opt/sc4/repositories'  # Base path for repositories

# Here we will instantiate the Security Center module
sc = SecurityCenter(hostname, username, password)

# Before we do anything, lets print the header information.
print ' ' * 40 + 'IP Count\t Raw Size\t NSR Size'
print ' ' * 40 + '--------\t---------\t---------'

# First we will get the list of repositories that SC4 is aware of, then
# iterate through them.
for repo in sc.repositories()['repositories']:
    # First we get the filesize of the raw database in bytes.
    raw_size = os.path.getsize('%s/%s/hdb.raw' % (path, repo['id']))

    # Next is the filesize of the nsr file in bytes.  As it is possible for the
    # NSR file to not exist, if there is no file, we will just set it to 0 bytes
    try:
        nsr_size = os.path.getsize('%s/%s/hdb.nsr' % (path, repo['id']))
    except OSError:
        nsr_size = 0

    # Lastly, lets print this stuff out to stdout ;)
    print '%3d: %-30s\t%6d\t\t%8s%s\t%8s%s' % (
        int(repo['id']), repo['name'], int(
            repo['ipCount']), '%.2f' % float(float(raw_size) / convert), unit,
        '%.2f' % float(float(nsr_size) / convert), unit)