@@ -4,8 +4,9 @@ import { Command, Flags } from '@oclif/core';
4
4
import ora from 'ora' ;
5
5
import { submitScan } from '../../api/nes.client.ts' ;
6
6
import { config , filenamePrefix } from '../../config/constants.ts' ;
7
+ import { track } from '../../service/analytics.svc.ts' ;
7
8
import { createSbom } from '../../service/cdx.svc.ts' ;
8
- import { formatScanResults , formatWebReportUrl } from '../../service/display.svc.ts' ;
9
+ import { countComponentsByStatus , formatScanResults , formatWebReportUrl } from '../../service/display.svc.ts' ;
9
10
import { readSbomFromFile , saveReportToFile , saveSbomToFile , validateDirectory } from '../../service/file.svc.ts' ;
10
11
import { getErrorMessage } from '../../service/log.svc.ts' ;
11
12
@@ -56,23 +57,81 @@ export default class ScanEol extends Command {
56
57
public async run ( ) : Promise < EolReport | undefined > {
57
58
const { flags } = await this . parse ( ScanEol ) ;
58
59
60
+ if ( ! flags . file ) {
61
+ track ( 'CLI SBOM Generation Started' , ( context ) => ( {
62
+ command : context . command ,
63
+ command_flags : context . command_flags ,
64
+ scan_location : flags . dir ,
65
+ } ) ) ;
66
+ }
67
+
68
+ const sbomStartTime = performance . now ( ) ;
59
69
const sbom = await this . loadSbom ( ) ;
70
+ const sbomEndTime = performance . now ( ) ;
71
+
72
+ if ( ! flags . file ) {
73
+ track ( 'CLI SBOM Generation Completed' , ( context ) => ( {
74
+ command : context . command ,
75
+ command_flags : context . command_flags ,
76
+ scan_location : flags . dir ,
77
+ sbom_created : true ,
78
+ sbom_load_time : ( sbomEndTime - sbomStartTime ) / 1000 ,
79
+ } ) ) ;
80
+ }
60
81
61
82
if ( ! sbom . components ?. length ) {
83
+ track ( 'CLI No Components Found, Report Not Generated' , ( context ) => ( {
84
+ command : context . command ,
85
+ command_flags : context . command_flags ,
86
+ scan_location : flags . dir ,
87
+ } ) ) ;
62
88
this . log ( 'No components found in scan. Report not generated.' ) ;
63
89
return ;
64
90
}
65
91
92
+ track ( 'CLI EOL Scan Started' , ( context ) => ( {
93
+ command : context . command ,
94
+ command_flags : context . command_flags ,
95
+ scan_location : flags . dir ,
96
+ } ) ) ;
97
+
98
+ const scanStartTime = performance . now ( ) ;
66
99
const scan = await this . scanSbom ( sbom ) ;
100
+ const scanEndTime = performance . now ( ) ;
101
+
102
+ const componentCounts = countComponentsByStatus ( scan ) ;
103
+ track ( 'CLI EOL Scan Completed' , ( context ) => ( {
104
+ command : context . command ,
105
+ command_flags : context . command_flags ,
106
+ eol_true_count : componentCounts . EOL ,
107
+ eol_unknown_count : componentCounts . UNKNOWN ,
108
+ nes_available_count : componentCounts . NES_AVAILABLE ,
109
+ number_of_packages : componentCounts . TOTAL ,
110
+ sbom_created : ! flags . file ,
111
+ scan_location : flags . dir ,
112
+ scan_load_time : ( scanEndTime - scanStartTime ) / 1000 ,
113
+ scanned_ecosystems : componentCounts . ECOSYSTEMS ,
114
+ web_report_link : scan . id ? `${ config . eolReportUrl } /${ scan . id } ` : undefined ,
115
+ } ) ) ;
67
116
68
117
if ( flags . save ) {
69
118
const reportPath = this . saveReport ( scan , flags . dir ) ;
70
119
this . log ( `Report saved to ${ reportPath } ` ) ;
120
+ track ( 'CLI JSON Scan Output Saved' , ( context ) => ( {
121
+ command : context . command ,
122
+ command_flags : context . command_flags ,
123
+ report_output_path : reportPath ,
124
+ } ) ) ;
71
125
}
72
126
73
127
if ( flags . saveSbom && ! flags . file ) {
74
128
const sbomPath = this . saveSbom ( flags . dir , sbom ) ;
75
129
this . log ( `SBOM saved to ${ sbomPath } ` ) ;
130
+ track ( 'CLI SBOM Output Saved' , ( context ) => ( {
131
+ command : context . command ,
132
+ command_flags : context . command_flags ,
133
+ sbom_output_path : sbomPath ,
134
+ } ) ) ;
76
135
}
77
136
78
137
if ( ! this . jsonEnabled ( ) ) {
@@ -107,23 +166,34 @@ export default class ScanEol extends Command {
107
166
return scan ;
108
167
} catch ( error ) {
109
168
spinner . fail ( 'Scanning failed' ) ;
110
- this . error ( `Failed to submit scan to NES. ${ getErrorMessage ( error ) } ` ) ;
169
+ const errorMessage = getErrorMessage ( error ) ;
170
+ track ( 'CLI EOL Scan Failed' , ( context ) => ( {
171
+ command : context . command ,
172
+ command_flags : context . command_flags ,
173
+ scan_location : context . scan_location ,
174
+ scan_failure_reason : errorMessage ,
175
+ } ) ) ;
176
+ this . error ( `Failed to submit scan to NES. ${ errorMessage } ` ) ;
111
177
}
112
178
}
113
179
114
180
private saveReport ( report : EolReport , dir : string ) : string {
115
181
try {
116
182
return saveReportToFile ( dir , report ) ;
117
183
} catch ( error ) {
118
- this . error ( getErrorMessage ( error ) ) ;
184
+ const errorMessage = getErrorMessage ( error ) ;
185
+ track ( 'CLI Error Encountered' , ( ) => ( { error : errorMessage } ) ) ;
186
+ this . error ( errorMessage ) ;
119
187
}
120
188
}
121
189
122
190
private saveSbom ( dir : string , sbom : CdxBom ) : string {
123
191
try {
124
192
return saveSbomToFile ( dir , sbom ) ;
125
193
} catch ( error ) {
126
- this . error ( getErrorMessage ( error ) ) ;
194
+ const errorMessage = getErrorMessage ( error ) ;
195
+ track ( 'CLI Error Encountered' , ( ) => ( { error : errorMessage } ) ) ;
196
+ this . error ( errorMessage ) ;
127
197
}
128
198
}
129
199
@@ -154,15 +224,19 @@ export default class ScanEol extends Command {
154
224
}
155
225
return sbom ;
156
226
} catch ( error ) {
157
- this . error ( `Failed to scan directory: ${ getErrorMessage ( error ) } ` ) ;
227
+ const errorMessage = getErrorMessage ( error ) ;
228
+ track ( 'CLI Error Encountered' , ( ) => ( { error : errorMessage } ) ) ;
229
+ this . error ( `Failed to scan directory: ${ errorMessage } ` ) ;
158
230
}
159
231
}
160
232
161
233
private getSbomFromFile ( filePath : string ) : CdxBom {
162
234
try {
163
235
return readSbomFromFile ( filePath ) ;
164
236
} catch ( error ) {
165
- this . error ( getErrorMessage ( error ) ) ;
237
+ const errorMessage = getErrorMessage ( error ) ;
238
+ track ( 'CLI Error Encountered' , ( ) => ( { error : errorMessage } ) ) ;
239
+ this . error ( errorMessage ) ;
166
240
}
167
241
}
168
242
}
0 commit comments