func newSubprobeTriggerSets(monitor *monitor, name string) map[db.TargetType]sameTypeTriggerSet {
	triggerSets := make(map[db.TargetType]sameTypeTriggerSet)
	for _, monitorTrigger := range monitor.triggers {
		if monitorTrigger.subprobes.MatchString(name) {
			triggerTemplate := monitorTrigger.triggerTemplate
			targetType := triggerTemplate.target.Type().ID()
			triggerSet := triggerSets[targetType]
			if triggerSet == nil {
				triggerSet = newSameTypeTriggerSet()
				triggerSets[targetType] = triggerSet
			}
			triggerSet.add(newTrigger(triggerTemplate, monitor.Env))
		}
	}
	return triggerSets
}
newSubprobeTriggerSets filters monitor's triggers down to a map appropriate
for the triggerSets field of a subprobe with the given name.
package daemon
import (
	"time"
	log "github.com/sirupsen/logrus"
	"github.com/juju/errors"
	"github.com/yext/revere/db"
	"github.com/yext/revere/env"
	"github.com/yext/revere/probe"
	"github.com/yext/revere/state"
	"github.com/yext/revere/target"
)
type subprobe struct {
	id      db.SubprobeID
	monitor *monitor
	name    string
	lastReading  time.Time
	state        state.State
	enteredState time.Time
	lastNormal   time.Time
	saveNextReading bool
	triggerSets map[db.TargetType]sameTypeTriggerSet
	*env.Env
}
func newSubprobe(name string, status db.SubprobeStatus, monitor *monitor) *subprobe {
	return &subprobe{
		id:              status.SubprobeID,
		monitor:         monitor,
		name:            name,
		lastReading:     status.Recorded,
		state:           status.State,
		enteredState:    status.EnteredState,
		lastNormal:      status.LastNormal,
		saveNextReading: false,
		triggerSets:     newSubprobeTriggerSets(monitor, name),
		Env:             monitor.Env,
	}
}
func createSubprobe(monitor *monitor, reading probe.Reading) (*subprobe, error) {
	s := &subprobe{
		monitor: monitor,
		name:    reading.Subprobe,
		lastReading:  reading.Recorded,
		state:        reading.State,
		enteredState: reading.Recorded,
		lastNormal: reading.Recorded,
		saveNextReading: true,
		triggerSets: newSubprobeTriggerSets(monitor, reading.Subprobe),
		Env: monitor.Env,
	}
	err := s.DB.Tx(func(tx *db.Tx) error {
		var err error
		s.id, err = tx.InsertSubprobe(monitor.id, s.name)
		if err != nil {
			return errors.Maskf(err, "insert subprobe")
		}
		status := s.dbStatus()
		err = tx.InsertSubprobeStatus(status)
		if err != nil {
			return errors.Maskf(err, "insert subprobe status")
		}
		return nil
	})
	if err != nil {
		return nil, errors.Mask(err)
	}
	return s, nil
}