-
Notifications
You must be signed in to change notification settings - Fork 67
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
[WIP] - add custom notification for scan jobs #326
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module ForemanOpenscap | ||
class NotificationBuilder < ::UINotifications::RemoteExecutionJobs::BaseJobFinish | ||
def deliver! | ||
::Notification.create!( | ||
:audience => Notification::AUDIENCE_USER, | ||
:notification_blueprint => blueprint, | ||
:initiator => initiator, | ||
:message => message, | ||
:subject => subject, | ||
:actions => { | ||
:links => links | ||
} | ||
) | ||
end | ||
|
||
def blueprint | ||
@blueprint ||= NotificationBlueprint.unscoped.find_by(:name => 'openscap_scan_succeeded') | ||
end | ||
|
||
def hosts_count | ||
@hosts_count ||= subject.template_invocations_hosts.size | ||
end | ||
|
||
def message | ||
UINotifications::StringParser.new(blueprint.message, { hosts_count: hosts_count }) | ||
end | ||
|
||
def links | ||
job_links + scap_links | ||
end | ||
|
||
# TODO do this only if there's single host | ||
# TODO also add link to policies dashboards for a given host | ||
def scap_links | ||
UINotifications::URLResolver.new( | ||
subject.template_invocations_hosts.first, | ||
{ | ||
:links => [{ | ||
:path_method => :host_path, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is. |
||
:title => _('Scanned Host') | ||
}] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indent the right brace the same as the start of the line where the left brace is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indent the right brace the same as the start of the line where the left brace is. |
||
} | ||
).actions[:links] | ||
end | ||
|
||
def job_links | ||
UINotifications::URLResolver.new( | ||
subject, | ||
{ | ||
:links => [{ | ||
:path_method => :job_invocation_path, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is. |
||
:title => _('Job Details') | ||
}] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indent the right brace the same as the start of the line where the left brace is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indent the right brace the same as the start of the line where the left brace is. |
||
} | ||
).actions[:links] | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
blueprints = [ | ||
{ | ||
group: N_('Jobs'), | ||
name: 'openscap_scan_succeeded', | ||
message: N_("OpenSCAP scan on %{hosts_count} host(s) has finished successfully"), | ||
level: 'success', | ||
actions: | ||
{ | ||
links: | ||
[ | ||
path_method: :job_invocation_path, | ||
title: N_('Job Details') | ||
] | ||
} | ||
} | ||
] | ||
|
||
blueprints.each { |blueprint| UINotifications::Seed.new(blueprint).configure } |
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.
Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.