mirror of
https://github.com/absmach/supermq.git
synced 2026-06-23 06:30:22 +00:00
NOISSUE - Move SMPP notifier to Magistrala core (#26)
Signed-off-by: Dusan Borovcanin <borovcanindusan1@gmail.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# SMPP Notifier
|
||||
|
||||
SMPP Notifier implements notifier for send SMS notifications.
|
||||
|
||||
## Configuration
|
||||
|
||||
The Subscription service using SMPP Notifier is configured using the environment variables presented in the
|
||||
following table. Note that any unset variables will be replaced with their
|
||||
default values.
|
||||
|
||||
| Variable | Description | Default |
|
||||
| --------------------------------- | --------------------------------------------------------------------------------- | ------------------------------ |
|
||||
| MG_SMPP_NOTIFIER_LOG_LEVEL | Log level for SMPP Notifier (debug, info, warn, error) | info |
|
||||
| MG_SMPP_NOTIFIER_FROM_ADDRESS | From address for SMS notifications | |
|
||||
| MG_SMPP_NOTIFIER_CONFIG_PATH | Config file path with Message broker subjects list, payload type and content-type | /config.toml |
|
||||
| MG_SMPP_NOTIFIER_HTTP_HOST | Service HTTP host | localhost |
|
||||
| MG_SMPP_NOTIFIER_HTTP_PORT | Service HTTP port | 9014 |
|
||||
| MG_SMPP_NOTIFIER_HTTP_SERVER_CERT | Service HTTP server certificate path | "" |
|
||||
| MG_SMPP_NOTIFIER_HTTP_SERVER_KEY | Service HTTP server key | "" |
|
||||
| MG_SMPP_NOTIFIER_DB_HOST | Database host address | localhost |
|
||||
| MG_SMPP_NOTIFIER_DB_PORT | Database host port | 5432 |
|
||||
| MG_SMPP_NOTIFIER_DB_USER | Database user | magistrala |
|
||||
| MG_SMPP_NOTIFIER_DB_PASS | Database password | magistrala |
|
||||
| MG_SMPP_NOTIFIER_DB_NAME | Name of the database used by the service | subscriptions |
|
||||
| MG_SMPP_NOTIFIER_DB_SSL_MODE | DB connection SSL mode (disable, require, verify-ca, verify-full) | disable |
|
||||
| MG_SMPP_NOTIFIER_DB_SSL_CERT | Path to the PEM encoded certificate file | "" |
|
||||
| MG_SMPP_NOTIFIER_DB_SSL_KEY | Path to the PEM encoded key file | "" |
|
||||
| MG_SMPP_NOTIFIER_DB_SSL_ROOT_CERT | Path to the PEM encoded root certificate file | "" |
|
||||
| MG_SMPP_ADDRESS | SMPP address [host:port] | |
|
||||
| MG_SMPP_USERNAME | SMPP Username | |
|
||||
| MG_SMPP_PASSWORD | SMPP Password | |
|
||||
| MG_SMPP_SYSTEM_TYPE | SMPP System Type | |
|
||||
| MG_SMPP_SRC_ADDR_TON | SMPP source address TON | |
|
||||
| MG_SMPP_DST_ADDR_TON | SMPP destination address TON | |
|
||||
| MG_SMPP_SRC_ADDR_NPI | SMPP source address NPI | |
|
||||
| MG_SMPP_DST_ADDR_NPI | SMPP destination address NPI | |
|
||||
| MG_AUTH_GRPC_URL | Auth service gRPC URL | localhost:7001 |
|
||||
| MG_AUTH_GRPC_TIMEOUT | Auth service gRPC request timeout in seconds | 1s |
|
||||
| MG_AUTH_GRPC_CLIENT_TLS | Auth client TLS flag | false |
|
||||
| MG_AUTH_GRPC_CA_CERT | Path to Auth client CA certs in pem format | "" |
|
||||
| MG_MESSAGE_BROKER_URL | Message broker URL | nats://127.0.0.1:4222 |
|
||||
| MG_JAEGER_URL | Jaeger server URL | http://jaeger:14268/api/traces |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to magistrala call home server | true |
|
||||
| MG_SMPP_NOTIFIER_INSTANCE_ID | SMPP Notifier instance ID | "" |
|
||||
|
||||
## Usage
|
||||
|
||||
Starting service will start consuming messages and sending SMS when a message is received.
|
||||
|
||||
[doc]: https://docs.magistrala.abstractmachines.fr
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package smpp
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
)
|
||||
|
||||
// Config represents SMPP transmitter configuration.
|
||||
type Config struct {
|
||||
Address string `env:"MG_SMPP_ADDRESS" envDefault:""`
|
||||
Username string `env:"MG_SMPP_USERNAME" envDefault:""`
|
||||
Password string `env:"MG_SMPP_PASSWORD" envDefault:""`
|
||||
SystemType string `env:"MG_SMPP_SYSTEM_TYPE" envDefault:""`
|
||||
SourceAddrTON uint8 `env:"MG_SMPP_SRC_ADDR_TON" envDefault:"0"`
|
||||
SourceAddrNPI uint8 `env:"MG_SMPP_DST_ADDR_TON" envDefault:"0"`
|
||||
DestAddrTON uint8 `env:"MG_SMPP_SRC_ADDR_NPI" envDefault:"0"`
|
||||
DestAddrNPI uint8 `env:"MG_SMPP_DST_ADDR_NPI" envDefault:"0"`
|
||||
TLS *tls.Config
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package smpp contains the domain concept definitions needed to
|
||||
// support Magistrala SMS notifications.
|
||||
package smpp
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package smpp
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/absmach/supermq/consumers/notifiers"
|
||||
"github.com/absmach/supermq/pkg/messaging"
|
||||
"github.com/absmach/supermq/pkg/transformers"
|
||||
"github.com/absmach/supermq/pkg/transformers/json"
|
||||
"github.com/fiorix/go-smpp/smpp"
|
||||
"github.com/fiorix/go-smpp/smpp/pdu/pdufield"
|
||||
"github.com/fiorix/go-smpp/smpp/pdu/pdutext"
|
||||
)
|
||||
|
||||
var _ notifiers.Notifier = (*notifier)(nil)
|
||||
|
||||
type notifier struct {
|
||||
transmitter *smpp.Transmitter
|
||||
transformer transformers.Transformer
|
||||
sourceAddrTON uint8
|
||||
sourceAddrNPI uint8
|
||||
destAddrTON uint8
|
||||
destAddrNPI uint8
|
||||
}
|
||||
|
||||
// New instantiates SMTP message notifier.
|
||||
func New(cfg Config) notifiers.Notifier {
|
||||
t := &smpp.Transmitter{
|
||||
Addr: cfg.Address,
|
||||
User: cfg.Username,
|
||||
Passwd: cfg.Password,
|
||||
SystemType: cfg.SystemType,
|
||||
RespTimeout: 3 * time.Second,
|
||||
}
|
||||
t.Bind()
|
||||
ret := ¬ifier{
|
||||
transmitter: t,
|
||||
transformer: json.New([]json.TimeField{}),
|
||||
sourceAddrTON: cfg.SourceAddrTON,
|
||||
destAddrTON: cfg.DestAddrTON,
|
||||
sourceAddrNPI: cfg.SourceAddrNPI,
|
||||
destAddrNPI: cfg.DestAddrNPI,
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (n *notifier) Notify(from string, to []string, msg *messaging.Message) error {
|
||||
send := &smpp.ShortMessage{
|
||||
Src: from,
|
||||
DstList: to,
|
||||
Validity: 10 * time.Minute,
|
||||
SourceAddrTON: n.sourceAddrTON,
|
||||
DestAddrTON: n.destAddrTON,
|
||||
SourceAddrNPI: n.sourceAddrNPI,
|
||||
DestAddrNPI: n.destAddrNPI,
|
||||
Text: pdutext.Raw(msg.GetPayload()),
|
||||
Register: pdufield.NoDeliveryReceipt,
|
||||
}
|
||||
_, err := n.transmitter.Submit(send)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -10,6 +10,7 @@ require (
|
||||
github.com/authzed/grpcutil v0.0.0-20240123194739-2ea1e3d2d98b
|
||||
github.com/caarlos0/env/v11 v11.3.1
|
||||
github.com/eclipse/paho.mqtt.golang v1.5.0
|
||||
github.com/fiorix/go-smpp v0.0.0-20210403173735-2894b96e70ba
|
||||
github.com/go-chi/chi v4.1.2+incompatible
|
||||
github.com/go-chi/chi/v5 v5.2.0
|
||||
github.com/go-kit/kit v0.13.0
|
||||
|
||||
@@ -56,6 +56,7 @@ github.com/containerd/continuity v0.4.3 h1:6HVkalIp+2u1ZLH1J/pYX2oBVXlJZvh1X1A7b
|
||||
github.com/containerd/continuity v0.4.3/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ=
|
||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
@@ -90,6 +91,8 @@ github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/fiorix/go-smpp v0.0.0-20210403173735-2894b96e70ba h1:vBqABUa2HUSc6tj22Tw+ZMVGHuBzKtljM38kbRanmrM=
|
||||
github.com/fiorix/go-smpp v0.0.0-20210403173735-2894b96e70ba/go.mod h1:VfKFK7fGeCP81xEhbrOqUEh45n73Yy6jaPWwTVbxprI=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
|
||||
@@ -334,6 +337,7 @@ github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OK
|
||||
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
|
||||
github.com/rubenv/sql-migrate v1.7.1 h1:f/o0WgfO/GqNuVg+6801K/KW3WdDSupzSjDYODmiUq4=
|
||||
github.com/rubenv/sql-migrate v1.7.1/go.mod h1:Ob2Psprc0/3ggbM6wCzyYVFFuc6FyZrb2AS+ezLDFb4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sagikazarmark/locafero v0.6.0 h1:ON7AQg37yzcRPU69mt7gwhFEBwxI6P9T4Qu3N51bwOk=
|
||||
github.com/sagikazarmark/locafero v0.6.0/go.mod h1:77OmuIc6VTraTXKXIs/uvUxKGUXjE1GbemJYHqdNjX0=
|
||||
@@ -346,6 +350,7 @@ github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
|
||||
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
|
||||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
@@ -388,6 +393,7 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
||||
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||
@@ -545,6 +551,9 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
|
||||
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/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=
|
||||
|
||||
Reference in New Issue
Block a user