Even I'm using zabbix 4.0 and the changes i made is in the "ZabbixAPI.class.php" changed "user.authenticate" to "user.login" and it started working. Now i'm able to fetch the graphs as well.
Ad Widget
Collapse
Zabbix Dynamic PDF Report Generation
Collapse
X
-
Hi Dear Lets expose you my problem:
I've installed a fresh zabbix server now. I installed Zabbix 4.4 on ubuntu 18.04.Now I would like you to tell me step by step what to do next...
For now i did this:- clone :
clone https://github.com/catonrug/zabbix-pdf-report.git to /usr/share/
-copy and edit:
cp config.inc.php.dist config.inc.php
vi config.inc.php
In the configuration i changed
#the server Ip
#The Login
# the passwd
-create tmp and reports folders
./fixrights.sh
-give the rights
chmod 777 tmp reports
-copy
cp /usr/share/zabbix-pdf-report/zabbix-pdf-report.conf /etc/apache2/conf-available/
-linked
ln -s /etc/apache2/conf-available/zabbix-pdf-report.conf /etc/apache2/conf-enabled
-restart apache2
service apache2 restart
-Disable SELinux
setenforce 0
after all this I was not able to get the UI so,
I -i've copy the zabbix-pdf-report folder to /var/www/html/
and linked with:
-ln /var/html/zabbix-pdf-report/zabbix-pdf-report.conf /etc/apache2/conf-enabled
Then the http://my ip/zabbix-pdf-report/ shows only the UI.
When I put the credentials, the next page doesn't appear
And I got this log in error.log
[Sat Oct 19 19:57:57.437477 2019] [php7:warn] [pid 29897] [client 192.168.2.254:52777] PHP Warning: get_class() expects parameter 1 to be object,null given in /var/www/html/zabbix-pdf-report/inc/ZabbixAPI.class.php on line 208, referer: http://my_Ip/zabbix-pdf-report/ [Sat Oct 19 19:57:57.437787 2019] [php7:error] [pid 29897] [client 192.168.2.254:52777] PHP Fatal error: Uncaught Error: Call to undefined function curl_init() in /var/www/html/zabbix-pdf-report/inc/ZabbixAPI.class.php:324\nStack trace:\n#0 /var/www/html/zabbix-pdf-report/inc/ZabbixAPI.class.php(257): ZabbixAPI::__jsonRequest('http://154.127....','{"auth":null,"m...')\n#1 /var/www/html/zabbix-pdf-report/inc/ZabbixAPI.class.php(285): ZabbixAPI->__callAPI('user.login', Array)\n#2 /var/www/html/zabbix-pdf-report/inc/ZabbixAPI.class.php(100):ZabbixAPI->__login()\n#3 /var/www/html/zabbix-pdf-report/index.php(30): ZabbixAPI::login('http://154.127....','Admin', '*******')\n#4 {main}\n thrown in /var/www/html/zabbix-pdf-report/inc/ZabbixAPI.class.php on line 324, referer: http://my_ip/zabbix-pdf-report/
So that is ,Could you please help me?Last edited by KINGAB_93; 21-10-2019, 10:17.Comment
-
I've downloaded the package fromgithub.com/martinm76/zabbix-pdf-report, and changed the IP and company name inconfig.inc.php, and thus it started working. Below is my Config.inc.php page for your referance.
<?php header('Access-Control-Allow-Origin: *');?><?php/*** Zabbix** Copyright (C) 2001-2018 Zabbix SIA**** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the** GNU General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program; if not, write to the Free Software** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.**/
// reset the LC_CTYPE locale so that case transformation functions would work correctly// it is also required for PHP to work with the Turkish locale (https://bugs.php.net/bug.php?id=18556)// WARNING: this must be done before executing any other code, otherwise code execution could fail!// this will be unnecessary in PHP 5.5//require_once dirname(__FILE__).'index.php';setlocale(LC_CTYPE, ['C', 'POSIX', 'en', 'en_US', 'en_US.UTF-8', 'English_United States.1252', 'en_GB', 'en_GB.UTF-8']);
require_once dirname(__FILE__).'/classes/core/Z.php';
try {Z::getInstance()->run(ZBase::EXEC_MODE_DEFAULT);}catch (DBException $e) {(new CView('general.warning', ['header' => 'Database error','messages' => [$e->getMessage()],'theme' => ZBX_DEFAULT_THEME]))->render();
exit;}catch (ConfigFileException $e) {switch ($e->getCode()) {case CConfigFile::CONFIG_NOT_FOUND:redirect('setup.php');exit;
case CConfigFile::CONFIG_ERROR:(new CView('general.warning', ['header' => 'Configuration file error','messages' => [$e->getMessage()],'theme' => ZBX_DEFAULT_THEME]))->render();
exit;}}catch (Exception $e) {(new CView('general.warning', ['header' => $e->getMessage(),'messages' => [],'theme' => ZBX_DEFAULT_THEME]))->render();
exit;}
CProfiler::getInstance()->start();
global $ZBX_SERVER, $ZBX_SERVER_PORT, $ZBX_USER_NAME, $ZBX_PWD, $page;
$page = ['title' => null,'file' => null,'scripts' => null,'type' => null,'menu' => null];
//dynamic pdf generation//CONFIGURABLE# zabbix server info(user must have API access)$z_server = 'http://127.0.0.1:8080/zabbix-4.0.0/';$z_server ='http://127.0.0.1:8080/zabbix-4.0.0/frontends/php/';$z_user ='Admin';$z_pass = '123456';# Temporary directory for storing pdf data and graphs - must exist$z_tmp_path = 'http://127.0.0.1:8080/zabbix-4.0.0/frontends/php/tmp';//$z_tmp_path = './tmp';# Directory for storing PDF reports//$pdf_report_dir = './reports';$pdf_report_dir = 'http://127.0.0.1:8080/zabbix-4.0.0/frontends/php/report/reports';# Root URL to reports//$pdf_report_url = $z_server ."report/reports";$pdf_report_url = 'http://127.0.0.1:8080/zabbix-4.0.0/frontends/php/report/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 = 'India/Kolkata';# Logo used in PDF - may be empty# TODO: Specify image size!$pdf_logo = 'http://127.0.0.1:8080/zabbix-4.0.0/frontends/php/images/general/zabbix.png';$company_name = 'Zabbix';
//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_url_api = $z_server ."api_jsonrpc.php";$z_login_data = "name=" .$z_user ."&password=" .$z_pass ."&autologin=1&enter=Sign+in";
Hope This will be useful for you.Comment
-
before make a configuration in config.inc.php and after you download what have you done?
I would like to know all your steps?
Also tell me which OS are you using ?
I'm for instance using ubuntu 18.04 and zabbix 4.4....Last edited by KINGAB_93; 21-10-2019, 15:35.
-
-
I downloaded the code from the I shared before, I'm using ubuntu 18.04 with zabbix version 4.2 and centos7 with 4.2 zabbix version.
First I changed "Zabbix.API.class.php" page. In this page I changed 'user.authenticate' to 'user.login'.
Second, I created a file with the name 'config.inc.php' and added the above code.
This was the coding changes I did and I was able to generate PDF based on hosts.Comment
-
Hi, just to comment what works for me in version 4.4 for zabbix on Centos 7.6
cd /usr/share/zabbix
git clone https://github.com/martinm76/zabbix-pdf-report.git
cd zabbix-pdf-report/
cp config.inc.php.dist config.inc.php ( and edit the file with your conf)
./fixrights.sh
chmod 777 reports/ tmp/
In your zabbix --> Screens --> Create New
Resource: URL
URL: http://zabbix.yourcompany/zabbix-pdf.../createpdf.php
800x600 center (1x1)Comment
-
Yes, but you have yo fill:
# zabbix server info(user must have API access)
// $z_server = 'http://localhost/zabbix/';
$z_server = ''; // 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 installed and use https!
$z_user = '';
$z_pass = '';
that's all.
There is no other change!
//CONFIGURABLE
$user_login=1; // 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','advanc ed 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'=>'number', '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 = ''; // 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 installed and use https!
$z_user = '';
$z_pass = '';
# 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/Oslo';
# 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";
?>
-
Hi all,
I have an issue with zabbix_pdf_report where my zabbix web UI freezes completely. I have 2 docker containers, one running the Zabbix server (zabbix/zabbix-server-mysql:alpine-latest) and the other one running the Zabbix web UI (zabbix/zabbix-web-nginx-mysql:alpine-latest). Sometimes it works, but sometimes it freezes, especially when I ask for 'Item Graphs'. By investigating the logs, I get some responses (in the __callAPI requests) fetching graph information, but at some point the process stops. I don't know if it is an issue of the ZabbixAPI or a configuration issue of nginx or docker setup. I just want to know if anyone has faced something similar, or if someone can give a hint.
I am using Zabbix 4.4 and php7 (if that helps)
Thank you in advance.Comment
-
Comment
-
Hello
Im currently having issues with pdf report.
Zabbix version : 4.x Php 7.2
Php-curl and php-json installed with full modules
Display_errors=off set in conf
When connected on URL http://my.ip.address/zbxreport/chooser.php
i get this at the top of my form :
CURL URL: http://my.ip.address/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":"mypassword","user":"myuser"},"jsonrp c":"2.0"} [10102] => gzip ) Got response from API: ({"jsonrpc":"2.0","result":"127babc958b92f06c7a717 3ab9c1e37d","id":1}) Response decoded: (Array ( [jsonrpc] => 2.0 [result] => 127babc958b92f06c7a7173ab9c1e37d [id] => 1 ) __login() Got response from API: (127babc958b92f06c7a7173ab9c1e37d) CURL URL: http://my.ip.address/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":"127babc958b92f06c7a7173ab9c1e37d","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":[{"hostid":"10322","name":"ILOM MANAGING"},{"hostid":"10324","name":"RDS"},{"hosti d":"10320","name":"ServerADWindows"},{"hostid":"10 319","name":"Simon"},{"hostid":"10336","name":"Uni fi 1"},{"hostid":"10338","name":"Unifi 2"},{"hostid":"10339","name":"Unifi Voip"},{"hostid":"10321","name":"Website"},{"hosti d":"10084","name":"Zabbix server"}],"id":1}) Response decoded: (Array ( [jsonrpc] => 2.0 [result] => Array ( [0] => Array ( [hostid] => 10322 [name] => ILOM MANAGING ) [1] => Array ( [hostid] => 10324 [name] => RDS ) [2] => Array ( [hostid] => 10320 [name] => ServerADWindows ) [3] => Array ( [hostid] => 10319 [name] => Simon ) [4] => Array ( [hostid] => 10336 [name] => Unifi 1 ) [5] => Array ( [hostid] => 10338 [name] => Unifi 2 ) [6] => Array ( [hostid] => 10339 [name] => Unifi Voip ) [7] => Array ( [hostid] => 10321 [name] => Website ) [8] => Array ( [hostid] => 10084 [name] => Zabbix server ) ) [id] => 1 ) CURL URL: http://my.ip.address/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":"127babc958b92f06c7a7173ab9c1e37d","method ":"hostgroup.get","id":1,"params":{"output":["groupid","name"],"real_hosts":"1","with_graphs":"1","sortfield":"n ame"},"jsonrpc":"2.0"} [10102] => gzip ) Got response from API: ({"jsonrpc":"2.0","result":[{"groupid":"15","name":"Test"},{"groupid":"4","nam e":"Zabbix servers"}],"id":1}) Response decoded: (Array ( [jsonrpc] => 2.0 [result] => Array ( [0] => Array ( [groupid] => 15 [name] => Test ) [1] => Array ( [groupid] => 4 [name] => Zabbix servers ) ) [id] => 1 ) CURL URL: http://192.168.25.196/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":"127babc958b92f06c7a7173ab9c1e37d","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)
I still get the form and i can complete it. However, i can only acces the link to the pdf report when checking "debug" and then, the link appaers in the bottom of the page which is full of data (as shown in linked image).
Is it noraml that the pdf is generated like this ? If not, can anybody help me please ?
Thank you.
Comment
-
Comment
-
Thanks, now the problem I'm having is this one.
CURL URL: http://192.168.16.5/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":"zabbix","user":"Admin"},"jsonrpc":"2 .0"} [10102] => gzip ) Got response from API: ({"jsonrpc":"2.0","result":"0ceb0de19676ea1dbdd0a0 68f423d179","id":1}) Response decoded: (Array ( [jsonrpc] => 2.0 [result] => 0ceb0de19676ea1dbdd0a068f423d179 [id] => 1 ) __login() Got response from API: (0ceb0de19676ea1dbdd0a068f423d179) CURL URL: http://192.168.16.5/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":"0ceb0de19676ea1dbdd0a068f423d179","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":[{"hostid":"10084","name":"Zabbix server"}],"id":1}) Response decoded: (Array ( [jsonrpc] => 2.0 [result] => Array ( [0] => Array ( [hostid] => 10084 [name] => Zabbix server ) ) [id] => 1 ) CURL URL: http://192.168.16.5/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":"0ceb0de19676ea1dbdd0a068f423d179","method ":"hostgroup.get","id":1,"params":{"output":["groupid","name"],"real_hosts":"1","with_graphs":"1","sortfield":"n ame"},"jsonrpc":"2.0"} [10102] => gzip ) Got response from API: ({"jsonrpc":"2.0","result":[{"groupid":"4","name":"Zabbix servers"}],"id":1}) Response decoded: (Array ( [jsonrpc] => 2.0 [result] => Array ( [0] => Array ( [groupid] => 4 [name] => Zabbix servers ) ) [id] => 1 ) CURL URL: http://192.168.16.5/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":"0ceb0de19676ea1dbdd0a068f423d179","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)
-
-
Comment
-
Thank you for distilling this down so completely. I'm on the 4.4.6 appliance. Followed your directions easily, but I seem to have a problem. I made all the edits, created the screen, and get the login screen, but after I login, all I see is a white screen, Maybe it's a rights issue? I'm using the Admin/zabbix login on the appliance version, I have to sudo for anything on the CL (and I did for anything in your commands that needed it). I'm no expert. Thanks for any input.Hi, just to comment what works for me in version 4.4 for zabbix on Centos 7.6
cd /usr/share/zabbix
git clone https://github.com/martinm76/zabbix-pdf-report.git
cd zabbix-pdf-report/
cp config.inc.php.dist config.inc.php ( and edit the file with your conf)
./fixrights.sh
chmod 777 reports/ tmp/
In your zabbix --> Screens --> Create New
Resource: URL
URL: http://zabbix.yourcompany/zabbix-pdf.../createpdf.php
800x600 center (1x1)
SOLVED!
Turns out the 4.4.6 appliance does not include either php-curl or php-json. Oops. Works great now! Thanks for these instructions!
Also had to edit the URL address to insert /zabbix/ between the "zabbix.yourcompany"and the "zabbix-pdf-report" folder. No big deal.HTML Code:sudo apt-get update sudo apt-get install php7.0-curl sudo apt-get install php-json
NEW ISSUE
Seems now I'm getting "Report type not selected!" regularly. Sometimes it comes up immediately, other times when the report is already displayed. That error is listed on line 186 of createpdf.php. Maybe the PDF generator's crashing. I'll keep messing with it, but it seems to work better if I access it from another PC rather than on the host screen itself. But once it crashes, I have to restart Apache or logoff/on Zabbix.
EdIt - Hmm, this may be a browser issue. The browser I was using was wound pretty tight security-wise. I ran the reports on a default Chrome install and they generated fine.
Is it me or is the "Old Reports (Click to Show)" link inoperative?Last edited by provels; 17-04-2020, 02:02.Comment
Comment