diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 1e85a347..cdfb43d6 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -101,7 +101,7 @@ jobs: env: VERSION: ${{ env.VERSION }} run: | - make build + make build certs chmod +x statping mv statping $(go env GOPATH)/bin/ diff --git a/go.mod b/go.mod index fcc3797b..cd267f11 100644 --- a/go.mod +++ b/go.mod @@ -12,24 +12,16 @@ require ( github.com/fsnotify/fsnotify v1.4.9 // indirect github.com/getsentry/sentry-go v0.5.1 github.com/go-mail/mail v2.3.1+incompatible - github.com/gogo/protobuf v1.3.1 // indirect github.com/golang/protobuf v1.3.5 github.com/gorilla/mux v1.7.4 - github.com/gorilla/securecookie v1.1.1 - github.com/gorilla/sessions v1.2.0 github.com/jinzhu/gorm v1.9.12 - github.com/joho/godotenv v1.3.0 - github.com/kataras/iris/v12 v12.0.1 github.com/magiconair/properties v1.8.1 github.com/mattn/go-sqlite3 v2.0.3+incompatible github.com/mitchellh/mapstructure v1.2.2 // indirect github.com/pelletier/go-toml v1.7.0 // indirect github.com/pkg/errors v0.9.1 - github.com/prometheus/common v0.9.1 - github.com/rendon/testcli v0.0.0-20161027181003-6283090d169f github.com/russross/blackfriday/v2 v2.0.1 github.com/sirupsen/logrus v1.4.2 - github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect github.com/spf13/afero v1.2.2 // indirect github.com/spf13/cast v1.3.1 // indirect github.com/spf13/cobra v1.0.0 @@ -38,12 +30,11 @@ require ( github.com/spf13/viper v1.6.3 github.com/stretchr/testify v1.5.1 github.com/t-tiger/gorm-bulk-insert/v2 v2.0.1 - github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e golang.org/x/crypto v0.0.0-20200406173513-056763e48d71 + golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 // indirect golang.org/x/text v0.3.2 // indirect - golang.org/x/tools v0.0.0-20200321014904-268ba720d32c // indirect google.golang.org/grpc v1.28.0 gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/ini.v1 v1.55.0 // indirect diff --git a/go.sum b/go.sum index 315b77f5..4c7af747 100755 --- a/go.sum +++ b/go.sum @@ -5,6 +5,7 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a/go.mod h1:EFZQ978U7x8IRnstaskI3IysnWY5Ao3QgZUKOXlsAdw= github.com/CloudyKit/jet v2.1.3-0.20180809161101-62edd43e4f88+incompatible/go.mod h1:HPYO+50pSWkPoj9Q/eq0aRGByCL6ScRlUmiEX5Zgm+w= +github.com/DATA-DOG/go-sqlmock v1.4.1 h1:ThlnYciV1iM/V0OSF/dtkqWb6xo5qITT1TJBG1MRDJM= github.com/DATA-DOG/go-sqlmock v1.4.1/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/GeertJohan/go.incremental v1.0.0 h1:7AH+pY1XUgQE4Y1HcXYaMqAI0m9yrFqo/jt0CW30vsg= github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0= @@ -19,11 +20,7 @@ github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw= github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E= -github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/ararog/timeago v0.0.0-20160328174124-e9969cf18b8d h1:ZX0t+GA3MWiP7LWt5xWOphWRQd5JwL4VW5uLW83KM8g= github.com/ararog/timeago v0.0.0-20160328174124-e9969cf18b8d/go.mod h1:EcJ034SpbWy4heOSDiBZJRn3b5wKJM1b4sFfYeVAkI4= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= @@ -52,6 +49,7 @@ 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/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM= github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= +github.com/denisenkom/go-mssqldb v0.0.0-20200206145737-bbfc9a55622e h1:LzwWXEScfcTu7vUZNlDDWDARoSGEtvlDKK2BYHowNeE= github.com/denisenkom/go-mssqldb v0.0.0-20200206145737-bbfc9a55622e/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= @@ -85,7 +83,6 @@ github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclK github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-mail/mail v2.3.1+incompatible h1:UzNOn0k5lpfVtO31cK3hn6I4VEVGhe3lX8AJBAxXExM= @@ -102,8 +99,6 @@ github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/E github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= -github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -123,13 +118,10 @@ github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= -github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= -github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ= -github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= @@ -156,13 +148,13 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.0.1 h1:HjfetcXq097iXP0uoPCdnM4Efp5/9MsM0/M+XOTeR3M= github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/jinzhu/now v1.1.1 h1:g39TucaRWyV3dwDO++eEc6qf8TVIQ/Da48WmqjZ3i7E= github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= -github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= @@ -177,7 +169,6 @@ github.com/kataras/neffos v0.0.10/go.mod h1:ZYmJC07hQPW67eKuzlfY7SO3bC0mw83A3j6i github.com/kataras/pio v0.0.0-20190103105442-ea782b38602d h1:V5Rs9ztEWdp58oayPq/ulmlqJJZeJP6pP79uP3qjcao= github.com/kataras/pio v0.0.0-20190103105442-ea782b38602d/go.mod h1:NV88laa9UiiDuX9AhMbDPkGYSPugBOV6yTZB1l2K9Z0= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= -github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.0 h1:GhthINjveNZAdFUD8QoQYfjxnOONZgztK/Yr6M23UTY= @@ -189,6 +180,7 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g= github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= @@ -230,6 +222,7 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM= github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229 h1:E2B8qYyeSgv5MXpmzZXRNp8IAQ4vjxIjhpAf5hv/tAg= github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E= @@ -251,22 +244,14 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= -github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U= -github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= -github.com/rendon/testcli v0.0.0-20161027181003-6283090d169f h1:onGP+qmYmjKs7pkmi9j0mwyr97/D5wki80e74aKIOxg= -github.com/rendon/testcli v0.0.0-20161027181003-6283090d169f/go.mod h1:cq57a4l475CeMvE7RRpSui1MEqCmhirIt1E7kl8BC2Q= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= @@ -279,9 +264,9 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA= -github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -318,11 +303,8 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= -github.com/t-tiger/gorm-bulk-insert v1.3.0 h1:9k7BaVEhw/3fsvh6GTOBwJ2RXk3asc5xs5m6hwozq20= github.com/t-tiger/gorm-bulk-insert/v2 v2.0.1 h1:HGVkRrwDCbmSP6h1CoBDj6l/mhnvsP5JbYaQ4ss0R6o= github.com/t-tiger/gorm-bulk-insert/v2 v2.0.1/go.mod h1:I3xbaE9ud9/TEXzehwkHx86SyJwqeSNsX2X5oV61jIg= -github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e h1:nt2877sKfojlHCTOBXbpWjBkuWKritFaGIfgQwbQUls= -github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e/go.mod h1:B4+Kq1u5FlULTjFSM707Q6e/cOHFv0z/6QRoxubDIQ8= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= @@ -344,7 +326,6 @@ github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmv github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= -github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= @@ -354,17 +335,13 @@ golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200320181102-891825fb96df h1:lDWgvUvNnaTnNBc/dwOty86cFeKoKWbwy2wQj0gIxbU= -golang.org/x/crypto v0.0.0-20200320181102-891825fb96df/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200406173513-056763e48d71 h1:DOmugCavvUtnUD114C1Wh+UgTgQZ4pMLzXxi1pSt+/Y= golang.org/x/crypto v0.0.0-20200406173513-056763e48d71/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -376,7 +353,6 @@ golang.org/x/net v0.0.0-20190327091125-710a502c58a2/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM= golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -388,7 +364,6 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -412,7 +387,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -420,11 +394,6 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190327201419-c70d86f8b7cf/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200321014904-268ba720d32c h1:Qp5jXmUCqMiVq4676uW7bY2oskIR1ivTboSMn8qgeX0= -golang.org/x/tools v0.0.0-20200321014904-268ba720d32c/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= @@ -446,6 +415,7 @@ gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= diff --git a/types/services/methods.go b/types/services/methods.go index 471f58f9..286f876b 100644 --- a/types/services/methods.go +++ b/types/services/methods.go @@ -20,7 +20,7 @@ import ( const limitedFailures = 25 func (s *Service) LoadTLSCert() (*tls.Config, error) { - if !s.TLSCert.Valid && !s.TLSCertKey.Valid { + if s.TLSCert.String == "" || s.TLSCertKey.String == "" { return nil, nil } @@ -38,22 +38,27 @@ func (s *Service) LoadTLSCert() (*tls.Config, error) { return nil, errors.Wrap(err, "issue loading X509KeyPair") } - // create Root CA pool or use Root CA provided - chainFile := s.TLSCert.String - if s.TLSCertRoot.String != "" { - chainFile = s.TLSCertRoot.String + config := &tls.Config{ + Certificates: []tls.Certificate{cert}, + InsecureSkipVerify: s.TLSCertRoot.String == "", } - caCert, err := ioutil.ReadFile(chainFile) + + if s.TLSCertRoot.String == "" { + return config, nil + } + + // create Root CA pool or use Root CA provided + rootCA := s.TLSCertRoot.String + caCert, err := ioutil.ReadFile(rootCA) if err != nil { - return nil, errors.Wrap(err, "issue reading cert file: "+chainFile) + return nil, errors.Wrap(err, "issue reading root CA file: "+rootCA) } caCertPool := x509.NewCertPool() caCertPool.AppendCertsFromPEM(caCert) - return &tls.Config{ - RootCAs: caCertPool, - Certificates: []tls.Certificate{cert}, - }, nil + config.RootCAs = caCertPool + + return config, nil } func (s *Service) Duration() time.Duration { diff --git a/types/services/routine.go b/types/services/routine.go index d4351172..b9e1f13c 100644 --- a/types/services/routine.go +++ b/types/services/routine.go @@ -15,7 +15,6 @@ import ( "github.com/statping/statping/types/failures" "github.com/statping/statping/types/hits" "github.com/statping/statping/utils" - "github.com/tatsushid/go-fastping" ) // checkServices will start the checking go routine for each service @@ -90,35 +89,23 @@ func isIPv6(address string) bool { } // checkIcmp will send a ICMP ping packet to the service -func CheckIcmp(s *Service, record bool) *Service { +func CheckIcmp(s *Service, record bool) (*Service, error) { defer s.updateLastCheck() - p := fastping.NewPinger() - resolveIP := "ip4:icmp" - if isIPv6(s.Domain) { - resolveIP = "ip6:icmp" - } - ra, err := net.ResolveIPAddr(resolveIP, s.Domain) + err := utils.Ping(s.Domain, s.Timeout) if err != nil { - recordFailure(s, fmt.Sprintf("Could not send ICMP to service %v, %v", s.Domain, err)) - return s - } - p.AddIPAddr(ra) - p.OnRecv = func(addr *net.IPAddr, rtt time.Duration) { - s.Latency = rtt.Microseconds() - recordSuccess(s) - } - err = p.Run() - if err != nil { - recordFailure(s, fmt.Sprintf("Issue running ICMP to service %v, %v", s.Domain, err)) - return s + if record { + recordFailure(s, fmt.Sprintf("Could not send ICMP to service %v, %v", s.Domain, err)) + } + return s, err } s.LastResponse = "" - return s + s.Online = true + return s, nil } // CheckGrpc will check a gRPC service -func CheckGrpc(s *Service, record bool) *Service { +func CheckGrpc(s *Service, record bool) (*Service, error) { defer s.updateLastCheck() dnsLookup, err := dnsCheck(s) @@ -126,7 +113,7 @@ func CheckGrpc(s *Service, record bool) *Service { if record { recordFailure(s, fmt.Sprintf("Could not get IP address for GRPC service %v, %v", s.Domain, err)) } - return s + return s, err } s.PingTime = dnsLookup t1 := utils.Now() @@ -145,25 +132,26 @@ func CheckGrpc(s *Service, record bool) *Service { if record { recordFailure(s, fmt.Sprintf("Dial Error %v", err)) } - return s + return s, err } if err := conn.Close(); err != nil { if record { recordFailure(s, fmt.Sprintf("%v Socket Close Error %v", strings.ToUpper(s.Type), err)) } - return s + return s, err } t2 := utils.Now() s.Latency = t2.Sub(t1).Microseconds() s.LastResponse = "" + s.Online = true if record { recordSuccess(s) } - return s + return s, nil } // checkTcp will check a TCP service -func CheckTcp(s *Service, record bool) *Service { +func CheckTcp(s *Service, record bool) (*Service, error) { defer s.updateLastCheck() dnsLookup, err := dnsCheck(s) @@ -171,7 +159,7 @@ func CheckTcp(s *Service, record bool) *Service { if record { recordFailure(s, fmt.Sprintf("Could not get IP address for TCP service %v, %v", s.Domain, err)) } - return s + return s, err } s.PingTime = dnsLookup t1 := utils.Now() @@ -188,22 +176,28 @@ func CheckTcp(s *Service, record bool) *Service { log.Errorln(err) } + // test TCP connection if there is no TLS Certificate set if s.TLSCert.String == "" { - conn, err := net.Dial(s.Type, domain) + conn, err := net.DialTimeout(s.Type, domain, time.Duration(s.Timeout)*time.Second) if err != nil { if record { recordFailure(s, fmt.Sprintf("Dial Error: %v", err)) } - return s + return s, err } defer conn.Close() } else { - conn, err := tls.DialWithDialer(&net.Dialer{Timeout: time.Duration(s.Timeout) * time.Second}, s.Type, domain, tlsConfig) + // test TCP connection if TLS Certificate was set + dialer := &net.Dialer{ + KeepAlive: time.Duration(s.Timeout) * time.Second, + Timeout: time.Duration(s.Timeout) * time.Second, + } + conn, err := tls.DialWithDialer(dialer, s.Type, domain, tlsConfig) if err != nil { if record { recordFailure(s, fmt.Sprintf("Dial Error: %v", err)) } - return s + return s, err } defer conn.Close() } @@ -211,10 +205,11 @@ func CheckTcp(s *Service, record bool) *Service { t2 := utils.Now() s.Latency = t2.Sub(t1).Microseconds() s.LastResponse = "" + s.Online = true if record { recordSuccess(s) } - return s + return s, nil } func (s *Service) updateLastCheck() { @@ -222,7 +217,7 @@ func (s *Service) updateLastCheck() { } // checkHttp will check a HTTP service -func CheckHttp(s *Service, record bool) *Service { +func CheckHttp(s *Service, record bool) (*Service, error) { defer s.updateLastCheck() dnsLookup, err := dnsCheck(s) @@ -230,7 +225,7 @@ func CheckHttp(s *Service, record bool) *Service { if record { recordFailure(s, fmt.Sprintf("Could not get IP address for domain %v, %v", s.Domain, err)) } - return s + return s, err } s.PingTime = dnsLookup t1 := utils.Now() @@ -282,7 +277,7 @@ func CheckHttp(s *Service, record bool) *Service { if record { recordFailure(s, fmt.Sprintf("HTTP Error %v", err)) } - return s + return s, err } t2 := utils.Now() s.Latency = t2.Sub(t1).Microseconds() @@ -298,19 +293,20 @@ func CheckHttp(s *Service, record bool) *Service { if record { recordFailure(s, fmt.Sprintf("HTTP Response Body did not match '%v'", s.Expected)) } - return s + return s, err } } if s.ExpectedStatus != res.StatusCode { if record { recordFailure(s, fmt.Sprintf("HTTP Status Code %v did not match %v", res.StatusCode, s.ExpectedStatus)) } - return s + return s, err } if record { recordSuccess(s) } - return s + s.Online = true + return s, err } // recordSuccess will create a new 'hit' record in the database for a successful/online service diff --git a/types/services/services_test.go b/types/services/services_test.go index 73b2e0b6..a69727ed 100644 --- a/types/services/services_test.go +++ b/types/services/services_test.go @@ -1,7 +1,10 @@ package services import ( + "context" + "crypto/tls" "fmt" + "github.com/gorilla/mux" "github.com/statping/statping/database" "github.com/statping/statping/types/checkins" "github.com/statping/statping/types/failures" @@ -10,6 +13,10 @@ import ( "github.com/statping/statping/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "google.golang.org/grpc" + pb "google.golang.org/grpc/examples/route_guide/routeguide" + "net" + "net/http" "testing" "time" ) @@ -77,6 +84,83 @@ var fail2 = &failures.Failure{ CreatedAt: utils.Now().Add(-5 * time.Second), } +type exampleGRPC struct { + pb.UnimplementedRouteGuideServer +} + +func (s *exampleGRPC) GetFeature(ctx context.Context, point *pb.Point) (*pb.Feature, error) { + return &pb.Feature{Location: point}, nil +} + +func TestStartExampleEndpoints(t *testing.T) { + // root CA for Linux: /etc/ssl/certs/ca-certificates.crt + // root CA for MacOSX: /opt/local/share/curl/curl-ca-bundle.crt + + tlsCert := utils.Params.GetString("STATPING_DIR") + "/cert.pem" + tlsCertKey := utils.Params.GetString("STATPING_DIR") + "/key.pem" + + require.FileExists(t, tlsCert) + require.FileExists(t, tlsCertKey) + + h := func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("ok")) + } + + r := mux.NewRouter() + r.HandleFunc("/", h) + + // start example HTTP server + go func(t *testing.T) { + require.Nil(t, http.ListenAndServe(":15000", r)) + }(t) + + // start example TLS HTTP server + go func(t *testing.T) { + require.Nil(t, http.ListenAndServeTLS(":15001", tlsCert, tlsCertKey, r)) + }(t) + + tcpHandle := func(conn net.Conn) { + defer conn.Close() + conn.Write([]byte("ok")) + } + + // start TCP server + go func(t *testing.T, hdl func(conn net.Conn)) { + ln, err := net.Listen("tcp", ":15002") + require.Nil(t, err) + for { + conn, err := ln.Accept() + require.Nil(t, err) + go hdl(conn) + } + }(t, tcpHandle) + + // start TLS TCP server + go func(t *testing.T, hdl func(conn net.Conn)) { + cer, err := tls.LoadX509KeyPair(tlsCert, tlsCertKey) + require.Nil(t, err) + ln, err := tls.Listen("tcp", ":15003", &tls.Config{Certificates: []tls.Certificate{cer}}) + require.Nil(t, err) + for { + conn, err := ln.Accept() + require.Nil(t, err) + go hdl(conn) + } + }(t, tcpHandle) + + // start GRPC server + go func(t *testing.T) { + list, err := net.Listen("tcp", ":15004") + require.Nil(t, err) + grpcServer := grpc.NewServer() + pb.RegisterRouteGuideServer(grpcServer, &exampleGRPC{}) + require.Nil(t, grpcServer.Serve(list)) + }(t) + + time.Sleep(15 * time.Second) +} + func TestServices(t *testing.T) { db, err := database.OpenTester() require.Nil(t, err) @@ -93,6 +177,9 @@ func TestServices(t *testing.T) { hits.SetDB(db) SetDB(db) + tlsCert := utils.Params.GetString("STATPING_DIR") + "/cert.pem" + tlsCertKey := utils.Params.GetString("STATPING_DIR") + "/key.pem" + t.Run("Test Find service", func(t *testing.T) { item, err := Find(1) require.Nil(t, err) @@ -102,6 +189,146 @@ func TestServices(t *testing.T) { assert.NotZero(t, item.LastCheck) }) + t.Run("Test HTTP Check", func(t *testing.T) { + e := &Service{ + Name: "Example HTTP", + Domain: "http://localhost:15000", + ExpectedStatus: 200, + Type: "http", + Method: "GET", + Timeout: 5, + VerifySSL: null.NewNullBool(false), + } + e, err = CheckHttp(e, false) + require.Nil(t, err) + assert.True(t, e.Online) + assert.False(t, e.LastCheck.IsZero()) + assert.NotEqual(t, 0, e.PingTime) + assert.NotEqual(t, 0, e.Latency) + }) + + t.Run("Test Load TLS Certificates", func(t *testing.T) { + e := &Service{ + Name: "Example TLS", + Domain: "http://localhost:15001", + ExpectedStatus: 200, + Type: "http", + Method: "GET", + Timeout: 5, + VerifySSL: null.NewNullBool(false), + TLSCert: null.NewNullString(tlsCert), + TLSCertKey: null.NewNullString(tlsCertKey), + } + customTLS, err := e.LoadTLSCert() + require.Nil(t, err) + + require.NotNil(t, customTLS) + assert.Nil(t, customTLS.RootCAs) + assert.NotNil(t, customTLS.Certificates) + assert.Equal(t, 1, len(customTLS.Certificates)) + }) + + t.Run("Test TLS HTTP Check", func(t *testing.T) { + e := &Service{ + Name: "Example TLS HTTP", + Domain: "https://localhost:15001", + ExpectedStatus: 200, + Type: "http", + Method: "GET", + Timeout: 15, + VerifySSL: null.NewNullBool(false), + TLSCert: null.NewNullString(tlsCert), + TLSCertKey: null.NewNullString(tlsCertKey), + } + e, err = CheckHttp(e, false) + require.Nil(t, err) + assert.True(t, e.Online) + assert.False(t, e.LastCheck.IsZero()) + assert.NotEqual(t, 0, e.PingTime) + assert.NotEqual(t, 0, e.Latency) + }) + + t.Run("Test TCP Check", func(t *testing.T) { + e := &Service{ + Name: "Example TCP", + Domain: "localhost", + Port: 15002, + Type: "tcp", + Timeout: 5, + } + e, err = CheckTcp(e, false) + require.Nil(t, err) + assert.True(t, e.Online) + assert.False(t, e.LastCheck.IsZero()) + assert.NotEqual(t, 0, e.PingTime) + assert.NotEqual(t, 0, e.Latency) + }) + + t.Run("Test TLS TCP Check", func(t *testing.T) { + e := &Service{ + Name: "Example TLS TCP", + Domain: "localhost", + Port: 15003, + Type: "tcp", + Timeout: 15, + TLSCert: null.NewNullString(tlsCert), + TLSCertKey: null.NewNullString(tlsCertKey), + } + e, err = CheckTcp(e, false) + require.Nil(t, err) + assert.True(t, e.Online) + assert.False(t, e.LastCheck.IsZero()) + assert.NotEqual(t, 0, e.PingTime) + assert.NotEqual(t, 0, e.Latency) + }) + + t.Run("Test UDP Check", func(t *testing.T) { + e := &Service{ + Name: "Example UDP", + Domain: "localhost", + Port: 15003, + Type: "udp", + Timeout: 5, + } + e, err = CheckTcp(e, false) + require.Nil(t, err) + assert.True(t, e.Online) + assert.False(t, e.LastCheck.IsZero()) + assert.NotEqual(t, 0, e.PingTime) + assert.NotEqual(t, 0, e.Latency) + }) + + t.Run("Test gRPC Check", func(t *testing.T) { + e := &Service{ + Name: "Example gRPC", + Domain: "localhost", + Port: 15004, + Type: "grpc", + Timeout: 5, + } + e, err = CheckGrpc(e, false) + require.Nil(t, err) + assert.True(t, e.Online) + assert.False(t, e.LastCheck.IsZero()) + assert.NotEqual(t, 0, e.PingTime) + assert.NotEqual(t, 0, e.Latency) + }) + + t.Run("Test ICMP Check", func(t *testing.T) { + e := &Service{ + Name: "Example ICMP", + Domain: "localhost", + Type: "icmp", + Timeout: 5, + } + e, err = CheckIcmp(e, false) + require.Nil(t, err) + assert.True(t, e.Online) + assert.False(t, e.LastCheck.IsZero()) + assert.NotEqual(t, 0, e.PingTime) + assert.NotEqual(t, 0, e.Latency) + }) + t.Run("Test All", func(t *testing.T) { items := All() assert.Len(t, items, 1) diff --git a/utils/utils_custom.go b/utils/utils_custom.go index 66252068..ffa6e8e0 100644 --- a/utils/utils_custom.go +++ b/utils/utils_custom.go @@ -4,8 +4,10 @@ package utils import ( "errors" + "fmt" "os" - "syscall" + "os/exec" + "strings" ) func DirWritable(path string) (bool, error) { @@ -22,13 +24,20 @@ func DirWritable(path string) (bool, error) { return false, errors.New("write permission bit is not set on this file for user") } - var stat syscall.Stat_t - if err = syscall.Stat(path, &stat); err != nil { - return false, errors.New("unable to get stat") - } - - if uint32(os.Geteuid()) != stat.Uid { - return false, errors.New("user doesn't have permission to write to this directory") - } return true, nil } + +func Ping(address string, secondsTimeout int) error { + ping, err := exec.LookPath("ping") + if err != nil { + return err + } + out, _, err := Command(ping, address, "-c 1", fmt.Sprintf("-W %v", secondsTimeout)) + if err != nil { + return err + } + if strings.Contains(out, "Destination Host Unreachable") { + return errors.New("destination host unreachable") + } + return nil +} diff --git a/utils/utils_windows.go b/utils/utils_windows.go index 3082b113..4119c0eb 100644 --- a/utils/utils_windows.go +++ b/utils/utils_windows.go @@ -1,3 +1,5 @@ +// +build windows + package utils import ( @@ -19,5 +21,28 @@ func DirWritable(path string) (bool, error) { return false, errors.New("write permission bit is not set on this file for user") } + var stat syscall.Stat_t + if err = syscall.Stat(path, &stat); err != nil { + return false, errors.New("unable to get stat") + } + + if uint32(os.Geteuid()) != stat.Uid { + return false, errors.New("user doesn't have permission to write to this directory") + } return true, nil } + +func Ping(address string, secondsTimeout int) error { + ping, err := exec.LookPath("ping") + if err != nil { + return err + } + out, _, err := Command(ping, address, "-n 1", fmt.Sprintf("-w %v", timeout*1000)) + if err != nil { + return err + } + if strings.Contains(out, "Destination Host Unreachable") { + return errors.New("destination host unreachable") + } + return nil +}