68 |
|
} |
69 |
|
// get raw data |
70 |
|
String data = packet.printAll(); |
71 |
< |
String hostname = packet.getParam("packet.attributes.host_name"); |
71 |
> |
String hostname = packet.getParam("packet.attributes.machine_name"); |
72 |
|
// set paths |
73 |
|
String destDir = rootPath+"/"+latestSubDir+"/"+hostname; |
74 |
|
String destFile = destDir+"/"+latestFileName; |
75 |
< |
// write data |
75 |
> |
// try to create directory |
76 |
|
File outDir = new File(destDir); |
77 |
< |
if(outDir.mkdirs()) { |
78 |
< |
File outFile = new File(destFile); |
79 |
< |
if(outFile.canWrite()) { |
80 |
< |
PrintWriter out; |
81 |
< |
try { |
82 |
< |
out = new PrintWriter(new FileWriter(outFile)); |
83 |
< |
out.println(data); |
84 |
< |
out.close(); |
85 |
< |
} catch (IOException e) { |
86 |
< |
_logger.write(this.toString(), Logger.ERROR, "Failed to write file: "+e); |
87 |
< |
} |
77 |
> |
if(!outDir.exists()) { |
78 |
> |
if(!outDir.mkdirs()) { |
79 |
> |
// didn't exist, and we couldn't make it |
80 |
> |
_logger.write(this.toString(), Logger.ERROR, "Failed to create directory: "+outDir.getPath()); |
81 |
> |
// bail out |
82 |
> |
return; |
83 |
|
} |
84 |
< |
else { |
85 |
< |
_logger.write(this.toString(), Logger.ERROR, "File not readable: "+outFile.getPath()); |
84 |
> |
} |
85 |
> |
// directory has been made, check file exists |
86 |
> |
File outFile = new File(destFile); |
87 |
> |
if(!outFile.exists()) { |
88 |
> |
try { |
89 |
> |
outFile.createNewFile(); |
90 |
> |
} catch (IOException e) { |
91 |
> |
_logger.write(this.toString(), Logger.ERROR, "Failed to create file: "+e); |
92 |
> |
// bail out |
93 |
> |
return; |
94 |
|
} |
95 |
|
} |
96 |
+ |
// file should now exist |
97 |
+ |
if(outFile.canWrite()) { |
98 |
+ |
PrintWriter out; |
99 |
+ |
try { |
100 |
+ |
out = new PrintWriter(new FileWriter(outFile)); |
101 |
+ |
out.println(data); |
102 |
+ |
out.close(); |
103 |
+ |
} catch (IOException e) { |
104 |
+ |
_logger.write(this.toString(), Logger.ERROR, "Failed to write file: "+e); |
105 |
+ |
} |
106 |
+ |
} |
107 |
|
else { |
108 |
< |
_logger.write(this.toString(), Logger.ERROR, "Failed to create directory: "+outDir.getPath()); |
108 |
> |
_logger.write(this.toString(), Logger.ERROR, "File not writeable: "+outFile.getPath()); |
109 |
|
} |
110 |
|
} |
111 |
|
|