Difference between revisions of "Script to Delete Devices"
From Observer GigaFlow Support | VIAVI Solutions Inc.
Kevin Wilkie (Talk | contribs) |
Kevin Wilkie (Talk | contribs) |
||
Line 13: | Line 13: | ||
}else{ | }else{ | ||
log.warn("Not Removing "+devices[i]); | 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); | ||
+ | }else{ | ||
+ | log.warn("Not Removing "+device.getIP()+" TotalFlows:"+device.getTotalFlows()+" snmpOK:"+device.isSnmpOK()); | ||
} | } | ||
} | } |
Revision as of 09:55, 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);
}else{
log.warn("Not Removing "+device.getIP()+" TotalFlows:"+device.getTotalFlows()+" snmpOK:"+device.isSnmpOK()); } }