def Main(): cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() #pidNum = cgiEnv.m_entity_id_dict["Pid"] #filNam = cgiEnv.m_entity_id_dict["File"] #sqlQuery_encode = cgiEnv.m_entity_id_dict["Query"] # sqlQuery_encode = cgiEnv.GetId() # TODO: This should be packaged in sql/__init__.py. #sqlQuery = lib_util.Base64Decode(sqlQuery_encode) sqlQuery = sql_query.GetEnvArgs(cgiEnv) dsnNam = survol_odbc_dsn.GetDsnNameFromCgi(cgiEnv) nodeSqlQuery = sqlserver_query.MakeUri(sqlQuery, dsnNam) propSheetToQuery = lib_common.MakeProp("Table dependency") list_of_table_names = lib_sql.TableDependencies(sqlQuery) # Based on the pid and the filnam, find which database connection it is. # What is the schema ?? list_of_nodes = sqlserver_query.QueryToNodesList( sqlQuery, {"Dsn": dsnNam}, list_of_table_names, dsnNam + ":SqlServerSchema") for nodTab in list_of_nodes: grph.add((nodeSqlQuery, propSheetToQuery, nodTab)) cgiEnv.OutCgiRdf()
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) 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 _get_info_requests(grph, session_id, node_session, cnxn, dsn_nam): logging.debug("GetInfoRequests") cursor_requests = cnxn.cursor() # select sqltext.TEXT, status, command from sys.dm_exec_requests # CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext qry_requests = """ select sqltext.TEXT, status, command from sys.dm_exec_requests CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext where session_id=%s """ % session_id prop_sql_server_sql_query = lib_common.MakeProp("Sql query") # TODO: Very often, it does not display anything. for row_requests in cursor_requests.execute(qry_requests): grph.add((node_session, lib_common.MakeProp("Status"), lib_util.NodeLiteral(row_requests.status))) grph.add((node_session, lib_common.MakeProp("Command"), lib_util.NodeLiteral(row_requests.command))) node_sql_query = sqlserver_query.MakeUri(row_requests.TEXT, dsn_nam) grph.add((node_session, prop_sql_server_sql_query, node_sql_query))
def GetInfoRequests(grph, sessionId, nodeSession, cnxn, dsnNam): DEBUG("GetInfoRequests") cursorRequests = cnxn.cursor() # select sqltext.TEXT, status, command from sys.dm_exec_requests # CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext qryRequests = """ select sqltext.TEXT, status, command from sys.dm_exec_requests CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext where session_id=%s """ % sessionId propSqlServerSqlQuery = lib_common.MakeProp("Sql query") # TODO: Very often, it does not display anything. for rowRequests in cursorRequests.execute(qryRequests): grph.add((nodeSession, lib_common.MakeProp("Status"), lib_common.NodeLiteral(rowRequests.status))) grph.add((nodeSession, lib_common.MakeProp("Command"), lib_common.NodeLiteral(rowRequests.command))) # nodeSqlQuery = sql_query.MakeUri(rowRequests.TEXT,"sqlserver/query",{"Dsn":"Tralala"}) nodeSqlQuery = sqlserver_query.MakeUri(rowRequests.TEXT, dsnNam) grph.add((nodeSession, propSqlServerSqlQuery, nodeSqlQuery))