Advertisement
Guest User

Untitled

a guest
Mar 15th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.36 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "time"
  6.     "net/http"
  7.     "bytes"
  8.     "io/ioutil"
  9.     "crypto/tls"
  10.     "log"
  11.     "encoding/json"
  12. )
  13.  
  14. const ZENOSS_URL = "https:/****/zport/dmd/device_router"
  15. const ZENNOSS_USER = "admin"
  16. const ZENNOSS_PASSWORD = "****"
  17.  
  18. var getDevices = []byte (`{
  19.     "action": "DeviceRouter",
  20.     "data": [{
  21.         "keys": ["groups"],
  22.         "limit": 100
  23.     }],
  24.     "method": "getDevices",
  25.     "tid": 1
  26. }`)
  27.  
  28. func check(e error) {
  29.     if e != nil {
  30.         panic(e)
  31.     }
  32. }
  33.  
  34. func main() {
  35.     currentDate := time.Now().Local().Format("2006-01-02")
  36.     //dumpfile := fmt.Sprintf("/mnt/backup/linux_servers/zenoss/post_dump/%s.dump", currentDate)
  37.     dumpfile := fmt.Sprintf("%s.dump", currentDate)
  38.     log.Println("Starting Backup...")
  39.  
  40.     http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
  41.     req, err := http.NewRequest("POST", ZENOSS_URL, bytes.NewBuffer(getDevices))
  42.     req.SetBasicAuth(ZENNOSS_USER, ZENNOSS_PASSWORD)
  43.     req.Header.Set("Content-Type", "application/json")
  44.  
  45.     client := &http.Client{}
  46.     resp, err := client.Do(req)
  47.     if err != nil {
  48.         panic(err)
  49.     }
  50.     defer resp.Body.Close()
  51.  
  52.     //fmt.Println("response Status:", resp.Status)
  53.     //fmt.Println("response Headers:", resp.Header)
  54.     body, _ := ioutil.ReadAll(resp.Body)
  55.  
  56.     dict := make(map[string]interface{})
  57.     json.Unmarshal(body, &dict)
  58.    
  59.     err = ioutil.WriteFile(dumpfile, body, 0644)
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement