Forum Discussion
please check my dicovery script. it is running sucessfully but instances are not discovering.please make some changes
import groovy.sql.Sql
import java.sql.*
// Get basic info to connect
def hostname = hostProps.get("system.hostname")
def user = hostProps.get("sybase.user")
def pass = hostProps.get("sybase.pass")
def port = 21000
// Construct an SQL instance with a url and a driver
def url = "jdbc:sybase:Tds:$hostname:$port"
def driver = "com.sybase.jdbc4.jdbc.SybDriver"
def sql = Sql.newInstance(url, user, pass, driver)
def conn = sql.getConnection()
try {
def stmt = conn.createStatement()
// Retrieve database names and IDs
def dbRs = stmt.executeQuery("select name, dbid from sysdatabases")
while (dbRs.next()) {
def dbName = dbRs.getString("name")
def dbId = dbRs.getInt("dbid")
// Retrieve segment information for each database
def segmentRs = stmt.executeQuery("select name from '${dbName}'..syssegments where dbid = ${dbId}")
while (segmentRs.next()) {
def segmentName = segmentRs.getString("segment_name")
def segment = segmentRs.getBytes("segment")
// Process segment information and create instance
def instanceName = "${dbName}_${segmentName}_segment"
def instanceConfig = [segment: segment]
createInstance(instanceName, instanceConfig)
}
segmentRs.close()
}
dbRs.close()
stmt.close()
} catch (SQLException e) {
// Handle SQL exception
e.printStackTrace()
} finally {
if (conn != null) {
conn.close()
}
}
// Function to create instance
def createInstance(name, config) {
println("Creating instance ${name} with config ${config}")
// Implementation of instance creation logic here
}
Related Content
- 2 years ago
- 3 days ago
- 2 years ago