Cacti / plugin_reportit

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

Undefined index #30

Closed gmourani closed 5 years ago

gmourani commented 6 years ago

When trying to export template, this is what I can see in the Apache log file.

[Mon Jul 09 09:52:47 2018] [error] [client 192.168.2.147] PHP Notice: Undefined index: reportit_tWizard in /var/www/html/cacti/plugins/reportit/templates.php on line 734, referer: https://192.168.2.227/cacti/plugins/reportit/templates.php?action=template_export_wizard

[Mon Jul 09 09:52:47 2018] [error] [client 192.168.2.147] PHP Notice: Undefined index: in /var/www/html/cacti/plugins/reportit/templates.php on line 737, referer: https://192.168.2.227/cacti/plugins/reportit/templates.php?action=template_export_wizard

Regards,

netniV commented 5 years ago

Does this happen with the latest version?

gmourani commented 5 years ago

No, nothing in the Apache log this time but see the attached screenshot I get after clicking Export.

screen shot 2018-09-26 at 8 34 45 am
netniV commented 5 years ago

Is this with the latest version of ReportIT (ie, current development?)

ikorzha commented 5 years ago

netniV, I can confirm. It is happening with the latest version of ReportIT. To replicate the issue go to Console->Report Template, click Export, Fillout Form and hit submit. Hint: Import doesn't work either :)

image

Also export results in the following php errors in the log: image

netniV commented 5 years ago

So this rabbit hole is far bigger than you guys realise. It's broken. I don't like it. I'm changing it.

Templates are going to get Version, Author on the table so they can be updated and simply exported when necessary. However, that lead to an amazing discovery that the description field has been renamed to name, then a new field adding (in the same SQL statement) called.... description

To make life more interesting, where you have seen Name on the screen, it's actually been using the description field. So, now we have a mess of Name being the original description name, or blank. Description being blank or the new name...and a whole lot of hair being scratched away as I unravel it.

Anyway, long story short, I'm part way through some changes but i'm calling it a night. I've added my fields, made name be name, description be description on the template editing. I've removed the export button and adding a small dollop of code from thold I create to be able to download and then redirect to the main listing page.

And before you all scream... NOOOO we need an export.... I've moved it... it's now a drop action for multi-selection... BUT... I need to also fix the import to work with multiple items. It does mean that templates exported from Reportit 1.1.x or above won't be directly importable to pre-1.1 without taking each <template> block and putting it in separate XML files.

That again lead me down another rabbit hole were I have now found two sets of dropdown menu items relating to templates, only the other one actually has UNLOCK and LOCK actions on it... I'm guessing no one wants a mass lock/unlock function.

netniV commented 5 years ago

Oh and I forgot the most important part. The reason that you guys are seeing that weird template edit form, the action element was being set twice. As such, it was only using the last one which was 'save', so I had to re-write that bit of code too. The cool thing is, I have a version of ReportIt that mostly works now. Just waiting for you guys to catch up and write the same code ;-)

ikorzha commented 5 years ago

netniV, sounds like you are taking charge to make this plugin right! 1.02 release is not even alpha quality that is how bad it is. I am hopeful that you conduct a thorough testing of 1.10 release before you let it out. Please pay attention to a specific items that are currently broken: template import/export, report scheduling (I currently don't even see anywhere where to schedule a report to deliver on daily weekly monthly time frame and exact time of delivery). Emailing report as part of scheduling process as well report archiving locally on disk. (I personally use disk archive of the report to upload it to Tablau for further processing of metrics) Thank you in advance for the hard work to get it right!

netniV commented 5 years ago

I think the biggest problem here is that there was work in progress which unfortunately became halted by real world issues. Then someone else came along with a patch which looked OK but since non of us had really reviewed this code, we couldn't properly say anything was bad so it got commited, then more changes, and now here we are.

v1.1.0 will likely still have plenty of bugs as I'd rather get some of the fixes out there since it would help clear up what is still to be fixed. But it should hopefully be beta quality... eg, I get no errors.

ikorzha commented 5 years ago

I am 100% with you on how this plugin got to be in this state..

I am looking forward to test it and provide useful comments/suggestions.. once new code is out.

netniV commented 5 years ago

OK, so I've just pushed up the first lot of v1.1.0 changes. There are no errors when installing, enabling or upgrading ReportIT or using the Templates -> Report section. This is NOT a release, merely the first set of changes but it can be run.

These firstly fixed UPGRADING. Previously, if you had already enabled ReportIT, it would never run an upgrade again. This results in missing fields if new ones are added, version number not changing, and errors all over the place because the code doesn't match the DB.

Also fixed up templates for exporting etc. Name and Description are now settable. When upgrading, if description is blank, it will be updated by name. If name is blank, it'll be updated by description. This will keep everything in sync. Also, you can now hover over a 'Name' in the template listing and it will show the description.

For author, this will default to the current username if not set. For version, this will default to 1.0

Exporting a set of templates will result in the following XML (ignore the really bad report definition as it was purely an export test) which I think looks good aside from the repeated ReportIT info. That is likely to move to further up the chain:

<?xml version="1.0" encoding="UTF-8"?>
<report_templates>
    <report_template>
        <reportit>
            <version>1.1.0</version>
            <type>1</type>
            <hash>63b6c97274517831f8dbc4e743ac2834</hash>
        </reportit>
        <settings>
            <id>2</id>
            <name>A memory swap</name>
            <user_id>0</user_id>
            <modified_by>0</modified_by>
            <last_modified>0000-00-00 00:00:00</last_modified>
            <author>admin</author>
            <description>A memory swap</description>
            <version>1.0</version>
            <pre_filter></pre_filter>
            <data_template_id>12</data_template_id>
            <locked>on</locked>
            <enabled></enabled>
            <export_folder></export_folder>
        </settings>
        <measurands>
        </measurands>
        <variables>
        </variables>
        <data_source_items>
            <data_source_item>
                <id>0</id>
                <template_id>2</template_id>
                <group_id>0</group_id>
                <data_template_id>0</data_template_id>
                <data_source_name>overall</data_source_name>
                <data_source_alias></data_source_alias>
                <data_source_title></data_source_title>
                <data_source_mp>1</data_source_mp>
            </data_source_item>
            <data_source_item>
                <id>20</id>
                <template_id>2</template_id>
                <group_id>0</group_id>
                <data_template_id>0</data_template_id>
                <data_source_name>mem_swap</data_source_name>
                <data_source_alias></data_source_alias>
                <data_source_title></data_source_title>
                <data_source_mp>1</data_source_mp>
            </data_source_item>
        </data_source_items>
    </report_template>
    <report_template>
        <reportit>
            <version>1.1.0</version>
            <type>1</type>
            <hash>55b0236508e2ffbf4114b310099d3e69</hash>
        </reportit>
        <settings>
            <id>1</id>
            <name>Memory Free</name>
            <user_id>0</user_id>
            <modified_by>0</modified_by>
            <last_modified>0000-00-00 00:00:00</last_modified>
            <author>netniv</author>
            <description>a description of Memory Free</description>
            <version>0.1</version>
            <pre_filter></pre_filter>
            <data_template_id>11</data_template_id>
            <locked>on</locked>
            <enabled></enabled>
            <export_folder></export_folder>
        </settings>
        <measurands>
            <measurand>
                <id>1</id>
                <template_id>1</template_id>
                <group_id>0</group_id>
                <description>Memory Useage</description>
                <abbreviation>FREE</abbreviation>
                <calc_formula>c1v / maxRRDValue * 100</calc_formula>
                <unit>%</unit>
                <visible>on</visible>
                <spanned>on</spanned>
                <rounding>2</rounding>
                <cf>1</cf>
                <data_type>1</data_type>
                <data_precision>2</data_precision>
            </measurand>
        </measurands>
        <variables>
            <variable>
                <id>1</id>
                <template_id>1</template_id>
                <abbreviation>c1v</abbreviation>
                <name>Memory Free</name>
                <description>Amount of Free Memory</description>
                <max_value>100</max_value>
                <min_value>0</min_value>
                <default_value>0</default_value>
                <input_type>2</input_type>
                <stepping>0</stepping>
            </variable>
        </variables>
        <data_source_items>
            <data_source_item>
                <id>0</id>
                <template_id>1</template_id>
                <group_id>0</group_id>
                <data_template_id>0</data_template_id>
                <data_source_name>overall</data_source_name>
                <data_source_alias>Memory Free</data_source_alias>
                <data_source_title></data_source_title>
                <data_source_mp>1</data_source_mp>
            </data_source_item>
            <data_source_item>
                <id>19</id>
                <template_id>1</template_id>
                <group_id>0</group_id>
                <data_template_id>0</data_template_id>
                <data_source_name>mem_buffers</data_source_name>
                <data_source_alias>mem_free</data_source_alias>
                <data_source_title></data_source_title>
                <data_source_mp>1</data_source_mp>
            </data_source_item>
        </data_source_items>
    </report_template>
</report_templates>
ikorzha commented 5 years ago

netniV, export didn't work for me on v1.10, as an extra feature disables the plugin too :) Here are the php errors from the log: image

netniV commented 5 years ago

In MySQL / MariaDB:

show create table plugin_reportit_templates\G
ikorzha commented 5 years ago

table plugin_reportit_templates below, I can export it for you and attach here if needed. image

netniV commented 5 years ago

OK, so I just pushed another change. This should hopefully fix your issue.

ikorzha commented 5 years ago

Unfortunately not, just tried export after update: Still getting same errors

2018/09/28 11:12:34 - CMDPHP ERRORS DETECTED - DISABLING PLUGIN 'reportit'

2018/09/28 11:12:34 - CMDPHP PHP ERROR Backtrace: (CactiShutdownHandler)(/lib/functions.php: 4628 cacti_debug_backtrace) thrown in file: /var/www/html/plugins/reportit/templates.php on line: 946

1 {main}

0 /var/www/html/plugins/reportit/templates.php(39): form_actions()

Stack trace: 2018/09/28 11:12:34 - ERROR PHP ERROR in Plugin 'reportit': Uncaught Error: [] operator not supported for strings in /var/www/html/plugins/reportit/templates.php:946

netniV commented 5 years ago

The next error... thought that would have been resolved by the previous fix... one sec....

netniV commented 5 years ago

Please try again..

netniV commented 5 years ago

@ikorzha This one is also with you ;-) . Made some more changes... and the unlocked icon is now a lot easier to see it's unlocked!

ikorzha commented 5 years ago

I have tested the export it is now fully functional. You can close this issue.