Difference between revisions of "Script to Delete Devices"
From Observer GigaFlow Support | VIAVI Solutions Inc.
Kevin Wilkie (Talk | contribs) |
Kevin Wilkie (Talk | contribs) |
||
(4 intermediate revisions by one user not shown) | |||
Line 3: | Line 3: | ||
] | ] | ||
for(var i in devices){ | 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{ | }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()){ | ||
+ | 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); | ||
+ | } | ||
} | } |
Latest revision as of 09:57, 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()){ 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); } }