<template name="Detect Report - MSYS" category="miscellaneous">
    <description>Detect Report - MSYS</description>
    <section name="Detect Report - MSYS">
       <description>Detect Report - MSYS</description>
       <input label="キーの選択" name="keys" type="view.rttraffic.key[]" value="time,sourceaddress,ipprotocol" />
       <input label="値" name="value" type="string" value="fps">
         <option value="frames" />
         <option value="fps" />
         <option value="bytes" />
         <option value="Bps" />
         <option value="bps" />
       </input>
       <input label="期間" name="interval" type="interval.realtime" value="last60minutes" />
       <input label="グループ" name="group" type="group" value="hour" />
       <input label="名前解決" name="lookupnames" type="string" value="no">
          <option value="yes" />
          <option value="no" />
       </input>
       <input label="条件" name="where" type="filter.rttraffic" required="false" />
       <input label="しきい値" name="thresh" type="integer" value="10000" />
       <script>
var report = new Report();
var truncate = "";
var filter = null;
if(typeof(where) != 'undefined') filter = where;
var vcol;
switch(value) {
  case "frames": vcol = "frames"; break;
  case "fps"   : vcol = "rate(frames)"; break;
  case "bytes" : vcol = "bytes"; break;
  case "Bps"   : vcol = "rate(bytes)"; break;
  case "bps"   : vcol = "rate(bytes)"; break;
  default      : vcol = "frames";
}
var select = keys.toString() + "," + vcol;
var query = new Query.topN("rttraffic",select,filter,interval,vcol,truncate);
query.group = group;
var table = query.run();
if("bps" == value) table.scaleColumn(table.ncols - 1,8);
if("yes" == lookupnames) table.addressesToNames();
table.cnames[table.ncols - 1] = value;

var violations = Table.create(table.cnames,table.ctypes);
for(var r = 0; r &lt; table.nrows; r++) {
  if(table.cell(r,table.ncols - 1) &gt; thresh) violations.addRow(table.row(r));
}

report.table(violations);

// if the threshold is set and the first row exceeded it, then raise an event
if(typeof(thresh) != 'undefined' &amp;&amp; table.nrows &gt; 0 &amp;&amp; violations.cell(0, table.ncols - 1) &gt; thresh) {
   report.sendEvent("threshold", "severe");
}
       </script>
    </section>  
</template>
