timestamps
This commit is contained in:
parent
a30314eb7a
commit
7bdc6e0774
11
ctstats.c
11
ctstats.c
|
@ -71,6 +71,17 @@ int main(int argc, char *argv[])
|
|||
exit(1);
|
||||
}
|
||||
|
||||
/* check logfile */
|
||||
char *logfile = config_get_string("global", "logfile", DEFAULT_LOGFILE);
|
||||
if (logfile != NULL && debug == 0) {
|
||||
/* start logging */
|
||||
if (!log_init(logfile))
|
||||
exit(1);
|
||||
|
||||
/* zum daemon mutieren */
|
||||
daemon(-1, 0);
|
||||
}
|
||||
|
||||
/* start event listener */
|
||||
conntrack_start_event_thread();
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
CREATE DATABASE `ctstats` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
|
||||
USE `ctstats`;
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `stats`
|
||||
--
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `stats` (
|
||||
`timestamp` int(10) unsigned NOT NULL,
|
||||
`srcip` int(10) unsigned NOT NULL default '0',
|
||||
`proto` int(10) unsigned NOT NULL default '0',
|
||||
`dport` int(10) unsigned NOT NULL default '0',
|
||||
`srcbytes` int(10) unsigned NOT NULL default '0',
|
||||
`dstbytes` int(10) unsigned NOT NULL default '0',
|
||||
`count` int(10) unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (`timestamp`,`srcip`,`proto`,`dport`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
11
database.c
11
database.c
|
@ -15,18 +15,16 @@ static MYSQL *dbh;
|
|||
|
||||
static void purge_hash_cb(struct hash_entry *entry, void *privdata)
|
||||
{
|
||||
struct in_addr src_ip = { .s_addr = entry->src_ip };
|
||||
int long *now = (long *)privdata;
|
||||
char query[256];
|
||||
|
||||
int len = snprintf(query, sizeof(query),
|
||||
"INSERT INTO stats SET srcip='%s', proto='%u', dport='%u', srcbytes='%llu', dstbytes='%llu', count='%u'",
|
||||
inet_ntoa(src_ip), entry->protonum, ntohs(entry->dst_port),
|
||||
"INSERT INTO stats SET timestamp='%lu', srcip='%u', proto='%u', dport='%u', srcbytes='%llu', dstbytes='%llu', count='%u'",
|
||||
*now, ntohl(entry->src_ip), entry->protonum, ntohs(entry->dst_port),
|
||||
entry->src_bytes, entry->dst_bytes, entry->count);
|
||||
|
||||
if (mysql_real_query(dbh, query, len +1) != 0)
|
||||
log_print(LOG_WARN, "purge_hash_cb: mysql_real_query(): %s", mysql_error(dbh));
|
||||
|
||||
log_print(LOG_DEBUG, query);
|
||||
}
|
||||
|
||||
int database_analyse(void)
|
||||
|
@ -39,7 +37,8 @@ int database_analyse(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
purge_hash(hash, purge_hash_cb, NULL);
|
||||
long now = time(NULL);
|
||||
purge_hash(hash, purge_hash_cb, (void *)&now);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue