blob: f68f280b84f8e540fa51976f7f403007ee414dd0 [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
Dinesh Belwalkare1e85ad2019-07-31 23:06:47 +000029// uri := "https://"+ip + REDFISH_ROOT + service
30 uri := s.devicemap[ip].protocol+"://"+ip + REDFISH_ROOT + service
31 fmt.Printf("%q", uri)
mce7028402019-07-18 04:10:01 +000032 resp, err := http.Get(uri)
33 if err != nil {
34 fmt.Println(err)
35 return
36 }
37 body := make(map[string]interface{})
38 json.NewDecoder(resp.Body).Decode(&body)
39 resp.Body.Close()
40
41 if members, ok := body["Members"]; ok {
42 re := regexp.MustCompile(`\[([^\[\]]*)\]`)
43 memberstr := fmt.Sprintf("%v", members)
44 matches := re.FindAllString(memberstr, -1)
45 for _, match := range matches {
46 m := strings.Trim(match, "[]")
Dinesh Belwalkare1e85ad2019-07-31 23:06:47 +000047 uri = s.devicemap[ip].protocol +"://"+ip + strings.TrimPrefix(m, "@odata.id:")
48 fmt.Println("Printing URI")
49 fmt.Println(uri)
mce7028402019-07-18 04:10:01 +000050 resp, err = http.Get(uri)
51 if err != nil {
52 fmt.Println(err)
53 } else {
54 b, err := ioutil.ReadAll(resp.Body)
55 if err != nil {
56 fmt.Println(err)
57 } else {
58 data = append(data, string(b))
59 rtn = true
60 }
61 }
62 defer resp.Body.Close()
63 }
64 }
65 return
66}