Example #1
0
def send_notifications(username, customer_name, operation_id, agent_id):
    try:
        notif_handler = RvNotificationHandler(customer_name, operation_id, agent_id)
        oper_info = get_agent_operation(operation_id)
        oper_plugin = oper_info[OperationKey.Plugin]
        oper_status = oper_info[OperationKey.OperationStatus]
        threshold = translate_opercodes_to_notif_threshold(oper_status)
        oper_type = return_notif_type_from_operation(oper_info[OperationKey.Operation])
        notif_rules = (
            notification_rule_exists(
                notif_handler, oper_plugin, oper_type, threshold
            )
        )

        if notif_rules:
            if oper_plugin == RV_PLUGIN or oper_plugin == CORE_PLUGIN:
                sender_addresses = (
                    notif_handler.get_sending_emails(notif_rules)
                )
                oper = AgentOperationRetriever(username, customer_name, None, None)
                oper_data = oper.get_install_operation_for_email_alert(operation_id)

                if sender_addresses:
                    subject, msg_body  = (
                        parse_install_operation_data(
                            oper_data, oper_type,
                            oper_plugin, threshold
                        )
                    )

                    send_data(
                        customer_name, subject,
                        msg_body, sender_addresses
                    )

    except Exception as e:
        logger.exception(e)