def Main(): cgiEnv = lib_common.CgiEnv( ) instanceName = cgiEnv.m_entity_id_dict["Instance"] instanceNode = survol_mysql_instance.MakeUri(instanceName) (hostname,hostport) = survol_mysql.InstanceToHostPort(instanceName) cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() hostAddr = lib_util.GlobalGetHostByName(hostname) # 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. hostNode = lib_common.gUriGen.HostnameUri(hostname) # BEWARE: This is duplicated. propDb = lib_common.MakeProp("Mysql database") aCred = lib_credentials.GetCredentials("MySql", instanceName) # If user/password incorrect, nothing we can do. try: aUser = aCred[0] connMysql = survol_mysql.MysqlConnect(instanceName,aUser,aPass=aCred[1]) except : exc = sys.exc_info() lib_common.ErrorMessageHtml("Cannot connect to instance=%s user=%s:%s"%(instanceName,aUser,str(exc))) cursorMysql = connMysql.cursor() cursorMysql.execute("show databases") propDb = lib_common.MakeProp("Mysql database") grph.add( ( hostNode, lib_common.MakeProp("Mysql instance"), instanceNode ) ) for dbInfo in cursorMysql: #('information_schema',) #('primhilltcsrvdb1',) sys.stderr.write("dbInfo=%s\n"%str(dbInfo)) dbNam = dbInfo[0] nodeMysqlDatabase = survol_mysql_database.MakeUri(instanceName,dbNam) # Create a node for each database. grph.add( ( nodeMysqlDatabase, pc.property_user, lib_common.NodeLiteral(aCred[0]) ) ) grph.add( ( instanceNode, propDb, nodeMysqlDatabase ) ) cursorMysql.close() connMysql.close() cgiEnv.OutCgiRdf("LAYOUT_SPLINE")
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.CgiEnv() instanceName = cgiEnv.m_entity_id_dict["Instance"] dbNam = cgiEnv.m_entity_id_dict["Database"] tableNam = cgiEnv.m_entity_id_dict["Table"] (hostname, hostport) = survol_mysql.InstanceToHostPort(instanceName) cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() hostAddr = lib_util.GlobalGetHostByName(hostname) # 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. hostNode = lib_common.gUriGen.HostnameUri(hostname) # BEWARE: This is duplicated. propDb = lib_common.MakeProp("Mysql database") nodeMysqlDatabase = survol_mysql_database.MakeUri(instanceName, dbNam) grph.add((hostNode, propDb, nodeMysqlDatabase)) aCred = lib_credentials.GetCredentials("MySql", instanceName) connMysql = survol_mysql.MysqlConnect(instanceName, aUser=aCred[0], aPass=aCred[1]) cursorMysql = connMysql.cursor() cursorMysql.execute( "select * from information_schema.TABLES where TABLE_SCHEMA='%s' and TABLE_NAME='%s'" % (dbNam.upper(), tableNam.upper())) propTable = lib_common.MakeProp("Mysql table") # >>> conn = MySQLdb.connect(user="******",passwd="?????",host="primhilltcsrvdb1.mysql.db") # >>> curs=conn.cursor() # >>> curs.execute("select * from information_schema.TABLES where TABLE_SCHEMA='primhilltcsrvdb1'") # >>> for x in curs: # TABLE_CATALOG def # TABLE_SCHEMA Table_... # TABLE_NAME Table_... # TABLE_TYPE # ENGINE Engine MySQL extension # VERSION Version The version number of the table's .frm file, MySQL extension # ROW_FORMAT Row_format MySQL extension # TABLE_ROWS Rows MySQL extension # AVG_ROW_LENGTH Avg_row_length MySQL extension # DATA_LENGTH Data_length MySQL extension # MAX_DATA_LENGTH Max_data_length MySQL extension # INDEX_LENGTH Index_length MySQL extension # DATA_FREE Data_free MySQL extension # AUTO_INCREMENT Auto_increment MySQL extension # CREATE_TIME Create_time MySQL extension # UPDATE_TIME Update_time MySQL extension # CHECK_TIME Check_time MySQL extension # TABLE_COLLATION Collation MySQL extension # CHECKSUM Checksum MySQL extension # CREATE_OPTIONS Create_options MySQL extension # TABLE_COMMENT Comment MySQL extension # ... print(x) # ( 'def', 'primhilltcsrvdb1', 'Test_Table', 'BASE TABLE', 'InnoDB', # 10L, 'Compact', 2L, 8192L, 16384L, # 0L, 0L, 0L, None, datetime.datetime(2017, 12, 13, 8, 59, 24), # None, None, 'latin1_swedish_ci', None, '', # 'Comment about this test table.') # There should be only one row, maximum. for tabInfo in cursorMysql: DEBUG("tabInfo=%s", str(tabInfo)) tableNam = tabInfo[2] nodeMysqlTable = survol_mysql_table.MakeUri(hostname, dbNam, tableNam) grph.add((nodeMysqlTable, lib_common.MakeProp("Table type"), lib_common.NodeLiteral(tabInfo[3]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Engine"), lib_common.NodeLiteral(tabInfo[4]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Version"), lib_common.NodeLiteral(tabInfo[5]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Row format"), lib_common.NodeLiteral(tabInfo[6]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Table rows"), lib_common.NodeLiteral(tabInfo[7]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Average row length"), lib_common.NodeLiteral(tabInfo[8]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Data length"), lib_common.NodeLiteral(tabInfo[9]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Maximum data length"), lib_common.NodeLiteral(tabInfo[10]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Index length"), lib_common.NodeLiteral(tabInfo[11]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Data free"), lib_common.NodeLiteral(tabInfo[12]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Auto increment"), lib_common.NodeLiteral(tabInfo[13]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Creation time"), lib_common.NodeLiteral(tabInfo[14]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Update time"), lib_common.NodeLiteral(tabInfo[15]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Check time"), lib_common.NodeLiteral(tabInfo[16]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Table collation"), lib_common.NodeLiteral(tabInfo[17]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Checksum"), lib_common.NodeLiteral(tabInfo[18]))) grph.add((nodeMysqlTable, lib_common.MakeProp("Create options"), lib_common.NodeLiteral(tabInfo[19]))) grph.add((nodeMysqlTable, pc.property_information, lib_common.NodeLiteral(tabInfo[20]))) grph.add((nodeMysqlDatabase, propTable, nodeMysqlTable)) cursorMysql.close() connMysql.close() cgiEnv.OutCgiRdf("LAYOUT_RECT_TB")
def Main(): cgiEnv = lib_common.CgiEnv() instanceName = cgiEnv.m_entity_id_dict["Instance"] dbNam = cgiEnv.m_entity_id_dict["Database"].upper() tableNam = cgiEnv.m_entity_id_dict["Table"].upper() (hostname, hostport) = survol_mysql.InstanceToHostPort(instanceName) cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() hostAddr = lib_util.GlobalGetHostByName(hostname) # 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. hostNode = lib_common.gUriGen.HostnameUri(hostname) # BEWARE: This is duplicated. propDb = lib_common.MakeProp("Mysql database") nodeMysqlDatabase = survol_mysql_database.MakeUri(instanceName, dbNam) grph.add((hostNode, propDb, nodeMysqlDatabase)) aCred = lib_credentials.GetCredentials("MySql", instanceName) propTable = lib_common.MakeProp("Mysql table") propConstraint = lib_common.MakeProp("Table type") connMysql = survol_mysql.MysqlConnect(instanceName, aUser=aCred[0], aPass=aCred[1]) cursorMysql = connMysql.cursor() cursorMysql.execute( "select TABLE_NAME, REFERENCED_TABLE_NAME from information_schema.referential_constraints" " where CONSTRAINT_SCHEMA='%s' " " and ( TABLE_NAME='%s' or REFERENCED_TABLE_NAME='%s' ) " % (dbNam, tableNam, tableNam)) # There should be only one row, maximum. for constraintInfo in cursorMysql: sys.stderr.write("constraintInfo=%s\n" % str(constraintInfo)) tableNam = constraintInfo[0] tableNamRef = constraintInfo[1] sys.stderr.write("tableNam=%s\n" % (tableNam)) nodeMysqlTable = survol_mysql_table.MakeUri(hostname, dbNam, tableNam) nodeMysqlTableRef = survol_mysql_table.MakeUri(hostname, dbNam, tableNamRef) grph.add((nodeMysqlTable, propConstraint, nodeMysqlTableRef)) grph.add((nodeMysqlDatabase, propTable, nodeMysqlTable)) cursorMysql.close() connMysql.close() cgiEnv.OutCgiRdf("LAYOUT_RECT_TB")
def Main(): cgiEnv = lib_common.ScriptEnvironment( ) instance_name = cgiEnv.m_entity_id_dict["Instance"] session_id = cgiEnv.m_entity_id_dict["Id"] 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) # BEWARE: This is duplicated. propDb = lib_common.MakeProp("Mysql database") a_cred = lib_credentials.GetCredentials("MySql", instance_name) conn_mysql = survol_mysql.MysqlConnect(instance_name, aUser=a_cred[0], aPass=a_cred[1]) cursor_mysql = conn_mysql.cursor() # mysql> select * from information_schema.processlist; # +--------+------------------+------------------+------+---------+------+-----------+----------------------------------------------+ # | ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO | # +--------+------------------+------------------+------+---------+------+-----------+----------------------------------------------+ # | 439768 | primhilltcsrvdb1 | 10.2.123.9:52146 | NULL | Query | 0 | executing | select * from information_schema.processlist | # | 439765 | primhilltcsrvdb1 | 10.2.123.9:52062 | NULL | Sleep | 13 | | NULL | # +--------+------------------+------------------+------+---------+------+-----------+----------------------------------------------+ cursor_mysql.execute("select * from information_schema.processlist where ID=%s" % session_id) grph.add((host_node, lib_common.MakeProp("Mysql instance"), instance_node)) # There should be one row only. for sess_info in cursor_mysql: logging.debug("sess_info=%s", str(sess_info)) mysql_session_id = sess_info[0] mysql_user = sess_info[1] session_node = survol_mysql_session.MakeUri(instance_name, mysql_session_id) # If there is a proper socket, then create a name for it. mysql_socket = sess_info[2] try: mysql_socket_host, mysql_socket_port = mysql_socket.split(":") socket_node = lib_uris.gUriGen.AddrUri(mysql_socket_host, mysql_socket_port) grph.add((session_node, lib_common.MakeProp("Connection socket"), socket_node)) except: pass mysql_db = sess_info[3] grph.add((session_node, lib_common.MakeProp("Database"), lib_util.NodeLiteral(mysql_db))) mysql_time = sess_info[5] grph.add((session_node, lib_common.MakeProp("Time"), lib_util.NodeLiteral(mysql_time))) # If there is a running query, then display it. mysql_command = sess_info[4] mysql_state = sess_info[6] if (mysql_command == "Query") and (mysql_state == "executing"): mysql_query = sess_info[7] node_query = survol_mysql_query.MakeUri(instance_name,mysql_query) grph.add((session_node, lib_common.MakeProp("Mysql query"), node_query)) grph.add((session_node, lib_common.MakeProp("Command"), lib_util.NodeLiteral(mysql_command))) grph.add((session_node, lib_common.MakeProp("State"), lib_util.NodeLiteral(mysql_state))) grph.add((session_node, lib_common.MakeProp("User"), lib_util.NodeLiteral(mysql_user))) grph.add((session_node, lib_common.MakeProp("Mysql session"), instance_node)) cursor_mysql.close() conn_mysql.close() cgiEnv.OutCgiRdf("LAYOUT_SPLINE")
def Main(): cgiEnv = lib_common.CgiEnv() instanceName = cgiEnv.m_entity_id_dict["Instance"] instanceNode = survol_mysql_instance.MakeUri(instanceName) (hostname, hostport) = survol_mysql.InstanceToHostPort(instanceName) cgiEnv = lib_common.CgiEnv() grph = cgiEnv.GetGraph() hostAddr = lib_util.GlobalGetHostByName(hostname) # 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. hostNode = lib_common.gUriGen.HostnameUri(hostname) # BEWARE: This is duplicated. propDb = lib_common.MakeProp("Mysql database") #nodeMysqlDatabase = survol_mysql_database.MakeUri(instanceName,dbNam) #grph.add( ( hostNode, propDb, nodeMysqlDatabase ) ) aCred = lib_credentials.GetCredentials("MySql", instanceName) connMysql = survol_mysql.MysqlConnect(instanceName, aUser=aCred[0], aPass=aCred[1]) cursorMysql = connMysql.cursor() # mysql> select * from information_schema.processlist; # +--------+------------------+------------------+------+---------+------+-----------+----------------------------------------------+ # | ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO | # +--------+------------------+------------------+------+---------+------+-----------+----------------------------------------------+ # | 439768 | primhilltcsrvdb1 | 10.2.123.9:52146 | NULL | Query | 0 | executing | select * from information_schema.processlist | # | 439765 | primhilltcsrvdb1 | 10.2.123.9:52062 | NULL | Sleep | 13 | | NULL | # +--------+------------------+------------------+------+---------+------+-----------+----------------------------------------------+ cursorMysql.execute("select * from information_schema.processlist") propTable = lib_common.MakeProp("Mysql table") grph.add((hostNode, lib_common.MakeProp("Mysql instance"), instanceNode)) for sessInfo in cursorMysql: sys.stderr.write("sessInfo=%s\n" % str(sessInfo)) mysqlSessionId = sessInfo[0] mysqlUser = sessInfo[1] sessionNode = survol_mysql_session.MakeUri(instanceName, mysqlSessionId) # If there is a proper socket, then create a name for it. mysqlSocket = sessInfo[2] try: (mysqlSocketHost, mysqlSocketPort) = mysqlSocket.split(":") socketNode = lib_common.gUriGen.AddrUri(mysqlSocketHost, mysqlSocketPort) grph.add((sessionNode, lib_common.MakeProp("Connection socket"), socketNode)) except: pass # If there is a running query, then display it. mysqlCommand = sessInfo[4] mysqlState = sessInfo[6] if (mysqlCommand == "Query") and (mysqlState == "executing"): mysqlQuery = sessInfo[7] nodeQuery = survol_mysql_query.MakeUri(instanceName, mysqlQuery) grph.add( (sessionNode, lib_common.MakeProp("Mysql query"), nodeQuery)) grph.add((sessionNode, lib_common.MakeProp("User"), lib_common.NodeLiteral(mysqlUser))) grph.add( (sessionNode, lib_common.MakeProp("Mysql session"), instanceNode)) cursorMysql.close() connMysql.close() cgiEnv.OutCgiRdf("LAYOUT_SPLINE")
def Main(): cgiEnv = lib_common.ScriptEnvironment() instance_name = cgiEnv.m_entity_id_dict["Instance"] db_nam = cgiEnv.m_entity_id_dict["Database"] hostname, hostport = survol_mysql.InstanceToHostPort(instance_name) cgiEnv = lib_common.ScriptEnvironment() grph = cgiEnv.GetGraph() host_node = lib_uris.gUriGen.HostnameUri(hostname) # BEWARE: This is duplicated. prop_db = lib_common.MakeProp("Mysql database") node_mysql_database = survol_mysql_database.MakeUri(instance_name, db_nam) grph.add((host_node, prop_db, node_mysql_database)) a_cred = lib_credentials.GetCredentials("MySql", instance_name) conn_mysql = survol_mysql.MysqlConnect(instance_name, aUser=a_cred[0], aPass=a_cred[1]) cursor_mysql = conn_mysql.cursor() cursor_mysql.execute( "select * from information_schema.TABLES where TABLE_SCHEMA='%s'" % db_nam) propTable = lib_common.MakeProp("Mysql table") cursor_mysql.execute( "select TABLE_NAME, REFERENCED_TABLE_NAME, CONSTRAINT_NAME " " from information_schema.referential_constraints" " where CONSTRAINT_SCHEMA='%s' " % db_nam) # There should be only one row, maximum. for constraint_info in cursor_mysql: logging.debug("constraint_info=%s", str(constraint_info)) table_nam = constraint_info[0] table_nam_ref = constraint_info[1] prop_constraint = lib_common.MakeProp(constraint_info[2]) logging.debug("table_nam=%s", table_nam) node_mysql_table = survol_mysql_table.MakeUri(hostname, db_nam, table_nam) node_mysql_table_ref = survol_mysql_table.MakeUri( hostname, db_nam, table_nam_ref) grph.add((node_mysql_table, prop_constraint, node_mysql_table_ref)) #grph.add( ( node_mysql_database, propTable, node_mysql_table ) ) cursor_mysql.close() conn_mysql.close() cgiEnv.OutCgiRdf("LAYOUT_SPLINE")
def Main(): cgiEnv = lib_common.ScriptEnvironment() instance_name = cgiEnv.m_entity_id_dict["Instance"] db_nam = cgiEnv.m_entity_id_dict["Database"] hostname, hostport = survol_mysql.InstanceToHostPort(instance_name) cgiEnv = lib_common.ScriptEnvironment() grph = cgiEnv.GetGraph() host_node = lib_uris.gUriGen.HostnameUri(hostname) # BEWARE: This is duplicated. prop_db = lib_common.MakeProp("Mysql database") node_mysql_database = survol_mysql_database.MakeUri(instance_name, db_nam) grph.add((host_node, prop_db, node_mysql_database)) a_cred = lib_credentials.GetCredentials("MySql", instance_name) conn_mysql = survol_mysql.MysqlConnect(instance_name, aUser=a_cred[0], aPass=a_cred[1]) cursor_mysql = conn_mysql.cursor() cursor_mysql.execute( "select * from information_schema.TABLES where TABLE_SCHEMA='%s'" % db_nam) prop_table = lib_common.MakeProp("Mysql table") # >>> conn = MySQLdb.connect(user="******",passwd="?????",host="primhilltcsrvdb1.mysql.db") # >>> curs=conn.cursor() # >>> curs.execute("select * from information_schema.TABLES where TABLE_SCHEMA='primhilltcsrvdb1'") # >>> for x in curs: # TABLE_CATALOG def # TABLE_SCHEMA Table_... # TABLE_NAME Table_... # TABLE_TYPE # ENGINE Engine MySQL extension # VERSION Version The version number of the table's .frm file, MySQL extension # ROW_FORMAT Row_format MySQL extension # TABLE_ROWS Rows MySQL extension # AVG_ROW_LENGTH Avg_row_length MySQL extension # DATA_LENGTH Data_length MySQL extension # MAX_DATA_LENGTH Max_data_length MySQL extension # INDEX_LENGTH Index_length MySQL extension # DATA_FREE Data_free MySQL extension # AUTO_INCREMENT Auto_increment MySQL extension # CREATE_TIME Create_time MySQL extension # UPDATE_TIME Update_time MySQL extension # CHECK_TIME Check_time MySQL extension # TABLE_COLLATION Collation MySQL extension # CHECKSUM Checksum MySQL extension # CREATE_OPTIONS Create_options MySQL extension # TABLE_COMMENT Comment MySQL extension # ... print(x) # ( 'def', 'primhilltcsrvdb1', 'Test_Table', 'BASE TABLE', 'InnoDB', # 10L, 'Compact', 2L, 8192L, 16384L, # 0L, 0L, 0L, None, datetime.datetime(2017, 12, 13, 8, 59, 24), # None, None, 'latin1_swedish_ci', None, '', # 'Comment about this test table.') for tab_info in cursor_mysql: logging.debug("tab_info=%s", str(tab_info)) table_nam = tab_info[2] node_mysql_table = survol_mysql_table.MakeUri(hostname, db_nam, table_nam) grph.add((node_mysql_table, lib_common.MakeProp("Table type"), lib_util.NodeLiteral(tab_info[3]))) grph.add((node_mysql_table, lib_common.MakeProp("Engine"), lib_util.NodeLiteral(tab_info[4]))) grph.add((node_mysql_table, pc.property_information, lib_util.NodeLiteral(tab_info[20]))) grph.add((node_mysql_database, prop_table, node_mysql_table)) cursor_mysql.close() conn_mysql.close() cgiEnv.OutCgiRdf("LAYOUT_RECT", [prop_table])