@@ -23,14 +23,15 @@ console.log();
2323
2424// 3. Parse log lines
2525const logPattern =
26- / ^ \[ .* ?\] \s + b u i l d c a g e \s + \[ ( A U D I T | A L L O W E D | B L O C K E D ) \] \s + " ( [ ^ " ] + ) " \s * ( \S * ) / ;
26+ / ^ \[ .* ?\] \s + b u i l d c a g e \s + \[ ( A U D I T | A L L O W E D | B L O C K E D ) \] \s + \( ( \w + ) \) \s + " ( [ ^ " ] + ) " \s * ( \S * ) / ;
2727
2828const entries = [ ] ;
2929for ( const line of logs . split ( "\n" ) ) {
3030 const m = line . match ( logPattern ) ;
3131 if ( m ) {
32- const hostPort = m [ 2 ] ;
33- const reason = m [ 3 ] || "-" ;
32+ const ruleType = m [ 2 ] ;
33+ const hostPort = m [ 3 ] ;
34+ const reason = m [ 4 ] || "-" ;
3435 const colonIdx = hostPort . lastIndexOf ( ":" ) ;
3536 let host , port ;
3637 if ( colonIdx > 0 ) {
@@ -42,6 +43,7 @@ for (const line of logs.split("\n")) {
4243 }
4344 entries . push ( {
4445 decision : m [ 1 ] ,
46+ ruleType,
4547 host,
4648 port,
4749 reason,
@@ -65,13 +67,13 @@ const isAudit = entries.some((e) => e.decision === "AUDIT");
6567function aggregate ( filtered ) {
6668 const map = new Map ( ) ;
6769 for ( const e of filtered ) {
68- const key = `${ e . host } \t${ e . port } \t${ e . reason } ` ;
70+ const key = `${ e . host } \t${ e . port } \t${ e . ruleType } \t ${ e . reason } ` ;
6971 map . set ( key , ( map . get ( key ) || 0 ) + 1 ) ;
7072 }
7173 return [ ...map . entries ( ) ]
7274 . map ( ( [ key , count ] ) => {
73- const [ host , portStr , reason ] = key . split ( "\t" ) ;
74- return { host, port : Number ( portStr ) , reason, count } ;
75+ const [ host , portStr , ruleType , reason ] = key . split ( "\t" ) ;
76+ return { host, port : Number ( portStr ) , ruleType , reason, count } ;
7577 } )
7678 . sort (
7779 ( a , b ) =>
@@ -83,15 +85,15 @@ function aggregate(filtered) {
8385
8486function markdownTable ( rows , { showReason = false } = { } ) {
8587 if ( showReason ) {
86- const lines = [ "| Host | Port | Reason | Count |" , "| --- | --- | --- | ---: |" ] ;
88+ const lines = [ "| Host | Port | Type | Reason | Count |" , "| --- | --- | --- | --- | ---: |" ] ;
8789 for ( const r of rows ) {
88- lines . push ( `| ${ r . host } | ${ r . port || "" } | ${ r . reason } | ${ r . count } |` ) ;
90+ lines . push ( `| ${ r . host } | ${ r . port || "" } | ${ r . ruleType } | ${ r . reason } | ${ r . count } |` ) ;
8991 }
9092 return lines . join ( "\n" ) ;
9193 }
92- const lines = [ "| Host | Port | Count |" , "| --- | --- | ---: |" ] ;
94+ const lines = [ "| Host | Port | Type | Count |" , "| --- | --- | --- | ---: |" ] ;
9395 for ( const r of rows ) {
94- lines . push ( `| ${ r . host } | ${ r . port || "" } | ${ r . count } |` ) ;
96+ lines . push ( `| ${ r . host } | ${ r . port || "" } | ${ r . ruleType } | ${ r . count } |` ) ;
9597 }
9698 return lines . join ( "\n" ) ;
9799}
0 commit comments