@@ -62,6 +62,7 @@ func (s *Server) handleUpload(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
result := p.Result()
|
||||
applyArchiveSourceMetadata(result)
|
||||
s.SetResult(result)
|
||||
s.SetDetectedVendor(p.DetectedVendor())
|
||||
|
||||
@@ -114,18 +115,31 @@ func (s *Server) handleGetSensors(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (s *Server) handleGetConfig(w http.ResponseWriter, r *http.Request) {
|
||||
result := s.GetResult()
|
||||
if result == nil || result.Hardware == nil {
|
||||
if result == nil {
|
||||
jsonResponse(w, map[string]interface{}{})
|
||||
return
|
||||
}
|
||||
|
||||
response := map[string]interface{}{
|
||||
"source_type": result.SourceType,
|
||||
"protocol": result.Protocol,
|
||||
"target_host": result.TargetHost,
|
||||
"collected_at": result.CollectedAt,
|
||||
}
|
||||
|
||||
if result.Hardware == nil {
|
||||
response["hardware"] = map[string]interface{}{}
|
||||
response["specification"] = []SpecLine{}
|
||||
jsonResponse(w, response)
|
||||
return
|
||||
}
|
||||
|
||||
// Build specification summary
|
||||
spec := buildSpecification(result)
|
||||
|
||||
jsonResponse(w, map[string]interface{}{
|
||||
"hardware": result.Hardware,
|
||||
"specification": spec,
|
||||
})
|
||||
response["hardware"] = result.Hardware
|
||||
response["specification"] = spec
|
||||
jsonResponse(w, response)
|
||||
}
|
||||
|
||||
// SpecLine represents a single line in specification
|
||||
@@ -495,9 +509,13 @@ func (s *Server) handleGetStatus(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
jsonResponse(w, map[string]interface{}{
|
||||
"loaded": true,
|
||||
"filename": result.Filename,
|
||||
"vendor": s.GetDetectedVendor(),
|
||||
"loaded": true,
|
||||
"filename": result.Filename,
|
||||
"vendor": s.GetDetectedVendor(),
|
||||
"source_type": result.SourceType,
|
||||
"protocol": result.Protocol,
|
||||
"target_host": result.TargetHost,
|
||||
"collected_at": result.CollectedAt,
|
||||
"stats": map[string]int{
|
||||
"events": len(result.Events),
|
||||
"sensors": len(result.Sensors),
|
||||
@@ -574,6 +592,8 @@ func (s *Server) handleCollectStart(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
job := s.jobManager.CreateJob(req)
|
||||
s.SetResult(newAPIResult(req))
|
||||
s.SetDetectedVendor("")
|
||||
s.startMockCollectionJob(job.ID, req)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
@@ -726,6 +746,28 @@ func generateJobID() string {
|
||||
return fmt.Sprintf("job_%x", buf)
|
||||
}
|
||||
|
||||
func applyArchiveSourceMetadata(result *models.AnalysisResult) {
|
||||
if result == nil {
|
||||
return
|
||||
}
|
||||
result.SourceType = models.SourceTypeArchive
|
||||
result.Protocol = ""
|
||||
result.TargetHost = ""
|
||||
result.CollectedAt = time.Now().UTC()
|
||||
}
|
||||
|
||||
func newAPIResult(req CollectRequest) *models.AnalysisResult {
|
||||
return &models.AnalysisResult{
|
||||
SourceType: models.SourceTypeAPI,
|
||||
Protocol: req.Protocol,
|
||||
TargetHost: req.Host,
|
||||
CollectedAt: time.Now().UTC(),
|
||||
Events: make([]models.Event, 0),
|
||||
FRU: make([]models.FRUInfo, 0),
|
||||
Sensors: make([]models.SensorReading, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func jsonResponse(w http.ResponseWriter, data interface{}) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(data)
|
||||
|
||||
Reference in New Issue
Block a user