Skip to content

Instantly share code, notes, and snippets.

@jessepeterson
Created January 9, 2020 22:35
Show Gist options
  • Save jessepeterson/8222174c65042afba5c22fb4934d30a4 to your computer and use it in GitHub Desktop.
Save jessepeterson/8222174c65042afba5c22fb4934d30a4 to your computer and use it in GitHub Desktop.
Dump a UDID's various command state in a MicroMDM database
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/boltdb/bolt"
"github.com/micromdm/micromdm/platform/pubsub/inmem"
"github.com/micromdm/micromdm/platform/queue"
)
func main() {
var (
flDB = flag.String("db", "/var/db/micromdm.db", "path to micromdm DB")
flUDID = flag.String("udid", "", "UDID of device")
)
flag.Parse()
if *flUDID == "" {
fmt.Fprintln(flag.CommandLine.Output(), "must supply udid with -udid")
flag.Usage()
os.Exit(2)
}
if _, err := os.Stat(*flDB); os.IsNotExist(err) {
log.Fatal(err)
}
db, err := bolt.Open(*flDB, 0600, nil)
if err != nil {
log.Fatal(err)
}
ps := inmem.NewPubSub()
q, err := queue.NewQueue(db, ps)
if err != nil {
log.Fatal(err)
}
dc, err := q.DeviceCommand(*flUDID)
if err != nil {
log.Fatal(err)
}
if dc == nil {
log.Fatalln("nil DeviceCommand")
}
fmt.Printf("DeviceCommand commands for udid %s\n\n", *flUDID)
fmt.Println("===> Commands (queue)")
for _, c := range dc.Commands {
fmt.Println(string(c.Payload))
}
fmt.Println("===> Completed")
for _, c := range dc.Completed {
fmt.Println(string(c.Payload))
}
fmt.Println("===> Failed")
for _, c := range dc.Failed {
fmt.Println(string(c.Payload))
}
fmt.Println("===> NotNow")
for _, c := range dc.NotNow {
fmt.Println(string(c.Payload))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment