Example #1
0
func CollectNagiosResource(typ string, resp chan<- *bytes.Buffer, tags ...string) {
	log.Print("INFO: Start PuppetDB query for resources of type nagios_", typ)
	cr, err := puppetquery.CollectResources(nagiosPrefix+typ, tags...)
	if err != nil {
		log.Fatalln("ERROR: cannot query PuppetDB: ", err)
	} else {
		log.Printf("INFO: End query for %s (received %d resources)\n", typ, len(cr))
	}
	b := new(bytes.Buffer)
	err = generate(b, time.Now(), cr)
	if err != nil {
		log.Println("ERROR: generating resources for", typ)
		resp <- nil
	} else {
		log.Printf("INFO: done generating %d %s definitions\n", len(cr), typ)
		resp <- b
	}
}
Example #2
0
func main() {
	var typ string
	flag.StringVar(&typ, "t", "", "type of resource")
	flag.Parse()
	tags := flag.Args()
	log.Print("INFO: Start query")
	cr, err := puppetquery.CollectResources(typ, tags...)
	if err != nil {
		log.Fatalln("ERROR: cannot query puppetdb: ", err)
	} else {
		log.Printf("INFO: End query (received %d resources)\n", len(cr))
	}
	b, err := json.MarshalIndent(cr, "", "  ")
	if err != nil {
		log.Fatalln("ERROR: cannot marshal result into json: ", err)
	}

	_, err = os.Stdout.Write(b)
	if err != nil {
		log.Fatalln("ERROR: cannot display result: ", err)
	}
}