def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() mysql_cmd = "mysqladmin processlist" try: mysql_resu = os.popen(mysql_cmd) except FileNotFoundError: lib_common.ErrorMessageHtml("Cannot find mysqladmin") for lin in mysql_resu: sys.stderr.write("lin=" + lin + "\n") words_arr = lin.split('|') if len(words_arr) < 4: continue mysql_id = words_arr[1].strip() # This is a MySql user, not Linux or Windows. mysql_user = words_arr[2].strip() mysql_host = words_arr[3].strip() mysql_command = words_arr[8].strip() if mysql_host == 'Host': continue sys.stderr.write("host=" + mysql_host + "\n") mysql_addr_arr = mysql_host.split(':') mysql_id_node = lib_common.NodeUrl('urn://' + lib_util.currentHostname + '/mysql/' + str(mysql_id)) if len(mysql_addr_arr) == 2: socketNode = lib_common.gUriGen.AddrUri(mysql_addr_arr[0], mysql_addr_arr[1]) # BEWARE: mysql_id_node is not a process. But why not after all. grph.add((mysql_id_node, pc.property_has_socket, socketNode)) # TODO: Here, we should create a dummy socket and a dummy process id on the other machine. # Otherwise, the merging will not bring anything. sql_task_node = socketNode # TODO: Here, we only know that another process from anothere machine is connected here. #else: # dummy_local_process = lib_common.AnonymousPidNode(lib_util.currentHostname) # grph.add( ( dummy_local_process, pc.property_mysql_id, mysql_id_node ) ) # sql_task_node = dummy_local_process if mysql_command != "": grph.add((sql_task_node, pc.property_information, lib_common.NodeLiteral(mysql_command))) # Ce lien est en principe toujours valable. # Mais idealement il faudrait le tester. # TODO: CHECK IF THIS IS THE RIGHT PORT NUMBER. phpmyadminUrl = "http://" + lib_util.currentHostname + "/phpmyadmin/" phpmyadminNode = lib_common.NodeUrl(phpmyadminUrl) grph.add( (lib_common.nodeMachine, pc.property_rdf_data_nolist1, phpmyadminNode)) cgiEnv.OutCgiRdf()
def _add_survol_node(grph, host_survol, url_survol_clean): logging.debug("AddSurvolNode hostSurvol=%s", host_survol) survol_host_node = lib_uris.gUriGen.HostnameUri(host_survol) curr_disp_mode = lib_util.GuessDisplayMode() # Several possibilities: # - Open a new HTML page with this URL. Or SVG, passed on the current mode. # - If we are in D3 mode, this should return a JSON object from the other agent. if curr_disp_mode == "json": server_box = lib_uris.OtherAgentBox(host_survol) # This is the URL of the remote host, on the remote agent. node_remote_host = server_box.HostnameUri(host_survol) grph.add((survol_host_node, lib_common.MakeProp("Survol host"), node_remote_host)) node_survol_url = lib_common.NodeUrl(url_survol_clean) grph.add((survol_host_node, lib_common.MakeProp("Survol agent"), node_survol_url)) else: url_survol_moded = lib_util.AnyUriModed(url_survol_clean, curr_disp_mode) node_survol_url = lib_common.NodeUrl(url_survol_moded) # Should check the URL to be sure it is valid. grph.add((survol_host_node, lib_common.MakeProp("Survol agent"), node_survol_url)) return node_survol_url
def _create_wbem_node(grph, root_node, entity_host, name_space, class_name, entity_id): wbem_namespace = name_space.replace("\\", "/") wbem_servers_desc_list = lib_wbem.GetWbemUrls(entity_host, wbem_namespace, class_name, entity_id) # If there are no servers. pair_name_node = None for url_server in wbem_servers_desc_list: wbem_node = lib_common.NodeUrl(url_server[0]) grph.add((root_node, pc.property_wbem_data, wbem_node)) wbemHostNode = lib_uris.gUriGen.HostnameUri(url_server[1]) grph.add((wbem_node, pc.property_host, wbemHostNode)) # TODO: Add a Yawn server ?? grph.add((wbem_node, pc.property_wbem_server, lib_util.NodeLiteral(url_server[1]))) # Now adds the description of the class. try: conn_wbem = lib_wbem.WbemConnection(entity_host) except Exception as exc: logging.error("WbemConnection throw:%s" % str(exc)) continue kla_descrip = lib_wbem.WbemClassDescription(conn_wbem, class_name, wbem_namespace) ok_wbem_class = True if not kla_descrip: ok_wbem_class = False kla_descrip = "Undefined class %s %s" % (wbem_namespace, class_name) grph.add((wbem_node, pc.property_information, lib_util.NodeLiteral(kla_descrip))) # Maybe this class is not Known in WBEM. try: pair_name_node = _wbem_add_all_base_classes( grph, conn_wbem, wbem_node, entity_host, name_space, class_name) except: pair_name_node = None if ok_wbem_class and wbem_ok and name_space != "" and entity_host != "": namespace_url = lib_wbem.NamespaceUrl(name_space, entity_host, class_name) namespace_node = lib_common.NodeUrl(namespace_url) grph.add((wbem_node, pc.property_information, namespace_node)) # TODO: This is a bit absurd because we return just one list. return pair_name_node
def CreateWbemNode(grph, rootNode, entity_host, nameSpace, className, entity_id): wbemNamespace = nameSpace.replace("\\", "/") wbem_servers_desc_list = lib_wbem.GetWbemUrls(entity_host, wbemNamespace, className, entity_id) # If there are no servers. pairNameNode = None for url_server in wbem_servers_desc_list: wbemNode = lib_common.NodeUrl(url_server[0]) grph.add((rootNode, pc.property_wbem_data, wbemNode)) # Le naming est idiot: "rchateau-HP at localhost" wbemHostNode = lib_common.gUriGen.HostnameUri(url_server[1]) grph.add((wbemNode, pc.property_host, wbemHostNode)) # TODO: Add a Yawn server ?? grph.add((wbemNode, pc.property_wbem_server, lib_common.NodeLiteral(url_server[1]))) # Now adds the description of the class. connWbem = lib_wbem.WbemConnection(entity_host) klaDescrip = lib_wbem.WbemClassDescription(connWbem, className, wbemNamespace) okWbemClass = True if not klaDescrip: okWbemClass = False klaDescrip = "Undefined class %s %s" % (wbemNamespace, className) grph.add((wbemNode, pc.property_information, lib_common.NodeLiteral(klaDescrip))) # Maybe this class is not Known in WBEM. try: pairNameNode = WbemAddBaseClasses(grph, connWbem, wbemNode, entity_host, nameSpace, className) except: pairNameNode = None if okWbemClass and wbemOk and nameSpace != "" and entity_host != "": namespaceUrl = lib_wbem.NamespaceUrl(nameSpace, entity_host, className) namespaceNode = lib_common.NodeUrl(namespaceUrl) grph.add((wbemNode, pc.property_information, namespaceNode)) # TODO: This is a bit absurd because we return just one list. return pairNameNode
def DisplayObjectAssociators(grph, wmiInstanceNode, objWmi, cgiMoniker): sys.stderr.write("DisplayObjectAssociators\n") # It is possible to restrict the associators to a specific class only. for anAssoc in objWmi.associators(): # assocMoniker=\\RCHATEAU-HP\root\cimv2:Win32_ComputerSystem.Name="RCHATEAU-HP" assocMoniker = str(anAssoc.path()) sys.stderr.write("DisplayObjectAssociators anAssoc Moniker=%s\n" % assocMoniker) # derivation=(u'CIM_UnitaryComputerSystem', u'CIM_ComputerSystem', u'CIM_System', u'CIM_LogicalElement', u'CIM_ManagedSystemElement') assocDerivation = anAssoc.derivation() sys.stderr.write("DisplayObjectAssociators anAssoc derivation=%s\n" % str(assocDerivation)) # sys.stderr.write("DisplayObjectAssociators anAssoc=%s\n"%str(dir(anAssoc))) # TODO: Consider these methods: associated_classes, associators, derivation, # id, keys, methods, ole_object, path, properties, property_map, put, # qualifiers, references, set, wmi_property # BEWARE: For example for CIM_ComputerSystem, the host name must be in lowercase. # TODO: This is not done here. Luckily the universal alias does this properly. assocInstanceUrl = lib_util.EntityUrlFromMoniker(assocMoniker) assocInstanceNode = lib_common.NodeUrl(assocInstanceUrl) grph.add((wmiInstanceNode, lib_common.MakeProp(assocDerivation[0]), assocInstanceNode))
def Main(): cgiEnv = lib_common.CgiEnv() configNam = cgiEnv.m_entity_id_dict["Url"] namVHost = cgiEnv.m_entity_id_dict["VHost"] nodeManager = survol_rabbitmq_manager.MakeUri(configNam) creds = lib_credentials.GetCredentials("RabbitMQ", configNam) # cl = Client('localhost:12345', 'guest', 'guest') cl = Client(configNam, creds[0], creds[1]) grph = cgiEnv.GetGraph() nodVHost = survol_rabbitmq_vhost.MakeUri(configNam, namVHost) grph.add((nodeManager, lib_common.MakeProp("virtual host node"), nodVHost)) for quList in cl.get_queues(namVHost): namQueue = quList["name"] DEBUG("q=%s", namQueue) nodeQueue = survol_rabbitmq_queue.MakeUri(configNam, namVHost, namQueue) managementUrl = rabbitmq.ManagementUrlPrefix(configNam, "queues", namVHost, namQueue) grph.add((nodeQueue, lib_common.MakeProp("Management"), lib_common.NodeUrl(managementUrl))) grph.add((nodVHost, lib_common.MakeProp("Queue"), nodeQueue)) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() config_nam = cgiEnv.m_entity_id_dict["Url"] nam_v_host = cgiEnv.m_entity_id_dict["VHost"] node_manager = survol_rabbitmq_manager.MakeUri(config_nam) creds = lib_credentials.GetCredentials("RabbitMQ", config_nam) # cl = Client('localhost:12345', 'guest', '*****') cl = Client(config_nam, creds[0], creds[1]) grph = cgiEnv.GetGraph() nod_v_host = survol_rabbitmq_vhost.MakeUri(config_nam, nam_v_host) grph.add( (node_manager, lib_common.MakeProp("virtual host node"), nod_v_host)) for obj_exchange in cl.get_exchanges(nam_v_host): nam_exchange = obj_exchange["name"] logging.debug("nam_exchange=%s", nam_exchange) node_exchange = survol_rabbitmq_exchange.MakeUri( config_nam, nam_v_host, nam_exchange) management_url = rabbitmq.ManagementUrlPrefix(config_nam, "exchanges", nam_v_host, nam_exchange) grph.add((node_exchange, lib_common.MakeProp("Management"), lib_common.NodeUrl(management_url))) grph.add((nod_v_host, lib_common.MakeProp("Exchange"), node_exchange)) cgiEnv.OutCgiRdf()
def DisplayObjectAssociators(grph, wmi_instance_node, obj_wmi, cgiMoniker): logging.debug("DisplayObjectAssociators.") # It is possible to restrict the associators to a specific class only. for an_assoc in obj_wmi.associators(): # assoc_moniker=\\MYMACHINE\root\cimv2:Win32_ComputerSystem.Name="MYMACHINE" assoc_moniker = str(an_assoc.path()) logging.debug("DisplayObjectAssociators an_assoc Moniker=%s", assoc_moniker) # derivation=(u'CIM_UnitaryComputerSystem', u'CIM_ComputerSystem', u'CIM_System', # u'CIM_LogicalElement', u'CIM_ManagedSystemElement') assoc_derivation = an_assoc.derivation() logging.debug("DisplayObjectAssociators an_assoc derivation=%s", str(assoc_derivation)) # TODO: Consider these methods: associated_classes, associators, derivation, # id, keys, methods, ole_object, path, properties, property_map, put, # qualifiers, references, set, wmi_property # BEWARE: For example for CIM_ComputerSystem, the host name must be in lowercase. # TODO: This is not done here. Luckily the universal alias does this properly. assoc_instance_url = lib_util.EntityUrlFromMoniker(assoc_moniker) assoc_instance_node = lib_common.NodeUrl(assoc_instance_url) grph.add((wmi_instance_node, lib_common.MakeProp(assoc_derivation[0]), assoc_instance_node))
def AddConnections(grph,listConnections,configNam,nodeManager): for objConnect in listConnections: namConnect = objConnect["name"] DEBUG("namConnect=%s",namConnect) nodeConnect = survol_rabbitmq_connection.MakeUri(configNam,namConnect) try: grph.add( ( nodeConnect, lib_common.MakeProp("Protocol"), lib_common.NodeLiteral(objConnect["protocol"]) ) ) except KeyError: pass try: grph.add( ( nodeConnect, lib_common.MakeProp("Node"), lib_common.NodeLiteral(objConnect["node"]) ) ) except KeyError: pass nodeUser = survol_rabbitmq_user.MakeUri(configNam,objConnect["user"]) try: grph.add( ( nodeConnect, lib_common.MakeProp("User"), nodeUser ) ) except KeyError: pass # '127.0.0.1:51532 -> 127.0.0.1:5672' # http://localhost:12345/#/connections/127.0.0.1%3A51532%20-%3E%20127.0.0.1%3A5672 namConnectCgi = namConnect.replace(">",">") DEBUG("namConnectCgi=%s",namConnectCgi) managementUrl = rabbitmq.ManagementUrlPrefix(configNam,"connections",namConnectCgi) grph.add( ( nodeConnect, lib_common.MakeProp("Management"), lib_common.NodeUrl(managementUrl) ) ) grph.add( ( nodeManager, lib_common.MakeProp("Connection"), nodeConnect ) )
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
def Main(): cgiEnv = lib_common.CgiEnv() configNam = cgiEnv.m_entity_id_dict["Url"] namVHost = cgiEnv.m_entity_id_dict["VHost"] nodeManager = survol_rabbitmq_manager.MakeUri(configNam) creds = lib_credentials.GetCredentials("RabbitMQ", configNam) # cl = Client('localhost:12345', 'guest', 'guest') cl = Client(configNam, creds[0], creds[1]) grph = cgiEnv.GetGraph() nodVHost = survol_rabbitmq_vhost.MakeUri(configNam, namVHost) grph.add((nodeManager, lib_common.MakeProp("virtual host node"), nodVHost)) for objExchange in cl.get_exchanges(namVHost): namExchange = objExchange["name"] sys.stderr.write("namExchange=%s\n" % (namExchange)) nodeExchange = survol_rabbitmq_exchange.MakeUri( configNam, namVHost, namExchange) managementUrl = rabbitmq.ManagementUrlPrefix(configNam, "exchanges", namVHost, namExchange) grph.add((nodeExchange, lib_common.MakeProp("Management"), lib_common.NodeUrl(managementUrl))) grph.add((nodVHost, lib_common.MakeProp("Exchange"), nodeExchange)) cgiEnv.OutCgiRdf()
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
def Main(): # TODO: can_process_remote should be suppressed because it duplicates CanProcessRemote cgiEnv = lib_common.CgiEnv(can_process_remote=True) pid = int(cgiEnv.GetId()) machine_name = cgiEnv.GetHost() grph = cgiEnv.GetGraph() cimom_url = lib_wbem.HostnameToWbemServer(machine_name) DEBUG( "wbem_process_info.py currentHostname=%s pid=%d machine_name=%s cimom_url=%s", lib_util.currentHostname, pid, machine_name, cimom_url) conn_wbem = lib_wbem.WbemConnection(cimom_url) name_space = "root/cimv2" try: inst_lists = conn_wbem.ExecQuery( "WQL", 'select * from CIM_Process where Handle="%s"' % pid, name_space) except: lib_common.ErrorMessageHtml("Error:" + str(sys.exc_info())) class_name = "CIM_Process" dict_props = {"Handle": pid} root_node = lib_util.EntityClassNode(class_name, name_space, cimom_url, "WBEM") # There should be only one object, hopefully. for an_inst in inst_lists: dict_inst = dict(an_inst) host_only = lib_util.EntHostToIp(cimom_url) if lib_util.IsLocalAddress(host_only): uri_inst = lib_common.gUriGen.UriMakeFromDict( class_name, dict_props) else: uri_inst = lib_common.RemoteBox(host_only).UriMakeFromDict( class_name, dict_props) grph.add((root_node, lib_common.MakeProp(class_name), uri_inst)) url_namespace = lib_wbem.NamespaceUrl(name_space, cimom_url, class_name) nod_namespace = lib_common.NodeUrl(url_namespace) grph.add((root_node, pc.property_cim_subnamespace, nod_namespace)) # None properties are not printed. for iname_key in dict_inst: iname_val = dict_inst[iname_key] # TODO: If this is a reference, create a Node !!!!!!! if not iname_val is None: grph.add((uri_inst, lib_common.MakeProp(iname_key), lib_common.NodeLiteral(iname_val))) # TODO: Call the method Associators(). Idem References(). cgiEnv.OutCgiRdf()
def PrintClassRecu(grph, rootNode, tree_classes, topclassNam, depth, wbemNamespace, cimomUrl, maxDepth, withYawnUrls): # sys.stderr.write("topclassNam=%s depth=%d\n" % (topclassNam,depth)) if depth > maxDepth: return depth += 1 wbemUrl = lib_wbem.ClassUrl(wbemNamespace, cimomUrl, topclassNam) wbemNode = lib_common.NodeUrl(wbemUrl) grph.add((rootNode, pc.property_cim_subclass, wbemNode)) # The class is the starting point when displaying the class tree of the namespace. wbemNodeSub = WbemNamespaceNode(wbemNamespace, cimomUrl, topclassNam) grph.add((wbemNode, pc.property_rdf_data_nolist1, wbemNodeSub)) nodeGeneralisedClass = lib_util.EntityClassNode(topclassNam, wbemNamespace, cimomUrl, "WBEM") grph.add((wbemNode, pc.property_rdf_data_nolist2, nodeGeneralisedClass)) if withYawnUrls: AddYawnNode(cimomUrl, topclassNam, wbemNamespace, grph, wbemNode) try: # TODO: This should be indexed with a en empty string ! if topclassNam == "": topclassNam = None for cl in tree_classes[topclassNam]: PrintClassRecu(grph, wbemNode, tree_classes, cl.classname, depth, wbemNamespace, cimomUrl, maxDepth, withYawnUrls) except KeyError: pass # No subclass.
def WbemAddBaseClass(grph, connWbem, wbemNode, entity_host, wbemNamespace, entity_type): wbemKlass = lib_wbem.WbemGetClassObj(connWbem, entity_type, wbemNamespace) if not wbemKlass: return (None, None) superKlassName = wbemKlass.superclass # sys.stderr.write("WBEM superKlassName=%s\n" % superKlassName) # An empty string or None. if not superKlassName: return (None, None) # TODO: Should be changed, this is slow and inconvenient. wbemSuperUrlsList = lib_wbem.GetWbemUrls(entity_host, wbemNamespace, superKlassName, "") if not wbemSuperUrlsList: return (None, None) # TODO: Which one should we take, http or https ??? wbemSuperUrl = wbemSuperUrlsList[0][0] sys.stderr.write("WBEM wbemSuperUrl=%s\n" % wbemSuperUrl) wbemSuperNode = lib_common.NodeUrl(wbemSuperUrl) grph.add((wbemSuperNode, pc.property_cim_subclass, wbemNode)) klaDescrip = lib_wbem.WbemClassDescription(connWbem, superKlassName, wbemNamespace) if not klaDescrip: klaDescrip = "Undefined class %s %s" % (wbemNamespace, superKlassName) grph.add((wbemSuperNode, pc.property_information, lib_common.NodeLiteral(klaDescrip))) return (wbemSuperNode, superKlassName)
def AddWbemServers(entity_host, name_space, entity_type, entity_id): map_wbem = dict() try: # Maybe some of these servers are not able to display anything about this object. import lib_wbem wbem_servers_desc_list = lib_wbem.GetWbemUrlsTyped( entity_host, name_space, entity_type, entity_id) for url_server in wbem_servers_desc_list: # TODO: Filter only entity_host if lib_wbem.ValidClassWbem(entity_type): wbem_node = lib_common.NodeUrl(url_server[0]) if entity_host: txt_literal = "WBEM url, host=%s class=%s" % (entity_host, entity_type) else: txt_literal = "WBEM url, current host, class=%s" % entity_type wbem_host_node = lib_uris.gUriGen.HostnameUri(url_server[1]) map_wbem[wbem_node] = [(pc.property_information, lib_util.NodeLiteral(txt_literal)), (pc.property_host, wbem_host_node)] # TODO: This could try to open a HTTP server on this machine, possibly with port 80. # grph.add( ( wbem_host_node, pc.property_information, lib_util.NodeLiteral("Url to host") ) ) except ImportError: pass return map_wbem
def CreateOurNode(grph, rootNode, entity_host, nameSpace, className, entity_id): # This try to find a correct url for an entity type, without an entity id. # TODO: Donner plusieurs types d'enumerations possibles. # At the moment, we just expect a file called "enumerate_<entity>.py" enumerateScript = "enumerate_" + className + ".py" # sys.stderr.write("enumerateScript=%s\n" % enumerateScript) baseDir = lib_util.gblTopScripts + "/sources_types" # TODO: Parser en fonction des "/" # TODO: C est idiot: Pourquoi boucler alors qu on connait le nom du fichier ?? for dirpath, dirnames, filenames in os.walk(baseDir): # sys.stderr.write("dirpath=%s\n" % dirpath) for filename in [f for f in filenames if f == enumerateScript]: shortDir = dirpath[len(lib_util.gblTopScripts):] fullScriptNam = os.path.join(shortDir, filename).replace('\\', '/') sys.stderr.write("fullScriptNam=%s\n" % fullScriptNam) # TODO: Maybe remove the beginning of the file. localClassUrl = lib_util.ScriptizeCimom(fullScriptNam, className, entity_host) localClassNode = lib_common.NodeUrl(localClassUrl) grph.add((rootNode, pc.property_directory, localClassNode))
def _enumerate_services(grph, subscription_name): subscription_id, certificate_path = lib_credentials.GetCredentials( "Azure", subscription_name) sms = ServiceManagementService(subscription_id, certificate_path) subscription_node = subscription.MakeUri(subscription_name) try: lst_srvs = sms.list_hosted_services() except Exception as exc: lib_common.ErrorMessageHtml("Unexpected error:" + str(exc)) for srv in lst_srvs: serv_node = service.MakeUri(srv.service_name, subscription_name) grph.add( (subscription_node, lib_common.MakeProp("Service"), serv_node)) # There will be duplicates. loca_node = location.MakeUri(srv.hosted_service_properties.location, subscription_name) grph.add((serv_node, lib_common.MakeProp("Location"), loca_node)) grph.add((serv_node, pc.property_rdf_data_nolist1, lib_common.NodeUrl(srv.url)))
def Main(): cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True) cimom_url = cgiEnv.GetHost() grph = cgiEnv.GetGraph() # There is no consensus on the WBEM class for namespaces, # so we have ours which must be correctly mapped. namespace_class = "wbem_namespace" root_node = lib_util.EntityUri(namespace_class, "") try: conn_wbem = lib_wbem.WbemConnection(cimom_url) nsd = lib_wbem.EnumNamespacesCapabilities(conn_wbem) except Exception as exc: lib_common.ErrorMessageHtml("Namespaces from :" + cimom_url + " Caught:" + str(exc)) # TODO: We should draw a namespaces tree but more examples needed. for nskey in nsd: cnt = nsd[nskey] wbem_url = lib_wbem.NamespaceUrl(nskey, cimom_url) wbem_node = lib_common.NodeUrl(wbem_url) grph.add((root_node, pc.property_cim_subnamespace, wbem_node)) grph.add( (wbem_node, pc.property_information, lib_util.NodeLiteral(nskey))) grph.add( (wbem_node, pc.property_information, lib_util.NodeLiteral(cnt))) cgiEnv.OutCgiRdf("LAYOUT_RECT")
def Main(): # This can process remote hosts because it does not call any script, just shows them. cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() (nameSpace, className, entity_type) = cgiEnv.get_namespace_type() entity_host = cgiEnv.GetHost() hostId = cgiEnv.GetId() DEBUG("entity_host=%s entity_type=%s hostname=%s", entity_host, entity_type, hostId) wbem_urls_list = lib_wbem.GetWbemUrlsTyped(entity_host, nameSpace, entity_type, hostId) # Maybe some of these servers are not able to display anything about this object. for (url_wbem, wbemHost) in wbem_urls_list: DEBUG("url_wbem=%s wbemHost=%s", url_wbem, wbemHost) wbemNode = lib_common.NodeUrl(url_wbem) hostNode = lib_common.gUriGen.HostnameUri(wbemHost) grph.add((hostNode, pc.property_information, wbemNode)) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() # subscriptionName=Azure.DefaultSubscription() subscriptionName = cgiEnv.m_entity_id_dict["Subscription"] (subscription_id, certificate_path) = lib_credentials.GetCredentials( "Azure", subscriptionName) sms = ServiceManagementService(subscription_id, certificate_path) subscriptionNode = subscription.MakeUri(subscriptionName) try: # This throws when running with Apache. OK with cgiserver.py lstSrvs = sms.list_hosted_services() except: lib_common.ErrorMessageHtml("Unexpected error:" + str(sys.exc_info())) for srv in lstSrvs: servNode = service.MakeUri(srv.service_name, subscriptionName) grph.add((subscriptionNode, lib_common.MakeProp("Service"), servNode)) # There will be duplicates. locaNode = location.MakeUri(srv.hosted_service_properties.location, subscriptionName) grph.add((servNode, lib_common.MakeProp("Location"), locaNode)) grph.add((servNode, pc.property_rdf_data_nolist1, lib_common.NodeUrl(srv.url))) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() configNam = cgiEnv.GetId() nodeManager = survol_rabbitmq_manager.MakeUri(configNam) creds = lib_credentials.GetCredentials("RabbitMQ", configNam) # cl = Client('localhost:12345', 'guest', 'guest') cl = Client(configNam, creds[0], creds[1]) grph = cgiEnv.GetGraph() # >>> cl.get_all_vhosts() # http://localhost:12345/api/vhosts # [{u'name': u'/', u'tracing': False, u'messages_details': {u'rate': 0.0}, u'messages': 0, u'message_stats': {u'deliver_no_ack': 0, u' # publish_out': 0, u'get_no_ack': 13, u'return_unroutable': 0, u'confirm': 0, u'deliver_get': 13, u'publish': 13, u'confirm_details': # {u'rate': 0.0}, u'ack_details': {u'rate': 0.0}, u'get': 0, u'deliver': 0, u'publish_out_details': {u'rate': 0.0}, u'redeliver_detail # s': {u'rate': 0.0}, u'deliver_details': {u'rate': 0.0}, u'deliver_get_details': {u'rate': 0.0}, u'publish_details': {u'rate': 0.0}, # u'publish_in_details': {u'rate': 0.0}, u'ack': 0, u'publish_in': 0, u'return_unroutable_details': {u'rate': 0.0}, u'get_details': {u # 'rate': 0.0}, u'get_no_ack_details': {u'rate': 0.0}, u'deliver_no_ack_details': {u'rate': 0.0}, u'redeliver': 0}, u'messages_unackno # wledged_details': {u'rate': 0.0}, u'messages_ready_details': {u'rate': 0.0}, u'messages_unacknowledged': 0, u'messages_ready': 0}] try: # listVHosts = cl.get_all_vhosts() except Exception as exc: lib_common.ErrorMessageHtml("Caught:" + str(exc)) for objVHost in listVHosts: namVHost = objVHost["name"] logging.debug("q=%s", namVHost) nodeVHost = survol_rabbitmq_vhost.MakeUri(configNam, namVHost) try: grph.add((nodeVHost, lib_common.MakeProp("tracing"), lib_util.NodeLiteral(objVHost["tracing"]))) except KeyError: pass try: grph.add((nodeVHost, lib_common.MakeProp("messages"), lib_util.NodeLiteral(objVHost["messages"]))) except KeyError: pass # http://127.0.0.1:12345/#/vhosts// managementUrl = rabbitmq.ManagementUrlPrefix(configNam, "vhosts", namVHost) grph.add((nodeVHost, lib_common.MakeProp("Management"), lib_common.NodeUrl(managementUrl))) grph.add((nodeManager, lib_common.MakeProp("Virtual host"), nodeVHost)) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() grph = cgiEnv.GetGraph() subscription_name = cgiEnv.m_entity_id_dict["Subscription"] subscription_id, certificate_path = lib_credentials.GetCredentials( "Azure", subscription_name) sms = ServiceManagementService(subscription_id, certificate_path) subscription_node = subscription.MakeUri(subscription_name) # Some information printed grph.add((subscription_node, lib_common.MakeProp(".requestid"), lib_util.NodeLiteral(sms.requestid))) grph.add((subscription_node, lib_common.MakeProp(".x_ms_version"), lib_util.NodeLiteral(sms.x_ms_version))) prop_disk = lib_common.MakeProp("Disk") prop_disk_label = lib_common.MakeProp("Label") prop_disk_location = lib_common.MakeProp("Location") prop_media_link = lib_common.MakeProp("Media Link") try: lst_disks = sms.list_disks() except Exception as exc: lib_common.ErrorMessageHtml("Unexpected error:" + str(exc)) for dsk in lst_disks: logging.debug("dsk=%s", str(dir(dsk))) node_disk = disk.MakeUri(dsk.name, subscription_name) grph.add((subscription_node, prop_disk, node_disk)) grph.add((node_disk, lib_common.MakeProp("Size"), lib_util.NodeLiteral(dsk.logical_disk_size_in_gb))) url_disk = dsk.media_link grph.add((node_disk, prop_media_link, lib_common.NodeUrl(url_disk))) if dsk.affinity_group: aff_group = dsk.affinity_group grph.add((node_disk, lib_common.MakeProp("Affinity group"), lib_util.NodeLiteral(aff_group))) grph.add((node_disk, lib_common.MakeProp("Source image name"), lib_util.NodeLiteral(dsk.source_image_name))) grph.add((node_disk, lib_util.NodeLiteral("Operating System"), lib_util.NodeLiteral(dsk.os))) # grph.add((node_disk, lib_util.NodeLiteral("Hosted Service Name"), # lib_util.NodeLiteral(dsk.hosted_service_name))) if dsk.is_corrupted: grph.add((node_disk, lib_util.NodeLiteral("Corrupted"), lib_util.NodeLiteral(dsk.is_corrupted))) grph.add((node_disk, lib_util.NodeLiteral("Label"), lib_util.NodeLiteral(dsk.label))) # grph.add((node_disk, lib_common.MakeProp("Affinity group"), lib_util.NodeLiteral("dsk.affinity_group"))) logging.debug("dsk.attached_to=%s",str(dir(dsk.attached_to))) node_location = location.MakeUri(dsk.location, subscription_name) grph.add((node_disk, prop_disk_location, node_location)) # cgiEnv.OutCgiRdf("LAYOUT_RECT",[prop_disk,prop_disk_location,prop_media_link]) # cgiEnv.OutCgiRdf("LAYOUT_RECT",[prop_disk,prop_disk_location]) # cgiEnv.OutCgiRdf("LAYOUT_RECT",[prop_disk]) cgiEnv.OutCgiRdf("LAYOUT_RECT_TB")
def AddData(log_strm, grph, node, entity_type, entity_id, header, values): if plain_old: # Pour le moment, on ne fait qu'ajouter les proprietes. lenHead = len(header) lenVals = len(values) if lenHead != lenVals: log_strm.write("AddData Different lens: %d and %d.\n" % (lenHead, lenVals)) return for idx in range(0, lenHead): tmp_property = lib_common.NodeUrl(lib_properties.primns_slash + header[idx]) grph.add((node, tmp_property, lib_common.NodeLiteral(values[idx]))) return # Constraint on the entity id which must be stored in a file name. tabFilNam = TabularFilNam(entity_type, entity_id, header) csvFil = lib_common.TmpFil(tabFilNam) delim = '\t' csvFilNam = lib_common.get_temporary_directory() + TabularFilNam( entity_type, entity_id, header) csvFd = open(csvFilNam, "a") pos = csvFd.tell() if pos == 0: log_strm.write("CVS file %s does not exist.\n" % csvFilNam) csvFd.write("time-stamp" + delim + delim.join(header)) # If the file is too old, we might erase it first. # Let's hope the header did not change. # We might compare it and create another file if needed. timeStamp = time.time() dtStr = datetime.datetime.fromtimestamp(timeStamp).strftime( '%Y-%m-%d %H:%M:%S') csvFd.write(dtStr + delim + delim.join(values)) csvFd.close() url_csv = TabularUrl(entity_type, entity_id, header) # Afficher les csv_data dans le bloc du node, surtout ne pas creer un lien. grph.add((node, pc.property_csv_data, lib_common.NodeUrl(url_csv))) return
def _url_to_directory(full_dir_path): dir_prefix = "C://Users/CurrentUser" if full_dir_path.startswith(dir_prefix): short_path = full_dir_path[len(dir_prefix):] shortpathclean = short_path.replace("&", "&") # TODO: This is an experimental feature. dir_url = "http://127.0.0.1/Home/" + shortpathclean return lib_common.NodeUrl(dir_url) return None
def UrlDirectory( fullDirPath ): # sys.stderr.write("UrlDirectory fullDirPath=%s\n" % fullDirPath) dirPrefix = "C://Users/CurrentUser" if fullDirPath.startswith(dirPrefix): shortPath = fullDirPath[ len(dirPrefix) : ] shortpathclean = shortPath.replace("&","&") dirUrl = "http://127.0.0.1/Home/" + shortpathclean return lib_common.NodeUrl(dirUrl) return None
def _class_to_node(wmi_namespace, cimom_url, cls_nam): global dict_class_to_node try: wmi_node = dict_class_to_node[cls_nam] except KeyError: wmi_url = lib_wmi.ClassUrl(wmi_namespace, cimom_url, cls_nam) wmi_node = lib_common.NodeUrl(wmi_url) dict_class_to_node[cls_nam] = wmi_node return wmi_node
def ClassToNode(wmiNamespace, cimomUrl, clsNam): global dictClassToNode try: wmiNode = dictClassToNode[clsNam] except KeyError: wmiUrl = lib_wmi.ClassUrl(wmiNamespace, cimomUrl, clsNam) wmiNode = lib_common.NodeUrl(wmiUrl) dictClassToNode[clsNam] = wmiNode return wmiNode
def Main(): cgiEnv = lib_common.CgiEnv() configNam = cgiEnv.GetId() nodeManager = survol_rabbitmq_manager.MakeUri(configNam) creds = lib_credentials.GetCredentials("RabbitMQ", configNam) # cl = Client('localhost:12345', 'guest', 'guest') cl = Client(configNam, creds[0], creds[1]) grph = cgiEnv.GetGraph() # cl.is_alive() #>>> cl.get_users() #[{u'hashing_algorithm': u'rabbit_password_hashing_sha256', u'name': u'guest', u'tags': u'administrator', u'password_hash': u'xxxxxx'}] try: # listUsers = cl.get_users() except: # exc = sys.exc_info()[1] lib_common.ErrorMessageHtml("Caught:" + str(exc)) for objUser in listUsers: namUser = objUser["name"] DEBUG("q=%s", namUser) nodeUser = survol_rabbitmq_user.MakeUri(configNam, namUser) try: grph.add((nodeUser, lib_common.MakeProp("Tags"), lib_common.NodeLiteral(objUser["tags"]))) except KeyError: pass try: grph.add((nodeUser, lib_common.MakeProp("Hashing algorithm"), lib_common.NodeLiteral(objUser["hashing_algorithm"]))) except KeyError: pass # http://127.0.0.1:12345/#/users/guest managementUrl = rabbitmq.ManagementUrlPrefix(configNam, "users", namUser) grph.add((nodeUser, lib_common.MakeProp("Management"), lib_common.NodeUrl(managementUrl))) grph.add((nodeManager, lib_common.MakeProp("User"), nodeUser)) cgiEnv.OutCgiRdf()
def _add_yawn_node(cimom_url, topclass_nam, wbem_namespace, grph, wbem_node): # We could take lib_util.currentHostname but Yawn is more probably running on a machine where Pegasus is there. cimom_no_port = cimom_url.split(":")[1] # The character "&" must be escaped TWICE ! ... yawn_url = "http:%s/yawn/GetClass/%s?url=%s&amp;verify=0&amp;ns=%s"\ % (cimom_no_port, topclass_nam, lib_util.EncodeUri(cimom_url), lib_util.EncodeUri(wbem_namespace)) # "http://192.168.1.88/yawn/GetClass/CIM_DeviceSAPImplementation?url=http%3A%2F%2F192.168.1.88%3A5988&verify=0&ns=root%2Fcimv2" grph.add((wbem_node, pc.property_rdf_data_nolist3, lib_common.NodeUrl(yawn_url)))