Skip to content

Instantly share code, notes, and snippets.

@Kambaa
Created August 8, 2024 19:32
Show Gist options
  • Save Kambaa/a09d06b9715ead277a1423d2506aac1d to your computer and use it in GitHub Desktop.
Save Kambaa/a09d06b9715ead277a1423d2506aac1d to your computer and use it in GitHub Desktop.
My NTFY notes

NTFY

website: https://ntfy.sh

Docker Compose Example:

services:
  ntfy:
    image: binwiederhier/ntfy
    container_name: ntfy
    command:
      - serve
    environment:
      - TZ=Europe/Istanbul
      - NTFY_BASE_URL=http://ntfy.domain.com.tr
      - NTFY_CACHE_FILE=/var/lib/ntfy/cache.db
      - NTFY_AUTH_FILE=/var/lib/ntfy/auth.db
      # restrict access to everybody/unauthorized
      - NTFY_AUTH_DEFAULT_ACCESS=deny-all
      - NTFY_BEHIND_PROXY=true
      - NTFY_ATTACHMENT_CACHE_DIR=/var/lib/ntfy/attachments
      - NTFY_ENABLE_LOGIN=true
    #user: UID:GID # optional: replace with your own user/group or uid/gid
    volumes:
      - /opt/stacks/ntfy/var/cache/ntfy:/var/cache/ntfy
      - /opt/stacks/ntfy/etc/ntfy:/etc/ntfy
      - /opt/stacks/ntfy/var/lib/ntfy:/var/lib/ntfy
    ports:
      - 11080:80
    healthcheck:
      # optional: remember to adapt the host:port to your environment
      test:
        - CMD-SHELL
        - wget -q --tries=1 http://localhost:80/v1/health -O - | grep -Eo
          '"healthy"\s*:\s*true' || exit 1
      interval: 60s
      timeout: 10s
      retries: 3
      start_period: 40s
    restart: unless-stopped
networks:
  dockge_default:
    external: true

# ayarladıktan sonra sh ile bağlanıp aşağıdaki kod ile bir kullanıcı ekle(add an admin user via these commands after start):
# ntfy user add --role=admin {USERNAME}
# sudo docker exec -it ntfy ntfy user add --role=admin {USERNAME}


# api kullanımı örneği(api usage examples): 
# curl -u USERNAME:PASSWORD -d "Look ma, with auth" https://ntfy.domain.com.tr/some-topic
# curl -H "Authorization: Bearer {YOUR TOKEN}" -d "Look ma, with auth" https://ntfy.domain.com.tr/some-topic

# more on: https://docs.ntfy.sh/publish/

SSH Login Notifications To Ntfy

add these to your /etc/profile

sudo nano /etc/profile

## ssh login notification to ntfy
## https://paramdeo.com/blog/enabling-ssh-login-notifications-using-ntfy

if [ -n "$SSH_CLIENT" ]; then

NTFY="${USER}@$(hostname -f) from $(echo $SSH_CLIENT|awk '{print $1}')"

curl -s -H "Authorization: Bearer {YOUR NTFY ACCESS TOKEN}" -H "Title: SSH Login" -d "$NTFY" https://ntfy.yourdomain.com/{YOUR TOPIC NAME} > /dev/null

fi

Links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment