From 6f6e4ead54f50bff45f9e358c26a87309fee5aa9 Mon Sep 17 00:00:00 2001 From: Rob Raymond Date: Tue, 29 Apr 2014 12:27:34 -0600 Subject: [PATCH] Changes for demo --- monitoring/api/__init__.py | 0 monitoring/api/__init__.pyc | Bin 0 -> 155 bytes monitoring/api/monitoring.py | 99 +++++++++++++++ monitoring/api/monitoring.pyc | Bin 0 -> 3476 bytes monitoring/static/monitoring/js/alarms.html | 11 -- .../static/monitoring/js/animation.html | 118 ------------------ monitoring/static/monitoring/js/animations.js | 52 -------- .../static/monitoring/js/controllers.js | 90 +------------ monitoring/templates/monitoring/_scripts.html | 3 +- monitoring/templates/monitoring/index.html | 2 +- monitoring/templates/monitoring/monitor.html | 3 +- .../monitoring/newmonitor.html} | 19 +-- monitoring/views.py | 37 +++--- 13 files changed, 134 insertions(+), 300 deletions(-) create mode 100644 monitoring/api/__init__.py create mode 100644 monitoring/api/__init__.pyc create mode 100644 monitoring/api/monitoring.py create mode 100644 monitoring/api/monitoring.pyc delete mode 100644 monitoring/static/monitoring/js/alarms.html delete mode 100644 monitoring/static/monitoring/js/animation.html delete mode 100644 monitoring/static/monitoring/js/animations.js rename monitoring/{static/monitoring/js/health.html => templates/monitoring/newmonitor.html} (52%) diff --git a/monitoring/api/__init__.py b/monitoring/api/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/monitoring/api/__init__.pyc b/monitoring/api/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..35c102533277c3f37d2785c05d954d31c5739089 GIT binary patch literal 155 zcmZSn%*&PC92lI;00oRd+5w1*S%5?e14FO|NW@PANHCxg#V$ZG{m|mnqGJ7`#LC?K zyp$sSf};Ga)Z`NV{DRcH;*!MVZ2gSiW(km;m#&{!kf|RZp9$p0$LkeT WmT&+KvdPU)Da}c>16fxL#0&sSFC?`9 literal 0 HcmV?d00001 diff --git a/monitoring/api/monitoring.py b/monitoring/api/monitoring.py new file mode 100644 index 00000000..154d5d05 --- /dev/null +++ b/monitoring/api/monitoring.py @@ -0,0 +1,99 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import logging + +from django.conf import settings +from monclient import client as mon_client +from horizon.utils import functions as utils +from openstack_dashboard.api import base + +LOG = logging.getLogger(__name__) + + +class AttrStore: + pass + +def format_parameters(params): + parameters = {} + for count, p in enumerate(params, 1): + parameters['Parameters.member.%d.ParameterKey' % count] = p + parameters['Parameters.member.%d.ParameterValue' % count] = params[p] + return parameters + + +def monclient(request, password=None): + api_version = "2_0" + insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) + cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) + endpoint = 'http://192.168.10.4:8080/v2.0' # base.url_for(request, 'orchestration') + LOG.debug('monclient connection created using token "%s" and url "%s"' % + (request.user.token.id, endpoint)) + kwargs = { + 'token': request.user.token.id, + 'insecure': insecure, + 'ca_file': cacert, + 'username': request.user.username, + 'password': password + #'timeout': args.timeout, + #'ca_file': args.ca_file, + #'cert_file': args.cert_file, + #'key_file': args.key_file, + } + client = mon_client.Client(api_version, endpoint, **kwargs) + client.format_parameters = format_parameters + return client + + +def alarm_list(request, marker=None, paginate=False): + limit = getattr(settings, 'API_RESULT_LIMIT', 1000) + page_size = utils.get_page_size(request) + + if paginate: + request_size = page_size + 1 + else: + request_size = limit + + kwargs = {} + if marker: + kwargs['marker'] = marker + args = AttrStore() + args.runlocal = True + args.os_tenant_id = "12345678" + alarm_iter = monclient(request).alarms.list(args, **kwargs) + + has_more_data = False + alarms = list(alarm_iter) + if paginate: + if len(alarms) > page_size: + alarms.pop() + has_more_data = True + return (alarms, has_more_data) + + +def alarm_delete(request, alarm_id): + return monclient(request).alarm.delete(alarm_id) + + +def alarm_get(request, alarm_id): + return monclient(request).alarm.get(alarm_id) + + +def alarm_create(request, password=None, **kwargs): + return monclient(request, password).alarm.create(**kwargs) + + +def alarm_update(request, alarm_id, **kwargs): + return monclient(request).alarm.update(alarm_id, **kwargs) + diff --git a/monitoring/api/monitoring.pyc b/monitoring/api/monitoring.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2d6b81ad58e3d3728c3f28eb5ce59f6a0471cf17 GIT binary patch literal 3476 zcmcgu-E!Mh5MIeYv0XdqZ$e99LQBCH9Xkmn4W$J_nlhom?Z|1FdMFx2I&tL4lB;vv z(vEYL-u6X!2Ogl;JOeY_^8oPe$`gm_1qj&{%Pe!EAxKWdfV%#UrK#=jh% zU*XojfCTtk6cKf@u}zUheVaNqSv;4cC`bJ~bqX1ur>IE%De9CmzCcl#`W5O_$WlbT z6QrtiU{R+=L6L$P3a02K(E-t;&NKxjW;&2s6qM;D*5!DtPEk;ymoR&pf)ldl3yvB2@#-weNr0OtStoUo(nw7)Fjzvzpjxp735V7gHvDa6wYbubqZa)cz5!h^% zEM=nafHWUymFi~dJ?|%RkTwTt(o?=^CIb~~O0%O;N8zqXO+92Ph^h{QC?lYZ-|`X)TYSqJ&5GUYV=X`Uz~eWpbcP?t+=a^WOdSR(or8?XKHyZ@R5}?!$Fw<_Kmr< z)wOkJOTUMSU1J6}n$5+}mKux8D~-j4#+7ueBLB`DxSY|MPHitVhGbn7|FQINwI~oR{k(mW(rz;&)o?lB@;tb7T2LL z15fK`NgC8^SS3rl%6O=52Rw<&J6?pU7i1@~k{E2>`$nb$wLR?06f1SO&mf7YsK7bH zV+H{nax;$vtZUL`oGNDO3<$BAswYFGjl;1s9BNdu`xIpZ=N-nFyy|#AmFqD~E{x z70ejf0{1c2ZR(+m0O%-&JcBU3Mhw>+%>nXpk$VjW+@vtJC~Y$ZOi>dzW2nsYvB7`^ zcmY^UWCKW09iq5bre1|-8Qri`;wbNzIYFb6SjGUBUkmChEWsA`@+=vlIBIOdf&skq zirGZS#Lks+;TTJzT4Oee@76c8%mz~Ub=?_a@H4@KDqYk z^7WPaG#KX`6Wkfzh9-=(VLSqgXe(Xi>hOh*UW(qxNr*xqY?ddmD~fQ|@pF(2q_`bUsdI&=d4n(;#;7@gc@*|TBj?`X zZp7pmw%PVB@vCfy!6?WV+ir;VFW&5W8b@BL+`u!Qa}_I(2d!LmnQ8X;b8z}25CT+Z z?4nh(i=cP{q(05A}0(v5$-sdBe3`g z%uz2m;C$a@Ie*=ttDw#~D`+NJhHQF8Z)PZSgzF+ZQL@|#^11aojN#*PXp))C@?%)~ z7d{<@92yjQ*Bhvt_%s}#veXfuI6wc3Pnl(J;!_qx{!EbbElRp*CtW$(f}R(5lLk)r z9qD;eI&ye97kNE5zVWwhLt3H30Cqm+IaYZ11<TcefKS4H`Hu9Y%!oC?IAN_HZ6^ zJv#3&;l3niuEQ#%3p&?%#O=Yk#pFvSs~{5q$mnf;E|#GFX7<_t#SF&!0!Y<9iL(=z UJ(D|=E0?NsGZ)JFa=x1X3yNI&{{R30 literal 0 HcmV?d00001 diff --git a/monitoring/static/monitoring/js/alarms.html b/monitoring/static/monitoring/js/alarms.html deleted file mode 100644 index df022d99..00000000 --- a/monitoring/static/monitoring/js/alarms.html +++ /dev/null @@ -1,11 +0,0 @@ - -
-
-
-
- \ No newline at end of file diff --git a/monitoring/static/monitoring/js/animation.html b/monitoring/static/monitoring/js/animation.html deleted file mode 100644 index c84f2f5b..00000000 --- a/monitoring/static/monitoring/js/animation.html +++ /dev/null @@ -1,118 +0,0 @@ - - - - -CoverFlow - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- - value - - - \ No newline at end of file diff --git a/monitoring/static/monitoring/js/animations.js b/monitoring/static/monitoring/js/animations.js deleted file mode 100644 index b40ddb06..00000000 --- a/monitoring/static/monitoring/js/animations.js +++ /dev/null @@ -1,52 +0,0 @@ -var monitoringAnimations = angular.module('monitoring.animations', ['ngAnimate']); - -monitoringAnimations.animation('.phone', function() { - - var animateUp = function(element, className, done) { - if(className != 'active') { - return; - } - element.css({ - position: 'absolute', - top: 500, - left: 0, - display: 'block' - }); - - jQuery(element).animate({ - top: 0 - }, done); - - return function(cancel) { - if(cancel) { - element.stop(); - } - }; - } - - var animateDown = function(element, className, done) { - if(className != 'active') { - return; - } - element.css({ - position: 'absolute', - left: 0, - top: 0 - }); - - jQuery(element).animate({ - top: -500 - }, done); - - return function(cancel) { - if(cancel) { - element.stop(); - } - }; - } - - return { - addClass: animateUp, - removeClass: animateDown - }; -}); diff --git a/monitoring/static/monitoring/js/controllers.js b/monitoring/static/monitoring/js/controllers.js index 52283012..a432f8b1 100644 --- a/monitoring/static/monitoring/js/controllers.js +++ b/monitoring/static/monitoring/js/controllers.js @@ -1,61 +1,7 @@ 'use strict'; angular.module('monitoring.controllers', []) .controller('monitoringController', function ($scope, $http) { - $scope._serviceModel = [{'name': 'Platform Services', - 'services': [{'name': 'MaaS', - 'display': 'MaaS'}, - {'name': 'DBaaS', - 'display': 'DBaaS'}, - {'name': 'LBaaS', - 'display': 'LBaaS'}, - {'name': 'DNSaaS', - 'display': 'DNSaaS'}, - {'name': 'MSGaaS', - 'display': 'MSGaaS'}, - ]}, - {'name': 'The OverCloud Services', - 'services': [{'name': 'nova', - 'display': 'Nova'}, - {'name': 'swift', - 'display': 'Swift'}, - {'name': 'bock', - 'display': 'Cinder'}, - {'name': 'glance', - 'display': 'Glance'}, - {'name': 'quantum', - 'display': 'Neutron'}, - {'name': 'mysql', - 'display': 'MySQL'}, - {'name': 'rabbitmq', - 'display': 'RabbitMQ'}, - ]}, - {'name': 'The UnderCloud Services', - 'services': [{'name': 'nova', - 'display': 'Nova'}, - {'name': 'swift', - 'display': 'Cinder'}, - {'name': 'glance', - 'display': 'Glance'}, - {'name': 'horizon', - 'display': 'Horizon'}, - ]}, - {'name': 'Network Services', - 'services': [{'name': 'dhcp', - 'display': 'DHCP'}, - {'name': 'dns', - 'display': 'DNS'}, - {'name': 'dns-servers', - 'display': 'DNS Servers'}, - {'name': 'http', - 'display': 'http'}, - {'name': 'web_proxy', - 'display': 'Web Proxy'} - ]} - ] - $scope.setStatus = function() { - $scope.fetchStatus() - }; - $scope.fetchStatus = function() { + $scope.fetchStatus = function() { $http({method: 'GET', url: '/admin/monitoring/status'}). success(function(data, status, headers, config) { // this callback will be called asynchronously @@ -76,22 +22,7 @@ angular.module('monitoring.controllers', []) alert("error") }); } - $scope.serviceModel = function() { - $scope.setStatus() - return $scope._serviceModel - } - $scope.current = 1; - $scope.showService = function(ev) { - // href="#/alarms/{{service.name}}" - console.log(ev.clientX, ev.clientY); - //$("#current"+$scope.current)[0].style.webkitTransform = "scale3d(10, 10, +1)" - //$("#current"+$scope.current).style.opacity = "0" - //$("#current"+$scope.current).style.visibility = false - $scope.current += 1; - //$("#current"+$scope.current)[0].style.webkitTransform = "translate3d(0,-400px,-1)" - }; - $scope.format = 'M/d/yy h:mm:ss a'; - }) + }) .controller('alarmController', function($scope) { $scope.myData = [{name: "API Response Time", status: 'Normal'}, {name: "System Health", status: 'Normal'}, @@ -102,23 +33,6 @@ angular.module('monitoring.controllers', []) columnDefs: [{field:'name', displayName:'Name'}, {field:'status', displayName:'Status'}]}; }); -function getRandomStatusValue() { - var distribution = [ - {prob:.04, value:'alert-error'}, - {prob:.04, value:'alert-warning'}, - {prob:.04, value:'alert-unknown'}, - {prob:.04, value:'alert-notfound'}, - {value:'alert-success'}, - ] - var num = Math.random() - for (var i=0; i < distribution.length - 1; i++) { - if (num < distribution[i]["prob"]) - return distribution[i]["value"] - num = num - distribution[i]["prob"] - } - return distribution[distribution.length - 1]["value"] -} - function getIcon(status) { if (status === 'alert-error') return '/static/monitoring/img/critical-icon.png' diff --git a/monitoring/templates/monitoring/_scripts.html b/monitoring/templates/monitoring/_scripts.html index 544fc907..af34e863 100644 --- a/monitoring/templates/monitoring/_scripts.html +++ b/monitoring/templates/monitoring/_scripts.html @@ -1,5 +1,4 @@ + - - \ No newline at end of file diff --git a/monitoring/templates/monitoring/index.html b/monitoring/templates/monitoring/index.html index 0c55f21e..5550f0c8 100644 --- a/monitoring/templates/monitoring/index.html +++ b/monitoring/templates/monitoring/index.html @@ -7,5 +7,5 @@ {% endblock page_header %} {% load url from future %} {% block main %} - {% include 'admin/monitoring/monitorng.html' %} + {% include 'admin/monitoring/newmonitor.html' %} {% endblock %} \ No newline at end of file diff --git a/monitoring/templates/monitoring/monitor.html b/monitoring/templates/monitoring/monitor.html index 7b96fe53..e82af159 100644 --- a/monitoring/templates/monitoring/monitor.html +++ b/monitoring/templates/monitoring/monitor.html @@ -1,5 +1,4 @@ - -
+
{% for group in service_groups %}
diff --git a/monitoring/static/monitoring/js/health.html b/monitoring/templates/monitoring/newmonitor.html similarity index 52% rename from monitoring/static/monitoring/js/health.html rename to monitoring/templates/monitoring/newmonitor.html index 1b31de4c..1041d3cf 100644 --- a/monitoring/static/monitoring/js/health.html +++ b/monitoring/templates/monitoring/newmonitor.html @@ -19,27 +19,28 @@ border-color: blue; color: lightgrey; } .diagram { - -webkit-transition: all 600ms ease-in-out; - background-color: darkgray; padding: 5px; } -
+
Current time is: + + + + diff --git a/monitoring/views.py b/monitoring/views.py index 74fd1b9f..ece807a8 100644 --- a/monitoring/views.py +++ b/monitoring/views.py @@ -24,9 +24,11 @@ from django.utils.translation import ugettext as _ from django.views.generic import TemplateView from horizon import tables + +from monitoring.api import monitoring + from .tables import AlertsTable from .tables import AlertHistoryTable -from openstack_dashboard import api LOG = logging.getLogger(__name__) @@ -140,7 +142,7 @@ class StatusView(TemplateView): def get(self, request, *args, **kwargs): services = ['MaaS', ] - #api.monitoring.alarm_list(self.request) + #monitoring.alarm_list(self.request) for group in SAMPLE: for service in group['services']: service['class'] = get_random_status() @@ -151,21 +153,6 @@ class StatusView(TemplateView): return HttpResponse(json.dumps(ret), content_type='application/json') -def get_random_status(): - distribution = [ - {'prob':.04, 'value':'alert-error'}, - {'prob':.04, 'value':'alert-warning'}, - {'prob':.04, 'value':'alert-unknown'}, - {'prob':.04, 'value':'alert-notfound'}, - {'prob':1.0, 'value':'alert-success'}, - ] - num = random.random() - for dist in distribution: - if num < dist["prob"]: - return dist["value"] - num = num - dist["prob"] - return distribution[len(distribution) - 1]["value"] - class AlertView(tables.DataTableView): table_class = AlertsTable @@ -224,3 +211,19 @@ class AlertHistoryView(tables.DataTableView): class AlertMeterView(TemplateView): template_name = 'admin/monitoring/alert_meter.html' + + +def get_random_status(): + distribution = [ + {'prob':.04, 'value':'alert-error'}, + {'prob':.04, 'value':'alert-warning'}, + {'prob':.04, 'value':'alert-unknown'}, + {'prob':.04, 'value':'alert-notfound'}, + {'prob':1.0, 'value':'alert-success'}, + ] + num = random.random() + for dist in distribution: + if num < dist["prob"]: + return dist["value"] + num = num - dist["prob"] + return distribution[len(distribution) - 1]["value"] \ No newline at end of file