36 |
|
*/ |
37 |
|
public final int DEFAULT_AGE = 3600; |
38 |
|
|
39 |
+ |
/** |
40 |
+ |
* The default path seperator, here for convienience |
41 |
+ |
*/ |
42 |
+ |
private final String sep = File.separator; |
43 |
+ |
|
44 |
|
//---STATIC METHODS--- |
45 |
|
|
46 |
|
/** |
76 |
|
alertSubDir = cp.getProperty("WebFeeder", "WebFeeder.alertSubDir"); |
77 |
|
File alertsDir = new File(rootPath, alertSubDir); |
78 |
|
if(deleteContents(alertsDir)) { |
79 |
< |
_logger.write(this.toString(), Logger.DEBUG, "Deleted all files and directories from: "+rootPath+"/"+alertSubDir); |
79 |
> |
_logger.write(this.toString(), Logger.DEBUG, "Deleted all files and directories from: "+rootPath+sep+alertSubDir); |
80 |
|
} else { |
81 |
< |
_logger.write(this.toString(), Logger.WARNING, "Failed to delete all files and directories from: "+rootPath+"/"+alertSubDir); |
81 |
> |
_logger.write(this.toString(), Logger.WARNING, "Failed to delete all files and directories from: "+rootPath+sep+alertSubDir); |
82 |
|
} |
83 |
|
// cleanup complete |
84 |
|
} catch (PropertyNotFoundException e) { |
148 |
|
|
149 |
|
// list the files and delete as appropriate |
150 |
|
File alertsDir = new File(rootPath, alertSubDir); |
151 |
+ |
// get all the hostnames directories |
152 |
|
File[] contents = alertsDir.listFiles(); |
153 |
|
for(int i=0; i < contents.length; i++) { |
154 |
+ |
// get a single directory from the array.. |
155 |
|
File hostdir = contents[i]; |
156 |
+ |
// ..and check it's a directory |
157 |
|
if(hostdir.isDirectory()) { |
158 |
+ |
// get all the contents of that directory |
159 |
|
File[] hostdirContents = hostdir.listFiles(); |
160 |
|
for(int j=0; j < hostdirContents.length; j++) { |
161 |
|
File alertFile = hostdirContents[j]; |
162 |
+ |
// get the filename.. |
163 |
|
String filename = alertFile.getName(); |
164 |
+ |
// ..and see if it ends with OK or FINAL |
165 |
|
if(filename.endsWith(Alert.alertLevels[0]) || |
166 |
|
filename.endsWith(Alert.alertLevels[Alert.alertLevels.length-1])) { |
167 |
< |
// it ends with either OK or FINAL |
167 |
> |
// it does end with either OK or FINAL |
168 |
|
// ... so we can check it for deletion |
169 |
|
long lastModified = alertFile.lastModified(); |
170 |
|
long age = System.currentTimeMillis() - lastModified; |
211 |
|
String data = packet.printAll(); |
212 |
|
String hostname = packet.getParam("packet.attributes.machine_name"); |
213 |
|
// set paths |
214 |
< |
File outDir = new File(rootPath, latestSubDir+"/"+hostname); |
215 |
< |
File outFile = new File(rootPath, latestSubDir+"/"+hostname+"/"+latestFileName); |
214 |
> |
File outDir = new File(rootPath, latestSubDir+sep+hostname); |
215 |
> |
File outFile = new File(rootPath, latestSubDir+sep+hostname+sep+latestFileName); |
216 |
|
// write the data out |
217 |
|
writeData(outDir, outFile, data); |
218 |
|
} |
241 |
|
String data = alert.printAll(); |
242 |
|
String hostname = alert.getSource(); |
243 |
|
// set paths |
244 |
< |
File outDir = new File(rootPath, alertSubDir+"/"+hostname); |
245 |
< |
String destFile = alertSubDir+"/"+hostname+"/"+alertFileName+"."+String.valueOf(alert.getInitialAlertTime()); |
244 |
> |
File outDir = new File(rootPath, alertSubDir+sep+hostname); |
245 |
> |
String destFile = alertSubDir+sep+hostname+sep+alertFileName+"."+String.valueOf(alert.getInitialAlertTime()); |
246 |
|
File outFile; |
247 |
|
// check if we're at a special "end case" (OK or FINAL) |
248 |
|
if(alert.getLevel()==0 || alert.getLevel()==Alert.alertLevels.length-1) { |
252 |
|
_logger.write(this.toString(), Logger.WARNING, "Failed to rename old file, "+oldFile.getPath()+" to new file, "+outFile.getPath()); |
253 |
|
} |
254 |
|
} else { |
255 |
< |
outFile = new File(destFile); |
255 |
> |
outFile = new File(rootPath, destFile); |
256 |
|
} |
257 |
|
// write the data out |
258 |
|
writeData(outDir, outFile, data); |