Thanks Stewart for getting me headed in the right direction. I should of known I had to define that variable. So here is what's happening now - The script runs correctly when tested on a box that's setup for Integrated auth however when tested on a box using SQL authentication just throws the standard error code(1). If I comment out the Integrated lines below then it works on the SQL auth instance. I'm not sure what's going on but it doesn't like something... fails the same way if I try moving the user and pass variables down under the "else" as well.
import org.xbill.DNS.*;
import groovy.sql.Sql;
def returnCode = 0;
def sql = null;
try {
hostname = hostProps.get('system.hostname');
integrated = hostProps.get('auto.integrated_security');
user = hostProps.get("jdbc.mssql.user");
pass = hostProps.get("jdbc.mssql.pass");
//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 {
SQLUrl = "jdbc:sqlserver://${hostname}:1433;user=${user};password=${pass}";
}
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;
}