void NdpiStats::lua(NetworkInterface *iface, lua_State* vm) { lua_newtable(vm); for(int i=0; i<MAX_NDPI_PROTOS; i++) if(counters[i] != NULL) { char *name = iface->get_ndpi_proto_name(i); if(name != NULL) { if(counters[i]->packets.sent || counters[i]->packets.rcvd) { lua_newtable(vm); lua_push_int_table_entry(vm, "packets.sent", counters[i]->packets.sent); lua_push_int_table_entry(vm, "packets.rcvd", counters[i]->packets.rcvd); lua_push_int_table_entry(vm, "bytes.sent", counters[i]->bytes.sent); lua_push_int_table_entry(vm, "bytes.rcvd", counters[i]->bytes.rcvd); lua_pushstring(vm, name); lua_insert(vm, -2); lua_settable(vm, -3); } } } lua_pushstring(vm, "ndpi"); lua_insert(vm, -2); lua_settable(vm, -3); }
void StringHost::lua(lua_State* vm, bool returnHost) { lua_newtable(vm); lua_push_str_table_entry(vm, "name", keyname); lua_push_int_table_entry(vm, "bytes.sent", sent.getNumBytes()); lua_push_int_table_entry(vm, "bytes.rcvd", rcvd.getNumBytes()); lua_push_int_table_entry(vm, "pkts.sent", sent.getNumPkts()); lua_push_int_table_entry(vm, "pkts.rcvd", rcvd.getNumPkts()); lua_push_int_table_entry(vm, "queries.rcvd", queriesReceived); lua_push_int_table_entry(vm, "seen.first", first_seen); lua_push_int_table_entry(vm, "seen.last", last_seen); lua_push_int_table_entry(vm, "duration", get_duration()); lua_push_int_table_entry(vm, "family", family_id); lua_push_float_table_entry(vm, "throughput", bytes_thpt); lua_push_int_table_entry(vm, "throughput_trend", getThptTrend()); if(ndpiStats) ndpiStats->lua(iface, vm); getHostContacts(vm); if(returnHost) { lua_pushstring(vm, keyname); lua_insert(vm, -2); lua_settable(vm, -3); } }
void HostContacts::getContacts(lua_State* vm) { char buf[64]; lua_newtable(vm); /* client */ lua_newtable(vm); for(int i=0; i<MAX_NUM_HOST_CONTACTS; i++) { if(clientContacts[i].num_contacts > 0) lua_push_int_table_entry(vm, clientContacts[i].host.print(buf, sizeof(buf)), clientContacts[i].num_contacts); } lua_pushstring(vm, "client"); lua_insert(vm, -2); lua_settable(vm, -3); /* server */ lua_newtable(vm); for(int i=0; i<MAX_NUM_HOST_CONTACTS; i++) { if(serverContacts[i].num_contacts > 0) lua_push_int_table_entry(vm, serverContacts[i].host.print(buf, sizeof(buf)), serverContacts[i].num_contacts); } lua_pushstring(vm, "server"); lua_insert(vm, -2); lua_settable(vm, -3); lua_pushstring(vm, "contacts"); lua_insert(vm, -2); lua_settable(vm, -3); }
void PacketDumper::lua(lua_State *vm) { lua_newtable(vm); lua_push_int_table_entry(vm, "num_dumped_pkts", get_num_dumped_packets()); lua_push_int_table_entry(vm, "num_dumped_files", get_num_dumped_files()); lua_pushstring(vm, "pkt_dumper"); lua_insert(vm, -2); lua_settable(vm, -3); }
void Flow::print_peers(lua_State* vm, bool verbose) { char buf1[64], buf2[64], buf[256]; Host *src = get_cli_host(), *dst = get_srv_host(); if((src == NULL) || (dst == NULL)) return; lua_newtable(vm); lua_push_str_table_entry(vm, "client", get_cli_host()->get_ip()->print(buf, sizeof(buf))); lua_push_str_table_entry(vm, "server", get_srv_host()->get_ip()->print(buf, sizeof(buf))); lua_push_int_table_entry(vm, "sent", cli2srv_bytes); lua_push_int_table_entry(vm, "rcvd", srv2cli_bytes); lua_push_int_table_entry(vm, "sent.last", get_current_bytes_cli2srv()); lua_push_int_table_entry(vm, "rcvd.last", get_current_bytes_srv2cli()); lua_push_int_table_entry(vm, "duration", get_duration()); lua_push_float_table_entry(vm, "client.latitude", get_cli_host()->get_latitude()); lua_push_float_table_entry(vm, "client.longitude", get_cli_host()->get_longitude()); lua_push_float_table_entry(vm, "server.latitude", get_srv_host()->get_latitude()); lua_push_float_table_entry(vm, "server.longitude", get_srv_host()->get_longitude()); if(verbose) { lua_push_bool_table_entry(vm, "client.private", get_cli_host()->get_ip()->isPrivateAddress()); lua_push_str_table_entry(vm, "client.country", get_cli_host()->get_country() ? get_cli_host()->get_country() : (char*)""); lua_push_bool_table_entry(vm, "server.private", get_srv_host()->get_ip()->isPrivateAddress()); lua_push_str_table_entry(vm, "server.country", get_srv_host()->get_country() ? get_srv_host()->get_country() : (char*)""); lua_push_str_table_entry(vm, "client.city", get_cli_host()->get_city() ? get_cli_host()->get_city() : (char*)""); lua_push_str_table_entry(vm, "server.city", get_srv_host()->get_city() ? get_srv_host()->get_city() : (char*)""); if(verbose) { if(((cli2srv_packets+srv2cli_packets) > NDPI_MIN_NUM_PACKETS) || (ndpi_detected_protocol != NDPI_PROTOCOL_UNKNOWN) || iface->is_ndpi_enabled() || iface->is_sprobe_interface()) lua_push_str_table_entry(vm, "proto.ndpi", get_detected_protocol_name()); else lua_push_str_table_entry(vm, "proto.ndpi", (char*)CONST_TOO_EARLY); } } // Key /* Too slow */ #if 0 snprintf(buf, sizeof(buf), "%s %s", src->Host::get_name(buf1, sizeof(buf1), false), dst->Host::get_name(buf2, sizeof(buf2), false)); #else snprintf(buf, sizeof(buf), "%s %s", intoaV4(ntohl(get_cli_ipv4()), buf1, sizeof(buf1)), intoaV4(ntohl(get_srv_ipv4()), buf2, sizeof(buf2))); #endif lua_pushstring(vm, buf); lua_insert(vm, -2); lua_settable(vm, -3); }
static int ntop_get_prefs(lua_State* vm) { lua_newtable(vm); lua_push_bool_table_entry(vm, "is_dns_resolution_enabled_for_all_hosts", ntop->getPrefs()->is_dns_resolution_enabled_for_all_hosts()); lua_push_bool_table_entry(vm, "is_dns_resolution_enabled", ntop->getPrefs()->is_dns_resolution_enabled()); lua_push_bool_table_entry(vm, "is_categorization_enabled", ntop->getPrefs()->is_categorization_enabled()); lua_push_int_table_entry(vm, "host_max_idle", ntop->getPrefs()->get_host_max_idle()); lua_push_int_table_entry(vm, "flow_max_idle", ntop->getPrefs()->get_flow_max_idle()); lua_push_int_table_entry(vm, "max_num_hosts", ntop->getPrefs()->get_max_num_hosts()); lua_push_int_table_entry(vm, "max_num_flows", ntop->getPrefs()->get_max_num_flows()); return(CONST_LUA_OK); }
void LocalTrafficStats::lua(lua_State* vm) { lua_newtable(vm); lua_newtable(vm); lua_push_int_table_entry(vm, "local2local", packets.local2local); lua_push_int_table_entry(vm, "local2remote", packets.local2remote); lua_push_int_table_entry(vm, "remote2local", packets.remote2local); lua_push_int_table_entry(vm, "remote2remote", packets.remote2remote); lua_pushstring(vm, "packets"); lua_insert(vm, -2); lua_settable(vm, -3); lua_newtable(vm); lua_push_int_table_entry(vm, "local2local", bytes.local2local); lua_push_int_table_entry(vm, "local2remote", bytes.local2remote); lua_push_int_table_entry(vm, "remote2local", bytes.remote2local); lua_push_int_table_entry(vm, "remote2remote", bytes.remote2remote); lua_pushstring(vm, "bytes"); lua_insert(vm, -2); lua_settable(vm, -3); lua_pushstring(vm, "localstats"); lua_insert(vm, -2); lua_settable(vm, -3); }
static int ntop_get_info(lua_State* vm) { char rsp[256]; int major, minor, patch; lua_newtable(vm); lua_push_str_table_entry(vm, "copyright", (char*)"© 1998-2013 - ntop.org"); lua_push_str_table_entry(vm, "authors", (char*)"Luca Deri and Alfredo Cardigliano"); lua_push_str_table_entry(vm, "license", (char*)"GNU GPLv3"); snprintf(rsp, sizeof(rsp), "%s (%s)", PACKAGE_VERSION, NTOPNG_SVN_RELEASE); lua_push_str_table_entry(vm, "version", rsp); lua_push_int_table_entry(vm, "uptime", ntop->getGlobals()->getUptime()); lua_push_str_table_entry(vm, "version.rrd", rrd_strversion()); lua_push_str_table_entry(vm, "version.redis", ntop->getRedis()->getVersion(rsp, sizeof(rsp))); lua_push_str_table_entry(vm, "version.httpd", (char*)mg_version()); lua_push_str_table_entry(vm, "version.luajit", (char*)LUAJIT_VERSION); #ifdef HAVE_GEOIP lua_push_str_table_entry(vm, "version.geoip", (char*)GeoIP_lib_version()); #endif lua_push_str_table_entry(vm, "version.ndpi", ndpi_revision()); zmq_version(&major, &minor, &patch); snprintf(rsp, sizeof(rsp), "%d.%d.%d", major, minor, patch); lua_push_str_table_entry(vm, "version.zmq", rsp); return(CONST_LUA_OK); }
void PacketStats::lua(lua_State* vm, const char *label) { lua_newtable(vm); lua_push_int_table_entry(vm, "upTo64", upTo64); lua_push_int_table_entry(vm, "upTo128", upTo128); lua_push_int_table_entry(vm, "upTo256", upTo256); lua_push_int_table_entry(vm, "upTo512", upTo512); lua_push_int_table_entry(vm, "upTo1024", upTo1024); lua_push_int_table_entry(vm, "upTo1518", upTo1518); lua_push_int_table_entry(vm, "upTo2500", upTo2500); lua_push_int_table_entry(vm, "upTo6500", upTo6500); lua_push_int_table_entry(vm, "upTo9000", upTo9000); lua_push_int_table_entry(vm, "above9000", above9000); lua_pushstring(vm, label); lua_insert(vm, -2); lua_settable(vm, -3); }
void CategoryStats::lua(lua_State* vm) { lua_newtable(vm); if(categories) { for(int i=0; i<ntop->get_flashstart()->getNumCategories(); i++) if(categories[i] > 0) lua_push_int_table_entry(vm, ntop->get_flashstart()->getCategoryName(i), categories[i]); } lua_pushstring(vm, "categories"); lua_insert(vm, -2); lua_settable(vm, -3); }
void Flow::processLua(lua_State* vm, ProcessInfo *proc, bool client) { lua_newtable(vm); lua_push_int_table_entry(vm, "cpu_id", proc->cpu_id); lua_push_int_table_entry(vm, "pid", proc->pid); lua_push_int_table_entry(vm, "father_pid", proc->father_pid); lua_push_str_table_entry(vm, "name", proc->name); lua_push_str_table_entry(vm, "father_name", proc->father_name); lua_push_str_table_entry(vm, "user_name", proc->user_name); lua_push_int_table_entry(vm, "actual_memory", proc->actual_memory); lua_push_int_table_entry(vm, "peak_memory", proc->peak_memory); lua_push_int_table_entry(vm, "average_cpu_load", proc->average_cpu_load); lua_push_int_table_entry(vm, "num_vm_page_faults", proc->num_vm_page_faults); lua_pushstring(vm, client ? "client_process" : "server_process"); lua_insert(vm, -2); lua_settable(vm, -3); }
void NetworkInterfaceView::lua(lua_State *vm) { int n = 0; lua_newtable(vm); lua_newtable(vm); for(int i = 0; i<numInterfaces; i++) { physIntf[i]->lua(vm); lua_pushstring(vm, physIntf[i]->get_name()); lua_insert(vm, -2); lua_settable(vm, -3); n++; } lua_pushstring(vm, "interfaces"); lua_insert(vm, -2); lua_settable(vm, -3); lua_push_str_table_entry(vm, "name", name); lua_push_int_table_entry(vm, "id", id); lua_push_bool_table_entry(vm, "isView", n > 1 ? true : false); }
void DnsStats::luaStats(lua_State *vm, struct dns_stats *stats, const char *label) { lua_newtable(vm); lua_push_int_table_entry(vm, "num_queries", stats->num_queries); lua_push_int_table_entry(vm, "num_replies_ok", stats->num_replies_ok); lua_push_int_table_entry(vm, "num_replies_error", stats->num_replies_error); lua_newtable(vm); lua_push_int_table_entry(vm, "num_a", stats->breakdown.num_a); lua_push_int_table_entry(vm, "num_ns", stats->breakdown.num_ns); lua_push_int_table_entry(vm, "num_cname", stats->breakdown.num_cname); lua_push_int_table_entry(vm, "num_soa", stats->breakdown.num_soa); lua_push_int_table_entry(vm, "num_ptr", stats->breakdown.num_ptr); lua_push_int_table_entry(vm, "num_mx", stats->breakdown.num_mx); lua_push_int_table_entry(vm, "num_txt", stats->breakdown.num_txt); lua_push_int_table_entry(vm, "num_aaaa", stats->breakdown.num_aaaa); lua_push_int_table_entry(vm, "num_any", stats->breakdown.num_any); lua_push_int_table_entry(vm, "num_other", stats->breakdown.num_other); lua_pushstring(vm, "queries"); lua_insert(vm, -2); lua_settable(vm, -3); lua_pushstring(vm, label); lua_insert(vm, -2); lua_settable(vm, -3); }
void Flow::lua(lua_State* vm, bool detailed_dump) { char buf[64]; lua_newtable(vm); if(get_cli_host()) { if(detailed_dump) lua_push_str_table_entry(vm, "cli.host", get_cli_host()->get_name(buf, sizeof(buf), false)); lua_push_int_table_entry(vm, "cli.source_id", get_cli_host()->getSourceId()); lua_push_str_table_entry(vm, "cli.ip", get_cli_host()->get_ip()->print(buf, sizeof(buf))); lua_push_bool_table_entry(vm, "cli.systemhost", get_cli_host()->isSystemHost()); } else { lua_push_nil_table_entry(vm, "cli.host"); lua_push_nil_table_entry(vm, "cli.ip"); } lua_push_int_table_entry(vm, "cli.port", get_cli_port()); if(get_srv_host()) { if(detailed_dump) lua_push_str_table_entry(vm, "srv.host", get_srv_host()->get_name(buf, sizeof(buf), false)); lua_push_int_table_entry(vm, "srv.source_id", get_cli_host()->getSourceId()); lua_push_str_table_entry(vm, "srv.ip", get_srv_host()->get_ip()->print(buf, sizeof(buf))); lua_push_bool_table_entry(vm, "srv.systemhost", get_srv_host()->isSystemHost()); } else { lua_push_nil_table_entry(vm, "srv.host"); lua_push_nil_table_entry(vm, "srv.ip"); } lua_push_int_table_entry(vm, "srv.port", get_srv_port()); lua_push_int_table_entry(vm, "vlan", get_vlan_id()); lua_push_str_table_entry(vm, "proto.l4", get_protocol_name()); if(((cli2srv_packets+srv2cli_packets) > NDPI_MIN_NUM_PACKETS) || (ndpi_detected_protocol != NDPI_PROTOCOL_UNKNOWN) || iface->is_ndpi_enabled() || iface->is_sprobe_interface()) { lua_push_str_table_entry(vm, "proto.ndpi", get_detected_protocol_name()); } else lua_push_str_table_entry(vm, "proto.ndpi", (char*)CONST_TOO_EARLY); lua_push_int_table_entry(vm, "bytes", cli2srv_bytes+srv2cli_bytes); lua_push_int_table_entry(vm, "bytes.last", get_current_bytes_cli2srv() + get_current_bytes_srv2cli()); lua_push_int_table_entry(vm, "seen.first", get_first_seen()); lua_push_int_table_entry(vm, "seen.last", get_last_seen()); lua_push_int_table_entry(vm, "duration", get_duration()); lua_push_int_table_entry(vm, "cli2srv.bytes", cli2srv_bytes); lua_push_int_table_entry(vm, "srv2cli.bytes", srv2cli_bytes); if(detailed_dump) { lua_push_int_table_entry(vm, "tcp_flags", getTcpFlags()); lua_push_str_table_entry(vm, "category", categorization.category ? categorization.category : (char*)""); lua_push_str_table_entry(vm, "moreinfo.json", get_json_info()); } if(client_proc) processLua(vm, client_proc, true); if(server_proc) processLua(vm, server_proc, false); //ntop->getTrace()->traceEvent(TRACE_NORMAL, "%.2f", bytes_thpt); lua_push_float_table_entry(vm, "throughput", bytes_thpt); lua_push_int_table_entry(vm, "throughput_trend", bytes_thpt_trend); if(!detailed_dump) { lua_pushinteger(vm, key()); // Index lua_insert(vm, -2); lua_settable(vm, -3); } else { lua_push_int_table_entry(vm, "cli2srv.packets", cli2srv_packets); lua_push_int_table_entry(vm, "srv2cli.packets", srv2cli_packets); } }