Skip to content

Commit 0d29b9e

Browse files
authored
Merge pull request #1964 from afumagalli98/1962
Improved compliance stats
2 parents caa6535 + d0d4d28 commit 0d29b9e

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

api-service/dto/compliance_stats.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type ComplianceStats struct {
2121
MySql *Stats `json:"mySql,omitempty"`
2222
PostgreSql *Stats `json:"postgreSql,omitempty"`
2323
MongoDb *Stats `json:"mongoDb,omitempty"`
24+
MariaDB *Stats `json:"mariaDb,omitempty"`
2425
}
2526

2627
type Stats struct {

api-service/service/frontend_api.go

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,31 @@ func (as *APIService) GetComplianceStats() (*dto.ComplianceStats, error) {
7777
return nil, err
7878
}
7979

80-
hostsCount, err := as.Database.CountAllHost()
80+
mariadbStats, err := as.mariaDbStats()
8181
if err != nil {
8282
return nil, err
8383
}
8484

85+
hostsCount := oracleStats.HostCount +
86+
sqlServerStats.HostCount +
87+
mysqlStats.HostCount +
88+
postgresqlStats.HostCount +
89+
mongodbStats.HostCount +
90+
mariadbStats.HostCount
91+
92+
instancesCount := oracleStats.Count +
93+
sqlServerStats.Count +
94+
mysqlStats.Count +
95+
postgresqlStats.Count +
96+
mongodbStats.Count +
97+
mariadbStats.Count
98+
8599
avg := (oracleStats.CompliancePercentageVal + mysqlStats.CompliancePercentageVal + sqlServerStats.CompliancePercentageVal +
86-
postgresqlStats.CompliancePercentageVal + mongodbStats.CompliancePercentageVal) / 5
100+
postgresqlStats.CompliancePercentageVal + mongodbStats.CompliancePercentageVal + mariadbStats.CompliancePercentageVal) / 6
87101

88102
totStats := dto.Stats{
89-
Count: int(hostsCount),
90-
HostCount: int(hostsCount),
103+
Count: instancesCount,
104+
HostCount: hostsCount,
91105
CompliancePercentageVal: avg,
92106
CompliancePercentageStr: fmt.Sprintf("%.2f%%", avg),
93107
}
@@ -99,6 +113,7 @@ func (as *APIService) GetComplianceStats() (*dto.ComplianceStats, error) {
99113
SqlServer: sqlServerStats,
100114
PostgreSql: postgresqlStats,
101115
MongoDb: mongodbStats,
116+
MariaDB: mariadbStats,
102117
}
103118

104119
return &res, nil
@@ -132,6 +147,10 @@ func (as *APIService) oracleStats() (*dto.Stats, error) {
132147
compliancePercentage = (totCompliance * 100) / float64(len(compliances))
133148
}
134149

150+
if compliancePercentage == 0 {
151+
compliancePercentage = 100
152+
}
153+
135154
return &dto.Stats{
136155
Count: int(count),
137156
HostCount: int(hostCount),
@@ -168,6 +187,10 @@ func (as *APIService) mysqlStats() (*dto.Stats, error) {
168187
compliancePercentage = (totCompliance * 100) / float64(len(compliances))
169188
}
170189

190+
if compliancePercentage == 0 {
191+
compliancePercentage = 100
192+
}
193+
171194
return &dto.Stats{
172195
Count: int(count),
173196
HostCount: int(hostCount),
@@ -204,6 +227,10 @@ func (as *APIService) sqlServerStats() (*dto.Stats, error) {
204227
compliancePercentage = (totCompliance * 100) / float64(len(compliances))
205228
}
206229

230+
if compliancePercentage == 0 {
231+
compliancePercentage = 100
232+
}
233+
207234
return &dto.Stats{
208235
Count: int(count),
209236
HostCount: int(hostCount),
@@ -249,3 +276,12 @@ func (as *APIService) mongoDbStats() (*dto.Stats, error) {
249276
CompliancePercentageVal: 100,
250277
}, nil
251278
}
279+
280+
func (as *APIService) mariaDbStats() (*dto.Stats, error) {
281+
return &dto.Stats{
282+
Count: 0,
283+
HostCount: 0,
284+
CompliancePercentageStr: "100%",
285+
CompliancePercentageVal: 100,
286+
}, nil
287+
}

0 commit comments

Comments
 (0)