Esempio n. 1
0
def Main():
    cgiEnv = lib_common.CgiEnv()

    grph = cgiEnv.GetGraph()

    dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv)
    sessionId = cgiEnv.m_entity_id_dict["SessionId"]

    DEBUG("dsn=(%s) sessionId=%s", dsnNam, sessionId)

    nodeSession = survol_sqlserver_dsn.MakeUri(dsnNam)

    ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam)
    try:
        cnxn = pyodbc.connect(ODBC_ConnectString)
        DEBUG("Connected: %s", dsnNam)

        grph.add((nodeSession, lib_common.MakeProp("Session id"),
                  lib_common.NodeLiteral(sessionId)))
        GetInfoConnections(grph, sessionId, nodeSession, cnxn)
        GetInfoSessions(grph, sessionId, nodeSession, cnxn)
        GetInfoRequests(grph, sessionId, nodeSession, cnxn, dsnNam)

    except Exception:
        exc = sys.exc_info()[0]
        lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" %
                                    (dsnNam, str(sys.exc_info())))

    cgiEnv.OutCgiRdf()
Esempio n. 2
0
def Main():

    cgiEnv = lib_common.CgiEnv()

    grph = cgiEnv.GetGraph()

    dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv)

    DEBUG("dsn=(%s)", dsnNam)

    nodeDsn = survol_odbc_dsn.MakeUri(dsnNam)

    ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam)

    try:
        cnxn = pyodbc.connect(ODBC_ConnectString)
        DEBUG("Connected: %s", dsnNam)

        # for prmstr in sqlgetinfo_params:
        for prmstr in dir(pyodbc):
            if not prmstr.startswith("SQL_"):
                continue
            #sys.stderr.write("prmstr: %s\n" % prmstr)

            # Some keywords are not interesting. This is a bit arbitrary.
            if prmstr in ["SQL_KEYWORDS"]:
                continue

            nicestr = prmstr[4:].replace("_", " ").capitalize()

            prop = lib_common.MakeProp(nicestr)

            try:
                prm = getattr(pyodbc, prmstr)
            # except AttributeError:
            except:
                grph.add(
                    (nodeDsn, prop, lib_common.NodeLiteral("Unavailable")))
                continue

            try:
                prm_value = cnxn.getinfo(prm)
            except:
                #txt = str( sys.exc_info()[1] )
                #grph.add( (nodeDsn, prop, lib_common.NodeLiteral(txt) ) )
                continue

            try:
                grph.add((nodeDsn, prop, lib_common.NodeLiteral(prm_value)))
            except:
                txt = str(sys.exc_info()[1])
                grph.add((nodeDsn, prop, lib_common.NodeLiteral(txt)))
                continue

    except Exception:
        exc = sys.exc_info()[0]
        lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" %
                                    (dsnNam, str(sys.exc_info())))

    cgiEnv.OutCgiRdf()
Esempio n. 3
0
def Main():
	cgiEnv = lib_common.CgiEnv()

	grph = cgiEnv.GetGraph()

	dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv)

	DEBUG("dsn=(%s)", dsnNam)

	nodeDsn = survol_sqlserver_dsn.MakeUri(dsnNam)

	ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam)
	try:
		cnxn = pyodbc.connect(ODBC_ConnectString)
		DEBUG("Connected: %s", dsnNam)
		cursorSessions = cnxn.cursor()

		qrySessions = """
		SELECT host_name,host_process_id,session_id,program_name,client_interface_name,original_login_name,nt_domain,nt_user_name
		FROM sys.dm_exec_sessions
		"""

		propSqlServerSession = lib_common.MakeProp("SqlServer session")
		propSqlServerHostProcess = lib_common.MakeProp("Host process")
		propSqlServerProgramName = lib_common.MakeProp("Program name")
		propSqlServerClientInterface = lib_common.MakeProp("Client Interface")

		propSqlServerOriginalLoginName = lib_common.MakeProp("original_login_name")
		propSqlServerNTDomain = lib_common.MakeProp("nt_domain")
		propSqlServerNTUserName = lib_common.MakeProp("nt_user_name")

		for rowSess in cursorSessions.execute(qrySessions):
			DEBUG("rowSess.session_id=(%s)", rowSess.session_id)
			nodeSession = session.MakeUri(dsnNam, rowSess.session_id)
			grph.add((nodeDsn, propSqlServerSession, nodeSession))

			if rowSess.host_process_id:
				node_process = lib_common.RemoteBox(rowSess.host_name).PidUri(rowSess.host_process_id)
				grph.add((node_process, pc.property_pid, lib_common.NodeLiteral(rowSess.host_process_id)))
				grph.add((nodeSession, propSqlServerHostProcess, node_process))

			if rowSess.program_name:
				grph.add((nodeSession, propSqlServerProgramName, lib_common.NodeLiteral(rowSess.program_name)))
			if rowSess.client_interface_name:
				grph.add((nodeSession, propSqlServerClientInterface, lib_common.NodeLiteral(rowSess.client_interface_name)))

			# TODO: Make nodes with these:
			if rowSess.original_login_name:
				grph.add((nodeSession, propSqlServerOriginalLoginName, lib_common.NodeLiteral(rowSess.original_login_name)))
			if rowSess.nt_domain:
				grph.add((nodeSession, propSqlServerNTDomain, lib_common.NodeLiteral(rowSess.nt_domain)))
			if rowSess.nt_user_name:
				grph.add((nodeSession, propSqlServerNTUserName, lib_common.NodeLiteral(rowSess.nt_user_name)))

	except Exception:
		exc = sys.exc_info()[0]
		lib_common.ErrorMessageHtml(
			"nodeDsn=%s Unexpected error:%s" % (dsnNam, str(sys.exc_info())))  # cgiEnv.OutCgiRdf()

	cgiEnv.OutCgiRdf("LAYOUT_RECT",[propSqlServerSession,propSqlServerHostProcess])
def Main():
    cgiEnv = lib_common.ScriptEnvironment()

    grph = cgiEnv.GetGraph()

    dsn_nam = cgiEnv.m_entity_id_dict["Dsn"]
    session_id = cgiEnv.m_entity_id_dict["SessionId"]

    logging.debug("dsn=(%s) session_id=%s", dsn_nam, session_id)

    node_session = survol_sqlserver_dsn.MakeUri(dsn_nam)

    ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsn_nam)
    try:
        cnxn = pyodbc.connect(ODBC_ConnectString)
        logging.debug("Connected: %s", dsn_nam)

        grph.add((node_session, lib_common.MakeProp("Session id"),
                  lib_util.NodeLiteral(session_id)))
        _get_info_connections(grph, session_id, node_session, cnxn)
        _get_info_sessions(grph, session_id, node_session, cnxn)
        _get_info_requests(grph, session_id, node_session, cnxn, dsn_nam)

    except Exception as exc:
        lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" %
                                    (dsn_nam, str(exc)))

    cgiEnv.OutCgiRdf()
Esempio n. 5
0
def Main():
    cgiEnv = lib_common.CgiEnv()

    grph = cgiEnv.GetGraph()

    dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv)

    sys.stderr.write("dsn=(%s)\n" % dsnNam)

    nodeDsn = survol_sqlserver_dsn.MakeUri(dsnNam)

    ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam)
    try:
        cnxn = pyodbc.connect(ODBC_ConnectString)
        sys.stderr.write("Connected: %s\n" % dsnNam)
        cursorQueries = cnxn.cursor()

        qryQueries = """
			SELECT sqltext.TEXT,
			req.session_id,
			req.status,
			sess.host_process_id,
			sess.host_name
			FROM sys.dm_exec_requests req
			CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext
			, sys.dm_exec_sessions sess
			where sess.session_id = req.session_id
		"""

        propSqlServerSqlQuery = lib_common.MakeProp("Sql query")
        propSqlServerHostProcess = lib_common.MakeProp("Host process")
        propSqlServerStatus = lib_common.MakeProp("Status")

        for rowQry in cursorQueries.execute(qryQueries):
            sys.stderr.write("rowQry.session_id=(%s)\n" % rowQry.session_id)
            nodeSession = session.MakeUri(dsnNam, rowQry.session_id)

            # A bit of cleanup.
            queryClean = rowQry.TEXT.replace("\n", " ").strip()

            # TODO: Must add connection information so we can go from the tables to sqlserver itself.
            nodeSqlQuery = sql_query.MakeUri(queryClean, dsnNam)
            grph.add((nodeSession, propSqlServerSqlQuery, nodeSqlQuery))
            node_process = lib_common.RemoteBox(rowQry.host_name).PidUri(
                rowQry.host_process_id)
            grph.add((node_process, pc.property_pid,
                      lib_common.NodeLiteral(rowQry.host_process_id)))

            grph.add((nodeSession, propSqlServerHostProcess, node_process))
            grph.add((nodeSession, propSqlServerStatus,
                      lib_common.NodeLiteral(rowQry.status)))

    except Exception:
        exc = sys.exc_info()[0]
        lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" %
                                    (dsnNam, str(sys.exc_info())))

    cgiEnv.OutCgiRdf()
Esempio n. 6
0
def Main():
    cgiEnv = lib_common.CgiEnv()

    grph = cgiEnv.GetGraph()

    dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv)

    DEBUG("dsn=(%s)", dsnNam)

    nodeDsn = survol_odbc_dsn.MakeUri(dsnNam)

    ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam)

    try:
        cnxn = pyodbc.connect(ODBC_ConnectString)
        DEBUG("Connected: %s", dsnNam)
        cursor = cnxn.cursor()

        # http://pyodbc.googlecode.com/git/web/docs.html
        # colList = ( "Catalog", "Schema", "Procedure", "Inputs", "Outputs", "Result", "Remarks", "Type")

        # http://pyodbc.googlecode.com/git/web/docs.html
        # Type: 'TABLE','VIEW','SYSTEM TABLE','GLOBAL TEMPORARY','LOCAL TEMPORARY','ALIAS','SYNONYM',
        # or a data source-specific type name.
        mapIndexToProp = {
            #0: pc.property_odbc_catalog,
            #1: pc.property_odbc_schema,
            #2: pc.property_odbc_procedure,
            3: pc.property_odbc_inputs,
            4: pc.property_odbc_outputs,
            5: pc.property_odbc_result,
            6: pc.property_odbc_remarks,
            7: pc.property_odbc_type
        }

        # This avoids cursor.fetchall()
        for row in cursor.procedures():
            # TODO: What are the other properties ??
            procNam = row[2]
            # sys.stderr.write("tabNam=%s\n" % tabNam)

            nodProc = survol_odbc_procedure.MakeUri(dsnNam, procNam)
            grph.add((nodeDsn, pc.property_odbc_procedure, nodProc))

            # This prints only some columns.
            for idxCol in mapIndexToProp:
                predicateNode = mapIndexToProp[idxCol]
                grph.add((nodProc, predicateNode,
                          lib_common.NodeLiteral(row[idxCol])))

    except Exception:
        exc = sys.exc_info()[0]
        lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" %
                                    (dsnNam, str(sys.exc_info())))

    # cgiEnv.OutCgiRdf()
    cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_odbc_procedure])
Esempio n. 7
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()

    grph = cgiEnv.GetGraph()

    dsn_nam = cgiEnv.m_entity_id_dict["Dsn"]

    logging.debug("dsn=(%s)", dsn_nam)

    odbc_connect_string = survol_odbc_dsn.MakeOdbcConnectionString(dsn_nam)
    try:
        cnxn = pyodbc.connect(odbc_connect_string)
        logging.debug("Connected: %s", dsn_nam)
        cursor_queries = cnxn.cursor()

        qry_queries = """
            SELECT sqltext.TEXT,
            req.session_id,
            req.status,
            sess.host_process_id,
            sess.host_name
            FROM sys.dm_exec_requests req
            CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext
            , sys.dm_exec_sessions sess
            where sess.session_id = req.session_id
        """

        prop_sql_server_sql_query = lib_common.MakeProp("Sql query")
        prop_sql_server_host_process = lib_common.MakeProp("Host process")
        prop_sql_server_status = lib_common.MakeProp("Status")

        for row_qry in cursor_queries.execute(qry_queries):
            logging.debug("row_qry.session_id=(%s)", row_qry.session_id)
            node_session = session.MakeUri(dsn_nam, row_qry.session_id)

            # A bit of cleanup.
            query_clean = row_qry.TEXT.replace("\n", " ").strip()

            # TODO: Must add connection information so we can go from the tables to sqlserver itself.
            node_sql_query = sql_query_module.MakeUri(query_clean, dsn_nam)
            grph.add((node_session, prop_sql_server_sql_query, node_sql_query))
            node_process = lib_common.RemoteBox(row_qry.host_name).PidUri(
                row_qry.host_process_id)
            grph.add((node_process, pc.property_pid,
                      lib_util.NodeLiteral(row_qry.host_process_id)))

            grph.add(
                (node_session, prop_sql_server_host_process, node_process))
            grph.add((node_session, prop_sql_server_status,
                      lib_util.NodeLiteral(row_qry.status)))

    except Exception as exc:
        lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" %
                                    (dsn_nam, str(exc)))

    cgiEnv.OutCgiRdf()
def Main():
    cgiEnv = lib_common.ScriptEnvironment()

    grph = cgiEnv.GetGraph()

    dsn_nam = cgiEnv.m_entity_id_dict["Dsn"]

    logging.debug("dsn=(%s)", dsn_nam)

    node_dsn = survol_sqlserver_dsn.MakeUri(dsn_nam)

    ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsn_nam)
    try:
        cnxn = pyodbc.connect(ODBC_ConnectString)
        logging.debug("Connected: %s", dsn_nam)
        cursor_sessions = cnxn.cursor()

        qry_sessions = """
        SELECT host_name,host_process_id,session_id,program_name,client_interface_name,original_login_name,nt_domain,nt_user_name
        FROM sys.dm_exec_sessions where host_process_id is not null
        """

        prop_sql_server_session = lib_common.MakeProp("SqlServer session")
        prop_sql_server_host_process = lib_common.MakeProp("Host process")
        prop_sql_server_program_name = lib_common.MakeProp("Program name")
        prop_sql_server_client_interface = lib_common.MakeProp("Client Interface")

        prop_sql_server_original_login_name = lib_common.MakeProp("original_login_name")
        prop_sql_server_nt_domain = lib_common.MakeProp("nt_domain")
        prop_sql_server_nt_user_name = lib_common.MakeProp("nt_user_name")

        for row_sess in cursor_sessions.execute(qry_sessions):
            logging.debug("row_sess.session_id=(%s)", row_sess.session_id)
            node_session = session.MakeUri(dsn_nam, row_sess.session_id)
            grph.add((node_dsn, prop_sql_server_session, node_session))

            node_process = lib_common.RemoteBox(row_sess.host_name).PidUri(row_sess.host_process_id)
            grph.add((node_process, pc.property_pid, lib_util.NodeLiteral(row_sess.host_process_id)))

            grph.add((node_session, prop_sql_server_host_process, node_process))
            grph.add((node_session, prop_sql_server_program_name, lib_util.NodeLiteral(row_sess.program_name)))
            grph.add((node_session, prop_sql_server_client_interface, lib_util.NodeLiteral(row_sess.client_interface_name)))

            # TODO: Make nodes with these:

            grph.add(
                (node_session, prop_sql_server_original_login_name, lib_util.NodeLiteral(row_sess.original_login_name)))
            grph.add((node_session, prop_sql_server_nt_domain, lib_util.NodeLiteral(row_sess.nt_domain)))
            grph.add((node_session, prop_sql_server_nt_user_name, lib_util.NodeLiteral(row_sess.nt_user_name)))

    except Exception as exc:
        lib_common.ErrorMessageHtml(
            "node_dsn=%s Unexpected error:%s" % (dsn_nam, str(exc)))

    cgiEnv.OutCgiRdf()
Esempio n. 9
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment()

    grph = cgiEnv.GetGraph()

    dsn_nam = cgiEnv.m_entity_id_dict["Dsn"]

    logging.debug("dsn=(%s)", dsn_nam)

    node_dsn = survol_odbc_dsn.MakeUri(dsn_nam)

    odbc_connect_string = survol_odbc_dsn.MakeOdbcConnectionString(dsn_nam)

    try:
        cnxn = pyodbc.connect(odbc_connect_string)
        logging.debug("Connected: %s", dsn_nam)
        cursor = cnxn.cursor()

        # http://pyodbc.googlecode.com/git/web/docs.html
        # colList = ( "Catalog", "Schema", "Procedure", "Inputs", "Outputs", "Result", "Remarks", "Type")

        # http://pyodbc.googlecode.com/git/web/docs.html
        # Type: 'TABLE','VIEW','SYSTEM TABLE','GLOBAL TEMPORARY','LOCAL TEMPORARY','ALIAS','SYNONYM',
        # or a data source-specific type name.
        map_index_to_prop = {
            #0: pc.property_odbc_catalog,
            #1: pc.property_odbc_schema,
            #2: pc.property_odbc_procedure,
            3: pc.property_odbc_inputs,
            4: pc.property_odbc_outputs,
            5: pc.property_odbc_result,
            6: pc.property_odbc_remarks,
            7: pc.property_odbc_type
        }

        # This avoids cursor.fetchall()
        for row in cursor.procedures():
            # TODO: What are the other properties ??
            proc_nam = row[2]

            nod_proc = survol_odbc_procedure.MakeUri(dsn_nam, proc_nam)
            grph.add((node_dsn, pc.property_odbc_procedure, nod_proc))

            # This prints only some columns.
            for idxcol in map_index_to_prop:
                predicate_node = map_index_to_prop[idxcol]
                grph.add((nod_proc, predicate_node,
                          lib_util.NodeLiteral(row[idxcol])))

    except Exception as exc:
        lib_common.ErrorMessageHtml("node_dsn=%s Unexpected error:%s" %
                                    (dsn_nam, str(exc)))

    cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_odbc_procedure])
Esempio n. 10
0
def Main():

    cgiEnv = lib_common.ScriptEnvironment()

    grph = cgiEnv.GetGraph()

    dsn_nam = cgiEnv.m_entity_id_dict["Dsn"]

    logging.debug("dsn=(%s)", dsn_nam)

    node_dsn = survol_odbc_dsn.MakeUri(dsn_nam)

    odbc_connect_string = survol_odbc_dsn.MakeOdbcConnectionString(dsn_nam)

    try:
        cnxn = pyodbc.connect(odbc_connect_string)
        logging.debug("Connected: %s", dsn_nam)

        for prmstr in dir(pyodbc):
            if not prmstr.startswith("SQL_"):
                continue

            # Some keywords are not interesting. This is a bit arbitrary.
            if prmstr in ["SQL_KEYWORDS"]:
                continue

            nicestr = prmstr[4:].replace("_", " ").capitalize()

            prop = lib_common.MakeProp(nicestr)

            try:
                prm = getattr(pyodbc, prmstr)
            except:
                grph.add((node_dsn, prop, lib_util.NodeLiteral("Unavailable")))
                continue

            try:
                prm_value = cnxn.getinfo(prm)
            except:
                continue

            try:
                grph.add((node_dsn, prop, lib_util.NodeLiteral(prm_value)))
            except Exception as exc:
                txt = str(exc)
                grph.add((node_dsn, prop, lib_util.NodeLiteral(txt)))
                continue

    except Exception as exc:
        lib_common.ErrorMessageHtml("node_dsn=%s Unexpected error:%s" %
                                    (dsn_nam, str(exc)))

    cgiEnv.OutCgiRdf()
Esempio n. 11
0
def AddInfo(grph, node, entity_ids_arr):
    dsnNam = lib_util.six_u(entity_ids_arr[0])
    sessionId = lib_util.six_u(entity_ids_arr[1])

    nodeDsn = survol_sqlserver_dsn.MakeUri(dsnNam)

    grph.add((nodeDsn, lib_common.MakeProp("DSN"), node))

    #session_id	most_recent_session_id	connect_time	net_transport	protocol_type	protocol_version	endpoint_id	encrypt_option	auth_scheme	node_affinity	num_reads	num_writes	last_read	last_write	net_packet_size	client_net_address	client_tcp_port	local_net_address	local_tcp_port	connection_id	parent_connection_id	most_recent_sql_handle
    #51	51	2016-10-05 22:39:24.080	Shared memory	TSQL	1946157060	2	FALSE	NTLM	0	13	13	2016-10-05 22:39:47.830	2016-10-05 22:39:47.847	4096	<local machine>	NULL	NULL	NULL	51D43D11-6A16-4E19-A253-0974EEDC634D	NULL	0x0200000016EF4D1B4BF65E91FF63A5D60122505E5DC8928000000000000000000000000000000000
    #52	52	2016-10-05 22:40:20.290	Shared memory	TSQL	1946157060	2	FALSE	NTLM	0	26	54	2016-10-11 23:28:00.727	2016-10-11 23:28:00.907	4096	<local machine>	NULL	NULL	NULL	853F7FC5-B1BD-4E06-8B3C-02E05EA0559E	NULL	0x0200000057662721C982D2FDEBFA2D0F498272D162E569C100000000000000000000000000000000
    #53	53	2016-10-07 08:14:12.107	TCP	TSQL	1946157060	4	FALSE	NTLM	0	14	17	2016-10-07 08:23:14.487	2016-10-07 08:23:14.490	4096	192.168.1.83	54982	192.168.1.83	1433	E79ECEF0-FBAF-4B79-8FB9-7591406EC1CF	NULL	0x02000000768991061E4A50B1FE93FC2F7ED994402142AE8C00000000000000000000000000000000
    #57	57	2016-10-08 17:33:40.710	TCP	TSQL	1895825409	4	FALSE	NTLM	0	5	5	2016-10-08 17:33:40.763	2016-10-08 17:33:40.767	4096	192.168.1.83	64542	192.168.1.83	1433	D49BC4D8-3EB1-4353-A5B2-DF738D9677AB	NULL	0x00000000000000000000000000000000000000000000000000000000000000000000000000000000	# 52	52	2016-10-05 22:40:20.290	Shared memory	TSQL	1946157060	2	FALSE	NTLM	0	23	43	2016-10-10 22:13:22.113	2016-10-10 22:13:38.230	4096	<local machine>	NULL	NULL	NULL	853F7FC5-B1BD-4E06-8B3C-02E05EA0559E	NULL	0x02000000A44FA72C19569D8EB73D9D9470A15C14F7CC6B4B00000000000000000000000000000000

    if pyodbcOk:
        ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam)
        cnxn = pyodbc.connect(ODBC_ConnectString)
        sys.stderr.write("Connected: %s\n" % dsnNam)
        cursorConnections = cnxn.cursor()

        qryConnections = """
		select net_transport, protocol_type,auth_scheme, connect_time,last_read,last_write,
		local_net_address,local_tcp_port,client_net_address,client_tcp_port
		from sys.dm_exec_connections where session_id=%s
		""" % sessionId

        for rowConnections in cursorConnections.execute(qryConnections):
            grph.add((node, lib_common.MakeProp("Net transport"),
                      lib_common.NodeLiteral(rowConnections.net_transport)))
            grph.add((node, lib_common.MakeProp("Protocol type"),
                      lib_common.NodeLiteral(rowConnections.protocol_type)))
            grph.add((node, lib_common.MakeProp("Auth scheme"),
                      lib_common.NodeLiteral(rowConnections.auth_scheme)))
            grph.add((node, lib_common.MakeProp("Connect time"),
                      lib_common.NodeLiteral(rowConnections.connect_time)))
            grph.add((node, lib_common.MakeProp("Last read"),
                      lib_common.NodeLiteral(rowConnections.last_read)))
            grph.add((node, lib_common.MakeProp("Last write"),
                      lib_common.NodeLiteral(rowConnections.last_write)))

            if rowConnections.net_transport == "TCP":
                lsocketNode = lib_common.gUriGen.AddrUri(
                    rowConnections.local_net_address,
                    rowConnections.local_tcp_port)
                rsocketNode = lib_common.gUriGen.AddrUri(
                    rowConnections.client_net_address,
                    rowConnections.client_tcp_port)
                grph.add((lsocketNode, pc.property_socket_end, rsocketNode))
                grph.add((node, pc.property_has_socket, lsocketNode))
Esempio n. 12
0
def Main():
    cgiEnv = lib_common.CgiEnv()

    grph = cgiEnv.GetGraph()

    dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv)

    DEBUG("dsn=(%s)", dsnNam )

    nodeDsn = survol_odbc_dsn.MakeUri( dsnNam )

    ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam)

    try:
        cnxn = pyodbc.connect(ODBC_ConnectString)
        DEBUG("Connected: %s", dsnNam)
        cursor = cnxn.cursor()

        # http://pyodbc.googlecode.com/git/web/docs.html
        # Type: 'TABLE','VIEW','SYSTEM TABLE','GLOBAL TEMPORARY','LOCAL TEMPORARY','ALIAS','SYNONYM',
        # or a data source-specific type name.
        mapIndexToProp = {
             0: pc.property_odbc_catalog,
             1: pc.property_odbc_schema,
             # 3: pc.property_odbc_table,
             3: pc.property_odbc_type }

        # This avoids cursor.fetchall()
        for row in cursor.tables():
            # TODO: What are the other properties ??
            tabNam = row.table_name

            nodTab = survol_odbc_table.MakeUri( dsnNam, tabNam )
            grph.add( (nodeDsn, pc.property_odbc_table, nodTab ) )

            # This prints only some columns.
            for idxCol in mapIndexToProp:
                predicateNode = mapIndexToProp[idxCol]
                grph.add( (nodTab, predicateNode, lib_common.NodeLiteral(row[idxCol]) ) )

    except Exception:
        WARNING("tabNam=%s", str(sys.exc_info()))
        exc = sys.exc_info()[0]
        lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" % ( dsnNam, str( sys.exc_info() ) ) )


    # cgiEnv.OutCgiRdf()
    cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_odbc_table] )
Esempio n. 13
0
def Main():
    cgiEnv = lib_common.CgiEnv()

    grph = cgiEnv.GetGraph()

    dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv)

    sys.stderr.write("dsn=(%s)\n" % dsnNam )

    nodeDsn = survol_odbc_dsn.MakeUri( dsnNam )

    ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam)

    try:
        cnxn = pyodbc.connect(ODBC_ConnectString)
        sys.stderr.write("Connected: %s\n" % dsnNam)
        cursor = cnxn.cursor()

        # http://pyodbc.googlecode.com/git/web/docs.html
        # Type: 'TABLE','VIEW','SYSTEM TABLE','GLOBAL TEMPORARY','LOCAL TEMPORARY','ALIAS','SYNONYM',
        # or a data source-specific type name.
        colList = ( "Catalog", "Schema", "Table", "Type")

        # This avoids cursor.fetchall()
        for row in cursor.tables():
            # TODO: What are the other properties ??
            tabNam = row.table_name
            # sys.stderr.write("tabNam=%s\n" % tabNam)

            nodTab = survol_odbc_table.MakeUri( dsnNam, tabNam )
            grph.add( (nodeDsn, pc.property_odbc_table, nodTab ) )

            for idxCol in ( 0, 1, 3):
                grph.add( (nodTab, lib_common.NodeLiteral(colList[idxCol]), lib_common.NodeLiteral(row[idxCol]) ) )

    except Exception:
        sys.stderr.write("tabNam=%s\n" % str(sys.exc_info()))
        exc = sys.exc_info()[0]
        lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" % ( dsnNam, str( sys.exc_info() ) ) )


    # cgiEnv.OutCgiRdf()
    cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_odbc_table] )
Esempio n. 14
0
def Main():
    cgiEnv = lib_common.CgiEnv()

    grph = cgiEnv.GetGraph()

    dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv)

    sys.stderr.write("dsn=(%s)\n" % dsnNam )

    nodeDsn = survol_odbc_dsn.MakeUri( dsnNam )

    ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam)

    try:
        cnxn = pyodbc.connect(ODBC_ConnectString)
        sys.stderr.write("Connected: %s\n" % dsnNam)
        cursor = cnxn.cursor()

        # http://pyodbc.googlecode.com/git/web/docs.html
        colList = ( "Catalog", "Schema", "Procedure", "Inputs", "Outputs", "Result", "Remarks", "Type")

        # This avoids cursor.fetchall()
        for row in cursor.procedures():
            # TODO: What are the other properties ??
            procNam = row[2]
            # sys.stderr.write("tabNam=%s\n" % tabNam)

            nodProc = survol_odbc_procedure.MakeUri( dsnNam, procNam )
            grph.add( (nodeDsn, pc.property_odbc_procedure, nodProc ) )

            for idxCol in (3, 4, 5, 6, 7):
                grph.add( (nodProc, lib_common.NodeLiteral(colList[idxCol]), lib_common.NodeLiteral(row[idxCol]) ) )

    except Exception:
        exc = sys.exc_info()[0]
        lib_common.ErrorMessageHtml("nodeDsn=%s Unexpected error:%s" % ( dsnNam, str( sys.exc_info() ) ) )


    # cgiEnv.OutCgiRdf()
    cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_odbc_procedure] )
Esempio n. 15
0
def Main():
    cgiEnv = lib_common.CgiEnv()

    grph = cgiEnv.GetGraph()

    dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv)
    tabNam = cgiEnv.m_entity_id_dict["Table"]

    DEBUG("dsn=%s tabNam=%s", dsnNam, tabNam)

    nodTab = survol_odbc_table.MakeUri(dsnNam, tabNam)

    # ('C:\\Program Files (x86)\\Microsoft Visual Studio 8\\Crystal Reports\\Samples\\en\\Databases\\xtreme', None, 'MSysAccessObjects', 'SYSTEM TABLE', None)

    ODBC_ConnectString = survol_odbc_dsn.MakeOdbcConnectionString(dsnNam)

    try:
        cnxn = pyodbc.connect(ODBC_ConnectString)
        DEBUG("Connected: %s", dsnNam)
        cursor = cnxn.cursor()

        cursor.columns(table=tabNam)
        DEBUG("Tables OK: %s", dsnNam)
        rows = cursor.fetchall()

        # http://pyodbc.googlecode.com/git/web/docs.html
        #
        # table_cat
        # table_schem
        # table_name
        # column_name
        # data_type
        # type_name
        # column_size
        # buffer_length
        # decimal_digits
        # num_prec_radix
        # nullable
        # remarks
        # column_def
        # sql_data_type
        # sql_datetime_sub
        # char_octet_length
        # ordinal_position
        # is_nullable: One of SQL_NULLABLE, SQL_NO_NULLS, SQL_NULLS_UNKNOWN.

        # or a data source-specific type name.
        colList = ("Catalog", "Schema", "Table", "Column", "Data type", "Type",
                   "Size", "Length", "Digits", "Radix", "Nullable", "Remarks",
                   "Column def", "Sql type", "Datetime sub",
                   "char octet length", "Ordinal", "is nullable")

        for row in rows:
            # TODO: What are the other properties ??
            tabNam = row.table_name
            # sys.stderr.write("tabNam=%s\n" % tabNam)

            nodColumn = survol_odbc_column.MakeUri(dsnNam, tabNam, row[3])
            grph.add((nodTab, pc.property_odbc_column, nodColumn))

            for idxCol in (5, 11, 12, 13, 17):
                # grph.add( (nodColumn, lib_common.NodeLiteral(colList[idxCol]), lib_common.NodeLiteral(row[idxCol]) ) )
                grph.add((nodColumn, lib_common.MakeProp(colList[idxCol]),
                          lib_common.NodeLiteral(row[idxCol])))

    except Exception:
        exc = sys.exc_info()[0]
        lib_common.ErrorMessageHtml("dsnNam=%s Unexpected error:%s" %
                                    (dsnNam, str(exc)))

    # cgiEnv.OutCgiRdf()
    cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_odbc_column])