Bulk import of SNMP devices to OpsMgr

If you want to import a larger bunch of SNMP-devices in to OpsMgr you will probably go thru the disovery wizard way to many times.

Instead of walking thru that wizard every time I asked the network team to write a CSV-file with all the devices and then used this function to import them.

Function Add-SnmpDevice {
        PARAM (
                [Parameter(Mandatory=$true )][string] $FromIpAddress,
                [Parameter(Mandatory=$true )][string] $MonitoringProxy,
                [string] $ManagementServer,
                [string] $ToIpAddress = "",
                [string] $SnmpCommunityString = "public",
                [int32] $SnmpVersion = 2
        )

        # Single ip ?
        If ($ToIpAddress.Length -eq 0) {
                $ToIpAddress = $FromIpAddress
        }

        # Check SNMP version
        if ($SnmpVersion -ne 1 -and $SnmpVersion -ne 2) {
                Throw "Only SNMP version 1 and 2 supported"
        }

        Write-Host "Setting up discovery for SNMP-devices..."
        Write-Host "       From: $($FromIpAddress)"
        Write-Host "         To: $($ToIpAddress)"
        Write-Host "  Community: $($SnmpCommunityString)"
        Write-Host "   SNMP ver: $($SnmpVersion)"

        $networkDeviceClass = Get-MonitoringClass -name "System.NetworkDevice"
        $DeviceDiscoveryConfig = New-DeviceDiscoveryConfiguration -MonitoringClass $networkDeviceClass -FromIpAddress $FromIpAddress -ToIpAddress $ToIpAddress

        # Set Community String
        $encoding = New-Object System.Text.UnicodeEncoding
        $encodedCommunityString = $encoding.GetBytes($SnmpCommunityString)
        $DeviceDiscoveryConfig.ReadOnlyCommunity = [System.Convert]::ToBase64String($encodedCommunityString)

        # Set SNMP version
        $DeviceDiscoveryConfig.SnmpVersion = $SnmpVersion

        # Get management server
        If ($ManagementServer.Length -eq 0) {
                $mgmtServer = Get-RootManagementServer
        } else {
                $mgmtServer = Get-ManagementServer | Where-Object {$_.Name -eq $ManagementServer}
        }
        If ($mgmtServer -eq $null) {
                Throw "Cant find management server named $($ManagementServer)"
        } else {
                Write-Host "Found management server: $($mgmtServer.name)"
        }

        # Find proxy agent
        Write-Host "Lookup of proxy agent named $($MonitoringProxy) ..."
        $ProxyAgent = Get-Agent | Where-Object {$_.Name -eq $MonitoringProxy}
        If ($ProxyAgent -eq $null) {
                Write-Host "No agent named $($MonitoringProxy) found, checking managementservers"
                $ProxyAgent = Get-ManagementServer | Where-Object {$_.Name -eq $MonitoringProxy}
                $ProxyIsMgmtServer = $true
        } else {
                $ProxyIsMgmtServer = $false
        }

        If ($ProxyAgent -eq $null) {
                Throw "Can't find agent or managementserver named $($MonitoringProxy)"
        } else {
                Write-Host "Found $($ProxyAgent.Name)"
        }

        Write-Host "Starting discovery..."
        $DiscResults = Start-Discovery -ManagementServer: $mgmtServer -DeviceDiscoveryConfiguration: $DeviceDiscoveryConfig

        If ($DiscResults.CustomMonitoringObjects.Count -eq 0) {
                Write-Host "Cant discover any objects"
                Return 0
        } else {
                $ObjectCount = 0
                Write-Host "Found objects"
                $discresults | select-object -expandproperty CustomMonitoringObjects | Select-Object Name | Format-Table -HideTableHeaders

                $DiscResults | ForEach-Object {
                        Write-Host "Adding object to proxy..."
                        if ($ProxyIsMgmtServer -eq $true) {
                                $ProxyAgent.InsertRemotelyManagedDevices($_.CustomMonitoringObjects) | Format-Table SnmpDevice, ProxyAgentPrincipalName, ManagementGroup -HideTableHeaders
                        } else {
                                Add-RemotelyManagedDevice -proxyagent $ProxyAgent -device $_.CustomMonitoringObjects
                        }
                        $ObjectCount++
                }
                Return $ObjectCount
        }
}

And two examples on how you can use it to add some devices:

# Add a devices in the range 192.168.100.240-.254 with the community "SomeSecret"
# Use mgmtserver.snowland.demo to do the discovery and add the devices with snmpmonitor.snowland.demo as monitoring proxy
Add-SnmpDevice -FromIpAddress "192.168.100.240" -ToIpAddress "192.168.100.254" -SnmpCommunityString "SomeSecret" -ManagementServer "mgmtserver.snowland.demo" -MonitoringProxy "snmpmonitor.snowland.demo"

# Add a single SNMPv1 device with the "public" community, use the RMS to do discovery
Add-SnmpDevice -FromIpAddress "192.168.100.10" -MonitoringProxy "snmpmonitor.snowland.demo" -SnmpVersion 1

So we ended up with something like this:

Import-Csv ".\snmplist.csv" -Delimiter ";" | ForEach-Object {
        Add-SnmpDevice -FromIpAddress $_.IpFrom -ToIpAddress $_.IpTo -SnmpCommunityString $_.Community -ManagementServer $_.MgmtServer -MonitoringProxy $_.Proxy
}

PSOL: Get-SNMPDevices

Quick and easy way to get a list of all OpsMgr monitored SNMP devices

Get-MonitoringClass -name 'System.NetworkDevice' | Get-MonitoringObject | Format-Table PathName, DisplayName

Jalasoft and SNMPv3

Got some info from my Jalasoft-contct… sad to say, but Jalasoft Xian doesn’t support SNMPv3.

It is being researched but due to the big differences with v2 we didn’t implement it yet. However it is very likely that in our next version we are going to support this.

Well, since you only need read-only SNMP rights it’s not that big problem, but v3 is way more secure than v2.


MOM & SNMP-MIB’ar

Den person som har testat importera MIBar i Windows mha smi2smir vet att det inte är helt enkelt.

Ska man övervaka SNMP-trappande saker (relativt enkelt) med MOM så är det första steget. Men med tanke på att det är ett smärre h-vete så har i alla fall jag oftast gett upp och skrivit ett script som tar hand om översättningen.

Egentligen lite fel att skriva “MOM &…” i rubriken, ska nog stå “Windows &…” med tanke på att MOM egentligen inte har någonting med saken att göra, det är Windows och Microsofts sätt att läsa MIBar som är kasst.

Pete Zerger har försökt reda ut en del av problemen på sin blogg. Mycket bra läsning.

This post is for MOM administrators using MOM as an SNMP Trap-catcher, as defined in

http://support.microsoft.com/kb/555455

In this post, I am going to offer some insight into addressing a common issue when compiling MIBs into WMI (MOF) format for MOM 2005 when using MOM as an SNMP trap-catcher, and offer a couple examples of an alternative that allows one to skip this process altogether.

Mer info på Pete’s Management BLOG.