Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jkaninda/notifier
Email, Telegram, and Mattermost notifier
https://github.com/jkaninda/notifier
Last synced: 10 days ago
JSON representation
Email, Telegram, and Mattermost notifier
- Host: GitHub
- URL: https://github.com/jkaninda/notifier
- Owner: jkaninda
- License: mit
- Created: 2024-08-07T20:59:17.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-09-06T17:15:44.000Z (2 months ago)
- Last Synced: 2024-09-06T20:27:45.494Z (2 months ago)
- Language: Go
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Notifier
Email, Telegram, and Mattermost NotifierThis tool was developed for personal needs.
I use the binary in my Docker Toolkit image to run on Gitlab jobs or Jenkins CI/CD.
This allows me to send notifications via email, Telegram channel, or Mattermost.I wanted to share it with you.
## Build
```sh
go build .
```## Send a mail
```sh
./notifier sendMail --body "Your message" --subject "Your subject"
```
## Attach a file to the mail```sh
./notifier sendMail --body "Your message" --subject "Your subject" --attach photo.jpg
```## Send Telegram Message
```sh
notifier sendMessage --message "Your message"
```
## Run on Docker
```sh
docker run --env-file your-env-file jkaninda/notifier sendMessage --message "Your message"
````.env`
```conf
MAIL_HOST=localhost
MAIL_PORT=1025
[email protected]
MAIL_PASSWORD=password
[email protected]
MAIL_BODY="Lorem Ipsum is simply dummy text of the printing and typesetting industry."
MAIL_SUBJECT="Greetings"
[email protected]## Telegram
TG_TOKEN=
TG_CHAT_ID=
TG_MESSAGE="Lorem Ipsum is simply dummy text of the printing and typesetting industry."
```
## Gitlab CI```yaml
variables:
CI_REGISTRY: ""
CI_REGISTRY_USER: ""
#CI_REGISTRY_PASSWORD: "" ## From Gitlab secret, don't put the password here!!!
CI_DOCKER_FILE: Dockerfile
IMAGE_NAME: jkaninda/sample
IMAGE_TAG: latest
# Telegram
TG_TOKEN: "xxxx"
TG_CHAT_ID: "xxxx"
MAIL_HOST: localhost
MAIL_PORT: 1025
MAIL_USERNAME: [email protected]
MAIL_PASSWORD: password
MAIL_TO: [email protected]
MAIL_BODY: "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
MAIL_SUBJECT: "Gitlab CI Build Completed"
MAIL_FROM: [email protected]
PROJECT_NAME: "Sample API"
build:
image: jkaninda/toolkit
stage: build
only:
- main
# artifacts:
# paths:
# - VERSION
script:
- >
TAG=v1.0-${CI_COMMIT_SHORT_SHA}
# Registry login
- docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
# Docker build and Push
- docker build -f $CI_DOCKER_FILE -t $IMAGE_NAME:$TAG .
- docker tag $IMAGE_NAME:$TAG $IMAGE_NAME:$IMAGE_TAG
- docker push $IMAGE_NAME:$TAG
- docker push $IMAGE_NAME:$IMAGE_TAG
- echo "Build and push completed, new tag is $TAG"
## Send Notification
- |
TG_MESSAGE="
[INFO] --------------------------------------
[INFO] BUILD COMPLETED
[INFO] --------------------------------------
Repository: REPOSITORY_URL
Build and Push Completed
New Image Tag: ${IMAGE_NAME}:${TAG}
State: Completed
You will get an email when the application will start running a new version of deployments.
Note: Full update may take 5-10 minutes, please be patient!
#CI/CD"
- echo "$TG_MESSAGE" # For debugging purposes to see the message
- notifier sendMessage --message "$TG_MESSAGE"
- echo "========================= JOB COMPLETED ================="
tags:
- docker
test:
image: jkaninda/toolkit
stage: test
only:
- main
script:
- >
TAG=v1.0-${CI_COMMIT_SHORT_SHA}
# Test
- echo "Start API Test...."
- echo "Test Completed"
## Send Email
- BUILD_DATE=$(date)
- |
MESSAGE="Hi Team,
Great news! The latest build for Project ${PROJECT_NAME} has successfully passed all tests.
Build Details:
-
Project: ${PROJECT_NAME} -
Branch: main -
Build Number: ${CI_PIPELINE_ID} -
Commit: ${CI_COMMIT_SHA} -
Build Time: ${BUILD_DATE}
Test Summary:
-
Total Tests: 150 -
Passed: 150 -
Failed: 0 -
Skipped: 0
You can view the detailed build report here.
Keep up the great work!
Best,
CI/CD Pipeline
"
- notifier sendMail --body "$MESSAGE" --subject "Gitlab CI Build Completed"
- echo "================= API TEST COMPLETED ======================================="
- echo "========================= JOB COMPLETED ================="
tags:
- docker
```
πππ Enjoy! Welcome star if you like itπ