# - Watcher-Stats.bashlib - . Watcher-Stats-helper.bashlib ### Globals STAT_DB=$MASTER_PATH/$ME.db POOL_DB=$POOL/Watcher-Report3.db STAT_SQL="sqlite3 -csv $STAT_DB" POOL_SQL="sqlite3 -csv $POOL_DB" declare -A DBs DBs[STAT]=$STAT_DB DBs[POOL]=$POOL_DB declare -A sql_parms declare -A sql_result declare -A formatter # Watcher-Stats API main wrapper # Rope ladder for the tasks to do report_stats() { local funtag="[${FUNCNAME[0]}]" statistics_efficiency statistics_procrate statistics_looprate statistics_sqlrate # ... and anything else report_raw #report_filter report_types } statistics_efficiency() { local funtag="[${FUNCNAME[0]}]" local rset cols sql_parms=() sql_parms[cmd]=" select event_stamp, type, active, efficiency_cur, efficiency_min, efficiency_max from efficiency_stats where active = 1 ;" procsql sql_parms STAT cols="${sql_parms[cols]}" echo "Columns : $cols" echo "-Resultset-" rset="${sql_result[result]}" echo "$rset" formatter=() formatter[data]=$rset formatter[cols]=$cols dump_csv formatter } statistics_procrate() { local funtag="[${FUNCNAME[0]}]" } statistics_looprate() { local funtag="[${FUNCNAME[0]}]" } statistics_sqlrate() { local funtag="[${FUNCNAME[0]}]" } # Report functions ... for testing ... report_raw() { local funtag="[${FUNCNAME[0]}]" local rset cols echo $funtag >&2 sql_parms=() sql_parms[cmd]=" select ipset, chain, target, osi, member, membertype, packets from ipsets where osi = 3 and target = 'DROP' and packets != 0 and packets > 1000 ;" procsql sql_parms POOL cols="${sql_parms[cols]}" echo "Columns : $cols" # Misc ... echo "Access : ${sql_parms[access]}" echo "Cmdtype : ${sql_parms[cmdtype]}" echo "ERC : ${sql_result[sqlrc]}" echo "-Resultset-" rset="${sql_result[result]}" echo "$rset" col_widths "$rset" print_table "$rset" "$cols" } report_filter() { local funtag="[${FUNCNAME[0]}]" } report_types () { local funtag="[${FUNCNAME[0]}]" local types="Login Mail Mailbox Web WBanalyse" echo "[ Members in firewall ]" for t in $types do printf "%10s: %9d\n" "$t" $(count-by-type $t) done } # vim: set filetype=sh noexpandtab tabstop=8 shiftwidth=8 autoindent smartindent :