MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / collectSSHLogItems

Function collectSSHLogItems

agent/app/service/ssh.go:1276–1316  ·  view source on GitHub ↗
(lines []string, filter, status string)

Source from the content-addressed store, hash-verified

1274}
1275
1276func collectSSHLogItems(lines []string, filter, status string) []sshParsedLog {
1277 var items []sshParsedLog
1278 auxiliaryIndex := make(map[string]int)
1279 sessionHasAuthEvent := make(map[string]bool)
1280 for lineIndex, line := range lines {
1281 if !shouldParseSSHLogLine(line, status, filter) {
1282 continue
1283 }
1284 item, ok := parseSSHLogLine(line)
1285 if !ok || !checkIsStandard(item.History) {
1286 continue
1287 }
1288 item.Index = lineIndex
1289 item.Search = line
1290 if isSSHAuthEvent(item) && item.SessionKey != "" {
1291 sessionHasAuthEvent[item.SessionKey] = true
1292 items = append(items, item)
1293 continue
1294 }
1295 if index, ok := auxiliaryIndex[item.SessionKey]; ok {
1296 items[index].Search += "\n" + line
1297 continue
1298 }
1299 auxiliaryIndex[item.SessionKey] = len(items)
1300 items = append(items, item)
1301 }
1302 items = filterRedundantSSHSessionItems(items, sessionHasAuthEvent)
1303 if filter != "" {
1304 filteredItems := make([]sshParsedLog, 0, len(items))
1305 for _, item := range items {
1306 if strings.Contains(item.Search, filter) {
1307 filteredItems = append(filteredItems, item)
1308 }
1309 }
1310 items = filteredItems
1311 }
1312 sort.SliceStable(items, func(i, j int) bool {
1313 return items[i].Index < items[j].Index
1314 })
1315 return items
1316}
1317
1318func filterRedundantSSHSessionItems(items []sshParsedLog, sessionHasAuthEvent map[string]bool) []sshParsedLog {
1319 filteredItems := make([]sshParsedLog, 0, len(items))

Callers 1

loadSSHDataFunction · 0.85

Calls 5

shouldParseSSHLogLineFunction · 0.85
parseSSHLogLineFunction · 0.85
checkIsStandardFunction · 0.85
isSSHAuthEventFunction · 0.85

Tested by

no test coverage detected