Cacti / plugin_reportit

ReportIt Plugin for Cacti
GNU General Public License v2.0
7 stars 8 forks source link

When reportit report is run, it doesn't get email delivered or archived when option is specified #63

Closed ikorzha closed 5 years ago

ikorzha commented 5 years ago

When reportit report is run, it doesn't get email delivered or archived when option is specified: Email is now being defined thanks to your latest git, however next action is not happening which is email delivery and local archiving of the report on disk in /reportit/archive/"reportid"/ folder image

This piece is actually the most important for me so I can abandon my old cacti 0.8.8h install base and reportit 0.8

netniV commented 5 years ago

Are there any errors in the web server log and/or cacti log?

ikorzha commented 5 years ago

I have just ran and checked both cacti log and httpd log, no errors at all. It appears to be unfinished functionality in 1.x which was fully operational in 0.8 branch.

netniV commented 5 years ago

More likely the toggle option checking was not updated from the 0/1 to ''/'on' formats that 1.x uses

ikorzha commented 5 years ago

netniV, we will be looking forward to results of your investigation :)

smiles1969 commented 5 years ago

I am also having same issue, emails are not being delivered. I also toggled off and back on the email option and did observe the field value changing from 1 to null, and then back to "on". However, the email is still not being sent.

netniV commented 5 years ago

@smiles1969 I'm heading home shortly, can you let me know which field it was you were observing as that will speed things up.

smiles1969 commented 5 years ago

table plugin_reportit_reports and field auto_email

netniV commented 5 years ago

OK, that helps. I couldn't remember off the top of my head... so this is all because it's email support still expects the old settings plugin which is no longer used since it's integrated. Needs modifying to use the mailer() functions that cacti 1.x has.

/* Basical Email Functions */
function check_email_support(){
        if (function_exists('settings_version')) {
                return true;
        } else {
                return false;
        }
}

function send_scheduled_email($report_id){
        global $config;

        $data   = '';
        $search = array('|title|', '|period|');

        include_once(CACTI_BASE_PATH . '/plugins/settings/include/mailer.php');

Since settings_version() does not exist, it won't ever run a scheduled report (though it should tell your or hide the flipping option!)

smiles1969 commented 5 years ago

Could you replace that check with:

if (read_config_option('reportit_email') == 'on')

perhaps?

netniV commented 5 years ago

It's not as simple as that. The whole mailer code is in need of a replacement. However, due to the nature of the plugin, it can't just use the base cacti mailer since that doesn't properly support attachments.

So, for now, I've ripped the 1.2 mailer code and i'm putting it into a custom function, but it means testing etc. so probably by the weekend.

netniV commented 5 years ago

This is partly underway. I have actually disabled the email functionality whilst I continue to test.

netniV commented 5 years ago

So, I have now managed to get an email out. But it has no attachment and I'm not sure if the content is right. If anyone has an example plus a template, I'd be grateful.

ikorzha commented 5 years ago

netniV, thank you for getting back on these issues, we are still here waiting until you have time :) I have the good experience with email reporting. So emailed report should only contain report name in subject as defined in report configuration and attachment either : .xml, csv or ms xml

Please let me know if anything is else is needed I can export all my reportit tables via sql and send to you via email...

netniV commented 5 years ago

Email delivery is finally here. It's not nice but it works.

smiles1969 commented 5 years ago

still not working for me after this commit

ikorzha commented 5 years ago

Email does get delivered, however don't expect a report attachment in it. It was outside of implementation scope.

smiles1969 commented 5 years ago

My email is working fine for graphs. It's set to use sendmail. However even after completely removing this plugin and re-installing the latest, I get no email when I run a report.

It is enabled under settings. The email address is defined in the report, it's just not being sent.

netniV commented 5 years ago

So the things to check are:

  1. Global emailing is enabled via reportit_email (under Configuration -> Settings -> Reports -> Auto Emailing -> Enabled)
  2. Report emailing is enabled
    1. If scheduling by operator is enabled, via Report -> Edit -> General -> Auto Generated Email
    2. If not, via Report -> Edit -> Administration -> Auto Generated Email
  3. If you want an attachment, Report email format must be set under Report -> Edit -> Email -> Format
  4. If you want to receive it, ensure that a recipient has been set.

When the mailer sends an email, or fails to, it logs it to the cacti log. Check there to see if any entries are made.

smiles1969 commented 5 years ago

Those settings are enabled, I even toggled them off and on to ensure there wasnt any boolean variable storage issues.

The only message that shows in the logs when I run the report are several "WEBLOG CACTI2RRD:" entries. Nothing else.

netniV commented 5 years ago

Try running it from the command line:

sudo -u <website or cacti user> php -q plugins/reportit/runtime.php <id of report> -v
smiles1969 commented 5 years ago

root@ctcv-cacti3:/var/www/html/cacti# sudo -u cactiuser php -q plugins/reportit/runtime.php 1 -v PHP Warning: include_once(/var/www/html/cacti/include/phpmailer/PHPMailerAutoload.php): failed to open stream: No such file or directory in /var/www/html/cacti/plugins/reportit/lib/funct_mailer.php on line 41 PHP Warning: include_once(): Failed opening '/var/www/html/cacti/include/phpmailer/PHPMailerAutoload.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/cacti/plugins/reportit/lib/funct_mailer.php on line 41 PHP Fatal error: Class 'PHPMailer' not found in /var/www/html/cacti/plugins/reportit/lib/funct_mailer.php on line 49

smiles1969 commented 5 years ago

apparently the phpmailer is not in the include folder in the dev branch, only in master. It is however in the include/vendor/phpmailer folder.

I just changed the include to this:

include_once($config['include_path'] . '/vendor/phpmailer/PHPMailerAutoload.php');

and now I get this:

root@ctcv-cacti3:/var/www/html/cacti# sudo -u cactiuser php -q plugins/reportit/runtime.php 1 -v 2018/10/19 13:39:11 - PLUGIN REPORTIT STATS: ID:1 Time:3.7 Reports:1 Emails:1 Exports:0

Oh.. and the email too :)

netniV commented 5 years ago

ReportIT should be using the inc/funct_mailer.php if your cacti version is not 1.2. What version of cacti are you running?

smiles1969 commented 5 years ago

1.2.0 - Beta 1 Im running the dev branch but probably 2 weeks old on commits.

smiles1969 commented 5 years ago

Also I assume you meant lib/funct_mailer.php. In that file there is an include statement on line 41.

That include references the phpmailer folder being in the root of the cacti path/include... which it is not for the dev branch, but it is for the master.

netniV commented 5 years ago

OK, Can you log this as a new issue so I can reference it in my commit.

smiles1969 commented 5 years ago

Done