Exemple #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
}
Exemple #2
0
//Spawn starts a checkDispatcher
func Spawn() {
	if !spawned {
		log.Warning("Spawning the daemon!")
		services.Load()
		go checkDispatcher()
	} else {
		log.Error("Daemon is already active!")
	}
}
Exemple #3
0
//AuthRequired is authentication middleware for user authenticaton.
func AuthRequired() gin.HandlerFunc {
	return func(c *gin.Context) {
		for _, value := range configuration.C.UserTokens {
			if ("Bearer " + value) == c.Request.Header.Get("Authorization") {
				c.Header("Content-Type", "application/json; charset=utf8") //TODO: This should be a seperate middleware
				c.Next()
				return
			}
		}

		log.Warning(c.ClientIP(), "No authorization header match.")
		c.String(401, "Unauthorized.")
		c.Abort()
	}
}
Exemple #4
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.")
}
Exemple #5
0
//Stop daemon from checking
func Stop() {
	log.Warning("Stopping..")
	IsActive = false
}