rijAth mohAmmed nr rijAth mohAmmed nr - 1 month ago 101
PHP Question

PDF report Generation in Zabbix is not working

I am trying to add pdf report generation module onto zabbix from the below repo:

https://github.com/SandipSingh14/Zabbix_

I have created tmp and report folders.
Looks like the PDF's are not getting created on the server, not sure why! Please see a snapshot of the request below:

Error Snapshot

PHP Config File:

<?php
//CONFIGURABLE
# zabbix server info(user must have API access)
$z_server = 'http://10.10.100.122/zabbix';
$z_user = 'admin';
$z_pass = 'zabbix';
# Temporary directory for storing pdf data and graphs - must exist
$z_tmp_path = '/usr/share/zabbix/zabbix-dynamic-pdf-report/tmp';
# Directory for storing PDF reports
$pdf_report_dir = '/usr/share/zabbix/zabbix-dynamic-pdf-report/report';
# Root URL to reports
$pdf_report_url = $z_server ."/zabbix-dynamic-pdf-report/report";
# 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 = 'Asia/Calcutta';
# Logo used in PDF - may be empty
# TODO: Specify image size!
$pdf_logo = './images/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";
?>


Here is what I get when using the debug from index.php

HostID: 10153
Report Type: host
Time Period: 3600
Temp image path: /tmp/zabbix_report_OPt9cZ

HOSTNAME(id:10153)
CPU load(id:1289)
Memory usage(id:1290)
Disk space usage C:(id:1297)
Disk space usage E:(id:1399)
Disk space usage F:(id:1400)
Disk space usage G:(id:1401)
Report ready - available as: http://10.10.100.122/zabbix/zabbix-dynamic-pdf- report/report/HOSTNAME.pdf


OS: Ubuntu
Zabbix Version: 2.4.7

Here are the PHP Error logs:

[Mon Feb 15 21:19:47.162244 2016] [:error] [pid 29796] [client 10.10.100.108:55341] PHP Warning: Creating default object from empty value in /usr/share/zabbix/zabbix-dynamic-pdf-report/inc/ZabbixAPI.class.php on line 122, referer: http://10.10.100.122/zabbix/zabbix-dynamic-pdf-report/index.php
[Mon Feb 15 21:19:47.696413 2016] [:error] [pid 29796] [client 10.10.100.108:55341] PHP Warning: fopen(/usr/share/zabbix/zabbix-dynamic-pdf-report/report/BLR-D-J9PSXX1.pdf): failed to open stream: Permission denied in /usr/share/zabbix/zabbix-dynamic-pdf-report/createpdf.php on line 319, referer: http://10.10.100.122/zabbix/zabbix-dynamic-pdf-report/index.php
[Mon Feb 15 21:19:47.696446 2016] [:error] [pid 29796] [client 10.10.100.108:55341] PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /usr/share/zabbix/zabbix-dynamic-pdf-report/createpdf.php on line 320, referer: http://10.10.100.122/zabbix/zabbix-dynamic-pdf-report/index.php
[Mon Feb 15 21:19:47.696455 2016] [:error] [pid 29796] [client 10.10.100.108:55341] PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /usr/share/zabbix/zabbix-dynamic-pdf-report/createpdf.php on line 321, referer: http://10.10.100.122/zabbix/zabbix-dynamic-pdf-report/index.php


Please help me with your suggestions!

Answer

zabbix­dynamic­pdf­report

zabbix­dynamic­pdf­report module allow us to generate pdf reports. Once implemented we have options to generate reports for ‘Host’, ‘Host Group’ on time range of ‘Hour’, ‘Day’, ‘Week’, ‘Month’, ‘Year’. We can retrieve old report from ‘Old Reports’ section.

Implementation

  • Note: This procedure is mentioned for Ubuntu or similar os only.

Dependencies

  • php5­curl
  • php5­json

sudo apt-­get install php5­curl php5­json

Clone the git repo that contain the module

cd /opt/ git clone https://github.com/SandipSingh14/Zabbix_

Configure zabbix­dynamic­pdf­report according to zabbix­server (After changes ​Zabbix_​/zabbix­dynamic­pdf­report/config.inc.php should look like)

cat Zabbix_​/zabbix­dynamic­pdf­report/config.inc.php

<?php 
//CONFIGURABLE 
# zabbix server info(user must have API access) 
$z_server = 'http://zabbix.example.com/'; 
$z_user = 'admin'; 
$z_pass = 'zabbix'; 
# Temporary directory for storing pdf data and graphs ­ must exist 
$z_tmp_path    = './tmp'; 
# Directory for storing PDF reports 
$pdf_report_dir    = './report'; 
# Root URL to reports 
$pdf_report_url    = "./report"; 
# 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 / lanscape 
# time zone ­ see http://php.net/manual/en/timezones.php 
$timezone    = 'Asia/Calcutta'; # Logo used in PDF ­ may be empty 
# TODO: Specify image size! 
$pdf_logo    = './images/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"; 
?> 
  • Note: Change below mentioned variables according to your zabbix server
    • z_server = http://$ZABBIX_SERVER_DOMAIN/
    • z_user = $ZABBIX_USERNAME # This user must have admin access
    • z_pass = $ZABBIX_PASSWORD
    • timezone = Asia/Calcutta # If you are in India.

Change directory and create directory inside zabbix­dynamic­pdf­report

cd Zabbix_/zabbix­dynamic­pdf­report mkdir tmp report

Change zabbix auth to login method, it’s required for login into zabbix server.

sed ­i 's,user.authenticate,user.login,g' inc/ZabbixAPI.class.php sed ­i 's,user.authenticate,user.login,g' inc/ZabbixAPI.class.php.org

Copy zabbix­dynamic­pdf­report into /usr/share/zabbix/

cp ­r /opt/Zabbix_/zabbix­dynamic­pdf­report /usr/share/zabbix/

Restart apache

service apache2 restart

Open Generate PDF Report page

http://zabbix.example.com/zabbix­dynamic­pdf­report/index.php

The page should look like this:

enter image description here

Now you can choose report type ‘HOST OR HOSTGROUP’ and click the dropdown to select the hostname or hostgroup name

enter image description here