import groovy.sql.Sql
//@Grab('org.hsqldb:hsqldb:2.7.1:jdk8')
//@GrabConfig(systemClassLoader=true)
Class.forName("com.sybase.jdbc4.jdbc.SybDriver")
// 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
def dbname = hostProps.get("sybase.dbname")
// Construct an SQL instance with a url and a driver
def url = "jdbc:sybase:Tds:${hostname}:${port}", username=user, password=pass
// Sybase SQL Driver
def driver = "com.sybase.jdbc4.jdbc.SybDriver"
// Create a connection to the SQL server
def sql = Sql.newInstance(url, user, pass, driver)
def results = []
sql.withTransaction {
// ADDED time_blocked to the sql query here so that it's in your results.
def wildvalue = instanceProps.get("wildvalue")
results = sql.rows("select spid, time_blocked, blocked from master..sysprocesses")
}
sql.close()
// Format the results as key-value pairs
results.each { row ->
println("${row.spid}.BLOCKED: ${row.blocked}") // use the println statement.
// add a second println statement for the second datapoint on this SPID. This datapoint is called TIME_BLOCKED
if (row.time_blocked != null) {
(h,m) = row.time_blocked.split(":")
time_blocked = h.toInteger()*60 + m.toInteger()
println("${row.spid}.TIME_BLOCKED: ${time_blocked}")
} else {
println("${row.spid}.TIME_BLOCKED: null")
}
// The datapoint definition would be a multi-line key-value pair just like the blocked datapoint
// The key would be ##WILDVALUE##.TIME_BLOCKED
}
return 0