@ -0,0 +1,44 @@ |
|||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg |
|||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html |
|||
:alt: License: AGPL-3 |
|||
|
|||
Cron Failure Notification |
|||
========================= |
|||
* Notify the Admin About Cron Failures Via Mail. |
|||
|
|||
Configuration |
|||
============ |
|||
- Install our custom addon |
|||
|
|||
Company |
|||
------- |
|||
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
|||
|
|||
License |
|||
------- |
|||
General Public License, Version 3 (AGPL V3). |
|||
(http://www.gnu.org/licenses/agpl-3.0-standalone.html) |
|||
|
|||
Credits |
|||
------- |
|||
Developer: (V18) Muhammed Rishad, Contact: odoo@cybrosys.com |
|||
|
|||
Contacts |
|||
-------- |
|||
* Mail Contact : odoo@cybrosys.com |
|||
|
|||
Bug Tracker |
|||
----------- |
|||
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. |
|||
|
|||
Maintainer |
|||
========== |
|||
.. image:: https://cybrosys.com/images/logo.png |
|||
:target: https://cybrosys.com |
|||
This module is maintained by Cybrosys Technologies. |
|||
|
|||
For support and more information, please visit https://www.cybrosys.com |
|||
|
|||
Further information |
|||
=================== |
|||
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,23 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2025-TODAY Cybrosys Technologies( |
|||
# <https://www.cybrosys.com>). |
|||
# Author: MUHAMMED RISHAD (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
################################################################################ |
|||
from . import models |
@ -0,0 +1,47 @@ |
|||
# -*- coding: utf-8 -*- |
|||
################################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2025-TODAY Cybrosys Technologies( |
|||
# <https://www.cybrosys.com>). |
|||
# Author: MUHAMMED RISHAD (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
################################################################################ |
|||
{ |
|||
'name': "Cron Failure Notification", |
|||
'version': '18.0.1.0.0', |
|||
'category': 'Discuss', |
|||
'summary': 'Notify the Admin About Cron Failures Via Mail', |
|||
'description': """This module helps to send notification to admin with |
|||
lists of failed scheduled actions.""", |
|||
'author': 'Cybrosys Techno Solutions', |
|||
'company': 'Cybrosys Techno Solutions', |
|||
'maintainer': 'Cybrosys Techno Solutions', |
|||
'website': 'https://www.cybrosys.com', |
|||
'depends': ['base', 'mail'], |
|||
'data': ['security/ir.model.access.csv', |
|||
'report/ir_cron_failure_templates.xml', |
|||
'report/ir_cron_reports.xml', |
|||
'data/failure_mail_data.xml', |
|||
'data/mail_template_data.xml', |
|||
'views/ir_cron_views.xml', |
|||
'views/failure_history_views.xml'], |
|||
'images': ['static/description/banner.png'], |
|||
'license': 'AGPL-3', |
|||
'installable': True, |
|||
'auto_install': False, |
|||
'application': False, |
|||
} |
@ -0,0 +1,15 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<odoo> |
|||
<data noupdate="1"> |
|||
<!-- Ir cron fail mail send schedule action--> |
|||
<record id="ir_cron_fail_report_mail" model="ir.cron"> |
|||
<field name="name">Mail: Cron Error Notification</field> |
|||
<field name="model_id" ref="model_ir_cron"/> |
|||
<field name="state">code</field> |
|||
<field name="code">model.mail_send_cron()</field> |
|||
<field name="user_id" ref="base.user_root"/> |
|||
<field name="interval_number">1</field> |
|||
<field name="interval_type">days</field> |
|||
</record> |
|||
</data> |
|||
</odoo> |
@ -0,0 +1,19 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<odoo> |
|||
<data noupdate="1"> |
|||
<!-- Ir cron fail mail template --> |
|||
<record id="mail_template_cron_error" model="mail.template"> |
|||
<field name="name">Mail: Cron Action Error23</field> |
|||
<field name="model_id" ref="cron_failure_notification.model_ir_cron"/> |
|||
<field name="subject">{{ object.name }} Cron Failed</field> |
|||
<field name="report_template_ids" eval="[(4, ref('cron_failure_notification.cron_fail_pdf_report'))]"/> |
|||
<field name="body_html" type="html"> |
|||
<p>Dear Admin,</p> |
|||
<p>Here is attaching failures from scheduled cron jobs on our |
|||
server, so please quickly take an action for this. |
|||
</p> |
|||
<p>Thank You.</p> |
|||
</field> |
|||
</record> |
|||
</data> |
|||
</odoo> |
@ -0,0 +1,7 @@ |
|||
## Module <cron_failure_notification> |
|||
|
|||
#### 19.02.2025 |
|||
#### Version 18.0.1.0.0 |
|||
#### ADD |
|||
|
|||
- Initial commit for Cron Failure Notification |
@ -0,0 +1,24 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2025-TODAY Cybrosys Technologies( |
|||
# <https://www.cybrosys.com>). |
|||
# Author: MUHAMMED RISHAD (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
from . import failure_history |
|||
from . import ir_cron |
@ -0,0 +1,36 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2025-TODAY Cybrosys Technologies( |
|||
# <https://www.cybrosys.com>). |
|||
# Author: MUHAMMED RISHAD (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
from odoo import fields, models |
|||
|
|||
|
|||
class FailureHistory(models.Model): |
|||
"""Creates failure history to store the failed cron action details |
|||
as a record""" |
|||
_name = 'failure.history' |
|||
_inherit = ['mail.thread', 'mail.activity.mixin'] |
|||
_description = 'Failure History' |
|||
|
|||
name = fields.Char(string='Name', required=True, help="Failed cron action " |
|||
"name") |
|||
error = fields.Char(string='Error Details', help="Detailed description " |
|||
"about error") |
@ -0,0 +1,100 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# ############################################################################ |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2025-TODAY Cybrosys Technologies( |
|||
# <https://www.cybrosys.com>). |
|||
# Author: MUHAMMED RISHAD (odoo@cybrosys.com) |
|||
# |
|||
# You can modify it under the terms of the GNU AFFERO |
|||
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. |
|||
# |
|||
# 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 AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. |
|||
# |
|||
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE |
|||
# (AGPL v3) along with this program. |
|||
# If not, see <http://www.gnu.org/licenses/>. |
|||
# |
|||
############################################################################## |
|||
import datetime |
|||
import logging |
|||
import time |
|||
from odoo import api, models, _ |
|||
from odoo.exceptions import ValidationError |
|||
from odoo.fields import Datetime, _logger |
|||
|
|||
|
|||
class IrCron(models.Model): |
|||
""" Inherits ir cron for add a feature that sends mail to admin |
|||
each day, if any cron failed """ |
|||
_name = 'ir.cron' |
|||
_inherit = ['ir.cron', 'mail.thread'] |
|||
|
|||
|
|||
def _callback(self, cron_name, server_action_id): |
|||
""" Run the method associated to a given job. It takes care of logging |
|||
and exception handling. Note that the user running the server action |
|||
is the user calling this method. """ |
|||
self.ensure_one() |
|||
try: |
|||
if self.pool != self.pool.check_signaling(): |
|||
# the registry has changed, reload self in the new registry |
|||
self.env.reset() |
|||
self = self.env()[self._name] |
|||
|
|||
_logger.debug( |
|||
"cron.object.execute(%r, %d, '*', %r, %d)", |
|||
self.env.cr.dbname, |
|||
self._uid, |
|||
cron_name, |
|||
server_action_id, |
|||
) |
|||
_logger.info('Job %r (%s) starting', cron_name, self.id) |
|||
start_time = time.time() |
|||
self.env['ir.actions.server'].browse(server_action_id).run() |
|||
self.env.flush_all() |
|||
end_time = time.time() |
|||
_logger.info('Job %r (%s) done in %.3fs', cron_name, self.id, |
|||
end_time - start_time) |
|||
if start_time and _logger.isEnabledFor(logging.DEBUG): |
|||
_logger.debug('Job %r (%s) server action #%s with uid %s ' |
|||
'executed in %.3fs', |
|||
cron_name, self.id, server_action_id, |
|||
self.env.uid, end_time - start_time) |
|||
self.pool.signal_changes() |
|||
except Exception as exception: |
|||
self.pool.reset_changes() |
|||
_logger.exception('Job %r (%s) server action #%s failed', |
|||
cron_name, self.id, server_action_id) |
|||
# self.env.cr.rollback() |
|||
if exception: |
|||
self.env['failure.history'].create({ |
|||
'name': cron_name, |
|||
'error': str(exception), |
|||
}) |
|||
raise ValidationError(_(str(exception))) |
|||
|
|||
def mail_send_cron(self): |
|||
""" If any cron's failed a notification email will send to admin """ |
|||
current_datetime = datetime.datetime.now() |
|||
yesterday_datetime = current_datetime - datetime.timedelta(days=1) |
|||
failure = self.env['failure.history'].search( |
|||
[('create_date', '>', yesterday_datetime), |
|||
('create_date', '<', current_datetime)] |
|||
) |
|||
if failure: |
|||
admin_mail = self.env['res.groups'].search( |
|||
[('category_id', '=', 'Administration'), |
|||
('name', '=', 'Access Rights')]).users.mapped('login') |
|||
email_values = { |
|||
'email_to': admin_mail[0] if len(admin_mail) == 1 |
|||
else ",".join(admin_mail) |
|||
} |
|||
mail_template = self.env.ref( |
|||
'cron_failure_notification.mail_template_cron_error') |
|||
mail_template.send_mail(self.id, email_values= email_values, |
|||
force_send=True) |
@ -0,0 +1,50 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<!--Cron action failure pdf template--> |
|||
<template id="report_logs_details"> |
|||
<t t-call="web.html_container"> |
|||
<t t-call="web.external_layout"> |
|||
<div class="page"> |
|||
<center> |
|||
<h2>Cron Failure Report</h2> |
|||
</center> |
|||
<br/> |
|||
<br/> |
|||
<div class="oe_structure" style=""> |
|||
<strong> |
|||
<p>Cron Action Name:</p> |
|||
</strong> |
|||
<table class="table table-sm"> |
|||
<tr> |
|||
<th style="border: solid 1px black; text-align: center;">Cron Name</th> |
|||
<th style="border: solid 1px black; text-align: center;">Date and Time of Run</th> |
|||
<th style="border: solid 1px black; text-align: center;">Error Details</th> |
|||
</tr> |
|||
<t t-set="end_time" |
|||
t-value="datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')"/> |
|||
<t t-set="start_time" |
|||
t-value="(datetime.datetime.now() - datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')"/> |
|||
<t t-set="failure_record" |
|||
t-value="request.env['failure.history'].search([('create_date', '>=', start_time), ('create_date', '<=', end_time )])"/> |
|||
<t t-foreach="failure_record" t-as="history"> |
|||
<tr> |
|||
<td style="border: solid 1px black; text-align: center;"> |
|||
<span t-esc="history.name"/> |
|||
</td> |
|||
<td style="border: solid 1px black; text-align: center;"> |
|||
<span t-esc="history.create_date"/> |
|||
</td> |
|||
<td style="color:#ea5252; border: solid 1px black; text-align: center;"> |
|||
<h5> |
|||
<span t-esc="history.error"/> |
|||
</h5> |
|||
</td> |
|||
</tr> |
|||
</t> |
|||
</table> |
|||
</div> |
|||
</div> |
|||
</t> |
|||
</t> |
|||
</template> |
|||
</odoo> |
@ -0,0 +1,13 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<odoo> |
|||
<!-- Ir cron report action --> |
|||
<record id="cron_fail_pdf_report" model="ir.actions.report"> |
|||
<field name="name">Cron failure report</field> |
|||
<field name="model">ir.cron</field> |
|||
<field name="report_type">qweb-pdf</field> |
|||
<field name="report_name">cron_failure_notification.report_logs_details</field> |
|||
<field name="report_file">cron_failure_notification.report_logs_details</field> |
|||
<field name="binding_model_id" ref="model_ir_cron"/> |
|||
<field name="binding_type">report</field> |
|||
</record> |
|||
</odoo> |
|
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 495 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 624 B |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 929 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 600 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 926 B |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 875 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 80 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 589 B |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 565 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 967 B |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 105 KiB |