Difference between revisions of "Script to Delete Devices"

From Observer GigaFlow Support | VIAVI Solutions Inc.
Jump to: navigation, search
Line 21: Line 21:
 
  for (var deviceid in actions.getDevices()) {
 
  for (var deviceid in actions.getDevices()) {
 
     var device = actions.getDevice(deviceid);
 
     var device = actions.getDevice(deviceid);
if (device!==null&&device.getTotalFlows().compareTo(0)===0&&!device.isSnmpOK()){
+
if (device!==null&&device.getTotalFlows().compareTo(0)===0&&!device.isSnmpOK()){
         //log.warn("No SNMP Or Flows "+device.getIP()+" TotalFlows:"+device.getTotalFlows()+" snmpOK:"+device.isSnmpOK());
+
         log.warn("No SNMP Or Flows "+device.getIP()+" TotalFlows:"+device.getTotalFlows()+" snmpOK:"+device.isSnmpOK());
 
         var c= device.getClass()
 
         var c= device.getClass()
 
         var m = c.getDeclaredMethod("remove")
 
         var m = c.getDeclaredMethod("remove")
 
         m.setAccessible(true);
 
         m.setAccessible(true);
         //m.invoke(device)
+
         m.invoke(device)
 
       count++
 
       count++
 
     //log.warn("Removing "+device.getIP()+" total:"+count);
 
     //log.warn("Removing "+device.getIP()+" total:"+count);
}else{
+
}
        log.warn("Not Removing "+device.getIP()+" TotalFlows:"+device.getTotalFlows()+" snmpOK:"+device.isSnmpOK());
+
    }
+
 
  }
 
  }

Revision as of 09:56, 23 November 2021

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()){
       log.warn("No SNMP Or Flows "+device.getIP()+" TotalFlows:"+device.getTotalFlows()+" snmpOK:"+device.isSnmpOK());
       var c= device.getClass()
       var m = c.getDeclaredMethod("remove")
       m.setAccessible(true);
       m.invoke(device)
     count++
   	//log.warn("Removing "+device.getIP()+" total:"+count);

}

}