/* Package autoshundb is an interface between the f5api and the NSI mongodb for tracking active shuns on the devices. It maintains the records in the mongodb to show what is shunned in what devices. That GUI is then used by various rackers to view the shun information, since the F5 does not have a way of showing it directly. Usage One first needs to initiate the client. This will connect to the DB, ping it, and set the collection for the functions to utilize. import ( "github.rackspace.com/gorax/f5api/autoshundb" "github.com/sirupsen/logrus" ) db, err := autoshundb.New() if err != nil { log.Fatal(err) } You can override the package's default logging by including a *logrus.Logger log := logrus.New() db, err := autoshundb.New([]*logrus.Logger{log}) ... Once the DB is initialized you'll need to either find an existing device, or create a new device before writing or updating it to the DB. reqID is the uuid of the http connection originating the action, for logging purposes. dev := new(autoshundb.Device) var err error dev, err = db.FindDevice("349764") if err != nil { if err == mongo.ErrNoDocuments { // Device wasn't found, just create a new one dev, err = db.NewDevice("349764", "reqID") if err != nil { log.Fatal(err) } } else { // Some other error happened log.Fatal(err) } } You can then add a new shun to that device. shunLength is provided by peg and will be the number of hours till the shun is removed removeDate is calculated by us, for reference in the gui RFC822 is just used as a reference, actual format from PEG is pending... shunLength = shunLength * time.Hour // convert the bare hours like "25" in to time.Duration * hour (destination is nanoseconds) remove, err := time.Now().Add(shunLength) err = db.AddShun(dev, "8.8.8.8", "user", "pegID", "reqID", shunLength, remove) if err != nil { log.Fatal(err) } Removing an existing shun is similar if err := db.RemoveShun(dev, "8.8.8.8", "user", "reqID"); err != nil { log.Fatal(err) } */ package autoshundb