DeviceBackup Policy - Example



Feature Overview

The word 'policy', in general, refers to a plan of action. Here, in Web NMS context, it refers to executing a task or set of tasks at a specified time based on a set of specified conditions. Policies are tasks that are executed by Web NMS at a system level, at a specified point of time. In Network Management, policies are used to control a variety of network activities like automated backups, routing & prioritization of network traffic, bandwidth allocation, cleaning up database tables, deleting failed nodes, etc.

This policy framework enables scalable administration of the Web NMS server and the network elements managed by it. The primary goal of the policy engine is to enable administration of complex functions easily. In Web NMS, policies can be used to customize the behaviour of the NMS and to provide a framework for adding policies for different network elements.

Web NMS policies can be broadly classified into two categories :

For more details, refer to the following section of our documentation : Developer Guide --> Policy Framework

Example Overview

Example name : DeviceBackup Policy
Related files : DeviceBackups.java
Location : <Web NMS Home>/default_impl/policies

This DeviceBackupPolicy explains how to take back up of the data of SNMP devices. In the event of loss of data due to human error, system crash or other disasters, the backedup data can be used to restore the device whose configuration is lost. This example illustrates how the backup can be taken for a MIB sub-tree on the device.

The class DeviceBackups extends PeriodicPolicyObject of com.adventnet.management.policydb package. Since DeviceBackups Policy is called at fixed time intervals for taking backup, it is advisable to extend the PeriodicPolicyObject class. In the constructor public DeviceBackups()  you can set the period for back up. In this example the time is set as one day.

The methods in DeviceBackupsPolicy are

public void setProperties(Properties p)

This method sets the User and Base properties for the policy object. The User Properties which are declared in deviceBackups() are  first removed and then set. This is done to avoid duplication of Property names.

The User Properties set are :

MIBs to be Loaded - This parameter can be used to load MIBs on the server before taking backups.  This allows using variable names instead of typing the entire object identifier when specifying the contents which are to be backedup.

MIB Sub-Tree to Backup - This is the object identifier for the sub-tree to collect data. You can use the label of the MIB node if the MIB is loaded, e.g. interfaces for the interfaces group.  Otherwise, you can use the numeric OID, e.g. .1.3.6.1.2.1.2 for the interfaces group.

Device Type - Enter the prefix of the device types, you wish to backup. For example, typing bay will backup the chosen MIB tree for all devices whose type begins with bay.

Backups Directory - This specifies where the files with backup data should be saved.  This directory will be created if required.

Maximum Data (variables) - The specified value is used to collect the maximum amount of data from a device. Some devices store a lot of MIB data, and this is to avoid collecting too much data when the OID is configured in error.  The default value of 1000 should meet most needs, but change it if you expect more than 1000 variables to be collected.

The Base Properties set are : GroupName,Status,Help URL and Period of  the policy object.

The "super.setBaseProperties()" method is invoked to set  the Base Properties.

Code Snippet

public  void executeAction(PolicyEvent policyEvt)
{
String mibs  = (String)getUserProperty("MIBs to be Loaded");
String subtree = (String)getUserProperty("MIB Sub-Tree toBackup")
.............................
SnmpTarget target = new SnmpTarget();
............................
Date now = new Date();
...........................
File dir = new File(PureUtils.rootDir+directory);
if (!dir.exists()) dir.mkdirs();
............................
Vector nodes = api.getNodes();
if (!node.getIsSNMP()) continue;

The execution of the policy begins from the above method. The OID for each class is checked and if the node is of SNMP, filtering is done for backup. SNMP target is instantiated and loading of Mibs begins. The present time is calculated for file creation to convert the same into the specified format. A directory is created, (if already not existing) to store back up data files. Once the nodes are fetched, it checks if it is a SNMP node and once it is confirmed, a file is created for each SNMP node and the details collected is written in a file. The data is stored in a dated file in the specified directory (default is DEVICE_DATA). The number of files created depends on the number of devices and the period between collections.

Working with the Example

Implementation has been provided for DeviceBackupPolicy by default. So, there is no need to make any classpath settings. However, if you want to customize the DeviceBackupPolicy.java file, you will have to integrate it with Web NMS in the following way.
Classpath Settings

Set the classpath as <WebNMS Home>\Adventnet SNMPV3\classes; <Web NMS Home>\ classes\AdventNetSNMP.jar; <WebNMS Home>\classes\AdventnetFramework.jar

Compiling and Bundling with Web NMS

Compile it over the destination directory using the following syntax in the command prompt.

javac -d <WebNMS Home>classesDeviceBackupsPolicy.java.

If you want to write your own Policy you should make an entry in relationalclasses.conf file.

relationalclasses.conf file entry sample

com.adventnet.nms.policies.UserDefinedPolicy policydb RelationalPolicyObject PolicyObject

To work on the Policy from the client end make an entry in Policy.conf file

Policy.conf file sample

  <POLICY

       classname="com.adventnet.nms.policies.User Defined Policy"

       display_name="User Defined Policy" />

(The "classname"should be the fully qualified classname of your Policy and the "display name" should be name of the policy)


Invoking the Example

Limitations

Configurations stored in the directory cannot be retrieved since it is stored in flat files. Configurations can be restored only manually.

Sample Output

On successful execution of this policy, you will find the backup files (of the devices of specified type) present under <Web NMS Home>/DEVICE_BACKUPS directory.


Copyright © 1996-2002, AdventNet Inc. All Rights Reserved.