@@ -8,6 +8,7 @@ package softwareinventoryimpl
88import (
99 "embed"
1010 "io"
11+ "sort"
1112 "strings"
1213 "time"
1314
@@ -70,6 +71,8 @@ func formatYYYYMMDD(ts string) (string, error) {
7071// This method processes the cached inventory data and formats it for display
7172// in the status output. It handles date formatting, computes statistics by
7273// software type, and organizes the data by software ID for easy lookup.
74+ // Entries are sorted by Source (software type) and then by DisplayName for
75+ // easier navigation in the GUI and status output.
7376// Note: Stats are computed from deduplicated entries to ensure consistency
7477// between the total count and the breakdown by type.
7578func (is * softwareInventory ) populateStatus (status map [string ]interface {}) {
@@ -84,21 +87,34 @@ func (is *softwareInventory) populateStatus(status map[string]interface{}) {
8487 data [inventory .GetID ()] = inventory
8588 }
8689
90+ // Convert to slice and sort by Source (category), then DisplayName
91+ sortedEntries := make ([]software.Entry , 0 , len (data ))
92+ for _ , v := range data {
93+ sortedEntries = append (sortedEntries , v .(software.Entry ))
94+ }
95+ sort .Slice (sortedEntries , func (i , j int ) bool {
96+ // First sort by Source (software type)
97+ if sortedEntries [i ].Source != sortedEntries [j ].Source {
98+ return sortedEntries [i ].Source < sortedEntries [j ].Source
99+ }
100+ // Then sort by DisplayName within each category
101+ return sortedEntries [i ].DisplayName < sortedEntries [j ].DisplayName
102+ })
103+
87104 // Second pass: compute stats from deduplicated entries
88105 // This ensures stats sum matches the total count
89106 stats := map [string ]int {}
90107 brokenCount := 0
91- for _ , v := range data {
92- inventory := v .(software.Entry )
108+ for _ , inventory := range sortedEntries {
93109 stats [inventory .Source ]++
94110 if strings .Contains (inventory .Status , "broken" ) {
95111 brokenCount ++
96112 }
97113 }
98114
99- status ["software_inventory_metadata" ] = data
115+ status ["software_inventory_metadata" ] = sortedEntries
100116 status ["software_inventory_stats" ] = stats
101- status ["software_inventory_total" ] = len (data )
117+ status ["software_inventory_total" ] = len (sortedEntries )
102118 // Only include broken count if there are broken entries
103119 if brokenCount > 0 {
104120 status ["software_inventory_broken" ] = brokenCount
0 commit comments