blob: 77a67d94a04ebf5148d5a59853cc81e33a56d0c0 [file] [log] [blame]
mce7028402019-07-18 04:10:01 +00001// Copyright 2018 Open Networking Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package main
16
17import (
18 "net/http"
19 "fmt"
20 "encoding/json"
21 "regexp"
22 "strings"
23 "io/ioutil"
24)
25
Dinesh Belwalkare1e85ad2019-07-31 23:06:47 +000026func (s *Server) get_status(ip string, service string) (rtn bool, data []string) {
mce7028402019-07-18 04:10:01 +000027 rtn = false
28
mc862dad02019-08-06 20:52:51 +000029 uri := s.devicemap[ip].Protocol + "://"+ip + REDFISH_ROOT + service
Dinesh Belwalkare1e85ad2019-07-31 23:06:47 +000030 fmt.Printf("%q", uri)
mce7028402019-07-18 04:10:01 +000031 resp, err := http.Get(uri)
32 if err != nil {
33 fmt.Println(err)
34 return
35 }
36 body := make(map[string]interface{})
37 json.NewDecoder(resp.Body).Decode(&body)
38 resp.Body.Close()
39
40 if members, ok := body["Members"]; ok {
41 re := regexp.MustCompile(`\[([^\[\]]*)\]`)
42 memberstr := fmt.Sprintf("%v", members)
43 matches := re.FindAllString(memberstr, -1)
44 for _, match := range matches {
45 m := strings.Trim(match, "[]")
mc862dad02019-08-06 20:52:51 +000046 uri = s.devicemap[ip].Protocol +"://"+ip + strings.TrimPrefix(m, "@odata.id:")
Dinesh Belwalkare1e85ad2019-07-31 23:06:47 +000047 fmt.Println("Printing URI")
48 fmt.Println(uri)
mce7028402019-07-18 04:10:01 +000049 resp, err = http.Get(uri)
50 if err != nil {
51 fmt.Println(err)
52 } else {
53 b, err := ioutil.ReadAll(resp.Body)
54 if err != nil {
55 fmt.Println(err)
56 } else {
57 data = append(data, string(b))
58 rtn = true
59 }
mc862dad02019-08-06 20:52:51 +000060 defer resp.Body.Close()
mce7028402019-07-18 04:10:01 +000061 }
mce7028402019-07-18 04:10:01 +000062 }
63 }
64 return
65}