Allow filter alarms with query including '/'

For example: mount_point=/
Django can't handle encoded URI correctly,
so this implementation uses base64url.

And allow filter alarms with dimensions having only key.

Change-Id: Ie23403278d4791c702abffd855cf0682510ac153
This commit is contained in:
Shinya Kawabata 2016-08-03 17:00:37 +09:00
parent a181c1cc34
commit 2ef9661ffd
4 changed files with 25 additions and 9 deletions

View File

@ -23,14 +23,19 @@
var dimension = document.forms["form1"]["dimension"].value;
var metric = document.forms["form1"]["metric"].value;
var location = "{{ alarm_url }}";
var param = '';
if (!isEmpty(metric)) {
location = location + "metric=" + metric;
param = 'metric=' + metric;
if (!isEmpty(dimension)) {
location = location + ",";
param = param + ',';
}
}
if (!isEmpty(dimension)) {
location = location + dimension;
param = param + dimension;
}
if (!isEmpty(param)) {
param = btoa(param).replace(/\+/g, '-').replace(/\//g, '_');
location = location + 'b64:' + param;
}
window.location = location;
}
@ -48,7 +53,7 @@
<hr>
<form method="GET" class="form-group" style="width:400px" onsubmit="sendDimensions()" name="form1">
<h3>{% trans 'Dimension(s)' %}</h3>
{% trans 'Key' %}:{% trans 'Value' %}
{% trans 'Key' %}[={% trans 'Value' %}]
<input class="form-control" name="dimension" placeholder="hostname=devstack, service=mysql" data-toggle="tooltip" data-placement="right" title="Example: hostname=devstack, service=mysql">
<br />
{% trans 'Metric Name' %}: <input class="form-control" name="metric" placeholder="http_status">

View File

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import base64
from datetime import timedelta
import logging
@ -157,6 +158,9 @@ class AlarmServiceView(tables.DataTableView):
return results
else:
try:
if self.service[:3] == 'b64':
name, value = self.service.split(":")
self.service = base64.urlsafe_b64decode(str(value))
results = api.monitor.alarm_list_by_dimension(self.request,
self.service,
page_offset,

View File

@ -70,11 +70,14 @@ def alarm_list_by_dimension(request, dimensions, offset=0, limit=10000,
dimensions = dimensions.replace(" ", "")
dimensions = dimensions.split(",")
for item in dimensions:
name, value = item.split("=")
if name == 'metric':
metric = value
if '=' in item:
name, value = item.split('=')
if name == 'metric':
metric = value
else:
dim_dict[name] = value
else:
dim_dict[name] = value
dim_dict[item] = None
if metric:
result = monascaclient(request).alarms.list(offset=offset, limit=limit,
metric_dimensions=dim_dict,

View File

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import base64
import copy
import json
import logging
@ -203,9 +204,12 @@ def generate_status(request):
group_alarms.append(a)
services = []
for group, group_alarms in alarms_by_group.items():
name = '%s=%s' % (row['groupBy'], group)
# Encode as base64url to be able to include '/'
name = 'b64:' + base64.urlsafe_b64encode(name)
service = {
'display': group,
'name': "%s=%s" % (row['groupBy'], group),
'name': name,
'class': get_status(group_alarms)
}
service['icon'] = get_icon(service['class'])