Fixes destination stat

This commit is contained in:
kevgliss 2015-10-06 09:43:31 -07:00
parent 73cb8da8c1
commit 798a6295ee
3 changed files with 38 additions and 36 deletions

View File

@ -8,6 +8,7 @@
from sqlalchemy import func from sqlalchemy import func
from lemur import database from lemur import database
from lemur.models import certificate_destination_associations
from lemur.destinations.models import Destination from lemur.destinations.models import Destination
from lemur.certificates.models import Certificate from lemur.certificates.models import Certificate
@ -117,10 +118,9 @@ def stats(**kwargs):
:param kwargs: :param kwargs:
:return: :return:
""" """
attr = getattr(Destination, kwargs.get('metric')) items = database.db.session.query(Destination.label, func.count(certificate_destination_associations.c.certificate_id))\
query = database.db.session.query(attr, func.count(attr)) .join(certificate_destination_associations)\
.group_by(Destination.label).all()
items = query.group_by(attr).all()
keys = [] keys = []
values = [] values = []

View File

@ -84,8 +84,8 @@ angular.module('lemur')
$scope.expiring = {labels: data.items.labels, values: [data.items.values]}; $scope.expiring = {labels: data.items.labels, values: [data.items.values]};
}); });
LemurRestangular.all('destinations').customGET('stats', {metric: 'certificates'}) LemurRestangular.all('destinations').customGET('stats', {metric: 'certificate'})
.then(function (data) { .then(function (data) {
$scope.destinations = {labels: data.items.labels, values: [data.items.values]}; $scope.destinations = data.items;
}); });
}); });

View File

@ -10,7 +10,8 @@
<h3 class="panel-title">Expiring Certificates</h3> <h3 class="panel-title">Expiring Certificates</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<canvas id="expiringBar" class="chart chart-bar" data="expiring.values" labels="expiring.labels" colours="colours"></canvas> <canvas id="expiringBar" class="chart chart-bar" data="expiring.values" labels="expiring.labels"
colours="colours"></canvas>
</div> </div>
</div> </div>
</div> </div>
@ -22,7 +23,8 @@
<h3 class="panel-title">Issuers</h3> <h3 class="panel-title">Issuers</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<canvas id="issuersPie" class="chart chart-pie" data="issuers.values" labels="issuers.labels" colours="colours" legend="true"></canvas> <canvas id="issuersPie" class="chart chart-pie" data="issuers.values" labels="issuers.labels" colours="colours"
legend="true"></canvas>
</div> </div>
</div> </div>
</div> </div>
@ -32,7 +34,8 @@
<h3 class="panel-title">Bit Strength</h3> <h3 class="panel-title">Bit Strength</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<canvas id="bitsPie" class="chart chart-pie" data="bits.values" labels="bits.labels" colours="colours" legend="true"></canvas> <canvas id="bitsPie" class="chart chart-pie" data="bits.values" labels="bits.labels" colours="colours"
legend="true"></canvas>
</div> </div>
</div> </div>
</div> </div>
@ -43,10 +46,9 @@
<h3 class="panel-title">Destinations</h3> <h3 class="panel-title">Destinations</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<canvas id="destinationPie" class="chart chart-pie" data="destinations.values" labels="destinations.labels" colours="colours" legend="true"></canvas> <canvas id="destinationPie" class="chart chart-pie" data="destinations.values" labels="destinations.labels"
colours="colours" legend="true"></canvas>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- /.row -->
</div>