Exemplo n.º 1
0
def DatabaseEnvParams(processId):
    # This is imported here to avoid circular references.
    from sources_types import CIM_Process

    DEBUG("\nDatabaseEnvParams processId=%s", str(processId))
    # Get the list of files open by the process.
    try:
        proc_obj = CIM_Process.PsutilGetProcObj(int(processId))
        fillist = CIM_Process.PsutilProcOpenFiles(proc_obj)
    except Exception:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("Caught:" + str(exc) + ": processId=" +
                                    str(processId))

    listArgs = []
    for filObj in fillist:
        filNam = filObj.path
        DEBUG("DatabaseEnvParams processId=%s filNam=%s", str(processId),
              filNam)
        if IsSqliteDatabase(filNam):
            DEBUG("DatabaseEnvParams ADDING filNam=%s", filNam)
            filNamClean = lib_util.standardized_file_path(filNam)
            filDef = {"File": filNamClean}
            listArgs.append(filDef)

    DEBUG("DatabaseEnvParams len=%d\n", len(listArgs))

    return ("sqlite/query", listArgs)
Exemplo n.º 2
0
def Main():
    paramkeyShowSharedLib = "Show shared libraries"
    paramkeyShowFontFiles = "Show font files"

    cgiEnv = lib_common.CgiEnv(parameters={
        paramkeyShowSharedLib: False,
        paramkeyShowFontFiles: False
    })
    top_pid = int(cgiEnv.GetId())

    flagShowSharedLib = bool(cgiEnv.get_parameters(paramkeyShowSharedLib))
    flagShowFontFiles = bool(cgiEnv.get_parameters(paramkeyShowFontFiles))

    grph = cgiEnv.GetGraph()

    proc_obj = CIM_Process.PsutilGetProcObj(top_pid)

    # sys.stderr.write("top_pid=%d\n" % top_pid)

    node_process = lib_common.gUriGen.PidUri(top_pid)
    CIM_Process.AddInfo(grph, node_process, [str(top_pid)])

    ################################################################################

    try:
        fillist = CIM_Process.PsutilProcOpenFiles(proc_obj)
    except Exception:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("Caught:" + str(exc) + ":" + str(proc_obj))

    for fil in fillist:
        # TODO: Resolve symbolic links. Do not do that if shared memory.
        # TODO: AVOIDS THESE TESTS FOR SHARED MEMORY !!!!
        if lib_common.is_meaningless_file(fil.path, not flagShowSharedLib,
                                          not flagShowFontFiles):
            continue

        fileNode = lib_common.gUriGen.FileUri(fil.path)
        grph.add((node_process, pc.property_open_file, fileNode))

    # This works but not really necessary because there are not so many files.
    # cgiEnv.OutCgiRdf( "", [pc.property_open_file] )
    cgiEnv.OutCgiRdf("LAYOUT_SPLINE")
Exemplo n.º 3
0
def Main():
    paramkeyShowSharedLib = "Show shared libraries"
    paramkeyShowFontFiles = "Show font files"
    paramkeyShowNonShared = "Show non shared files"

    # TODO: At the moment, only uses false default values for boolean parameters,
    # TODO: because CGI and the CGI lib do not send empty strings.
    cgiEnv = lib_common.CgiEnv(
        parameters={
            paramkeyShowSharedLib: False,
            paramkeyShowFontFiles: False,
            paramkeyShowNonShared: False
        })

    flagShowSharedLib = bool(cgiEnv.GetParameters(paramkeyShowSharedLib))
    flagShowFontFiles = bool(cgiEnv.GetParameters(paramkeyShowFontFiles))
    flagShowNonShared = bool(cgiEnv.GetParameters(paramkeyShowNonShared))

    grph = cgiEnv.GetGraph()

    ################################################################################

    Main.dictPathToNod = {}

    AddPidFileLink.dictFiles = {}

    # Maybe this is done in another CGI. What happens when merging ?
    grph.add((lib_common.nodeMachine, pc.property_hostname,
              lib_common.NodeLiteral(lib_util.currentHostname)))

    # https://code.google.com/p/psutil/issues/detail?id=340
    # This might hang.

    for proc in CIM_Process.ProcessIter():
        try:
            if lib_common.UselessProc(proc):
                continue

            pid = proc.pid

            node_process = None

            # http://code.google.com/p/psutil/issues/detail?id=340
            # https://github.com/giampaolo/psutil/issues/340
            for fil in CIM_Process.PsutilProcOpenFiles(proc):

                # Some files are not interesting even if accessed by many processes.
                if lib_common.MeaninglessFile(fil.path, not flagShowSharedLib,
                                              not flagShowFontFiles):
                    continue

                # Adds the process node only if it has at least one open file.
                if node_process == None:
                    node_process = lib_common.gUriGen.PidUri(pid)
                    grph.add((node_process, pc.property_pid,
                              lib_common.NodeLiteral(pid)))

                # TODO: What about files on a shared drive?
                if flagShowNonShared:
                    fileNode = PathToNod(fil.path)
                    grph.add((node_process, pc.property_open_file, fileNode))
                else:
                    # This takes into account only files accessed by several processes.
                    AddPidFileLink(grph, node_process, fil.path)

        # except psutil.AccessDenied:
        #	pass
        except:
            exc = sys.exc_info()[1]
            sys.stderr.write("Exception:%s\n" % str(exc))
            pass

    cgiEnv.OutCgiRdf("LAYOUT_SPLINE")