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