Creating Maps and Map Objects in WebNMS Framework

Creating Maps through Map Filters

nms-switches-map-filter

Map filter is a powerful mechanism to create maps and map symbols, as depicted above. Developers can write their own map filter by implementing com.adventnet.nms.mapdb.MapFilter or com.adventnet.nms.mapdb.ExtendedMapFilter interfaces. The extended map filter is an enhancement over the MapFilter interface. Map filters are capable of reacting to additions (notifications with "type" as added) in the TopoDB, whereas extended map filters are reactive to any updates (notifications with "type" as added or updated or deleted) in the TopoDB.

All custom map filter classes should have an entry in map.filters or mapIcon.data files. This is a very important step because map server, on initialization, reads these files and initializes the map filters that are mentioned there. If developers fail to give an entry for your map filter in any of these files then your filter will not be invoked.

  • Note on MapFilter Class: filterMapSymbols(Vector mapSymbs, ManagedObject obj, MapAPI api) is the method present inside the MapFilter interface. This method is invoked on addition of every MO in the topology database. You can write a class implementing the MapFilter interface and provide your own implementation for this method based on your requirement. Refer to Javadocs of MapFilter interface for more details.
  • Note on ExtendedMapFilter Class: update(String type, ManagedObject obj, MapAPI api) is the method that is present in ExtendedMapFilter interface in addition to the filterMapSymbols() method. This method gets invoked for the following "type" of updates on the MO in topology database. Developers have to write a class implementing the ExtendedMapFilter interface and write your implementation for the update() method based on their requirement.

Switch Map Filter Example

One of the best layout renderest that the WebNMS has been implemented is the "switch" topology. In this example we will show how to implement a filter that renders the HP V1910 family of network switches in amaizingly eye-candy way. 

Let's start with the mandatory part, definition of the method:

public class BaselineSwitchMapFilter implements MapFilter {
TopoAPI topoapi = null;
String switchMap = "Switches.netmap";
String routerMap = "RouterMap.netmap";
String suffix =".netmap";
boolean traceMap= false;

@SuppressWarnings("unchecked")
public Vector filterMapSymbols( Vector mapSymbs, ManagedObject obj, MapAPI api ) throws NmsStorageException, UserTransactionException {

if ( obj instanceof Network )
return mapSymbs;

So we are not goint to bother with networks, the boolean traceMap is for the development debugging purpose, and we are forcing suppressing compiler warning. 

 if ( obj instanceof BaselineSwitch || obj instanceof CatalystSwitch) {
if (traceMap) NmsLogMgr.MAPUSER.log("SwitchMapFilter:: object " + obj.getName()+" is a Switch" , Log.SUMMARY);
try {

Vector mapNames = createMaps( (SwitchObject) obj, api );
if (traceMap) for( int z = 0; z < mapNames.size(); z++ ) {
if (traceMap) NmsLogMgr.MAPUSER.log("SwitchMapFilter:: Map Name in vector is" + (String) mapNames.elementAt(z) + " at index="+z, Log.SUMMARY);
}

 Next, the initial maps containing switch map containers and mapping port must be initiated. The ubiquitous aggregate "Switches", "Routers" and eventual parent networks will be rendered, having map symbols automatically relayed over "$switch" topology layout, and the symbols will be rendered using "com.adventnet.nms.mapui.SwitchMapRender" rendering engine. Any possible links on the map will be rendered utilizing built-in "com.adventnet.nms.mapui.MapLinkRender", as maps properties show below.

p.put("autoPlacement", String.valueOf( true ));
p.put("anchored", String.valueOf( true ));
p.put("treeIconFileName", "images/switch1" + NmsUtil.getImageType());
p.put("topology","$switch");
p.put("currentTopology","switch");
p.put("backgroundColor","255,255,255");
p.put("mapSymbolRenderer", "com.adventnet.nms.mapui.SwitchMapRenderer");
p.put("mapLinkRenderer", "com.adventnet.nms.mapui.MapLinkRendererImpl");
p.put("helpDoc", "default_impl/applications/help/SwitchMap.html");
p.put("HTML-TABLE","Infrastructure View");

Once maps initiated, the MapContainer interfaces have been created and based on the sysOID of the SnmpNode object it can be determine the type of the object, so appropriate switch "face plate" image and menu can be selected and apply to the container. The generated map symbols will be applied to the vector of symbols returned by the function.

MapContainer mapobject = null;
String sysoid = ((SnmpNode)obj).getSysOID();
if (traceMap) NmsLogMgr.MAPUSER.log("SwitchMapFilter:: Vector mapNames for " + obj.getName()+" created, length="+mapNames.size() , Log.SUMMARY);
for( int z = 0; z < mapNames.size(); z++ ) {
String mapName = (String) mapNames.elementAt(z);
if (traceMap) NmsLogMgr.MAPUSER.log("SwitchMapFilter:: Get mapName " + mapName + " at index="+z, Log.SUMMARY);
mapobject = (MapContainer) createMapObject( obj, "Container" );String switchType = null;

String menu = null;

if (UltraUtils.is3ComSwitch(sysoid) ) {switchType = "switchbaseline";menu = "baselineswitchmenu";}

else if (UltraUtils.isHPV1910Switch(sysoid) ) {switchType = "switchhpv1910";menu = "baselineswitchmenu";}
else if (UltraUtils.isCatalystSwitch(sysoid) ) {switchType = "switchcatalyst";menu = "catalystmenu";}
else {switchType = "switch2";menu ="hubmenu";}
mapobject.setMapName( mapName );
mapobject.setMenuName(menu);
mapobject.setObjType( 1 );
mapobject.setTopology("$switch");
mapobject.setCurrentTopology("switch");
mapobject.setParameter("label",obj.getDisplayName());
mapobject.setParameter("iconName",switchType+ NmsUtil.getImageType());
mapobject.setParameter("anchored", String.valueOf(false));
mapSymbs.addElement( mapobject );
}

The map symbols have to cloned, and the properties of the clones will be changed to accommodate the network element sysLocation property. This in turn generates a map for the network element "Site" map which contains map containers of all network elements that physically belong to a topology defined "communication room" entity.

MapContainer mapObjForSites= (MapContainer)mapobject.clone();
String location = null;
@SuppressWarnings("unused")
String iconName = null;
if (obj instanceof BaselineSwitch) {
location = ((BaselineSwitch)obj).getV1910SysLocation();
if (sysoid.startsWith(".1.3.6.1.4.1.43.1.8")){
iconName="baselineswitch"+ NmsUtil.getImageType();
}
else if(sysoid.startsWith(".1.3.6.1.4.1.25506.11.1"))
iconName="hpv1910switch"+ NmsUtil.getImageType();
else iconName="hpv1910-24gswitch"+ NmsUtil.getImageType();
}
else if (obj instanceof CatalystSwitch){
location= ((CatalystSwitch)obj).getCatSysLocation(); iconName="catalyst3750"+NmsUtil.getImageType();
}
else {
location = ((SwitchObject)obj).getUserProperty("sysLocation");
iconName="switch"+ NmsUtil.getImageType();
}
if (location != null && !location.equals("")) {
if (traceMap) NmsLogMgr.MAPUSER.log("SwitchMapFilter:: location is " + location, Log.SUMMARY);
mapObjForSites.setParameter("location", location);
mapObjForSites.setParameter("anchored", String.valueOf(false));
String site = UltraUtils.getSite(location);
if (traceMap) NmsLogMgr.MAPUSER.log("SwitchMapFilter:: location " + location + " is checked towards site "+ site , Log.SUMMARY);
if (site != null && api.doesTheMapExist(site+suffix)) {
if (traceMap) NmsLogMgr.MAPUSER.log("SwitchMapFilter:: " + site +".netmap exists", Log.SUMMARY);
mapObjForSites.setMapName( site+suffix );
mapSymbs.addElement( mapObjForSites );
}

Upon maping the swith ports, the beautiful switch map will be rendered as depicted below.

 nms-single-switch

The map filter source code can be download here. Please provide a valid address he file should be sent to the that e-mail address.

Go to top