0

I m trying to make notify-send passing messages to host and create a notification on my desktop from my local-machine.
But its not that simple :(.

My Operation system is Ubuntu and vm machine's Debian.

I know that containers communicating with "bridge" in docker or via "volume"

  1. My approche was to install dbus-monitor,libnotify-bin on virtual machine
  2. Write to file called notofications via demon who intercept notify-send messages.
  3. Than have some sort of deamon on host machine which "watch" that file and everytime a new line of text is being added to that from virtual machine, deamon triggers launch a command notify-send "that line"

Usecase:
I work with docker container workspace.

I m developing websites and I found it pretty annoying that when I m "live building" script and it fails I dont get a notification. So I wanted to get one with having same environment accross my teamates using ddev

Problem:
To intercept and write to file I tried to use dbus but:
my dbus-monitor script:

#!/bin/bash

file=notifications

dbus-monitor "interface='org.freedesktop.Notifications'" |\
 grep --line-buffered "string" |\
 grep --line-buffered -e method -e ":" -e '""' -e urgency -e notify -v |\
 grep --line-buffered '.*(?=string)|(?<=string).*' -oPi |\
 grep --line-buffered -v '^\s*$' |\
 xargs -I '{}' echo {} >> $file

seemss not to work without display configuration. And I have no idea how to fix that.

Failed to open connection to session bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11

In order to work I need to find solution to somehow "watch" notify-send command and intercept the message. Please help :)

Paweł Witek
  • 171
  • 11
  • If you have a listener on the host that can cause the notification to happen, you can do it. But you'll need some kind of proxy on the host to cause the notification. So 1) Set up a TCP listener on the host - could be just netcat, could be piped to how you're doing your notifications. 2) Inside the container, connect to `host.docker.internal` on the port the netcat is listening to and send something that is the content of the notification. – rfay Oct 06 '21 at 20:35
  • 1
    I had the same use case and went with https://www.npmjs.com/package/grunt-bell - that generates a "console bell" which most terminals will change into a notification if the terminal is not in focus. You can try with `while true; do sleep 1; tput bel; done` if that would work for you. – Jonas Eberle Oct 06 '21 at 20:41
  • @JonasEberle I want to use npm packages with gulp instead or webpack. I m using npx wpgulp which is awesome and it uses notify-send. I also can force ddev to lunch some commands on lunch a project like some sort of deamon on host. and deamon on container. – Paweł Witek Oct 07 '21 at 10:38
  • @rfay yeah ure probably right with this communication what I need to implement is some sort of my own notifier package mechanism which send "notifications" from docker container to that "endpoint/port" – Paweł Witek Oct 07 '21 at 10:42
  • When you get it sorted out I hope you'll add an answer here, thanks! – rfay Oct 07 '21 at 13:21
  • I hope you'll answer your own question with the solution you come up with. – rfay Oct 14 '21 at 11:36

0 Answers0