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.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()
def AddInfo(grph,node,entity_ids_arr): dsnNam = entity_ids_arr[0] ODBC_ConnectString = MakeOdbcConnectionString(dsnNam) try: cnxn = pyodbc.connect(ODBC_ConnectString) except: exc = sys.exc_info()[1] grph.add( ( node, pc.property_information, lib_common.NodeLiteral(str(exc)) ) ) return dbEntityType = GetDatabaseEntityTypeFromConnection(cnxn) DEBUG("AddInfo dbEntityType=%s", dbEntityType ) if dbEntityType == "oracle": # For example "XE". server_name = cnxn.getinfo(pyodbc.SQL_SERVER_NAME) node_oradb = oracle_db.MakeUri( server_name ) grph.add( ( node, pc.property_oracle_db, node_oradb ) ) elif dbEntityType == "sqlserver": # We stick to the DSN because it encloses all the needed information. node_sqlserverdb = survol_sqlserver_dsn.MakeUri( dsnNam ) grph.add( ( node, pc.property_sqlserver_db, node_sqlserverdb ) ) DEBUG("AddInfo dbEntityType=%s ADDING NODE", dbEntityType )
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()
def AddInfo(grph, node, entity_ids_arr): """" This displays links to the Oracle database, not seen from ODBC, so we can have more specific queries. """ "" dsn_nam = entity_ids_arr[0] odbc_connect_string = MakeOdbcConnectionString(dsn_nam) try: cnxn = pyodbc.connect(odbc_connect_string) except Exception as exc: grph.add( (node, pc.property_information, lib_util.NodeLiteral(str(exc)))) return db_entity_type = GetDatabaseEntityTypeFromConnection(cnxn) logging.debug("AddInfo db_entity_type=%s", db_entity_type) if db_entity_type == "oracle": # For example "XE". server_name = cnxn.getinfo(pyodbc.SQL_SERVER_NAME) node_oradb = oracle_db.MakeUri(server_name) grph.add((node, pc.property_oracle_db, node_oradb)) elif db_entity_type == "sqlserver": # We stick to the DSN because it encloses all the needed information. node_sqlserverdb = survol_sqlserver_dsn.MakeUri(dsn_nam) grph.add((node, pc.property_sqlserver_db, node_sqlserverdb)) logging.debug("AddInfo db_entity_type=%s ADDING NODE", db_entity_type)
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()
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()
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))
def AddInfo(grph, node, entity_ids_arr): # strQuery = entity_ids_arr[0] theDsn = entity_ids_arr[1] nodeDsn = sqlserver_dsn.MakeUri(theDsn) grph.add((node, lib_common.MakeProp("Dsn"), nodeDsn))
def AddInfo(grph, node, entity_ids_arr): # TODO: Ca serait quand meme mieux de passer au AddInfo un dict plutot qu un tableau. dsnNam = entity_ids_arr[0] nodeDsn = sqlserver_dsn.MakeUri(dsnNam) grph.add((nodeDsn, lib_common.MakeProp("Sqlserver DSN"), node))
def AddInfo(grph, node, entity_ids_arr): dsn_nam = entity_ids_arr[0] node_dsn = sqlserver_dsn.MakeUri(dsn_nam) grph.add((node_dsn, lib_common.MakeProp("Sqlserver DSN"), node))