Skip to content

Commit

Permalink
Merge pull request #717 from setchy/feature/dashboard-violations
Browse files Browse the repository at this point in the history
feat(dashboard): policy violations by state and classification cards
  • Loading branch information
nscuro authored Feb 3, 2024
2 parents e88974d + b6c9846 commit 90d49af
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 24 deletions.
64 changes: 52 additions & 12 deletions src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
<b-card>
<b-row>
<b-col sm="5">
<h4 id="chart-violations" class="card-title mb-0">{{ $t('message.policy_violations') }}</h4>
<h4 id="chart-policy-violations-state" class="card-title mb-0">{{ $t('message.policy_violations') }}</h4>
<div class="small text-muted">{{$t('message.policy_violations_by_state')}}</div>
</b-col>
<b-col sm="7" class="d-none d-md-block">
</b-col>
</b-row>
<chart-policy-violations ref="chartPolicyViolations" chartId="chartPolicyViolations" class="chart-wrapper" style="height:200px;margin-top:40px;" :height="200"></chart-policy-violations>
<div slot="footer">
<chart-policy-violations-state ref="chartPolicyViolationsState" chartId="chartPolicyViolationsState" class="chart-wrapper" style="height:200px;margin-top:40px;" :height="200"></chart-policy-violations-state> <div slot="footer">
<b-row class="text-center">
<b-col class="mb-sm-2 mb-0 d-md-down-none">
<b-col class="mb-sm-2 mb-0">
<div class="text-muted">{{ $t("policy_violation.fails") }}</div>
<strong>{{ failViolations }} ({{ failViolationsPercent }}%)</strong>
<b-progress height="{}" class="progress-xs mt-2 status-failed" :precision="1" v-bind:value="failViolationsPercent"></b-progress>
Expand All @@ -71,6 +71,37 @@
</div>
</b-card>
</b-col>
<b-col sm="6">
<b-card>
<b-row>
<b-col sm="5">
<h4 id="chart-policy-violations-classification" class="card-title mb-0">{{ $t('message.policy_violations') }}</h4>
<div class="small text-muted">{{$t('message.policy_violations_by_classification')}}</div> </b-col>
<b-col sm="7" class="d-none d-md-block">
</b-col>
</b-row>
<chart-policy-violations-classification ref="chartPolicyViolationsClassification" chartId="chartPolicyViolationsClassification" class="chart-wrapper" style="height:200px;margin-top:40px;" :height="200"></chart-policy-violations-classification>
<div slot="footer">
<b-row class="text-center">
<b-col class="mb-sm-2 mb-0">
<div class="text-muted">{{ $t("policy_violation.security") }}</div>
<strong>{{ securityViolations }} ({{ securityViolationsPercent }}%)</strong>
<b-progress height="{}" class="progress-xs mt-2 status-failed" :precision="1" v-bind:value="securityViolationsPercent"></b-progress>
</b-col>
<b-col class="mb-sm-2 mb-0">
<div class="text-muted">{{ $t("policy_violation.operational") }}</div>
<strong>{{ operationalViolations }} ({{ operationalViolationsPercent }}%)</strong>
<b-progress height="{}" class="progress-xs mt-2 status-warning" :precision="1" v-bind:value="operationalViolationsPercent"></b-progress>
</b-col>
<b-col class="mb-sm-2 mb-0">
<div class="text-muted">{{ $t("policy_violation.license") }}</div>
<strong>{{ licenseViolations }} ({{ licenseViolationsPercent }}%)</strong>
<b-progress height="{}" class="progress-xs mt-2 status-info" :precision="1" v-bind:value="licenseViolationsPercent"></b-progress>
</b-col>
</b-row>
</div>
</b-card>
</b-col>
</b-row>

<b-row>
Expand Down Expand Up @@ -286,7 +317,8 @@
import ChartProjectVulnerabilities from "./dashboard/ChartProjectVulnerabilities";
import ChartAuditingFindingsProgress from "./dashboard/ChartAuditingFindingsProgress";
import ChartAuditingViolationsProgress from "./dashboard/ChartAuditingViolationsProgress";
import ChartPolicyViolations from "./dashboard/ChartPolicyViolations";
import ChartPolicyViolationsState from "./dashboard/ChartPolicyViolationsState";
import ChartPolicyViolationsClassification from "./dashboard/ChartPolicyViolationsClassification";
import ChartComponentVulnerabilities from "./dashboard/ChartComponentVulnerabilities";
import { Callout } from '@coreui/vue'
import permissionsMixin from "../mixins/permissionsMixin";
Expand All @@ -301,7 +333,8 @@
ChartProjectVulnerabilities,
ChartAuditingFindingsProgress,
ChartAuditingViolationsProgress,
ChartPolicyViolations,
ChartPolicyViolationsState,
ChartPolicyViolationsClassification,
ChartComponentVulnerabilities
},
data() {
Expand Down Expand Up @@ -335,9 +368,12 @@
warnViolationsPercent: 0,
infoViolations: 0,
infoViolationsPercent: 0,
licenseViolations: 0,
operationalViolations: 0,
securityViolations: 0,
securityViolationsPercent: 0,
operationalViolations: 0,
operationalViolationsPercent: 0,
licenseViolations: 0,
licenseViolationsPercent: 0,
vulnerabilities: 0,
suppressed: 0,
Expand Down Expand Up @@ -379,9 +415,12 @@
this.warnViolationsPercent = common.calcProgressPercent(this.totalViolations, this.warnViolations);
this.infoViolations = common.valueWithDefault(metric.policyViolationsInfo, "0");
this.infoViolationsPercent = common.calcProgressPercent(this.totalViolations, this.infoViolations);
this.licenseViolations = common.valueWithDefault(metric.policyViolationsLicenseTotal,"0");
this.operationalViolations = common.valueWithDefault(metric.policyViolationsOperationalTotal,"0");
this.securityViolations = common.valueWithDefault(metric.policyViolationsSecurityTotal,"0");
this.securityViolations = common.valueWithDefault(metric.policyViolationsSecurityTotal, "0");
this.securityViolationsPercent = common.calcProgressPercent(this.totalViolations, this.securityViolations);
this.operationalViolations = common.valueWithDefault(metric.policyViolationsOperationalTotal, "0");
this.operationalViolationsPercent = common.calcProgressPercent(this.totalViolations, this.operationalViolations);
this.licenseViolations = common.valueWithDefault(metric.policyViolationsLicenseTotal, "0");
this.licenseViolationsPercent = common.calcProgressPercent(this.totalViolations, this.licenseViolations);
this.vulnerabilities = common.valueWithDefault(metric.vulnerabilities, "0");
this.suppressed = common.valueWithDefault(metric.suppressed, "0");
Expand All @@ -404,7 +443,8 @@
this.$refs.chartProjectVulnerabilities.render(response.data);
this.$refs.chartAuditingFindingsProgress.render(response.data);
this.$refs.chartAuditingViolationsProgress.render(response.data);
this.$refs.chartPolicyViolations.render(response.data);
this.$refs.chartPolicyViolationsState.render(response.data);
this.$refs.chartPolicyViolationsClassification.render(response.data);
this.$refs.chartComponentVulnerabilities.render(response.data);
this.extractStats(response.data);
});
Expand Down
106 changes: 106 additions & 0 deletions src/views/dashboard/ChartPolicyViolationsClassification.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<script>
import common from "../../shared/common"
import { Line } from 'vue-chartjs'
import { getStyle } from '@coreui/coreui/dist/js/coreui-utilities'
import { CustomTooltips } from '@coreui/coreui-plugin-chartjs-custom-tooltips'
export default {
extends: Line,
props: {
height: Number
},
methods: {
render: function(metrics) {
const securityStyle = getStyle('--notification-fail');
const operationalStyle = getStyle('--notification-warn');
const licenseStyle = getStyle('--notification-info');
let labels = [];
let securityData = [];
let operationalData = [];
let licenseData = [];
for (let i = 0; i < metrics.length; i++) {
labels.push(common.formatTimestamp(metrics[i].firstOccurrence));
securityData.push(metrics[i].policyViolationsSecurityTotal);
operationalData.push(metrics[i].policyViolationsOperationalTotal);
licenseData.push(metrics[i].policyViolationsLicenseTotal);
if (i === metrics.length - 1) {
labels.push(common.formatTimestamp(metrics[i].lastOccurrence));
securityData.push(metrics[i].policyViolationsSecurityTotal);
operationalData.push(metrics[i].policyViolationsOperationalTotal);
licenseData.push(metrics[i].policyViolationsLicenseTotal);
}
}
this.renderChart({
labels: labels,
datasets: [
{
label: this.$t('policy_violation.security'),
backgroundColor: 'transparent',
borderColor: securityStyle,
pointHoverBackgroundColor: '#fff',
data: securityData
},
{
label: this.$t('policy_violation.operational'),
backgroundColor: 'transparent',
borderColor: operationalStyle,
pointHoverBackgroundColor: '#fff',
data: operationalData
},
{
label: this.$t('policy_violation.license'),
backgroundColor: 'transparent',
borderColor: licenseStyle,
pointHoverBackgroundColor: '#fff',
data: licenseData
}
]
}, {
tooltips: {
enabled: false,
custom: CustomTooltips,
intersect: true,
mode: 'index',
position: 'nearest',
callbacks: {
labelColor: function (tooltipItem, chart) {
return { backgroundColor: chart.data.datasets[tooltipItem.datasetIndex].borderColor }
}
}
},
maintainAspectRatio: false,
legend: {
display: false
},
scales: {
xAxes: [{
gridLines: {
drawOnChartArea: false
}
}],
yAxes: [{
ticks: {
beginAtZero: true,
maxTicksLimit: 1
},
gridLines: {
display: true
}
}]
},
elements: {
line: {
tension: 0.1,
borderWidth: 2
},
point: {
radius: 0,
hitRadius: 20,
hoverRadius: 4,
hoverBorderWidth: 3
}
}
})
}
}
}
</script>
8 changes: 4 additions & 4 deletions src/views/portfolio/projects/ComponentDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<b-col sm="7" class="d-none d-md-block">
</b-col>
</b-row>
<chart-policy-violations ref="chartPolicyViolations" chartId="chartPolicyViolations" class="chart-wrapper" style="height:200px;margin-top:40px;" :height="200"></chart-policy-violations>
<chart-policy-violations-state ref="chartPolicyViolationsState" chartId="chartPolicyViolationsState" class="chart-wrapper" style="height:200px;margin-top:40px;" :height="200"></chart-policy-violations-state>
</b-card>
</b-col>
<b-col sm="6">
Expand All @@ -105,15 +105,15 @@
import { Callout } from '@coreui/vue'
import ChartComponentVulnerabilities from "../../dashboard/ChartComponentVulnerabilities";
import ChartPortfolioVulnerabilities from '../../dashboard/ChartPortfolioVulnerabilities';
import ChartPolicyViolations from "@/views/dashboard/ChartPolicyViolations";
import ChartPolicyViolationsState from "@/views/dashboard/ChartPolicyViolationsState";
import ChartPolicyViolationBreakdown from '@/views/dashboard/ChartPolicyViolationBreakdown';
export default {
name: 'ComponentDashboard',
components: {
ChartComponentVulnerabilities,
ChartPortfolioVulnerabilities,
ChartPolicyViolations,
ChartPolicyViolationsState,
ChartPolicyViolationBreakdown,
Callout,
Expand Down Expand Up @@ -171,7 +171,7 @@
let url = `${this.$api.BASE_URL}/${this.$api.URL_METRICS}/component/${uuid}/days/${daysBack}`;
this.axios.get(url).then((response) => {
this.$refs.chartComponentVulnerabilities.render(response.data);
this.$refs.chartPolicyViolations.render(response.data);
this.$refs.chartPolicyViolationsState.render(response.data);
this.$refs.chartPolicyViolationBreakdown.render(response.data);
this.extractStats(response.data);
});
Expand Down
8 changes: 4 additions & 4 deletions src/views/portfolio/projects/ProjectDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<b-col sm="7" class="d-none d-md-block">
</b-col>
</b-row>
<chart-policy-violations ref="chartPolicyViolations" chartId="chartPolicyViolations" class="chart-wrapper" style="height:200px;margin-top:40px;" :height="200"></chart-policy-violations>
<chart-policy-violations-state ref="chartPolicyViolationsState" chartId="chartPolicyViolationsState" class="chart-wrapper" style="height:200px;margin-top:40px;" :height="200"></chart-policy-violations-state>
</b-card>
</b-col>
<b-col sm="6">
Expand Down Expand Up @@ -144,13 +144,13 @@
import ChartAuditingFindingsProgress from "../../dashboard/ChartAuditingFindingsProgress";
import ChartComponentVulnerabilities from "../../dashboard/ChartComponentVulnerabilities";
import ChartPortfolioVulnerabilities from '../../dashboard/ChartPortfolioVulnerabilities'
import ChartPolicyViolations from "@/views/dashboard/ChartPolicyViolations";
import ChartPolicyViolationsState from "@/views/dashboard/ChartPolicyViolationsState";
import ChartPolicyViolationBreakdown from '@/views/dashboard/ChartPolicyViolationBreakdown';
export default {
name: 'project-dashboard',
components: {
ChartPolicyViolations,
ChartPolicyViolationsState,
ChartPolicyViolationBreakdown,
ChartAuditingFindingsProgress,
ChartComponentVulnerabilities,
Expand Down Expand Up @@ -213,7 +213,7 @@
let url = `${this.$api.BASE_URL}/${this.$api.URL_METRICS}/project/${this.uuid}/days/${daysBack}`;
this.axios.get(url).then((response) => {
this.$refs.chartProjectVulnerabilities.render(response.data);
this.$refs.chartPolicyViolations.render(response.data);
this.$refs.chartPolicyViolationsState.render(response.data);
this.$refs.chartPolicyViolationBreakdown.render(response.data);
this.$refs.chartAuditingFindingsProgress.render(response.data);
this.$refs.chartComponentVulnerabilities.render(response.data);
Expand Down
8 changes: 4 additions & 4 deletions src/views/portfolio/projects/ServiceDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<b-col sm="7" class="d-none d-md-block">
</b-col>
</b-row>
<chart-policy-violations ref="chartPolicyViolations" chartId="chartPolicyViolations" class="chart-wrapper" style="height:200px;margin-top:40px;" :height="200"></chart-policy-violations>
<chart-policy-violations-state ref="chartPolicyViolationsState" chartId="chartPolicyViolationsState" class="chart-wrapper" style="height:200px;margin-top:40px;" :height="200"></chart-policy-violations-state>
</b-card>
</b-col>
<b-col sm="6">
Expand All @@ -105,15 +105,15 @@ import common from "../../../shared/common"
import { Callout } from '@coreui/vue'
import ChartComponentVulnerabilities from "../../dashboard/ChartComponentVulnerabilities";
import ChartPortfolioVulnerabilities from '../../dashboard/ChartPortfolioVulnerabilities';
import ChartPolicyViolations from "@/views/dashboard/ChartPolicyViolations";
import ChartPolicyViolationsState from "@/views/dashboard/ChartPolicyViolationsState";
import ChartPolicyViolationBreakdown from '@/views/dashboard/ChartPolicyViolationBreakdown';
export default {
name: 'ServiceDashboard',
components: {
ChartComponentVulnerabilities,
ChartPortfolioVulnerabilities,
ChartPolicyViolations,
ChartPolicyViolationsState,
ChartPolicyViolationBreakdown,
Callout,
Expand Down Expand Up @@ -174,7 +174,7 @@ export default {
let url = `${this.$api.BASE_URL}/${this.$api.URL_METRICS}/service/${uuid}/days/${daysBack}`;
this.axios.get(url).then((response) => {
this.$refs.chartServiceVulnerabilities.render(response.data);
this.$refs.chartPolicyViolations.render(response.data);
this.$refs.chartPolicyViolationsState.render(response.data);
this.$refs.chartPolicyViolationBreakdown.render(response.data);
this.extractStats(response.data);
});
Expand Down

0 comments on commit 90d49af

Please sign in to comment.