Beispiel #1
0
//Reload compares current map with memory and updates added, changed or removed services
func Reload() {
	//Do not start a new check while updating
	jsonServices := loader.FindServices() //[]Service
	jsonServicesMap := model.NewCMap()    //Concurrent string-Service map

	for _, newService := range jsonServices {
		//oldService := Services[newService.Identifier]
		oldService, _ := model.Services.Get(newService.Identifier)

		if oldService.Identifier != newService.Identifier {
			newService.Health = 2 //TODO: const enum
		} else {
			newService.Health = oldService.Health
		}

		newService.Claimed = oldService.Claimed
		newService.LastCheck = oldService.LastCheck
		newService.ThresholdCounter = oldService.ThresholdCounter
		newService.Output = oldService.Output
		newService.RTime = oldService.RTime

		jsonServicesMap.Set(newService.Identifier, newService)
		log.Warning("Reloaded " + oldService.Identifier + " as " + newService.Identifier)
	}

	model.Services = jsonServicesMap
}
Beispiel #2
0
//TestConfiguration checks if configuration can be loaded and shows amount of services
func TestConfiguration() error {
	services := loader.FindServices()
	length := len(services)
	log.Info("Length:", length, "services")
	if length > 0 {
		return nil
	} else {
		return errors.New("Amount of services is invalid.")
	}
}
Beispiel #3
0
//UpdateService updates only the given service from actual configuration
func UpdateService(old model.Service) error {
	//Do not start a new check while updating by claiming it.
	old.Claim()
	for _, new := range loader.FindServices() {
		if new.Identifier == old.Identifier {
			new.CopyAttributes(&old)
			//push new service to Services map
			model.Services.Set(old.Identifier, new)

			log.Warning("Reloaded", new.Identifier, "from", old.Identifier)
			return nil
		}
	}

	return errors.New("Service not found.")
}
Beispiel #4
0
func Load() {
	for _, service := range loader.FindServices() {
		service.Health = -1 //you know nothing, monitoring
		model.Services.Set(service.Identifier, service)
	}
}