Forum Discussion
- Anonymous
For batchscript, it's not one wildvalue, but all of the ones from discovery. Usually, I just run the same code that ran in the discovery script to the list of wildvalues. Then i loop through it. I saw some code from LM recently (I'd have to search) that had a shortcut for pulling in the wild values.
- manthena2020Advisor
Ok. Could you please Help me on short cut to Pull. Thanks
- Anonymous
What does your discovery script look like?
- manthena2020Advisor
As you said i done the looping in collection script using same code which i have used in Active Discovery, i am getting output. The Only Challenging here is the output is not Posting against each instance under Raw data Tab
- manthena2020Advisor
when i try to do Pollnow from LM Console against each instance
Output : i am getting Null
script output : i am getting Data
- manthena2020Advisor
Active Discovery-Discovery Method Script ============================================================================================================================================== import groovy.sql.Sql def hostname = hostProps.get("system.hostname") def sqlInstances = hostProps.get("mssql.sql_server_instances") ?: hostProps.get("auto.sql_server_instances") if (sqlInstances) { def executor = java.util.concurrent.Executors.newFixedThreadPool(sqlInstances.size().toInteger()) sqlInstances.toString().tokenize(",").each { instanceName -> executor.submit({ instanceName = instanceName.replaceAll(/[:|\\|\s|=]+/, "_") def jdbcConnectionString = hostProps.get("mssql.${instanceName.trim()}.mssql_url") ?: hostProps.get("auto.${instanceName.trim()}.mssql_url") def user = hostProps.get("mssql.${instanceName.trim()}.user") ?: hostProps.get("jdbc.mssql.user") ?: "" def pass = hostProps.get("mssql.${instanceName.trim()}.pass") ?: hostProps.get("jdbc.mssql.pass") ?: "" if (jdbcConnectionString) { def sql = Sql.newInstance(jdbcConnectionString, user, pass, "com.microsoft.sqlserver.jdbc.SQLServerDriver") try { def query1 = """ SQL QUERY """ def resultSet = sql.rows(query1) if (resultSet) { resultSet.each { row -> def x = row.get("database_name") def y = row.get("BackupType") def z = row.get("bkSize") def c = row.get("TimeTaken") def a = row.get("physical_device_name") def b = row.get("recovery_model") def p = row.get("server_name") def m = row.get("Is_Native_Backup") println("${a}##${a}######instance=${instanceName}&DB=${x}&BackupType=${y}&bkSize=${z}&TimeTaken=${c}&physical_device_name=${a}&recovery_model=${b}&&server_name=${p}&BackupLocation=${m}") } } else { println("Result set is null or empty") } } catch (Exception e) { println("Exception during sql.rows execution: ${e.message}") e.printStackTrace() } finally { sql.close() println("Finally block executed") } } } as java.util.concurrent.Callable) } executor.shutdown() executor.awaitTermination(20, java.util.concurrent.TimeUnit.SECONDS) } return 0 ============================================================================================================================================ Collection script-Batch Method ============================================================================================================================================ import groovy.sql.Sql def hostname = hostProps.get("system.hostname") def sqlInstances = hostProps.get("mssql.sql_server_instances") ?: hostProps.get("auto.sql_server_instances") if (sqlInstances) { sqlInstances.toString().tokenize(",").each { currentInstance -> currentInstance = currentInstance.replaceAll(/[:|\\|\s|=]+/, "_") def jdbcConnectionString = hostProps.get("mssql.${currentInstance.trim()}.mssql_url") ?: hostProps.get("auto.${currentInstance.trim()}.mssql_url") def user = hostProps.get("mssql.${currentInstance.trim()}.user") ?: hostProps.get("jdbc.mssql.user") ?: "" def pass = hostProps.get("mssql.${currentInstance.trim()}.pass") ?: hostProps.get("jdbc.mssql.pass") ?: "" if (jdbcConnectionString) { def sql = Sql.newInstance(jdbcConnectionString, user, pass, "com.microsoft.sqlserver.jdbc.SQLServerDriver") try { def initialQuery = """ ( same SQL used in Discovery) """ def resultSet = sql.rows(initialQuery) def deviceNamesList = resultSet.collect { it.get("physical_device_name") } //.replaceAll("\\\\", "") } if (deviceNamesList) { deviceNamesList.each { deviceName -> def secondaryQuery = """ ( same SQL used in Discovery) """ def secondaryResultSet = sql.rows(secondaryQuery) if (secondaryResultSet) { secondaryResultSet.each { row -> def databaseName = row.get("database_name") def backupType = row.get("BackupType") def backupSize = row.get("bkSize").replaceAll(/\D/, '') def timeTaken = row.get("TimeTaken").replaceAll(/\D/, '') def recoveryModel = row.get("recovery_model") def isNativeBackup = row.get("Is_Native_Backup") def M = row.get("physical_device_name") //.replaceAll("\\\\", "") recoveryModel = (recoveryModel == 'simple') ? '1' : (recoveryModel == 'full') ? '2' : (recoveryModel == 'bulk_logged') ? '3' : recoveryModel if (deviceName == M) { def wildvalue = deviceName //println("${wildvalue}.Device Name: ${deviceName}") //println("${wildvalue}.Database Name: ${databaseName}") println("${wildvalue}.BackupType:${backupType}") println("${wildvalue}.BackupSize: ${backupSize}") println("${wildvalue}.TimeTaken: ${timeTaken}") println("${wildvalue}.RecoveryModel: ${recoveryModel}") println("${wildvalue}.Native_Backup: ${isNativeBackup}") } } } } } } finally { sql.close() } } else { println("JDBC Connection String not found for $currentInstance") } } } else { println("No SQL instances found") } return 0
- Anonymous
All that seems good. Could you post a screenshot of your poll now? Redact any private information. What I'm looking to see is the script output down below so try to get the whole dialog box if possible.
- manthena2020Advisor
====================================================================================
Active Discovery-Script
====================================================================================Wildvalue
D:\HP123\ramDB\DIFF\HP123_dkkDB_DIFF_20240821_160039.bak
D:\HP123\model\DIFF\HP123_model_DIFF_20240821_160038.bak
=======================================================================================
collection Output-Batchscript
=======================================================================================D:\HP123\ramDB\DIFF\HP123_dkkDB_DIFF_20240821_160039.bak.BackupType:2
D:\HP123\ramDB\DIFF\HP123_dkkDB_DIFF_20240821_160039.bak.BackupSize: 3
D:\HP123\ramDB\DIFF\HP123_dkkDB_DIFF_20240821_160039.bak.TimeTaken: 0
D:\HP123\ramDB\DIFF\HP123_dkkDB_DIFF_20240821_160039.bak.RecoveryModel: 1
D:\HP123\ramDB\DIFF\HP123_dkkDB_DIFF_20240821_160039.bak.Native_Backup: 1
D:\HP123\model\DIFF\HP123_model_DIFF_20240821_160038.bak.BackupType:2
D:\HP123\model\DIFF\HP123_model_DIFF_20240821_160038.bak.BackupSize: 0
D:\HP123\model\DIFF\HP123_model_DIFF_20240821_160038.bak.TimeTaken: 0
D:\HP123\model\DIFF\HP123_model_DIFF_20240821_160038.bak.RecoveryModel: 2
D:\HP123\model\DIFF\HP123_model_DIFF_20240821_160038.bak.Native_Backup: 1- Anonymous
Not what i was looking for, but it highlights one problem. See this documentation.
- manthena2020Advisor
What you want me to share?
- Anonymous
I was looking for a screenshot of the results of a poll now. But that doesn't matter because you have illegal characters in your wildvalue. You'll need to update your discovery and collection scripts to remove the offending characters. The link i provided in the last reply highlights which characters you can't have in your wildvalue.
- manthena2020Advisor
I can see issue is fixed. But my question here is why cant we call this property
def wildvalue = instanceProps.get("wildvalue")
in Collection Script?
- Anonymous
Because with batchscript, the script runs for all instances. Which instance's wildvalue did you expect back? You can only do instanceProps.get("wildvalue") on script, not batchscript.
- Anonymous
I believe there is a way to grab from the deviceDatasourceProps the list of wildvalues, but i haven't been able to relocate the code where i saw that done.
It would be nice if someone from LM who knew how to do it chimed in here. Maybe someone from the ME team...
- manthena2020Advisor
is there any other ways apart from Looping. Like call wild value in different way
- Anonymous
Like i mentioned before, yes, i believe there is a way. However, I don't know the exact code, someone from LM would need to provide that (they should).
That said, i've built hundreds of datasources and it's never really been an issue to just use the same code that produces the instance list in the first place right in the collection script. In many cases, the same call that grabs the list of instances from the target can include the metrics as well so you're still only doing one call.
So if your query calls the database to grab the list of instances during discovery, do the same thing during collection, but expand your query to include the metrics. Then loop through the rows of that query outputting the wildvalue along with the metrics.
- Mike_RodriguesProduct Manager
I pinged the ME's channel and linked to this thread. If there is some way of enumerating wildaliases from within an AD batchscript, it's not something I'm aware of. There could be some new way I'm not aware of.
I wrote countless official LM modules that did the same thing with respect to running the same code in AD and collection, to get the instances.
*About 2 seconds after posting this I received this from the MEs:datasourceinstanceProps.each{ instance, instanceProperties -> instanceProperties.each{ it -> println it.wildValue } }
def listOfWildValues = datasourceinstanceProps.values().collect { it.wildvalue }
- manthena2020Advisor
Hello, I confirm that it is fetching Wild values list. The only thing I observed is, we have to save the Active Discovery Script & Applies (server details, where the code shall run) then only we can fetch the information .Thanks
- Anonymous
Yeah, it wouldn't work in test script nor in the collector debug since those aren't fully fledged collection tasks. Only when the task is scheduled as a collection task will that be present. Just like you can't fetch a single wildvalue on a test script for a script based DS.
Related Content
- 10 months ago
- 10 months ago
- 7 months ago
- 2 months ago