package fenetsec import ( "bytes" "fmt" "net/http" ) type ( // DeviceBackup is the api response from running a backup job DeviceBackup struct { Category string `json:"category"` Created string `json:"created"` Details map[string][]string `json:"details"` Ended string `json:"ended"` ID string `json:"id"` Links map[string]*Link `json:"links"` Node string `json:"node"` PID string `json:"pid"` Result string `json:"result"` Started string `json:"started"` Status string `json:"status"` User string `json:"user"` } // DeviceData holds all of the information on a device from fire engine DeviceData struct { LogicalName string `json:"logical_name"` CoreID int `json:"core_id"` Customer int `json:"customer"` PrimaryIP string `json:"primary_ip"` Netmask string `json:"netmask"` Gateway string `json:"gateway"` DracIP string `json:"drac_ip"` DracNetmask string `json:"drac_netmask"` DracGateway string `json:"drac_gateway"` Platform string `json:"platform"` PlatformType string `json:"platform_type"` PlatfromSku int `json:"platform_sku"` OSVersion string `json:"os_version"` DataCenter string `json:"datacenter"` Segment string `json:"segment"` Status string `json:"status"` HostName string `json:"hostname"` DomanName string `json:"domainname"` Team string `json:"team"` Skus []int `json:"skus"` AttachedDevices []int `json:"attached_devices"` Active bool `json:"active"` Exclude bool `json:"exclude"` Links map[string]*Link `json:"links"` } // DeviceEvents defines the return value from the /events method DeviceEvents struct { Items []DeviceEvent `json:"items"` } // DeviceEvent defines the structure for a single device event DeviceEvent struct { ID string `json:"id" bson:"id"` Created string `json:"created" bson:"created"` Started string `json:"started" bson:"started"` Ended string `json:"ended" bson:"ended"` Category string `json:"category" bson:"category"` User string `json:"user" bson:"user"` Details map[string][]string `json:"details" bson:"details"` PID string `json:"pid" bson:"pid"` Node string `json:"node" bson:"node"` Status string `json:"status" bson:"status"` Result string `json:"result" bson:"result"` Links map[string]*Link `json:"links"` } // DeviceFiles holds a list of links and items DeviceFiles struct { Links map[string]*Link `json:"links"` Items []*DeviceFile `json:"items"` } // DeviceFile holds all of the information on a file in fire engine DeviceFile struct { ID string `json:"id"` Created string `json:"created"` Updated string `json:"updated"` Name string `json:"name"` CheckSum string `json:"checksum"` Content string `json:"content"` Current bool `json:"current"` Retatin bool `json:"retain"` DisplayName string `json:"display_name"` NetsecFile bool `json:"netsec_file"` NetsecStandard bool `json:"netsec_standard"` Links map[string]*Link `json:"links"` } // Link holds the links of a fire engine object Link struct { Rel string `json:"rel"` HRef string `json:"href"` } ) // DeviceBackup runs a backup job on the device and returns the result func (c *Client) DeviceBackup(d int, options ...*FireEngineOptions) (*DeviceBackup, error) { o := processOptions(options...) req, err := c.newRequest(feAPI+fmt.Sprintf("/devices/%d/backup", d), http.MethodPost, o, nil) if err != nil { return nil, err } fdd := new(DeviceBackup) _, err = c.do(req, o, fdd) return fdd, err } // DeviceInfo returns the top level information for the device func (c *Client) DeviceInfo(d int, options ...*FireEngineOptions) (*DeviceData, error) { o := processOptions(options...) req, err := c.newRequest(feAPI+fmt.Sprintf("/devices/%d", d), http.MethodGet, o, nil) if err != nil { return nil, err } fdd := new(DeviceData) _, err = c.do(req, o, fdd) return fdd, err } // DeviceEvents returns the list of events for the device func (c *Client) DeviceEvents(d int, options ...*FireEngineOptions) (*DeviceEvents, error) { o := processOptions(options...) req, err := c.newRequest(feAPI+fmt.Sprintf("/devices/%d/events", d), http.MethodGet, o, nil) if err != nil { return nil, err } fdd := new(DeviceEvents) _, err = c.do(req, o, fdd) return fdd, err } // DeviceFiles returns all the files for the device given. func (c *Client) DeviceFiles(d int, options ...*FireEngineOptions) (*DeviceFiles, error) { o := processOptions(options...) req, err := c.newRequest(feAPI+fmt.Sprintf("/devices/%d/files", d), http.MethodGet, o, nil) if err != nil { return nil, err } fdf := new(DeviceFiles) _, err = c.do(req, o, fdf) return fdf, err } // DeviceFile returns the file for the device and filename given. func (c *Client) DeviceFile(d int, fn string, options ...*FireEngineOptions) (*DeviceFile, error) { o := processOptions(options...) req, err := c.newRequest(feAPI+fmt.Sprintf("/devices/%d/files/%s", d, fn), http.MethodGet, o, nil) if err != nil { return nil, err } fdf := new(DeviceFile) _, err = c.do(req, o, fdf) return fdf, err } // DeviceFileRaw returns the raw file for the device and filename given. func (c *Client) DeviceFileRaw(d int, fn string, options ...*FireEngineOptions) (string, error) { var ret string o := processOptions(options...) req, err := c.newRequest(feAPI+fmt.Sprintf("/devices/%d/files/%s?raw=true", d, fn), http.MethodGet, o, nil) if err != nil { return ret, err } var buf bytes.Buffer _, err = c.do(req, o, &buf) if err != nil { return ret, err } return buf.String(), nil }