Revision d8af1309 snf-stats-app/synnefo_stats/grapher.py
b/snf-stats-app/synnefo_stats/grapher.py | ||
---|---|---|
43 | 43 |
|
44 | 44 |
import rrdtool |
45 | 45 |
|
46 |
from Crypto.Cipher import AES |
|
47 |
from base64 import b64decode |
|
48 |
|
|
46 | 49 |
from synnefo_stats import settings |
47 | 50 |
|
48 | 51 |
from synnefo.util.text import uenc |
... | ... | |
196 | 199 |
outfname += "-net.png" |
197 | 200 |
|
198 | 201 |
rrdtool.graph(outfname, "-s", "-1d", "-e", "-20s", |
199 |
#"-t", "Network traffic", |
|
200 | 202 |
"--units", "si", |
201 | 203 |
"-v", "Bits/s", |
202 |
#"--lazy", |
|
203 | 204 |
"COMMENT:\t\t\tAverage network traffic\\n", |
204 | 205 |
"DEF:rx=%s:rx:AVERAGE" % fname, |
205 | 206 |
"DEF:tx=%s:tx:AVERAGE" % fname, |
... | ... | |
218 | 219 |
outfname += "-net-weekly.png" |
219 | 220 |
|
220 | 221 |
rrdtool.graph(outfname, "-s", "-1w", "-e", "-20s", |
221 |
#"-t", "Network traffic", |
|
222 | 222 |
"--units", "si", |
223 | 223 |
"-v", "Bits/s", |
224 |
#"--lazy", |
|
225 | 224 |
"COMMENT:\t\t\tAverage network traffic\\n", |
226 | 225 |
"DEF:rx=%s:rx:AVERAGE" % fname, |
227 | 226 |
"DEF:tx=%s:tx:AVERAGE" % fname, |
... | ... | |
235 | 234 |
return read_file(outfname) |
236 | 235 |
|
237 | 236 |
|
237 |
def decrypt(secret): |
|
238 |
# Make sure key is 32 bytes long |
|
239 |
key = sha256(settings.SECRET_KEY).digest() |
|
240 |
|
|
241 |
aes = AES.new(key) |
|
242 |
return aes.decrypt(zeropad(b64decode(secret))) |
|
243 |
|
|
244 |
|
|
238 | 245 |
available_graph_types = { |
239 | 246 |
'cpu-bar': draw_cpu_bar, |
240 | 247 |
'net-bar': draw_net_bar, |
... | ... | |
248 | 255 |
@api_method(http_method='GET', token_required=False, user_required=False, |
249 | 256 |
format_allowed=False, logger=log) |
250 | 257 |
def grapher(request, graph_type, hostname): |
251 |
fname = uenc(os.path.join(settings.RRD_PREFIX, hostname))
|
|
258 |
fname = uenc(os.path.join(settings.RRD_PREFIX, decrypt(hostname)))
|
|
252 | 259 |
if not os.path.isdir(fname): |
253 | 260 |
raise faults.ItemNotFound('No such instance') |
254 | 261 |
|
Also available in: Unified diff