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

php error when trigger threshold sendmail #3380

Closed
yingbaiibm opened this issue Mar 27, 2020 · 8 comments
Closed

php error when trigger threshold sendmail #3380

yingbaiibm opened this issue Mar 27, 2020 · 8 comments
Labels
bug Undesired behaviour resolved A fixed issue
Milestone

Comments

@yingbaiibm
Copy link

To Reproduce
Steps to reproduce the behavior:

  1. Create multiple threshold and trigger them to sendmail to user
  2. After trigger, check mail, only receive one mail.
  3. Check Log, error exist and garbled log exist

2020/03/27 04:45:03 - CMDPHP MAILER ERROR Backtrace: (/poller.php[801]:api_plugin_hook(), /lib/plugins.php[74]:api_plugin_run_plugin_hook(), /lib/plugins.php[177]:thold_poller_bottom(), /plugins/thold/includes/polling.php[45]:thold_check_all_thresholds(), /plugins/thold/includes/polling.php[474]:thold_check_threshold(), /plugins/thold/thold_functions.php[2920]:thold_mail(), /plugins/thold/thold_functions.php[5388]:mailer(), /lib/functions.php[3535]:record_mailer_error(), /lib/functions.php[3733]:cacti_debug_backtrace())
2020/03/27 04:45:03 - CMDPHP MAILER ERROR:
2020/03/27 04:45:03 - CMDPHP MAILER ERROR Backtrace: (/poller.php[801]:api_plugin_hook(), /lib/plugins.php[74]:api_plugin_run_plugin_hook(), /lib/plugins.php[177]:thold_poller_bottom(), /plugins/thold/includes/polling.php[45]:thold_check_all_thresholds(), /plugins/thold/includes/polling.php[474]:thold_check_threshold(), /plugins/thold/thold_functions.php[2334]:thold_mail(), /plugins/thold/thold_functions.php[5388]:mailer(), /lib/functions.php[3535]:record_mailer_error(), /lib/functions.php[3733]:cacti_debug_backtrace())
2020/03/27 04:45:03 - CMDPHP MAILER ERROR:

At present, the main body of attachment specified by the mailer function provided by cacti core is PNG itself, but the third-party library phpmailer only supports the local file path. It recognizes the PNG content as a path and directly reports an error

Screenshots
Screen Shot 2020-03-27 at 5 48 55 PM

Desktop (please complete the following information):
rhel8.2 x64
cacti 1.2.10
thold 1.3.4
FF 74

@ddb4github
Copy link
Contributor

ddb4github commented Mar 27, 2020

If mail body do not include both of <GRAPH> and <GRAPH:, functions.php--> mailer() will attach image object as attachement with PHPMailer-->addAttachment()
But PHPMailer-->addAttachment() only accept Local file path as attachment source.

@TheWitness TheWitness added the bug Undesired behaviour label Mar 27, 2020
@TheWitness TheWitness added this to the 1.2.11 milestone Mar 27, 2020
TheWitness added a commit that referenced this issue Mar 27, 2020
php error when trigger threshold sendmail
@TheWitness TheWitness added the resolved A fixed issue label Mar 27, 2020
@ddb4github
Copy link
Contributor

How about this diff, then $attachment['attachment'] support both image realpath and image data..
Before this diff:

  • mailer() will ignore attachment that is image data.
    After this diff:
  • inline mode also support read attachment from local filepath
--- a/lib/functions.php
+++ b/lib/functions.php
@@ -3644,11 +3644,17 @@ function mailer($from, $to, $cc, $bcc, $replyto, $subject, $body, $body_text = '

                                /* attempt to attach */
                                if (!($graph_mode || $graph_ids)) {
-                                       if (!empty($attachment['filename']) && file_exists($attachment['filename'])) {
+                                       if (!empty($attachment['attachment']) && file_exists($attachment['attachment'])) {
                                                $result = $mail->addAttachment($attachment['attachment'], $attachment['filename'], $attachment['encoding'], $attachment['mime_type'], $attachment['inline']);
+                                       } else {
+                                               $result = $mail->addStringAttachment($attachment['attachment'], $attachment['filename'], 'base64', $attachment['mime_type'], $attachment['inline']);
                                        }
                                } else {
-                                       $result = $mail->addStringEmbeddedImage($attachment['attachment'], $cid, $attachment['filename'], 'base64', $attachment['mime_type'], $attachment['inline']);
+                                       if (!empty($attachment['attachment']) && file_exists($attachment['attachment'])) {
+                                               $result = $mail->addEmbeddedImage($attachment['attachment'], $cid, $attachment['filename'], 'base64', $attachment['encoding'], $attachment['mime_type'], $attachment['inline']);
+                                       } else {
+                                               $result = $mail->addStringEmbeddedImage($attachment['attachment'], $cid, $attachment['filename'], 'base64', $attachment['mime_type'], $attachment['inline']);
+                                       }
                                }

                                if ($result == false) {

@TheWitness
Copy link
Member

It tried and received a number of back trace errors. Also, your theme pull request was reverted due to not working.

@ddb4github
Copy link
Contributor

$result = $mail->addEmbeddedImage($attachment['attachment'], $cid, $attachment['filename'], 'base64', $attachment['encoding'], $attachment['mime_type'], $attachment['inline']);

should be

$result = $mail->addEmbeddedImage($attachment['attachment'], $cid, $attachment['filename'], $attachment['encoding'], $attachment['mime_type'], $attachment['inline']);

@TheWitness
Copy link
Member

Just when I thought I could go for a walk.

@ddb4github
Copy link
Contributor

Need to upgrade PHPMailer.
Before 6.1.0, function addStringAttachment does not return any true/false

@netniV
Copy link
Member

netniV commented Apr 1, 2020

If we have updated PHPMailer and that becomes a minimum requirement, packagers such as @paulgevers and @mortenstevens will need to add that to the requirements of their packages.

@netniV
Copy link
Member

netniV commented Apr 5, 2020

OK, I'm confused as both the commits listed in this issue are showing up as DEVELOP commits, yet appear it's @ddb4github's change that appears in the 1.2.x branch.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Undesired behaviour resolved A fixed issue
Projects
None yet
Development

No branches or pull requests

4 participants