44 #include <flowmonexp/plugin_export.h>
47 #define PRINTV(format, args...) do {if (VERBOSE) { fprintf(stdout, format, ##args); fflush(stdout); } } while (0)
49 #define PRINTD(format, args...) do {if (DEBUG) { fprintf(stdout, format, ##args); fflush(stdout); } } while (0)
51 #define PRINTA(format, args...) do {if (VERBOSE || DEBUG) { fprintf(stdout, format, ##args); fflush(stdout); } } while (0)
87 static plugin_desc_t pcap_desc = {
89 "Plugin which outputs all records to file in csv format\n"
91 " file=/path/file file to write into\n"
92 " verbose=y/n verbose mode(default same as flowmonexp)\n"
93 " debug=y/n debug mode(default same as flowmonexp\n)",
115 char *token, *value, *param;
119 if (params == NULL) {
120 fprintf(stderr,
"input-http-flow need parameters\n");
125 token = strtok(params,
",=");
126 while (token != NULL) {
131 PRINTA(
"param: %s\t", param);
132 PRINTA(
"value: %s\n", value);
133 if (strcmp(
"file", param) == 0) {
134 conf->
f = fopen(value,
"a");
135 }
else if (strcmp(
"verbose", param) == 0) {
136 if (strcmp(value,
"y") == 0) {
138 }
else if (strcmp(value,
"n") == 0) {
141 fprintf(stderr,
" value of 'verbose' parameter is not valid");
143 }
else if (strcmp(
"debug", param) == 0) {
144 if (strcmp(value,
"y") == 0) {
146 }
else if (strcmp(value,
"n") == 0) {
149 fprintf(stderr,
" value of 'debug' parameter is not valid");
152 fprintf(stderr,
"Unknown parameter '%s'\n", param);
158 token = strtok(NULL,
",=");
171 void *plugin_export_init(
char *params, flow_record_getter_t *getter_list)
173 if (verbose_level >= 0) {
178 if (debug_level >= 0) {
183 PRINTA(
"plugin export init start\n");
185 flow_record_getter_t *tmp = getter_list;
191 fei_parse_params(params, retval);
195 while (tmp && tmp->name) {
196 PRINTD(
"getter: %s - %i\n", tmp->name, tmp->length);
197 getter_copy_to(&retval->
getters, tmp);
201 PRINTA(
"plugin export init end\n");
212 int plugin_export_export(
void *plugin_private, flow_record_t *record)
214 PRINTD(
"plugin export export start\n");
216 flow_record_getter_t *tmp = p->
getters;
217 unsigned char block[1024];
224 fputs(
"Cant open output file.\n", stderr);
228 fprintf(output,
"FLOW: %i, ", p->
counter++);
229 while (tmp && tmp->name) {
230 if (tmp->valid(tmp->self, record)) {
231 fprintf(output,
", ");
232 len = tmp->current_length(tmp->self, record);
238 fprintf(output,
"%s: ", tmp->name);
240 tmp->filler(tmp->self, record, block, len, 1);
241 if (tmp->length > 0) {
242 for (i = 0; i < len; i++) {
243 fprintf(output,
"%02X", block[i]);
252 fprintf(output,
"\n");
253 PRINTV(
"flow data written into file\n");
254 PRINTD(
"plugin export export end\n");
265 int plugin_export_flush(
void *plugin_private)
267 PRINTD(
"plugin flush start\n");
269 PRINTD(
"plugin flush end\n");