From a2acbbd0976233f0ed9d34971a6e153a4fe1f972 Mon Sep 17 00:00:00 2001 From: Markus Blaschke Date: Sun, 2 May 2021 22:06:17 +0200 Subject: [PATCH] add azurerm_keyvault_entries metric general refactoring and add new metric azurerm_keyvault_entries Signed-off-by: Markus Blaschke --- README.md | 2 +- azure_tag_filter.go | 3 +- go.mod | 5 +- go.sum | 59 +----------- main.go | 1 + metrics_keyvault.go | 227 ++++++++++++++++++++++++++++---------------- 6 files changed, 151 insertions(+), 146 deletions(-) diff --git a/README.md b/README.md index b959a4d..da18a19 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Metrics |----------------------------------------|---------------------------------------------------------------------------------------| | `azurerm_keyvault_info` | Azure KeyVault information | | `azurerm_keyvault_status` | Azure KeyVault status information (eg. if accessable from exporter) | +| `azurerm_keyvault_entries` | Count of entries (seperated by type) inside Azure KeyVault | | `azurerm_keyvault_key_info` | General inforamtions about keys | | `azurerm_keyvault_key_status` | Status information (notBefore & expiry date) | | `azurerm_keyvault_secret_info` | General inforamtions about secrets | @@ -48,4 +49,3 @@ Metrics | `azurerm_keyvault_certificate_info` | General inforamtions about certificate | | `azurerm_keyvault_certificate_status` | Status information (notBefore & expiry date) | | `azurerm_ratelimit` | Azure API ratelimit information (from last api call) | - diff --git a/azure_tag_filter.go b/azure_tag_filter.go index 96f160e..0bad7fe 100644 --- a/azure_tag_filter.go +++ b/azure_tag_filter.go @@ -3,6 +3,7 @@ package main import ( "fmt" "github.com/prometheus/client_golang/prometheus" + log "github.com/sirupsen/logrus" "regexp" "strings" ) @@ -75,7 +76,7 @@ func (t *AzureTagFilter) filterTags(tags map[string]*string, usePrometheusName b case "title": filterTagValue = strings.ToTitle(filterTagValue) default: - panic(fmt.Sprintf("Unknown filter method \"%v\" specified for tag \"%v\"", method, filterTag.name)) + log.Panic(fmt.Sprintf("unknown filter method \"%v\" specified for tag \"%v\"", method, filterTag.name)) } } } diff --git a/go.mod b/go.mod index fab3263..2e55974 100644 --- a/go.mod +++ b/go.mod @@ -6,19 +6,16 @@ require ( github.com/Azure/azure-sdk-for-go v53.4.0+incompatible github.com/Azure/go-autorest/autorest v0.11.18 github.com/Azure/go-autorest/autorest/azure/auth v0.5.7 - github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect + github.com/Azure/go-autorest/autorest/to v0.4.0 github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect - github.com/dimchansky/utfbom v1.1.1 // indirect github.com/gofrs/uuid v4.0.0+incompatible // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/jessevdk/go-flags v1.5.0 github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect github.com/prometheus/client_golang v1.10.0 github.com/prometheus/common v0.23.0 // indirect - github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect github.com/sirupsen/logrus v1.8.1 github.com/webdevops/go-prometheus-common v0.0.0-20200601190815-465c9d5d262b golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79 // indirect - google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect ) diff --git a/go.sum b/go.sum index d205e37..577a34f 100644 --- a/go.sum +++ b/go.sum @@ -1,24 +1,16 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/Azure/azure-sdk-for-go v48.2.0+incompatible h1:+t2P1j1r5N6lYgPiiz7ZbEVZFkWjVe9WhHbMm0gg8hw= -github.com/Azure/azure-sdk-for-go v48.2.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/azure-sdk-for-go v53.4.0+incompatible h1:ky9S0JoJOvO39ncwrYAVMEBiIjFB/WkbZsWkg/nbYx0= github.com/Azure/azure-sdk-for-go v53.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs= github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= -github.com/Azure/go-autorest/autorest v0.11.9/go.mod h1:eipySxLmqSyC5s5k1CLupqet0PSENBEDP93LQ9a8QYw= -github.com/Azure/go-autorest/autorest v0.11.11 h1:k/wzH9pA3hrtFNsEhJ5SqPEs75W3bzS8VOYA/fJ0j1k= -github.com/Azure/go-autorest/autorest v0.11.11/go.mod h1:eipySxLmqSyC5s5k1CLupqet0PSENBEDP93LQ9a8QYw= github.com/Azure/go-autorest/autorest v0.11.17/go.mod h1:eipySxLmqSyC5s5k1CLupqet0PSENBEDP93LQ9a8QYw= github.com/Azure/go-autorest/autorest v0.11.18 h1:90Y4srNYrwOtAgVo3ndrQkTYn6kf1Eg/AjTFJ8Is2aM= github.com/Azure/go-autorest/autorest v0.11.18/go.mod h1:dSiJPy22c3u0OtOKDNttNgqpNFY/GeWa7GH/Pz56QRA= -github.com/Azure/go-autorest/autorest/adal v0.9.5 h1:Y3bBUV4rTuxenJJs41HU3qmqsb+auo+a3Lz+PlJPpL0= github.com/Azure/go-autorest/autorest/adal v0.9.5/go.mod h1:B7KF7jKIeC9Mct5spmyCB/A8CG/sEz1vwIRGv/bbw7A= github.com/Azure/go-autorest/autorest/adal v0.9.11/go.mod h1:nBKAnTomx8gDtl+3ZCJv2v0KACFHWTB2drffI1B68Pk= github.com/Azure/go-autorest/autorest/adal v0.9.13 h1:Mp5hbtOePIzM8pJVRa3YLrWWmZtoxRXqUEzCfJt3+/Q= github.com/Azure/go-autorest/autorest/adal v0.9.13/go.mod h1:W/MM4U6nLxnIskrw4UwWzlHfGjwUS50aOsc/I3yuU8M= -github.com/Azure/go-autorest/autorest/azure/auth v0.5.3 h1:lZifaPRAk1bqg5vGqreL6F8uLC5V0fDpY8nFvc3boFc= -github.com/Azure/go-autorest/autorest/azure/auth v0.5.3/go.mod h1:4bJZhUhcq8LB20TruwHbAQsmUs2Xh+QR7utuJpLXX3A= github.com/Azure/go-autorest/autorest/azure/auth v0.5.7 h1:8DQB8yl7aLQuP+nuR5e2RO6454OvFlSTXXaNHshc16s= github.com/Azure/go-autorest/autorest/azure/auth v0.5.7/go.mod h1:AkzUsqkrdmNhfP2i54HqINVQopw0CLDnvHpJ88Zz1eI= github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 h1:dMOmEJfkLKW/7JsokJqkyoYSgmR08hi9KrhjZb+JALY= @@ -29,11 +21,8 @@ github.com/Azure/go-autorest/autorest/mocks v0.4.1 h1:K0laFcLE6VLTOwNgSxaGbUcLPu github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k= github.com/Azure/go-autorest/autorest/to v0.4.0 h1:oXVqrxakqqV1UZdSazDOPOLvOIz+XA683u8EctwboHk= github.com/Azure/go-autorest/autorest/to v0.4.0/go.mod h1:fE8iZBn7LQR7zH/9XU2NcPR4o9jEImooCeWJcYV/zLE= -github.com/Azure/go-autorest/autorest/validation v0.3.0 h1:3I9AAI63HfcLtphd9g39ruUwRI+Ca+z/f36KHPFRUss= -github.com/Azure/go-autorest/autorest/validation v0.3.0/go.mod h1:yhLgjC0Wda5DYXl6JAsWyUe4KVNffhoDhG0zVzUMo3E= github.com/Azure/go-autorest/autorest/validation v0.3.1 h1:AgyqjAd94fwNAoTjl/WQXg4VvFeRFpO+UhNyRXqF1ac= github.com/Azure/go-autorest/autorest/validation v0.3.1/go.mod h1:yhLgjC0Wda5DYXl6JAsWyUe4KVNffhoDhG0zVzUMo3E= -github.com/Azure/go-autorest/logger v0.2.0 h1:e4RVHVZKC5p6UANLJHkM4OfR1UKZPj8Wt8Pcx+3oqrE= github.com/Azure/go-autorest/logger v0.2.0/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8= github.com/Azure/go-autorest/logger v0.2.1 h1:IG7i4p/mDa2Ce4TRyAO8IHnVhAVF3RFU+ZtXWSmf4Tg= github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8= @@ -81,9 +70,7 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/dimchansky/utfbom v1.1.0 h1:FcM3g+nofKgUteL8dm/UpdRXNC9KmADgTpLKsu0TRo4= github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U= github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE= @@ -122,17 +109,13 @@ github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4er github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= @@ -143,11 +126,9 @@ github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= @@ -184,8 +165,6 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= -github.com/jessevdk/go-flags v1.4.1-0.20181221193153-c0795c8afcf4 h1:xKkUL6QBojwguhKKetf1SocCAKqc6W7S/mGm9xEGllo= -github.com/jessevdk/go-flags v1.4.1-0.20181221193153-c0795c8afcf4/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= @@ -202,7 +181,6 @@ github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8 github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -277,17 +255,12 @@ github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= -github.com/prometheus/client_golang v1.6.0 h1:YVPodQOcK15POxhgARIvnDRVpLcuK8mglnMrWfyrw6A= github.com/prometheus/client_golang v1.6.0/go.mod h1:ZLOG9ck3JLRdB5MgO8f+lLTe83AXG6ro35rLTxvnIl4= -github.com/prometheus/client_golang v1.7.1 h1:NTGy1Ja9pByO+xAeH/qiWnLrKtr3hJPNjaVUwnjpdpA= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= -github.com/prometheus/client_golang v1.8.0 h1:zvJNkoCFAnYFNC24FV8nW4JdRJ3GIFcLbg65lL/JDcw= -github.com/prometheus/client_golang v1.8.0/go.mod h1:O9VU6huf47PktckDQfMTX0Y8tY0/7TSWwj+ITvv0TnM= github.com/prometheus/client_golang v1.10.0 h1:/o0BDeWzLWXNZ+4q5gXltUvaMpJqckTa+jTNoB+z4cg= github.com/prometheus/client_golang v1.10.0/go.mod h1:WJM3cc3yu7XKBKa/I8WeZm+V3eltZnBwfENSU7mdogU= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -297,11 +270,7 @@ github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8 github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lNawc= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= -github.com/prometheus/common v0.14.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= -github.com/prometheus/common v0.15.0 h1:4fgOnadei3EZvgRwxJ7RMpG1k1pOZth5Pc13tyspaKM= -github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= github.com/prometheus/common v0.18.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= github.com/prometheus/common v0.23.0 h1:GXWvPYuTUenIa+BhOq/x+L/QZzCqASkVRny5KTlPDGM= github.com/prometheus/common v0.23.0/go.mod h1:H6QK/N6XVT42whUeIdI3dp36w49c+/iMDk7UAI2qm7Q= @@ -309,12 +278,8 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= -github.com/prometheus/procfs v0.0.11 h1:DhHlBtkHWPYi8O2y31JkK0TF+DGM+51OopZjH/Ia5qI= github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8= github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/prometheus/procfs v0.2.0 h1:wH4vA7pcjKuZzjF7lM8awk4fnuJO6idemZXoKnULUx4= -github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= @@ -323,16 +288,11 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= -github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b h1:gQZ0qzfKHQIybLANtM3mBXNUtOfsCFXeTsnBqCsx1KM= -github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= -github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= -github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= @@ -347,7 +307,6 @@ github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5J github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -377,8 +336,6 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201116153603-4be66e5b6582 h1:0WDrJ1E7UolDk1KhTXxxw3Fc8qtk5x7dHP431KHEJls= -golang.org/x/crypto v0.0.0-20201116153603-4be66e5b6582/go.mod h1:tCqSYrHVcf3i63Co2FzBkTCo2gdF6Zak62921dSfraU= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= @@ -436,20 +393,15 @@ golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 h1:YTzHMGlqJu67/uEo1lBv0n3wBXhXNeUbB1XfN2vmTm0= golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201116161645-c061ba923fbb h1:+EHGEcgeA7ESswi5i4ojbo7sRzlz7vWoxFGcMuEZtu8= -golang.org/x/sys v0.0.0-20201116161645-c061ba923fbb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79 h1:RX8C8PRZc2hTIod4ds8ij+/4RQX3AqhYj3uOHmyaz4E= golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/term v0.0.0-20201113234701-d7a72108b828/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -483,7 +435,6 @@ google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= @@ -493,23 +444,16 @@ google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= @@ -525,7 +469,6 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/main.go b/main.go index ca4fec2..195fc73 100644 --- a/main.go +++ b/main.go @@ -176,6 +176,7 @@ func startHttpServer() { http.Handle("/metrics", promhttp.Handler()) log.Error(http.ListenAndServe(opts.ServerBind, nil)) } + func azureResponseInspector(subscription *subscriptions.Subscription) autorest.RespondDecorator { subscriptionId := "" if subscription != nil { diff --git a/metrics_keyvault.go b/metrics_keyvault.go index 9992b32..4bb3d3c 100644 --- a/metrics_keyvault.go +++ b/metrics_keyvault.go @@ -2,7 +2,6 @@ package main import ( "context" - "fmt" "github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/subscriptions" "github.com/Azure/azure-sdk-for-go/services/keyvault/2016-10-01/keyvault" keyvaultMgmt "github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2016-10-01/keyvault" @@ -22,12 +21,21 @@ type MetricsCollectorKeyvault struct { keyvaultAuth autorest.Authorizer prometheus struct { - keyvault *prometheus.GaugeVec - keyvaultStatus *prometheus.GaugeVec - keyvaultKeyInfo *prometheus.GaugeVec - keyvaultKeyStatus *prometheus.GaugeVec - keyvaultSecretInfo *prometheus.GaugeVec - keyvaultSecretStatus *prometheus.GaugeVec + // general + keyvault *prometheus.GaugeVec + keyvaultStatus *prometheus.GaugeVec + keyvaultAccessPolicy *prometheus.GaugeVec + keyvaultEntryCount *prometheus.GaugeVec + + // key + keyvaultKeyInfo *prometheus.GaugeVec + keyvaultKeyStatus *prometheus.GaugeVec + + // secret + keyvaultSecretInfo *prometheus.GaugeVec + keyvaultSecretStatus *prometheus.GaugeVec + + // certs keyvaultCertificateInfo *prometheus.GaugeVec keyvaultCertificateStatus *prometheus.GaugeVec } @@ -45,7 +53,7 @@ func (m *MetricsCollectorKeyvault) Setup(collector *CollectorGeneral) { m.prometheus.keyvault = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "azurerm_keyvault_info", - Help: "Azure KeyVault informations", + Help: "Azure KeyVault information", }, append( []string{ @@ -66,7 +74,6 @@ func (m *MetricsCollectorKeyvault) Setup(collector *CollectorGeneral) { Help: "Azure KeyVault status", }, []string{ - "subscriptionID", "resourceID", "vaultName", "type", @@ -75,14 +82,28 @@ func (m *MetricsCollectorKeyvault) Setup(collector *CollectorGeneral) { ) prometheus.MustRegister(m.prometheus.keyvaultStatus) + m.prometheus.keyvaultEntryCount = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "azurerm_keyvault_entries", + Help: "Azure KeyVault entries", + }, + []string{ + "resourceID", + "vaultName", + "type", + }, + ) + prometheus.MustRegister(m.prometheus.keyvaultEntryCount) + // ------------------------------------------ // key m.prometheus.keyvaultKeyInfo = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "azurerm_keyvault_key_info", - Help: "Azure KeyVault key informations", + Help: "Azure KeyVault key information", }, []string{ + "resourceID", "vaultName", "keyID", "enabled", @@ -96,6 +117,7 @@ func (m *MetricsCollectorKeyvault) Setup(collector *CollectorGeneral) { Help: "Azure KeyVault key status", }, []string{ + "resourceID", "vaultName", "keyID", "type", @@ -108,9 +130,10 @@ func (m *MetricsCollectorKeyvault) Setup(collector *CollectorGeneral) { m.prometheus.keyvaultSecretInfo = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "azurerm_keyvault_secret_info", - Help: "Azure KeyVault secret informations", + Help: "Azure KeyVault secret information", }, []string{ + "resourceID", "vaultName", "secretID", "enabled", @@ -124,6 +147,7 @@ func (m *MetricsCollectorKeyvault) Setup(collector *CollectorGeneral) { Help: "Azure KeyVault secret status", }, []string{ + "resourceID", "vaultName", "secretID", "type", @@ -136,9 +160,10 @@ func (m *MetricsCollectorKeyvault) Setup(collector *CollectorGeneral) { m.prometheus.keyvaultCertificateInfo = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "azurerm_keyvault_certificate_info", - Help: "Azure KeyVault certificate informations", + Help: "Azure KeyVault certificate information", }, []string{ + "resourceID", "vaultName", "certificateID", "enabled", @@ -152,6 +177,7 @@ func (m *MetricsCollectorKeyvault) Setup(collector *CollectorGeneral) { Help: "Azure KeyVault certificate status", }, []string{ + "resourceID", "vaultName", "certificateID", "type", @@ -163,6 +189,7 @@ func (m *MetricsCollectorKeyvault) Setup(collector *CollectorGeneral) { func (m *MetricsCollectorKeyvault) Reset() { m.prometheus.keyvault.Reset() m.prometheus.keyvaultStatus.Reset() + m.prometheus.keyvaultEntryCount.Reset() m.prometheus.keyvaultKeyInfo.Reset() m.prometheus.keyvaultKeyStatus.Reset() m.prometheus.keyvaultSecretInfo.Reset() @@ -176,7 +203,7 @@ func (m *MetricsCollectorKeyvault) Collect(ctx context.Context, logger *log.Entr var err error var wg sync.WaitGroup - keyvaultClient := keyvaultMgmt.NewVaultsClientWithBaseURI(azureEnvironment.KeyVaultEndpoint, *subscription.SubscriptionID) + keyvaultClient := keyvaultMgmt.NewVaultsClientWithBaseURI(azureEnvironment.ResourceManagerEndpoint, *subscription.SubscriptionID) keyvaultClient.Authorizer = AzureAuthorizer keyvaultClient.ResponseInspector = azureResponseInspector(&subscription) @@ -187,7 +214,7 @@ func (m *MetricsCollectorKeyvault) Collect(ctx context.Context, logger *log.Entr } if err != nil { - panic(err) + log.WithField("subscription", *subscription.SubscriptionID).Panic(err) } keyvaultCount := 0 @@ -229,7 +256,13 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * vaultCertificateMetrics := prometheusCommon.NewMetricsList() vaultCertificateStatusMetrics := prometheusCommon.NewMetricsList() - vaultUrl := fmt.Sprintf("https://%s.%s", to.String(vault.Name), azureEnvironment.KeyVaultDNSSuffix) + vaultUrl := to.String(vault.Properties.VaultURI) + vaultResourceId := to.String(vault.ID) + vaultName := to.String(vault.Name) + + entrySecretsCount := float64(0) + entryKeysCount := float64(0) + entryCertsCount := float64(0) // ######################## // Keyvault @@ -237,8 +270,8 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * vaultLabels := prometheus.Labels{ "subscriptionID": to.String(subscription.SubscriptionID), - "resourceID": to.String(vault.ID), - "vaultName": to.String(vault.Name), + "resourceID": vaultResourceId, + "vaultName": vaultName, "location": to.String(vault.Location), "resourceGroup": extractResourceGroupFromAzureId(*vault.ID), } @@ -253,29 +286,29 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * if err != nil { logger.Warning(err) vaultStatusMetrics.Add(prometheus.Labels{ - "subscriptionID": to.String(subscription.SubscriptionID), - "resourceID": to.String(vault.ID), - "vaultName": to.String(vault.Name), - "type": "access", - "scope": "keys", + "resourceID": vaultResourceId, + "vaultName": vaultName, + "type": "access", + "scope": "keys", }, 0) } else { vaultStatusMetrics.Add(prometheus.Labels{ - "subscriptionID": to.String(subscription.SubscriptionID), - "resourceID": to.String(vault.ID), - "vaultName": to.String(vault.Name), - "type": "access", - "scope": "keys", + "resourceID": vaultResourceId, + "vaultName": vaultName, + "type": "access", + "scope": "keys", }, 1) } for keyResult.NotDone() { item := keyResult.Value() + entryKeysCount++ vaultKeyMetrics.AddInfo(prometheus.Labels{ - "vaultName": to.String(vault.Name), - "keyID": to.String(item.Kid), - "enabled": boolToString(*item.Attributes.Enabled), + "resourceID": vaultResourceId, + "vaultName": vaultName, + "keyID": to.String(item.Kid), + "enabled": boolToString(*item.Attributes.Enabled), }) // expiry date @@ -285,9 +318,10 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * expiryDate = float64(timestamp.Unix()) } vaultKeyStatusMetrics.Add(prometheus.Labels{ - "vaultName": to.String(vault.Name), - "keyID": to.String(item.Kid), - "type": "expiry", + "resourceID": vaultResourceId, + "vaultName": vaultName, + "keyID": to.String(item.Kid), + "type": "expiry", }, expiryDate) // not before @@ -297,9 +331,10 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * notBeforeDate = float64(timestamp.Unix()) } vaultKeyStatusMetrics.Add(prometheus.Labels{ - "vaultName": to.String(vault.Name), - "keyID": to.String(item.Kid), - "type": "notBefore", + "resourceID": vaultResourceId, + "vaultName": vaultName, + "keyID": to.String(item.Kid), + "type": "notBefore", }, notBeforeDate) // created @@ -309,9 +344,10 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * createdDate = float64(timestamp.Unix()) } vaultKeyStatusMetrics.Add(prometheus.Labels{ - "vaultName": to.String(vault.Name), - "keyID": to.String(item.Kid), - "type": "created", + "resourceID": vaultResourceId, + "vaultName": vaultName, + "keyID": to.String(item.Kid), + "type": "created", }, createdDate) // updated @@ -321,9 +357,10 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * updatedDate = float64(timestamp.Unix()) } vaultKeyStatusMetrics.Add(prometheus.Labels{ - "vaultName": to.String(vault.Name), - "keyID": to.String(item.Kid), - "type": "updated", + "resourceID": vaultResourceId, + "vaultName": vaultName, + "keyID": to.String(item.Kid), + "type": "updated", }, updatedDate) if keyResult.NextWithContext(ctx) != nil { @@ -339,29 +376,29 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * if err != nil { logger.Warning(err) vaultStatusMetrics.Add(prometheus.Labels{ - "subscriptionID": to.String(subscription.SubscriptionID), - "resourceID": to.String(vault.ID), - "vaultName": to.String(vault.Name), - "type": "access", - "scope": "secrets", + "resourceID": vaultResourceId, + "vaultName": vaultName, + "type": "access", + "scope": "secrets", }, 0) } else { vaultStatusMetrics.Add(prometheus.Labels{ - "subscriptionID": to.String(subscription.SubscriptionID), - "resourceID": to.String(vault.ID), - "vaultName": to.String(vault.Name), - "type": "access", - "scope": "secrets", + "resourceID": vaultResourceId, + "vaultName": vaultName, + "type": "access", + "scope": "secrets", }, 1) } for secretsResult.NotDone() { item := secretsResult.Value() + entrySecretsCount++ vaultSecretMetrics.AddInfo(prometheus.Labels{ - "vaultName": to.String(vault.Name), - "secretID": to.String(item.ID), - "enabled": boolToString(to.Bool(item.Attributes.Enabled)), + "resourceID": vaultResourceId, + "vaultName": vaultName, + "secretID": to.String(item.ID), + "enabled": boolToString(to.Bool(item.Attributes.Enabled)), }) // expiry date @@ -371,9 +408,10 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * expiryDate = float64(timestamp.Unix()) } vaultSecretStatusMetrics.Add(prometheus.Labels{ - "vaultName": to.String(vault.Name), - "secretID": to.String(item.ID), - "type": "expiry", + "resourceID": vaultResourceId, + "vaultName": vaultName, + "secretID": to.String(item.ID), + "type": "expiry", }, expiryDate) // notbefore @@ -383,9 +421,10 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * notBeforeDate = float64(timestamp.Unix()) } vaultSecretStatusMetrics.Add(prometheus.Labels{ - "vaultName": to.String(vault.Name), - "secretID": to.String(item.ID), - "type": "notBefore", + "resourceID": vaultResourceId, + "vaultName": vaultName, + "secretID": to.String(item.ID), + "type": "notBefore", }, notBeforeDate) // created @@ -395,9 +434,10 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * createdDate = float64(timestamp.Unix()) } vaultSecretStatusMetrics.Add(prometheus.Labels{ - "vaultName": to.String(vault.Name), - "secretID": to.String(item.ID), - "type": "created", + "resourceID": vaultResourceId, + "vaultName": vaultName, + "secretID": to.String(item.ID), + "type": "created", }, createdDate) // updated @@ -407,9 +447,10 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * updatedDate = float64(timestamp.Unix()) } vaultSecretStatusMetrics.Add(prometheus.Labels{ - "vaultName": to.String(vault.Name), - "secretID": to.String(item.ID), - "type": "updated", + "resourceID": vaultResourceId, + "vaultName": vaultName, + "secretID": to.String(item.ID), + "type": "updated", }, updatedDate) if secretsResult.NextWithContext(ctx) != nil { @@ -425,27 +466,27 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * if err != nil { logger.Warning(err) vaultStatusMetrics.Add(prometheus.Labels{ - "subscriptionID": to.String(subscription.SubscriptionID), - "resourceID": to.String(vault.ID), - "vaultName": to.String(vault.Name), - "type": "access", - "scope": "certificates", + "resourceID": vaultResourceId, + "vaultName": vaultName, + "type": "access", + "scope": "certificates", }, 0) } else { vaultStatusMetrics.Add(prometheus.Labels{ - "subscriptionID": to.String(subscription.SubscriptionID), - "resourceID": to.String(vault.ID), - "vaultName": to.String(vault.Name), - "type": "access", - "scope": "certificates", + "resourceID": vaultResourceId, + "vaultName": vaultName, + "type": "access", + "scope": "certificates", }, 1) } for certificateResult.NotDone() { item := certificateResult.Value() + entryCertsCount++ vaultCertificateMetrics.AddInfo(prometheus.Labels{ - "vaultName": to.String(vault.Name), + "resourceID": vaultResourceId, + "vaultName": vaultName, "certificateID": to.String(item.ID), "enabled": boolToString(to.Bool(item.Attributes.Enabled)), }) @@ -457,7 +498,8 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * expiryDate = float64(timestamp.Unix()) } vaultCertificateStatusMetrics.Add(prometheus.Labels{ - "vaultName": to.String(vault.Name), + "resourceID": vaultResourceId, + "vaultName": vaultName, "certificateID": to.String(item.ID), "type": "expiry", }, expiryDate) @@ -469,7 +511,8 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * notBeforeDate = float64(timestamp.Unix()) } vaultCertificateStatusMetrics.Add(prometheus.Labels{ - "vaultName": to.String(vault.Name), + "resourceID": vaultResourceId, + "vaultName": vaultName, "certificateID": to.String(item.ID), "type": "notBefore", }, notBeforeDate) @@ -481,7 +524,8 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * createdDate = float64(timestamp.Unix()) } vaultCertificateStatusMetrics.Add(prometheus.Labels{ - "vaultName": to.String(vault.Name), + "resourceID": vaultResourceId, + "vaultName": vaultName, "certificateID": to.String(item.ID), "type": "created", }, createdDate) @@ -493,7 +537,8 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * updatedDate = float64(timestamp.Unix()) } vaultCertificateStatusMetrics.Add(prometheus.Labels{ - "vaultName": to.String(vault.Name), + "resourceID": vaultResourceId, + "vaultName": vaultName, "certificateID": to.String(item.ID), "type": "updated", }, updatedDate) @@ -516,6 +561,24 @@ func (m *MetricsCollectorKeyvault) collectKeyvault(ctx context.Context, logger * vaultSecretStatusMetrics.GaugeSet(m.prometheus.keyvaultSecretStatus) vaultCertificateMetrics.GaugeSet(m.prometheus.keyvaultCertificateInfo) vaultCertificateStatusMetrics.GaugeSet(m.prometheus.keyvaultCertificateStatus) + + m.prometheus.keyvaultEntryCount.With(prometheus.Labels{ + "resourceID": vaultResourceId, + "vaultName": vaultName, + "type": "secrets", + }).Set(entrySecretsCount) + + m.prometheus.keyvaultEntryCount.With(prometheus.Labels{ + "resourceID": vaultResourceId, + "vaultName": vaultName, + "type": "keys", + }).Set(entryKeysCount) + + m.prometheus.keyvaultEntryCount.With(prometheus.Labels{ + "resourceID": vaultResourceId, + "vaultName": vaultName, + "type": "certificates", + }).Set(entryCertsCount) } return