blob: b5b4d49782b26f0a12f0e7a20fb93e8273e3ee9c [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
26func get_status(ip string, service string) (rtn bool, data []string) {
27 rtn = false
28
29 uri := ip + REDFISH_ROOT + service
30 resp, err := http.Get(uri)
31 if err != nil {
32 fmt.Println(err)
33 return
34 }
35 body := make(map[string]interface{})
36 json.NewDecoder(resp.Body).Decode(&body)
37 resp.Body.Close()
38
39 if members, ok := body["Members"]; ok {
40 re := regexp.MustCompile(`\[([^\[\]]*)\]`)
41 memberstr := fmt.Sprintf("%v", members)
42 matches := re.FindAllString(memberstr, -1)
43 for _, match := range matches {
44 m := strings.Trim(match, "[]")
45 uri = ip + strings.TrimPrefix(m, "@odata.id:")
46 resp, err = http.Get(uri)
47 if err != nil {
48 fmt.Println(err)
49 } else {
50 b, err := ioutil.ReadAll(resp.Body)
51 if err != nil {
52 fmt.Println(err)
53 } else {
54 data = append(data, string(b))
55 rtn = true
56 }
57 }
58 defer resp.Body.Close()
59 }
60 }
61 return
62}