Skip to content
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

feat: E-mail reporting for the available updates #483

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 17 additions & 1 deletion sbin/patchman
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ from django.conf import settings
from django.core.exceptions import MultipleObjectsReturned
from django.db.models import Count
from django import setup as django_setup
from django.core.mail import mail_admins

django_setup()

Expand Down Expand Up @@ -344,10 +345,25 @@ def host_updates(host=None):
""" Find updates for all hosts, specify host for a single host
"""
hosts = get_hosts(host, 'Finding updates')
updates = []
for host in hosts:
info_message.send(sender=None, text=str(host))
host.find_updates()
var = host.find_updates()
if var:
updates.append({'host': str(host), 'updates': var})
info_message.send(sender=None, text='')
# send notif
if updates:
subject = "Avaibles updates for {} hosts".format(str(len(updates)))
msg = ""
html_msg = ""
for update in updates:
msg += update['host'] + ' :\n'
html_msg += '<h1>' + update['host'] + ' :</h1>\n'
for update_avaible in update['updates']:
msg += '\t' + str(update_avaible) + '\n'
html_msg += '\t' + str(update_avaible) + '\n'
mail_admins(subject=subject, message=msg, html_message=html_msg)


def diff_hosts(hosts):
Expand Down