Misc updates and comments
This commit is contained in:
parent
5ebbb2ec58
commit
8fae4c40a7
21
sim/sim.py
21
sim/sim.py
|
@ -1,24 +1,29 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys
|
|
||||||
import socket
|
import socket
|
||||||
import os
|
import os
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
DEST = ("127.0.0.1", 4200)
|
DEST = "127.0.0.1"
|
||||||
FNAME = 1
|
|
||||||
|
|
||||||
|
|
||||||
def main(fname):
|
def main():
|
||||||
with open(os.path.join(os.path.dirname(__file__), fname), "r") as f:
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("file")
|
||||||
|
parser.add_argument("port", type=int, default=4200)
|
||||||
|
parser.add_argument("rate", type=float, default=1)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
with open(os.path.join(os.path.dirname(args.file), args.file), "r") as f:
|
||||||
lines = [line.rstrip().encode("UTF-8") for line in f]
|
lines = [line.rstrip().encode("UTF-8") for line in f]
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
while True:
|
while True:
|
||||||
for line in lines:
|
for line in lines:
|
||||||
sock.sendto(line, DEST)
|
sock.sendto(line, (DEST, args.port))
|
||||||
sleep(1)
|
sleep(args.rate)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main(sys.argv[FNAME])
|
main()
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
|
||||||
ADD csyslog /csyslog
|
ADD csyslog /csyslog
|
||||||
|
ADD GeoLiteCity.dat /
|
||||||
|
ADD GeoLiteCityv6.dat /
|
||||||
|
|
||||||
STOPSIGNAL 9
|
STOPSIGNAL 9
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@ const char* geo_country_name(GeoIPRecord* rec) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
|
|
||||||
static const char * _mk_NA( const char * p ){
|
static const char * _mk_NA( const char * p ){
|
||||||
return p ? p : "N/A";
|
return p ? p : "N/A";
|
||||||
}
|
}
|
||||||
|
@ -44,7 +43,7 @@ static const char * _mk_NA( const char * p ){
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
geo_init();
|
geo_init();
|
||||||
char* host = "24.4.129.164";
|
char* host = "24.4.129.164";
|
||||||
char* host6 = "2601:647:4701:733:5bf:f3c2:f2b2:9c1f";
|
// char* host6 = "2601:647:4701:733:5bf:f3c2:f2b2:9c1f";
|
||||||
|
|
||||||
GeoIPRecord *gir = GeoIP_record_by_name(gi, (const char *) host); // GeoIP_record_by_name_v6
|
GeoIPRecord *gir = GeoIP_record_by_name(gi, (const char *) host); // GeoIP_record_by_name_v6
|
||||||
// GeoIPRecord *gir = GeoIP_record_by_name_v6(gi, (const char *) host6);
|
// GeoIPRecord *gir = GeoIP_record_by_name_v6(gi, (const char *) host6);
|
||||||
|
@ -64,5 +63,4 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
geo_close();
|
geo_close();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,7 +15,7 @@ int main(int argc, char** argv) {
|
||||||
char* portend;
|
char* portend;
|
||||||
unsigned int portl;
|
unsigned int portl;
|
||||||
portl = strtol(argv[1], &portend, 10);
|
portl = strtol(argv[1], &portend, 10);
|
||||||
if (portend == NULL) {
|
if (portend == NULL || portend == argv[1]) {
|
||||||
fprintf(stderr, "usage: %s <port>\n", argv[0]);
|
fprintf(stderr, "usage: %s <port>\n", argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
15
src/server.c
15
src/server.c
|
@ -1,7 +1,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -40,7 +39,6 @@ void sig_handler(int signum) {
|
||||||
|
|
||||||
|
|
||||||
int submit_events(char* message) {
|
int submit_events(char* message) {
|
||||||
// Send it
|
|
||||||
if(put_events(message, "http://192.168.1.120:8298") == 0) {
|
if(put_events(message, "http://192.168.1.120:8298") == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -51,6 +49,10 @@ int submit_events(char* message) {
|
||||||
|
|
||||||
|
|
||||||
char* collect_buffer(int max_size, int* howmany) {
|
char* collect_buffer(int max_size, int* howmany) {
|
||||||
|
/*
|
||||||
|
Pop up to $howmany items from the message buffer and allocate a buffer of at most $max_size bytes containing them.
|
||||||
|
Returns a char pointer to the buffer
|
||||||
|
*/
|
||||||
char header[72];
|
char header[72];
|
||||||
// sprintf(header, "{\"index\": {\"_index\": \"firewall-test\", \"_type\": \"event\"}}\n");
|
// sprintf(header, "{\"index\": {\"_index\": \"firewall-test\", \"_type\": \"event\"}}\n");
|
||||||
sprintf(header, "{\"index\": {\"_index\": \"firewall-%04d.%02d.%02d\", \"_type\": \"event\"}}\n",
|
sprintf(header, "{\"index\": {\"_index\": \"firewall-%04d.%02d.%02d\", \"_type\": \"event\"}}\n",
|
||||||
|
@ -89,7 +91,9 @@ char* collect_buffer(int max_size, int* howmany) {
|
||||||
|
|
||||||
|
|
||||||
void* buffer_watch() {
|
void* buffer_watch() {
|
||||||
/*flush the buffer when larger than 10 messages or older than 5 seconds*/
|
/*
|
||||||
|
Threaded task that flushes the buffer when it is larger than 10 messages or older than 5 seconds
|
||||||
|
*/
|
||||||
time_t last_flush = time(NULL);
|
time_t last_flush = time(NULL);
|
||||||
char* buffer = NULL;
|
char* buffer = NULL;
|
||||||
while(running) {
|
while(running) {
|
||||||
|
@ -125,6 +129,9 @@ void* buffer_watch() {
|
||||||
|
|
||||||
|
|
||||||
void start_bufwatch() {
|
void start_bufwatch() {
|
||||||
|
/*
|
||||||
|
Start the bufwatch thread
|
||||||
|
*/
|
||||||
if (pthread_mutex_init(&buflock, NULL) != 0) {
|
if (pthread_mutex_init(&buflock, NULL) != 0) {
|
||||||
printf("\n mutex init failed\n");
|
printf("\n mutex init failed\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -262,5 +269,5 @@ int run_server(int port) {
|
||||||
bufwatch_cleanup();
|
bufwatch_cleanup();
|
||||||
buff_freeall();
|
buff_freeall();
|
||||||
geo_close();
|
geo_close();
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue