Пример #1
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.")
}
Пример #2
0
func SpawnCheck(service *model.Service) int {
	args := service.Command
	args = strings.Replace(args, "$HOST$", service.Host, -1)
	args = strings.Replace(args, "$TIMEOUT$", strconv.Itoa(service.Timeout), -1)

	status, output, rtime := CheckService(service.Timeout, args)
	service.Output = output

	if status != 0 { //It's going down
		oldHealth := service.Health
		service.ThresholdCounter++

		if oldHealth == -1 { //cold check, now its down
			service.Health = health.WARNING //set warning state
		}

		if oldHealth == 0 {
			service.Health = health.WARNING //(re)set warning state
		}

		if oldHealth == health.WARNING && service.ThresholdCounter >= service.Threshold {
			service.Health = health.CRITICAL //Service is down
			action.Handle(*service)          //Ready for action
		}
	} else {
		oldHealth := service.Health
		service.Health = health.OK
		service.ThresholdCounter = 0
		if oldHealth == health.CRITICAL {
			action.Handle(*service)
		}
	}

	service.Release()
	service.RTime = rtime
	service.LastCheck = time.Now()
	model.Services.Set(service.Identifier, *service)

	return status
}