1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.client; |
2 |
> |
package uk.org.iscream.client; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
6 |
< |
import uk.ac.ukc.iscream.core.*; |
7 |
< |
import uk.ac.ukc.iscream.util.*; |
5 |
> |
import uk.org.iscream.componentmanager.*; |
6 |
> |
import uk.org.iscream.core.*; |
7 |
> |
import uk.org.iscream.util.*; |
8 |
|
import java.io.*; |
9 |
|
|
10 |
|
/** |
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.getPath(), true)); |
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 |
|
/** |
176 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
177 |
|
* method to provide clean logging (every class should have this). |
178 |
|
* |
179 |
< |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
179 |
> |
* This uses the uk.org.iscream.util.FormatName class |
180 |
|
* to format the toString() |
181 |
|
* |
182 |
|
* @return the name of this class and its CVS revision |