Enhanced Script Netscan

Last updated on 01 November, 2022

The Advanced NetScan, Enhanced Script Netscan, provides enhanced features, improved output formatting, additional group assignment options, and device filtering. Additionally, you can choose to inherit device credentials from a specific device, device group, or you can set custom credentials in the Enhanced Script Netscan. 


  • Collector version 32.400 or higher

Adding an Enhanced Script Netscan

The following steps are specific to adding an Enhanced Script Netscan. For information about creating NetScans (Basic or Advanced), see Creating NetScans.

  1. Go to Settings > NetScans > Add > Advanced NetScan.
  2. On the Add NetScan window, provide a Name and a Description.
  3. Provide a Group. You can select from a list of existing groups or you can leave the field blank to add it to the @default group.
  4. Use the Collector Group and Collector fields to select a collector. This is the collector that will run the Enhanced Script Netscan. Options in the Collector field are filtered based on the Collector Group.
  5. Select Enhanced Script Netscan as the Method. Additional Enhanced Script fields appear.

  6. From the Device Credentials section:
    • Inherit credentials from Device Group: Begin typing to select the Device Group that you want to inherit credentials from.
    • Inherit credentials from Device: Begin typing to select the Device that you want to inherit credentials from.
    • Use custom credentials for this scan: Click Add to provide a Property (you can select from a list provided or type your own custom key name) and Property value

Note: These properties can be accessed for use in the script using netscanProps.get("property.key"). If you want any of these properties to be added to the device, include them in the JSON structure for the device under the hostProps field. For more information, see Script Formatting.

  1. Optional: Use the Filters field to exclude devices from the Enhanced Script Netscan, based on device properties assigned in the script:
    • Attribute
    • Operation
    • Value
    • Comment
  2. Select one of the following Upload Script methods to supply a script. For more information, see Script Formatting.
    • Upload script file
    • Upload script file from the network
    • Embed a Groovy script
  3. If a group is not specified in the script output, the Default Group field will determine which group a resource will be added to. If a group is specified in the script output, this field is ignored.
  4. You can Exclude Duplicate IP Addresses based on the following options:
    • Matching monitored resources: Excludes any discovered resource that has the same IP address as a resource that is already being monitored.
    • Matching resources already discovered by this NetScan: Excludes any discovered resource that has already been moved into monitoring.
    • Matching resources in these resource groups: Excludes any discovered resource that has the same IP address as a resource belonging to a specified resource group. When this option is selected, an additional field appears so that you can specify one or more resource groups.
    • Matching resources currently assigned to these Collectors: Excludes any discovered resource that has the same IP addresses as a resource that is assigned to a specified collector. When this option is selected, an additional field appears so that you can specify one or more collectors.
  5. Use the Run this NetScan on a schedule option to run the Enhanced Script Netscan at a set intervals. This will ensure that any new devices added to your infrastructure are added into monitoring in a timely, automatic fashion.
    • Frequency
    • Start time
    • Timezone
  6. Select Save and Run to save your changes and to run the Enhanced Script Netscan. Select Save to save without running it.

Collector Assignment

You can assign a device to any collector. The precedence for collector assignment is as follows (checking for both existence and validity at each step and taking the first match found):

  1. The collectorId value specified for the device in JSON output.
  2. The preferred collector of host group reported by the NetScan. For multiple group assignments, it follows the order in which the groups are listed.
  3. The preferred collector of the default NetScan group.
  4. The collector performing the NetScan.

Script Formatting

Enhanced Script Netscan requires JSON format for output. Devices should be formatted as a list of objects using only the valid keys listed below.

Key NameGroovy Data TypesRequired / Optional
hostPropsMap<String, String>Optional

Script Formatting Example

The following example may provide formatting guidance as you develop your script.


    "hostname" : "",
    "displayname" : "Server 123",
    "hostProps" : {
        "custom.prop"  : "value",
        "another.prop" : "384597",
        "ya.prop"      : "null"
    "groupName" : ["ParentGroup/ChildGroup", "RootLevelGroup"],
    "collectorId" : 18
    "hostname" : "",
    "displayname" : "Server 456",
    "hostProps" : {
        "custom.creds.user" : varUser.toString(),
        "custom.creds.pass" : varPass.toString()
    "groupName" : ["GrandparentGroup/ParentGroup/NewGroupNotYetInExistence"],
    "collectorId" : 20


Custom Properties

You can assign custom properties to devices during Enhanced Script Netscan runs using the hostProps field. These properties are custom and as such will be editable from the Resources page. Certain types of properties cannot be set by the NetScan and will fail if you attempt to assign properties with any of the following prefixes:

  • auto. 
  • predef. 
  • system.

Sample Enhanced Script Netscan Script

LogicMonitor provides Enhanced Script Netscan options out-of-the-box for select technologies. Advanced users with Groovy scripting capabilities may use the following boilerplate code to build from to create their own custom scripts.

 * © 2007-2022 - LogicMonitor, Inc. All rights reserved.
import com.logicmonitor.common.sse.utils.GroovyScriptHelper as GSH
import com.logicmonitor.mod.Snippets
import com.santaba.agent.AgentVersion
import java.text.DecimalFormat
// To run in debug mode, set to true
Boolean debug = false
// Import any needed credentials or properties that have been set in the UI
String netCreds = netscanProps.get("custom.property.key")
// Retrieve the collector version
Integer collectorVersion = AgentVersion.AGENT_VERSION.toInteger()
// Bail out early if we don't have the correct minimum collector version to ensure netscan runs properly
if (collectorVersion < 32400) {
    def formattedVer = new DecimalFormat("00.000").format(collectorVersion / 1000)
    throw new Exception(" Upgrade collector running netscan to 32.400 or higher to run full featured enhanced script netscan. Currently running version ${formattedVer}.")
// Bail out early if we don't have the necessary credentials
if (!netCreds) {
    throw new Exception(" Must provide credentials to run this script.  Verify necessary credentials have been provided in Netscan properties.")
// Load the lm.emit snippet to ensure proper output formatting
def modLoader = GSH.getInstance()._getScript("Snippets", Snippets.getLoader()).withBinding(getBinding())
def lmEmit = modLoader.load("lm.emit", "0.0")
// Get your data and build your list of resources
List<Map> resources = []
Insert your custom code to retrieve data about the devices you want to add
// Loop through your data to build your device map with proper keys
// in loop...
    Map resource = [
        "hostname"    : ip,          // String
        "displayname" : displayName, // String
        "hostProps"   : deviceProps, // Map<String, String>
        "groupName"   : groupName,   // List<String>
        "collectorId" : 123          // Integer
// ...end loop
// Output validated data in JSON format
// If errors have been made in acceptable/required keys, lm.emit will throw and inform the user
In This Article