Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ notifiers:
token: bigsecrettokenhere
room: myroom
username: doge
desktop:
start_stop_message: false
timeout: 2000
units:
- unicorn.service
- nginx.service
Expand Down
50 changes: 50 additions & 0 deletions lib/systemd_mon/notifiers/desktop.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'systemd_mon/error'
require 'systemd_mon/notifiers/base'
require 'systemd_mon/formatters/state_table_formatter'


module SystemdMon::Notifiers
class Desktop < Base
bus = DBus::SessionBus.instance
not_service = bus.service("org.freedesktop.Notifications")
not_object = not_service.object("/org/freedesktop/Notifications")
not_object.introspect
DesktopNotifier = not_object["org.freedesktop.Notifications"]

def initialize(*)
super
if options['start_stop_message']
@startstopmessage = true
else
@startstopmessage = false
end
if options['timeout']
@timeout = timeout
else
@timeout = 2000
end
end


def notify_start!(hostname)
if @startstopmessage
DesktopNotifier.Notify("Systemd_mon", 0, "info", "Started", "", [], {}, @timeout)
end
end

def notify_stop!(hostname)
if @startstopmessage
DesktopNotifier.Notify("Systemd_mon", 0, "info", "Stopped", "", [], {}, @timeout)
end
end

def notify!(notification)
unit = notification.unit
DesktopNotifier.Notify("Systemd_mon", 0, "#{notification.type_text}", "#{unit.name} changed to #{unit.state_change.status_text}", "", [], {}, @timeout)
end
end
end




2 changes: 1 addition & 1 deletion systemd_mon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency "ruby-dbus", "~> 0.11.0"
spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "bundler", ">= 1.6"
spec.add_development_dependency "rake"
end