Script to Delete Devices

From Observer GigaFlow Support | VIAVI Solutions Inc.
Jump to: navigation, search
var devices=[
"10.171.255.179","10.130.255.187","10.171.255.177","10.170.255.179","10.130.255.183"
]
for(var i in devices){
var thisDevice = actions.getDevice(devices[i]);
if (thisDevice!=null){
var c= thisDevice.getClass()
 var m = c.getDeclaredMethod("remove")
m.setAccessible(true);
 log.warn(m)
m.invoke(thisDevice)
log.warn("Removing "+devices[i]);
   }else{
   	log.warn("Not Removing "+devices[i]);
   }
}


You can also parse all devices and delete based on criteria such as no flows or snmp working

var count=0;
for (var deviceid in actions.getDevices()) {
  var device = actions.getDevice(deviceid);
  if (device!==null&&device.getTotalFlows().compareTo(0)===0&&!device.isSnmpOK()){
    var c= device.getClass()
    var m = c.getDeclaredMethod("remove")
    m.setAccessible(true);
    m.invoke(device)
    count++
    log.warn("No SNMP Or Flows "+device.getIP()+" TotalFlows:"+device.getTotalFlows()+" snmpOK:"+device.isSnmpOK()+" total:"+count);
  }
}