// Set usage policy var interval = "8am,5pm"; var quotas = new Array(); quotas['Noe Valley'] = 2e9; // 2G bytes quotas['Marina'] = 4e9; // 4G bytes // Build zone list var zones = new Array(); for(zone in quotas) zones.push("'" + zone + "'"); // Get the outbound traffic var query = Query.topN( "rttraffic", "sourcezone,ipsource,bytes", "sourcezone=" + zones + "&islayer3multicast=0&destinationzone=EXTERNAL", interval, "bytes", 100); var table = query.run(); // See if anyone has exceeded quota and collect info var exceeded = Table.create( ["Host","Bytes"], ["address","integer"]); exceeded.start = table.start; exceeded.end = table.end; for(var r = 0; r < table.nrows; r++) { var zone = table.cell(r,0); var addr = table.cell(r,1); var bytes = table.cell(r,2); if(zone && addr) { if(quotas[zone] < bytes) { exceeded.addRow(new Array(addr,bytes)); } } } // Add additional information from the network state function unique(array) { var result = new Array(); for(var i = 0; i < array.length; i++) { result[i] = array[i] ? (array[i].length == 1 ? array[i][0] : null) : null; } return result; } var n = Network.current(); // Lookup DNS names exceeded.insertColumn( "DNS","address", unique(n.dnsMap(exceeded.column(0))),0); // Lookup MAC addresses exceeded.insertColumn( "MAC","address", unique(n.addressMap(exceeded.column(1))),2); // Locate MAC addresses to switch ports var interfaces = n.locationMap(exceeded.column(2)); // Get switch IP addresses and port ifNames var switchIPs = new Array(); var ifNames = new Array(); for(var i = 0; i < interfaces.length; i++) { n.path = interfaces[i]; switchIPs.push(n.agentIP()); ifNames.push(n.ifName()); } exceeded.insertColumn("Switch IP","agent",switchIPs,3); exceeded.insertColumn("ifName","string",ifNames,4); // Print results exceeded.printCSV(false);