Changes to Discovery commands


The following sections show the discovery command changes between BMC Discovery versions.

The following changes are not shown:

  • Entirely new discovery platforms
  • Changes to comments only
  • Commands which have been removed and not replaced
  • Changes to echo only statements

Discovery command changes from 24.1 to 24.2

VMware ESX

getIPAddresses

The following code:

 
    # GCE public IPs
    if [ "$TW_CLOUD_PLATFORM" = "GCE" ]; then
        interfaces=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/ 2>/dev/null | sed -e 's#/$##'`
        for i in $interfaces
        do
            mac=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/$i/mac 2>/dev/null`
            public_ip=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/$i/access-configs/0/external-ip 2>/dev/null`
            echo "$i: nic$i: <UP> mtu 1500 state UP"
            echo "    link/ether $mac brd ff:ff:ff:ff:ff:ff"
            echo "    inet $public_ip/0 brd 0.0.0.0 scope tw:internet nic$i"
        done
    fi
rep

is replaced with:

    # GCE public and alias IPs
    if [ "$TW_CLOUD_PLATFORM" = "GCE" ]; then
        interfaces=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/ 2>/dev/null | sed -e 's#/$##'`
        for i in $interfaces
        do
            mac=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/$i/mac 2>/dev/null`
            public_ip=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/$i/access-configs/0/external-ip 2>/dev/null`
            ip_aliases=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/$i/ip-aliases/ 2>/dev/null`
            echo "$i: nic$i: <UP> mtu 1500 state UP"
            echo "    link/ether $mac brd ff:ff:ff:ff:ff:ff"
            echo "    inet $public_ip/0 brd 0.0.0.0 scope tw:internet nic$i"
            for a in $ip_aliases
            do
                alias_ip=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/$i/ip-aliases/$a 2>/dev/null`
                echo "    inet $alias_ip brd 0.0.0.0 scope tw:internet nic$i"
            done
        done
    fi
rep

initialise

The following privilege escalation is added. It is not currently used:

    PRIV_NSENTER() {
        "$@"
    }
...
    # nsenter requires superuser privileges to run commands in alternative
    # namespaces
    PRIV_NSENTER() {
        "$@"
    }
...
    # nsenter requires superuser privileges to run commands in alternative
    # namespaces
    PRIV_NSENTER() {
        "$@"
    }


Windows

getHostInfo

The following code:

$current_time = $os.LocalDateTime;
$boot_time    = $os.LastBootUpTime;
if ($boot_time) {
    "boot_time: {0}" -f $boot_time.toString("yyyy-MM-dd HH:mm:ss K");
}

$uptime = $null;

is replaced with:

$current_time = $os.LocalDateTime;
$boot_time    = $os.LastBootUpTime;
if ($boot_time) {
    try {
        "boot_time: {0}" -f $boot_time.toString("yyyy-MM-dd HH:mm:ss K");
    } catch {
        # Ignore errors
    }
}

$uptime = $null;

runWMIQuery

The following code:

 
             elseif ($_.Value -is [String[]]) {
                 "{0}: [String[]] {1}" -f ($_.Name, ($_.Value -join '\0'))
             }
             elseif ($_.IsInstance) {
                 # Convert associators to string form matching proxy output

is replaced with:

                elseif ($_.Value -is [String[]]) {
                    "{0}: [String[]] {1}" -f ($_.Name, ($_.Value -join '\0'))
                }
                elseif ($_.Value -is [array]) {
                    "{0}: [{1}] [{2}]" -f $_.Name, $_.Value.GetType().Name, ($_.Value -join ",")
                }
                elseif ($_.IsInstance) {
                    # Convert associators to string form matching proxy output

getFileSystems

The following code:

 
Get-CIMInstance -Query "SELECT * FROM Win32_LogicalDisk WHERE DriveType = 3 OR DriveType = 4" | ForEach-Object {
    if ($_.DriveType -eq 3) {
        # Get associated disk partition
        if ($PSVersionTable.PSVersion.Major -lt 3) {
            $device_id = $_.DeviceID.Replace("\", "\\");
            $parts = Get-WmiObject -query "ASSOCIATORS OF {Win32_LogicalDisk.DeviceID='$device_id'} WHERE AssocClass = Win32_LogicalDiskToPartition";
            foreach ($part in $Parts) {
                "name: {0}" -f $part.Caption;
                break;
            }
        } else {
            $part = Get-CimAssociatedInstance -CimInstance $_ -ResultClassName Win32_DiskPartition;
            "name: {0}" -f $part.Name;
        }
        "kind: LOCAL";
        "fs_type: {0}" -f $_.FileSystem;
    }

is replaced with:

Get-CIMInstance -Query "SELECT * FROM Win32_LogicalDisk WHERE DriveType = 3 OR DriveType = 4" | ForEach-Object {
    if ($_.DriveType -eq 3) {
        # Get associated disk partition
        $part = Get-CimAssociatedInstance -CimInstance $_ -ResultClassName Win32_DiskPartition;
        "name: {0}" -f $part.Name;
        "kind: LOCAL";
        "fs_type: {0}" -f $_.FileSystem;
    }

The following code:

  
# Need PowerShell 3.0 or later and Server 2012 or later to use Get-SmbShare
$get_smbshare = $false;
if ($PSVersionTable.PSVersion.Major -ge 3) {
    $command = Get-Command Get-SmbShare -errorAction SilentlyContinue;
    if ($command) {
        $get_smbshare = $true;
    }

is replaced with:

# Need PowerShell 3.0 or later and Server 2012 or later to use Get-SmbShare
$get_smbshare = $false;
$command = Get-Command Get-SmbShare -errorAction SilentlyContinue;
if ($command) {
  $get_smbshare = $true;
}

The following code:

  
if ($PSVersionTable.PSVersion.Major -ge 3) {
    if (Get-Module -ListAvailable -Name NFS) {
        Import-Module NFS;
        Get-NfsShare -ErrorAction SilentlyContinue | ForEach-Object {
            "name: {0}" -f $_.Path;
            "kind: EXPORTED";
            "fs_type: nfs";
            "size: 0";
            "used: 0";
            "mount: ";
            "export_name: {0}" -f $_.Name;
            if ($_.Availability) {
                "availability: {0}" -f $_.Availability;
            }
            "";
        };
    }
}

is replaced with:

if (Get-Module -ListAvailable -Name NFS) {
    Import-Module NFS;
    Get-NfsShare -ErrorAction SilentlyContinue | ForEach-Object {
        "name: {0}" -f $_.Path;
        "kind: EXPORTED";
        "fs_type: nfs";
        "size: 0";
        "used: 0";
        "mount: ";
        "export_name: {0}" -f $_.Name;
        if ($_.Availability) {
            "availability: {0}" -f $_.Availability;
        }
        "";
    };
}

initialise

The following code:

 
# Define some aliases for older Powershell versions to make scripting easier

if ($PSVersionTable.PSVersion.Major -lt 3) {
    Set-Alias -Name Get-CIMInstance -Value Get-WmiObject;
}

is replaced with:

# We need at least PowerShell 3.0

if ($PSVersionTable.PSVersion.Major -lt 3) {
  Throw "Unsupported PowerShell version";
}

The following code:

function tw_detect_cloud_platform {
    # Have we already detected the cloud platform?
    if ($global:TW_CLOUD_PLATFORM) {
        return;
    }

    # We need PowerShell 3.0 or later to make REST requests
    if ($PSVersionTable.PSVersion.Major -lt 3) {
        return;
    }

is replaced with:

function tw_detect_cloud_platform {
 # Have we already detected the cloud platform?
 if ($global:TW_CLOUD_PLATFORM) {
     return;
 }

The following code:

 
     # Filter by ServiceName
    if ($adapter.ServiceName) {
        if ($adapter.ServiceName -in $SERVICE_NAMES_TO_FILTER) {
            return $True;
        }
    }
...

    # Filter by ServiceName
    if ($config.ServiceName) {
        # PowerShell 2.0 doesn't have the -in operator so we must use -contains
        if ($SERVICE_NAMES_TO_FILTER -contains $config.ServiceName) {
            return $True;
        }
    }

is replaced with:

     # Filter by ServiceName
    if ($adapter.ServiceName) {
        # PowerShell 2.0 doesn't have the -in operator so we must use -contains
        if ($SERVICE_NAMES_TO_FILTER -contains $adapter.ServiceName) {
            return $True;
        }
    }
...

    # Filter by ServiceName
    if ($config.ServiceName) {
        # PowerShell 2.0 doesn't have the -in operator so we must use -contains
        if ($SERVICE_NAMES_TO_FILTER -contains $config.ServiceName) {
            return $True;
        }
    }

getNetworkConnectionList

The following code:

 
# We can only use the nettcpip module in PowerShell 3.0 or later

if ($PSVersionTable.PSVersion.Major -ge 3) {
    Get-NetTCPConnection | ForEach-Object {
        "protocol: TCP";
        "local_ip_addr: {0}" -f $_.LocalAddress;
        "local_port: {0}" -f $_.LocalPort;
        "remote_ip_addr: {0}" -f $_.RemoteAddress;
        "remote_port: {0}" -f $_.RemotePort;
        "state: {0}" -f $_.State;
        "pid: {0}" -f $_.OwningProcess;
        "";
    };

    Get-NetUDPEndpoint | ForEach-Object {
        "protocol: UDP";
        "local_ip_addr: {0}" -f $_.LocalAddress;
        "local_port: {0}" -f $_.LocalPort;
        "state: Listen";
        "pid: {0}" -f $_.OwningProcess;
        "";
    };
}
else {
    # We can still get network connection information on older PowerShell versions, its just a bit ugly
    [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties().GetActiveTcpConnections() | ForEach-Object {
        "protocol: TCP";
        "local_ip_addr: {0}" -f $_.LocalEndpoint.Address.IPAddressToString;
        "local_port: {0}" -f $_.LocalEndpoint.Port;
        "remote_ip_addr: {0}" -f $_.RemoteEndpoint.Address.IPAddressToString;
        "remote_port: {0}" -f $_.RemoteEndpoint.Port;
        "state: {0}" -f $_.State;
        "";
    };

    [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties().GetActiveTcpListeners() | ForEach-Object {
        "protocol: TCP";
        "local_ip_addr: {0}" -f $_.Address.IPAddressToString;
        "local_port: {0}" -f $_.Port;
        "state: Listen";
        "";
    };

    [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties().GetActiveUdpListeners() | ForEach-Object {
        "protocol: UDP";
        "local_ip_addr: {0}" -f $_.Address.IPAddressToString;
        "local_port: {0}" -f $_.Port;
        "state: Listen";
        "";
    };
}

is replaced with:

Get-NetTCPConnection | ForEach-Object {
    "protocol: TCP";
    "local_ip_addr: {0}" -f $_.LocalAddress;
    "local_port: {0}" -f $_.LocalPort;
    "remote_ip_addr: {0}" -f $_.RemoteAddress;
    "remote_port: {0}" -f $_.RemotePort;
    "state: {0}" -f $_.State;
    "pid: {0}" -f $_.OwningProcess;
    "";
};

Get-NetUDPEndpoint | ForEach-Object {
    "protocol: UDP";
    "local_ip_addr: {0}" -f $_.LocalAddress;
    "local_port: {0}" -f $_.LocalPort;
    "state: Listen";
    "pid: {0}" -f $_.OwningProcess;
    "";
};

getIPAddresses

The following code is added:

 
                $ip_aliases = Invoke-RestMethod -TimeoutSec 5 -Headers $TW_CLOUD_IMDS_HEADERS -Uri "http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/$id/ip-aliases/" -ErrorAction SilentlyContinue;
                $ip_aliases | ForEach-Object {
                $alias_ip = Invoke-RestMethod -TimeoutSec 5 -Headers $TW_CLOUD_IMDS_HEADERS -Uri "http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/$id/ip-aliases/$_" -ErrorAction SilentlyContinue;

                # Comes in form 10.11.12.0/24
                $ip_addr, $cidr = $alias_ip -split "/";

                # Convert CIDR notation to dotted-decimal format
                $shift = 64 - $cidr
                [System.Net.IPAddress]$netmask = 0
                if ($cidr -ne 0) {
                    $netmask = [System.Net.IPAddress]::HostToNetworkOrder([int64]::MaxValue -shl $shift)
                }

                "interface_id: nic{0}" -f $id;
                "ip_addr: {0}" -f $ip_addr;
                "netmask: {0}" -f $netmask.IPAddressToString;
                "address_type: IPv4";
                "scope: tw:internet";
                "";
                };

getProcessList

The following code:

 
    # Need to invoke getOwner method which is different in older PowerShell
    # versions. It also seems to be unavailable for some processes ...

    try {
        if ($PSVersionTable.PSVersion.Major -lt 3) {
            $owner = Invoke-WmiMethod -InputObject $_ -Name getOwner -ErrorAction SilentlyContinue;
        } else {
            $owner = Invoke-CimMethod -InputObject $_ -MethodName getOwner -ErrorAction SilentlyContinue;
        }
        if ($owner) {
            $user = $owner.User;
            $domain = $owner.Domain;

is replaced with:

    # Need to invoke getOwner. It seems to be unavailable for some processes

    try {
        $owner = Invoke-CimMethod -InputObject $_ -MethodName getOwner -ErrorAction SilentlyContinue;
        if ($owner) {
            $user = $owner.User;
            $domain = $owner.Domain;

getDeviceInfo

The following code:

$cs = Get-CIMInstance -Class Win32_ComputerSystem;
"hostname: {0}" -f $cs.Name;

$fqdn = [System.Net.Dns]::GetHostByName($env:computerName).HostName;
"fqdn: {0}" -f $fqdn;
"domain: {0}" -f $cs.Domain;

is replaced with:

$cs = Get-CIMInstance -Class Win32_ComputerSystem;
"hostname: {0}" -f $cs.Name;
try {
    $fqdn = [System.Net.Dns]::GetHostByName($env:computerName).HostName;
    "fqdn: {0}" -f $fqdn;
}
catch {
}
"domain: {0}" -f $cs.Domain;

Linux

getIPAddresses

The following code:

  
    # GCE public IPs
    if [ "$TW_CLOUD_PLATFORM" = "GCE" ]; then
        interfaces=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/ 2>/dev/null | sed -e 's#/$##'`
        for i in $interfaces
        do
            mac=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/$i/mac 2>/dev/null`
            public_ip=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/$i/access-configs/0/external-ip 2>/dev/null`
            echo "$i: nic$i: <UP> mtu 1500 state UP"
            echo "    link/ether $mac brd ff:ff:ff:ff:ff:ff"
            echo "    inet $public_ip/0 brd 0.0.0.0 scope tw:internet nic$i"
        done
    fi

is replaced with:

    # GCE public and alias IPs
    if [ "$TW_CLOUD_PLATFORM" = "GCE" ]; then
        interfaces=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/ 2>/dev/null | sed -e 's#/$##'`
        for i in $interfaces
        do
            mac=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/$i/mac 2>/dev/null`
            public_ip=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/$i/access-configs/0/external-ip 2>/dev/null`
            ip_aliases=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/$i/ip-aliases/ 2>/dev/null`
            echo "$i: nic$i: <UP> mtu 1500 state UP"
            echo "    link/ether $mac brd ff:ff:ff:ff:ff:ff"
            echo "    inet $public_ip/0 brd 0.0.0.0 scope tw:internet nic$i"
            for a in $ip_aliases
            do
                alias_ip=`$TW_CLOUD_IMDS_CMD/instance/network-interfaces/$i/ip-aliases/$a 2>/dev/null`
                echo "    inet $alias_ip brd 0.0.0.0 scope tw:internet nic$i"
            done
        done
    fi

initialise

The following code is added:

 
    PRIV_NSENTER() {
        "$@"
    }
...
    # nsenter requires superuser privileges to run commands in alternative
    # namespaces
    PRIV_NSENTER() {
        "$@"
    }
...
    # nsenter requires superuser privileges to run commands in alternative
    # namespaces
    PRIV_NSENTER() {
        "$@"
    }

Solaris

getHostInfo

The following code:

  
if [ `uname -p` = i386 ]; then
    echo 'begin prtconf:'
    /usr/sbin/prtconf 2>/dev/null | egrep "System Configuration:"
    echo 'end prtconf'

    if [ -x /usr/sbin/smbios ]; then
        /usr/sbin/smbios -t SMB_TYPE_SYSTEM 2>/dev/null | nawk '{
            if( $1 ~ /Manufacturer:/ ) { sub(".*Manufacturer: *","");  printf( "vendor: %s\n", $0 ); }
            if( $1 ~ /Product:/ ) { sub(".*Product: *",""); printf( "model: %s\n", $0 ); }
            if( $1 ~ /Serial/ && $2 ~ /Number:/ ) { sub(".*Serial Number: *",""); printf( "serial: %s\n", $0 ); }
        }'
        /usr/sbin/smbios -t SMB_TYPE_MEMDEVICE 2>/dev/null | nawk '
/Size: [0-9]+/ { RAM+=$2 }
END { printf("ram: %dkB\n", RAM/1024) }
'
    else
        if [ -f /usr/sbin/dmidecode ]; then
            PRIV_DMIDECODE /usr/sbin/dmidecode 2>/dev/null | nawk '/DMI type 1,/,/^Handle 0x0*[2-9]+0*/ {
                if( $1 ~ /Manufacturer:/ ) { sub(".*Manufacturer: *","");  printf( "vendor: %s\n", $0 ); }
                if( $1 ~ /Product/ && $2 ~ /Name:/ ) { sub(".*Product Name: *",""); printf( "model: %s\n", $0 ); }
                if( $1 ~ /Serial/ && $2 ~ /Number:/ ) { sub(".*Serial Number: *",""); printf( "serial: %s\n", $0 ); }
            }'
        fi
    fi
else
    # Solaris SPARC
    echo 'begin prtconf:'
    /usr/sbin/prtconf 2>/dev/null | egrep "System Configuration:|Memory size:"
    echo 'end prtconf'

    # Use prtdiag if possible
    run_prtdiag=1
    if [ -x /usr/bin/zonename ]; then
        # Solaris 10 or later, check this is the global zone before attempting
        # to run prtdiag
        if [ `/usr/bin/zonename 2>/dev/null` != "global" ]; then
            # Non global zone, don't run prtdiag
            run_prtdiag=0
        fi
    fi

    if [ $run_prtdiag -eq 1 ]; then
        if [ -x /usr/platform/`uname -m`/sbin/prtdiag ]; then
            platdir=/usr/platform/`uname -m`/sbin
        elif [ -x /usr/platform/`uname -m`/sbin/sparcv9/prtdiag ]; then

is replaced with:

# Collect the CPU type once
cpu_type=`uname -p`

# smbios, demidecode and prtconf are not available in non global zones
global_zone=1
if [ -x /usr/bin/zonename ]; then
    # Solaris 10 or later, check this is the global zone before attempting
    # to run smbios and dmidecode
    if [ `/usr/bin/zonename 2>/dev/null` != "global" ]; then
        # Non global zone, do not run smbios and dmidecode
        global_zone=0
    fi
fi

echo 'begin prtconf:'
if [ $cpu_type = i386 ] && [ $global_zone -eq 1 ]; then
    # i386/AMD64 in global zone will collect memory further down
    /usr/sbin/prtconf 2>/dev/null | egrep "System Configuration:"
else
    /usr/sbin/prtconf 2>/dev/null | egrep "System Configuration:|Memory size:"
fi
echo 'end prtconf'
# Only global zone can run smbios, dmidecode and prtdiag
if [ $global_zone -eq 1 ]; then
    if [ $cpu_type = i386 ]; then
        if [ -x /usr/sbin/smbios ]; then
            /usr/sbin/smbios -t SMB_TYPE_SYSTEM 2>/dev/null | nawk '{
                if( $1 ~ /Manufacturer:/ ) { sub(".*Manufacturer: *","");  printf( "vendor: %s\n", $0 ); }
                if( $1 ~ /Product:/ ) { sub(".*Product: *",""); printf( "model: %s\n", $0 ); }
                if( $1 ~ /Serial/ && $2 ~ /Number:/ ) { sub(".*Serial Number: *",""); printf( "serial: %s\n", $0 ); }
            }'
            /usr/sbin/smbios -t SMB_TYPE_MEMDEVICE 2>/dev/null | nawk '
/Size: [0-9]+/ { RAM+=$2 }
END { printf("ram: %dkB\n", RAM/1024) }
'
        else
            if [ -f /usr/sbin/dmidecode ]; then
                PRIV_DMIDECODE /usr/sbin/dmidecode 2>/dev/null | nawk '/DMI type 1,/,/^Handle 0x0*[2-9]+0*/ {
                    if( $1 ~ /Manufacturer:/ ) { sub(".*Manufacturer: *","");  printf( "vendor: %s\n", $0 ); }
                    if( $1 ~ /Product/ && $2 ~ /Name:/ ) { sub(".*Product Name: *",""); printf( "model: %s\n", $0 ); }
                    if( $1 ~ /Serial/ && $2 ~ /Number:/ ) { sub(".*Serial Number: *",""); printf( "serial: %s\n", $0 ); }
                }'
            fi
        fi
    else
        # Solaris SPARC
        if [ -x /usr/platform/`uname -m`/sbin/prtdiag ]; then
            platdir=/usr/platform/`uname -m`/sbin
        elif [ -x /usr/platform/`uname -m`/sbin/sparcv9/prtdiag ]; then




 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*