5.20.6.11 An Overall Picture

 

Till now, we have been explaining the various steps involved in configuring the devices in the network. Now, in this document, we will put together all those concepts to provide you with an overall picture.  

 

The following code creates a task with the following details.

 

Task Name : sampletask

Protocol : snmp

Variables Configured : "sysName" and "sysLocation"

Values to be set : "myname" and "mylocation"

Rollback Option : Enabled

Rollback Type : Rollback Document

Rollback Document : rollbacktask

Devices over which it has to be executed : "device1" and "device2".

 

import com.adventnet.management.config.snmp.SnmpAttribute;

import com.adventnet.management.config.TaskGenerator;

import com.adventnet.management.config.xml.Device;

import com.adventnet.management.config.ConfigClient;

import com.adventnet.management.config.ConfigClientAPI;

import com.adventnet.management.config.ConfigResultListener;

import com.adventnet.management.config.ConfigResultEvent;

import com.adventnet.management.config.xml.DeviceResult;

public class SnmpTask implements ConfigResultListener

{

ConfigClient configclient = null;

ConfigClientAPI configclientAPI = null;

public void fetchInstance()

{

try

{

configclient = ConfigClient.getInstance("com.adventnet.management.config.DefaultConfigClientImpl", "localhost", "9000", "root", "public");

String uniqueID = configclient.registerResultListener(this);

ConfigClientAPI configclientAPI = new ConfigClientAPI(configclient, uniqueID);

 }

catch(Exception e)

{

System.out.println("Error in getting the handle of ConfigClientaPI");

}

}

public void executeTask()

{

SnmpAttribute snmpattrib1 = new SnmpAttribute("1.5.0", "sysName", "STRING", "myname");

SnmpAttribute snmpattrib2 = new SnmpAttribute("1.6.0", "sysLocation", "STRING", "mylocation");

     

TaskGenerator tg = new TaskGenerator();

tg.setTaskName("sampletask");

tg.setNewTask(true);

tg.setOverwrite(true);

tg.setProtocol("snmp");

tg.setPersistence(true);

tg.setRollback(true);

tg.setRollbackType(2);

tg.setRollbackDocument("rollbacktask");

tg.addAttribute(snmpattrib1);

tg.addAttribute(snmpattrib2);

Device d1 = new Device("device1", "161");

Device d2 = new Device("device2", "161");

tg.setDevices(new Device[] {d1,d2});

 

String taskXML = tg.getTask();

  

try

{

   configclientAPI.executeTask(taskXML);

}

catch (Exception e)

{

   System.out.println("Exception while executing the task");

}

}

public void setResult(ConfigResultEvent resultEvent)

{

DeviceResult result[] = resultEvent.getConfigResult();

for (int i =0; i<result.length; i++)

{

System.out.println("TaskName: "+result[i].getTaskName());

System.out.println("DeviceName: "+result[i].getDeviceName());

System.out.println("Rollback Status: "+result[i].getRollbackStatus());

System.out.println("Is Configuration Attempted: "+result[i].isConfigurationAttempted());

}

}

public static void main (String args[])

{

SnmpTask task = new SnmpTask();

task.fetchInstance();

task.executeTask();

}

}

 



Copyright © 2011, ZOHO Corp. All Rights Reserved.