Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "time"
- "net/http"
- "bytes"
- "io/ioutil"
- "crypto/tls"
- "log"
- "encoding/json"
- )
- const ZENOSS_URL = "https:/****/zport/dmd/device_router"
- const ZENNOSS_USER = "admin"
- const ZENNOSS_PASSWORD = "****"
- var getDevices = []byte (`{
- "action": "DeviceRouter",
- "data": [{
- "keys": ["groups"],
- "limit": 100
- }],
- "method": "getDevices",
- "tid": 1
- }`)
- func check(e error) {
- if e != nil {
- panic(e)
- }
- }
- func main() {
- currentDate := time.Now().Local().Format("2006-01-02")
- //dumpfile := fmt.Sprintf("/mnt/backup/linux_servers/zenoss/post_dump/%s.dump", currentDate)
- dumpfile := fmt.Sprintf("%s.dump", currentDate)
- log.Println("Starting Backup...")
- http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
- req, err := http.NewRequest("POST", ZENOSS_URL, bytes.NewBuffer(getDevices))
- req.SetBasicAuth(ZENNOSS_USER, ZENNOSS_PASSWORD)
- req.Header.Set("Content-Type", "application/json")
- client := &http.Client{}
- resp, err := client.Do(req)
- if err != nil {
- panic(err)
- }
- defer resp.Body.Close()
- //fmt.Println("response Status:", resp.Status)
- //fmt.Println("response Headers:", resp.Header)
- body, _ := ioutil.ReadAll(resp.Body)
- dict := make(map[string]interface{})
- json.Unmarshal(body, &dict)
- err = ioutil.WriteFile(dumpfile, body, 0644)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement