So close again:
import com.santaba.agent.groovyapi.expect.Expect;
import com.santaba.agent.groovyapi.snmp.Snmp;
import com.santaba.agent.groovyapi.http.*;
import com.santaba.agent.groovyapi.jmx.*;
import org.xbill.DNS.*;
import groovy.sql.Sql // needed for SQL connection and query
hostname = hostProps.get("system.hostname");
user = ''
pass = ''
SQLUrl = "jdbc:sqlserver://" + hostname + ";databaseName=master;integratedSecurity=true" //
sql = Sql.newInstance(SQLUrl, user, pass, 'com.microsoft.sqlserver.jdbc.SQLServerDriver')
sql.eachRow( 'SELECT name, expiry_date from sys.certificates'){
certname = it.name.toString().replaceAll("#","")
println(certname + "##" + certname)
}
sql.close() // Close connection
The problem was two-fold: 1) you were not outputting in the AD format and 2) you had "##" in your certificate names, which interferes with the built in parsing mechanism that parses the output. Make sure discovery is working properly first because the collector script will look very similar up until the println statement.
Your collection script would be very similar (assuming you've set batchscript as the collector type on the DS):
import com.santaba.agent.groovyapi.expect.Expect;
import com.santaba.agent.groovyapi.snmp.Snmp;
import com.santaba.agent.groovyapi.http.*;
import com.santaba.agent.groovyapi.jmx.*;
import org.xbill.DNS.*;
import groovy.sql.Sql // needed for SQL connection and query
import groovy.time.*
hostname = hostProps.get("system.hostname");
user = ''
pass = ''
SQLUrl = "jdbc:sqlserver://" + hostname + ";databaseName=master;integratedSecurity=true" //
sql = Sql.newInstance(SQLUrl, user, pass, 'com.microsoft.sqlserver.jdbc.SQLServerDriver')
sql.eachRow( 'SELECT name, expiry_date from sys.certificates'){
certname = it.name.toString().replaceAll("#","")
timetoexpire = TimeCategory.minus(new Date(),Date.parse("yyy-MM-dd HH:mm:ss.S",it.expiry_date))
println(certname + ".daystoexpire: " + daystoexpire.getDays())
}
sql.close() // Close connection
The timetoexpire variable might need some tweaking to make sure it parses properly. This should give you collection output that looks like this (fake values):
MS_AgentSigningCertificate.daystoexpire: 23
MS_PolicySigningCertificate.daystoexpire: 45
etc.
You'd create a datapoint and set "Content the script writes to the standard output" and set Interpret output with to "multi-line key-value pairs". Then set the key to ##WILDVALUE##.daystoexpire