From: <lin...@us...> - 2010-08-29 19:58:29
|
Revision: 14 http://nuggetfarm.svn.sourceforge.net/nuggetfarm/?rev=14&view=rev Author: linuxgeek247 Date: 2010-08-29 19:58:23 +0000 (Sun, 29 Aug 2010) Log Message: ----------- Updating files for fsmonitor Modified Paths: -------------- trunk/collection-nuggets/fsmonitor/Makefile trunk/collection-nuggets/fsmonitor/README Added Paths: ----------- trunk/collection-nuggets/fsmonitor/fsmonitor.c Removed Paths: ------------- trunk/collection-nuggets/fsmonitor/file_monitor.c Modified: trunk/collection-nuggets/fsmonitor/Makefile =================================================================== --- trunk/collection-nuggets/fsmonitor/Makefile 2010-08-29 19:56:42 UTC (rev 13) +++ trunk/collection-nuggets/fsmonitor/Makefile 2010-08-29 19:58:23 UTC (rev 14) @@ -6,7 +6,7 @@ all: file-monitor file-monitor:: - $(CC) $(INCLUDES) $(LIBS) file_monitor.c -o file_monitor + $(CC) $(INCLUDES) $(LIBS) fsmonitor.c -o fsmonitor clean: - rm -f file_monitor + rm -f fsmonitor Modified: trunk/collection-nuggets/fsmonitor/README =================================================================== --- trunk/collection-nuggets/fsmonitor/README 2010-08-29 19:56:42 UTC (rev 13) +++ trunk/collection-nuggets/fsmonitor/README 2010-08-29 19:58:23 UTC (rev 14) @@ -10,4 +10,4 @@ Usage: # Copy rzb.conf and update required information to point to your dispatcher - ./file_monitor /monitor/path /monitor/path2 + ./fsmonitor /monitor/path /monitor/path2 Deleted: trunk/collection-nuggets/fsmonitor/file_monitor.c =================================================================== --- trunk/collection-nuggets/fsmonitor/file_monitor.c 2010-08-29 19:56:42 UTC (rev 13) +++ trunk/collection-nuggets/fsmonitor/file_monitor.c 2010-08-29 19:58:23 UTC (rev 14) @@ -1,152 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <signal.h> -#include <stdlib.h> -#include <inotifytools/inotifytools.h> -#include <inotifytools/inotify.h> -#include <uuid/uuid.h> -#include <rzb_global.h> -#include <rzb_conf.h> -#include <rzb_client.h> -#include <rzb_network.h> - -#define MAX_FILE_NAME 1024 - -void cleanup(int sig) { - printf("\nCleaning up and shutting down\n"); - inotifytools_cleanup(); -} - -int file_size(char *filename) { - FILE *fp = NULL; - int size = 0; - - if((fp = fopen(filename, "r")) != NULL) { - fseek(fp, 0L, SEEK_END); - size = ftell(fp); - fclose(fp); - } - else { - perror("Error opening file"); - } - - return size; -} - -// Returns malloc'ed data block. Free when you are done -char *read_file(char *filename) { - FILE *fp = NULL; - char *data = NULL; - int size = 0; - - if((fp = fopen(filename, "r")) != NULL) { - - if((size = file_size(filename)) > 0) { - - if((data = malloc(size)) != NULL) { - fread(data, 1, size, fp); - } - else { - perror("Error allocating space"); - } - } - else { - perror("Error getting filesize or empty file"); - } - - fclose(fp); - } - else { - perror("Error opening file for reading"); - } - - return data; -} - - -int main(int argc, char *argv[]) { - int i = 0, fd = 0; - struct inotify_event *event = NULL; - char filename[MAX_FILE_NAME], *data = NULL; - BLOCK_META_DATA *metaData; - - // We can accept any number of paths to monitor - if(argc < 2) { - printf("Usage: %s <path to monitor> ...\n", argv[0]); - return -1; - } - - // Make sure inotify tools initializes properly - if(!inotifytools_initialize()) { - fprintf(stderr, "%s\n", strerror(inotifytools_error())); - return -1; - } - - // Add listeners for all specified directories - for(i = 1; i < argc; i++) { - if(!inotifytools_watch_recursively(argv[i], IN_CLOSE_WRITE)) { - fprintf(stderr, "%s\n", strerror(inotifytools_error())); - } - } - - // Hijack sigint so we can close cleanly - signal(SIGINT, cleanup); - - // Read in the config - readConfig(&nrtconfig, "rzb.conf"); - - // We'll need this later to randomize our port - srand(time(NULL)); - - // Register ourselves as a nugget - registerNugget(COLLECTOR, TESTCOLLECT, NO_DATA_TYPE, ((rand() % 30000) + 30000), 1, 0, "file-monitor-collector"); - - // Read all of the events and send any files being written to - while(event = inotifytools_next_event(-1)) { - - // Make sure we can get the filename - if(inotifytools_snprintf(filename, MAX_FILE_NAME - 1, event, "%w%f") <= 0) { - fprintf(stderr, "Unable to get event filename\n"); - continue; - } - - // Read in the actual data from the file - if((data = read_file(filename)) == NULL) { - fprintf(stderr, "Unable to read file for submission"); - continue; - } - - // We need to malloc each new message - if((metaData = malloc(sizeof(BLOCK_META_DATA))) == NULL) { - fprintf(stderr, "Error allocating space for metadata"); - continue; - } - - // Zero out the metadata - memset(metaData, 0, sizeof(BLOCK_META_DATA)); - - // Fill in the required data - metaData->timestamp = time(NULL); - metaData->data = data; - metaData->size = file_size(filename); - uuid_copy(metaData->datatype, (const unsigned char *)file_type_lookup(data, file_size(filename))); - - // Required for now - metaData->ip_proto = 6; - metaData->src_port = 1; - metaData->dst_port = 1; - inet_aton("127.0.0.1", &metaData->dst_ip); - inet_aton("127.0.0.1", &metaData->src_ip); - - // Finally, send the data (sendData will free) - if(uuid_compare(metaData->datatype, NO_DATA_TYPE) != 0) { - sendData(metaData); - } - else { - printf("Unable to send unknown file type\n"); - } - } - - return 0; -} Copied: trunk/collection-nuggets/fsmonitor/fsmonitor.c (from rev 13, trunk/collection-nuggets/fsmonitor/file_monitor.c) =================================================================== --- trunk/collection-nuggets/fsmonitor/fsmonitor.c (rev 0) +++ trunk/collection-nuggets/fsmonitor/fsmonitor.c 2010-08-29 19:58:23 UTC (rev 14) @@ -0,0 +1,152 @@ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <signal.h> +#include <stdlib.h> +#include <inotifytools/inotifytools.h> +#include <inotifytools/inotify.h> +#include <uuid/uuid.h> +#include <rzb_global.h> +#include <rzb_conf.h> +#include <rzb_client.h> +#include <rzb_network.h> + +#define MAX_FILE_NAME 1024 + +void cleanup(int sig) { + printf("\nCleaning up and shutting down\n"); + inotifytools_cleanup(); +} + +int file_size(char *filename) { + FILE *fp = NULL; + int size = 0; + + if((fp = fopen(filename, "r")) != NULL) { + fseek(fp, 0L, SEEK_END); + size = ftell(fp); + fclose(fp); + } + else { + perror("Error opening file"); + } + + return size; +} + +// Returns malloc'ed data block. Free when you are done +char *read_file(char *filename) { + FILE *fp = NULL; + char *data = NULL; + int size = 0; + + if((fp = fopen(filename, "r")) != NULL) { + + if((size = file_size(filename)) > 0) { + + if((data = malloc(size)) != NULL) { + fread(data, 1, size, fp); + } + else { + perror("Error allocating space"); + } + } + else { + perror("Error getting filesize or empty file"); + } + + fclose(fp); + } + else { + perror("Error opening file for reading"); + } + + return data; +} + + +int main(int argc, char *argv[]) { + int i = 0, fd = 0; + struct inotify_event *event = NULL; + char filename[MAX_FILE_NAME], *data = NULL; + BLOCK_META_DATA *metaData; + + // We can accept any number of paths to monitor + if(argc < 2) { + printf("Usage: %s <path to monitor> ...\n", argv[0]); + return -1; + } + + // Make sure inotify tools initializes properly + if(!inotifytools_initialize()) { + fprintf(stderr, "%s\n", strerror(inotifytools_error())); + return -1; + } + + // Add listeners for all specified directories + for(i = 1; i < argc; i++) { + if(!inotifytools_watch_recursively(argv[i], IN_CLOSE_WRITE)) { + fprintf(stderr, "%s\n", strerror(inotifytools_error())); + } + } + + // Hijack sigint so we can close cleanly + signal(SIGINT, cleanup); + + // Read in the config + readConfig(&nrtconfig, "rzb.conf"); + + // We'll need this later to randomize our port + srand(time(NULL)); + + // Register ourselves as a nugget + registerNugget(COLLECTOR, TESTCOLLECT, NO_DATA_TYPE, ((rand() % 30000) + 30000), 1, 0, "file-monitor-collector"); + + // Read all of the events and send any files being written to + while(event = inotifytools_next_event(-1)) { + + // Make sure we can get the filename + if(inotifytools_snprintf(filename, MAX_FILE_NAME - 1, event, "%w%f") <= 0) { + fprintf(stderr, "Unable to get event filename\n"); + continue; + } + + // Read in the actual data from the file + if((data = read_file(filename)) == NULL) { + fprintf(stderr, "Unable to read file for submission"); + continue; + } + + // We need to malloc each new message + if((metaData = malloc(sizeof(BLOCK_META_DATA))) == NULL) { + fprintf(stderr, "Error allocating space for metadata"); + continue; + } + + // Zero out the metadata + memset(metaData, 0, sizeof(BLOCK_META_DATA)); + + // Fill in the required data + metaData->timestamp = time(NULL); + metaData->data = data; + metaData->size = file_size(filename); + uuid_copy(metaData->datatype, (const unsigned char *)file_type_lookup(data, file_size(filename))); + + // Required for now + metaData->ip_proto = 6; + metaData->src_port = 1; + metaData->dst_port = 1; + inet_aton("127.0.0.1", &metaData->dst_ip); + inet_aton("127.0.0.1", &metaData->src_ip); + + // Finally, send the data (sendData will free) + if(uuid_compare(metaData->datatype, NO_DATA_TYPE) != 0) { + sendData(metaData); + } + else { + printf("Unable to send unknown file type\n"); + } + } + + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |