def Main(): cgiEnv = lib_common.ScriptEnvironment() instance_name = cgiEnv.m_entity_id_dict["Instance"] instance_node = survol_mysql_instance.MakeUri(instance_name) hostname, hostport = survol_mysql.InstanceToHostPort(instance_name) cgiEnv = lib_common.ScriptEnvironment() grph = cgiEnv.GetGraph() # BEWARE: The rule whether we use the host name or the host IP is not very clear ! # The IP address would be unambiguous but less clear. host_node = lib_uris.gUriGen.HostnameUri(hostname) prop_db = lib_common.MakeProp("Mysql database") a_cred = lib_credentials.GetCredentials("MySql", instance_name) # If user/password incorrect, nothing we can do. try: a_user = a_cred[0] conn_mysql = survol_mysql.MysqlConnect(instance_name, a_user, aPass=a_cred[1]) except Exception as exc: lib_common.ErrorMessageHtml( "Cannot connect to instance=%s user=%s:%s" % (instance_name, a_user, str(exc))) cursor_mysql = conn_mysql.cursor() cursor_mysql.execute("show databases") grph.add((host_node, lib_common.MakeProp("Mysql instance"), instance_node)) for db_info in cursor_mysql: #('information_schema',) #('primhilltcsrvdb1',) logging.debug("db_info=%s", str(db_info)) db_nam = db_info[0] node_mysql_database = survol_mysql_database.MakeUri( instance_name, db_nam) # Create a node for each database. user_node = lib_uris.gUriGen.UserUri(a_cred[0]) grph.add((node_mysql_database, pc.property_user, user_node)) grph.add((instance_node, prop_db, node_mysql_database)) cursor_mysql.close() conn_mysql.close() cgiEnv.OutCgiRdf("LAYOUT_SPLINE")
def Main(): cgiEnv = lib_common.ScriptEnvironment() grph = cgiEnv.GetGraph() display_data_sources(grph) cgiEnv.OutCgiRdf()
def Main(): # If this flag is set, the script uses SLP to discover WBEM Agents. paramkey_slp = "Service Location Protocol" cgiEnv = lib_common.ScriptEnvironment( parameters={paramkey_slp: False} ) flag_slp = bool(cgiEnv.get_parameters(paramkey_slp)) grph = cgiEnv.GetGraph() _wbem_servers_display(grph) if flag_slp: dict_services = survol_neighborhood.GetSLPServices("survol") for key_service in dict_services: wbem_node = _add_from_wbem_cimom(grph, key_service) if not wbem_node: continue grph.add((wbem_node, pc.property_information, lib_util.NodeLiteral("Service Location Protocol"))) attrs_service = dict_services[key_service] for key_attr in attrs_service: prop_attr = lib_common.MakeProp(key_attr) val_attr = attrs_service[key_attr] grph.add((wbem_node, prop_attr, lib_util.NodeLiteral(val_attr))) cgiEnv.OutCgiRdf()
def Snapshot(loop_number=1): tcpdump_cmd = _get_tcmp_dump_command() cgiEnv = lib_common.ScriptEnvironment() proc_open = None try: logging.debug("tcpdump_cmd=%s" % str(tcpdump_cmd)) proc_popen = subprocess.Popen(tcpdump_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) logging.debug("tcpdump started pid=i%d" % proc_open.pid) for lin in proc_popen.stdout.readlines(): if not lin: continue grph = cgiEnv.ReinitGraph() _parse_tcpdump_line(grph, lin) cgiEnv.OutCgiRdf() loop_number -= 1 if loop_number == 0: break except Exception as exc: logging.debug("tcpdump. Caught:%s" % str(exc)) lib_common.ErrorMessageHtml("tcpdump error:%s" % str(exc)) finally: logging.debug("tcpdump. Ending") if proc_open: logging.debug("tcpdump. Killing subprocess") proc_open.kill() stdout_data, stderr_data = proc_open.communicate() logging.debug("tcpdump. stdout_data=%s" % stdout_data) logging.debug("tcpdump. stderr_data=%s" % stderr_data) proc_open.terminate() else: logging.debug("tcpdump. Subprocess not started")
def Main(): cgiEnv = lib_common.ScriptEnvironment() try: the_pid = int(cgiEnv.GetId()) except Exception: lib_common.ErrorMessageHtml("Must provide a pid") grph = cgiEnv.GetGraph() node_process = lib_uris.gUriGen.PidUri(the_pid) CIM_Process.AddInfo(grph, node_process, [str(the_pid)]) fil_cgroups = "/proc/%d/cgroup" % the_pid for lin_cg in open(fil_cgroups): split_cg = lin_cg.split(':') hierarchy = split_cg[0] subsys_name_list = split_cg[1] mount_path = split_cg[2] mount_path = mount_path[:-1] # Strip trailing backslash-N mount_path_node = lib_uris.gUriGen.DirectoryUri(mount_path) for subsys_name in subsys_name_list.split(","): if subsys_name: cgrp_node = survol_cgroup.MakeUri(subsys_name) grph.add( (node_process, lib_common.MakeProp("CGroup"), cgrp_node)) grph.add((cgrp_node, lib_common.MakeProp("Hierarchy"), lib_util.NodeLiteral(hierarchy))) grph.add((cgrp_node, lib_common.MakeProp("Control group path"), mount_path_node)) cgiEnv.OutCgiRdf()
def Main(): paramkey_extensive_scan = "Extensive scan" # Beware that unchecked checkboxes are not posted, i.e. boolean variables set to False. # http://stackoverflow.com/questions/1809494/post-the-checkboxes-that-are-unchecked cgiEnv = lib_common.ScriptEnvironment( parameters={paramkey_extensive_scan: False}) pidint = int(cgiEnv.GetId()) grph = cgiEnv.GetGraph() paramExtensiveScan = cgiEnv.get_parameters(paramkey_extensive_scan) # By default, uses a small map of possible connection strings keyword. # Otherwise it is very slow to scan the whole process memory. if paramExtensiveScan: rgx_dsn = survol_odbc.regex_odbc_heavy else: rgx_dsn = survol_odbc.regex_odbc_light aggreg_dsns = _get_aggreg_dsns(pidint, rgx_dsn) node_process = lib_uris.gUriGen.PidUri(pidint) # TODO: Add a parameter to choose between light and heavy connection string definition. # TODO: Eliminate aggregated strings containing one or two tokens, # because they cannot be genuine DSNs. # 29812569: SERVER=\MYMACHINE # 34515016: Driver={SQL Server};Server=.\SQLEXPRESS;Database=ExpressDB;Trusted_Connection=yes # 34801013: SERVER=\MYMACHINE # 35634904: Driver={SQL Server};Server=.\SQLEXPRESS;Database=ExpressDB;Trusted_Connection=yes for aggreg_offset in aggreg_dsns: # Do not take the character before the keyword. aggreg_dsn_raw = aggreg_dsns[aggreg_offset] # Replaces all non-printable characters by spaces. # This should be done now by the regular expressions, but better be sure. aggreg_dsn = re.sub(b'[\x00-\x1f\x7f-\xff]+', b' ', aggreg_dsn_raw) # This should contain Ascii, convertible to UTF-8, but if the regular expression catch something else, # this decode throw: 'utf-8' codec can't decode bytes in position 3768-3769: invalid continuation byte. aggreg_dsn = aggreg_dsn.decode("utf-8", "ignore") dsn_full = str(aggreg_offset) + ": " + aggreg_dsn logging.debug("aggreg_offset=%s dsn_full=%s", aggreg_offset, dsn_full) grph.add((node_process, pc.property_information, lib_util.NodeLiteral(dsn_full))) ### NO! Confusion between DSN and connection string. # All the existing code does: ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam) # which basically creates "DSN=dsvNam;PWD=..." but here we already have the connection string. # TODO: Should we assimilate both ??? node_dsn = survol_odbc_dsn.MakeUri(aggreg_dsn) grph.add((node_process, pc.property_odbc_dsn, node_dsn)) # Fix this message. grph.add((node_dsn, pc.property_odbc_driver, lib_util.NodeLiteral("ODBC driver"))) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() try: the_pid = int(cgiEnv.GetId()) except KeyError: lib_common.ErrorMessageHtml("Process id should be provided") grph = cgiEnv.GetGraph() proc_obj = CIM_Process.PsutilGetProcObj(the_pid) procNode = lib_uris.gUriGen.PidUri(the_pid) CIM_Process.AddInfo(grph, procNode, [str(the_pid)]) execName, execErrMsg = CIM_Process.PsutilProcToExe(proc_obj) if execName == "": lib_common.ErrorMessageHtml("Cannot gdb:" + execErrMsg) PassThreads(the_pid, execName, grph, procNode) # If the command did not return anything, it means that # there are no threads, so we fall back to the "classical" # gdb output format. if len(grph) == 0: PassNoThreads(the_pid, execName, grph, procNode) 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) try: # This throws when running with Apache. OK with cgiserver.py 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))) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() file_shared_lib = cgiEnv.GetId() grph = cgiEnv.GetGraph() node_shared_lib = lib_uris.gUriGen.FileUri(file_shared_lib) cnt = 0 for symbol_type, tail in lib_nm.GetSymbols(file_shared_lib): if symbol_type == 'T' or type == 't': _add_known_symbol(grph, node_shared_lib, tail, file_shared_lib, symbol_type) #"U" The symbol is undefined. elif symbol_type == 'U': _add_unknown_symbol(grph, node_shared_lib, tail) else: # Does not display all symbols because it is too much information. # _add_known_symbol(tail, file_shared_lib, symbol_type) pass cnt += 1 logging.debug("Nm: Processed %d lines", cnt) cgiEnv.OutCgiRdf( "LAYOUT_RECT", [pc.property_symbol_defined, pc.property_symbol_undefined])
def Snapshot(): cgiEnv = lib_common.ScriptEnvironment() grph = cgiEnv.GetGraph() sample_root_node = rdflib.BNode() logging.debug("Adding net_io_counters") try: _add_system_counters_to_sample_node(grph, sample_root_node) except Exception as exc: logging.error("Caught:%s" % exc) logging.debug("Added net_io_counters") property_system_counters = lib_properties.MakeProp("system_counters") current_node_hostname = lib_uris.gUriGen.HostnameUri( lib_util.currentHostname) # TODO: pc.property_information is the default property for sorting. # TODO: This could use a specific timestamp property, for example "point in time" P585 timestamp_node = lib_kbase.time_stamp_now_node() grph.add((sample_root_node, pc.property_information, timestamp_node)) grph.add( (current_node_hostname, property_system_counters, sample_root_node)) cgiEnv.OutCgiRdf("LAYOUT_RECT", [property_system_counters])
def Main(): cgiEnv = lib_common.ScriptEnvironment() config_nam = cgiEnv.m_entity_id_dict["Url"] nam_connection = cgiEnv.m_entity_id_dict["Connection"] node_manager = survol_rabbitmq_manager.MakeUri(config_nam) creds = lib_credentials.GetCredentials("RabbitMQ", config_nam) cl = Client(config_nam, creds[0], creds[1]) grph = cgiEnv.GetGraph() logging.debug("nam_connection=%s", nam_connection) nod_connection = survol_rabbitmq_connection.MakeUri(config_nam, nam_connection) grph.add((node_manager, lib_common.MakeProp("Connection"), nod_connection)) try: connect_list = cl.get_connection(nam_connection) except Exception as exc: lib_common.ErrorMessageHtml("Caught:" + str(exc)) for connect_key in connect_list: connect_val = connect_list[connect_key] if connect_key == "vhost": nod_v_host = survol_rabbitmq_vhost.MakeUri(config_nam, connect_val) grph.add((nod_connection, lib_common.MakeProp("Virtual host"), nod_v_host)) elif connect_key == "user": nod_user = survol_rabbitmq_user.MakeUri(config_nam, connect_val) grph.add((nod_connection, lib_common.MakeProp("User"), nod_user)) elif connect_key == "host": nod_host = lib_uris.gUriGen.HostnameUri(connect_val) grph.add((nod_connection, lib_common.MakeProp("Host"), nod_host)) elif connect_key in ["name", "peer_host", "peer_port"]: pass else: if isinstance(connect_val, six.string_types): connect_val = connect_val.replace(">", "@") logging.debug("connect_key=%s connect_val=%s", connect_key, connect_val) elif isinstance(connect_val, dict): pass elif isinstance(connect_val, tuple): pass elif isinstance(connect_val, list): pass else: pass logging.debug("Literal=%s", lib_util.NodeLiteral(connect_val)) grph.add((nod_connection, lib_common.MakeProp(connect_key), lib_util.NodeLiteral(connect_val))) survol_rabbitmq_connection.AddSockets(grph, nod_connection, nam_connection) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() grph = cgiEnv.GetGraph() lib_common.ErrorMessageHtml("Not implemented yet") cgiEnv.OutCgiRdf("LAYOUT_RECT")
def Main(): cgiEnv = lib_common.ScriptEnvironment() grph = cgiEnv.GetGraph() # Several threads can add nodes at the same time. grph_lock = threading.Lock() map_hostnames_ipcount = dict() lookup_threads = [] set_ips = set() for lin_split in lib_arp.GetArpEntries(): ip_addr = lin_split[0] # Remove possible duplicates. if ip_addr in set_ips: continue set_ips.add(ip_addr) logging.debug("lin_split=%s", str(lin_split)) thr = LookupThread(lin_split, grph, grph_lock, map_hostnames_ipcount) thr.start() lookup_threads.append(thr) for thread in lookup_threads: thread.join() 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() try: lstOverview = cl.get_overview() except Exception as exc: lib_common.ErrorMessageHtml("Caught:" + str(exc)) for keyOverview in lstOverview: valOverview = lstOverview[keyOverview] valClean = valOverview # Otherwise it does not work as these chars should be espaced. # TODO: Nice display for Python lists and dicts. valClean = str(valClean).replace("{", "").replace("}", "") grph.add((nodeManager, lib_common.MakeProp(keyOverview), lib_util.NodeLiteral(valClean))) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() grph = cgiEnv.GetGraph() for lin_cg in open("/proc/cgroups"): # Just in case there would be a comment. lin_cg = lin_cg.strip() if lin_cg.startswith("#"): continue split_cg = lin_cg.split('\t') subsys_name = split_cg[0] hierarchy = split_cg[1] num_cgroups = split_cg[2] enabled = split_cg[3] cgrp_node = survol_cgroup.MakeUri(subsys_name) grph.add((cgrp_node, lib_common.MakeProp("Hierarchy"), lib_util.NodeLiteral(hierarchy))) grph.add((cgrp_node, lib_common.MakeProp("Num CGroups"), lib_util.NodeLiteral(num_cgroups))) grph.add((cgrp_node, lib_common.MakeProp("Enabled"), lib_util.NodeLiteral(enabled))) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() grph = cgiEnv.GetGraph() cgroupName = cgiEnv.GetId() cgroupNode = survol_cgroup.MakeUri(cgroupName) propCGroup = lib_common.MakeProp("cgroup") # This file contains all processes belonging to this cgroup. # Example "/sys/fs/cgroup/cpuset/cgroup.procs" # Read access might be forbidden. filNamCGroup = "/sys/fs/cgroup/%s/cgroup.procs" % cgroupName try: for lin_cg in open(filNamCGroup): procId = int(lin_cg) procNode = lib_uris.gUriGen.PidUri(procId) grph.add( ( cgroupNode, propCGroup, procNode ) ) except: logging.error("Invalid cgroup:%s",cgroupName) lib_common.ErrorMessageHtml("Invalid cgroup:%s"%cgroupName) # This lists processes in a table instead of scattered nodes. # This is because there might be a lot of processes. cgiEnv.OutCgiRdf("LAYOUT_RECT", [propCGroup] )
def Main(): cgiEnv = lib_common.ScriptEnvironment() pid = int(cgiEnv.GetId()) grph = cgiEnv.GetGraph() proc_obj = CIM_Process.PsutilGetProcObj(pid) #[pconn(fd=115, family=2, type=1, laddr=('10.0.0.1', 48776), raddr=('93.186.135.91', 80), status='ESTABLISHED'), # pconn(fd=117, family=2, type=1, laddr=('10.0.0.1', 43761), raddr=('72.14.234.100', 80), status='CLOSING'), # pconn(fd=119, family=2, type=1, laddr=('10.0.0.1', 60759), raddr=('72.14.234.104', 80), status='ESTABLISHED'), node_process = lib_uris.gUriGen.PidUri(pid) try: connects = CIM_Process.PsutilProcConnections(proc_obj, 'all') except Exception: # Version 3.2.2 at least. try: connects = proc_obj.connections('all') except Exception as exc: lib_common.ErrorMessageHtml("Error:" + str(exc)) survol_addr.PsutilAddSocketToGraph(node_process, connects, grph) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() file_shared_lib = cgiEnv.GetId() if not lib_util.isPlatformLinux: lib_common.ErrorMessageHtml("LDD on Linux platform only") grph = cgiEnv.GetGraph() # Maybe the file does not contain its path so it must be added. if file_shared_lib[0] != '/': file_shared_lib = os.getcwd() + '/' + file_shared_lib node_shared_lib = lib_uris.gUriGen.SharedLibUri(file_shared_lib) CIM_DataFile.AddInfo(grph, node_shared_lib, [file_shared_lib]) stream = os.popen("ldd " + file_shared_lib) # Line read are such as: # linux-gate.so.1 => (0xffffe000) # libdl.so.2 => /lib/libdl.so.2 (0xb7dae000) # libc.so.6 => /lib/i686/libc.so.6 (0xb7c6a000) # /lib/ld-linux.so.2 (0x80000000) # Do not know what to do with the lines without an arrow. # Do not know what happens if a library name contains a space. rgx = re.compile(r'^.*=> *([^ ]+) \(') for line in stream: match_obj = re.match(rgx, line) if match_obj: AddDepends(grph, node_shared_lib, match_obj.group(1)) # The dependencies are flattened which may be is a mistake. cgiEnv.OutCgiRdf("LAYOUT_RECT")
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, parameters={lib_util.paramkeyShowAll: False}) entity_id = cgiEnv.m_entity_id entity_host = cgiEnv.GetHost() flag_show_all = int(cgiEnv.get_parameters(lib_util.paramkeyShowAll)) name_space, entity_type = cgiEnv.get_namespace_type() if lib_util.is_local_address(entity_host): entity_host = "" logging.debug("entity: entity_host=%s entity_type=%s entity_id=%s", entity_host, entity_type, entity_id) grph = cgiEnv.GetGraph() root_node = lib_util.RootUri() if entity_id != "" or entity_type == "": def callback_grph_add(tripl, depth_call): grph.add(tripl) recursive_walk_on_scripts(callback_grph_add, root_node, entity_type, entity_id, entity_host, flag_show_all) cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_directory, pc.property_script])
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 main_events(): # TODO: The delay could be a parameter. vmstat_cmd = [ "vmstat", "1", ] cgiEnv = lib_common.ScriptEnvironment() logging.debug(__file__ + " Events Starting process:%s" % str(vmstat_cmd)) Main.proc_popen = subprocess.Popen(vmstat_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) logging.debug(__file__ + " Events Started") line_counter = 0 while True: current_line = Main.proc_popen.stdout.readline() logging.debug(__file__ + " Events Read:%s" % current_line) line_counter += 1 if line_counter == 1: continue if line_counter == 2: # Contains the last header read. vmstat_header = current_line continue if not current_line: continue _vmstat_to_graph(cgiEnv, vmstat_header, current_line)
def Main(): cgiEnv = lib_common.ScriptEnvironment() pid = int(cgiEnv.GetId()) grph = cgiEnv.GetGraph() proc_obj = CIM_Process.PsutilGetProcObj(pid) node_process = lib_uris.gUriGen.PidUri(pid) try: all_maps = proc_obj.memory_maps() except Exception as exc: lib_common.ErrorMessageHtml("get_memory_maps Pid=%d. Caught %s\n" % (pid, str(exc))) propMemoryRSS = lib_common.MakeProp("Resident Set Size") for map_obj in all_maps: # This, because all Windows paths are "standardized" by us. # TODO: clean_map_path = lib_util.standardized_file_path(map_obj.path) clean_map_path = map_obj.path.replace("\\", "/") uri_mem_map = lib_uris.gUriGen.MemMapUri(clean_map_path) grph.add((uri_mem_map, propMemoryRSS, rdflib.Literal(map_obj.rss))) grph.add((node_process, pc.property_memmap, uri_mem_map)) cgiEnv.OutCgiRdf( "LAYOUT_SPLINE")
def Main(): cgiEnv = lib_common.ScriptEnvironment() entity_id = cgiEnv.m_entity_id name_space, entity_type = cgiEnv.get_namespace_type() grph = cgiEnv.GetGraph() root_node = lib_util.RootUri() entity_ids_arr = lib_util.EntityIdToArray(entity_type, entity_id) mode_disp = lib_util.GuessDisplayMode() logging.debug("entity_type=%s mode_disp=%s", entity_type, mode_disp) if not entity_type: lib_common.ErrorMessageHtml("entity_mime.py needs an object") entity_module = lib_util.GetEntityModule(entity_type) if not entity_module: lib_common.ErrorMessageHtml( "entity_mime.py entity_type=%s needs a module" % entity_type) try: entity_module.DisplayAsMime(grph, root_node, entity_ids_arr) except Exception as exc: lib_common.ErrorMessageHtml( __file__ + " DisplayAsMime fails: %s %s: %s. File=%s.\n" % (entity_type, entity_id, str(exc), entity_module.__file__))
def Main(): cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True) entity_host = cgiEnv.GetHost() logging.debug("entity_host=%s", entity_host) entity_host = lib_wmi.NormalHostName(entity_host) cimom_url = entity_host logging.debug("cimom_url=%s", cimom_url) grph = cgiEnv.GetGraph() # There is no consensus on the WMI class for namespaces, # so we have ours which must be correctly mapped. namespace_class = "wmi_namespace" # root_node = lib_util.EntityUri(namespace_class,"") root_node = lib_util.EntityUri(namespace_class) for nskey in _hardcoded_namespaces: # _sub_namespace( root_node, grph, nskey ) try: # "root\\" + # _sub_namespace( root_node, grph, nskey, cimom_url ) _sub_namespace(root_node, grph, nskey, cimom_url) except Exception as exc: lib_common.ErrorMessageHtml("namespaces_wmi.py cimom_url=%s nskey=%s Caught:%s" % ( cimom_url, nskey , str(exc) ) ) cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_cim_subnamespace])
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) subscriptionNode = subscription.MakeUri(subscription_name) try: # This throws when running with Apache. OK with cgiserver.py lst_locations = sms.list_locations() except Exception as exc: lib_common.ErrorMessageHtml("Unexpected error:" + str(exc)) result = lst_locations for loca in result: locaNode = location.MakeUri(loca.name, subscription_name) grph.add((subscriptionNode, lib_common.MakeProp("Location"), locaNode)) cgiEnv.OutCgiRdf()
def Main(): cgiEnv = lib_common.ScriptEnvironment() table_name = cgiEnv.m_entity_id_dict["Table"] db_fil_nam = cgiEnv.m_entity_id_dict["File"] grph = cgiEnv.GetGraph() fil_node = lib_uris.gUriGen.FileUri(db_fil_nam) tab_nod = sqlite_table.MakeUri(db_fil_nam, table_name) grph.add((tab_nod, lib_common.MakeProp("Table"), fil_node)) con = sqlite3.connect(db_fil_nam) cursor = con.cursor() #>>> eta = curs.execute("PRAGMA table_info('tz_data')") #(0, u'tzid', u'TEXT', 0, None, 0) #(1, u'alias', u'TEXT', 0, None, 0) try: cursor.execute("PRAGMA table_info('%s')" % table_name) prop_column = lib_common.MakeProp("Column") prop_type = lib_common.MakeProp("Type") for the_row in cursor.fetchall(): column_nam = the_row[1] column_nod = sqlite_column.MakeUri(db_fil_nam, table_name, column_nam) grph.add((tab_nod, prop_column, column_nod)) type_nam = the_row[2] grph.add((column_nod, prop_type, lib_util.NodeLiteral(type_nam))) except Exception as exc: lib_common.ErrorMessageHtml("Error %s:%s" % (db_fil_nam, str(exc))) cgiEnv.OutCgiRdf("LAYOUT_RECT", [prop_column])
def Main(): cgiEnv = lib_common.ScriptEnvironment() pid_int = int(cgiEnv.GetId()) grph = cgiEnv.GetGraph() node_process = lib_uris.gUriGen.PidUri(pid_int) jmx_data = survol_java.GetJavaDataFromJmx(pid_int) try: jmx_data_m_beans = jmx_data["allMBeans"] except KeyError: jmx_data_m_beans = [] prop_m_bean = lib_common.MakeProp("MBean") for jmx_m_bean in jmx_data_m_beans: cls_nam = jmx_m_bean["className"] obj_nam = jmx_m_bean["objectName"] # "=sun.management.ManagementFactoryHelper$1[java.nio:type=BufferPool,name=mapped]" logging.debug("jmx_m_bean=%s", jmx_m_bean) # Not sure about the file name node_class = survol_mbean.MakeUri(pid_int, obj_nam) grph.add((node_class, lib_common.MakeProp("Class name"), lib_util.NodeLiteral(cls_nam))) grph.add((node_process, prop_m_bean, node_class)) cgiEnv.OutCgiRdf("LAYOUT_RECT", [prop_m_bean])
def Main(): paramkey_recursive = "Recursive exploration" paramkey_explode_classes = "Explode classes members" cgiEnv = lib_common.ScriptEnvironment(parameters={ paramkey_recursive: False, paramkey_explode_classes: False }) param_explode_classes = int( cgiEnv.get_parameters(paramkey_explode_classes)) file_param = cgiEnv.GetId() grph = cgiEnv.GetGraph() objects_by_location = lib_doxygen.DoxygenMain(False, file_param) directory_name = os.path.dirname(file_param) root_node = lib_uris.gUriGen.FileUri(file_param) lib_doxygen.CreateObjs(grph, root_node, directory_name, objects_by_location, param_explode_classes) # TODO: THE GENERATED GRAPH SHOULD BE MORE SIMILAR TO DOXYGEN'S. cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_symbol_defined, pc.property_member])
def Main(): paramkey_max_depth = "Maximum depth" paramkey_disp_packages = "Display packages" paramkey_disp_files = "Display files" cgiEnv = lib_common.ScriptEnvironment({ paramkey_max_depth: 1, paramkey_disp_packages: True, paramkey_disp_files: False }) max_depth = cgiEnv.get_parameters(paramkey_max_depth) disp_packages = cgiEnv.get_parameters(paramkey_disp_packages) disp_files = cgiEnv.get_parameters(paramkey_disp_files) py_fil_nam = cgiEnv.GetId() grph = cgiEnv.GetGraph() fil_node = lib_uris.gUriGen.FileUri(py_fil_nam) try: survol_python.AddAssociatedFiles(grph, fil_node, py_fil_nam) survol_python_package.AddImportedModules(grph, fil_node, py_fil_nam, max_depth, disp_packages, disp_files) except Exception as exc: lib_common.ErrorMessageHtml("File:%s Unexpected error:%s" % (py_fil_nam, str(exc))) cgiEnv.OutCgiRdf("LAYOUT_SPLINE")
def Main(): cgiEnv = lib_common.ScriptEnvironment() grph = cgiEnv.GetGraph() try: num = 0 while True: try: # DO NOT close handle. # (<class 'pywintypes.error'>, error(6, 'RegQueryInfoKey', 'The handle is invalid.') key_name = win32api.RegEnumKey( lib_com_type_lib.TypeLibRegistryKey, num) except win32api.error as exc: logging.warning("RegEnumKey CAUGHT:%s", str(exc)) break versions = lib_com_type_lib.ComKeyAllNameVersion( lib_com_type_lib.TypeLibRegistryKey, key_name) # Name of the last version. best_typ_lib_name, best_version = lib_com_type_lib.ComKeyLastName( versions) # The name will be awful. First we must experiment a bit. lib_com_type_lib.CreateComRegisteredTypeLibNode( grph, key_name, best_typ_lib_name, best_version) num = num + 1 finally: # This avoids: error(6, 'RegQueryInfoKey', 'The handle is invalid.') logging.error("DO NOT close handle") # win32api.RegCloseKey(lib_com_type_lib.TypeLibRegistryKey cgiEnv.OutCgiRdf()