53 |
|
// that to a file. |
54 |
|
|
55 |
|
public void receiveXMLPacket(XMLPacket packet) { |
56 |
+ |
String packetType = packet.getParam("packet.attributes.type"); |
57 |
+ |
if(packetType == null || !packetType.equals("data")) { |
58 |
+ |
// bail out, without warning |
59 |
+ |
// this is probably a heartbeat or similar |
60 |
+ |
return; |
61 |
+ |
} |
62 |
|
// get config proxy |
63 |
|
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
64 |
|
// get file locations |
74 |
|
} |
75 |
|
// get raw data |
76 |
|
String data = packet.printAll(); |
77 |
< |
String hostname = packet.getParam("packet.attributes.host_name"); |
77 |
> |
String hostname = packet.getParam("packet.attributes.machine_name"); |
78 |
|
// set paths |
79 |
|
String destDir = rootPath+"/"+latestSubDir+"/"+hostname; |
80 |
|
String destFile = destDir+"/"+latestFileName; |
81 |
< |
// write data |
81 |
> |
// try to create directory |
82 |
|
File outDir = new File(destDir); |
83 |
< |
if(outDir.mkdirs()) { |
84 |
< |
File outFile = new File(destFile); |
85 |
< |
if(outFile.canWrite()) { |
86 |
< |
PrintWriter out; |
87 |
< |
try { |
88 |
< |
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 |
< |
} |
83 |
> |
if(!outDir.exists()) { |
84 |
> |
if(!outDir.mkdirs()) { |
85 |
> |
// didn't exist, and we couldn't make it |
86 |
> |
_logger.write(this.toString(), Logger.ERROR, "Failed to create directory: "+outDir.getPath()); |
87 |
> |
// bail out |
88 |
> |
return; |
89 |
|
} |
90 |
< |
else { |
91 |
< |
_logger.write(this.toString(), Logger.ERROR, "File not readable: "+outFile.getPath()); |
90 |
> |
} |
91 |
> |
// directory has been made, check file exists |
92 |
> |
File outFile = new File(destFile); |
93 |
> |
if(!outFile.exists()) { |
94 |
> |
try { |
95 |
> |
outFile.createNewFile(); |
96 |
> |
} catch (IOException e) { |
97 |
> |
_logger.write(this.toString(), Logger.ERROR, "Failed to create file: "+e); |
98 |
> |
// bail out |
99 |
> |
return; |
100 |
|
} |
101 |
|
} |
102 |
+ |
// file should now exist |
103 |
+ |
if(outFile.canWrite()) { |
104 |
+ |
PrintWriter out; |
105 |
+ |
try { |
106 |
+ |
out = new PrintWriter(new FileWriter(outFile)); |
107 |
+ |
out.println(data); |
108 |
+ |
out.close(); |
109 |
+ |
} catch (IOException e) { |
110 |
+ |
_logger.write(this.toString(), Logger.ERROR, "Failed to write file: "+e); |
111 |
+ |
} |
112 |
+ |
} |
113 |
|
else { |
114 |
< |
_logger.write(this.toString(), Logger.ERROR, "Failed to create directory: "+outDir.getPath()); |
114 |
> |
_logger.write(this.toString(), Logger.ERROR, "File not writeable: "+outFile.getPath()); |
115 |
|
} |
116 |
|
} |
117 |
|
|
118 |
|
public void receiveAlert(Alert alert) { |
119 |
< |
// process and save |
119 |
> |
// get config proxy |
120 |
> |
ConfigurationProxy cp = ConfigurationProxy.getInstance(); |
121 |
> |
// get file locations |
122 |
> |
String rootPath, alertSubDir, alertFileName; |
123 |
> |
try { |
124 |
> |
rootPath = cp.getProperty("WebFeeder", "WebFeeder.rootPath"); |
125 |
> |
alertSubDir = cp.getProperty("WebFeeder", "WebFeeder.alertSubDir"); |
126 |
> |
alertFileName = cp.getProperty("WebFeeder", "WebFeeder.alertFileName"); |
127 |
> |
} catch (PropertyNotFoundException e) { |
128 |
> |
_logger.write(this.toString(), Logger.ERROR, "Failed to get config for Alert Data: "+e); |
129 |
> |
// bail out |
130 |
> |
return; |
131 |
> |
} |
132 |
> |
// get raw data |
133 |
> |
String data = alert.printAll(); |
134 |
> |
String hostname = alert.getSource(); |
135 |
> |
// set paths |
136 |
> |
String destDir = rootPath+"/"+alertSubDir+"/"+hostname; |
137 |
> |
String destFile = destDir+"/"+alertFileName; |
138 |
> |
// try to create directory |
139 |
> |
File outDir = new File(destDir); |
140 |
> |
if(!outDir.exists()) { |
141 |
> |
if(!outDir.mkdirs()) { |
142 |
> |
// didn't exist, and we couldn't make it |
143 |
> |
_logger.write(this.toString(), Logger.ERROR, "Failed to create directory: "+outDir.getPath()); |
144 |
> |
// bail out |
145 |
> |
return; |
146 |
> |
} |
147 |
> |
} |
148 |
> |
// directory has been made, check file exists |
149 |
> |
File outFile = new File(destFile); |
150 |
> |
if(!outFile.exists()) { |
151 |
> |
try { |
152 |
> |
outFile.createNewFile(); |
153 |
> |
} catch (IOException e) { |
154 |
> |
_logger.write(this.toString(), Logger.ERROR, "Failed to create file: "+e); |
155 |
> |
// bail out |
156 |
> |
return; |
157 |
> |
} |
158 |
> |
} |
159 |
> |
// file should now exist |
160 |
> |
if(outFile.canWrite()) { |
161 |
> |
PrintWriter out; |
162 |
> |
try { |
163 |
> |
out = new PrintWriter(new FileWriter(outFile)); |
164 |
> |
out.println(data); |
165 |
> |
out.close(); |
166 |
> |
} catch (IOException e) { |
167 |
> |
_logger.write(this.toString(), Logger.ERROR, "Failed to write file: "+e); |
168 |
> |
} |
169 |
> |
} |
170 |
> |
else { |
171 |
> |
_logger.write(this.toString(), Logger.ERROR, "File not writeable: "+outFile.getPath()); |
172 |
> |
} |
173 |
|
} |
174 |
|
|
175 |
|
/** |