コード例 #1
0
def AddWmiServers(entity_host, nameSpace, entity_type, entity_id):
    DEBUG(
        "AddWmiServers entity_host=%s nameSpace=%s entity_type=%s entity_id=%s",
        entity_host, nameSpace, entity_type, entity_id)

    # This will not work on Linux.
    import lib_wmi

    mapWmi = dict()
    if lib_wmi.ValidClassWmi(entity_type):
        # TODO: We may also loop on all machines which may describe this object.
        wmiurl = lib_wmi.GetWmiUrl(entity_host, nameSpace, entity_type,
                                   entity_id)
        # sys.stderr.write("wmiurl=%s\n" % str(wmiurl))
        if wmiurl:
            wmiNode = lib_common.NodeUrl(wmiurl)
            if entity_host:
                txtLiteral = "WMI url, host=%s class=%s" % (entity_host,
                                                            entity_type)
            else:
                txtLiteral = "WMI url, current host, class=%s" % (entity_type)

            mapWmi[wmiNode] = [(pc.property_information,
                                lib_common.NodeLiteral(txtLiteral))]

            if entity_host:
                nodePortalWmi = lib_util.UrlPortalWmi(entity_host)

                mapWmi[wmiNode].append(
                    (pc.property_rdf_data_nolist2, nodePortalWmi))
    return mapWmi
コード例 #2
0
def AddWmiServers(entity_host, name_space, entity_type, entity_id):
    """This adds a couple of URL """
    map_wmi = dict()

    # No WMI implementation is available on Linux.
    if lib_util.isPlatformLinux:
        return map_wmi

    import lib_wmi

    if lib_wmi.ValidClassWmi(entity_type):
        # TODO: This could loop on all machines possibly describing this object. How ?
        wmiurl = lib_wmi.GetWmiUrl(entity_host, name_space, entity_type,
                                   entity_id)
        if wmiurl:
            wmi_node = lib_common.NodeUrl(wmiurl)
            if entity_host:
                txt_literal = "WMI url, host=%s class=%s" % (entity_host,
                                                             entity_type)
            else:
                txt_literal = "WMI url, current host, class=%s" % entity_type

            map_wmi[wmi_node] = [(pc.property_information,
                                  lib_util.NodeLiteral(txt_literal))]

            if entity_host:
                node_portal_wmi = lib_util.UrlPortalWmi(entity_host)

                map_wmi[wmi_node].append(
                    (pc.property_rdf_data_nolist2, node_portal_wmi))
    return map_wmi
コード例 #3
0
def Main():
    # This can process remote hosts because it does not call any script, just shows them.
    cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True)

    grph = cgiEnv.GetGraph()

    entity_host = cgiEnv.GetHost()
    entity_host = lib_wmi.NormalHostName(entity_host)

    # TODO: We may also loop on all machines which may describe this object.
    wmiurl = lib_wmi.GetWmiUrl(entity_host, "", "", "")
    if not wmiurl is None:
        wmi_node = lib_common.NodeUrl(wmiurl)

        host_node = lib_uris.gUriGen.HostnameUri(entity_host)
        grph.add((host_node, pc.property_information, wmi_node))
    else:
        lib_common.ErrorMessageHtml("WMI module not installed")

    cgiEnv.OutCgiRdf()
コード例 #4
0
ファイル: class_type_all.py プロジェクト: rchateauneu/survol
def _create_wmi_node(grph, root_node, entity_host, name_space, class_name,
                     entity_id):
    """Adds a WMI node and other stuff, for the class name."""
    wmiurl = lib_wmi.GetWmiUrl(entity_host, name_space, class_name, entity_id)
    if wmiurl is None:
        return

    # There might be "http:" or the port number around the host.
    wmi_node = lib_common.NodeUrl(wmiurl)
    grph.add((root_node, pc.property_wmi_data, wmi_node))

    # TODO: Shame, we just did it in GetWmiUrl.
    ip_only = lib_util.EntHostToIp(entity_host)
    try:
        # It simply returns if it cannot connect.
        conn_wmi = lib_wmi.WmiConnect(ip_only, name_space, False)
        if not conn_wmi:
            raise Exception("Cannot connect")
        lib_wmi.WmiAddClassQualifiers(grph, conn_wmi, wmi_node, class_name,
                                      False)

        # Now displays the base classes, to the top of the inheritance tree.
        pair_name_node = lib_wmi.WmiAddBaseClasses(grph, conn_wmi, wmi_node,
                                                   ip_only, name_space,
                                                   class_name)

    except Exception as exc:
        pair_name_node = None
        # TODO: If the class is not defined, maybe do not display it.
        err_msg = "WMI connection %s: %s" % (ip_only, str(exc))
        grph.add((wmi_node, lib_common.MakeProp("WMI Error"),
                  lib_util.NodeLiteral(err_msg)))

    url_name_space = lib_wmi.NamespaceUrl(name_space, ip_only, class_name)
    grph.add((wmi_node, pc.property_information,
              lib_common.NodeUrl(url_name_space)))

    return pair_name_node
コード例 #5
0
def CreateWmiNode(grph, rootNode, entity_host, nameSpace, className,
                  entity_id):
    wmiurl = lib_wmi.GetWmiUrl(entity_host, nameSpace, className, entity_id)
    if wmiurl is None:
        return

    # There might be "http:" or the port number around the host.
    # hostOnly = lib_util.EntHostToIp(entity_host)
    # sys.stderr.write("entity_host=%s nameSpace=%s entity_type=%s className=%s wmiurl=%s\n" % ( entity_host, nameSpace, entity_type, className, str(wmiurl) ) )
    wmiNode = lib_common.NodeUrl(wmiurl)
    grph.add((rootNode, pc.property_wmi_data, wmiNode))

    # TODO: Shame, we just did it in GetWmiUrl.
    ipOnly = lib_util.EntHostToIp(entity_host)
    try:
        # It simply returns if it cannot connect.
        connWmi = lib_wmi.WmiConnect(ipOnly, nameSpace, False)
        lib_wmi.WmiAddClassQualifiers(grph, connWmi, wmiNode, className, False)

        # Now displays the base classes, to the top of the inheritance tree.
        pairNameNode = lib_wmi.WmiAddBaseClasses(grph, connWmi, wmiNode,
                                                 ipOnly, nameSpace, className)

    except Exception:
        pairNameNode = None
        # TODO: If the class is not defined, maybe do not display it.
        exc = sys.exc_info()[1]
        grph.add((wmiNode, lib_common.MakeProp("WMI Error"),
                  lib_common.NodeLiteral(str(exc))))

    urlNameSpace = lib_wmi.NamespaceUrl(nameSpace, ipOnly, className)
    # sys.stderr.write("entity_host=%s urlNameSpace=%s\n"%(entity_host,urlNameSpace))
    grph.add(
        (wmiNode, pc.property_information, lib_common.NodeUrl(urlNameSpace)))

    return pairNameNode