Exemple #1
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])
Exemple #2
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()
Exemple #3
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()