Misc updates and comments

This commit is contained in:
dave 2018-07-15 17:41:13 -07:00
parent 5ebbb2ec58
commit 8fae4c40a7
5 changed files with 28 additions and 16 deletions

View File

@ -1,24 +1,29 @@
#!/usr/bin/env python3
import sys
import socket
import os
from time import sleep
import argparse
DEST = ("127.0.0.1", 4200)
FNAME = 1
DEST = "127.0.0.1"
def main(fname):
with open(os.path.join(os.path.dirname(__file__), fname), "r") as f:
def main():
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]
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while True:
for line in lines:
sock.sendto(line, DEST)
sleep(1)
sock.sendto(line, (DEST, args.port))
sleep(args.rate)
if __name__ == '__main__':
main(sys.argv[FNAME])
main()

View File

@ -1,6 +1,8 @@
FROM scratch
ADD csyslog /csyslog
ADD GeoLiteCity.dat /
ADD GeoLiteCityv6.dat /
STOPSIGNAL 9

View File

@ -36,7 +36,6 @@ const char* geo_country_name(GeoIPRecord* rec) {
}
#ifdef TEST
static const char * _mk_NA( const char * p ){
return p ? p : "N/A";
}
@ -44,7 +43,7 @@ static const char * _mk_NA( const char * p ){
int main(int argc, char** argv) {
geo_init();
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_v6(gi, (const char *) host6);
@ -64,5 +63,4 @@ int main(int argc, char** argv) {
geo_close();
}
#endif

View File

@ -15,7 +15,7 @@ int main(int argc, char** argv) {
char* portend;
unsigned int portl;
portl = strtol(argv[1], &portend, 10);
if (portend == NULL) {
if (portend == NULL || portend == argv[1]) {
fprintf(stderr, "usage: %s <port>\n", argv[0]);
exit(1);
}

View File

@ -1,7 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
@ -40,7 +39,6 @@ void sig_handler(int signum) {
int submit_events(char* message) {
// Send it
if(put_events(message, "http://192.168.1.120:8298") == 0) {
return 0;
} else {
@ -51,6 +49,10 @@ int submit_events(char* message) {
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];
// sprintf(header, "{\"index\": {\"_index\": \"firewall-test\", \"_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() {
/*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);
char* buffer = NULL;
while(running) {
@ -125,6 +129,9 @@ void* buffer_watch() {
void start_bufwatch() {
/*
Start the bufwatch thread
*/
if (pthread_mutex_init(&buflock, NULL) != 0) {
printf("\n mutex init failed\n");
exit(1);
@ -262,5 +269,5 @@ int run_server(int port) {
bufwatch_cleanup();
buff_freeall();
geo_close();
return 1;
return 0;
}