-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from genegr/main
New release to add the enhancement requested in issue #19
- Loading branch information
Showing
76 changed files
with
46,408 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package config | ||
|
||
type FlashBlade struct { | ||
Address string `yaml:"address"` | ||
ApiToken string `yaml:"api_token"` | ||
} | ||
|
||
type FlashBladeList map[string]FlashBlade | ||
|
||
func (f *FlashBladeList) GetArrayParams(fb string) (string, string) { | ||
for a_name, a := range *f { | ||
if a_name == fb { | ||
return a.Address, a.ApiToken | ||
} | ||
} | ||
return "", "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package collectors | ||
|
||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"regexp" | ||
"strings" | ||
"net/http" | ||
"net/http/httptest" | ||
"encoding/json" | ||
"os" | ||
|
||
"purestorage/fb-openmetrics-exporter/internal/rest-client" | ||
) | ||
|
||
func TestAlertsCollector(t *testing.T) { | ||
|
||
ropen, _ := os.ReadFile("../../test/data/alerts_open.json") | ||
rall, _ := os.ReadFile("../../test/data/alerts.json") | ||
vers, _ := os.ReadFile("../../test/data/versions.json") | ||
var aopen client.AlertsList | ||
var aall client.AlertsList | ||
json.Unmarshal(ropen, &aopen) | ||
json.Unmarshal(rall, &aall) | ||
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
urlall := regexp.MustCompile(`^/api/([0-9]+.[0-9]+)?/alerts$`) | ||
urlopen := regexp.MustCompile(`^/api/([0-9]+.[0-9]+)?/alerts\?filter=state%3D%27open%27$`) | ||
if r.URL.Path == "/api/api_version" { | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
w.Write([]byte(vers)) | ||
} else if urlopen.MatchString(r.URL.Path + "?" + r.URL.RawQuery) { | ||
w.Header().Set("x-auth-token", "faketoken") | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
w.Write([]byte(ropen)) | ||
} else if urlall.MatchString(r.URL.Path) { | ||
w.Header().Set("x-auth-token", "faketoken") | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
w.Write([]byte(rall)) | ||
} | ||
})) | ||
endp := strings.Split(server.URL, "/") | ||
e := endp[len(endp)-1] | ||
al := make(map[string]float64) | ||
for _, a := range aopen.Items { | ||
al[fmt.Sprintf("%s,%s,%s", a.ComponentName, a.ComponentType, a.Severity)] += 1 | ||
} | ||
want := make(map[string]bool) | ||
for a, n := range al { | ||
alert := strings.Split(a, ",") | ||
want[fmt.Sprintf("label:<name:\"component_name\" value:\"%s\" > label:<name:\"component_type\" value:\"%s\" > label:<name:\"severity\" value:\"%s\" > gauge:<value:%g > ", alert[0], alert[1], alert[2], n)] = true | ||
} | ||
c := client.NewRestClient(e, "fake-api-token", "latest", false) | ||
ac := NewAlertsCollector(c) | ||
metricsCheck(t, ac, want) | ||
server.Close() | ||
} |
Oops, something went wrong.