Ad Widget

Collapse

Zabbix Dynamic PDF Report Generation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Hello,

    thanks for this PDF creation tool.

    I set it up. But I have the same error like user cottirola and @tabalag.

    zabbix_server (Zabbix) 4.4.7 on
    Distributor ID: Debian
    Description: Debian GNU/Linux 10 (buster)
    Release: 10
    Codename: buster

    php7.3-curl 7.3.14-1~deb10u1
    php7.3-json 7.3.14-1


    When I'm try to connect to http://myzabbixserver/zabbix/zabbix-.../createpdf.php I see this message in the /apache2/error.log.

    HTML Code:
    [Thu Apr 16 07:47:26.119554 2020] [php7:notice] [pid 36387] [client IP:50268] PHP Notice:  Undefined variable: starttime in /usr/share/zabbix/zabbix-pdf-report/createpdf.php on line 114
    [Thu Apr 16 07:47:26.119667 2020] [php7:notice] [pid 36387] [client IP:50268] PHP Notice:  Undefined variable: endtime in /usr/share/zabbix/zabbix-pdf-report/createpdf.php on line 115
    [Thu Apr 16 07:47:26.119888 2020] [php7:warn] [pid 36387] [client IP:50268] PHP Warning:  get_class() expects parameter 1 to be object, null given in /usr/share/zabbix/zabbix-pdf-report/inc/ZabbixAPI.class.php on line 208
    [Thu Apr 16 07:47:26.139667 2020] [php7:notice] [pid 36387] [client IP:50268] PHP Notice:  Undefined variable: reporttype in /usr/share/zabbix/zabbix-pdf-report/createpdf.php on line 162
    [Thu Apr 16 07:47:26.139735 2020] [php7:notice] [pid 36387] [client IP:50268] PHP Notice:  Undefined variable: reporttype in /usr/share/zabbix/zabbix-pdf-report/createpdf.php on line 172
    And this on the webpage.

    HTML Code:
    CURL URL: http://myzabbixserver/zabbix/api_jsonrpc.php 
    CURL Options: Array ( [19913] => 1 [13] => 30 [78] => 5 [81] => [64] => [52] => 1 [74] => 1 [10023] => Array ( [0] => Content-Type: application/json-rpc [1] => User-Agent: ZabbixAPI v1.0 - http://andrewfarley.com/zabbix_php_api ) [10036] => POST [10015] => {"auth":null,"method":"user.login","id":1,"params":{"password":"password","user":"username"},"jsonrpc":"2.0"} [10102] => gzip ) Got response from API: ({"jsonrpc":"2.0","result":"c7bdf02f0ebad48f445a2537d141b8d9","id":1}) Response decoded: (Array ( [jsonrpc] => 2.0 [result] => c7bdf02f0ebad48f445a2537d141b8d9 [id] => 1 ) __login() Got response from API: (c7bdf02f0ebad48f445a2537d141b8d9) Report type not selected! 

    Try to connect to http://myzabbixserver/zabbix/zabbix-...rt/chooser.php
    I can see the form but I'm not able to select something. Above the form I see the following lines.

    HTML Code:
    CURL URL: http://myzabbixserver/zabbix/api_jsonrpc.php
    CURL Options: Array ( [19913] => 1 [13] => 30 [78] => 5 [81] => [64] => [52] => 1 [74] => 1 [10023] => Array ( [0] => Content-Type: application/json-rpc [1] => User-Agent: ZabbixAPI v1.0 - http://andrewfarley.com/zabbix_php_api ) [10036] => POST [10015] => {"auth":null,"method":"user.login","id":1,"params":{"password":"pass","user":"username"},"jsonrpc":"2.0"} [10102] => gzip ) Got response from API: ({"jsonrpc":"2.0","result":"4ff6684817001590a24d0f41dc8cd42d","id":1}) Response decoded: (Array ( [jsonrpc] => 2.0 [result] => 4ff6684817001590a24d0f41dc8cd42d [id] => 1 ) __login() Got response from API: (4ff6684817001590a24d0f41dc8cd42d)
    CURL URL: http://myzabbixserverzabbix/api_jsonrpc.php
    CURL Options: Array ( [19913] => 1 [13] => 30 [78] => 5 [81] => [64] => [52] => 1 [74] => 1 [10023] => Array ( [0] => Content-Type: application/json-rpc [1] => User-Agent: ZabbixAPI v1.0 - http://andrewfarley.com/zabbix_php_api ) [10036] => POST [10015] => {"auth":"4ff6684817001590a24d0f41dc8cd42d","method":"host.get","id":1,"params":{"output":["hostid","name"],"sortfield":"name","with_graphs":"1"},"jsonrpc":"2.0"} [10102] => gzip ) Got response from API: ({"jsonrpc":"2.0","result":[],"id":1}) Response decoded: (Array ( [jsonrpc] => 2.0 [result] => Array ( ) [id] => 1 )
    CURL URL: http://myzabbixserver/zabbix/api_jsonrpc.php
    CURL Options: Array ( [19913] => 1 [13] => 30 [78] => 5 [81] => [64] => [52] => 1 [74] => 1 [10023] => Array ( [0] => Content-Type: application/json-rpc [1] => User-Agent: ZabbixAPI v1.0 - http://andrewfarley.com/zabbix_php_api ) [10036] => POST [10015] => {"auth":"4ff6684817001590a24d0f41dc8cd42d","method":"hostgroup.get","id":1,"params":{"output":["groupid","name"],"real_hosts":"1","with_graphs":"1","sortfield":"name"},"jsonrpc":"2.0"} [10102] => gzip ) Got response from API: ({"jsonrpc":"2.0","result":[],"id":1}) Response decoded: (Array ( [jsonrpc] => 2.0 [result] => Array ( ) [id] => 1 )
    CURL URL: http://myzabbixserver/zabbix/api_jsonrpc.php
    CURL Options: Array ( [19913] => 1 [13] => 30 [78] => 5 [81] => [64] => [52] => 1 [74] => 1 [10023] => Array ( [0] => Content-Type: application/json-rpc [1] => User-Agent: ZabbixAPI v1.0 - http://andrewfarley.com/zabbix_php_api ) [10036] => POST [10015] => {"auth":"4ff6684817001590a24d0f41dc8cd42d","method":"user.logout","id":1,"params":[],"jsonrpc":"2.0"} [10102] => gzip ) Got response from API: ({"jsonrpc":"2.0","result":true,"id":1}) Response decoded: (Array ( [jsonrpc] => 2.0 [result] => 1 [id] => 1 ) __logout() Got response from API: (1)


    Thanks for your help.

    Comment


    • Beatfussel
      Beatfussel commented
      Editing a comment
      Sure, here is the config-inc.php

      HTML Code:
      <?php
      //CONFIGURABLE
      $user_login=0; // If $user_login is 0, use credentials below and don't prompt for login.
      //$user_login=0; // If $user_login is 0, use credentials below and don't prompt for login.
      $allow_localhost=1; // If a request is made from 127.0.0.1, use credentials below in createpdf.php
      
      $version        = '1.1.1';
      
      // What items would you like to see in the report? Things that do not match are excluded automatically.
      $items = array('system information'=>'string','uptime'=>'seconds', 'boot time'=>'datetime', 'total memory'=>'bytes', 'available memory'=>'bytes', 'Free disk space'=>'number', 'Free swap space in %'=>'number', 'version of zabbix_agent'=>'
      string', 'services'=>'string', 'update'=>'number','certificate'=>'string','advanced ntp'=>'string','Interface speed'=>'bits','Operational status'=>'updown','Alias of interface'=>'string','certificate'=>'string');
      
      // Which items would you like to see overall statistics for over the selected period? Presently only avg is shown, but min and max could easily be added.
      $trends = array('ICMP ping'=>'updown','ICMP loss'=>'number', 'ICMP response'=>'ms', 'BatteryCharge'=>'number', 'Battery capacity'=>'number', 'voltage'=>'number', 'output power'=>'number', 'CPU Idle Time'=>'number', '15 min average'=>'num
      ber', 'Temp'=>'number', 'Watt'=>'number', 'uptime'=>'seconds','transactions per second'=>'number');
      
      $showdates = false; // Prepend date and time on items and trends, or leave it out? false = leave it out.
      //$showdates = true; // Prepend date and time on items and trends, or leave it out? false = leave it out.
      
      // Would you like to limit what graphs are displayed? Enter partial matches (or complete names) here.
      // $mygraphs = '#.*#'; // Match all graphs
      $mygraphs = '#(Ping|CPU load|CPU usage|CPU util|processor|Disk space|Swap|Ethernet|Memory usage|^Traffic on |traffic on eth)#';
      $myitemgraphs = '#(Utilization of|farm connection|Average Latency|Number of processes|Cache % Hit)#';
      
      # zabbix server info(user must have API access)
      // $z_server    = 'http://localhost/zabbix/';
      $z_server       = 'http://myzabbixserver/zabbix/'; // Replace YourServerHere with either en IP or an FDQN (e.g. zabbix.company.com). Remove the s in https if for some reason you don't use https yet. Or better yet, get Let's Encrypt i
      nstalled and use https!
      $z_user         = 'MYUSER';
      $z_pass         = 'MYPASSWORD';
      
      
      # Temporary directory for storing pdf data and graphs - must exist
      $z_tmp_path     = './tmp';
      # Directory for storing PDF reports
      $pdf_report_dir = './reports';
      # Root URL to reports
      #$pdf_report_url        = $z_server ."report/reports";
      $pdf_report_url = "./reports";
      # paper settings
      $paper_format   = 'A4'; // formats supported: 4A0, 2A0, A0 -> A10, B0 -> B10, C0 -> C10, RA0 -> RA4, SRA0 -> SRA4, LETTER, LEGAL, EXECUTIVE, FOLIO
      $paper_orientation = 'portrait'; // formats supported: portrait / landscape
      # time zone - see http://php.net/manual/en/timezones.php
      $timezone       = 'Europe/Berlin';
      # Logo used in PDF - may be empty
      # TODO: Specify image size!
      $pdf_logo       = './images/general/zabbix.png';
      $company_name   = 'YourCompany Name';
      
      //DO NOT CHANGE BELOW THIS LINE
      $z_tmp_cookies  = "/tmp/";
      $z_url_index    = $z_server ."index.php";
      $z_url_graph    = $z_server ."chart2.php";
      $z_item_graph   = $z_server ."chart.php";
      $z_url_api      = $z_server ."api_jsonrpc.php";
      $z_login_data   = "name=" .$z_user ."&password=" .$z_pass ."&autologin=1&enter=Sign+in";
      ?>

    • provels
      provels commented
      Editing a comment
      Nothing really to see there. If you set $user_login=1; you get the login page and then the screen gets built, right? You can make selections, and hit "Generate" but then it posts the errors on the following page? Maybe it's some mismatch between json and curl versions that the forms require. I'm just running the 4.4.6 prebuilt Hyper-V appliance and had to install php7.0-curl and php-json to get mine to start working. I don't know what might be required for the Debian/4.4.7 combo. Sorry.

      Using
      cURL Information => 7.47.0
      PHP Version => 7.0.33-0ubuntu0.16.04.14

      Your user is an Admin with api access, right? Sorry if that's a dumb question.
      Last edited by provels; 17-04-2020, 15:02.

    • Beatfussel
      Beatfussel commented
      Editing a comment
      Yes, I see the login screen and after login I see the form with the error message above it, as I described in my first post (chosser.php). Thanks for help analyzing.

      Yes I thought about which Rights are nessesary and decidet give this user Super Admin rights for testing.
      Last edited by Beatfussel; 17-04-2020, 13:49.

    Can anyone tell me where this search string is coded? I have some templates that use (I assume) non-standard titles for their graphs. I've browsed through many of the files in the zabbix-pdf-report tree without success. Thanks.
    HTML Code:
    #(Ping|CPU load|CPU usage|CPU util|processor|Disk space|Swap|Ethernet|Memory usage|^Traffic on |traffic on eth)#
    Oh, duh. Here it is -> config.inc.php

    I found I can just trim the line down to the basics, like CPU, Disk, Memory, Interface, etc., and it will simply pull any graph that has that somewhere in the title. Probably old news for some, but just leaving this in case it helps someone new...
    Last edited by provels; 16-04-2020, 17:12.

    Comment


      Is the "Old reports (click to show)" link at the bottom of the chooser.php page just a dead link? It just reacts like text to me. Maybe it's a browser thing again? I'm trying... Thanks.

      Comment


        Hello everyobody,

        Fort hose who had an issue with CURL text on the chooser.php page, i found the solution !

        You need to edit your chooser.php file, which is for me in usr/share/zabbix-df-repport/chooser.php
        Then you need to remove the ligne 132:
        ZabbixAPI::debugEnabled(TRUE);

        Which is causing all the data to spam.

        Hope it will help you,
        Have a nice day.

        Comment


          Dears

          I have followed instructions and installed the report generator on zabbix 4.4.4

          but getting unable to login

          please advise how to fix this

          attached screen shots from error

          Thanks
          heba
          Attached Files

          Comment


          If you need all graphs, only write #.*# and delete all filter #(Ping|......)#

          Comment


            Hi folks.

            I finally had a bit of time to look at the report again and I have fixed most issues mentioned here, if not all.
            Version 1.2.0 is available from https://github.com/martinm76/zabbix-pdf-report and I have tested it on Zabbix 5.0 with PHP 7.2 on Ubuntu 18.04

            The Date and time picker is very basic right now. It seems there is some incompatiblity between the picker and latest jQuery. If someone gets it working, please inform me.
            It works, but it's not very pretty.

            2020-07-05 Martin Møller <[email protected]> - Update to v1.2.0
            • Fixed issue in index.php with = in stead of == if user login is disabled
            • Updated jQuery to 3.5.1
            • Fixed references to previously removed 3.3.1 version in chooser.php
            • Updated datetimepicker to latest available
            • It seems there is incompatibility with current jQuery though
              • There is a date/time picker, but very generic
            • Adjusted scaler formula for company name in PDF
              • Should stay within page size in most cases now
            • Disabled curl debugging, which apparently was enabled before.
            • Added rudimentary attempts at fixing possible SELinux issues
              • For this to work, the report must be placed in the normal www directory (usually /var/www/html or /srv/www/html)
            • Fixed 'Show old reports' not necessarily showing all it should.
            • Tested with Zabbix 5.0 and PHP 7.2

            Comment


            • sancho
              sancho commented
              Editing a comment
              Thanks for your work Martin,

              In version 5 it works correctly for me.

            First off, not complaining. I appreciate every effort by every individual in any open-source effort.

            Is this possibly not compatible with versions older than 5.0? I'm using the 4.4.6 appliance.

            I renamed my old directory.
            Did a git clone to retrieve the new version.
            Created the tmp, reports directories, chmod 777.
            Edited the copied config.inc.php with my server IP, creds, timezone, company_name.
            Restarted apache2.
            Restarted server.
            Dumped browser cache.

            All I get is a white page with the Zabbix logo and "Generate PDF Report". If I make login=1, I get a 500 server error. I know it's probably me (it usually is... :/ , but any thoughts?
            Last edited by provels; 05-07-2020, 20:17.

            Comment


            • martinm_76
              martinm_76 commented
              Editing a comment
              It should work with older versions, too. Nothing big has changed. What does your error_log say?
              I'll try it on Zabbix 4.4 and CentOS 7.6 shortly.

            Here you go. Thanks for your quick reply.

            login=0
            HTML Code:
            [Sun Jul 05 19:42:09.054197 2020] [:error] [pid 2212] [client 192.168.0.150:62916] PHP Warning: Creating default object from empty value in /usr/share/zabbix/zabbix-pdf-report/inc/ZabbixAPI.class.php on line 96
            [Sun Jul 05 19:42:09.054475 2020] [:error] [pid 2212] [client 192.168.0.150:62916] PHP Fatal error: Uncaught Error: Call to undefined method stdClass::__login() in /usr/share/zabbix/zabbix-pdf-report/inc/ZabbixAPI.class.php:100\nStack trace:\n#0 /usr/share/zabbix/zabbix-pdf-report/chooser.php(133): ZabbixAPI::login('https://192.168...', 'Admin', 'zabbix')\n#1 {main}\n thrown in /usr/share/zabbix/zabbix-pdf-report/inc/ZabbixAPI.class.php on line 100
            login=1
            HTML Code:
            [Sun Jul 05 20:26:24.462673 2020] [:error] [pid 7380] [client 192.168.0.150:63005] PHP Notice: Undefined index: username in /usr/share/zabbix/zabbix-pdf-report/chooser.php on line 26
            [Sun Jul 05 20:26:24.462910 2020] [:error] [pid 7380] [client 192.168.0.150:63005] PHP Notice: Undefined index: password in /usr/share/zabbix/zabbix-pdf-report/chooser.php on line 27
            [Sun Jul 05 20:26:24.463408 2020] [:error] [pid 7380] [client 192.168.0.150:63005] PHP Warning: Creating default object from empty value in /usr/share/zabbix/zabbix-pdf-report/inc/ZabbixAPI.class.php on line 96
            [Sun Jul 05 20:26:24.463571 2020] [:error] [pid 7380] [client 192.168.0.150:63005] PHP Fatal error: Uncaught Error: Call to undefined method stdClass::__login() in /usr/share/zabbix/zabbix-pdf-report/inc/ZabbixAPI.class.php:100\nStack trace:\n#0 /usr/share/zabbix/zabbix-pdf-report/chooser.php(133): ZabbixAPI::login('https://192.168...', NULL, NULL)\n#1 {main}\n thrown in /usr/share/zabbix/zabbix-pdf-report/inc/ZabbixAPI.class.php on line 100
            [Sun Jul 05 20:26:26.893664 2020] [:error] [pid 2210] [client 192.168.0.150:63006] PHP Warning: Creating default object from empty value in /usr/share/zabbix/zabbix-pdf-report/inc/ZabbixAPI.class.php on line 96, referer: https://192.168.0.69/zabbix/zabbix-pdf-report/index.php
            [Sun Jul 05 20:26:26.893830 2020] [:error] [pid 2210] [client 192.168.0.150:63006] PHP Fatal error: Uncaught Error: Call to undefined method stdClass::__login() in /usr/share/zabbix/zabbix-pdf-report/inc/ZabbixAPI.class.php:100\nStack trace:\n#0 /usr/share/zabbix/zabbix-pdf-report/index.php(30): ZabbixAPI::login('https://192.168...', 'Admin', 'zabbix')\n#1 {main}\n thrown in /usr/share/zabbix/zabbix-pdf-report/inc/ZabbixAPI.class.php on line 100, referer: https://192.168.0.69/zabbix/zabbix-pdf-report/index.php
            Last edited by provels; 05-07-2020, 22:28.

            Comment


            • martinm_76
              martinm_76 commented
              Editing a comment
              Alright. Apparently the Debug lines I commented are needed for Zabbix versions below 5.0. I have tried to address it with an extra variable in config.inc.php(.dist) to define your version.
              It could probably be found with an API call, but that might fail if the debug statement was not already correct.
              I have tried to expand fixrights.sh as well to try to address some of the other installation concerns.
              I have done 3-4 commits today to fix these things. Could you try again? Default version for the variable is 4.4. Basically anything below 5.0 will have debugging enabled and anything after will not.

            There was apparently a need for the debugging in versions prior to Zabbix 5.0 and it seems it never quite did what you would expect, or at least what is does has changed with version 5.0
            I have tried to take care of both scenarios, but you have to define your Zabbix version in config.inc.php now. I have a $zabbix_version = 4.4 as default in config.inc.php.dist
            As of right now, the only change is if version is 5 or above, but don't do debug, if below, we do.

            I also apparently had not committed the config with $hide_company_name - that is fixed as well.

            I have tried to divine what user the process running on port 80 or 443 is using and have that user owning the contents of the directory, falling back to apache presently if root is set. Let me know if it poses a problem for any of you,
            You can run fixrights.sh as often as you like, but please only run it directly from the report directory.

            Comment


            • provels
              provels commented
              Editing a comment
              Yes, that was it. Of course. I do see an error when the script runs. Should this be 'apache2'? I have no idea. Thanks again for all you've done.

              [email protected]:/usr/share/zabbix/zabbix-pdf-report$ sudo ./fixrights.sh
              [sudo] password for appliance:
              chown: invalid user: ‘apache’
              drwxrwxrwx 2 root root 4096 Jul 6 09:59 reports
              drwxrwxrwx 2 root root 4096 Jul 6 09:59 tmp

              You should now have tmp and reports folders that your webserver can write to.
              [email protected]:/usr/share/zabbix/zabbix-pdf-report$
              Last edited by provels; 06-07-2020, 12:27.

            • martinm_76
              martinm_76 commented
              Editing a comment
              Possibly (apache2). Maybe I should just not guess if all I can find is root ;-) - Thank you for the datapoint. Do you have apache2 in /etc/passwd?

            • provels
              provels commented
              Editing a comment
              No, I just saw apache2 in top and it was running as root. Not in passwd.

            There was apparently a need for the debugging in versions prior to Zabbix 5.0 and it seems it never quite did what you would expect, or at least what is does has changed with version 5.0
            I have tried to take care of both scenarios, but you have to define your Zabbix version in config.inc.php now. I have a $zabbix_version = 4.4 as default in config.inc.php.dist
            As of right now, the only change is if version is 5 or above, but don't do debug, if below, we do.

            I also apparently had not committed the config with $hide_company_name - that is fixed as well.

            I have tried to divine what user the process running on port 80 or 443 is using and have that user owning the contents of the directory, falling back to apache presently if root is set. Let me know if it poses a problem for any of you,
            You can run fixrights.sh as often as you like, but please only run it directly from the report directory.

            Now also tested on Zabbix 4.4, PHP 5.4 - CentOS 7.7 - With and without SELinux active (Needed some extra twiddling with SELinux enabled - version 1.2.2 has the fix)

            Comment


              Click image for larger version

Name:	Capture.PNG
Views:	229
Size:	72.6 KB
ID:	405806Hi , i am able to reach the landing page , however when i try to generate the report, the report can't get any graph, is just show "No matching graphs found. Maybe tune the setting? " , anyone can advise ?
              Last edited by BEV3498; 24-07-2020, 06:43.

              Comment


              • Markus_M
                Markus_M commented
                Editing a comment
                Hi all,

                is it possible to exclude disabled items on a host when i create a report?

                martin,
                thx for this cool project.

                Regards
                Markus

              • provels
                provels commented
                Editing a comment
                Try changing the filter line to #.*#
                That will show anything and everything configured.

              • Markus_M
                Markus_M commented
                Editing a comment
                provels,
                that´s not that what i like. for example: i have a template with 43 service-checks, but on some hosts, only 2-3 services are on this host existent, the other items are disabled. i try to exclude the disabled items for the report, but the disabled items will show with no data...

                Thx for help

              Will this work with nginx webserver?

              Comment


              • rvanderkooi
                rvanderkooi commented
                Editing a comment
                Yes, install the zabbix-pdf-folder into your zabbix folder.

                I have also installed nginx en place the zabbix-pdf-folder into /usr/share/zabbix/

              Hello,

              i have Centos 8 with Zabbix 5.0.2 and nginx with php-pfm 7.2

              i have installed this pdf report, but it doesn't work.

              my nginx log said:

              2020/07/28 18:36:53 [error] 23162#0: *261 FastCGI sent in stderr: "PHP message: PHP Warning: get_class() expects parameter 1 to be object, null given in /usr/share/zabbix/zabbix-pdf-report/inc/ZabbixAPI.class.php on line 208" while reading response header from upstream, client: MYIP, server: myzabbixserver, request: "GET /zabbix-pdf-report/chooser.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/zabbix.sock:", host: "myzabbixserver"


              when i browse i have many of errors: CURL URL: https://myserver.
              I can see and choose the hosts.

              anybody a idea?

              Comment


              • rvanderkooi
                rvanderkooi commented
                Editing a comment
                This is fixed it!

                I downloaded the newest version of generator tool and change zabbix version: 4.4 to 5.0 in the config.inc.php.

              Hello,

              I am new to zabbix - could you send me directions on how we initiate this ? I have so far:

              1. installed the project from git
              2. copied the config.inc.php.dist to config.inc.php
              2. edited the config.inc.php file with my server info etc.
              3. Run the ./fixrights.sh

              then what we do ? restart httpd and zabbix server ?

              thank you,

              Spyros

              Comment

              Announcement

              Collapse
              No announcement yet.
              Working...
              X