Commit e6119fc7 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* Fixed log directory, it now corrosponds to the rest of BWM Tools

* Better error handling while generating graphs & rrd data
* Fixed bug preventing graphing from working 
parent b02c060b
......@@ -27,7 +27,7 @@ RRDTOOL_LIBS=@RRDTOOL_LIBS@
RRDTOOL_LDADDS=@RRDTOOL_LDADDS@
RRDTOOL_VER=@RRDTOOL_VER@
LOG_DIR=@localstatedir@/bwm_tools
LOG_DIR=/var/bwm_tools
bin_PROGRAMS = bwm_graph
bwm_graph_SOURCES = bwm_graph.c graph.c
......
......@@ -200,7 +200,7 @@ RRDTOOL_INCLUDEDIR = @RRDTOOL_INCLUDEDIR@
RRDTOOL_LIBS = @RRDTOOL_LIBS@
RRDTOOL_LDADDS = @RRDTOOL_LDADDS@
RRDTOOL_VER = @RRDTOOL_VER@
LOG_DIR = @localstatedir@/bwm_tools
LOG_DIR = /var/bwm_tools
bwm_graph_SOURCES = bwm_graph.c graph.c
bwm_graph_DEPENDENCIES = $(RRDTOOL_LDADDS)
bwm_graph_LDADD = $(top_builddir)/lib/libbwm.la $(RRDTOOL_LDADDS)
......
......@@ -260,14 +260,16 @@ int writeRRDFile(GList *graphSources, struct graphOptions_t *options)
fd = open(filename,O_RDONLY);
if (fd < 0)
{
fprintf(stderr,"Failed opening file %s: %s\n",filename,strerror(errno));
printf(" ERROR!\n");
fprintf(stderr,"ERROR: Failed opening file %s: %s\n",filename,strerror(errno));
return;
}
// Grab header
opRes = read(fd,&fileHeader,sizeof(struct aLogFileHeader_t));
if (opRes != sizeof(struct aLogFileHeader_t))
{
fprintf(stderr,"Error reading header from file %s: %s\n",filename,strerror(errno));
printf(" ERROR!\n");
fprintf(stderr,"ERROR: Error reading header from file %s: %s\n",filename,strerror(errno));
close(fd);
return;
}
......@@ -281,7 +283,8 @@ int writeRRDFile(GList *graphSources, struct graphOptions_t *options)
opRes = lseek(fd,sizeof(struct aLogFileHeader_t) + (j * sizeof(struct aLogFileEntry_t)),SEEK_SET);
if (opRes < 0)
{
fprintf(stderr,"Error seeking end %s: %s\n",filename,strerror(errno));
printf(" ERROR!\n");
fprintf(stderr,"ERROR: Error seeking end %s: %s\n",filename,strerror(errno));
err = 1;
break;
}
......@@ -294,6 +297,7 @@ int writeRRDFile(GList *graphSources, struct graphOptions_t *options)
opRes = read(fd,fileEntry,sizeof(struct aLogFileEntry_t));
if (opRes < 0)
{
printf(" ERROR!\n");
fprintf(stderr,"Error reading file entry %s: %s\n",filename,strerror(errno));
err = 1;
break;
......@@ -316,10 +320,10 @@ int writeRRDFile(GList *graphSources, struct graphOptions_t *options)
}
// Close file...
close(fd);
printf("sorting...");
printf(" sorting...");
// Sort our list of data...
entryList = g_list_sort(entryList,sort_newest);
printf("writing RRD file %s...",rrd_filename);
printf(" generating RRD:%s...",rrd_filename);
// Set "static" params
snprintf(params[1],BUFFER_SIZE,"%s",rrd_filename);
strcpy(params[2],"--template");
......@@ -387,19 +391,21 @@ int createRRDFiles(GList *graphSources, struct graphOptions_t *options)
// Get the filename
snprintf(filename,MAX_NAMELEN,"%s/%s.dat",LOG_DIR,aSource->flowRef);
printf(" Getting details for %s...",filename);
printf(" Processing %s...",filename);
// Open
fd = open(filename,O_RDONLY);
if (fd < 0)
{
fprintf(stderr,"Failed opening file %s: %s\n",filename,strerror(errno));
printf(" ERROR!\n");
fprintf(stderr,"ERROR: Failed to open %s: %s\n",filename,strerror(errno));
return;
}
// Grab header
opRes = read(fd,&fileHeader,sizeof(struct aLogFileHeader_t));
if (opRes != sizeof(struct aLogFileHeader_t))
{
fprintf(stderr,"Error reading header from file %s: %s\n",filename,strerror(errno));
printf(" ERROR!\n");
fprintf(stderr,"ERROR: Failed to read from %s: %s\n",filename,strerror(errno));
close(fd);
return;
}
......@@ -408,7 +414,7 @@ int createRRDFiles(GList *graphSources, struct graphOptions_t *options)
close(fd);
snprintf(filename,MAX_NAMELEN,"%s/%s.rrd",LOG_DIR,aSource->flowRef);
printf(" %s ...",filename);
printf(" RRD:%s...",filename);
// Create params
memset(params[5],'\0',BUFFER_SIZE);
memset(params[6],'\0',BUFFER_SIZE);
......@@ -441,7 +447,7 @@ int createRRDFiles(GList *graphSources, struct graphOptions_t *options)
fprintf(stderr,"Failed to create RRD file %s: %s\n",filename,rrd_get_error());
return;
}
printf("done\n");
printf(" done\n");
i++;
}
......@@ -621,10 +627,8 @@ int writeGraphs(GList *graphSources, struct graphOptions_t *options)
}
g_list_foreach(graphSources,processSourceOptions,NULL);
// Check if we must display our cute little line
if (hasOptions)
ADD_SINGLE_PARAM(params,numParams,"COMMENT:%s\\c","- * - * -");
ADD_SINGLE_PARAM(params,numParams,"COMMENT:%s\\c","Graph generated by bwm_tools v"PACKAGE_VERSION" (http://bwm-tools.pr.linuxrulz.org)");
ADD_SINGLE_PARAM(params,numParams,"COMMENT:%s\\c","- * - * -");
ADD_SINGLE_PARAM(params,numParams,"COMMENT:%s\\c","Graph generated by BWM Tools");
// Call rrd tool
optind = 0; opterr = 0;
......@@ -638,11 +642,12 @@ int writeGraphs(GList *graphSources, struct graphOptions_t *options)
#endif
if (result < 0)
{
fprintf(stderr,"Failed to create RRD graph %s: %s\n",options->outputFile,rrd_get_error());
printf(" ERROR!\n");
fprintf(stderr,"ERROR: Failed to create RRD graph %s: %s\n",options->outputFile,rrd_get_error());
result = -1;
}
else
printf("done (%dx%d)\n",xsize,ysize);
printf(" done (%dx%d)\n",xsize,ysize);
// Free memory
for (i = 0; i < numParams; i++)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment