Nuke all storage computation
Doesn't fucking work
This commit is contained in:
24
esi/types.go
24
esi/types.go
@@ -15,13 +15,16 @@ type Link struct {
|
||||
}
|
||||
|
||||
type Pin struct {
|
||||
Contents []Content `json:"contents"`
|
||||
LastCycleStart *time.Time `json:"last_cycle_start,omitempty"`
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
PinID int64 `json:"pin_id"`
|
||||
TypeID int64 `json:"type_id"`
|
||||
SchematicID *int64 `json:"schematic_id,omitempty"`
|
||||
Contents []Content `json:"contents"`
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
PinID int64 `json:"pin_id"`
|
||||
TypeID int64 `json:"type_id"`
|
||||
LastCycleStart *time.Time `json:"last_cycle_start,omitempty"`
|
||||
SchematicID *int64 `json:"schematic_id,omitempty"`
|
||||
ExpiryTime *time.Time `json:"expiry_time,omitempty"`
|
||||
ExtractorDetails *ExtractorDetails `json:"extractor_details,omitempty"`
|
||||
InstallTime *time.Time `json:"install_time,omitempty"`
|
||||
}
|
||||
|
||||
type Content struct {
|
||||
@@ -49,3 +52,10 @@ type Planet struct {
|
||||
SolarSystemID int64 `json:"solar_system_id"`
|
||||
UpgradeLevel int64 `json:"upgrade_level"`
|
||||
}
|
||||
|
||||
type ExtractorDetails struct {
|
||||
CycleTime int64 `json:"cycle_time"`
|
||||
HeadRadius float64 `json:"head_radius"`
|
||||
ProductTypeID int64 `json:"product_type_id"`
|
||||
QtyPerCycle int64 `json:"qty_per_cycle"`
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -112,51 +113,63 @@ func (o *Orchestrator) refetchAllData() {
|
||||
// processCharacter processes a single character's data
|
||||
func (o *Orchestrator) processCharacter(char types.Character) {
|
||||
logger.Info("Orchestrator.processCharacter: Starting processing for character: %s (ID: %d)", char.CharacterName, char.ID)
|
||||
|
||||
// Get extractors for this character
|
||||
// logger.Info("Orchestrator.processCharacter: Getting extractors for character %s", char.CharacterName)
|
||||
// extractors, err := routes.GetExtractorsForCharacter(o.esiClient, int(char.ID), char.AccessToken)
|
||||
// if err != nil {
|
||||
// logger.Warning("Orchestrator.processCharacter: Failed to get extractors for character %s: %v", char.CharacterName, err)
|
||||
// return
|
||||
// }
|
||||
// logger.Info("Orchestrator.processCharacter: Got %d extractors for character %s", len(extractors), char.CharacterName)
|
||||
|
||||
// Get storage for this character
|
||||
logger.Info("Orchestrator.processCharacter: Getting storage for character %s", char.CharacterName)
|
||||
storage, err := routes.GetStorageForCharacter(o.esiClient, int(char.ID), char.AccessToken)
|
||||
|
||||
planets, err := o.esiClient.GetCharacterPlanets(context.Background(), int(char.ID), char.AccessToken)
|
||||
if err != nil {
|
||||
logger.Warning("Orchestrator.processCharacter: Failed to get storage for character %s: %v", char.CharacterName, err)
|
||||
logger.Warning("Orchestrator.processCharacter: Failed to get planets for character %s: %v", char.CharacterName, err)
|
||||
return
|
||||
}
|
||||
logger.Info("Orchestrator.processCharacter: Got %d storage facilities for character %s", len(storage), char.CharacterName)
|
||||
logger.Info("Orchestrator.processCharacter: Got %d planets for character %s", len(planets), char.CharacterName)
|
||||
|
||||
planetIds := make([]int64, len(planets))
|
||||
for i, planet := range planets {
|
||||
planetIds[i] = planet.PlanetID
|
||||
}
|
||||
|
||||
// Get extractors for this character
|
||||
logger.Info("Orchestrator.processCharacter: Getting extractors for character %s", char.CharacterName)
|
||||
extractors, err := routes.GetExtractorsForCharacter(o.esiClient, int(char.ID), char.AccessToken, planetIds)
|
||||
if err != nil {
|
||||
logger.Warning("Orchestrator.processCharacter: Failed to get extractors for character %s: %v", char.CharacterName, err)
|
||||
return
|
||||
}
|
||||
logger.Info("Orchestrator.processCharacter: Got %d extractors for character %s", len(extractors), char.CharacterName)
|
||||
|
||||
// Get storage for this character
|
||||
// logger.Info("Orchestrator.processCharacter: Getting storage for character %s", char.CharacterName)
|
||||
// storage, err := routes.GetStorageForCharacter(o.esiClient, int(char.ID), char.AccessToken)
|
||||
// if err != nil {
|
||||
// logger.Warning("Orchestrator.processCharacter: Failed to get storage for character %s: %v", char.CharacterName, err)
|
||||
// return
|
||||
// }
|
||||
// logger.Info("Orchestrator.processCharacter: Got %d storage facilities for character %s", len(storage), char.CharacterName)
|
||||
|
||||
// Check storage thresholds
|
||||
logger.Info("Orchestrator.processCharacter: Checking storage thresholds for character %s", char.CharacterName)
|
||||
o.checkStorageThresholds(char.CharacterName, storage)
|
||||
// logger.Info("Orchestrator.processCharacter: Checking storage thresholds for character %s", char.CharacterName)
|
||||
// o.checkStorageThresholds(char.CharacterName, storage)
|
||||
|
||||
// Update expiry timers for extractors
|
||||
// logger.Info("Orchestrator.processCharacter: Updating expiry timers for character %s", char.CharacterName)
|
||||
// o.updateExpiryTimers(char.CharacterName, extractors)
|
||||
logger.Info("Orchestrator.processCharacter: Updating expiry timers for character %s", char.CharacterName)
|
||||
o.updateExpiryTimers(char.CharacterName, extractors)
|
||||
|
||||
logger.Info("Orchestrator.processCharacter: Completed processing for character %s", char.CharacterName)
|
||||
}
|
||||
|
||||
// checkStorageThresholds checks storage utilization against configured thresholds
|
||||
func (o *Orchestrator) checkStorageThresholds(characterName string, storage []routes.StorageInfo) {
|
||||
warningThreshold := options.GlobalOptions.StorageWarning
|
||||
criticalThreshold := options.GlobalOptions.StorageCritical
|
||||
// func (o *Orchestrator) checkStorageThresholds(characterName string, storage []routes.StorageInfo) {
|
||||
// warningThreshold := options.GlobalOptions.StorageWarning
|
||||
// criticalThreshold := options.GlobalOptions.StorageCritical
|
||||
|
||||
for _, s := range storage {
|
||||
if s.Utilization >= criticalThreshold {
|
||||
message := routes.FormatStorageAlert(s, true)
|
||||
o.sendWebhook(characterName, message)
|
||||
} else if s.Utilization >= warningThreshold {
|
||||
message := routes.FormatStorageAlert(s, false)
|
||||
o.sendWebhook(characterName, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
// for _, s := range storage {
|
||||
// if s.Utilization >= criticalThreshold {
|
||||
// message := routes.FormatStorageAlert(s, true)
|
||||
// o.sendWebhook(characterName, message)
|
||||
// } else if s.Utilization >= warningThreshold {
|
||||
// message := routes.FormatStorageAlert(s, false)
|
||||
// o.sendWebhook(characterName, message)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// updateExpiryTimers updates the in-memory expiry timers for extractors
|
||||
func (o *Orchestrator) updateExpiryTimers(characterName string, extractors []routes.ExtractorInfo) {
|
||||
|
||||
278
routes/data.go
278
routes/data.go
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go-eve-pi/constants"
|
||||
"go-eve-pi/esi"
|
||||
|
||||
logger "git.site.quack-lab.dev/dave/cylogger"
|
||||
@@ -28,169 +27,176 @@ type StorageInfo struct {
|
||||
|
||||
// GetExtractorsForCharacter retrieves extractor information for a character
|
||||
func GetExtractorsForCharacter(esiClient esi.ESIInterface, characterID int, accessToken string, planetIDs []int64) ([]ExtractorInfo, error) {
|
||||
logger.Info("GetExtractorsForCharacter: Starting for character ID %d", characterID)
|
||||
funclog := logger.Default.WithPrefix("GetExtractorsForCharacter").WithPrefix(fmt.Sprintf("characterID=%d", characterID))
|
||||
funclog.Info("Starting")
|
||||
|
||||
logger.Info("GetExtractorsForCharacter: Found %d planets for character %d", len(planetIDs), characterID)
|
||||
funclog.Info("Found %d planets", len(planetIDs))
|
||||
|
||||
var extractors []ExtractorInfo
|
||||
|
||||
for i, planetID := range planetIDs {
|
||||
logger.Info("GetExtractorsForCharacter: Processing planet %d/%d (ID: %d)", i+1, len(planetIDs), planetID)
|
||||
planetlog := funclog.WithPrefix(fmt.Sprintf("planetID=%d", planetID))
|
||||
planetlog.Info("Processing planet %d/%d", i+1, len(planetIDs))
|
||||
|
||||
// Get planet details
|
||||
details, err := esiClient.GetPlanetPI(context.Background(), characterID, planetID, accessToken)
|
||||
if err != nil {
|
||||
logger.Warning("GetExtractorsForCharacter: Failed to fetch details for planet %d: %v", planetID, err)
|
||||
planetlog.Warning("Failed to fetch details: %v", err)
|
||||
continue
|
||||
}
|
||||
logger.Info("GetExtractorsForCharacter: Got planet details for planet %d with %d pins", planetID, len(details.Pins))
|
||||
if details == nil {
|
||||
planetlog.Warning("Planet details are nil")
|
||||
continue
|
||||
}
|
||||
if details.Pins == nil {
|
||||
planetlog.Warning("Planet details have no pins")
|
||||
continue
|
||||
}
|
||||
planetlog.Info("Got planet details with %d pins", len(details.Pins))
|
||||
|
||||
if details != nil {
|
||||
// Get planet name from universe endpoint
|
||||
planetNameData, err := esiClient.GetPlanetName(context.Background(), planetID)
|
||||
if err != nil {
|
||||
logger.Error("GetExtractorsForCharacter: Failed to get planet name for planet ID %d: %v", planetID, err)
|
||||
// Get planet name from universe endpoint
|
||||
planetNameData, err := esiClient.GetPlanetName(context.Background(), planetID)
|
||||
if err != nil {
|
||||
planetlog.Error("Failed to get planet name: %v", err)
|
||||
continue
|
||||
}
|
||||
planetlog.Info("Planet name: %s", planetNameData.Name)
|
||||
|
||||
// Count extractors and get expiry dates
|
||||
extractorCount := 0
|
||||
for j, pin := range details.Pins {
|
||||
pinlog := planetlog.WithPrefix(fmt.Sprintf("pinID=%d", pin.PinID)).WithPrefix(fmt.Sprintf("pinTypeID=%d", pin.TypeID))
|
||||
pinlog.Info("Processing pin %d/%d", j+1, len(details.Pins))
|
||||
if pin.ExpiryTime == nil {
|
||||
pinlog.Info("Pin %d has no expiry time", j+1)
|
||||
continue
|
||||
}
|
||||
logger.Info("GetExtractorsForCharacter: Planet %d name: %s", planetID, planetNameData.Name)
|
||||
|
||||
// Count extractors and get expiry dates
|
||||
extractorCount := 0
|
||||
// for j, pin := range details.Pins {
|
||||
// logger.Info("GetExtractorsForCharacter: Processing pin %d/%d (TypeID: %d) on planet %s", j+1, len(details.Pins), pin.TypeID, planetNameData.Name)
|
||||
|
||||
// if pin.ExtractorDetails != nil {
|
||||
// logger.Info("GetExtractorsForCharacter: Found extractor (TypeID: %d) on planet %s", pin.TypeID, planetNameData.Name)
|
||||
// extractorCount++
|
||||
// expiryDate := "N/A"
|
||||
// if pin.ExpiryTime != nil {
|
||||
// expiryDate = *pin.ExpiryTime
|
||||
// logger.Info("GetExtractorsForCharacter: Extractor expiry: %s", expiryDate)
|
||||
// } else {
|
||||
// logger.Info("GetExtractorsForCharacter: Extractor has no expiry time")
|
||||
// }
|
||||
|
||||
// extractors = append(extractors, ExtractorInfo{
|
||||
// PlanetName: planetNameData.Name,
|
||||
// ExtractorNumber: extractorCount,
|
||||
// ExpiryDate: expiryDate,
|
||||
// })
|
||||
// logger.Info("GetExtractorsForCharacter: Added extractor %d to results", extractorCount)
|
||||
// } else {
|
||||
// logger.Info("GetExtractorsForCharacter: Pin %d is not an extractor (TypeID: %d)", j+1, pin.TypeID)
|
||||
// }
|
||||
// }
|
||||
logger.Info("GetExtractorsForCharacter: Found %d extractors on planet %s", extractorCount, planetNameData.Name)
|
||||
pinlog.Info("Pin has expiry time: %s", pin.ExpiryTime.Format(time.RFC3339))
|
||||
expiryDate := pin.ExpiryTime.Format(time.RFC3339)
|
||||
pinlog.Info("Expiry date: %s", expiryDate)
|
||||
extractors = append(extractors, ExtractorInfo{
|
||||
PlanetName: planetNameData.Name,
|
||||
ExtractorNumber: extractorCount,
|
||||
ExpiryDate: expiryDate,
|
||||
})
|
||||
extractorCount++
|
||||
pinlog.Info("Added extractor %d to results", extractorCount)
|
||||
}
|
||||
planetlog.Info("Found %d extractors", extractorCount)
|
||||
}
|
||||
|
||||
logger.Info("GetExtractorsForCharacter: Returning %d total extractors for character %d", len(extractors), characterID)
|
||||
funclog.Info("Returning %d total extractors", len(extractors))
|
||||
return extractors, nil
|
||||
}
|
||||
|
||||
// GetStorageForCharacter retrieves storage information for a character
|
||||
func GetStorageForCharacter(esiClient esi.ESIInterface, characterID int, accessToken string) ([]StorageInfo, error) {
|
||||
logger.Info("GetStorageForCharacter: Starting for character ID %d", characterID)
|
||||
// func GetStorageForCharacter(esiClient esi.ESIInterface, characterID int, accessToken string) ([]StorageInfo, error) {
|
||||
// funclog := logger.Default.WithPrefix("GetStorageForCharacter").WithPrefix(fmt.Sprintf("characterID=%d", characterID))
|
||||
// funclog.Info("Starting")
|
||||
|
||||
// Get character planets
|
||||
planets, err := esiClient.GetCharacterPlanets(context.Background(), characterID, accessToken)
|
||||
if err != nil {
|
||||
logger.Error("GetStorageForCharacter: Failed to get planets for character %d: %v", characterID, err)
|
||||
return nil, err
|
||||
}
|
||||
logger.Info("GetStorageForCharacter: Found %d planets for character %d", len(planets), characterID)
|
||||
// // Get character planets
|
||||
// planets, err := esiClient.GetCharacterPlanets(context.Background(), characterID, accessToken)
|
||||
// if err != nil {
|
||||
// funclog.Error("Failed to get planets: %v", err)
|
||||
// return nil, err
|
||||
// }
|
||||
// funclog.Info("Found %d planets", len(planets))
|
||||
|
||||
var storage []StorageInfo
|
||||
// var storage []StorageInfo
|
||||
|
||||
for i, planet := range planets {
|
||||
logger.Info("GetStorageForCharacter: Processing planet %d/%d (ID: %d)", i+1, len(planets), planet.PlanetID)
|
||||
// for i, planet := range planets {
|
||||
// planetlog := funclog.WithPrefix(fmt.Sprintf("planetID=%d", planet.PlanetID))
|
||||
// planetlog.Info("Processing planet %d/%d", i+1, len(planets))
|
||||
|
||||
// Get planet details
|
||||
details, err := esiClient.GetPlanetPI(context.Background(), characterID, planet.PlanetID, accessToken)
|
||||
if err != nil {
|
||||
logger.Warning("GetStorageForCharacter: Failed to fetch details for planet %d: %v", planet.PlanetID, err)
|
||||
continue
|
||||
}
|
||||
logger.Info("GetStorageForCharacter: Got planet details for planet %d with %d pins", planet.PlanetID, len(details.Pins))
|
||||
// // Get planet details
|
||||
// details, err := esiClient.GetPlanetPI(context.Background(), characterID, planet.PlanetID, accessToken)
|
||||
// if err != nil {
|
||||
// planetlog.Warning("Failed to fetch details: %v", err)
|
||||
// continue
|
||||
// }
|
||||
// planetlog.Info("Got planet details with %d pins", len(details.Pins))
|
||||
// if details == nil {
|
||||
// planetlog.Warning("Planet details are nil")
|
||||
// continue
|
||||
// }
|
||||
|
||||
if details != nil {
|
||||
// Get planet name from universe endpoint
|
||||
planetNameData, err := esiClient.GetPlanetName(context.Background(), planet.PlanetID)
|
||||
if err != nil {
|
||||
logger.Error("GetStorageForCharacter: Failed to get planet name for planet ID %d: %v", planet.PlanetID, err)
|
||||
continue
|
||||
}
|
||||
logger.Info("GetStorageForCharacter: Planet %d name: %s", planet.PlanetID, planetNameData.Name)
|
||||
// // Get planet name from universe endpoint
|
||||
// planetNameData, err := esiClient.GetPlanetName(context.Background(), planet.PlanetID)
|
||||
// if err != nil {
|
||||
// planetlog.Error("Failed to get planet name: %v", err)
|
||||
// continue
|
||||
// }
|
||||
// planetlog = planetlog.WithPrefix(fmt.Sprintf("planetName=%s", planetNameData.Name))
|
||||
// planetlog.Info("Planet name: %s", planetNameData.Name)
|
||||
|
||||
// Analyze storage utilization
|
||||
storageCount := 0
|
||||
for j, pin := range details.Pins {
|
||||
logger.Info("GetStorageForCharacter: Processing pin %d/%d (TypeID: %d) on planet %s", j+1, len(details.Pins), pin.TypeID, planetNameData.Name)
|
||||
// // Analyze storage utilization
|
||||
// storageCount := 0
|
||||
// for j, pin := range details.Pins {
|
||||
// planetlog.Info("Processing pin %d/%d (TypeID: %d) on planet %s", j+1, len(details.Pins), pin.TypeID, planetNameData.Name)
|
||||
|
||||
// Check if this pin is actually a storage facility
|
||||
_, isStorage := constants.StorageCapacities[pin.TypeID]
|
||||
if !isStorage {
|
||||
logger.Info("GetStorageForCharacter: Pin %d is not a storage facility (TypeID: %d), skipping", j+1, pin.TypeID)
|
||||
continue
|
||||
}
|
||||
logger.Info("GetStorageForCharacter: Pin %d is a storage facility (TypeID: %d)", j+1, pin.TypeID)
|
||||
// // Check if this pin is actually a storage facility
|
||||
// _, isStorage := constants.StorageCapacities[pin.TypeID]
|
||||
// if !isStorage {
|
||||
// planetlog.Info("Pin %d is not a storage facility (TypeID: %d), skipping", j+1, pin.TypeID)
|
||||
// continue
|
||||
// }
|
||||
// planetlog.Info("Pin %d is a storage facility (TypeID: %d)", j+1, pin.TypeID)
|
||||
|
||||
storageType, exists := constants.PITypesMap[pin.TypeID]
|
||||
if !exists {
|
||||
logger.Error("GetStorageForCharacter: Unknown storage type ID %d for planet %s - this should not happen", pin.TypeID, planetNameData.Name)
|
||||
return nil, fmt.Errorf("unknown storage type ID %d", pin.TypeID)
|
||||
}
|
||||
logger.Info("GetStorageForCharacter: Storage type: %s", storageType)
|
||||
// storageType, exists := constants.PITypesMap[pin.TypeID]
|
||||
// if !exists {
|
||||
// planetlog.Error("Unknown storage type ID %d for planet %s - this should not happen", pin.TypeID, planetNameData.Name)
|
||||
// return nil, fmt.Errorf("unknown storage type ID %d", pin.TypeID)
|
||||
// }
|
||||
// planetlog.Info("Storage type: %s", storageType)
|
||||
|
||||
totalVolume := 0.0
|
||||
logger.Info("GetStorageForCharacter: Processing %d contents for storage facility %s", len(pin.Contents), storageType)
|
||||
for k, content := range pin.Contents {
|
||||
logger.Info("GetStorageForCharacter: Processing content %d/%d (TypeID: %d, Amount: %d)", k+1, len(pin.Contents), content.TypeID, content.Amount)
|
||||
// totalVolume := 0.0
|
||||
// planetlog.Info("Processing %d contents for storage facility %s", len(pin.Contents), storageType)
|
||||
// for k, content := range pin.Contents {
|
||||
// planetlog.Info("Processing content %d/%d (TypeID: %d, Amount: %d)", k+1, len(pin.Contents), content.TypeID, content.Amount)
|
||||
|
||||
volume, exists := constants.PIProductVolumes[content.TypeID]
|
||||
if !exists {
|
||||
logger.Error("GetStorageForCharacter: Missing product volume data for type ID %d - cannot calculate storage utilization", content.TypeID)
|
||||
return nil, fmt.Errorf("missing product volume data for type ID %d", content.TypeID)
|
||||
}
|
||||
itemVolume := float64(content.Amount) * volume
|
||||
totalVolume += itemVolume
|
||||
logger.Info("GetStorageForCharacter: Content TypeID %d: Amount %d, Volume %f, ItemVolume %f", content.TypeID, content.Amount, volume, itemVolume)
|
||||
}
|
||||
// volume, exists := constants.PIProductVolumes[content.TypeID]
|
||||
// if !exists {
|
||||
// planetlog.Error("Missing product volume data for type ID %d - cannot calculate storage utilization", content.TypeID)
|
||||
// return nil, fmt.Errorf("missing product volume data for type ID %d", content.TypeID)
|
||||
// }
|
||||
// itemVolume := float64(content.Amount) * volume
|
||||
// totalVolume += itemVolume
|
||||
// planetlog.Info("Content TypeID %d: Amount %d, Volume %f, ItemVolume %f", content.TypeID, content.Amount, volume, itemVolume)
|
||||
// }
|
||||
|
||||
storageCapacity := constants.StorageCapacities[pin.TypeID]
|
||||
utilization := (totalVolume / float64(storageCapacity)) * 100.0
|
||||
logger.Info("GetStorageForCharacter: Storage calculation: %s on %s - TotalVolume: %f, Capacity: %d, Utilization: %f%%", storageType, planetNameData.Name, totalVolume, storageCapacity, utilization)
|
||||
// storageCapacity := constants.StorageCapacities[pin.TypeID]
|
||||
// utilization := (totalVolume / float64(storageCapacity)) * 100.0
|
||||
// planetlog.Info("Storage calculation: %s on %s - TotalVolume: %f, Capacity: %d, Utilization: %f%%", storageType, planetNameData.Name, totalVolume, storageCapacity, utilization)
|
||||
|
||||
storage = append(storage, StorageInfo{
|
||||
PlanetName: planetNameData.Name,
|
||||
StorageType: storageType,
|
||||
Utilization: utilization,
|
||||
})
|
||||
storageCount++
|
||||
logger.Info("GetStorageForCharacter: Added storage facility %d to results", storageCount)
|
||||
}
|
||||
logger.Info("GetStorageForCharacter: Found %d storage facilities on planet %s", storageCount, planetNameData.Name)
|
||||
}
|
||||
}
|
||||
// storage = append(storage, StorageInfo{
|
||||
// PlanetName: planetNameData.Name,
|
||||
// StorageType: storageType,
|
||||
// Utilization: utilization,
|
||||
// })
|
||||
// storageCount++
|
||||
// planetlog.Info("Added storage facility %d to results", storageCount)
|
||||
// }
|
||||
// planetlog.Info("Found %d storage facilities on planet %s", storageCount, planetNameData.Name)
|
||||
// }
|
||||
|
||||
logger.Info("GetStorageForCharacter: Returning %d total storage facilities for character %d", len(storage), characterID)
|
||||
return storage, nil
|
||||
}
|
||||
// funclog.Info("Returning %d total storage facilities", len(storage))
|
||||
// return storage, nil
|
||||
// }
|
||||
|
||||
// CheckStorageThresholds checks storage utilization against thresholds
|
||||
func CheckStorageThresholds(storage []StorageInfo, warningThreshold, criticalThreshold float64) []StorageInfo {
|
||||
var alerts []StorageInfo
|
||||
// func CheckStorageThresholds(storage []StorageInfo, warningThreshold, criticalThreshold float64) []StorageInfo {
|
||||
// var alerts []StorageInfo
|
||||
|
||||
for _, s := range storage {
|
||||
if s.Utilization >= criticalThreshold {
|
||||
alerts = append(alerts, s)
|
||||
} else if s.Utilization >= warningThreshold {
|
||||
alerts = append(alerts, s)
|
||||
}
|
||||
}
|
||||
// for _, s := range storage {
|
||||
// if s.Utilization >= criticalThreshold {
|
||||
// alerts = append(alerts, s)
|
||||
// } else if s.Utilization >= warningThreshold {
|
||||
// alerts = append(alerts, s)
|
||||
// }
|
||||
// }
|
||||
|
||||
return alerts
|
||||
}
|
||||
// return alerts
|
||||
// }
|
||||
|
||||
// CheckExtractorExpiry checks extractor expiry against thresholds
|
||||
func CheckExtractorExpiry(extractors []ExtractorInfo, warningDuration, criticalDuration time.Duration) []ExtractorInfo {
|
||||
@@ -202,9 +208,9 @@ func CheckExtractorExpiry(extractors []ExtractorInfo, warningDuration, criticalD
|
||||
continue
|
||||
}
|
||||
|
||||
expiryTime, err := time.Parse("2006-01-02 15:04:05", e.ExpiryDate)
|
||||
expiryTime, err := time.Parse(time.RFC3339, e.ExpiryDate)
|
||||
if err != nil {
|
||||
logger.Warning("Failed to parse expiry date %s: %v", e.ExpiryDate, err)
|
||||
logger.Warning("Failed to parse expiry date in ISO 8601 (RFC3339) format %s: %v", e.ExpiryDate, err)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -220,15 +226,15 @@ func CheckExtractorExpiry(extractors []ExtractorInfo, warningDuration, criticalD
|
||||
}
|
||||
|
||||
// FormatStorageAlert formats a storage alert message
|
||||
func FormatStorageAlert(storage StorageInfo, isCritical bool) string {
|
||||
severity := "WARNING"
|
||||
if isCritical {
|
||||
severity = "CRITICAL"
|
||||
}
|
||||
// func FormatStorageAlert(storage StorageInfo, isCritical bool) string {
|
||||
// severity := "WARNING"
|
||||
// if isCritical {
|
||||
// severity = "CRITICAL"
|
||||
// }
|
||||
|
||||
return fmt.Sprintf("%s: %s almost full on %s (%.1f%% utilized)",
|
||||
severity, storage.StorageType, storage.PlanetName, storage.Utilization)
|
||||
}
|
||||
// return fmt.Sprintf("%s: %s almost full on %s (%.1f%% utilized)",
|
||||
// severity, storage.StorageType, storage.PlanetName, storage.Utilization)
|
||||
// }
|
||||
|
||||
// FormatExtractorAlert formats an extractor alert message
|
||||
func FormatExtractorAlert(extractor ExtractorInfo, isCritical bool) string {
|
||||
|
||||
@@ -50,7 +50,7 @@ func (rh *RouteHandler) SetupRoutes(r *router.Router) {
|
||||
|
||||
// New endpoints
|
||||
r.GET("/extractors/{characterName}", rh.handleGetExtractors)
|
||||
r.GET("/storage/{characterName}", rh.handleGetStorage)
|
||||
// r.GET("/storage/{characterName}", rh.handleGetStorage)
|
||||
}
|
||||
|
||||
// handleRoot handles the root endpoint
|
||||
@@ -266,30 +266,30 @@ func (rh *RouteHandler) handleGetExtractors(ctx *fasthttp.RequestCtx) {
|
||||
}
|
||||
|
||||
// handleGetStorage returns storage information for a character
|
||||
func (rh *RouteHandler) handleGetStorage(ctx *fasthttp.RequestCtx) {
|
||||
characterName := ctx.UserValue("characterName").(string)
|
||||
logger.Info("Getting storage for character: %s", characterName)
|
||||
// func (rh *RouteHandler) handleGetStorage(ctx *fasthttp.RequestCtx) {
|
||||
// characterName := ctx.UserValue("characterName").(string)
|
||||
// logger.Info("Getting storage for character: %s", characterName)
|
||||
|
||||
// Get character info
|
||||
char, err := rh.SSO.GetCharacter(context.Background(), characterName)
|
||||
if err != nil {
|
||||
logger.Error("Failed to get character %s: %v", characterName, err)
|
||||
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
|
||||
ctx.SetBodyString("Failed to get character")
|
||||
return
|
||||
}
|
||||
// // Get character info
|
||||
// char, err := rh.SSO.GetCharacter(context.Background(), characterName)
|
||||
// if err != nil {
|
||||
// logger.Error("Failed to get character %s: %v", characterName, err)
|
||||
// ctx.SetStatusCode(fasthttp.StatusInternalServerError)
|
||||
// ctx.SetBodyString("Failed to get character")
|
||||
// return
|
||||
// }
|
||||
|
||||
// Get storage using the standalone function
|
||||
storage, err := GetStorageForCharacter(rh.ESI, int(char.ID), char.AccessToken)
|
||||
if err != nil {
|
||||
logger.Error("Failed to get storage for character %s: %v", characterName, err)
|
||||
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
|
||||
ctx.SetBodyString("Failed to get storage")
|
||||
return
|
||||
}
|
||||
// // Get storage using the standalone function
|
||||
// storage, err := GetStorageForCharacter(rh.ESI, int(char.ID), char.AccessToken)
|
||||
// if err != nil {
|
||||
// logger.Error("Failed to get storage for character %s: %v", characterName, err)
|
||||
// ctx.SetStatusCode(fasthttp.StatusInternalServerError)
|
||||
// ctx.SetBodyString("Failed to get storage")
|
||||
// return
|
||||
// }
|
||||
|
||||
// Return storage as JSON
|
||||
ctx.SetContentType("application/json")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
json.NewEncoder(ctx).Encode(storage)
|
||||
}
|
||||
// // Return storage as JSON
|
||||
// ctx.SetContentType("application/json")
|
||||
// ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
// json.NewEncoder(ctx).Encode(storage)
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user