Exemplo n.º 1
0
def status(conf):
    """
    Show anchore system status.
    """

    ecode = 0
    try:
        if conf:
            if config.cliargs['json']:
                anchore_print(config.data, do_formatting=True)
            else:
                anchore_print(
                    yaml.safe_dump(config.data,
                                   indent=True,
                                   default_flow_style=False))
        else:
            result = {}
            if contexts['anchore_db'].check():
                result["anchore_db"] = "OK"
            else:
                result["anchore_db"] = "NOTINITIALIZED"

            if anchore_feeds.check():
                result["anchore_feeds"] = "OK"
            else:
                result["anchore_feeds"] = "NOTSYNCED"

            afailed = False
            latest = 0
            for imageId in list(
                    contexts['anchore_db'].load_all_images().keys()):
                amanifest = anchore_utils.load_analyzer_manifest(imageId)
                for module_name in list(amanifest.keys()):
                    try:
                        if amanifest[module_name]['timestamp'] > latest:
                            latest = amanifest[module_name]['timestamp']
                        if amanifest[module_name]['status'] != 'SUCCESS':
                            analyzer_failed_imageId = imageId
                            analyzer_failed_name = module_name
                            afailed = True
                    except:
                        pass

            if latest == 0:
                result["analyzer_status"] = "NODATA"
            elif afailed:
                result[
                    "analyzer_status"] = "FAIL (" + analyzer_failed_imageId + ")"
                result["analyzer_latest_run"] = time.ctime(latest)
            else:
                result["analyzer_status"] = "OK"
                result["analyzer_latest_run"] = time.ctime(latest)

            anchore_print(result, do_formatting=True)

    except Exception as err:
        anchore_print_err('operation failed')
        ecode = 1

    sys.exit(ecode)
Exemplo n.º 2
0
def feeds(anchore_config):
    global config
    config = anchore_config

    ecode = 0
    emsg = ""
    success = True

    try:
        rc, msg = anchore_feeds.check()
        if not rc:
            anchore_print("initializing feed metadata: ...")
            rc, ret = anchore_feeds.sync_feedmeta()
            if not rc:
                emsg = "could not sync feed metadata from service: " + ret[
                    'text']
                success = False

    except Exception as err:
        anchore_print_err('operation failed')
        sys.exit(1)

    if not success:
        anchore_print_err(emsg)
        sys.exit(1)
Exemplo n.º 3
0
def status(conf):
    """
    Show anchore system status.
    """

    ecode = 0
    try:
        if conf:
            if config.cliargs['json']:
                anchore_print(config.data, do_formatting=True)
            else:
                anchore_print(yaml.safe_dump(config.data, indent=True, default_flow_style=False))
        else:
            result = {}
            if contexts['anchore_db'].check():
                result["anchore_db"] = "OK"
            else:
                result["anchore_db"] = "NOTINITIALIZED"

            if anchore_feeds.check():
                result["anchore_feeds"] = "OK"
            else:
                result["anchore_feeds"] = "NOTSYNCED"

            afailed = False
            latest = 0
            for imageId in contexts['anchore_db'].load_all_images().keys():
                amanifest = anchore_utils.load_analyzer_manifest(imageId)
                for module_name in amanifest.keys():
                    try:
                        if amanifest[module_name]['timestamp'] > latest:
                            latest = amanifest[module_name]['timestamp']
                        if amanifest[module_name]['status'] != 'SUCCESS':
                            analyzer_failed_imageId = imageId
                            analyzer_failed_name = module_name
                            afailed = True
                    except:
                        pass

            if latest == 0:
                result["analyzer_status"] = "NODATA"
            elif afailed:
                result["analyzer_status"] = "FAIL ("+analyzer_failed_imageId+")"
                result["analyzer_latest_run"] = time.ctime(latest)
            else:
                result["analyzer_status"] = "OK"
                result["analyzer_latest_run"] = time.ctime(latest)
   
            anchore_print(result, do_formatting=True)

    except Exception as err:
        anchore_print_err('operation failed')
        ecode = 1

    sys.exit(ecode)
Exemplo n.º 4
0
def feeds(anchore_config):
    global config
    config = anchore_config

    ecode = 0
    emsg = ""
    success = True

    try:
        rc, msg = anchore_feeds.check()
        if not rc:
            anchore_print("initializing feed metadata: ...")
            rc, ret = anchore_feeds.sync_feedmeta()
            if not rc:
                emsg = "could not sync feed metadata from service: " + ret['text']
                success = False

    except Exception as err:
        anchore_print_err('operation failed')
        sys.exit(1)

    if not success:
        anchore_print_err(emsg)
        sys.exit(1)