-Add some first stuff of the main vermont
git-svn-id: file:///Users/braun/svn/vermont/trunk/vermont@46 aef3b71b-58ee-0310-9ba9-8811b9f0742fmaster
commit
4971768641
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
Based upon libiniparser, by Nicolas Devillard
|
||||
Hacked into 1 file (m-iniparser) by Freek/2005
|
||||
Original terms following:
|
||||
|
||||
-- -
|
||||
|
||||
Copyright (c) 2000 by Nicolas Devillard (ndevilla AT free DOT fr).
|
||||
|
||||
Written by Nicolas Devillard. Not derived from licensed software.
|
||||
|
||||
Permission is granted to anyone to use this software for any
|
||||
purpose on any computer system, and to redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The author is not responsible for the consequences of use of
|
||||
this software, no matter how awful, even if they arise
|
||||
from defects in it.
|
||||
|
||||
2. The origin of this software must not be misrepresented, either
|
||||
by explicit claim or by omission.
|
||||
|
||||
3. Altered versions must be plainly marked as such, and must not
|
||||
be misrepresented as being the original software.
|
||||
|
||||
4. This notice may not be removed or altered.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _INIPARSER_H_
|
||||
#define _INIPARSER_H_
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct _dictionary_ {
|
||||
/** Number of entries in dictionary */
|
||||
int n;
|
||||
/** Storage size */
|
||||
int size;
|
||||
/** List of string values */
|
||||
char **val;
|
||||
/** List of string keys */
|
||||
char **key ;
|
||||
/** List of hash values for keys */
|
||||
unsigned *hash;
|
||||
} dictionary ;
|
||||
|
||||
|
||||
/* generated by genproto */
|
||||
|
||||
dictionary * iniparser_new(char *ininame);
|
||||
void iniparser_free(dictionary * d);
|
||||
|
||||
int iniparser_getnsec(dictionary * d);
|
||||
char * iniparser_getsecname(dictionary * d, int n);
|
||||
void iniparser_dump(dictionary * d, FILE * f);
|
||||
void iniparser_dump_ini(dictionary * d, FILE * f);
|
||||
char * iniparser_getvalue(dictionary *d, char *section, char *key);
|
||||
char * iniparser_getstr(dictionary * d, char * key);
|
||||
char * iniparser_getstring(dictionary * d, char * key, char * def);
|
||||
int iniparser_getint(dictionary * d, char * key, int notfound);
|
||||
double iniparser_getdouble(dictionary * d, char * key, double notfound);
|
||||
int iniparser_getboolean(dictionary * d, char * key, int notfound);
|
||||
int iniparser_find_entry(dictionary * ini, char * entry);
|
||||
int iniparser_setstr(dictionary * ini, char * entry, char * val);
|
||||
void iniparser_unset(dictionary * ini, char * entry);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
this is vermont.
|
||||
released under GPL v2
|
||||
|
||||
(C) by Ronny T. Lampert
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "msg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static int msg_level=MSG_DEFAULT;
|
||||
static char *MSG_TAB[]={"FATAL", "VERMONT", "ERROR", "DEBUG", "INFO ", 0};
|
||||
|
||||
void msg(int level, char *fmt, ...)
|
||||
{
|
||||
/* nummerically higher value means lower priority */
|
||||
if (level > msg_level) {
|
||||
return;
|
||||
} else {
|
||||
va_list args;
|
||||
printf("%s: ", MSG_TAB[level]);
|
||||
va_start(args, fmt);
|
||||
vprintf(fmt, args);
|
||||
va_end(args);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void msg_setlevel(int level)
|
||||
{
|
||||
msg_level=level;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
this is vermont.
|
||||
released under GPL v2
|
||||
|
||||
(C) by Ronny T. Lampert
|
||||
|
||||
*/
|
||||
#ifndef MSG_H
|
||||
#define MSG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* defines for the message system */
|
||||
#define MSG_BLANK 256
|
||||
#define MSG_INFO 4
|
||||
#define MSG_DEBUG 3
|
||||
#define MSG_ERROR 2
|
||||
#define MSG_DIALOG 1
|
||||
#define MSG_FATAL 0
|
||||
#define MSG_DEFAULT MSG_ERROR
|
||||
|
||||
void msg(int, char *, ...);
|
||||
void msg_setlevel(int);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
this is vermont.
|
||||
released under GPL v2
|
||||
|
||||
(C) by Ronny T. Lampert
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "subsystems.h"
|
||||
#include "msg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
should print all running subsystems
|
||||
by now only dump flags
|
||||
*/
|
||||
void subsys_dump(unsigned int flags)
|
||||
{
|
||||
int size=(8*sizeof(flags));
|
||||
|
||||
msg(MSG_DIALOG, "subsystems running: 0x%x", flags);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void subsys_on(unsigned int *flag, unsigned int sys)
|
||||
{
|
||||
*flag |= sys;
|
||||
}
|
||||
|
||||
|
||||
void subsys_off(unsigned int *flag, unsigned int sys)
|
||||
{
|
||||
*flag &= ~sys;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
this is vermont.
|
||||
released under GPL v2
|
||||
|
||||
(C) by Ronny T. Lampert
|
||||
|
||||
*/
|
||||
#ifndef SUBSYSTEMS_H
|
||||
#define SUBSYSTEMS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void subsys_dump(unsigned int flags);
|
||||
void subsys_on(unsigned int *flag, unsigned int sys);
|
||||
void subsys_off(unsigned int *flag, unsigned int sys);
|
||||
|
||||
|
||||
#define SUBSYS_CONFIG 0x1
|
||||
|
||||
#define SUBSYS_COL_RECEIVE 0x2
|
||||
#define SUBSYS_COL_ACCOUNT 0x4
|
||||
#define SUBSYS_COL_EXPORT 0x8
|
||||
|
||||
#define SUBSYS_SAMP_CAPTURE 0x10
|
||||
#define SUBSYS_SAMP_FILTER 0x20
|
||||
#define SUBSYS_SAMP_EXPORT 0x40
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,25 @@
|
|||
[collector]
|
||||
# INADDR_ANY
|
||||
listen_ip=0.0.0.0
|
||||
listen_port=1500
|
||||
export_ip=127.0.0.1
|
||||
export_port=1501
|
||||
|
||||
[sampler]
|
||||
export_ip=127.0.0.1
|
||||
export_port=1502
|
||||
|
||||
# for pcap_open_live(char *device)
|
||||
# or off if you don't want to use this input stream
|
||||
interface=eth0
|
||||
|
||||
# config filters
|
||||
filters=ip1,random1
|
||||
ipf1=<type_of_filter,params>
|
||||
random1=<type_of_filter,params>
|
||||
|
||||
[main]
|
||||
# all or filtered
|
||||
# filtered is after sampler's filters
|
||||
packets=all
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
this is vermont.
|
||||
released under GPL v2
|
||||
|
||||
(C) by Ronny T. Lampert
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "iniparser.h"
|
||||
#include "msg.h"
|
||||
#include "subsystems.h"
|
||||
|
||||
static void usage();
|
||||
static void sig_handler(int x);
|
||||
static int setup_signal(int signal, void (*handler)(int));
|
||||
int vermont_readconf(char *file, dictionary **conf);
|
||||
|
||||
/* initialized subsystems */
|
||||
unsigned int v_subsystems;
|
||||
|
||||
|
||||
int main(int ac, char **dc)
|
||||
{
|
||||
dictionary *config;
|
||||
int c, debug_level=MSG_DEFAULT;
|
||||
char *config_file=NULL;
|
||||
|
||||
/* parse command line */
|
||||
while((c=getopt(ac, dc, "hf:d")) != -1) {
|
||||
|
||||
switch(c) {
|
||||
|
||||
case 'f':
|
||||
config_file=optarg;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
debug_level++;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
usage();
|
||||
return 0;
|
||||
default:
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* setup verboseness */
|
||||
msg_setlevel(debug_level);
|
||||
|
||||
setup_signal(SIGINT, sig_handler);
|
||||
|
||||
if(vermont_readconf(config_file, &config)) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
subsys_dump(v_subsystems);
|
||||
|
||||
iniparser_dump(config, stdout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
read the config from *file and attach the iniparser stuff to **conf
|
||||
perform basic checks
|
||||
*/
|
||||
int vermont_readconf(char *file, dictionary **conf)
|
||||
{
|
||||
dictionary *d;
|
||||
|
||||
/* read configuration */
|
||||
d=iniparser_new(file);
|
||||
if(!d) {
|
||||
msg(MSG_FATAL, "could not open config_file %s", file);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* check if all section we need are present */
|
||||
if((iniparser_find_entry(d, "collector") == 1) &&
|
||||
(iniparser_find_entry(d, "sampler") == 1) &&
|
||||
(iniparser_find_entry(d, "main") == 1)
|
||||
) {
|
||||
subsys_on(&v_subsystems, SUBSYS_CONFIG);
|
||||
*conf=d;
|
||||
|
||||
return 0;
|
||||
|
||||
} else {
|
||||
msg(MSG_FATAL, "not all needed sections in config %s", file);
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* bla bla bla */
|
||||
static void usage()
|
||||
{
|
||||
printf(
|
||||
"Versatile MONitoring Tool - VERMONT\n" \
|
||||
" mandatory:
|
||||
" -f <inifile> load config\n" \
|
||||
" optional:
|
||||
" -d increase debug level\n" \
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
static int setup_signal(int signal, void (*handler)(int))
|
||||
{
|
||||
struct sigaction sig;
|
||||
|
||||
sig.sa_handler=sig_handler;
|
||||
sig.sa_flags=SA_RESTART;
|
||||
sigemptyset(&sig.sa_mask);
|
||||
return (sigaction(signal, &sig, NULL));
|
||||
}
|
||||
|
||||
|
||||
/* just shallow right now */
|
||||
static void sig_handler(int x)
|
||||
{
|
||||
msg(MSG_DIALOG, "got signal %d", x);
|
||||
}
|
Loading…
Reference in New Issue