func NewMeasurementCollection(args ...interface{}) *MeasurementCollection { c := MeasurementCollection(make(map[string]Measurement)) l := len(args) if l > 0 && l%2 == 0 { l /= 2 for i := 0; i < l; i++ { key := args[i*2].(string) value := args[i*2+1] switch value.(type) { case int: c[key] = Measurement(value.(int)) case int64: c[key] = Measurement(value.(int64)) case uint64: c[key] = Measurement(value.(uint64)) case float32: c[key] = Measurement(value.(float32)) case float64: c[key] = Measurement(value.(float64)) case time.Duration: c[key] = Measurement(value.(time.Duration).Nanoseconds()) default: logger.Error("plugins", "Unsupported type") } } } else if l > 0 { logger.Error("plugins", "Wrong number of arguments to NewMeasurementCollection()") } return &c }
func init() { var err error conn, err = icmp.ListenPacket("ip4:icmp", "0.0.0.0") if err != nil { if err.Error() == "listen ip4:icmp 0.0.0.0: socket: operation not permitted" { logger.Error("icmpping", "Please run:\nsudo setcap cap_net_raw=ep %s\n", os.Args[0]) } else { logger.Error("icmpping", err.Error()) } } active = make(map[uint16]chan IcmpReply) plugins.Register("icmp4", NewIcmpPing) go ListenLoop() }
func Register(protocol string, constructor Constructor) { _, exists := plugins[protocol] if exists { logger.Error("plugins", "plugins.Register(): Duplicate protocol: '%s' (%T and %T)\n", protocol, plugins[protocol], constructor()) return } plugins[protocol] = constructor }
func init() { sess, err := mgo.Dial("127.0.0.1") if err != nil { logger.Error("monitor", "Can't connect to mongo, go error %v", err) os.Exit(1) } db = sess.DB("alerto") hostCollection = db.C("hosts") monitorCollection = db.C("monitors") }