-
Notifications
You must be signed in to change notification settings - Fork 28
[WIP] Adding Flowdock support #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jsjohnst
wants to merge
1
commit into
joonty:master
Choose a base branch
from
jsjohnst:add_flowdock_support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| require 'systemd_mon/error' | ||
| require 'systemd_mon/notifiers/base' | ||
|
|
||
| begin | ||
| require 'flowdock' | ||
| rescue LoadError | ||
| raise SystemdMon::NotifierDependencyError, "The 'flowdock' gem is required by the flowdock notifier" | ||
| end | ||
|
|
||
| module SystemdMon::Notifiers | ||
| class Flowdock < Base | ||
| def initialize(*) | ||
| super | ||
| self.client = ::Flowdock::Client.new(flow_token: options['token']) | ||
| end | ||
|
|
||
| def notify_start!(hostname) | ||
| thread_id = "systemd_mon-#{hostname}" | ||
| title = "SystemdMon is starting on #{hostname}" | ||
| message = "" | ||
| chat title, message, thread_id, 'green', "starting" | ||
| end | ||
|
|
||
| def notify_stop!(hostname) | ||
| thread_id = "systemd_mon-#{hostname}" | ||
| title = "SystemdMon is stopping on #{hostname}" | ||
| message = "" | ||
| chat title, message, thread_id, 'yellow', "stopping" | ||
| end | ||
|
|
||
| def notify!(notification) | ||
| unit = notification.unit | ||
|
|
||
| title = "#{notification.type_text}: #{unit.name} on #{notification.hostname}: #{unit.state_change.status_text}" | ||
| message = "Systemd unit #{unit.name} on #{notification.hostname} #{unit.state_change.status_text}: #{unit.state.active} (#{unit.state.sub})" | ||
|
|
||
| if unit.state_change.length > 1 | ||
| message << SystemdMon::Formatters::StateTableFormatter.new(unit).as_text | ||
| end | ||
|
|
||
| thread_id = "#{unit.name}-#{notification.hostname}" | ||
|
|
||
| chat title, message, thread_id, color(notification.type), unit.state.active | ||
|
|
||
| log "sent flowdock notification" | ||
| end | ||
|
|
||
| protected | ||
| attr_accessor :client, :options | ||
|
|
||
| def chat(title, message, thread_id, shade, status) | ||
| client.post_to_thread( | ||
| event: "activity", | ||
| title: title, | ||
| external_thread_id: thread_id, | ||
| thread: { | ||
| title: title, | ||
| body: message, | ||
| status: { | ||
| color: shade, | ||
| value: status | ||
| } | ||
| } | ||
| ) | ||
| end | ||
|
|
||
| def color(type) | ||
| case type | ||
| when :alert | ||
| 'red' | ||
| when :warning | ||
| 'yellow' | ||
| when :info | ||
| 'purple' | ||
| else | ||
| 'green' | ||
| end | ||
| end | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to satisfy my OCD, could you get everything in the following hash indented with two spaces instead of a mixture of 2 and 3? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course! Was annoyed by that too, but wanted to make the pull before I fell asleep. Will resolve while testing today
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jsjohnst, much appreciated!