Saturday, November 28, 2015

SCOM 2012 Network Monitoring: Rename network adapter "PORT-xxx"

Scenario:
Everyone who has implemented SCOM 2012 Network Monitoring will be satisfied with the improvements with respect to SCOM 2007. More and more devices can be deeply monitored with SCOM 2012. One of the downsides at this moment is the naming of the Network Adapters. The name inside SCOM does not always reflect the name on the switch. The alerts send for this network adapters will also contain the DisplayName. The subject of the alert with the above naming will be something like 'Interface PORT-0.15 is flapping'. This alert is not very useful. Sounds familiar?


Solution:
Following XML Management Pack from Arjan Vroege will change the DisplayName of your network adapters in SCOM. The standard names of the network adapters cannot be changed through the standard configuration settings. With this Management Pack the names will be changed by using SNMP variables.
After downloading the MP and importing it your existing Network adapters will be renamed with the following naming convention:

$Displayname = $NodeSysName + " -- " + $Description + " -- " + $InterfaceAlias


This information is collected by SCOM through the Network Discovery and are SNMP variables. If you want to change them you have to change the discovery of the Management Pack. You can find and change the discovery in the Authoring section of SCOM.

<?xml version="1.0" encoding="utf-8"?>
<ManagementPack SchemaVersion="2.0" ContentReadable="true" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Manifest>
    <Identity>
      <ID>Network.Monitoring.ChangeNetworkAdapter</ID>
      <Version>1.0.0.0</Version>
    </Identity>
    <Name>Network.Monitoring.ChangeNetworkAdapter</Name>
    <References>
      <Reference Alias="Windows">
        <ID>Microsoft.Windows.Library</ID>
        <Version>7.5.8501.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
      <Reference Alias="System">
        <ID>System.Library</ID>
        <Version>7.5.8501.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
      <Reference Alias="SNL">
        <ID>System.NetworkManagement.Library</ID>
        <Version>7.1.10226.0</Version>
        <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
      </Reference>
    </References>
  </Manifest>
  <Monitoring>
    <Discoveries>
      <Discovery ID="Network.Monitoring.ChangeNetworkAdapter.Network.Monitoring.ChangeNetworkAdapter.Discovery" Target="SNL!System.NetworkManagement.NetworkAdapter" Enabled="true" ConfirmDelivery="false" Remotable="true" Priority="Normal">
        <Category>Discovery</Category>
        <DiscoveryTypes>
          <DiscoveryClass TypeID="SNL!System.NetworkManagement.NetworkAdapter" />
        </DiscoveryTypes>
        <DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
          <IntervalSeconds>86400</IntervalSeconds>
          <SyncTime>04:00</SyncTime>
          <ScriptName>NetworkAdapterChange.ps1</ScriptName>
          <ScriptBody>

    # NetworkAdapterChange.ps1
    # Written by Arjan Vroege. All rights reserved.

    param($SourceID, $ManagedEntityID, $Key, $Description, $InterfaceAlias, $DeviceKey, $NodeSysName, $CurDisplayName)
    $Displayname = $NodeSysName + " -- " + $Description + " -- " + $InterfaceAlias

    if ($CurDisplayName -eq $DisplayName) { continue }
    
    $scomapi = new-object -comObject "MOM.ScriptAPI"
    $DiscData = $scomapi.CreateDiscoveryData(0, $SourceID, $ManagedEntityID)

    #fill out the key properties
    $NetworkAdapter = $DiscData.CreateClassInstance("$MPElement[Name='SNL!System.NetworkManagement.NetworkAdapter']$")
    $NetworkAdapter.AddProperty("$MPElement[Name='SNL!System.NetworkManagement.NetworkAdapter']/Key$", $Key)
    $NetworkAdapter.AddProperty("$MPElement[Name='SNL!System.NetworkManagement.Node']/DeviceKey$", $DeviceKey)
    $NetworkAdapter.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $Displayname)
    $scomapi.LogScriptEvent("NetworkAdapterChange.ps1",101,2, "Discovery was executed for $Devicekey and Current: $curDisplayName --&gt; new: $Displayname")

    # add the WebSite to the DiscoveryData object
    $discData.AddInstance($NetworkAdapter)
    $discData
  </ScriptBody>
          <Parameters>
            <Parameter>
              <Name>SourceID</Name>
              <Value>$MPElement$</Value>
            </Parameter>
            <Parameter>
              <Name>ManagedEntityID</Name>
              <Value>$Target/Id$</Value>
            </Parameter>
            <Parameter>
              <Name>Key</Name>
              <Value>$Target/Property[Type="SNL!System.NetworkManagement.NetworkAdapter"]/Key$</Value>
            </Parameter>
            <Parameter>
              <Name>Description</Name>
              <Value>$Target/Property[Type="SNL!System.NetworkManagement.NetworkAdapter"]/Description$</Value>
            </Parameter>
            <Parameter>
              <Name>InterfaceAlias</Name>
              <Value>$Target/Property[Type="SNL!System.NetworkManagement.NetworkAdapter"]/InterfaceAlias$</Value>
            </Parameter>
            <Parameter>
              <Name>DeviceKey</Name>
              <Value>$Target/Host/Property[Type="SNL!System.NetworkManagement.Node"]/DeviceKey$</Value>
            </Parameter>
            <Parameter>
              <Name>NodeSysName</Name>
              <Value>$Target/Host/Property[Type="SNL!System.NetworkManagement.Node"]/sysName$</Value>
            </Parameter>
            <Parameter>
              <Name>CurDisplayName</Name>
              <Value>$Target/Property[Type="System!System.Entity"]/DisplayName$</Value>
            </Parameter>
          </Parameters>
          <TimeoutSeconds>60</TimeoutSeconds>
          <StrictErrorHandling>true</StrictErrorHandling>
        </DataSource>
      </Discovery>
    </Discoveries>
  </Monitoring>
  <LanguagePacks>
    <LanguagePack ID="ENU" IsDefault="true">
      <DisplayStrings>
        <DisplayString ElementID="Network.Monitoring.ChangeNetworkAdapter.Network.Monitoring.ChangeNetworkAdapter.Discovery">
          <Name>Network.Monitoring.ChangeNetworkAdapter.Discovery</Name>
          <Description>Description for the new discovery.</Description>
        </DisplayString>
      </DisplayStrings>
      <KnowledgeArticles></KnowledgeArticles>
    </LanguagePack>
  </LanguagePacks>
</ManagementPack>

In next article I'll show you how to "convert" GENERIC network device (Juniper EX4550 and Dell Force10 MXL 10/40GbE) to CERTIFIED using just Notepad and no XML MP development effort.

References: