5. IMPLEMENTATION
5.4 Creating Maps
The Switch devices discovered need to be represented by images/icons. These representations need to be laid out and displayed in a map.
The map also displays the links, representing the physical connections between the Switches as well as other devices. Apart from this, individual Switch device is represented as an actual model of the physical equipment. This is called Chassis view. In this view, the Switch device with Shelves, Slots, Cards, and Ports are displayed in a NMS Frame.
This chapter explains the procedure to achieve the following tasks using AdventNet Web NMS Eclipse Plugin:
• Adding Custom map and configuring the custom map in maps.conf file
• Creating Map Filter for the Switch devices
• Customizing Map filter code to change the symbol of the Link and configuring the filter in mapIcon.data file
• Creating Chassis view using Chassis wizard
5.4.1 Adding Custom Map - Switch Map
If we want to display a map of all the switches and the trunks connecting the switches, creating a custom map showing all the switches and trunks in one map is straightforward solution. This topic deals with adding custom Maps in this application.
Using Eclipse Plugin to Add Custom Maps
For adding the Switch Map for this application you need to import the maps.conf configuration file into the EMS Development project created earlier for this tutorial. In the project, steps to edit the
maps.conf file were followed and the nodes and their details were added.
You can add or edit the node or modify the existing node directly as per your requirement using the UI.
Modifying maps.conf File for Adding Switch Map
Use the Import WebNMS Conf files wizard to import the maps.conf configuration file into the EMS Development project from the WebNMS installation that is used for developing this project.
Refer the section Working with Files in Eclipse Guide for more details on how to import maps.conf to Eclipse.
Open the conf file in the editor to define the new entry for this custom map.
For displaying a map of all the switches and the trunks connecting the switches, simply add the following code to the maps.conf file.
<MAP_CONFIG>
<map
label="Switches"
index="0"
treeIconFileName="images/maps.png"
helpDoc="help/userguide/use_map_client.html"
autoPlacement="true"
anchored="false"
imageName="ems_tut_white.png"
mapSymbolRenderer="com.adventnet.nms.mapui.MapSymbolRendererImpl_3
topology="$ring"
currentTopology="ring"
mapname="Switches.netmap">
<criteria type="Switch,Trunk" />
5.4.2 Creating Map Filter
Aim
To create link symbols automatically for each trunk in the Switches map.
Creating a Map Filter
Follow the steps given below to define a Map filter. For details on Creating Map Filter, refer to the Web NMS EclipsePlugin Guide.
Step 1 : Invoking the MapFilter Creation Wizard
Select WebNMS > Filters > Map > Create Map Filter menu.
Step 2 : Map Filter Details
Provide the following details about the Map Filter:
Package Name - com.adventnet.nms.tutorials.ems Filter ClassName - TrunkMapFilter
Click Finish..
You will find the <Map Filter class> under <Your Project>/source folder in the Project Explorer window.
You can add the custom code or modify the existing code of the source using the editor directly as per your requirement.
The entry for this MapFilter implementation class will be appended to the map.filters configuration file present in <Your Project>/resources/conf directory. You can rearrange the entries as per your requirement as the filters will be invoked based on the order in which they are listed in this file.
The details of the custom code added to the Map filter class are discussed in the next topic.
5.4.3 Customizing Map Filter Code
This topic deals with the custom code added to the Map filter class (TrunkMapFilter). This custom code is meant for changing the symbol automatically generated for each trunk into a link on the map.
Custom Code Specific to the Tutorial Application Requirements
The following custom code has been added to map filter to change the symbol automatically generated for each trunk to a link on the map.
Add the implementation code for the filterMapSymbols method of the MapFilter as shown below:
if((!(mo instanceof Trunk ))) {
Eclipse Plugin will automatically put entry in map.filters located in <Web NMS Home>/conf directory when a NAR is installed. The entry will be as shown below.
5.4.4 Creating Chassis View
In this section, we will discuss how the discovered Switch along with its sub-components such as Shelf, Slot, etc. is represented.
The Switch with its sub-components will be represented as a Chassis.
The Chassis can be built as a UI in two ways:
1. Using Map APIs of AdventNet Web NMS
2. Using Chassis Wizard of AdventNet Client Builder
For details on How to build the Chassis using Chassis Wizard of AdventNet Client Builder, refer to Building the Chassis section of this tutorial documentation.
In this tutorial, the Switch is being represented as a Chassis with the help of Chassis Wizard of AdventNet Client Builder.
Creating Chassis View Using the AdventNet Client Builder
• The Chassis is built as a separate project using the Chassis Wizard of the AdventNet Client Builder.
• The project is compiled and packaged as a NAR.
• This NAR is then imported into the EMS Project.
• Now, the Chassis view of the Switch will become part of the EMS application.
Importing the Chassis NAR in the EMS Application
• Select the project in the Package Explorer.
• Select WebNMS > Import Client Nar menu. Client Application Import Wizard" screen pops up.
• In the Client Application Import Wizard screen, Select the ChassisScreen.nar from <Web NMS Home>/StudioTools/ClientBuilder directory using the Browse button.
• Click Next button to view the Users Information page.
• In the " Users Information" page , select the users for whom the Nar has to be installed.
• Click Next button to view the Menu Details page.
• In the "Menu Details" screen configure the Map Menu details. Enter Map Menu File , Menu Item name and the name of the Map Icon File. Enter Menu Name as SwitchMenu (this is the new SwitchMenu.xml menu file that we will create as part of this application. This menu should be placed in the <EMS Project>/resources/mapdata/menus directory) and Menu Item Name as ChassisView
• Click Finish button.
The NAR is imported in the EMS Application.
The Final Output
The Chassis is represented as a dynamic view, i.e., the view will be automatically updated based on the status of the components. The Chassis is built based on the corresponding Switch
ManagedObject added to the Web NMS database.
This application can be invoked from the device node in the Switch -> Chassis View.
5.5 Fault Management of Switch Devices
To receive, process the failures in the managed network elements (i.e., Switches) and present it in a meaningful form, you have to implement Fault management service of AdventNet Web NMS. The Switch notifies any abnormality in the operations, parameters and failures to the EMS application in the form of traps
Processing Alerts and Events of Switch device
You have to process the events of the Switch received through the traps to convert it into a meaningful alert.
Create a Trap filter to process the traps. In the application you will be creating a filter called TrapHandling. Add Custom code to handle Addition of Card and Deletion of Card. Model the managed object to check the device status (a method in the Managed Object class to check the status; here, it is the checkStatus() method).
Status polling of Switch device
You have to ensure that EMS gets the status of the Switch and its components periodically. This will be updated in the database and displayed in the Client.
The tutorial explains how to customize the Fault management features.
• The Trap handling topic explains how to process traps effectively.
• The Status polling topic deals in a detailed manner on how to carryout surveillance of Switch and components periodically.
5.5.1 Creating Trap Filter
Aim
To provide a complete Switch management capability to the EMS with effective Trap handling and periodic status polling.
Tasks
• Convert the failure notifications (Traps) into meaningful Event Objects using the Trap Filter Wizard
• Status Poll the Switch Device and its components using the Status Poller Wizard.
Instructions
Follow the steps given below to define a Trap Filter and after completion proceed to the Status Poller Wizard. For details on Creating Trap Filter, refer to the Web NMS EclipsePlugin Guide.
Step 1: Invoking the TrapFilter Creation Wizard
Select WebNMS > Filters > Fault > Create Trap Filter menu
Step 2 : Trap Filter Details
Provide the following details about the Trap Filter
Package Name - com.adventnet.nms.tutorials.ems Filter ClassName - TrapHandling
Enter the Match Criteria for filtering the trap. It includes V1 Trap, V2 Trap. For V1 Trap , enter the Enterprise OID , Generic Trap Type and Specific Trap Type. For V2 Trap , enter the Trap OID.
Enterprise OID * Generic Trap Type 6 Specific Trap Type 100 Click Finish.
You will find the <Trap Filter class> under <Your Project>/ source folder in the Project
The appropriate entry for this trap filter will be appended in the trap.filters file in the <Your
Project>/resources/conf folder. You can rearrange the entries in this file as per your requirement to change the order in which the trap.filters are invoked.
The details of the custom code added to the Trap filter class is discussed in the next topic.
5.5.2 Customizing Trap handling filter's code
In this application, we have tried to simulate a real time situation in which cards are removed or added physically from a Switch. Whenever a card is removed or added, the agent in the device sends a trap to the manager and notifies the problem. To simulate this condition, we will send separate SNMP V1 traps for adding and removing the cards. To process the trap, we need to associate a trap filter.
This topic deals with creating a trap filter called TrapHandling.
Custom code specific to the tutorial application requirements
TrapHandling is the trap filter, which does the addition and removal of cards based on the trap received.
Incorporate the implementation code for the TrapFilter as shown below. The trap filter is designed to perform three separate tasks:
1. It will parse the incoming trap and convert it to an Event and add it to the WebNMS system assigning the appropriate severity.
2. Check if it is a trap denoting the Card deletion. Then it will delete the corresponding card in the topology database.
3. Check if it is a trap denoting the card addition. Then it will add the corresponding card into the topology database.
For parsing the snmp trap and converting it into an event the following custom code is added to the TrapHandling class inside the auto-generated stub for applyTrapFilter method:
//creating the new event object Event event = new Event( );
if(pdu.getVersion() == SnmpAPI.SNMP_VERSION_1) {
NmsLogMgr.EVENTUSER.log("Trap version is V1 ",Log.DEBUG);//No I18N
NmsLogMgr.EVENTUSER.log("Trap EnterpriseOID is :"+pdu.getEnterprise().toString() ,Log.DEBUG);//No I18N
NmsLogMgr.EVENTUSER.log("Trap Generic type is :"+pdu.getTrapType(),Log.DEBUG);//No I18N
NmsLogMgr.EVENTUSER.log("Trap Specific type is :"+pdu.getSpecificType(),Log.DEBUG);//No I18N }
else {
if(pdu.getVersion() == SnmpAPI.SNMP_VERSION_3 )
//Handling the trap of type Card Deleted.
if((pdu.getTrapType() == 6 ) && ( pdu.getSpecificType() == 100)) {
// INSERT THE CODE FOR DELETION OF CARD HERE.
//Setting the properties of the Event object from the received Trap PDU.
event.setText(pdu.getAgentAddress().getHostName()+"_Shelf1_"+slotName+"_Card is deleted");//No I18N
event.setEntity(pdu.getAgentAddress().getHostName()+"_Shelf1_"+slotName+"_Card"
//No I18N
event.setSource(pdu.getAgentAddress().getHostName());
event.setSeverity(1);
NmsLogMgr.EVENTUSER.log("Returned Event properties in TrapHandling are :
"+event.getProperties().toString(),Log.DEBUG);//No I18N
//Setting the event properties from the received Trap PDU.
event.setText(pdu.getAgentAddress().getHostName()+"_Shelf1_"+slotName+"_Card is added");//No I18N
event.setEntity(pdu.getAgentAddress().getHostName()+"_Shelf1_"+slotName+"_Card");
//No I18N
event.setSource(pdu.getAgentAddress().getHostName());
NmsLogMgr.EVENTUSER.log("Returned Event properties in TrapHandling are : "+event.getProperties().toString(),Log.DEBUG);//No I18N
return event;
}
For Deletion of Card the following custom code is added to the TrapHandling class inside the if loop which checks for the Trap with Generic Type as 6 and Specific Type as 100
//Retrieving the card object from the database and deleting it.
try { Card
card=(Card)api.getByName(pdu.getAgentAddress().getHostName()+"_Shelf1_"+slotNam //No I18N
Properties p=new Properties();
p.put("parentKey",card.getName());//No I18N Vector v=api.getObjectNamesWithProps(p);
boolean b=api.deleteObject(card,false,false);
if(b) {
for (Enumeration e = v.elements() ; e.hasMoreElements() ;) {
boolean
bool=api.deleteObject(api.getByName((String)e.nextElement()),false,false);
} } }
catch(Exception e) {
System.err.println(" Error while deleting card");//No I18N return pdu; //log the trap message
}
Since the card and its children need to be deleted, we need to get the corresponding Card object.
Using the Topo API handle, the api.getByName() method returns the Managed Object corresponding to the card.
The TopoAPI method deleteObjectAndSubElements() deletes the ManagedObject specified (Card) and its children (Ports). Once the object is deleted from the database, the map module is notified and it in turn deletes these Objects from the Map database.
If a new card is inserted then in the received trap we will get the slot number where the card needs to be added and accordingly add the card and ports. The code snippet for Addition of Card is as given below. Add the code inside the if loop which checks for the Trap with Generic Type as 6 and Specific Type as 200
//Retrieving the Slot object from the database to which a card has been added.
try{
String ifObjectName= pdu.getAgentAddress().getHostName();
Switch sw=(Switch)api.getByName(ifObjectName);
Slot
slot=(Slot)api.getByName(ifObjectName+"_Shelf1_"+slotName);//
No I18N
//Invoking the addCard method that will take care of adding the card object to the database.
SwitchDiscoveryFilter.addCard(slot,sw,api);
}
catch(RemoteException e) {
System.err.println("Unable to get the managed object");
//No I18N
return pdu; //log the trap message }
catch(Exception e) {
System.err.println(" Error while adding card");//No I18N return pdu; //log the trap message
}
The name of the agent (Device) from which the trap was received can be obtained from the
pdu.getAgentAddress().getHostName() method. Using the Topo API handle we will get the Managed Object of the device as done before. As we need to add the cards and its children in the specified slot we need to get the Slot Object of the corresponding slot. This can be obtained by the following
method.
Slot slot=(Slot)api.getByName(ifObjectName+"_Shelf1_"+slotName);
After getting the slot object we will invoke the addCard() method of the SwitchDiscoveryFilter which
5.5.3 Status Polling
You need to ensure the status of the Managed Objects are monitored and displayed in the Client UI.
For each type of device, Web NMS performs status polling of these devices based on the configuration.
For each managed object, it invokes the status polling specified by the configuration, which may be a standard operation like pinging the device already supported by Web NMS or a custom polling that is needed for a specific device or component.
You can override the status polling code for your managed object. You will see how the Port object is used, for which you will poll the operational status of an interface corresponding to the port number on a card.
The custom code for achieving the above task is added to the Port object as explained in the Implementation > Modeling the Switch and its components > Customizing Port object topic of this tutorial document.