Merge pull request #644 from prymitive/openapi

feat: support alertmanager >=0.17.0
This commit is contained in:
Łukasz Mierzwa
2019-04-24 22:01:27 +01:00
committed by GitHub
77 changed files with 6080 additions and 98 deletions

View File

@@ -12,7 +12,7 @@ PORT := 8080
# based on http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html
rwildcard = $(foreach d, $(wildcard $1*), $(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
SOURCES := $(wildcard *.go) $(wildcard */*.go) $(wildcard */*/*.go)
SOURCES := $(wildcard *.go) $(call rwildcard, internal, *)
ASSET_SOURCES := $(call rwildcard, ui/public ui/src, *)
GO_BINDATA_MODE := prod

View File

@@ -5,13 +5,16 @@ Alert dashboard for
---
Alertmanager `>=0.16.0` is currently **NOT** supported by karma due to changes
Alertmanager `0.16.x` is **NOT** supported by karma due to changes
in the API, see [this issue](https://github.com/prymitive/karma/issues/115)
for details.
There is an issue tracking Alertmanager feature request that will enable karma
support for future releases, see
[this issue](https://github.com/prometheus/alertmanager/issues/868) for
details.
A new API endpoint
[was added](https://github.com/prometheus/alertmanager/pull/1791) and will be
available in the next Alertmanager release (`>=0.17.0`). This new endpoint is
supported by karma.
tl;dr skip Alertmanager `0.16.x` and wait for `0.17.0` if you wish to use it
with karma
---

View File

@@ -47,7 +47,10 @@ def jsonGetRequest(uri):
def jsonPostRequest(uri, data):
req = urllib2.Request(uri)
req.add_header("Content-Type", "application/json")
response = urllib2.urlopen(req, json.dumps(data))
try:
response = urllib2.urlopen(req, json.dumps(data))
except Exception as e:
print("Request to '%s' failed: %s" % (uri, e))
def addSilence(matchers, startsAt, endsAt, createdBy, comment):

5
go.mod
View File

@@ -13,6 +13,11 @@ require (
github.com/gin-gonic/contrib v0.0.0-20190408174833-b5986969cb50
github.com/gin-gonic/gin v1.3.0
github.com/go-bindata/go-bindata v3.1.1+incompatible
github.com/go-openapi/errors v0.18.0
github.com/go-openapi/runtime v0.18.0
github.com/go-openapi/strfmt v0.18.0
github.com/go-openapi/swag v0.18.0
github.com/go-openapi/validate v0.18.0
github.com/golangci/golangci-lint v1.16.0
github.com/hansrodtang/randomcolor v0.0.0-20160512071917-d27108b3d7a5
github.com/jarcoal/httpmock v1.0.3

59
go.sum
View File

@@ -4,10 +4,16 @@ github.com/DeanThompson/ginpprof v0.0.0-20190408070748-3be636683586 h1:xM7fXz/Ol
github.com/DeanThompson/ginpprof v0.0.0-20190408070748-3be636683586/go.mod h1:kMi/fSDAgvjo9TYfYwYeQ2vkyj+VTR/tB6u/Tjh39t0=
github.com/OpenPeeDeeP/depguard v0.0.0-20180806142446-a69c782687b2 h1:HTOmFEEYrWi4MW5ZKUx6xfeyM10Sx3kQF65xiQJMPYA=
github.com/OpenPeeDeeP/depguard v0.0.0-20180806142446-a69c782687b2/go.mod h1:7/4sitnI9YlQgTLLk734QlzXT8DuHVnAyztLplQjk+o=
github.com/PuerkitoBio/purell v1.1.0 h1:rmGxhojJlM0tuKtfdvliR84CFHljx9ag64t2xmVkjK4=
github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf h1:eg0MeVzsP1G42dRafH3vf+al2vQIJU0YHX+1Tw87oco=
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/blang/semver v3.6.1+incompatible h1:RmA4CjDkwiAdjCfRQH6UZRp45n/uV30JiSkad6Acn/8=
@@ -21,7 +27,7 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
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/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/elazarl/go-bindata-assetfs v1.0.1-0.20180223160309-38087fe4dafb h1:Dnxl6iOR/3QQRcCBDEOCpusGgsx7uDS+Pa/InwqCFfw=
github.com/elazarl/go-bindata-assetfs v1.0.1-0.20180223160309-38087fe4dafb/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
@@ -43,6 +49,9 @@ github.com/gin-gonic/contrib v0.0.0-20190408174833-b5986969cb50 h1:4Oea7uehNujse
github.com/gin-gonic/contrib v0.0.0-20190408174833-b5986969cb50/go.mod h1:iqneQ2Df3omzIVTkIfn7c1acsVnMGiSLn4XF5Blh3Yg=
github.com/gin-gonic/gin v1.3.0 h1:kCmZyPklC0gVdL728E6Aj20uYBJV93nj/TkwBTKhFbs=
github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y=
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 h1:DujepqpGd1hyOd7aW59XpK7Qymp8iy83xq74fLr21is=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/go-bindata/go-bindata v3.1.1+incompatible h1:tR4f0e4VTO7LK6B2YWyAoVEzG9ByG1wrXB4TL9+jiYg=
github.com/go-bindata/go-bindata v3.1.1+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/go-critic/go-critic v0.0.0-20181204210945-ee9bf5809ead h1:qwmAYufKDopQnFdeMw+iHJVxAd2CbF+VFKHyJJwnPKk=
@@ -52,6 +61,40 @@ github.com/go-lintpack/lintpack v0.5.2 h1:DI5mA3+eKdWeJ40nU4d6Wc26qmdG8RCi/btYq0
github.com/go-lintpack/lintpack v0.5.2/go.mod h1:NwZuYi2nUHho8XEIZ6SIxihrnPoqBTDqfpXvXAN0sXM=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
github.com/go-openapi/analysis v0.0.0-20180825180245-b006789cd277/go.mod h1:k70tL6pCuVxPJOHXQ+wIac1FUrvNkHolPie/cLEU6hI=
github.com/go-openapi/analysis v0.17.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik=
github.com/go-openapi/analysis v0.17.2 h1:eYp14J1o8TTSCzndHBtsNuckikV1PfZOSnx4BcBeu0c=
github.com/go-openapi/analysis v0.17.2/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik=
github.com/go-openapi/errors v0.17.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0=
github.com/go-openapi/errors v0.17.2/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0=
github.com/go-openapi/errors v0.18.0 h1:+RnmJ5MQccF7jwWAoMzwOpzJEspZ18ZIWfg9Z2eiXq8=
github.com/go-openapi/errors v0.18.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0=
github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M=
github.com/go-openapi/jsonpointer v0.17.2 h1:3ekBy41gar/iJi2KSh/au/PrC2vpLr85upF/UZmm3W0=
github.com/go-openapi/jsonpointer v0.17.2/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M=
github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
github.com/go-openapi/jsonreference v0.17.2 h1:lF3z7AH8dd0IKXc1zEBi1dj0B4XgVb5cVjn39dCK3Ls=
github.com/go-openapi/jsonreference v0.17.2/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
github.com/go-openapi/loads v0.17.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU=
github.com/go-openapi/loads v0.17.2 h1:tEXYu6Xc0pevpzzQx5ghrMN9F7IVpN/+u4iD3rkYE5o=
github.com/go-openapi/loads v0.17.2/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU=
github.com/go-openapi/runtime v0.0.0-20180920151709-4f900dc2ade9/go.mod h1:6v9a6LTXWQCdL8k1AO3cvqx5OtZY/Y9wKTgaoP6YRfA=
github.com/go-openapi/runtime v0.18.0 h1:ddoL4Uo/729XbNAS9UIsG7Oqa8R8l2edBe6Pq/i8AHM=
github.com/go-openapi/runtime v0.18.0/go.mod h1:uI6pHuxWYTy94zZxgcwJkUWa9wbIlhteGfloI10GD4U=
github.com/go-openapi/spec v0.17.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI=
github.com/go-openapi/spec v0.17.2 h1:eb2NbuCnoe8cWAxhtK6CfMWUYmiFEZJ9Hx3Z2WRwJ5M=
github.com/go-openapi/spec v0.17.2/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI=
github.com/go-openapi/strfmt v0.17.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
github.com/go-openapi/strfmt v0.17.2/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
github.com/go-openapi/strfmt v0.18.0 h1:FqqmmVCKn3di+ilU/+1m957T1CnMz3IteVUcV3aGXWA=
github.com/go-openapi/strfmt v0.18.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
github.com/go-openapi/swag v0.17.2/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
github.com/go-openapi/swag v0.18.0 h1:1DU8Km1MRGv9Pj7BNLmkA+umwTStwDHttXvx3NhJA70=
github.com/go-openapi/swag v0.18.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
github.com/go-openapi/validate v0.17.2/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4=
github.com/go-openapi/validate v0.18.0 h1:PVXYcP1GkTl+XIAJnyJxOmK6CSG5Q1UcvoCvNO++5Kg=
github.com/go-openapi/validate v0.18.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-toolsmith/astcast v0.0.0-20181028201508-b7a89ed70af1 h1:h+1eMw+tZAlgTVclcVN0/rdPaBI/RUzG0peblT6df+Q=
github.com/go-toolsmith/astcast v0.0.0-20181028201508-b7a89ed70af1/go.mod h1:TEo3Ghaj7PsZawQHxT/oBvo4HK/sl1RcuUHDKTTju+o=
@@ -113,6 +156,9 @@ github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 h1:zwtduBRr5SSW
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4/go.mod h1:Izgrg8RkN3rCIMLGE9CyYmU9pY2Jer6DgANEnZ/L/cQ=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s=
github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hansrodtang/randomcolor v0.0.0-20160512071917-d27108b3d7a5 h1:9WT/rQ2tZI0TBZhBsA/dYU1bdI2QKaUzQ3X6YDwaLUY=
github.com/hansrodtang/randomcolor v0.0.0-20160512071917-d27108b3d7a5/go.mod h1:XvzgNvkcPBKMxeywFlPioejZ5ulXi/GMLZDoBw915FA=
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w=
@@ -142,6 +188,8 @@ github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQ
github.com/magiconair/properties v1.7.6/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
@@ -175,6 +223,8 @@ github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.1.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
@@ -188,7 +238,6 @@ github.com/prometheus/client_golang v0.9.2 h1:awm861/B8OKDd2I/6o1dy3ra4BamzKhYOi
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 h1:PnBWHBf+6L0jOqq0gIVUe6Yk0/QMZ640k6NvkxcBf+8=
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.3.0 h1:taZ4h8Tkxv2kNyoSctBvfXEHmBmxrwmIidZTIaHons4=
github.com/prometheus/common v0.3.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
@@ -235,16 +284,15 @@ github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 h1:EICbibRW4JNKMcY
github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a h1:YX8ljsm6wXlHZO+aRz9Exqr0evNhKRNe5K/gi+zKh4U=
golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20170915142106-8351a756f30f/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3 h1:eH6Eip3UpmR+yM/qI9Ijluzb1bNv/cAU/n+6l8tRSis=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190313220215-9f648a60d977 h1:actzWV6iWn3GLqN8dZjzsB+CLt+gaV2+wsxroxiQI8I=
@@ -258,9 +306,7 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6 h1:IcgEB62HYgAhX0Nd/QrVgZlxlcyxbGQHElLUhW2X4Fo=
golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb h1:pf3XwC90UUdNPYWZdFjhGBE7DUFuK3Ct1zWmZ65QN30=
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313 h1:pczuHS43Cp2ktBEEmLwScxgjWsBSzdaQiKzUyf3DTTc=
@@ -277,7 +323,6 @@ golang.org/x/tools v0.0.0-20190314010720-f0bfdbff1f9c h1:nE2ID2IbO0sUUG/3vWMz0LS
golang.org/x/tools v0.0.0-20190314010720-f0bfdbff1f9c/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
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 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@@ -2,10 +2,11 @@ package alertmanager
import (
"github.com/prymitive/karma/internal/mapper"
"github.com/prymitive/karma/internal/mapper/v04"
"github.com/prymitive/karma/internal/mapper/v05"
"github.com/prymitive/karma/internal/mapper/v061"
"github.com/prymitive/karma/internal/mapper/v062"
v016 "github.com/prymitive/karma/internal/mapper/v016"
v04 "github.com/prymitive/karma/internal/mapper/v04"
v05 "github.com/prymitive/karma/internal/mapper/v05"
v061 "github.com/prymitive/karma/internal/mapper/v061"
v062 "github.com/prymitive/karma/internal/mapper/v062"
)
// initialize all mappers
@@ -16,4 +17,6 @@ func init() {
mapper.RegisterAlertMapper(v062.AlertMapper{})
mapper.RegisterSilenceMapper(v04.SilenceMapper{})
mapper.RegisterSilenceMapper(v05.SilenceMapper{})
mapper.RegisterAlertMapper(v016.AlertMapper{})
mapper.RegisterSilenceMapper(v016.SilenceMapper{})
}

View File

@@ -9,7 +9,7 @@ type karmaCollector struct {
errorsTotal *prometheus.Desc
}
func newkarmaCollector() *karmaCollector {
func newKarmaCollector() *karmaCollector {
return &karmaCollector{
collectedAlerts: prometheus.NewDesc(
"karma_collected_alerts_count",
@@ -117,5 +117,5 @@ func (c *karmaCollector) Collect(ch chan<- prometheus.Metric) {
}
func init() {
prometheus.MustRegister(newkarmaCollector())
prometheus.MustRegister(newKarmaCollector())
}

View File

@@ -170,31 +170,40 @@ func (am *Alertmanager) pullSilences(version string) error {
return err
}
// generate full URL to collect silences from
url, err := mapper.AbsoluteURL(am.URI)
if err != nil {
log.Errorf("[%s] Failed to generate silences endpoint URL: %s", am.Name, err)
return err
}
// append query args if mapper needs those
queryArgs := mapper.QueryArgs()
if queryArgs != "" {
url = fmt.Sprintf("%s?%s", url, queryArgs)
}
var silences []models.Silence
start := time.Now()
// read raw body from the source
source, err := am.reader.Read(url, am.HTTPHeaders)
if err != nil {
log.Errorf("[%s] %s request failed: %s", am.Name, uri.SanitizeURI(url), err)
return err
}
defer source.Close()
if mapper.IsOpenAPI() {
silences, err = mapper.Collect(am.URI, am.HTTPHeaders, am.RequestTimeout, am.HTTPTransport)
if err != nil {
return err
}
} else {
// generate full URL to collect silences from
url, err := mapper.AbsoluteURL(am.URI)
if err != nil {
log.Errorf("[%s] Failed to generate silences endpoint URL: %s", am.Name, err)
return err
}
// append query args if mapper needs those
queryArgs := mapper.QueryArgs()
if queryArgs != "" {
url = fmt.Sprintf("%s?%s", url, queryArgs)
}
// decode body text
silences, err := mapper.Decode(source)
if err != nil {
return err
// read raw body from the source
source, err := am.reader.Read(url, am.HTTPHeaders)
if err != nil {
log.Errorf("[%s] %s request failed: %s", am.Name, uri.SanitizeURI(url), err)
return err
}
defer source.Close()
// decode body text
silences, err = mapper.Decode(source)
if err != nil {
return err
}
}
log.Infof("[%s] Got %d silences(s) in %s", am.Name, len(silences), time.Since(start))
@@ -234,32 +243,42 @@ func (am *Alertmanager) pullAlerts(version string) error {
return err
}
// generate full URL to collect alerts from
url, err := mapper.AbsoluteURL(am.URI)
if err != nil {
log.Errorf("[%s] Failed to generate alerts endpoint URL: %s", am.Name, err)
return err
}
// append query args if mapper needs those
queryArgs := mapper.QueryArgs()
if queryArgs != "" {
url = fmt.Sprintf("%s?%s", url, queryArgs)
}
var groups []models.AlertGroup
start := time.Now()
// read raw body from the source
source, err := am.reader.Read(url, am.HTTPHeaders)
if err != nil {
log.Errorf("[%s] %s request failed: %s", am.Name, uri.SanitizeURI(url), err)
return err
}
defer source.Close()
if mapper.IsOpenAPI() {
groups, err = mapper.Collect(am.URI, am.HTTPHeaders, am.RequestTimeout, am.HTTPTransport)
if err != nil {
return err
}
} else {
// decode body text
groups, err := mapper.Decode(source)
if err != nil {
return err
// generate full URL to collect alerts from
url, err := mapper.AbsoluteURL(am.URI)
if err != nil {
log.Errorf("[%s] Failed to generate alerts endpoint URL: %s", am.Name, err)
return err
}
// append query args if mapper needs those
queryArgs := mapper.QueryArgs()
if queryArgs != "" {
url = fmt.Sprintf("%s?%s", url, queryArgs)
}
// read raw body from the source
source, err := am.reader.Read(url, am.HTTPHeaders)
if err != nil {
log.Errorf("[%s] %s request failed: %s", am.Name, uri.SanitizeURI(url), err)
return err
}
defer source.Close()
// decode body text
groups, err = mapper.Decode(source)
if err != nil {
return err
}
}
log.Infof("[%s] Got %d alert group(s) in %s", am.Name, len(groups), time.Since(start))

View File

@@ -0,0 +1,22 @@
package mapper
import "net/http"
func SetHeaders(inner http.RoundTripper, headers map[string]string) http.RoundTripper {
return &headersRoundTripper{
inner: inner,
Headers: headers,
}
}
type headersRoundTripper struct {
inner http.RoundTripper
Headers map[string]string
}
func (hrt *headersRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
for k, v := range hrt.Headers {
r.Header.Set(k, v)
}
return hrt.inner.RoundTrip(r)
}

View File

@@ -3,6 +3,8 @@ package mapper
import (
"fmt"
"io"
"net/http"
"time"
"github.com/prymitive/karma/internal/models"
)
@@ -17,18 +19,21 @@ type Mapper interface {
IsSupported(version string) bool
AbsoluteURL(baseURI string) (string, error)
QueryArgs() string
IsOpenAPI() bool
}
// AlertMapper handles mapping of Alertmanager alert information to karma AlertGroup models
type AlertMapper interface {
Mapper
Decode(io.ReadCloser) ([]models.AlertGroup, error)
Collect(string, map[string]string, time.Duration, http.RoundTripper) ([]models.AlertGroup, error)
}
// SilenceMapper handles mapping of Alertmanager silence information to karma Silence models
type SilenceMapper interface {
Mapper
Decode(io.ReadCloser) ([]models.Silence, error)
Collect(string, map[string]string, time.Duration, http.RoundTripper) ([]models.Silence, error)
}
// RegisterAlertMapper allows to register mapper implementing alert data

View File

@@ -0,0 +1,7 @@
FROM quay.io/goswagger/swagger:v0.19.0
RUN apk add --update curl
COPY run.sh /run.sh
ENTRYPOINT ["/run.sh"]

View File

@@ -0,0 +1,17 @@
ALERTMANAGER_VERSION := 2fa210d0e3c86bea44a38f4131c069752738a6cb
API_VERSION := v2
PACKAGE := v016
TARGET_DIR := /go/src/github.com/prymitive/karma/internal/mapper/$(PACKAGE)
IMAGE_NAME := openapi_client_$(PACKAGE)
.PHONY: client
client:
docker build -t $(IMAGE_NAME) .
docker run \
--rm \
-w $(TARGET_DIR) \
-v $(shell pwd):$(TARGET_DIR) \
$(IMAGE_NAME) \
$(ALERTMANAGER_VERSION) $(API_VERSION) $(TARGET_DIR)
.DEFAULT_GOAL := client

View File

@@ -0,0 +1,43 @@
package v016
import (
"net/http"
"time"
"github.com/blang/semver"
"github.com/prymitive/karma/internal/mapper"
"github.com/prymitive/karma/internal/models"
"github.com/prymitive/karma/internal/uri"
)
// AlertMapper implements Alertmanager API schema
type AlertMapper struct {
mapper.AlertMapper
}
// AbsoluteURL for alerts API endpoint this mapper supports
func (m AlertMapper) AbsoluteURL(baseURI string) (string, error) {
return uri.JoinURL(baseURI, "api/v2/alerts/groups")
}
// QueryArgs for HTTP requests send to the Alertmanager API endpoint
func (m AlertMapper) QueryArgs() string {
return ""
}
// IsSupported returns true if given version string is supported
func (m AlertMapper) IsSupported(version string) bool {
versionRange := semver.MustParseRange(">=0.16.1")
return versionRange(semver.MustParse(version))
}
// IsOpenAPI returns true is remote Alertmanager uses OpenAPI
func (m AlertMapper) IsOpenAPI() bool {
return true
}
func (m AlertMapper) Collect(uri string, headers map[string]string, timeout time.Duration, httpTransport http.RoundTripper) ([]models.AlertGroup, error) {
c := newClient(uri, headers, httpTransport)
return groups(c, timeout)
}

View File

@@ -0,0 +1,95 @@
package v016
import (
"net/http"
"net/url"
"path"
"sort"
"time"
httptransport "github.com/go-openapi/runtime/client"
"github.com/prymitive/karma/internal/mapper"
"github.com/prymitive/karma/internal/mapper/v016/client"
"github.com/prymitive/karma/internal/mapper/v016/client/alertgroup"
"github.com/prymitive/karma/internal/mapper/v016/client/silence"
"github.com/prymitive/karma/internal/models"
)
func newClient(uri string, headers map[string]string, httpTransport http.RoundTripper) *client.Alertmanager {
u, _ := url.Parse(uri)
transport := httptransport.New(u.Host, path.Join(u.Path, "/api/v2"), []string{u.Scheme})
if httpTransport != nil {
transport.Transport = mapper.SetHeaders(httpTransport, headers)
} else {
transport.Transport = mapper.SetHeaders(transport.Transport, headers)
}
c := client.New(transport, nil)
return c
}
// Alerts will fetch all alert groups from the API
func groups(c *client.Alertmanager, timeout time.Duration) ([]models.AlertGroup, error) {
ret := []models.AlertGroup{}
groups, err := c.Alertgroup.GetAlertGroups(alertgroup.NewGetAlertGroupsParamsWithTimeout(timeout))
if err != nil {
return []models.AlertGroup{}, err
}
for _, group := range groups.Payload {
g := models.AlertGroup{
Receiver: *group.Receiver.Name,
Labels: group.Labels,
}
for _, alert := range group.Alerts {
a := models.Alert{
Receiver: *group.Receiver.Name,
Annotations: models.AnnotationsFromMap(alert.Annotations),
Labels: alert.Labels,
StartsAt: time.Time(*alert.StartsAt),
EndsAt: time.Time(*alert.EndsAt),
GeneratorURL: alert.GeneratorURL.String(),
State: *alert.Status.State,
InhibitedBy: alert.Status.InhibitedBy,
SilencedBy: alert.Status.SilencedBy,
}
sort.Strings(a.InhibitedBy)
sort.Strings(a.SilencedBy)
a.UpdateFingerprints()
g.Alerts = append(g.Alerts, a)
}
ret = append(ret, g)
}
return ret, nil
}
func silences(c *client.Alertmanager, timeout time.Duration) ([]models.Silence, error) {
ret := []models.Silence{}
silences, err := c.Silence.GetSilences(silence.NewGetSilencesParamsWithTimeout(timeout))
if err != nil {
return ret, err
}
for _, s := range silences.Payload {
us := models.Silence{
ID: *s.ID,
StartsAt: time.Time(*s.StartsAt),
EndsAt: time.Time(*s.EndsAt),
CreatedBy: *s.CreatedBy,
Comment: *s.Comment,
}
for _, m := range s.Matchers {
sm := models.SilenceMatcher{
Name: *m.Name,
Value: *m.Value,
IsRegex: *m.IsRegex,
}
us.Matchers = append(us.Matchers, sm)
}
ret = append(ret, us)
}
return ret, nil
}

View File

@@ -0,0 +1,86 @@
// Code generated by go-swagger; DO NOT EDIT.
package alert
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
)
// New creates a new alert API client.
func New(transport runtime.ClientTransport, formats strfmt.Registry) *Client {
return &Client{transport: transport, formats: formats}
}
/*
Client for alert API
*/
type Client struct {
transport runtime.ClientTransport
formats strfmt.Registry
}
/*
GetAlerts Get a list of alerts
*/
func (a *Client) GetAlerts(params *GetAlertsParams) (*GetAlertsOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewGetAlertsParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "getAlerts",
Method: "GET",
PathPattern: "/alerts",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &GetAlertsReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*GetAlertsOK), nil
}
/*
PostAlerts Create new Alerts
*/
func (a *Client) PostAlerts(params *PostAlertsParams) (*PostAlertsOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewPostAlertsParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "postAlerts",
Method: "POST",
PathPattern: "/alerts",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &PostAlertsReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*PostAlertsOK), nil
}
// SetTransport changes the transport on the client
func (a *Client) SetTransport(transport runtime.ClientTransport) {
a.transport = transport
}

View File

@@ -0,0 +1,336 @@
// Code generated by go-swagger; DO NOT EDIT.
package alert
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/swag"
strfmt "github.com/go-openapi/strfmt"
)
// NewGetAlertsParams creates a new GetAlertsParams object
// with the default values initialized.
func NewGetAlertsParams() *GetAlertsParams {
var (
activeDefault = bool(true)
inhibitedDefault = bool(true)
silencedDefault = bool(true)
unprocessedDefault = bool(true)
)
return &GetAlertsParams{
Active: &activeDefault,
Inhibited: &inhibitedDefault,
Silenced: &silencedDefault,
Unprocessed: &unprocessedDefault,
timeout: cr.DefaultTimeout,
}
}
// NewGetAlertsParamsWithTimeout creates a new GetAlertsParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewGetAlertsParamsWithTimeout(timeout time.Duration) *GetAlertsParams {
var (
activeDefault = bool(true)
inhibitedDefault = bool(true)
silencedDefault = bool(true)
unprocessedDefault = bool(true)
)
return &GetAlertsParams{
Active: &activeDefault,
Inhibited: &inhibitedDefault,
Silenced: &silencedDefault,
Unprocessed: &unprocessedDefault,
timeout: timeout,
}
}
// NewGetAlertsParamsWithContext creates a new GetAlertsParams object
// with the default values initialized, and the ability to set a context for a request
func NewGetAlertsParamsWithContext(ctx context.Context) *GetAlertsParams {
var (
activeDefault = bool(true)
inhibitedDefault = bool(true)
silencedDefault = bool(true)
unprocessedDefault = bool(true)
)
return &GetAlertsParams{
Active: &activeDefault,
Inhibited: &inhibitedDefault,
Silenced: &silencedDefault,
Unprocessed: &unprocessedDefault,
Context: ctx,
}
}
// NewGetAlertsParamsWithHTTPClient creates a new GetAlertsParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewGetAlertsParamsWithHTTPClient(client *http.Client) *GetAlertsParams {
var (
activeDefault = bool(true)
inhibitedDefault = bool(true)
silencedDefault = bool(true)
unprocessedDefault = bool(true)
)
return &GetAlertsParams{
Active: &activeDefault,
Inhibited: &inhibitedDefault,
Silenced: &silencedDefault,
Unprocessed: &unprocessedDefault,
HTTPClient: client,
}
}
/*GetAlertsParams contains all the parameters to send to the API endpoint
for the get alerts operation typically these are written to a http.Request
*/
type GetAlertsParams struct {
/*Active
Show active alerts
*/
Active *bool
/*Filter
A list of matchers to filter alerts by
*/
Filter []string
/*Inhibited
Show inhibited alerts
*/
Inhibited *bool
/*Receiver
A regex matching receivers to filter alerts by
*/
Receiver *string
/*Silenced
Show silenced alerts
*/
Silenced *bool
/*Unprocessed
Show unprocessed alerts
*/
Unprocessed *bool
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the get alerts params
func (o *GetAlertsParams) WithTimeout(timeout time.Duration) *GetAlertsParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the get alerts params
func (o *GetAlertsParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the get alerts params
func (o *GetAlertsParams) WithContext(ctx context.Context) *GetAlertsParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the get alerts params
func (o *GetAlertsParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the get alerts params
func (o *GetAlertsParams) WithHTTPClient(client *http.Client) *GetAlertsParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the get alerts params
func (o *GetAlertsParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithActive adds the active to the get alerts params
func (o *GetAlertsParams) WithActive(active *bool) *GetAlertsParams {
o.SetActive(active)
return o
}
// SetActive adds the active to the get alerts params
func (o *GetAlertsParams) SetActive(active *bool) {
o.Active = active
}
// WithFilter adds the filter to the get alerts params
func (o *GetAlertsParams) WithFilter(filter []string) *GetAlertsParams {
o.SetFilter(filter)
return o
}
// SetFilter adds the filter to the get alerts params
func (o *GetAlertsParams) SetFilter(filter []string) {
o.Filter = filter
}
// WithInhibited adds the inhibited to the get alerts params
func (o *GetAlertsParams) WithInhibited(inhibited *bool) *GetAlertsParams {
o.SetInhibited(inhibited)
return o
}
// SetInhibited adds the inhibited to the get alerts params
func (o *GetAlertsParams) SetInhibited(inhibited *bool) {
o.Inhibited = inhibited
}
// WithReceiver adds the receiver to the get alerts params
func (o *GetAlertsParams) WithReceiver(receiver *string) *GetAlertsParams {
o.SetReceiver(receiver)
return o
}
// SetReceiver adds the receiver to the get alerts params
func (o *GetAlertsParams) SetReceiver(receiver *string) {
o.Receiver = receiver
}
// WithSilenced adds the silenced to the get alerts params
func (o *GetAlertsParams) WithSilenced(silenced *bool) *GetAlertsParams {
o.SetSilenced(silenced)
return o
}
// SetSilenced adds the silenced to the get alerts params
func (o *GetAlertsParams) SetSilenced(silenced *bool) {
o.Silenced = silenced
}
// WithUnprocessed adds the unprocessed to the get alerts params
func (o *GetAlertsParams) WithUnprocessed(unprocessed *bool) *GetAlertsParams {
o.SetUnprocessed(unprocessed)
return o
}
// SetUnprocessed adds the unprocessed to the get alerts params
func (o *GetAlertsParams) SetUnprocessed(unprocessed *bool) {
o.Unprocessed = unprocessed
}
// WriteToRequest writes these params to a swagger request
func (o *GetAlertsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if o.Active != nil {
// query param active
var qrActive bool
if o.Active != nil {
qrActive = *o.Active
}
qActive := swag.FormatBool(qrActive)
if qActive != "" {
if err := r.SetQueryParam("active", qActive); err != nil {
return err
}
}
}
valuesFilter := o.Filter
joinedFilter := swag.JoinByFormat(valuesFilter, "multi")
// query array param filter
if err := r.SetQueryParam("filter", joinedFilter...); err != nil {
return err
}
if o.Inhibited != nil {
// query param inhibited
var qrInhibited bool
if o.Inhibited != nil {
qrInhibited = *o.Inhibited
}
qInhibited := swag.FormatBool(qrInhibited)
if qInhibited != "" {
if err := r.SetQueryParam("inhibited", qInhibited); err != nil {
return err
}
}
}
if o.Receiver != nil {
// query param receiver
var qrReceiver string
if o.Receiver != nil {
qrReceiver = *o.Receiver
}
qReceiver := qrReceiver
if qReceiver != "" {
if err := r.SetQueryParam("receiver", qReceiver); err != nil {
return err
}
}
}
if o.Silenced != nil {
// query param silenced
var qrSilenced bool
if o.Silenced != nil {
qrSilenced = *o.Silenced
}
qSilenced := swag.FormatBool(qrSilenced)
if qSilenced != "" {
if err := r.SetQueryParam("silenced", qSilenced); err != nil {
return err
}
}
}
if o.Unprocessed != nil {
// query param unprocessed
var qrUnprocessed bool
if o.Unprocessed != nil {
qrUnprocessed = *o.Unprocessed
}
qUnprocessed := swag.FormatBool(qrUnprocessed)
if qUnprocessed != "" {
if err := r.SetQueryParam("unprocessed", qUnprocessed); err != nil {
return err
}
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,133 @@
// Code generated by go-swagger; DO NOT EDIT.
package alert
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/prymitive/karma/internal/mapper/v016/models"
)
// GetAlertsReader is a Reader for the GetAlerts structure.
type GetAlertsReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *GetAlertsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewGetAlertsOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
case 400:
result := NewGetAlertsBadRequest()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
case 500:
result := NewGetAlertsInternalServerError()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
default:
return nil, runtime.NewAPIError("unknown error", response, response.Code())
}
}
// NewGetAlertsOK creates a GetAlertsOK with default headers values
func NewGetAlertsOK() *GetAlertsOK {
return &GetAlertsOK{}
}
/*GetAlertsOK handles this case with default header values.
Get alerts response
*/
type GetAlertsOK struct {
Payload models.GettableAlerts
}
func (o *GetAlertsOK) Error() string {
return fmt.Sprintf("[GET /alerts][%d] getAlertsOK %+v", 200, o.Payload)
}
func (o *GetAlertsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewGetAlertsBadRequest creates a GetAlertsBadRequest with default headers values
func NewGetAlertsBadRequest() *GetAlertsBadRequest {
return &GetAlertsBadRequest{}
}
/*GetAlertsBadRequest handles this case with default header values.
Bad request
*/
type GetAlertsBadRequest struct {
Payload string
}
func (o *GetAlertsBadRequest) Error() string {
return fmt.Sprintf("[GET /alerts][%d] getAlertsBadRequest %+v", 400, o.Payload)
}
func (o *GetAlertsBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewGetAlertsInternalServerError creates a GetAlertsInternalServerError with default headers values
func NewGetAlertsInternalServerError() *GetAlertsInternalServerError {
return &GetAlertsInternalServerError{}
}
/*GetAlertsInternalServerError handles this case with default header values.
Internal server error
*/
type GetAlertsInternalServerError struct {
Payload string
}
func (o *GetAlertsInternalServerError) Error() string {
return fmt.Sprintf("[GET /alerts][%d] getAlertsInternalServerError %+v", 500, o.Payload)
}
func (o *GetAlertsInternalServerError) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,139 @@
// Code generated by go-swagger; DO NOT EDIT.
package alert
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
models "github.com/prymitive/karma/internal/mapper/v016/models"
)
// NewPostAlertsParams creates a new PostAlertsParams object
// with the default values initialized.
func NewPostAlertsParams() *PostAlertsParams {
var ()
return &PostAlertsParams{
timeout: cr.DefaultTimeout,
}
}
// NewPostAlertsParamsWithTimeout creates a new PostAlertsParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewPostAlertsParamsWithTimeout(timeout time.Duration) *PostAlertsParams {
var ()
return &PostAlertsParams{
timeout: timeout,
}
}
// NewPostAlertsParamsWithContext creates a new PostAlertsParams object
// with the default values initialized, and the ability to set a context for a request
func NewPostAlertsParamsWithContext(ctx context.Context) *PostAlertsParams {
var ()
return &PostAlertsParams{
Context: ctx,
}
}
// NewPostAlertsParamsWithHTTPClient creates a new PostAlertsParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewPostAlertsParamsWithHTTPClient(client *http.Client) *PostAlertsParams {
var ()
return &PostAlertsParams{
HTTPClient: client,
}
}
/*PostAlertsParams contains all the parameters to send to the API endpoint
for the post alerts operation typically these are written to a http.Request
*/
type PostAlertsParams struct {
/*Alerts
The alerts to create
*/
Alerts models.PostableAlerts
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the post alerts params
func (o *PostAlertsParams) WithTimeout(timeout time.Duration) *PostAlertsParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the post alerts params
func (o *PostAlertsParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the post alerts params
func (o *PostAlertsParams) WithContext(ctx context.Context) *PostAlertsParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the post alerts params
func (o *PostAlertsParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the post alerts params
func (o *PostAlertsParams) WithHTTPClient(client *http.Client) *PostAlertsParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the post alerts params
func (o *PostAlertsParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithAlerts adds the alerts to the post alerts params
func (o *PostAlertsParams) WithAlerts(alerts models.PostableAlerts) *PostAlertsParams {
o.SetAlerts(alerts)
return o
}
// SetAlerts adds the alerts to the post alerts params
func (o *PostAlertsParams) SetAlerts(alerts models.PostableAlerts) {
o.Alerts = alerts
}
// WriteToRequest writes these params to a swagger request
func (o *PostAlertsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if o.Alerts != nil {
if err := r.SetBodyParam(o.Alerts); err != nil {
return err
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,125 @@
// Code generated by go-swagger; DO NOT EDIT.
package alert
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
)
// PostAlertsReader is a Reader for the PostAlerts structure.
type PostAlertsReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *PostAlertsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewPostAlertsOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
case 400:
result := NewPostAlertsBadRequest()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
case 500:
result := NewPostAlertsInternalServerError()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
default:
return nil, runtime.NewAPIError("unknown error", response, response.Code())
}
}
// NewPostAlertsOK creates a PostAlertsOK with default headers values
func NewPostAlertsOK() *PostAlertsOK {
return &PostAlertsOK{}
}
/*PostAlertsOK handles this case with default header values.
Create alerts response
*/
type PostAlertsOK struct {
}
func (o *PostAlertsOK) Error() string {
return fmt.Sprintf("[POST /alerts][%d] postAlertsOK ", 200)
}
func (o *PostAlertsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
return nil
}
// NewPostAlertsBadRequest creates a PostAlertsBadRequest with default headers values
func NewPostAlertsBadRequest() *PostAlertsBadRequest {
return &PostAlertsBadRequest{}
}
/*PostAlertsBadRequest handles this case with default header values.
Bad request
*/
type PostAlertsBadRequest struct {
Payload string
}
func (o *PostAlertsBadRequest) Error() string {
return fmt.Sprintf("[POST /alerts][%d] postAlertsBadRequest %+v", 400, o.Payload)
}
func (o *PostAlertsBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewPostAlertsInternalServerError creates a PostAlertsInternalServerError with default headers values
func NewPostAlertsInternalServerError() *PostAlertsInternalServerError {
return &PostAlertsInternalServerError{}
}
/*PostAlertsInternalServerError handles this case with default header values.
Internal server error
*/
type PostAlertsInternalServerError struct {
Payload string
}
func (o *PostAlertsInternalServerError) Error() string {
return fmt.Sprintf("[POST /alerts][%d] postAlertsInternalServerError %+v", 500, o.Payload)
}
func (o *PostAlertsInternalServerError) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,58 @@
// Code generated by go-swagger; DO NOT EDIT.
package alertgroup
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
)
// New creates a new alertgroup API client.
func New(transport runtime.ClientTransport, formats strfmt.Registry) *Client {
return &Client{transport: transport, formats: formats}
}
/*
Client for alertgroup API
*/
type Client struct {
transport runtime.ClientTransport
formats strfmt.Registry
}
/*
GetAlertGroups Get a list of alert groups
*/
func (a *Client) GetAlertGroups(params *GetAlertGroupsParams) (*GetAlertGroupsOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewGetAlertGroupsParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "getAlertGroups",
Method: "GET",
PathPattern: "/alerts/groups",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &GetAlertGroupsReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*GetAlertGroupsOK), nil
}
// SetTransport changes the transport on the client
func (a *Client) SetTransport(transport runtime.ClientTransport) {
a.transport = transport
}

View File

@@ -0,0 +1,296 @@
// Code generated by go-swagger; DO NOT EDIT.
package alertgroup
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/swag"
strfmt "github.com/go-openapi/strfmt"
)
// NewGetAlertGroupsParams creates a new GetAlertGroupsParams object
// with the default values initialized.
func NewGetAlertGroupsParams() *GetAlertGroupsParams {
var (
activeDefault = bool(true)
inhibitedDefault = bool(true)
silencedDefault = bool(true)
)
return &GetAlertGroupsParams{
Active: &activeDefault,
Inhibited: &inhibitedDefault,
Silenced: &silencedDefault,
timeout: cr.DefaultTimeout,
}
}
// NewGetAlertGroupsParamsWithTimeout creates a new GetAlertGroupsParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewGetAlertGroupsParamsWithTimeout(timeout time.Duration) *GetAlertGroupsParams {
var (
activeDefault = bool(true)
inhibitedDefault = bool(true)
silencedDefault = bool(true)
)
return &GetAlertGroupsParams{
Active: &activeDefault,
Inhibited: &inhibitedDefault,
Silenced: &silencedDefault,
timeout: timeout,
}
}
// NewGetAlertGroupsParamsWithContext creates a new GetAlertGroupsParams object
// with the default values initialized, and the ability to set a context for a request
func NewGetAlertGroupsParamsWithContext(ctx context.Context) *GetAlertGroupsParams {
var (
activeDefault = bool(true)
inhibitedDefault = bool(true)
silencedDefault = bool(true)
)
return &GetAlertGroupsParams{
Active: &activeDefault,
Inhibited: &inhibitedDefault,
Silenced: &silencedDefault,
Context: ctx,
}
}
// NewGetAlertGroupsParamsWithHTTPClient creates a new GetAlertGroupsParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewGetAlertGroupsParamsWithHTTPClient(client *http.Client) *GetAlertGroupsParams {
var (
activeDefault = bool(true)
inhibitedDefault = bool(true)
silencedDefault = bool(true)
)
return &GetAlertGroupsParams{
Active: &activeDefault,
Inhibited: &inhibitedDefault,
Silenced: &silencedDefault,
HTTPClient: client,
}
}
/*GetAlertGroupsParams contains all the parameters to send to the API endpoint
for the get alert groups operation typically these are written to a http.Request
*/
type GetAlertGroupsParams struct {
/*Active
Show active alerts
*/
Active *bool
/*Filter
A list of matchers to filter alerts by
*/
Filter []string
/*Inhibited
Show inhibited alerts
*/
Inhibited *bool
/*Receiver
A regex matching receivers to filter alerts by
*/
Receiver *string
/*Silenced
Show silenced alerts
*/
Silenced *bool
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the get alert groups params
func (o *GetAlertGroupsParams) WithTimeout(timeout time.Duration) *GetAlertGroupsParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the get alert groups params
func (o *GetAlertGroupsParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the get alert groups params
func (o *GetAlertGroupsParams) WithContext(ctx context.Context) *GetAlertGroupsParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the get alert groups params
func (o *GetAlertGroupsParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the get alert groups params
func (o *GetAlertGroupsParams) WithHTTPClient(client *http.Client) *GetAlertGroupsParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the get alert groups params
func (o *GetAlertGroupsParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithActive adds the active to the get alert groups params
func (o *GetAlertGroupsParams) WithActive(active *bool) *GetAlertGroupsParams {
o.SetActive(active)
return o
}
// SetActive adds the active to the get alert groups params
func (o *GetAlertGroupsParams) SetActive(active *bool) {
o.Active = active
}
// WithFilter adds the filter to the get alert groups params
func (o *GetAlertGroupsParams) WithFilter(filter []string) *GetAlertGroupsParams {
o.SetFilter(filter)
return o
}
// SetFilter adds the filter to the get alert groups params
func (o *GetAlertGroupsParams) SetFilter(filter []string) {
o.Filter = filter
}
// WithInhibited adds the inhibited to the get alert groups params
func (o *GetAlertGroupsParams) WithInhibited(inhibited *bool) *GetAlertGroupsParams {
o.SetInhibited(inhibited)
return o
}
// SetInhibited adds the inhibited to the get alert groups params
func (o *GetAlertGroupsParams) SetInhibited(inhibited *bool) {
o.Inhibited = inhibited
}
// WithReceiver adds the receiver to the get alert groups params
func (o *GetAlertGroupsParams) WithReceiver(receiver *string) *GetAlertGroupsParams {
o.SetReceiver(receiver)
return o
}
// SetReceiver adds the receiver to the get alert groups params
func (o *GetAlertGroupsParams) SetReceiver(receiver *string) {
o.Receiver = receiver
}
// WithSilenced adds the silenced to the get alert groups params
func (o *GetAlertGroupsParams) WithSilenced(silenced *bool) *GetAlertGroupsParams {
o.SetSilenced(silenced)
return o
}
// SetSilenced adds the silenced to the get alert groups params
func (o *GetAlertGroupsParams) SetSilenced(silenced *bool) {
o.Silenced = silenced
}
// WriteToRequest writes these params to a swagger request
func (o *GetAlertGroupsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if o.Active != nil {
// query param active
var qrActive bool
if o.Active != nil {
qrActive = *o.Active
}
qActive := swag.FormatBool(qrActive)
if qActive != "" {
if err := r.SetQueryParam("active", qActive); err != nil {
return err
}
}
}
valuesFilter := o.Filter
joinedFilter := swag.JoinByFormat(valuesFilter, "multi")
// query array param filter
if err := r.SetQueryParam("filter", joinedFilter...); err != nil {
return err
}
if o.Inhibited != nil {
// query param inhibited
var qrInhibited bool
if o.Inhibited != nil {
qrInhibited = *o.Inhibited
}
qInhibited := swag.FormatBool(qrInhibited)
if qInhibited != "" {
if err := r.SetQueryParam("inhibited", qInhibited); err != nil {
return err
}
}
}
if o.Receiver != nil {
// query param receiver
var qrReceiver string
if o.Receiver != nil {
qrReceiver = *o.Receiver
}
qReceiver := qrReceiver
if qReceiver != "" {
if err := r.SetQueryParam("receiver", qReceiver); err != nil {
return err
}
}
}
if o.Silenced != nil {
// query param silenced
var qrSilenced bool
if o.Silenced != nil {
qrSilenced = *o.Silenced
}
qSilenced := swag.FormatBool(qrSilenced)
if qSilenced != "" {
if err := r.SetQueryParam("silenced", qSilenced); err != nil {
return err
}
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,133 @@
// Code generated by go-swagger; DO NOT EDIT.
package alertgroup
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/prymitive/karma/internal/mapper/v016/models"
)
// GetAlertGroupsReader is a Reader for the GetAlertGroups structure.
type GetAlertGroupsReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *GetAlertGroupsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewGetAlertGroupsOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
case 400:
result := NewGetAlertGroupsBadRequest()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
case 500:
result := NewGetAlertGroupsInternalServerError()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
default:
return nil, runtime.NewAPIError("unknown error", response, response.Code())
}
}
// NewGetAlertGroupsOK creates a GetAlertGroupsOK with default headers values
func NewGetAlertGroupsOK() *GetAlertGroupsOK {
return &GetAlertGroupsOK{}
}
/*GetAlertGroupsOK handles this case with default header values.
Get alert groups response
*/
type GetAlertGroupsOK struct {
Payload models.AlertGroups
}
func (o *GetAlertGroupsOK) Error() string {
return fmt.Sprintf("[GET /alerts/groups][%d] getAlertGroupsOK %+v", 200, o.Payload)
}
func (o *GetAlertGroupsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewGetAlertGroupsBadRequest creates a GetAlertGroupsBadRequest with default headers values
func NewGetAlertGroupsBadRequest() *GetAlertGroupsBadRequest {
return &GetAlertGroupsBadRequest{}
}
/*GetAlertGroupsBadRequest handles this case with default header values.
Bad request
*/
type GetAlertGroupsBadRequest struct {
Payload string
}
func (o *GetAlertGroupsBadRequest) Error() string {
return fmt.Sprintf("[GET /alerts/groups][%d] getAlertGroupsBadRequest %+v", 400, o.Payload)
}
func (o *GetAlertGroupsBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewGetAlertGroupsInternalServerError creates a GetAlertGroupsInternalServerError with default headers values
func NewGetAlertGroupsInternalServerError() *GetAlertGroupsInternalServerError {
return &GetAlertGroupsInternalServerError{}
}
/*GetAlertGroupsInternalServerError handles this case with default header values.
Internal server error
*/
type GetAlertGroupsInternalServerError struct {
Payload string
}
func (o *GetAlertGroupsInternalServerError) Error() string {
return fmt.Sprintf("[GET /alerts/groups][%d] getAlertGroupsInternalServerError %+v", 500, o.Payload)
}
func (o *GetAlertGroupsInternalServerError) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,145 @@
// Code generated by go-swagger; DO NOT EDIT.
package client
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
"github.com/prymitive/karma/internal/mapper/v016/client/alert"
"github.com/prymitive/karma/internal/mapper/v016/client/alertgroup"
"github.com/prymitive/karma/internal/mapper/v016/client/general"
"github.com/prymitive/karma/internal/mapper/v016/client/receiver"
"github.com/prymitive/karma/internal/mapper/v016/client/silence"
)
// Default alertmanager HTTP client.
var Default = NewHTTPClient(nil)
const (
// DefaultHost is the default Host
// found in Meta (info) section of spec file
DefaultHost string = "localhost"
// DefaultBasePath is the default BasePath
// found in Meta (info) section of spec file
DefaultBasePath string = "/"
)
// DefaultSchemes are the default schemes found in Meta (info) section of spec file
var DefaultSchemes = []string{"http"}
// NewHTTPClient creates a new alertmanager HTTP client.
func NewHTTPClient(formats strfmt.Registry) *Alertmanager {
return NewHTTPClientWithConfig(formats, nil)
}
// NewHTTPClientWithConfig creates a new alertmanager HTTP client,
// using a customizable transport config.
func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *Alertmanager {
// ensure nullable parameters have default
if cfg == nil {
cfg = DefaultTransportConfig()
}
// create transport and client
transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes)
return New(transport, formats)
}
// New creates a new alertmanager client
func New(transport runtime.ClientTransport, formats strfmt.Registry) *Alertmanager {
// ensure nullable parameters have default
if formats == nil {
formats = strfmt.Default
}
cli := new(Alertmanager)
cli.Transport = transport
cli.Alert = alert.New(transport, formats)
cli.Alertgroup = alertgroup.New(transport, formats)
cli.General = general.New(transport, formats)
cli.Receiver = receiver.New(transport, formats)
cli.Silence = silence.New(transport, formats)
return cli
}
// DefaultTransportConfig creates a TransportConfig with the
// default settings taken from the meta section of the spec file.
func DefaultTransportConfig() *TransportConfig {
return &TransportConfig{
Host: DefaultHost,
BasePath: DefaultBasePath,
Schemes: DefaultSchemes,
}
}
// TransportConfig contains the transport related info,
// found in the meta section of the spec file.
type TransportConfig struct {
Host string
BasePath string
Schemes []string
}
// WithHost overrides the default host,
// provided by the meta section of the spec file.
func (cfg *TransportConfig) WithHost(host string) *TransportConfig {
cfg.Host = host
return cfg
}
// WithBasePath overrides the default basePath,
// provided by the meta section of the spec file.
func (cfg *TransportConfig) WithBasePath(basePath string) *TransportConfig {
cfg.BasePath = basePath
return cfg
}
// WithSchemes overrides the default schemes,
// provided by the meta section of the spec file.
func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig {
cfg.Schemes = schemes
return cfg
}
// Alertmanager is a client for alertmanager
type Alertmanager struct {
Alert *alert.Client
Alertgroup *alertgroup.Client
General *general.Client
Receiver *receiver.Client
Silence *silence.Client
Transport runtime.ClientTransport
}
// SetTransport changes the transport on the client and all its subresources
func (c *Alertmanager) SetTransport(transport runtime.ClientTransport) {
c.Transport = transport
c.Alert.SetTransport(transport)
c.Alertgroup.SetTransport(transport)
c.General.SetTransport(transport)
c.Receiver.SetTransport(transport)
c.Silence.SetTransport(transport)
}

View File

@@ -0,0 +1,58 @@
// Code generated by go-swagger; DO NOT EDIT.
package general
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
)
// New creates a new general API client.
func New(transport runtime.ClientTransport, formats strfmt.Registry) *Client {
return &Client{transport: transport, formats: formats}
}
/*
Client for general API
*/
type Client struct {
transport runtime.ClientTransport
formats strfmt.Registry
}
/*
GetStatus Get current status of an Alertmanager instance and its cluster
*/
func (a *Client) GetStatus(params *GetStatusParams) (*GetStatusOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewGetStatusParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "getStatus",
Method: "GET",
PathPattern: "/status",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &GetStatusReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*GetStatusOK), nil
}
// SetTransport changes the transport on the client
func (a *Client) SetTransport(transport runtime.ClientTransport) {
a.transport = transport
}

View File

@@ -0,0 +1,113 @@
// Code generated by go-swagger; DO NOT EDIT.
package general
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
)
// NewGetStatusParams creates a new GetStatusParams object
// with the default values initialized.
func NewGetStatusParams() *GetStatusParams {
return &GetStatusParams{
timeout: cr.DefaultTimeout,
}
}
// NewGetStatusParamsWithTimeout creates a new GetStatusParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewGetStatusParamsWithTimeout(timeout time.Duration) *GetStatusParams {
return &GetStatusParams{
timeout: timeout,
}
}
// NewGetStatusParamsWithContext creates a new GetStatusParams object
// with the default values initialized, and the ability to set a context for a request
func NewGetStatusParamsWithContext(ctx context.Context) *GetStatusParams {
return &GetStatusParams{
Context: ctx,
}
}
// NewGetStatusParamsWithHTTPClient creates a new GetStatusParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewGetStatusParamsWithHTTPClient(client *http.Client) *GetStatusParams {
return &GetStatusParams{
HTTPClient: client,
}
}
/*GetStatusParams contains all the parameters to send to the API endpoint
for the get status operation typically these are written to a http.Request
*/
type GetStatusParams struct {
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the get status params
func (o *GetStatusParams) WithTimeout(timeout time.Duration) *GetStatusParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the get status params
func (o *GetStatusParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the get status params
func (o *GetStatusParams) WithContext(ctx context.Context) *GetStatusParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the get status params
func (o *GetStatusParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the get status params
func (o *GetStatusParams) WithHTTPClient(client *http.Client) *GetStatusParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the get status params
func (o *GetStatusParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WriteToRequest writes these params to a swagger request
func (o *GetStatusParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,67 @@
// Code generated by go-swagger; DO NOT EDIT.
package general
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/prymitive/karma/internal/mapper/v016/models"
)
// GetStatusReader is a Reader for the GetStatus structure.
type GetStatusReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *GetStatusReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewGetStatusOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
return nil, runtime.NewAPIError("unknown error", response, response.Code())
}
}
// NewGetStatusOK creates a GetStatusOK with default headers values
func NewGetStatusOK() *GetStatusOK {
return &GetStatusOK{}
}
/*GetStatusOK handles this case with default header values.
Get status response
*/
type GetStatusOK struct {
Payload *models.AlertmanagerStatus
}
func (o *GetStatusOK) Error() string {
return fmt.Sprintf("[GET /status][%d] getStatusOK %+v", 200, o.Payload)
}
func (o *GetStatusOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.AlertmanagerStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,113 @@
// Code generated by go-swagger; DO NOT EDIT.
package receiver
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
)
// NewGetReceiversParams creates a new GetReceiversParams object
// with the default values initialized.
func NewGetReceiversParams() *GetReceiversParams {
return &GetReceiversParams{
timeout: cr.DefaultTimeout,
}
}
// NewGetReceiversParamsWithTimeout creates a new GetReceiversParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewGetReceiversParamsWithTimeout(timeout time.Duration) *GetReceiversParams {
return &GetReceiversParams{
timeout: timeout,
}
}
// NewGetReceiversParamsWithContext creates a new GetReceiversParams object
// with the default values initialized, and the ability to set a context for a request
func NewGetReceiversParamsWithContext(ctx context.Context) *GetReceiversParams {
return &GetReceiversParams{
Context: ctx,
}
}
// NewGetReceiversParamsWithHTTPClient creates a new GetReceiversParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewGetReceiversParamsWithHTTPClient(client *http.Client) *GetReceiversParams {
return &GetReceiversParams{
HTTPClient: client,
}
}
/*GetReceiversParams contains all the parameters to send to the API endpoint
for the get receivers operation typically these are written to a http.Request
*/
type GetReceiversParams struct {
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the get receivers params
func (o *GetReceiversParams) WithTimeout(timeout time.Duration) *GetReceiversParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the get receivers params
func (o *GetReceiversParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the get receivers params
func (o *GetReceiversParams) WithContext(ctx context.Context) *GetReceiversParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the get receivers params
func (o *GetReceiversParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the get receivers params
func (o *GetReceiversParams) WithHTTPClient(client *http.Client) *GetReceiversParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the get receivers params
func (o *GetReceiversParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WriteToRequest writes these params to a swagger request
func (o *GetReceiversParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,65 @@
// Code generated by go-swagger; DO NOT EDIT.
package receiver
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/prymitive/karma/internal/mapper/v016/models"
)
// GetReceiversReader is a Reader for the GetReceivers structure.
type GetReceiversReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *GetReceiversReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewGetReceiversOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
return nil, runtime.NewAPIError("unknown error", response, response.Code())
}
}
// NewGetReceiversOK creates a GetReceiversOK with default headers values
func NewGetReceiversOK() *GetReceiversOK {
return &GetReceiversOK{}
}
/*GetReceiversOK handles this case with default header values.
Get receivers response
*/
type GetReceiversOK struct {
Payload []*models.Receiver
}
func (o *GetReceiversOK) Error() string {
return fmt.Sprintf("[GET /receivers][%d] getReceiversOK %+v", 200, o.Payload)
}
func (o *GetReceiversOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,58 @@
// Code generated by go-swagger; DO NOT EDIT.
package receiver
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
)
// New creates a new receiver API client.
func New(transport runtime.ClientTransport, formats strfmt.Registry) *Client {
return &Client{transport: transport, formats: formats}
}
/*
Client for receiver API
*/
type Client struct {
transport runtime.ClientTransport
formats strfmt.Registry
}
/*
GetReceivers Get list of all receivers (name of notification integrations)
*/
func (a *Client) GetReceivers(params *GetReceiversParams) (*GetReceiversOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewGetReceiversParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "getReceivers",
Method: "GET",
PathPattern: "/receivers",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &GetReceiversReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*GetReceiversOK), nil
}
// SetTransport changes the transport on the client
func (a *Client) SetTransport(transport runtime.ClientTransport) {
a.transport = transport
}

View File

@@ -0,0 +1,136 @@
// Code generated by go-swagger; DO NOT EDIT.
package silence
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
)
// NewDeleteSilenceParams creates a new DeleteSilenceParams object
// with the default values initialized.
func NewDeleteSilenceParams() *DeleteSilenceParams {
var ()
return &DeleteSilenceParams{
timeout: cr.DefaultTimeout,
}
}
// NewDeleteSilenceParamsWithTimeout creates a new DeleteSilenceParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewDeleteSilenceParamsWithTimeout(timeout time.Duration) *DeleteSilenceParams {
var ()
return &DeleteSilenceParams{
timeout: timeout,
}
}
// NewDeleteSilenceParamsWithContext creates a new DeleteSilenceParams object
// with the default values initialized, and the ability to set a context for a request
func NewDeleteSilenceParamsWithContext(ctx context.Context) *DeleteSilenceParams {
var ()
return &DeleteSilenceParams{
Context: ctx,
}
}
// NewDeleteSilenceParamsWithHTTPClient creates a new DeleteSilenceParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewDeleteSilenceParamsWithHTTPClient(client *http.Client) *DeleteSilenceParams {
var ()
return &DeleteSilenceParams{
HTTPClient: client,
}
}
/*DeleteSilenceParams contains all the parameters to send to the API endpoint
for the delete silence operation typically these are written to a http.Request
*/
type DeleteSilenceParams struct {
/*SilenceID
ID of the silence to get
*/
SilenceID strfmt.UUID
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the delete silence params
func (o *DeleteSilenceParams) WithTimeout(timeout time.Duration) *DeleteSilenceParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the delete silence params
func (o *DeleteSilenceParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the delete silence params
func (o *DeleteSilenceParams) WithContext(ctx context.Context) *DeleteSilenceParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the delete silence params
func (o *DeleteSilenceParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the delete silence params
func (o *DeleteSilenceParams) WithHTTPClient(client *http.Client) *DeleteSilenceParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the delete silence params
func (o *DeleteSilenceParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithSilenceID adds the silenceID to the delete silence params
func (o *DeleteSilenceParams) WithSilenceID(silenceID strfmt.UUID) *DeleteSilenceParams {
o.SetSilenceID(silenceID)
return o
}
// SetSilenceID adds the silenceId to the delete silence params
func (o *DeleteSilenceParams) SetSilenceID(silenceID strfmt.UUID) {
o.SilenceID = silenceID
}
// WriteToRequest writes these params to a swagger request
func (o *DeleteSilenceParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
// path param silenceID
if err := r.SetPathParam("silenceID", o.SilenceID.String()); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,91 @@
// Code generated by go-swagger; DO NOT EDIT.
package silence
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
)
// DeleteSilenceReader is a Reader for the DeleteSilence structure.
type DeleteSilenceReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *DeleteSilenceReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewDeleteSilenceOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
case 500:
result := NewDeleteSilenceInternalServerError()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
default:
return nil, runtime.NewAPIError("unknown error", response, response.Code())
}
}
// NewDeleteSilenceOK creates a DeleteSilenceOK with default headers values
func NewDeleteSilenceOK() *DeleteSilenceOK {
return &DeleteSilenceOK{}
}
/*DeleteSilenceOK handles this case with default header values.
Delete silence response
*/
type DeleteSilenceOK struct {
}
func (o *DeleteSilenceOK) Error() string {
return fmt.Sprintf("[DELETE /silence/{silenceID}][%d] deleteSilenceOK ", 200)
}
func (o *DeleteSilenceOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
return nil
}
// NewDeleteSilenceInternalServerError creates a DeleteSilenceInternalServerError with default headers values
func NewDeleteSilenceInternalServerError() *DeleteSilenceInternalServerError {
return &DeleteSilenceInternalServerError{}
}
/*DeleteSilenceInternalServerError handles this case with default header values.
Internal server error
*/
type DeleteSilenceInternalServerError struct {
Payload string
}
func (o *DeleteSilenceInternalServerError) Error() string {
return fmt.Sprintf("[DELETE /silence/{silenceID}][%d] deleteSilenceInternalServerError %+v", 500, o.Payload)
}
func (o *DeleteSilenceInternalServerError) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,136 @@
// Code generated by go-swagger; DO NOT EDIT.
package silence
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
)
// NewGetSilenceParams creates a new GetSilenceParams object
// with the default values initialized.
func NewGetSilenceParams() *GetSilenceParams {
var ()
return &GetSilenceParams{
timeout: cr.DefaultTimeout,
}
}
// NewGetSilenceParamsWithTimeout creates a new GetSilenceParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewGetSilenceParamsWithTimeout(timeout time.Duration) *GetSilenceParams {
var ()
return &GetSilenceParams{
timeout: timeout,
}
}
// NewGetSilenceParamsWithContext creates a new GetSilenceParams object
// with the default values initialized, and the ability to set a context for a request
func NewGetSilenceParamsWithContext(ctx context.Context) *GetSilenceParams {
var ()
return &GetSilenceParams{
Context: ctx,
}
}
// NewGetSilenceParamsWithHTTPClient creates a new GetSilenceParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewGetSilenceParamsWithHTTPClient(client *http.Client) *GetSilenceParams {
var ()
return &GetSilenceParams{
HTTPClient: client,
}
}
/*GetSilenceParams contains all the parameters to send to the API endpoint
for the get silence operation typically these are written to a http.Request
*/
type GetSilenceParams struct {
/*SilenceID
ID of the silence to get
*/
SilenceID strfmt.UUID
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the get silence params
func (o *GetSilenceParams) WithTimeout(timeout time.Duration) *GetSilenceParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the get silence params
func (o *GetSilenceParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the get silence params
func (o *GetSilenceParams) WithContext(ctx context.Context) *GetSilenceParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the get silence params
func (o *GetSilenceParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the get silence params
func (o *GetSilenceParams) WithHTTPClient(client *http.Client) *GetSilenceParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the get silence params
func (o *GetSilenceParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithSilenceID adds the silenceID to the get silence params
func (o *GetSilenceParams) WithSilenceID(silenceID strfmt.UUID) *GetSilenceParams {
o.SetSilenceID(silenceID)
return o
}
// SetSilenceID adds the silenceId to the get silence params
func (o *GetSilenceParams) SetSilenceID(silenceID strfmt.UUID) {
o.SilenceID = silenceID
}
// WriteToRequest writes these params to a swagger request
func (o *GetSilenceParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
// path param silenceID
if err := r.SetPathParam("silenceID", o.SilenceID.String()); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,129 @@
// Code generated by go-swagger; DO NOT EDIT.
package silence
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/prymitive/karma/internal/mapper/v016/models"
)
// GetSilenceReader is a Reader for the GetSilence structure.
type GetSilenceReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *GetSilenceReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewGetSilenceOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
case 404:
result := NewGetSilenceNotFound()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
case 500:
result := NewGetSilenceInternalServerError()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
default:
return nil, runtime.NewAPIError("unknown error", response, response.Code())
}
}
// NewGetSilenceOK creates a GetSilenceOK with default headers values
func NewGetSilenceOK() *GetSilenceOK {
return &GetSilenceOK{}
}
/*GetSilenceOK handles this case with default header values.
Get silence response
*/
type GetSilenceOK struct {
Payload *models.GettableSilence
}
func (o *GetSilenceOK) Error() string {
return fmt.Sprintf("[GET /silence/{silenceID}][%d] getSilenceOK %+v", 200, o.Payload)
}
func (o *GetSilenceOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.GettableSilence)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewGetSilenceNotFound creates a GetSilenceNotFound with default headers values
func NewGetSilenceNotFound() *GetSilenceNotFound {
return &GetSilenceNotFound{}
}
/*GetSilenceNotFound handles this case with default header values.
A silence with the specified ID was not found
*/
type GetSilenceNotFound struct {
}
func (o *GetSilenceNotFound) Error() string {
return fmt.Sprintf("[GET /silence/{silenceID}][%d] getSilenceNotFound ", 404)
}
func (o *GetSilenceNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
return nil
}
// NewGetSilenceInternalServerError creates a GetSilenceInternalServerError with default headers values
func NewGetSilenceInternalServerError() *GetSilenceInternalServerError {
return &GetSilenceInternalServerError{}
}
/*GetSilenceInternalServerError handles this case with default header values.
Internal server error
*/
type GetSilenceInternalServerError struct {
Payload string
}
func (o *GetSilenceInternalServerError) Error() string {
return fmt.Sprintf("[GET /silence/{silenceID}][%d] getSilenceInternalServerError %+v", 500, o.Payload)
}
func (o *GetSilenceInternalServerError) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,140 @@
// Code generated by go-swagger; DO NOT EDIT.
package silence
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/swag"
strfmt "github.com/go-openapi/strfmt"
)
// NewGetSilencesParams creates a new GetSilencesParams object
// with the default values initialized.
func NewGetSilencesParams() *GetSilencesParams {
var ()
return &GetSilencesParams{
timeout: cr.DefaultTimeout,
}
}
// NewGetSilencesParamsWithTimeout creates a new GetSilencesParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewGetSilencesParamsWithTimeout(timeout time.Duration) *GetSilencesParams {
var ()
return &GetSilencesParams{
timeout: timeout,
}
}
// NewGetSilencesParamsWithContext creates a new GetSilencesParams object
// with the default values initialized, and the ability to set a context for a request
func NewGetSilencesParamsWithContext(ctx context.Context) *GetSilencesParams {
var ()
return &GetSilencesParams{
Context: ctx,
}
}
// NewGetSilencesParamsWithHTTPClient creates a new GetSilencesParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewGetSilencesParamsWithHTTPClient(client *http.Client) *GetSilencesParams {
var ()
return &GetSilencesParams{
HTTPClient: client,
}
}
/*GetSilencesParams contains all the parameters to send to the API endpoint
for the get silences operation typically these are written to a http.Request
*/
type GetSilencesParams struct {
/*Filter
A list of matchers to filter silences by
*/
Filter []string
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the get silences params
func (o *GetSilencesParams) WithTimeout(timeout time.Duration) *GetSilencesParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the get silences params
func (o *GetSilencesParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the get silences params
func (o *GetSilencesParams) WithContext(ctx context.Context) *GetSilencesParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the get silences params
func (o *GetSilencesParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the get silences params
func (o *GetSilencesParams) WithHTTPClient(client *http.Client) *GetSilencesParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the get silences params
func (o *GetSilencesParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithFilter adds the filter to the get silences params
func (o *GetSilencesParams) WithFilter(filter []string) *GetSilencesParams {
o.SetFilter(filter)
return o
}
// SetFilter adds the filter to the get silences params
func (o *GetSilencesParams) SetFilter(filter []string) {
o.Filter = filter
}
// WriteToRequest writes these params to a swagger request
func (o *GetSilencesParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
valuesFilter := o.Filter
joinedFilter := swag.JoinByFormat(valuesFilter, "multi")
// query array param filter
if err := r.SetQueryParam("filter", joinedFilter...); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,99 @@
// Code generated by go-swagger; DO NOT EDIT.
package silence
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/prymitive/karma/internal/mapper/v016/models"
)
// GetSilencesReader is a Reader for the GetSilences structure.
type GetSilencesReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *GetSilencesReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewGetSilencesOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
case 500:
result := NewGetSilencesInternalServerError()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
default:
return nil, runtime.NewAPIError("unknown error", response, response.Code())
}
}
// NewGetSilencesOK creates a GetSilencesOK with default headers values
func NewGetSilencesOK() *GetSilencesOK {
return &GetSilencesOK{}
}
/*GetSilencesOK handles this case with default header values.
Get silences response
*/
type GetSilencesOK struct {
Payload models.GettableSilences
}
func (o *GetSilencesOK) Error() string {
return fmt.Sprintf("[GET /silences][%d] getSilencesOK %+v", 200, o.Payload)
}
func (o *GetSilencesOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewGetSilencesInternalServerError creates a GetSilencesInternalServerError with default headers values
func NewGetSilencesInternalServerError() *GetSilencesInternalServerError {
return &GetSilencesInternalServerError{}
}
/*GetSilencesInternalServerError handles this case with default header values.
Internal server error
*/
type GetSilencesInternalServerError struct {
Payload string
}
func (o *GetSilencesInternalServerError) Error() string {
return fmt.Sprintf("[GET /silences][%d] getSilencesInternalServerError %+v", 500, o.Payload)
}
func (o *GetSilencesInternalServerError) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,139 @@
// Code generated by go-swagger; DO NOT EDIT.
package silence
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
models "github.com/prymitive/karma/internal/mapper/v016/models"
)
// NewPostSilencesParams creates a new PostSilencesParams object
// with the default values initialized.
func NewPostSilencesParams() *PostSilencesParams {
var ()
return &PostSilencesParams{
timeout: cr.DefaultTimeout,
}
}
// NewPostSilencesParamsWithTimeout creates a new PostSilencesParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewPostSilencesParamsWithTimeout(timeout time.Duration) *PostSilencesParams {
var ()
return &PostSilencesParams{
timeout: timeout,
}
}
// NewPostSilencesParamsWithContext creates a new PostSilencesParams object
// with the default values initialized, and the ability to set a context for a request
func NewPostSilencesParamsWithContext(ctx context.Context) *PostSilencesParams {
var ()
return &PostSilencesParams{
Context: ctx,
}
}
// NewPostSilencesParamsWithHTTPClient creates a new PostSilencesParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewPostSilencesParamsWithHTTPClient(client *http.Client) *PostSilencesParams {
var ()
return &PostSilencesParams{
HTTPClient: client,
}
}
/*PostSilencesParams contains all the parameters to send to the API endpoint
for the post silences operation typically these are written to a http.Request
*/
type PostSilencesParams struct {
/*Silence
The silence to create
*/
Silence *models.PostableSilence
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the post silences params
func (o *PostSilencesParams) WithTimeout(timeout time.Duration) *PostSilencesParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the post silences params
func (o *PostSilencesParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the post silences params
func (o *PostSilencesParams) WithContext(ctx context.Context) *PostSilencesParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the post silences params
func (o *PostSilencesParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the post silences params
func (o *PostSilencesParams) WithHTTPClient(client *http.Client) *PostSilencesParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the post silences params
func (o *PostSilencesParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithSilence adds the silence to the post silences params
func (o *PostSilencesParams) WithSilence(silence *models.PostableSilence) *PostSilencesParams {
o.SetSilence(silence)
return o
}
// SetSilence adds the silence to the post silences params
func (o *PostSilencesParams) SetSilence(silence *models.PostableSilence) {
o.Silence = silence
}
// WriteToRequest writes these params to a swagger request
func (o *PostSilencesParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if o.Silence != nil {
if err := r.SetBodyParam(o.Silence); err != nil {
return err
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,166 @@
// Code generated by go-swagger; DO NOT EDIT.
package silence
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/swag"
strfmt "github.com/go-openapi/strfmt"
)
// PostSilencesReader is a Reader for the PostSilences structure.
type PostSilencesReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *PostSilencesReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewPostSilencesOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
case 400:
result := NewPostSilencesBadRequest()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
case 404:
result := NewPostSilencesNotFound()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
default:
return nil, runtime.NewAPIError("unknown error", response, response.Code())
}
}
// NewPostSilencesOK creates a PostSilencesOK with default headers values
func NewPostSilencesOK() *PostSilencesOK {
return &PostSilencesOK{}
}
/*PostSilencesOK handles this case with default header values.
Create / update silence response
*/
type PostSilencesOK struct {
Payload *PostSilencesOKBody
}
func (o *PostSilencesOK) Error() string {
return fmt.Sprintf("[POST /silences][%d] postSilencesOK %+v", 200, o.Payload)
}
func (o *PostSilencesOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(PostSilencesOKBody)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewPostSilencesBadRequest creates a PostSilencesBadRequest with default headers values
func NewPostSilencesBadRequest() *PostSilencesBadRequest {
return &PostSilencesBadRequest{}
}
/*PostSilencesBadRequest handles this case with default header values.
Bad request
*/
type PostSilencesBadRequest struct {
Payload string
}
func (o *PostSilencesBadRequest) Error() string {
return fmt.Sprintf("[POST /silences][%d] postSilencesBadRequest %+v", 400, o.Payload)
}
func (o *PostSilencesBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewPostSilencesNotFound creates a PostSilencesNotFound with default headers values
func NewPostSilencesNotFound() *PostSilencesNotFound {
return &PostSilencesNotFound{}
}
/*PostSilencesNotFound handles this case with default header values.
A silence with the specified ID was not found
*/
type PostSilencesNotFound struct {
Payload string
}
func (o *PostSilencesNotFound) Error() string {
return fmt.Sprintf("[POST /silences][%d] postSilencesNotFound %+v", 404, o.Payload)
}
func (o *PostSilencesNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
/*PostSilencesOKBody post silences o k body
swagger:model PostSilencesOKBody
*/
type PostSilencesOKBody struct {
// silence ID
SilenceID string `json:"silenceID,omitempty"`
}
// Validate validates this post silences o k body
func (o *PostSilencesOKBody) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (o *PostSilencesOKBody) MarshalBinary() ([]byte, error) {
if o == nil {
return nil, nil
}
return swag.WriteJSON(o)
}
// UnmarshalBinary interface implementation
func (o *PostSilencesOKBody) UnmarshalBinary(b []byte) error {
var res PostSilencesOKBody
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*o = res
return nil
}

View File

@@ -0,0 +1,142 @@
// Code generated by go-swagger; DO NOT EDIT.
package silence
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
)
// New creates a new silence API client.
func New(transport runtime.ClientTransport, formats strfmt.Registry) *Client {
return &Client{transport: transport, formats: formats}
}
/*
Client for silence API
*/
type Client struct {
transport runtime.ClientTransport
formats strfmt.Registry
}
/*
DeleteSilence Delete a silence by its ID
*/
func (a *Client) DeleteSilence(params *DeleteSilenceParams) (*DeleteSilenceOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewDeleteSilenceParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "deleteSilence",
Method: "DELETE",
PathPattern: "/silence/{silenceID}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &DeleteSilenceReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*DeleteSilenceOK), nil
}
/*
GetSilence Get a silence by its ID
*/
func (a *Client) GetSilence(params *GetSilenceParams) (*GetSilenceOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewGetSilenceParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "getSilence",
Method: "GET",
PathPattern: "/silence/{silenceID}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &GetSilenceReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*GetSilenceOK), nil
}
/*
GetSilences Get a list of silences
*/
func (a *Client) GetSilences(params *GetSilencesParams) (*GetSilencesOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewGetSilencesParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "getSilences",
Method: "GET",
PathPattern: "/silences",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &GetSilencesReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*GetSilencesOK), nil
}
/*
PostSilences Post a new silence or update an existing one
*/
func (a *Client) PostSilences(params *PostSilencesParams) (*PostSilencesOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewPostSilencesParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "postSilences",
Method: "POST",
PathPattern: "/silences",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &PostSilencesReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*PostSilencesOK), nil
}
// SetTransport changes the transport on the client
func (a *Client) SetTransport(transport runtime.ClientTransport) {
a.transport = transport
}

View File

@@ -0,0 +1,88 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// Alert alert
// swagger:model alert
type Alert struct {
// generator URL
// Format: uri
GeneratorURL strfmt.URI `json:"generatorURL,omitempty"`
// labels
// Required: true
Labels LabelSet `json:"labels"`
}
// Validate validates this alert
func (m *Alert) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateGeneratorURL(formats); err != nil {
res = append(res, err)
}
if err := m.validateLabels(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *Alert) validateGeneratorURL(formats strfmt.Registry) error {
if swag.IsZero(m.GeneratorURL) { // not required
return nil
}
if err := validate.FormatOf("generatorURL", "body", "uri", m.GeneratorURL.String(), formats); err != nil {
return err
}
return nil
}
func (m *Alert) validateLabels(formats strfmt.Registry) error {
if err := m.Labels.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("labels")
}
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *Alert) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *Alert) UnmarshalBinary(b []byte) error {
var res Alert
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,128 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// AlertGroup alert group
// swagger:model alertGroup
type AlertGroup struct {
// alerts
Alerts []*GettableAlert `json:"alerts"`
// labels
Labels LabelSet `json:"labels,omitempty"`
// receiver
Receiver *Receiver `json:"receiver,omitempty"`
}
// Validate validates this alert group
func (m *AlertGroup) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateAlerts(formats); err != nil {
res = append(res, err)
}
if err := m.validateLabels(formats); err != nil {
res = append(res, err)
}
if err := m.validateReceiver(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *AlertGroup) validateAlerts(formats strfmt.Registry) error {
if swag.IsZero(m.Alerts) { // not required
return nil
}
for i := 0; i < len(m.Alerts); i++ {
if swag.IsZero(m.Alerts[i]) { // not required
continue
}
if m.Alerts[i] != nil {
if err := m.Alerts[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("alerts" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *AlertGroup) validateLabels(formats strfmt.Registry) error {
if swag.IsZero(m.Labels) { // not required
return nil
}
if err := m.Labels.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("labels")
}
return err
}
return nil
}
func (m *AlertGroup) validateReceiver(formats strfmt.Registry) error {
if swag.IsZero(m.Receiver) { // not required
return nil
}
if m.Receiver != nil {
if err := m.Receiver.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("receiver")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *AlertGroup) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *AlertGroup) UnmarshalBinary(b []byte) error {
var res AlertGroup
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,45 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// AlertGroups alert groups
// swagger:model alertGroups
type AlertGroups []*AlertGroup
// Validate validates this alert groups
func (m AlertGroups) Validate(formats strfmt.Registry) error {
var res []error
for i := 0; i < len(m); i++ {
if swag.IsZero(m[i]) { // not required
continue
}
if m[i] != nil {
if err := m[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName(strconv.Itoa(i))
}
return err
}
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,138 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// AlertStatus alert status
// swagger:model alertStatus
type AlertStatus struct {
// inhibited by
// Required: true
InhibitedBy []string `json:"inhibitedBy"`
// silenced by
// Required: true
SilencedBy []string `json:"silencedBy"`
// state
// Required: true
// Enum: [unprocessed active suppressed]
State *string `json:"state"`
}
// Validate validates this alert status
func (m *AlertStatus) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateInhibitedBy(formats); err != nil {
res = append(res, err)
}
if err := m.validateSilencedBy(formats); err != nil {
res = append(res, err)
}
if err := m.validateState(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *AlertStatus) validateInhibitedBy(formats strfmt.Registry) error {
if err := validate.Required("inhibitedBy", "body", m.InhibitedBy); err != nil {
return err
}
return nil
}
func (m *AlertStatus) validateSilencedBy(formats strfmt.Registry) error {
if err := validate.Required("silencedBy", "body", m.SilencedBy); err != nil {
return err
}
return nil
}
var alertStatusTypeStatePropEnum []interface{}
func init() {
var res []string
if err := json.Unmarshal([]byte(`["unprocessed","active","suppressed"]`), &res); err != nil {
panic(err)
}
for _, v := range res {
alertStatusTypeStatePropEnum = append(alertStatusTypeStatePropEnum, v)
}
}
const (
// AlertStatusStateUnprocessed captures enum value "unprocessed"
AlertStatusStateUnprocessed string = "unprocessed"
// AlertStatusStateActive captures enum value "active"
AlertStatusStateActive string = "active"
// AlertStatusStateSuppressed captures enum value "suppressed"
AlertStatusStateSuppressed string = "suppressed"
)
// prop value enum
func (m *AlertStatus) validateStateEnum(path, location string, value string) error {
if err := validate.Enum(path, location, value, alertStatusTypeStatePropEnum); err != nil {
return err
}
return nil
}
func (m *AlertStatus) validateState(formats strfmt.Registry) error {
if err := validate.Required("state", "body", m.State); err != nil {
return err
}
// value enum
if err := m.validateStateEnum("state", "body", *m.State); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *AlertStatus) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *AlertStatus) UnmarshalBinary(b []byte) error {
var res AlertStatus
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,64 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// AlertmanagerConfig alertmanager config
// swagger:model alertmanagerConfig
type AlertmanagerConfig struct {
// original
// Required: true
Original *string `json:"original"`
}
// Validate validates this alertmanager config
func (m *AlertmanagerConfig) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateOriginal(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *AlertmanagerConfig) validateOriginal(formats strfmt.Registry) error {
if err := validate.Required("original", "body", m.Original); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *AlertmanagerConfig) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *AlertmanagerConfig) UnmarshalBinary(b []byte) error {
var res AlertmanagerConfig
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,147 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// AlertmanagerStatus alertmanager status
// swagger:model alertmanagerStatus
type AlertmanagerStatus struct {
// cluster
// Required: true
Cluster *ClusterStatus `json:"cluster"`
// config
// Required: true
Config *AlertmanagerConfig `json:"config"`
// uptime
// Required: true
// Format: date-time
Uptime *strfmt.DateTime `json:"uptime"`
// version info
// Required: true
VersionInfo *VersionInfo `json:"versionInfo"`
}
// Validate validates this alertmanager status
func (m *AlertmanagerStatus) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateCluster(formats); err != nil {
res = append(res, err)
}
if err := m.validateConfig(formats); err != nil {
res = append(res, err)
}
if err := m.validateUptime(formats); err != nil {
res = append(res, err)
}
if err := m.validateVersionInfo(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *AlertmanagerStatus) validateCluster(formats strfmt.Registry) error {
if err := validate.Required("cluster", "body", m.Cluster); err != nil {
return err
}
if m.Cluster != nil {
if err := m.Cluster.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("cluster")
}
return err
}
}
return nil
}
func (m *AlertmanagerStatus) validateConfig(formats strfmt.Registry) error {
if err := validate.Required("config", "body", m.Config); err != nil {
return err
}
if m.Config != nil {
if err := m.Config.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("config")
}
return err
}
}
return nil
}
func (m *AlertmanagerStatus) validateUptime(formats strfmt.Registry) error {
if err := validate.Required("uptime", "body", m.Uptime); err != nil {
return err
}
if err := validate.FormatOf("uptime", "body", "date-time", m.Uptime.String(), formats); err != nil {
return err
}
return nil
}
func (m *AlertmanagerStatus) validateVersionInfo(formats strfmt.Registry) error {
if err := validate.Required("versionInfo", "body", m.VersionInfo); err != nil {
return err
}
if m.VersionInfo != nil {
if err := m.VersionInfo.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("versionInfo")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *AlertmanagerStatus) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *AlertmanagerStatus) UnmarshalBinary(b []byte) error {
var res AlertmanagerStatus
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,141 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// ClusterStatus cluster status
// swagger:model clusterStatus
type ClusterStatus struct {
// name
Name string `json:"name,omitempty"`
// peers
// Minimum: 0
Peers []*PeerStatus `json:"peers"`
// status
// Required: true
// Enum: [ready settling disabled]
Status *string `json:"status"`
}
// Validate validates this cluster status
func (m *ClusterStatus) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validatePeers(formats); err != nil {
res = append(res, err)
}
if err := m.validateStatus(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *ClusterStatus) validatePeers(formats strfmt.Registry) error {
if swag.IsZero(m.Peers) { // not required
return nil
}
for i := 0; i < len(m.Peers); i++ {
if swag.IsZero(m.Peers[i]) { // not required
continue
}
if m.Peers[i] != nil {
if err := m.Peers[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("peers" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
var clusterStatusTypeStatusPropEnum []interface{}
func init() {
var res []string
if err := json.Unmarshal([]byte(`["ready","settling","disabled"]`), &res); err != nil {
panic(err)
}
for _, v := range res {
clusterStatusTypeStatusPropEnum = append(clusterStatusTypeStatusPropEnum, v)
}
}
const (
// ClusterStatusStatusReady captures enum value "ready"
ClusterStatusStatusReady string = "ready"
// ClusterStatusStatusSettling captures enum value "settling"
ClusterStatusStatusSettling string = "settling"
// ClusterStatusStatusDisabled captures enum value "disabled"
ClusterStatusStatusDisabled string = "disabled"
)
// prop value enum
func (m *ClusterStatus) validateStatusEnum(path, location string, value string) error {
if err := validate.Enum(path, location, value, clusterStatusTypeStatusPropEnum); err != nil {
return err
}
return nil
}
func (m *ClusterStatus) validateStatus(formats strfmt.Registry) error {
if err := validate.Required("status", "body", m.Status); err != nil {
return err
}
// value enum
if err := m.validateStatusEnum("status", "body", *m.Status); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *ClusterStatus) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *ClusterStatus) UnmarshalBinary(b []byte) error {
var res ClusterStatus
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,313 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// GettableAlert gettable alert
// swagger:model gettableAlert
type GettableAlert struct {
// annotations
// Required: true
Annotations LabelSet `json:"annotations"`
// ends at
// Required: true
// Format: date-time
EndsAt *strfmt.DateTime `json:"endsAt"`
// fingerprint
// Required: true
Fingerprint *string `json:"fingerprint"`
// receivers
// Required: true
Receivers []*Receiver `json:"receivers"`
// starts at
// Required: true
// Format: date-time
StartsAt *strfmt.DateTime `json:"startsAt"`
// status
// Required: true
Status *AlertStatus `json:"status"`
// updated at
// Required: true
// Format: date-time
UpdatedAt *strfmt.DateTime `json:"updatedAt"`
Alert
}
// UnmarshalJSON unmarshals this object from a JSON structure
func (m *GettableAlert) UnmarshalJSON(raw []byte) error {
// AO0
var dataAO0 struct {
Annotations LabelSet `json:"annotations"`
EndsAt *strfmt.DateTime `json:"endsAt"`
Fingerprint *string `json:"fingerprint"`
Receivers []*Receiver `json:"receivers"`
StartsAt *strfmt.DateTime `json:"startsAt"`
Status *AlertStatus `json:"status"`
UpdatedAt *strfmt.DateTime `json:"updatedAt"`
}
if err := swag.ReadJSON(raw, &dataAO0); err != nil {
return err
}
m.Annotations = dataAO0.Annotations
m.EndsAt = dataAO0.EndsAt
m.Fingerprint = dataAO0.Fingerprint
m.Receivers = dataAO0.Receivers
m.StartsAt = dataAO0.StartsAt
m.Status = dataAO0.Status
m.UpdatedAt = dataAO0.UpdatedAt
// AO1
var aO1 Alert
if err := swag.ReadJSON(raw, &aO1); err != nil {
return err
}
m.Alert = aO1
return nil
}
// MarshalJSON marshals this object to a JSON structure
func (m GettableAlert) MarshalJSON() ([]byte, error) {
_parts := make([][]byte, 0, 2)
var dataAO0 struct {
Annotations LabelSet `json:"annotations"`
EndsAt *strfmt.DateTime `json:"endsAt"`
Fingerprint *string `json:"fingerprint"`
Receivers []*Receiver `json:"receivers"`
StartsAt *strfmt.DateTime `json:"startsAt"`
Status *AlertStatus `json:"status"`
UpdatedAt *strfmt.DateTime `json:"updatedAt"`
}
dataAO0.Annotations = m.Annotations
dataAO0.EndsAt = m.EndsAt
dataAO0.Fingerprint = m.Fingerprint
dataAO0.Receivers = m.Receivers
dataAO0.StartsAt = m.StartsAt
dataAO0.Status = m.Status
dataAO0.UpdatedAt = m.UpdatedAt
jsonDataAO0, errAO0 := swag.WriteJSON(dataAO0)
if errAO0 != nil {
return nil, errAO0
}
_parts = append(_parts, jsonDataAO0)
aO1, err := swag.WriteJSON(m.Alert)
if err != nil {
return nil, err
}
_parts = append(_parts, aO1)
return swag.ConcatJSON(_parts...), nil
}
// Validate validates this gettable alert
func (m *GettableAlert) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateAnnotations(formats); err != nil {
res = append(res, err)
}
if err := m.validateEndsAt(formats); err != nil {
res = append(res, err)
}
if err := m.validateFingerprint(formats); err != nil {
res = append(res, err)
}
if err := m.validateReceivers(formats); err != nil {
res = append(res, err)
}
if err := m.validateStartsAt(formats); err != nil {
res = append(res, err)
}
if err := m.validateStatus(formats); err != nil {
res = append(res, err)
}
if err := m.validateUpdatedAt(formats); err != nil {
res = append(res, err)
}
// validation for a type composition with Alert
if err := m.Alert.Validate(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *GettableAlert) validateAnnotations(formats strfmt.Registry) error {
if err := m.Annotations.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("annotations")
}
return err
}
return nil
}
func (m *GettableAlert) validateEndsAt(formats strfmt.Registry) error {
if err := validate.Required("endsAt", "body", m.EndsAt); err != nil {
return err
}
if err := validate.FormatOf("endsAt", "body", "date-time", m.EndsAt.String(), formats); err != nil {
return err
}
return nil
}
func (m *GettableAlert) validateFingerprint(formats strfmt.Registry) error {
if err := validate.Required("fingerprint", "body", m.Fingerprint); err != nil {
return err
}
return nil
}
func (m *GettableAlert) validateReceivers(formats strfmt.Registry) error {
if err := validate.Required("receivers", "body", m.Receivers); err != nil {
return err
}
for i := 0; i < len(m.Receivers); i++ {
if swag.IsZero(m.Receivers[i]) { // not required
continue
}
if m.Receivers[i] != nil {
if err := m.Receivers[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("receivers" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *GettableAlert) validateStartsAt(formats strfmt.Registry) error {
if err := validate.Required("startsAt", "body", m.StartsAt); err != nil {
return err
}
if err := validate.FormatOf("startsAt", "body", "date-time", m.StartsAt.String(), formats); err != nil {
return err
}
return nil
}
func (m *GettableAlert) validateStatus(formats strfmt.Registry) error {
if err := validate.Required("status", "body", m.Status); err != nil {
return err
}
if m.Status != nil {
if err := m.Status.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("status")
}
return err
}
}
return nil
}
func (m *GettableAlert) validateUpdatedAt(formats strfmt.Registry) error {
if err := validate.Required("updatedAt", "body", m.UpdatedAt); err != nil {
return err
}
if err := validate.FormatOf("updatedAt", "body", "date-time", m.UpdatedAt.String(), formats); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *GettableAlert) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *GettableAlert) UnmarshalBinary(b []byte) error {
var res GettableAlert
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,45 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// GettableAlerts gettable alerts
// swagger:model gettableAlerts
type GettableAlerts []*GettableAlert
// Validate validates this gettable alerts
func (m GettableAlerts) Validate(formats strfmt.Registry) error {
var res []error
for i := 0; i < len(m); i++ {
if swag.IsZero(m[i]) { // not required
continue
}
if m[i] != nil {
if err := m[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName(strconv.Itoa(i))
}
return err
}
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,182 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// GettableSilence gettable silence
// swagger:model gettableSilence
type GettableSilence struct {
// id
// Required: true
ID *string `json:"id"`
// status
// Required: true
Status *SilenceStatus `json:"status"`
// updated at
// Required: true
// Format: date-time
UpdatedAt *strfmt.DateTime `json:"updatedAt"`
Silence
}
// UnmarshalJSON unmarshals this object from a JSON structure
func (m *GettableSilence) UnmarshalJSON(raw []byte) error {
// AO0
var dataAO0 struct {
ID *string `json:"id"`
Status *SilenceStatus `json:"status"`
UpdatedAt *strfmt.DateTime `json:"updatedAt"`
}
if err := swag.ReadJSON(raw, &dataAO0); err != nil {
return err
}
m.ID = dataAO0.ID
m.Status = dataAO0.Status
m.UpdatedAt = dataAO0.UpdatedAt
// AO1
var aO1 Silence
if err := swag.ReadJSON(raw, &aO1); err != nil {
return err
}
m.Silence = aO1
return nil
}
// MarshalJSON marshals this object to a JSON structure
func (m GettableSilence) MarshalJSON() ([]byte, error) {
_parts := make([][]byte, 0, 2)
var dataAO0 struct {
ID *string `json:"id"`
Status *SilenceStatus `json:"status"`
UpdatedAt *strfmt.DateTime `json:"updatedAt"`
}
dataAO0.ID = m.ID
dataAO0.Status = m.Status
dataAO0.UpdatedAt = m.UpdatedAt
jsonDataAO0, errAO0 := swag.WriteJSON(dataAO0)
if errAO0 != nil {
return nil, errAO0
}
_parts = append(_parts, jsonDataAO0)
aO1, err := swag.WriteJSON(m.Silence)
if err != nil {
return nil, err
}
_parts = append(_parts, aO1)
return swag.ConcatJSON(_parts...), nil
}
// Validate validates this gettable silence
func (m *GettableSilence) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateID(formats); err != nil {
res = append(res, err)
}
if err := m.validateStatus(formats); err != nil {
res = append(res, err)
}
if err := m.validateUpdatedAt(formats); err != nil {
res = append(res, err)
}
// validation for a type composition with Silence
if err := m.Silence.Validate(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *GettableSilence) validateID(formats strfmt.Registry) error {
if err := validate.Required("id", "body", m.ID); err != nil {
return err
}
return nil
}
func (m *GettableSilence) validateStatus(formats strfmt.Registry) error {
if err := validate.Required("status", "body", m.Status); err != nil {
return err
}
if m.Status != nil {
if err := m.Status.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("status")
}
return err
}
}
return nil
}
func (m *GettableSilence) validateUpdatedAt(formats strfmt.Registry) error {
if err := validate.Required("updatedAt", "body", m.UpdatedAt); err != nil {
return err
}
if err := validate.FormatOf("updatedAt", "body", "date-time", m.UpdatedAt.String(), formats); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *GettableSilence) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *GettableSilence) UnmarshalBinary(b []byte) error {
var res GettableSilence
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,45 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// GettableSilences gettable silences
// swagger:model gettableSilences
type GettableSilences []*GettableSilence
// Validate validates this gettable silences
func (m GettableSilences) Validate(formats strfmt.Registry) error {
var res []error
for i := 0; i < len(m); i++ {
if swag.IsZero(m[i]) { // not required
continue
}
if m[i] != nil {
if err := m[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName(strconv.Itoa(i))
}
return err
}
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,19 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
)
// LabelSet label set
// swagger:model labelSet
type LabelSet map[string]string
// Validate validates this label set
func (m LabelSet) Validate(formats strfmt.Registry) error {
return nil
}

View File

@@ -0,0 +1,98 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// Matcher matcher
// swagger:model matcher
type Matcher struct {
// is regex
// Required: true
IsRegex *bool `json:"isRegex"`
// name
// Required: true
Name *string `json:"name"`
// value
// Required: true
Value *string `json:"value"`
}
// Validate validates this matcher
func (m *Matcher) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateIsRegex(formats); err != nil {
res = append(res, err)
}
if err := m.validateName(formats); err != nil {
res = append(res, err)
}
if err := m.validateValue(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *Matcher) validateIsRegex(formats strfmt.Registry) error {
if err := validate.Required("isRegex", "body", m.IsRegex); err != nil {
return err
}
return nil
}
func (m *Matcher) validateName(formats strfmt.Registry) error {
if err := validate.Required("name", "body", m.Name); err != nil {
return err
}
return nil
}
func (m *Matcher) validateValue(formats strfmt.Registry) error {
if err := validate.Required("value", "body", m.Value); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *Matcher) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *Matcher) UnmarshalBinary(b []byte) error {
var res Matcher
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,52 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// Matchers matchers
// swagger:model matchers
type Matchers []*Matcher
// Validate validates this matchers
func (m Matchers) Validate(formats strfmt.Registry) error {
var res []error
iMatchersSize := int64(len(m))
if err := validate.MinItems("", "body", iMatchersSize, 1); err != nil {
return err
}
for i := 0; i < len(m); i++ {
if swag.IsZero(m[i]) { // not required
continue
}
if m[i] != nil {
if err := m[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName(strconv.Itoa(i))
}
return err
}
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,81 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// PeerStatus peer status
// swagger:model peerStatus
type PeerStatus struct {
// address
// Required: true
Address *string `json:"address"`
// name
// Required: true
Name *string `json:"name"`
}
// Validate validates this peer status
func (m *PeerStatus) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateAddress(formats); err != nil {
res = append(res, err)
}
if err := m.validateName(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *PeerStatus) validateAddress(formats strfmt.Registry) error {
if err := validate.Required("address", "body", m.Address); err != nil {
return err
}
return nil
}
func (m *PeerStatus) validateName(formats strfmt.Registry) error {
if err := validate.Required("name", "body", m.Name); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *PeerStatus) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *PeerStatus) UnmarshalBinary(b []byte) error {
var res PeerStatus
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,182 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// PostableAlert postable alert
// swagger:model postableAlert
type PostableAlert struct {
// annotations
Annotations LabelSet `json:"annotations,omitempty"`
// ends at
// Format: date-time
EndsAt strfmt.DateTime `json:"endsAt,omitempty"`
// starts at
// Format: date-time
StartsAt strfmt.DateTime `json:"startsAt,omitempty"`
Alert
}
// UnmarshalJSON unmarshals this object from a JSON structure
func (m *PostableAlert) UnmarshalJSON(raw []byte) error {
// AO0
var dataAO0 struct {
Annotations LabelSet `json:"annotations,omitempty"`
EndsAt strfmt.DateTime `json:"endsAt,omitempty"`
StartsAt strfmt.DateTime `json:"startsAt,omitempty"`
}
if err := swag.ReadJSON(raw, &dataAO0); err != nil {
return err
}
m.Annotations = dataAO0.Annotations
m.EndsAt = dataAO0.EndsAt
m.StartsAt = dataAO0.StartsAt
// AO1
var aO1 Alert
if err := swag.ReadJSON(raw, &aO1); err != nil {
return err
}
m.Alert = aO1
return nil
}
// MarshalJSON marshals this object to a JSON structure
func (m PostableAlert) MarshalJSON() ([]byte, error) {
_parts := make([][]byte, 0, 2)
var dataAO0 struct {
Annotations LabelSet `json:"annotations,omitempty"`
EndsAt strfmt.DateTime `json:"endsAt,omitempty"`
StartsAt strfmt.DateTime `json:"startsAt,omitempty"`
}
dataAO0.Annotations = m.Annotations
dataAO0.EndsAt = m.EndsAt
dataAO0.StartsAt = m.StartsAt
jsonDataAO0, errAO0 := swag.WriteJSON(dataAO0)
if errAO0 != nil {
return nil, errAO0
}
_parts = append(_parts, jsonDataAO0)
aO1, err := swag.WriteJSON(m.Alert)
if err != nil {
return nil, err
}
_parts = append(_parts, aO1)
return swag.ConcatJSON(_parts...), nil
}
// Validate validates this postable alert
func (m *PostableAlert) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateAnnotations(formats); err != nil {
res = append(res, err)
}
if err := m.validateEndsAt(formats); err != nil {
res = append(res, err)
}
if err := m.validateStartsAt(formats); err != nil {
res = append(res, err)
}
// validation for a type composition with Alert
if err := m.Alert.Validate(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *PostableAlert) validateAnnotations(formats strfmt.Registry) error {
if swag.IsZero(m.Annotations) { // not required
return nil
}
if err := m.Annotations.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("annotations")
}
return err
}
return nil
}
func (m *PostableAlert) validateEndsAt(formats strfmt.Registry) error {
if swag.IsZero(m.EndsAt) { // not required
return nil
}
if err := validate.FormatOf("endsAt", "body", "date-time", m.EndsAt.String(), formats); err != nil {
return err
}
return nil
}
func (m *PostableAlert) validateStartsAt(formats strfmt.Registry) error {
if swag.IsZero(m.StartsAt) { // not required
return nil
}
if err := validate.FormatOf("startsAt", "body", "date-time", m.StartsAt.String(), formats); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *PostableAlert) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *PostableAlert) UnmarshalBinary(b []byte) error {
var res PostableAlert
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,45 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// PostableAlerts postable alerts
// swagger:model postableAlerts
type PostableAlerts []*PostableAlert
// Validate validates this postable alerts
func (m PostableAlerts) Validate(formats strfmt.Registry) error {
var res []error
for i := 0; i < len(m); i++ {
if swag.IsZero(m[i]) { // not required
continue
}
if m[i] != nil {
if err := m[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName(strconv.Itoa(i))
}
return err
}
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,103 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// PostableSilence postable silence
// swagger:model postableSilence
type PostableSilence struct {
// id
ID string `json:"id,omitempty"`
Silence
}
// UnmarshalJSON unmarshals this object from a JSON structure
func (m *PostableSilence) UnmarshalJSON(raw []byte) error {
// AO0
var dataAO0 struct {
ID string `json:"id,omitempty"`
}
if err := swag.ReadJSON(raw, &dataAO0); err != nil {
return err
}
m.ID = dataAO0.ID
// AO1
var aO1 Silence
if err := swag.ReadJSON(raw, &aO1); err != nil {
return err
}
m.Silence = aO1
return nil
}
// MarshalJSON marshals this object to a JSON structure
func (m PostableSilence) MarshalJSON() ([]byte, error) {
_parts := make([][]byte, 0, 2)
var dataAO0 struct {
ID string `json:"id,omitempty"`
}
dataAO0.ID = m.ID
jsonDataAO0, errAO0 := swag.WriteJSON(dataAO0)
if errAO0 != nil {
return nil, errAO0
}
_parts = append(_parts, jsonDataAO0)
aO1, err := swag.WriteJSON(m.Silence)
if err != nil {
return nil, err
}
_parts = append(_parts, aO1)
return swag.ConcatJSON(_parts...), nil
}
// Validate validates this postable silence
func (m *PostableSilence) Validate(formats strfmt.Registry) error {
var res []error
// validation for a type composition with Silence
if err := m.Silence.Validate(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// MarshalBinary interface implementation
func (m *PostableSilence) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *PostableSilence) UnmarshalBinary(b []byte) error {
var res PostableSilence
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,64 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// Receiver receiver
// swagger:model receiver
type Receiver struct {
// name
// Required: true
Name *string `json:"name"`
}
// Validate validates this receiver
func (m *Receiver) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateName(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *Receiver) validateName(formats strfmt.Registry) error {
if err := validate.Required("name", "body", m.Name); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *Receiver) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *Receiver) UnmarshalBinary(b []byte) error {
var res Receiver
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,149 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// Silence silence
// swagger:model silence
type Silence struct {
// comment
// Required: true
Comment *string `json:"comment"`
// created by
// Required: true
CreatedBy *string `json:"createdBy"`
// ends at
// Required: true
// Format: date-time
EndsAt *strfmt.DateTime `json:"endsAt"`
// matchers
// Required: true
Matchers Matchers `json:"matchers"`
// starts at
// Required: true
// Format: date-time
StartsAt *strfmt.DateTime `json:"startsAt"`
}
// Validate validates this silence
func (m *Silence) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateComment(formats); err != nil {
res = append(res, err)
}
if err := m.validateCreatedBy(formats); err != nil {
res = append(res, err)
}
if err := m.validateEndsAt(formats); err != nil {
res = append(res, err)
}
if err := m.validateMatchers(formats); err != nil {
res = append(res, err)
}
if err := m.validateStartsAt(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *Silence) validateComment(formats strfmt.Registry) error {
if err := validate.Required("comment", "body", m.Comment); err != nil {
return err
}
return nil
}
func (m *Silence) validateCreatedBy(formats strfmt.Registry) error {
if err := validate.Required("createdBy", "body", m.CreatedBy); err != nil {
return err
}
return nil
}
func (m *Silence) validateEndsAt(formats strfmt.Registry) error {
if err := validate.Required("endsAt", "body", m.EndsAt); err != nil {
return err
}
if err := validate.FormatOf("endsAt", "body", "date-time", m.EndsAt.String(), formats); err != nil {
return err
}
return nil
}
func (m *Silence) validateMatchers(formats strfmt.Registry) error {
if err := validate.Required("matchers", "body", m.Matchers); err != nil {
return err
}
if err := m.Matchers.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("matchers")
}
return err
}
return nil
}
func (m *Silence) validateStartsAt(formats strfmt.Registry) error {
if err := validate.Required("startsAt", "body", m.StartsAt); err != nil {
return err
}
if err := validate.FormatOf("startsAt", "body", "date-time", m.StartsAt.String(), formats); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *Silence) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *Silence) UnmarshalBinary(b []byte) error {
var res Silence
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,104 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// SilenceStatus silence status
// swagger:model silenceStatus
type SilenceStatus struct {
// state
// Required: true
// Enum: [expired active pending]
State *string `json:"state"`
}
// Validate validates this silence status
func (m *SilenceStatus) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateState(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
var silenceStatusTypeStatePropEnum []interface{}
func init() {
var res []string
if err := json.Unmarshal([]byte(`["expired","active","pending"]`), &res); err != nil {
panic(err)
}
for _, v := range res {
silenceStatusTypeStatePropEnum = append(silenceStatusTypeStatePropEnum, v)
}
}
const (
// SilenceStatusStateExpired captures enum value "expired"
SilenceStatusStateExpired string = "expired"
// SilenceStatusStateActive captures enum value "active"
SilenceStatusStateActive string = "active"
// SilenceStatusStatePending captures enum value "pending"
SilenceStatusStatePending string = "pending"
)
// prop value enum
func (m *SilenceStatus) validateStateEnum(path, location string, value string) error {
if err := validate.Enum(path, location, value, silenceStatusTypeStatePropEnum); err != nil {
return err
}
return nil
}
func (m *SilenceStatus) validateState(formats strfmt.Registry) error {
if err := validate.Required("state", "body", m.State); err != nil {
return err
}
// value enum
if err := m.validateStateEnum("state", "body", *m.State); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *SilenceStatus) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *SilenceStatus) UnmarshalBinary(b []byte) error {
var res SilenceStatus
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,149 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// VersionInfo version info
// swagger:model versionInfo
type VersionInfo struct {
// branch
// Required: true
Branch *string `json:"branch"`
// build date
// Required: true
BuildDate *string `json:"buildDate"`
// build user
// Required: true
BuildUser *string `json:"buildUser"`
// go version
// Required: true
GoVersion *string `json:"goVersion"`
// revision
// Required: true
Revision *string `json:"revision"`
// version
// Required: true
Version *string `json:"version"`
}
// Validate validates this version info
func (m *VersionInfo) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateBranch(formats); err != nil {
res = append(res, err)
}
if err := m.validateBuildDate(formats); err != nil {
res = append(res, err)
}
if err := m.validateBuildUser(formats); err != nil {
res = append(res, err)
}
if err := m.validateGoVersion(formats); err != nil {
res = append(res, err)
}
if err := m.validateRevision(formats); err != nil {
res = append(res, err)
}
if err := m.validateVersion(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *VersionInfo) validateBranch(formats strfmt.Registry) error {
if err := validate.Required("branch", "body", m.Branch); err != nil {
return err
}
return nil
}
func (m *VersionInfo) validateBuildDate(formats strfmt.Registry) error {
if err := validate.Required("buildDate", "body", m.BuildDate); err != nil {
return err
}
return nil
}
func (m *VersionInfo) validateBuildUser(formats strfmt.Registry) error {
if err := validate.Required("buildUser", "body", m.BuildUser); err != nil {
return err
}
return nil
}
func (m *VersionInfo) validateGoVersion(formats strfmt.Registry) error {
if err := validate.Required("goVersion", "body", m.GoVersion); err != nil {
return err
}
return nil
}
func (m *VersionInfo) validateRevision(formats strfmt.Registry) error {
if err := validate.Required("revision", "body", m.Revision); err != nil {
return err
}
return nil
}
func (m *VersionInfo) validateVersion(formats strfmt.Registry) error {
if err := validate.Required("version", "body", m.Version); err != nil {
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *VersionInfo) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *VersionInfo) UnmarshalBinary(b []byte) error {
var res VersionInfo
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

10
internal/mapper/v016/run.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh -e
AM_VERSION=$1
API_VERSION=$2
TARGET_DIR=$3
API_YAML_URL=https://raw.githubusercontent.com/prometheus/alertmanager/${AM_VERSION}/api/${API_VERSION}/openapi.yaml
curl -sL -o /tmp/openapi.yaml ${API_YAML_URL}
swagger generate client -f /tmp/openapi.yaml --target ${TARGET_DIR}

View File

@@ -0,0 +1,42 @@
package v016
import (
"net/http"
"time"
"github.com/blang/semver"
"github.com/prymitive/karma/internal/mapper"
"github.com/prymitive/karma/internal/models"
"github.com/prymitive/karma/internal/uri"
)
// SilenceMapper implements Alertmanager 0.4 API schema
type SilenceMapper struct {
mapper.SilenceMapper
}
// AbsoluteURL for silences API endpoint this mapper supports
func (m SilenceMapper) AbsoluteURL(baseURI string) (string, error) {
return uri.JoinURL(baseURI, "api/v2/silences")
}
// QueryArgs for HTTP requests send to the Alertmanager API endpoint
func (m SilenceMapper) QueryArgs() string {
return ""
}
// IsSupported returns true if given version string is supported
func (m SilenceMapper) IsSupported(version string) bool {
versionRange := semver.MustParseRange(">=0.16.0")
return versionRange(semver.MustParse(version))
}
// IsOpenAPI returns true is remote Alertmanager uses OpenAPI
func (m SilenceMapper) IsOpenAPI() bool {
return true
}
func (m SilenceMapper) Collect(uri string, headers map[string]string, timeout time.Duration, httpTransport http.RoundTripper) ([]models.Silence, error) {
c := newClient(uri, headers, httpTransport)
return silences(c, timeout)
}

View File

@@ -70,6 +70,11 @@ func (m AlertMapper) IsSupported(version string) bool {
return versionRange(semver.MustParse(version))
}
// IsOpenAPI returns true is remote Alertmanager uses OpenAPI
func (m AlertMapper) IsOpenAPI() bool {
return false
}
// Decode Alertmanager API response body and return karma model instances
func (m AlertMapper) Decode(source io.ReadCloser) ([]models.AlertGroup, error) {
groups := []models.AlertGroup{}

View File

@@ -67,6 +67,11 @@ func (m SilenceMapper) IsSupported(version string) bool {
return versionRange(semver.MustParse(version))
}
// IsOpenAPI returns true is remote Alertmanager uses OpenAPI
func (m SilenceMapper) IsOpenAPI() bool {
return false
}
// Decode Alertmanager API response body and return karma model instances
func (m SilenceMapper) Decode(source io.ReadCloser) ([]models.Silence, error) {
silences := []models.Silence{}
@@ -85,13 +90,20 @@ func (m SilenceMapper) Decode(source io.ReadCloser) ([]models.Silence, error) {
for _, s := range resp.Data.Silences {
us := models.Silence{
ID: strconv.Itoa(s.ID),
Matchers: s.Matchers,
StartsAt: s.StartsAt,
EndsAt: s.EndsAt,
CreatedAt: s.CreatedAt,
CreatedBy: s.CreatedBy,
Comment: s.Comment,
}
for _, m := range s.Matchers {
sm := models.SilenceMatcher{
Name: m.Name,
Value: m.Value,
IsRegex: m.IsRegex,
}
us.Matchers = append(us.Matchers, sm)
}
silences = append(silences, us)
}
return silences, nil

View File

@@ -69,6 +69,11 @@ func (m AlertMapper) IsSupported(version string) bool {
return versionRange(semver.MustParse(version))
}
// IsOpenAPI returns true is remote Alertmanager uses OpenAPI
func (m AlertMapper) IsOpenAPI() bool {
return false
}
// Decode Alertmanager API response body and return karma model instances
func (m AlertMapper) Decode(source io.ReadCloser) ([]models.AlertGroup, error) {
groups := []models.AlertGroup{}

View File

@@ -53,10 +53,15 @@ func (m SilenceMapper) QueryArgs() string {
// IsSupported returns true if given version string is supported
func (m SilenceMapper) IsSupported(version string) bool {
versionRange := semver.MustParseRange(">=0.5.0")
versionRange := semver.MustParseRange(">=0.5.0 <0.16.0")
return versionRange(semver.MustParse(version))
}
// IsOpenAPI returns true is remote Alertmanager uses OpenAPI
func (m SilenceMapper) IsOpenAPI() bool {
return false
}
// Decode Alertmanager API response body and return karma model instances
func (m SilenceMapper) Decode(source io.ReadCloser) ([]models.Silence, error) {
silences := []models.Silence{}
@@ -75,13 +80,20 @@ func (m SilenceMapper) Decode(source io.ReadCloser) ([]models.Silence, error) {
for _, s := range resp.Data {
us := models.Silence{
ID: s.ID,
Matchers: s.Matchers,
StartsAt: s.StartsAt,
EndsAt: s.EndsAt,
CreatedAt: s.CreatedAt,
CreatedBy: s.CreatedBy,
Comment: s.Comment,
}
for _, m := range s.Matchers {
sm := models.SilenceMatcher{
Name: m.Name,
Value: m.Value,
IsRegex: m.IsRegex,
}
us.Matchers = append(us.Matchers, sm)
}
silences = append(silences, us)
}
return silences, nil

View File

@@ -71,6 +71,11 @@ func (m AlertMapper) IsSupported(version string) bool {
return versionRange(semver.MustParse(version))
}
// IsOpenAPI returns true is remote Alertmanager uses OpenAPI
func (m AlertMapper) IsOpenAPI() bool {
return false
}
// Decode Alertmanager API response body and return karma model instances
func (m AlertMapper) Decode(source io.ReadCloser) ([]models.AlertGroup, error) {
groups := []models.AlertGroup{}

View File

@@ -71,10 +71,15 @@ func (m AlertMapper) QueryArgs() string {
// IsSupported returns true if given version string is supported
func (m AlertMapper) IsSupported(version string) bool {
versionRange := semver.MustParseRange(">=0.6.2")
versionRange := semver.MustParseRange(">=0.6.2 <0.16.0")
return versionRange(semver.MustParse(version))
}
// IsOpenAPI returns true is remote Alertmanager uses OpenAPI
func (m AlertMapper) IsOpenAPI() bool {
return false
}
// Decode Alertmanager API response body and return karma model instances
func (m AlertMapper) Decode(source io.ReadCloser) ([]models.AlertGroup, error) {
groups := []models.AlertGroup{}

View File

@@ -2,22 +2,24 @@ package models
import "time"
type SilenceMatcher struct {
Name string `json:"name"`
Value string `json:"value"`
IsRegex bool `json:"isRegex"`
}
// Silence is vanilla silence + some additional attributes
// karma adds JIRA support, it can extract JIRA IDs from comments
// extracted ID is used to generate link to JIRA issue
// this means karma needs to store additional fields for each silence
type Silence struct {
ID string `json:"id"`
Matchers []struct {
Name string `json:"name"`
Value string `json:"value"`
IsRegex bool `json:"isRegex"`
} `json:"matchers"`
StartsAt time.Time `json:"startsAt"`
EndsAt time.Time `json:"endsAt"`
CreatedAt time.Time `json:"createdAt"`
CreatedBy string `json:"createdBy"`
Comment string `json:"comment"`
ID string `json:"id"`
Matchers []SilenceMatcher `json:"matchers"`
StartsAt time.Time `json:"startsAt"`
EndsAt time.Time `json:"endsAt"`
CreatedAt time.Time `json:"createdAt"`
CreatedBy string `json:"createdBy"`
Comment string `json:"comment"`
// karma fields
JiraID string `json:"jiraID"`
JiraURL string `json:"jiraURL"`

View File

@@ -80,5 +80,11 @@ func setupRouterProxyHandlers(router *gin.Engine, alertmanager *alertmanager.Ale
router.DELETE(
proxyPath(alertmanager.Name, "/api/v1/silence/*id"),
gin.WrapH(http.StripPrefix(proxyPathPrefix(alertmanager.Name), proxy)))
router.POST(
proxyPath(alertmanager.Name, "/api/v2/silences"),
gin.WrapH(http.StripPrefix(proxyPathPrefix(alertmanager.Name), proxy)))
router.DELETE(
proxyPath(alertmanager.Name, "/api/v2/silence/*id"),
gin.WrapH(http.StripPrefix(proxyPathPrefix(alertmanager.Name), proxy)))
return nil
}

View File

@@ -50,6 +50,7 @@
"react-tippy": "1.2.3",
"react-transition-group": "4.0.0",
"react-truncate": "2.4.0",
"semver": "6.0.0",
"whatwg-fetch": "3.0.0"
},
"scripts": {

View File

@@ -4,6 +4,8 @@ import PropTypes from "prop-types";
import { observable, action } from "mobx";
import { observer } from "mobx-react";
import semver from "semver";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faTrash } from "@fortawesome/free-solid-svg-icons/faTrash";
import { faExclamationCircle } from "@fortawesome/free-solid-svg-icons/faExclamationCircle";
@@ -119,9 +121,7 @@ const DeleteSilenceModalContent = observer(
]);
this.previewState.fetch = fetch(alertsURI, { credentials: "include" })
.then(result => {
return result.json();
})
.then(result => result.json())
.then(result => {
this.previewState.groupsToUniqueLabels(Object.values(result.groups));
this.previewState.setError(null);
@@ -140,13 +140,29 @@ const DeleteSilenceModalContent = observer(
// if it's already deleted then do nothing
if (this.deleteState.done && this.deleteState.error === null) return;
const uri = `${alertmanager.publicURI}/api/v1/silence/${silenceID}`;
const isOpenAPI = semver.satisfies(alertmanager.version, ">=0.16.0");
const uri = isOpenAPI
? `${alertmanager.publicURI}/api/v2/silence/${silenceID}`
: `${alertmanager.publicURI}/api/v1/silence/${silenceID}`;
this.deleteState.fetch = fetch(uri, {
method: "DELETE",
credentials: "include"
})
.then(result => result.json())
.then(result => this.parseAlertmanagerResponse(result))
.then(result => {
if (isOpenAPI) {
if (result.ok) {
this.deleteState.setError(null);
this.deleteState.setDone();
} else {
result.text().then(this.deleteState.setError);
this.deleteState.setDone();
}
} else {
result.json().then(this.parseAlertmanagerResponse);
}
})
.catch(err => {
console.trace(err);
this.deleteState.setDone();

View File

@@ -13,6 +13,7 @@ let alertStore;
beforeEach(() => {
alertmanager = MockAlertmanager();
alertStore = new AlertStore([]);
alertStore.data.upstreams.instances[0] = alertmanager;
fetch.mockResponseOnce(JSON.stringify(MockAPIResponse()));
jest.restoreAllMocks();
@@ -121,7 +122,7 @@ describe("<DeleteSilenceModalContent />", () => {
expect(tree.find("ErrorMessage")).toHaveLength(1);
});
it("sends a DELETE request after clicking 'Confirm' button", async () => {
it("[v1] sends a DELETE request after clicking 'Confirm' button ", async () => {
await VerifyResponse({ status: "success" });
expect(fetch.mock.calls[1][0]).toBe(
"http://am.example.com/api/v1/silence/123456789"
@@ -129,6 +130,15 @@ describe("<DeleteSilenceModalContent />", () => {
expect(fetch.mock.calls[1][1]).toMatchObject({ method: "DELETE" });
});
it("[v2] sends a DELETE request after clicking 'Confirm' button ", async () => {
alertmanager.version = "0.16.2";
await VerifyResponse({ status: "success" });
expect(fetch.mock.calls[1][0]).toBe(
"http://am.example.com/api/v2/silence/123456789"
);
expect(fetch.mock.calls[1][1]).toMatchObject({ method: "DELETE" });
});
it("'Confirm' button is no-op after successful DELETE", async () => {
const tree = await VerifyResponse({ status: "success" });
expect(fetch.mock.calls[1][0]).toBe(
@@ -165,7 +175,7 @@ describe("<DeleteSilenceModalContent />", () => {
expect(tree.find("ErrorMessage")).toHaveLength(1);
});
it("renders ErrorMessage on failed fetch request", async () => {
it("[v1] renders ErrorMessage on failed fetch request", async () => {
const tree = MountedDeleteSilenceModalContent();
await expect(tree.instance().previewState.fetch).resolves.toBeUndefined();
@@ -179,4 +189,20 @@ describe("<DeleteSilenceModalContent />", () => {
tree.update();
expect(tree.find("ErrorMessage")).toHaveLength(1);
});
it("[v2] renders ErrorMessage on failed fetch request", async () => {
alertmanager.version = "0.16.2";
const tree = MountedDeleteSilenceModalContent();
await expect(tree.instance().previewState.fetch).resolves.toBeUndefined();
jest.spyOn(console, "trace").mockImplementation(() => {});
fetch.resetMocks();
fetch.mockResponseOnce("500 Internal Server Error", { status: 500 });
tree.find(".btn-outline-danger").simulate("click");
await expect(tree.instance().deleteState.fetch).resolves.toBeUndefined();
tree.update();
expect(tree.find("ErrorMessage")).toHaveLength(1);
});
});

View File

@@ -175,7 +175,7 @@ exports[`<Silence /> matches snapshot with expaned details 1`] = `
>
</path>
</svg>
Created
Started
<time datetime=\\"946720800000\\">
5 hours ago
</time>

View File

@@ -128,7 +128,7 @@ const SilenceDetails = ({
<div>
<span className="badge text-nowrap text-truncate px-1 mr-1">
<FontAwesomeIcon className="text-muted mr-1" icon={faCalendarCheck} />
Created <Moment fromNow>{silence.startsAt}</Moment>
Started <Moment fromNow>{silence.startsAt}</Moment>
</span>
<span
className={`badge ${expiresClass} text-nowrap text-truncate px-1 mr-1`}

View File

@@ -4,6 +4,8 @@ import PropTypes from "prop-types";
import { action, observable } from "mobx";
import { observer } from "mobx-react";
import semver from "semver";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCircleNotch } from "@fortawesome/free-solid-svg-icons/faCircleNotch";
import { faCheckCircle } from "@fortawesome/free-regular-svg-icons/faCheckCircle";
@@ -54,7 +56,8 @@ const SilenceSubmitProgress = observer(
startsAt: PropTypes.string.isRequired,
endsAt: PropTypes.string.isRequired,
createdBy: PropTypes.string.isRequired,
comment: PropTypes.string.isRequired
comment: PropTypes.string.isRequired,
id: PropTypes.string
}).isRequired,
alertStore: PropTypes.instanceOf(AlertStore).isRequired
};
@@ -99,7 +102,13 @@ const SilenceSubmitProgress = observer(
return;
}
this.submitState.fetch = fetch(`${am.publicURI}/api/v1/silences`, {
const isOpenAPI = semver.satisfies(am.version, ">=0.16.0");
const uri = isOpenAPI
? `${am.publicURI}/api/v2/silences`
: `${am.publicURI}/api/v1/silences`;
this.submitState.fetch = fetch(uri, {
method: "POST",
body: JSON.stringify(payload),
headers: {
@@ -107,9 +116,34 @@ const SilenceSubmitProgress = observer(
},
credentials: "include"
})
.then(result => result.json())
.then(result => this.parseAlertmanagerResponse(am.uri, result))
.catch(err => this.maybeTryAgainAfterError(err));
.then(result => {
if (isOpenAPI) {
if (result.ok) {
return result
.json()
.then(r => this.parseOpenAPIResponse(am.uri, r));
} else {
return result.text().then(text => {
this.submitState.markFailed(text);
return text;
});
}
} else {
return result
.json()
.then(r => this.parseAlertmanagerResponse(am.uri, r));
}
})
.catch(err => {
this.maybeTryAgainAfterError(err);
});
};
parseOpenAPIResponse = (uri, response) => {
const link = <SilenceLink uri={uri} silenceId={response.silenceID} />;
this.submitState.markDone(link);
// return silenceId so we can assert it in tests
return response.silenceID;
};
parseAlertmanagerResponse = (uri, response) => {

View File

@@ -48,7 +48,15 @@ describe("<SilenceSubmitProgress />", () => {
expect(fetch.mock.calls).toHaveLength(1);
});
it("appends /api/v1/silences to the passed URI", async () => {
it("[v1] appends /api/v1/silences to the passed URI", async () => {
const tree = MountedSilenceSubmitProgress();
await expect(tree.instance().submitState.fetch).resolves.toBeUndefined();
const uri = fetch.mock.calls[0][0];
expect(uri).toBe("http://example.com/api/v1/silences");
});
it("[v2] appends /api/v2/silences to the passed URI", async () => {
alertStore.data.upstreams.instances[0].version = "0.16.2";
const tree = MountedSilenceSubmitProgress();
await expect(tree.instance().submitState.fetch).resolves.toBeUndefined();
const uri = fetch.mock.calls[0][0];
@@ -188,7 +196,7 @@ describe("<SilenceSubmitProgress />", () => {
expect(tree.text()).toBe("mockAlertmanagermock error message");
});
it("renders success icon on successful fetch", async () => {
it("[v1] renders success icon on successful fetch", async () => {
fetch.mockResponseOnce(
JSON.stringify({ status: "success", data: { silenceId: "123" } })
);
@@ -199,7 +207,36 @@ describe("<SilenceSubmitProgress />", () => {
expect(tree.find("FontAwesomeIcon.text-danger")).toHaveLength(0);
});
it("renders error icon on failed fetch", async () => {
it("[v1] renders silence link on successful fetch", async () => {
fetch.mockResponseOnce(
JSON.stringify({ status: "success", data: { silenceId: "123" } })
);
const tree = MountedSilenceSubmitProgress();
await expect(tree.instance().submitState.fetch).resolves.toBe("success");
tree.update();
expect(tree.find("a").getDOMNode().getAttribute("href")).toBe("file:///mock/#/silences/123");
});
it("[v2] renders success icon on successful fetch", async () => {
alertStore.data.upstreams.instances[0].version = "0.16.2";
fetch.mockResponseOnce(JSON.stringify({ silenceID: "123" }));
const tree = MountedSilenceSubmitProgress();
await expect(tree.instance().submitState.fetch).resolves.toBe("123");
tree.update();
expect(tree.find("FontAwesomeIcon.text-success")).toHaveLength(1);
expect(tree.find("FontAwesomeIcon.text-danger")).toHaveLength(0);
});
it("[v2] renders silence link on successful fetch", async () => {
alertStore.data.upstreams.instances[0].version = "0.16.2";
fetch.mockResponseOnce(JSON.stringify({ silenceID: "123" }));
const tree = MountedSilenceSubmitProgress();
await expect(tree.instance().submitState.fetch).resolves.toBe("123");
tree.update();
expect(tree.find("a").getDOMNode().getAttribute("href")).toBe("file:///mock/#/silences/123");
});
it("[v1] renders error icon on failed fetch", async () => {
fetch.mockResponseOnce(JSON.stringify({ status: "error" }));
const tree = MountedSilenceSubmitProgress();
await expect(tree.instance().submitState.fetch).resolves.toBe("error");
@@ -208,6 +245,18 @@ describe("<SilenceSubmitProgress />", () => {
expect(tree.find("FontAwesomeIcon.text-danger")).toHaveLength(1);
});
it("[v2] renders error icon on failed fetch", async () => {
alertStore.data.upstreams.instances[0].version = "0.16.2";
fetch.mockResponseOnce("error message", { status: 500 });
const tree = MountedSilenceSubmitProgress();
await expect(tree.instance().submitState.fetch).resolves.toBe(
"error message"
);
tree.update();
expect(tree.find("FontAwesomeIcon.text-success")).toHaveLength(0);
expect(tree.find("FontAwesomeIcon.text-danger")).toHaveLength(1);
});
it("renders unhandled 'status' values in the response as error", async () => {
fetch.mockResponseOnce(JSON.stringify({ status: "unhandled" }));
const tree = MountedSilenceSubmitProgress();