Compare commits

...

11 Commits

Author SHA1 Message Date
Hugo
ef76d9889e
Merge 8ea7456812d6f8b53d11c2aa26f6a2645b83322f into 7da210906c67343dec629004bf9696b4030e7c12 2025-11-24 09:31:34 +01:00
Bernhard B
7da210906c free up some disk space 2025-11-23 23:30:40 +01:00
Bernhard B
e41bec91a0 clean up free disk space 2025-11-23 23:27:20 +01:00
Bernhard B
142a7c2eb6 avoid running out of disk space during docker image building
* remove unnecessary data from base image to avoid running out
  of disk space during docker image building.
2025-11-23 21:54:58 +01:00
Bernhard B
c049764d3b updated signal-cli to v0.13.22 2025-11-23 17:58:01 +01:00
Bernhard B.
452d899f07
Merge pull request #764 from bbernhard/dependabot/go_modules/src/golang.org/x/crypto-0.45.0
Bump golang.org/x/crypto from 0.36.0 to 0.45.0 in /src
2025-11-20 22:17:31 +01:00
dependabot[bot]
b6f619b7db
Bump golang.org/x/crypto from 0.36.0 to 0.45.0 in /src
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.36.0 to 0.45.0.
- [Commits](https://github.com/golang/crypto/compare/v0.36.0...v0.45.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-version: 0.45.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-20 02:01:57 +00:00
Bernhard B.
565b0dbf86
Merge pull request #763 from emrikol/patch-1
Fix typo in HOMEASSISTANT.md
2025-11-19 20:10:56 +01:00
Derrick Tennant
ec9cd56c0d
Fix typo in HOMEASSISTANT.md 2025-11-18 19:53:49 -05:00
Hugo
8ea7456812
Add files via upload
added 2 API registrations :

/api/v2/sendalertmanager
/api/v2/sendgraylognotification
2024-12-24 08:45:50 +01:00
Hugo
95c14a5f2b
Add files via upload
Additional functions to process calls from Graylog or Grafana. Grafana uses the AlertManager structure, so all tools using this structure can use this.
2024-12-24 08:43:15 +01:00
10 changed files with 245 additions and 26 deletions

View File

@ -20,6 +20,8 @@ jobs:
run: echo ${{ steps.buildx.outputs.platforms }}
- name: Install Podman
run: sudo apt update && sudo apt install -y podman
- name: Free up some disk space
run: sudo apt-get remove -y '^aspnetcore-.*' && sudo apt-get remove -y '^dotnet-.*' --fix-missing && sudo apt-get remove -y 'php.*' --fix-missing && sudo apt-get remove -y '^mongodb-.*' --fix-missing && sudo apt-get remove -y '^mysql-.*' --fix-missing && sudo apt-get remove -y google-cloud-sdk --fix-missing && sudo apt-get autoremove -y && sudo apt-get clean && sudo rm -rf /usr/share/dotnet && sudo rm -rf /usr/local/lib/android
build:
runs-on: ubuntu-24.04
needs: setup

View File

@ -1,6 +1,6 @@
ARG SIGNAL_CLI_VERSION=0.13.21
ARG LIBSIGNAL_CLIENT_VERSION=0.84.0
ARG SIGNAL_CLI_NATIVE_PACKAGE_VERSION=0.13.21+morph027+2
ARG SIGNAL_CLI_VERSION=0.13.22
ARG LIBSIGNAL_CLIENT_VERSION=0.86.1
ARG SIGNAL_CLI_NATIVE_PACKAGE_VERSION=0.13.22+morph027+1
ARG SWAG_VERSION=1.16.4
ARG GRAALVM_VERSION=21.0.0

View File

@ -29,7 +29,7 @@ services:
signal-cli-rest-api:
image: bbernhard/signal-cli-rest-api:latest
environment:
- MODE=json-rpc #supported modes: json-rpc, native, normal. json-prc is recommended for speed
- MODE=json-rpc #supported modes: json-rpc, native, normal. json-rpc is recommended for speed
ports:
- "8080:8080" # map docker port 8080 to host port 8080.
volumes:

211
src/api/graylogapi.go Normal file
View File

@ -0,0 +1,211 @@
package api
import (
"encoding/json"
"errors"
"strconv"
"strings"
"fmt"
_ "runtime/debug"
_ "github.com/yassinebenaid/godump"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"github.com/bbernhard/signal-cli-rest-api/client"
)
type AlertManagerNotification struct {
Receiver string `json:"receiver"`
Status string `json:"status"`
Alerts []Alert `json:"alerts"`
GroupLabels Labels `json:"groupLabels"`
CommonLabels Labels `json:"commonLabels"`
CommonAnnotations Annotations `json:"commonAnnotations"`
ExternalURL string `json:"externalURL"`
Version string `json:"version"`
GroupKey string `json:"groupKey"`
TruncatedAlerts int64 `json:"truncatedAlerts"`
OrgID int64 `json:"orgId"`
Title string `json:"title"`
State string `json:"state"`
Message string `json:"message"`
}
type Alert struct {
Status string `json:"status"`
Labels Labels `json:"labels"`
Annotations Annotations `json:"annotations"`
StartsAt string `json:"startsAt"`
EndsAt string `json:"endsAt"`
GeneratorURL string `json:"generatorURL"`
Fingerprint string `json:"fingerprint"`
SilenceURL string `json:"silenceURL"`
DashboardURL string `json:"dashboardURL"`
PanelURL string `json:"panelURL"`
Values interface{} `json:"values"`
ValueString string `json:"valueString"`
}
type Annotations struct {
Summary string `json:"summary"`
}
type Labels struct {
Alertname string `json:"alertname"`
Instance string `json:"instance"`
}
type GrafanaMessage struct {
Number string `json:"number"`
Recipients string `json:"recipients"`
Message string `json:"message"`
}
type GraylogNotification struct {
EventDefinitionID string `json:"event_definition_id"`
EventDefinitionType string `json:"event_definition_type"`
EventDefinitionTitle string `json:"event_definition_title"`
EventDefinitionDescription string `json:"event_definition_description"`
JobDefinitionID string `json:"job_definition_id"`
JobTriggerID string `json:"job_trigger_id"`
Event GraylogEvent `json:"event"`
Backlog []interface{} `json:"backlog"`
}
type GraylogEvent struct {
ID string `json:"id"`
EventDefinitionType string `json:"event_definition_type"`
EventDefinitionID string `json:"event_definition_id"`
OriginContext string `json:"origin_context"`
Timestamp string `json:"timestamp"`
TimestampProcessing string `json:"timestamp_processing"`
TimerangeStart interface{} `json:"timerange_start"`
TimerangeEnd interface{} `json:"timerange_end"`
Streams []string `json:"streams"`
SourceStreams []interface{} `json:"source_streams"`
Message string `json:"message"`
Source string `json:"source"`
KeyTuple []string `json:"key_tuple"`
Key string `json:"key"`
Priority int64 `json:"priority"`
Alert bool `json:"alert"`
Fields Fields `json:"fields"`
}
type Fields struct {
Recipients string `json:"recipients"`
FromNumber string `json:"fromnumber"`
Message string `json:"message"`
}
// @Summary Send a signal message.
// @Tags Messages
// @Description Send a signal message. Set the text_mode to 'styled' in case you want to add formatting to your text message. Styling Options: *italic text*, **bold text**, ~strikethrough text~.
// @Accept json
// @Produce json
// @Success 201 {object} SendMessageResponse
// @Failure 400 {object} SendMessageError
// @Param data body SendMessageV2 true "Input Data"
// @Router /v2/send [post]
func (a *Api) SendAlertManagerV2(c *gin.Context) {
var req AlertManagerNotification
var msg GrafanaMessage
base64Attachments := []string{}
err := c.BindJSON(&req)
if err != nil {
c.JSON(400, gin.H{"error": "Couldn't process request - invalid request"})
log.Error(err.Error())
return
}
//fmt.Printf(">>>%s\n",[]byte(req.Message))
// Unmarshal or Decode the JSON to the interface.
json.Unmarshal([]byte(req.Message), &msg)
// timestamp, err := a.signalClient.SendV1(msg.Number, msg.Message, msg.Recipients, base64Attachments, msg.IsGroup)
// if err != nil {
// c.JSON(400, Error{Msg: err.Error()})
// return
// }
// c.JSON(201, SendMessageResponse{Timestamp: strconv.FormatInt(timestamp.Timestamp, 10)})
data, err := a.signalClient.SendV2(msg.Number, msg.Message, strings.Split(msg.Recipients,","), base64Attachments, "", nil, nil, nil, nil, nil, nil, nil, nil)
if err != nil {
switch err.(type) {
case *client.RateLimitErrorType:
if rateLimitError, ok := err.(*client.RateLimitErrorType); ok {
extendedError := errors.New(err.Error() + ". Use the attached challenge tokens to lift the rate limit restrictions via the '/v1/accounts/{number}/rate-limit-challenge' endpoint.")
c.JSON(429, SendMessageError{Msg: extendedError.Error(), ChallengeTokens: rateLimitError.ChallengeTokens, Account: msg.Number})
return
} else {
c.JSON(400, Error{Msg: err.Error()})
return
}
default:
c.JSON(400, Error{Msg: err.Error()})
return
}
c.JSON(400, Error{Msg: err.Error()})
return
}
c.JSON(201, SendMessageResponse{Timestamp: strconv.FormatInt((*data)[0].Timestamp, 10)})
}
// @Summary Send a signal message.
// @Tags Messages
// @Description Send a signal message. Set the text_mode to 'styled' in case you want to add formatting to your text message. Styling Options: *italic text*, **bold text**, ~strikethrough text~.
// @Accept json
// @Produce json
// @Success 201 {object} SendMessageResponse
// @Failure 400 {object} SendMessageError
// @Param data body SendMessageV2 true "Input Data"
// @Router /v2/send [post]
func (a *Api) SendGraylogNotificationV2(c *gin.Context) {
var req GraylogNotification
base64Attachments := []string{}
// jsonData,err2 := io.ReadAll(c.Request.Body)
//if err2 != nil {
// log.Error(err2.Error())
//}
//fmt.Printf("<<<%s\n",jsonData)
err := c.BindJSON(&req)
if err != nil {
c.JSON(400, gin.H{"error": "Couldn't process request - invalid requestttttt"})
log.Error(err.Error())
fmt.Printf("<<<%s\n",c.Request.Body)
return
}
data, err := a.signalClient.SendV2(req.Event.Fields.FromNumber, req.Event.Fields.Message, strings.Split(req.Event.Fields.Recipients,","), base64Attachments, "", nil, nil, nil, nil, nil, nil, nil, nil)
if err != nil {
switch err.(type) {
case *client.RateLimitErrorType:
if rateLimitError, ok := err.(*client.RateLimitErrorType); ok {
extendedError := errors.New(err.Error() + ". Use the attached challenge tokens to lift the rate limit restrictions via the '/v1/accounts/{number}/rate-limit-challenge' endpoint.")
c.JSON(429, SendMessageError{Msg: extendedError.Error(), ChallengeTokens: rateLimitError.ChallengeTokens, Account: req.Event.Fields.FromNumber})
return
} else {
c.JSON(400, Error{Msg: err.Error()})
return
}
default:
c.JSON(400, Error{Msg: err.Error()})
return
}
c.JSON(400, Error{Msg: err.Error()})
return
}
c.JSON(201, SendMessageResponse{Timestamp: strconv.FormatInt((*data)[0].Timestamp, 10)})
}

View File

@ -1,8 +1,6 @@
module github.com/bbernhard/signal-cli-rest-api
go 1.23.0
toolchain go1.23.4
go 1.24.0
require (
github.com/cjoudrey/gluahttp v0.0.0-20201111170219-25003d9adfa9
@ -54,11 +52,11 @@ require (
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.14.0 // indirect
golang.org/x/crypto v0.36.0 // indirect
golang.org/x/net v0.38.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/text v0.23.0 // indirect
golang.org/x/tools v0.29.0 // indirect
golang.org/x/crypto v0.45.0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/tools v0.38.0 // indirect
google.golang.org/protobuf v1.36.4 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@ -128,21 +128,21 @@ golang.org/x/arch v0.14.0 h1:z9JUEZWr8x4rR0OU6c4/4t6E6jOZ8/QBS2bBYBm4tx4=
golang.org/x/arch v0.14.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=
golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/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-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -152,8 +152,8 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
@ -161,13 +161,13 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.29.0 h1:Xx0h3TtM9rzQpQuR4dKLrdglAmCEN5Oi+P74JdhdzXE=
golang.org/x/tools v0.29.0/go.mod h1:KMQVMRsVxU6nHCFXrBPhDB8XncLNLM0lIy/F14RP588=
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM=
google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=

View File

@ -356,6 +356,14 @@ func main() {
{
sendV2.POST("", api.SendV2)
}
sendalertmanagerV2 := v2.Group("/sendalertmanager")
{
sendalertmanagerV2.POST("", api.SendAlertManagerV2)
}
sendgraylognotificationV2 := v2.Group("/sendgraylognotification")
{
sendgraylognotificationV2.POST("", api.SendGraylogNotificationV2)
}
}
protocol := "http"