13 /* xs_submit takes a file containing a single XonStat request and submits it
14 to the server URL specified */
16 fn := flag.String("file", "xonstat.log", "Logfile from XonStat")
17 url := flag.String("url", "http://localhost:6543/stats/submit", "XonStat submission URL")
18 out := flag.Bool("out", false, "logs the response body to <file>.out")
21 body, err := ioutil.ReadFile(*fn)
23 fmt.Printf("Issue opening file %s\n", *fn)
26 contentlength := int64(len(body))
28 r := bytes.NewReader(body)
30 req, _ := http.NewRequest("POST", *url, r)
31 req.ContentLength = contentlength
32 res, _ := http.DefaultClient.Do(req)
33 defer res.Body.Close()
35 fmt.Printf("%s: %s\n", *fn, res.Status)
38 // open the output file for the response
39 of, err := os.Create(*fn + ".out")
41 fmt.Printf("Issue creating file %s.out\n", *fn)
46 bo := bufio.NewWriter(of)
49 scanner := bufio.NewScanner(res.Body)
51 fmt.Fprintln(bo, scanner.Text())