Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,35 @@ Prometheus exporter for the Icinga2 API.
The `icinga2_exporter` listens on HTTP port 9665 by default.
See the `-help` output for more options.

```
-collector.apilistener
Include APIListener data
-debug
Enable debug logging
-icinga.api string
Path to the Icinga2 API (default "https://localhost:5665/v1")
-icinga.cafile string
Path to the Icinga2 API TLS CA
-icinga.certfile string
Path to the Icinga2 API TLS cert
-icinga.insecure
Skip TLS verification for Icinga2 API
-icinga.keyfile string
Path to the Icinga2 API TLS key
-icinga.password string
Icinga2 API Password
-icinga.username string
Icinga2 API Username
-version
Print version
-web.cache-ttl uint
Cache lifetime in seconds for the Icinga API responses (default 60)
-web.listen-address string
Address on which to expose metrics and web interface. (default ":9665")
-web.metrics-path string
Path under which to expose metrics. (default "/metrics")
```

## Collectors

By default only the `CIB` metrics of the status API are collected.
Expand Down
82 changes: 82 additions & 0 deletions internal/icinga/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package icinga

import (
"net/http"
"net/http/httptest"
"net/url"
"os"
"reflect"
"testing"
"time"
)

const (
icingaTestDataCIB1 = "testdata/cib1.json"
)

func loadTestdata(filepath string) []byte {
data, _ := os.ReadFile(filepath)
return data
}

func testConfig(ts *httptest.Server) Config {
u, _ := url.Parse(ts.URL)
return Config{
BasicAuthUsername: "",
BasicAuthPassword: "",
CAFile: "",
CertFile: "",
KeyFile: "",
Insecure: true,
CacheTTL: 0 * time.Second,
IcingaAPIURI: *u,
}
}

func Test_GetCIBMetrics(t *testing.T) {
testcases := map[string]struct {
expected CIBResult
server *httptest.Server
}{
"cib": {
server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(loadTestdata(icingaTestDataCIB1))
})),
expected: CIBResult{
Results: []struct {
Name string `json:"name"`
Status map[string]float64 `json:"status,omitempty"`
}{
{
Name: "CIB",
Status: map[string]float64{
"active_host_checks": 0.123,
"uptime": 123.456,
},
},
},
},
},
}

for name, test := range testcases {
t.Run(name, func(t *testing.T) {
defer test.server.Close()

cfg := testConfig(test.server)

cli, _ := NewClient(cfg)

actual, err := cli.GetCIBMetrics()

if err != nil {
t.Fatalf("did not expect error got:\n %+v", err)
}

if !reflect.DeepEqual(test.expected, actual) {
t.Fatalf("expected:\n %+v \ngot:\n %+v", test.expected, actual)
}
})
}
}
12 changes: 12 additions & 0 deletions internal/icinga/testdata/cib1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"results": [
{
"name": "CIB",
"perfdata": [],
"status": {
"active_host_checks": 0.123,
"uptime": 123.456
}
}
]
}