I'd suggest adding checks within your main try block. You might check that you're actually fetching values for user/pass. If you run this in a Collector debug, you can get more output, like the println statements.
import org.xbill.DNS.*; //BTW, you don't need this unless you're interacting with a DNS server here in your script.
import groovy.sql.Sql
def returnCode = 0
def sql = null
hostname = hostProps.get('system.hostname')
integrated = hostProps.get('auto.integrated_security')
user = hostProps.get("jdbc.mssql.user")
pass = hostProps.get("jdbc.mssql.pass")
try {
//Check for Integrated Security and then authenticate that way if it's available
if(integrated){
SQLUrl = "jdbc:sqlserver://${hostname};integratedSecurity=true;applicationIntent=ReadOnly;logintimeout=5"
} else {
if (!user || !pass) {
println("Unable to fetch username/password.")
return 2
}
SQLUrl = "jdbc:sqlserver://${hostname}:1433;user=${user};password=${pass}"
}
println(SQLUrl)
sql = Sql.newInstance(SQLUrl)
// Loop through every row returned by the query
sql.eachRow( 'SELECT dev_id,dev_displayname,dev_ipaddress,dev_serialnumber,dev_mac_address,dev_manufacturer,dev_model,PPM,total_memory,system_systemname FROM genericdatabase.dbo.view_device_properties' ) {
// Print active discovery script output - WildValue, WildAlias and auto properties.
println "$it.dev_id##$it.dev_displayname##$it.dev_mac_address####genericdatabase.id=$it.dev_id&genericdatabase.displayName=$it.dev_displayname&genericdatabase.ip=$it.dev_ipaddress&genericdatabase.serialNumber=$it.dev_serialnumber&genericdatabase.macAddress=$it.dev_mac_address&genericdatabase.manufacturer=$it.dev_manufacturer&genericdatabase.Model=$it.dev_model&genericdatabase.memory(mb)=$it.total_memory&genericdatabase.ppm=$it.ppm&genericdatabase.devicename=$it.system_systemname"
}
}
catch (Exception e){
returnCode = 1
}
finally {
if(sql != null) {
sql.close()
}
return returnCode
}