Add LOGPile BMC diagnostic log analyzer
Features: - Modular parser architecture for vendor-specific formats - Inspur/Kaytus parser supporting asset.json, devicefrusdr.log, component.log, idl.log, and syslog files - PCI Vendor/Device ID lookup for hardware identification - Web interface with tabs: Events, Sensors, Config, Serials, Firmware - Server specification summary with component grouping - Export to CSV, JSON, TXT formats - BMC alarm parsing from IDL logs (memory errors, PSU events, etc.) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
96
internal/server/server.go
Normal file
96
internal/server/server.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"git.mchus.pro/mchus/logpile/internal/models"
|
||||
)
|
||||
|
||||
// WebFS holds embedded web files (set by main package)
|
||||
var WebFS embed.FS
|
||||
|
||||
type Config struct {
|
||||
Port int
|
||||
PreloadFile string
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
config Config
|
||||
mux *http.ServeMux
|
||||
|
||||
mu sync.RWMutex
|
||||
result *models.AnalysisResult
|
||||
detectedVendor string
|
||||
}
|
||||
|
||||
func New(cfg Config) *Server {
|
||||
s := &Server{
|
||||
config: cfg,
|
||||
mux: http.NewServeMux(),
|
||||
}
|
||||
s.setupRoutes()
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Server) setupRoutes() {
|
||||
// Static files
|
||||
staticContent, err := fs.Sub(WebFS, "static")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s.mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(staticContent))))
|
||||
|
||||
// Pages
|
||||
s.mux.HandleFunc("/", s.handleIndex)
|
||||
|
||||
// API endpoints
|
||||
s.mux.HandleFunc("POST /api/upload", s.handleUpload)
|
||||
s.mux.HandleFunc("GET /api/status", s.handleGetStatus)
|
||||
s.mux.HandleFunc("GET /api/parsers", s.handleGetParsers)
|
||||
s.mux.HandleFunc("GET /api/events", s.handleGetEvents)
|
||||
s.mux.HandleFunc("GET /api/sensors", s.handleGetSensors)
|
||||
s.mux.HandleFunc("GET /api/config", s.handleGetConfig)
|
||||
s.mux.HandleFunc("GET /api/serials", s.handleGetSerials)
|
||||
s.mux.HandleFunc("GET /api/firmware", s.handleGetFirmware)
|
||||
s.mux.HandleFunc("GET /api/export/csv", s.handleExportCSV)
|
||||
s.mux.HandleFunc("GET /api/export/json", s.handleExportJSON)
|
||||
s.mux.HandleFunc("GET /api/export/txt", s.handleExportTXT)
|
||||
s.mux.HandleFunc("DELETE /api/clear", s.handleClear)
|
||||
}
|
||||
|
||||
func (s *Server) Run() error {
|
||||
addr := fmt.Sprintf(":%d", s.config.Port)
|
||||
return http.ListenAndServe(addr, s.mux)
|
||||
}
|
||||
|
||||
// SetResult sets the analysis result (thread-safe)
|
||||
func (s *Server) SetResult(result *models.AnalysisResult) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.result = result
|
||||
}
|
||||
|
||||
// GetResult returns the analysis result (thread-safe)
|
||||
func (s *Server) GetResult() *models.AnalysisResult {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.result
|
||||
}
|
||||
|
||||
// SetDetectedVendor sets the detected vendor name
|
||||
func (s *Server) SetDetectedVendor(vendor string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.detectedVendor = vendor
|
||||
}
|
||||
|
||||
// GetDetectedVendor returns the detected vendor name
|
||||
func (s *Server) GetDetectedVendor() string {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.detectedVendor
|
||||
}
|
||||
Reference in New Issue
Block a user