Skip to content

Commit d13fef8

Browse files
committed
Use icinga-go-library
1 parent 404fcec commit d13fef8

File tree

18 files changed

+135
-148
lines changed

18 files changed

+135
-148
lines changed

cmd/icinga-notifications-daemon/main.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import (
44
"context"
55
"flag"
66
"fmt"
7+
"github.com/icinga/icinga-go-library/database"
8+
"github.com/icinga/icinga-go-library/driver"
9+
"github.com/icinga/icinga-go-library/logging"
10+
"github.com/icinga/icinga-go-library/utils"
711
"github.com/icinga/icinga-notifications/internal"
812
"github.com/icinga/icinga-notifications/internal/config"
913
"github.com/icinga/icinga-notifications/internal/listener"
10-
"github.com/icinga/icingadb/pkg/logging"
11-
"github.com/icinga/icingadb/pkg/utils"
1214
"go.uber.org/zap"
1315
"os"
1416
"runtime"
@@ -61,7 +63,13 @@ func main() {
6163

6264
logger := logs.GetLogger()
6365
logger.Infof("Starting Icinga Notifications daemon (%s)", internal.Version.Version)
64-
db, err := conf.Database.Open(logs.GetChildLogger("database"))
66+
67+
dbLogger := logs.GetChildLogger("database")
68+
// Icinga GO Library doesn't take care of the SQL drivers registration automatically.
69+
// So, we have to do it on our own.
70+
driver.Register(dbLogger)
71+
72+
db, err := database.NewDbFromConfig(&conf.Database, dbLogger)
6573
if err != nil {
6674
logger.Fatalw("cannot create database connection from config", zap.Error(err))
6775
}

go.mod

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,29 @@ go 1.20
55
require (
66
github.com/creasty/defaults v1.7.0
77
github.com/goccy/go-yaml v1.11.2
8-
github.com/icinga/icingadb v1.1.1-0.20230418113126-7c4b947aad3a
8+
github.com/icinga/icinga-go-library v0.0.0-20231010133022-ee8ee635e589
99
github.com/jmoiron/sqlx v1.3.5
1010
github.com/stretchr/testify v1.8.4
1111
github.com/teambition/rrule-go v1.8.2
1212
go.uber.org/zap v1.26.0
13-
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d
13+
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
1414
)
1515

1616
require (
17-
github.com/cespare/xxhash/v2 v2.1.2 // indirect
1817
github.com/davecgh/go-spew v1.1.1 // indirect
19-
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
2018
github.com/fatih/color v1.13.0 // indirect
21-
github.com/go-redis/redis/v8 v8.11.5 // indirect
22-
github.com/go-sql-driver/mysql v1.6.0 // indirect
23-
github.com/google/uuid v1.3.0 // indirect
19+
github.com/go-sql-driver/mysql v1.7.1 // indirect
20+
github.com/google/uuid v1.3.1 // indirect
2421
github.com/jessevdk/go-flags v1.5.0 // indirect
25-
github.com/lib/pq v1.10.7 // indirect
22+
github.com/lib/pq v1.10.9 // indirect
2623
github.com/mattn/go-colorable v0.1.13 // indirect
2724
github.com/mattn/go-isatty v0.0.16 // indirect
2825
github.com/pkg/errors v0.9.1 // indirect
2926
github.com/pmezard/go-difflib v1.0.0 // indirect
3027
github.com/ssgreg/journald v1.0.0 // indirect
3128
go.uber.org/multierr v1.10.0 // indirect
32-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
33-
golang.org/x/sys v0.6.0 // indirect
29+
golang.org/x/sync v0.4.0 // indirect
30+
golang.org/x/sys v0.13.0 // indirect
3431
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
3532
gopkg.in/yaml.v3 v3.0.1 // indirect
3633
)

go.sum

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,39 @@
1-
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
2-
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
31
github.com/creasty/defaults v1.7.0 h1:eNdqZvc5B509z18lD8yc212CAqJNvfT1Jq6L8WowdBA=
42
github.com/creasty/defaults v1.7.0/go.mod h1:iGzKe6pbEHnpMPtfDXZEr0NVxWnPTjb1bbDy08fPzYM=
53
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
64
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7-
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
8-
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
95
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
106
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
11-
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
127
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
138
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
149
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
15-
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
16-
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
17-
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
1810
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
11+
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
12+
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
1913
github.com/goccy/go-yaml v1.11.2 h1:joq77SxuyIs9zzxEjgyLBugMQ9NEgTWxXfz2wVqwAaQ=
2014
github.com/goccy/go-yaml v1.11.2/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU=
2115
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
22-
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
23-
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
24-
github.com/icinga/icingadb v1.1.1-0.20230418113126-7c4b947aad3a h1:NfVdBKa4dhPk7IU8u0MOF6ywi0LDpMkQMGs1j803+3c=
25-
github.com/icinga/icingadb v1.1.1-0.20230418113126-7c4b947aad3a/go.mod h1:zamCKaKn4JJQinctcUyewTSNNXDfpLc0HSbqb+9lTYs=
16+
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
17+
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
18+
github.com/icinga/icinga-go-library v0.0.0-20231010133022-ee8ee635e589 h1:t89ip4LnjrVGAPGZIG2WVz7TrmzfQm9FTZrEKQbz35c=
19+
github.com/icinga/icinga-go-library v0.0.0-20231010133022-ee8ee635e589/go.mod h1:h5vMFSCEkEcj8SSqfEVZt8auPSLiTOkejHvhIqLejik=
2620
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
2721
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
2822
github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g=
2923
github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ=
3024
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
3125
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
32-
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
33-
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
26+
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
27+
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
3428
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
3529
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
3630
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
3731
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
3832
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
3933
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
4034
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
35+
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
4136
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
42-
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
43-
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
44-
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
45-
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
4637
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
4738
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
4839
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -59,24 +50,20 @@ go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8
5950
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
6051
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
6152
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
62-
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d h1:vtUKgx8dahOomfFzLREU8nSv25YHnTgLBn4rDnWZdU0=
63-
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
64-
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0=
65-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
66-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
53+
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
54+
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
55+
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
56+
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
6757
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6858
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6959
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
7060
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7161
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
72-
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
73-
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
74-
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
62+
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
63+
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7564
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
7665
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
7766
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
7867
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
79-
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
80-
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
8168
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
8269
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/config/configfile.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ package config
33
import (
44
"github.com/creasty/defaults"
55
"github.com/goccy/go-yaml"
6-
icingadbConfig "github.com/icinga/icingadb/pkg/config"
6+
"github.com/icinga/icinga-go-library/database"
7+
"github.com/icinga/icinga-go-library/logging"
78
"os"
89
)
910

1011
type ConfigFile struct {
11-
Listen string `yaml:"listen" default:"localhost:5680"`
12-
DebugPassword string `yaml:"debug-password"`
13-
ChannelPluginDir string `yaml:"channel-plugin-dir" default:"/usr/libexec/icinga-notifications/channel"`
14-
Icingaweb2URL string `yaml:"icingaweb2-url"`
15-
Database icingadbConfig.Database `yaml:"database"`
16-
Logging icingadbConfig.Logging `yaml:"logging"`
12+
Listen string `yaml:"listen" default:"localhost:5680"`
13+
DebugPassword string `yaml:"debug-password"`
14+
ChannelPluginDir string `yaml:"channel-plugin-dir" default:"/usr/libexec/icinga-notifications/channel"`
15+
Icingaweb2URL string `yaml:"icingaweb2-url"`
16+
Database database.Config `yaml:"database"`
17+
Logging logging.Config `yaml:"logging"`
1718
}
1819

1920
func FromFile(path string) (*ConfigFile, error) {

internal/config/rule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package config
22

33
import (
44
"context"
5+
"github.com/icinga/icinga-go-library/utils"
56
"github.com/icinga/icinga-notifications/internal/filter"
67
"github.com/icinga/icinga-notifications/internal/rule"
7-
"github.com/icinga/icinga-notifications/internal/utils"
88
"github.com/jmoiron/sqlx"
99
"go.uber.org/zap"
1010
)

internal/config/runtime.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package config
33
import (
44
"context"
55
"database/sql"
6+
"github.com/icinga/icinga-go-library/database"
7+
"github.com/icinga/icinga-go-library/logging"
68
"github.com/icinga/icinga-notifications/internal/channel"
79
"github.com/icinga/icinga-notifications/internal/recipient"
810
"github.com/icinga/icinga-notifications/internal/rule"
911
"github.com/icinga/icinga-notifications/internal/timeperiod"
10-
"github.com/icinga/icingadb/pkg/icingadb"
11-
"github.com/icinga/icingadb/pkg/logging"
1212
"github.com/jmoiron/sqlx"
1313
"go.uber.org/zap"
1414
"sync"
@@ -26,13 +26,13 @@ type RuntimeConfig struct {
2626

2727
logs *logging.Logging
2828
logger *logging.Logger
29-
db *icingadb.DB
29+
db *database.DB
3030

3131
// mu is used to synchronize access to the live ConfigSet.
3232
mu sync.RWMutex
3333
}
3434

35-
func NewRuntimeConfig(db *icingadb.DB, logs *logging.Logging) *RuntimeConfig {
35+
func NewRuntimeConfig(db *database.DB, logs *logging.Logging) *RuntimeConfig {
3636
return &RuntimeConfig{db: db, logs: logs, logger: logs.GetChildLogger("runtime-updates")}
3737
}
3838

internal/config/timeperiod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"context"
55
"database/sql"
66
"fmt"
7+
"github.com/icinga/icinga-go-library/types"
78
"github.com/icinga/icinga-notifications/internal/timeperiod"
8-
"github.com/icinga/icingadb/pkg/types"
99
"github.com/jmoiron/sqlx"
1010
"go.uber.org/zap"
1111
"time"

internal/event/event.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"github.com/icinga/icinga-notifications/internal/utils"
8-
"github.com/icinga/icingadb/pkg/icingadb"
9-
"github.com/icinga/icingadb/pkg/types"
7+
"github.com/icinga/icinga-go-library/database"
8+
"github.com/icinga/icinga-go-library/types"
109
"github.com/jmoiron/sqlx"
1110
"time"
1211
)
@@ -76,15 +75,16 @@ func (e *Event) FullString() string {
7675
}
7776

7877
// Sync transforms this event to *event.EventRow and synchronises with the database.
79-
func (e *Event) Sync(ctx context.Context, tx *sqlx.Tx, db *icingadb.DB, objectId types.Binary) error {
78+
func (e *Event) Sync(ctx context.Context, tx *sqlx.Tx, db *database.DB, objectId types.Binary) error {
8079
if e.ID != 0 {
8180
return nil
8281
}
8382

8483
eventRow := NewEventRow(e, objectId)
85-
eventID, err := utils.InsertAndFetchId(ctx, tx, utils.BuildInsertStmtWithout(db, eventRow, "id"), eventRow)
84+
stmt, _ := db.BuildInsertStmt(eventRow, "id")
85+
eventID, err := db.InsertObtainID(ctx, tx, stmt, eventRow)
8686
if err == nil {
87-
e.ID = eventID
87+
e.ID = eventID.Int64
8888
}
8989

9090
return err
@@ -110,9 +110,9 @@ func NewEventRow(e *Event, objectId types.Binary) *EventRow {
110110
return &EventRow{
111111
Time: types.UnixMilli(e.Time),
112112
ObjectID: objectId,
113-
Type: utils.ToDBString(e.Type),
113+
Type: types.ToString(e.Type),
114114
Severity: e.Severity,
115-
Username: utils.ToDBString(e.Username),
116-
Message: utils.ToDBString(e.Message),
115+
Username: types.ToString(e.Username),
116+
Message: types.ToString(e.Message),
117117
}
118118
}

internal/incident/db_types.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package incident
33
import (
44
"context"
55
"fmt"
6+
"github.com/icinga/icinga-go-library/database"
7+
"github.com/icinga/icinga-go-library/types"
68
"github.com/icinga/icinga-notifications/internal/event"
79
"github.com/icinga/icinga-notifications/internal/recipient"
8-
"github.com/icinga/icinga-notifications/internal/utils"
9-
"github.com/icinga/icingadb/pkg/icingadb"
10-
"github.com/icinga/icingadb/pkg/types"
1110
"github.com/jmoiron/sqlx"
1211
)
1312

@@ -35,20 +34,21 @@ func (i *IncidentRow) Upsert() interface{} {
3534
// Sync synchronizes incidents to the database.
3635
// Fetches the last inserted incident id and modifies this incident's id.
3736
// Returns an error on database failure.
38-
func (i *IncidentRow) Sync(ctx context.Context, tx *sqlx.Tx, db *icingadb.DB, upsert bool) error {
37+
func (i *IncidentRow) Sync(ctx context.Context, tx *sqlx.Tx, db *database.DB, upsert bool) error {
3938
if upsert {
4039
stmt, _ := db.BuildUpsertStmt(i)
4140
_, err := tx.NamedExecContext(ctx, stmt, i)
4241
if err != nil {
4342
return fmt.Errorf("failed to upsert incident: %s", err)
4443
}
4544
} else {
46-
incidentId, err := utils.InsertAndFetchId(ctx, tx, utils.BuildInsertStmtWithout(db, i, "id"), i)
45+
stmt, _ := db.BuildInsertStmt(i, "id")
46+
incidentId, err := db.InsertObtainID(ctx, tx, stmt, i)
4747
if err != nil {
4848
return err
4949
}
5050

51-
i.ID = incidentId
51+
i.ID = incidentId.Int64
5252
}
5353

5454
return nil

0 commit comments

Comments
 (0)