Executing Commands on the Database Using Scripts

From Observer GigaFlow Support | VIAVI Solutions Inc.
Jump to: navigation, search

Executing Commands

//Create a table
actions.getDatabaseManager().executePrepared("create table test1(id integer,name text) ",[])
// if there are no last params, you may have to use null actions.getDatabaseManager().executePrepared("create table test1(id integer,name text) ",null)
//Populate table with data
for (var i=0;i<10;i++){
  /Create the array with the data to push into the database
  var datatogo = [i,i+"text"];
  //Create and execute the prepared statement
  actions.getDatabaseManager().executePrepared("insert into test1 (id,name) values (?,?)",[datatogo])
}
//Count the number of entries in the table
log.warn(actions.getDatabaseManager().getLongFromDB("select count(*) from test1",0))

//log.warn(actionsgetDeviceManager()) //log.warn(actions.ros.subscriptedBlacklists) //log.warn(actions.ros.subscriptedBlacklists.get("https://lists.blocklist.de/lists/strongips.txt"))

Removing devices directly

log.warn(actions.devices.size())
var aenum = actions.devices.keys()
log.warn(aenum)
while(aenum.hasMoreElements()){
 var nex = aenum.nextElement()
 var dev=actions.devices.get(nex);
log.warn(dev.getIP())
   if (dev.getIP().startsWith("77.95.167.45")){
     var mm = dev.getClass().getDeclaredMethod("remove");
     log.warn(mm)
     mm.setAccessible(true);
     log.warn(dev)
     log.warn(dev.getIP()+" removing")
     mm.invoke(dev,[])
     log.warn(dev.getIP()+" removing done")
    }
}