diff --git a/cron_failure_notification/README.rst b/cron_failure_notification/README.rst new file mode 100644 index 000000000..7ec198b7b --- /dev/null +++ b/cron_failure_notification/README.rst @@ -0,0 +1,31 @@ +Cron Job Failure Notifications v9 +================================= +This module will generate error Logs for Scheduled Actions / Cron jobs running in backend server. +Purpose of module to have creating history & PDF reports of failure of all jobs in backend. + +Features +======== +* Any failure will automatically logged. +* PDF Report for error logs. +* Custom Error Logs Scheduled Actions Email Template. + +Installation +============ +No other requirements. + +To test the module: +- Activate Developer mode +- Go to Settings --> Technical --> Automation --> Scheduled actions. +- Select the record "Test Cron Failure Notification" and check active button. +- Click the button 'Run Manually'. +- A log of scheduler failure will be created under the menu 'Logs Scheduled Actions'. + +Configuration +============= +To analyse/test the log history of cron failure, +Go to Settings --> Technical --> Automation --> Logs Scheduled Actions. + +Credits +======= +Developer: Mufeeda C K @ cybrosys +Guidance: Nilmar Shereef @ cybrosys, shereef@cybrosys.in diff --git a/cron_failure_notification/__init__.py b/cron_failure_notification/__init__.py new file mode 100644 index 000000000..b2462eb50 --- /dev/null +++ b/cron_failure_notification/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2009-TODAY Cybrosys Technologies(). +# Author: Nilmar Shereef() +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## +import models diff --git a/cron_failure_notification/__openerp__.py b/cron_failure_notification/__openerp__.py new file mode 100644 index 000000000..b66d9fe7a --- /dev/null +++ b/cron_failure_notification/__openerp__.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2009-TODAY Cybrosys Technologies(). +# Author: Nilmar Shereef() +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## +{ + 'name': "Cron Job Failure Notification", + 'summary': """Cron jobs/Scheduled Actions failure Log Notification & Its PDF Reports""", + 'description': """ + This module will generate error Logs for Scheduled + Actions / Cron jobs running in backend server + """, + 'author': "Cybrosys Techno Solution", + 'website': "http://www.cybrosys.com", + 'category': 'Extra Tools', + 'depends': ['base', 'mail', 'web', 'base_setup'], + 'data': [ + 'views/logs_scheduled_actions_view.xml', + 'views/error_log_report_template.xml', + 'views/report.xml', + 'views/error_mail_template.xml', + ], + 'demo': [ + 'demo/ir_cron_demo.xml', + ], + 'images': ['static/description/banner.jpg'], + 'license': 'AGPL-3', + 'installable': True, + 'auto_install': False, + 'application': False, +} diff --git a/cron_failure_notification/demo/ir_cron_demo.xml b/cron_failure_notification/demo/ir_cron_demo.xml new file mode 100644 index 000000000..dc658525b --- /dev/null +++ b/cron_failure_notification/demo/ir_cron_demo.xml @@ -0,0 +1,19 @@ + + + + + + Test Cron Failure Notification + + + 1 + hours + -1 + + + ir.cron + _test_scheduler_failure + + + + diff --git a/cron_failure_notification/models/__init__.py b/cron_failure_notification/models/__init__.py new file mode 100644 index 000000000..806b49499 --- /dev/null +++ b/cron_failure_notification/models/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2009-TODAY Cybrosys Technologies(). +# Author: Nilmar Shereef() +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## +import logs_scheduled_actions diff --git a/cron_failure_notification/models/logs_scheduled_actions.py b/cron_failure_notification/models/logs_scheduled_actions.py new file mode 100644 index 000000000..1e3e1764c --- /dev/null +++ b/cron_failure_notification/models/logs_scheduled_actions.py @@ -0,0 +1,115 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2009-TODAY Cybrosys Technologies(). +# Author: Nilmar Shereef() +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## +import datetime +import logging +from openerp import models, fields, api, _ +from openerp.exceptions import UserError + + +class LogsScheduledActions(models.Model): + _description = "Error log" + _name = 'logs.action' + _inherit = ['mail.thread', 'ir.needaction_mixin', 'ir.cron'] + + name = fields.Char(string="Name", required=True, track_visibility='always') + method = fields.Char(string="Method", track_visibility='always') + created_by = fields.Many2one('res.users', string="Created by", default=lambda self: self.env.user, index=True) + object_action = fields.Char(string="Object", track_visibility='always') + exec_date = fields.Datetime(string="Execution Date Time") + company_name = fields.Many2one('res.company', string="Company", default=lambda self: self.env.user.company_id, + index=True) + stages_id = fields.Selection( + [('new', 'New'), ('confirm', 'Confirmed'), ('resolved', 'Resolved'), ('cancelled', 'Cancelled')], string="State", default='new') + error_details = fields.Char(string="Error details", track_visibility='always') + + @api.multi + def action_mail_send(self): + self.ensure_one() + ir_model_data = self.env['ir.model.data'] + template_id = ir_model_data.get_object_reference('cron_failure_notification', + 'scheduler_error_mailer')[1] + try: + compose_form_id = ir_model_data.get_object_reference('mail', 'email_compose_message_wizard_form')[1] + except ValueError: + compose_form_id = False + ctx = dict(self.env.context or {}) + ctx.update({ + 'default_model': 'logs.action', + 'default_res_id': self.ids[0], + 'default_use_template': bool(template_id), + 'default_template_id': template_id, + 'default_composition_mode': 'comment', + }) + + return { + 'name': _('Compose Email'), + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'mail.compose.message', + 'views': [(compose_form_id, 'form')], + 'view_id': compose_form_id, + 'target': 'new', + 'context': ctx, + } + + @api.multi + def button_confirm_action(self): + self.write({'stages_id': 'confirm'}) + + @api.multi + def button_resolved_action(self): + self.write({'stages_id': 'resolved'}) + + @api.multi + def button_cancel_action(self): + self.write({'stages_id': 'cancelled'}) + +_logger = logging.getLogger(__name__) + + +class IrCron(models.Model): + _inherit = "ir.cron" + + @api.model + def _handle_callback_exception( + self, model_name, method_name, args, job_id, job_exception): + res = super(IrCron, self)._handle_callback_exception( + model_name, method_name, args, job_id, job_exception) + my_cron = self.browse(job_id) + self.env['logs.action'].create({ + 'name': my_cron.name, + 'method': my_cron.model, + 'object_action': my_cron.function, + 'exec_date': datetime.datetime.now(), + 'error_details': str(job_exception), + }) + + return res + + @api.model + def _test_scheduler_failure(self): + """This function is used to test and debug this module""" + + raise UserError( + _("Task failure with UID = %d.") % self._uid) diff --git a/cron_failure_notification/static/description/banner.jpg b/cron_failure_notification/static/description/banner.jpg new file mode 100644 index 000000000..7521f7554 Binary files /dev/null and b/cron_failure_notification/static/description/banner.jpg differ diff --git a/cron_failure_notification/static/description/cybro_logo.png b/cron_failure_notification/static/description/cybro_logo.png new file mode 100644 index 000000000..bb309114c Binary files /dev/null and b/cron_failure_notification/static/description/cybro_logo.png differ diff --git a/cron_failure_notification/static/description/icon.png b/cron_failure_notification/static/description/icon.png new file mode 100644 index 000000000..941f25e18 Binary files /dev/null and b/cron_failure_notification/static/description/icon.png differ diff --git a/cron_failure_notification/static/description/index.html b/cron_failure_notification/static/description/index.html new file mode 100644 index 000000000..06f2d6ec6 --- /dev/null +++ b/cron_failure_notification/static/description/index.html @@ -0,0 +1,71 @@ +
+
+

Cron Job Failure Notification

+

Error Logs for Scheduled Actions/Cron jobs running in backend server.

+

Cybrosys Technologies , www.cybrosys.com

+ +
+
+

Major Features:

+
    +
  •    Creating Failure History for All Jobs in Backend.
  • +
  •    Failure Report Will Automatically Logged.
  • +
  •    Administrator Can Review Logs.
  • +
  •    Send Report to Support/Technical Team by Email Button.
  • +
  •    Custom Email Template for Sending Mail with Failure Details.
  • +
+
+
+ +
+

Error Logs Scheduled Actions - Form View

+
+ +
+
+ +
+

Print PDF Report- Error Logs Scheduled

+
+ +
+
+ +
+

Send By Email - Error Logs Scheduled Actions Attaching PDF Report

+
+ +
+
+ +
+

How to test this module ?

+
+

+

    +
  • Activate Developer mode.
  • +
  • Go to Settings --> Technical --> Automation --> Scheduled actions.
  • +
  • Select the record "Test Cron Failure Notification" and check active button.
  • +
  • Click the button 'Run Manually'.
  • +
  • A log of scheduler failure will be created under the menu 'Logs Scheduled Actions'.
  • +
  • For more details, Please see the README.rst file with this module.
  • +
+

+
+
+ +
+

Need Any Help?

+ + +
\ No newline at end of file diff --git a/cron_failure_notification/static/description/logs_form_view.png b/cron_failure_notification/static/description/logs_form_view.png new file mode 100644 index 000000000..ed57786cd Binary files /dev/null and b/cron_failure_notification/static/description/logs_form_view.png differ diff --git a/cron_failure_notification/static/description/logs_mail_template.png b/cron_failure_notification/static/description/logs_mail_template.png new file mode 100644 index 000000000..1dd3dad1b Binary files /dev/null and b/cron_failure_notification/static/description/logs_mail_template.png differ diff --git a/cron_failure_notification/static/description/logs_pdf_report.png b/cron_failure_notification/static/description/logs_pdf_report.png new file mode 100644 index 000000000..d296ea061 Binary files /dev/null and b/cron_failure_notification/static/description/logs_pdf_report.png differ diff --git a/cron_failure_notification/views/error_log_report_template.xml b/cron_failure_notification/views/error_log_report_template.xml new file mode 100644 index 000000000..281f485b6 --- /dev/null +++ b/cron_failure_notification/views/error_log_report_template.xml @@ -0,0 +1,54 @@ + + + + + + + + + diff --git a/cron_failure_notification/views/error_mail_template.xml b/cron_failure_notification/views/error_mail_template.xml new file mode 100644 index 000000000..6c685c318 --- /dev/null +++ b/cron_failure_notification/views/error_mail_template.xml @@ -0,0 +1,25 @@ + + + + + + + + Scheduler Error + ${object.user_id.email} + '${object.name}' FAILED + + + + + +

Here we are attaching error logs from scheduled cron jobs on our server, so please + urgently take action.
If you have any question, don't hesitate to contact us.


+ Thank You. + ]]> +
+
+ +
+
\ No newline at end of file diff --git a/cron_failure_notification/views/logs_scheduled_actions_view.xml b/cron_failure_notification/views/logs_scheduled_actions_view.xml new file mode 100644 index 000000000..87b3961e2 --- /dev/null +++ b/cron_failure_notification/views/logs_scheduled_actions_view.xml @@ -0,0 +1,77 @@ + + + + + DeveloperMode + + + + + '%s%sdebug=1' % (redirect or '/web', redirect and '?' in redirect and '&' or '?') + + + + + logs.action.form + logs.action + form + form + +
+
+
+ + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+ + + logs.action.tree + logs.action + + + + + + + + + + + Logs Scheduled Actions + logs.action + form + form,tree + + + + +
+
\ No newline at end of file diff --git a/cron_failure_notification/views/report.xml b/cron_failure_notification/views/report.xml new file mode 100644 index 000000000..855f20369 --- /dev/null +++ b/cron_failure_notification/views/report.xml @@ -0,0 +1,12 @@ + + + + +