コード例 #1
1
function CreatePDF($hostarray)
{
    global $stime, $timeperiod, $tmp_pdf_data, $z_tmpimg_path, $debug;
    foreach ($hostarray as $key => $host) {
        $hostid = $hostarray[$key]['hostid'];
        $hostname = $hostarray[$key]['name'];
        $trimmed_hostname = str_replace(" ", "_", $hostname);
        if ($debug) {
            echo "<b>{$hostname}(id:{$hostid})</b></br>\n";
        }
        $fh = fopen($tmp_pdf_data, 'a') or die("Can't open {$tmp_pdf_data} for writing!");
        $stringData = "1<Graphs for " . $hostname . ">\n";
        fwrite($fh, $stringData);
        fclose($fh);
        #$hostGraphs = ZabbixAPI::fetch_array('graph','get',array('output'=>'extend','hostids'=>$hostid))
        $hostGraphs = ZabbixAPI::fetch_array('graph', 'get', array('output' => array('graphid', 'name'), 'hostids' => $hostid)) or die('Unable to get graphs: ' . print_r(ZabbixAPI::getLastError(), true));
        #var_dump($hostGraphs);
        asort($hostGraphs);
        foreach ($hostGraphs as $graphkey => $graphs) {
            $graphid = $hostGraphs[$graphkey]['graphid'];
            $graphname = $hostGraphs[$graphkey]['name'];
            $image_file = $z_tmpimg_path . "/" . $trimmed_hostname . "_" . $graphid . ".png";
            if ($debug) {
                echo "{$graphname}(id:{$graphid})</br>\n";
            }
            $fh = fopen($tmp_pdf_data, 'a') or die("Can't open {$tmp_pdf_data} for writing!");
            $stringData = "2<{$graphname}>\n";
            fwrite($fh, $stringData);
            $stringData = "[" . $image_file . "]\n";
            fwrite($fh, $stringData);
            GetGraphImageById($graphid, $stime, $timeperiod, '750', '150', $image_file);
            fclose($fh);
            if ($debug) {
                ob_flush();
                flush();
            }
        }
    }
}
コード例 #2
0
ファイル: index.php プロジェクト: SandipSingh14/Zabbix_
<body class="originalblue">
<div id="message-global-wrap"><div id="message-global"></div></div>
<table class="maxwidth page_header" cellspacing="0" cellpadding="5"><tr><td class="page_header_l"><a class="image" href="http://www.zabbix.com/" target="_blank"><div class="zabbix_logo">&nbsp;</div></a></td><td class="maxwidth page_header_r">&nbsp;</td></tr></table>
<br/><br/>
<center><h1>Generate PDF Report</h1></center>
<br/>
<?php 
// ERROR REPORTING
error_reporting(E_ALL);
set_time_limit(60);
// ZabbixAPI Connection
ZabbixAPI::debugEnabled(TRUE);
ZabbixAPI::login($z_server, $z_user, $z_pass) or die('Unable to login: '******'host', 'get', array('output' => array('hostid', 'name'), 'sortfield' => 'host', 'with_graphs' => '1', 'sortfield' => 'name')) or die('Unable to get hosts: ' . print_r(ZabbixAPI::getLastError(), true));
$host_groups = ZabbixAPI::fetch_array('hostgroup', 'get', array('output' => array('groupid', 'name'), 'real_hosts' => '1', 'with_graphs' => '1', 'sortfield' => 'name')) or die('Unable to get hosts: ' . print_r(ZabbixAPI::getLastError(), true));
ZabbixAPI::logout($z_server, $z_user, $z_pass) or die('Unable to logout: ' . print_r(ZabbixAPI::getLastError(), true));
//var_dump($hosts);
//var_dump($host_group);
// Form dropdown boxes from Zabbix API Data
?>
<center>
<form class="cmxform" id="ReportForm" name="ReportForm" action='createpdf.php' method='GET'>
<table border="1" rules="NONE" frame="BOX" width="600" cellpadding="10">
<tr><td valign="middle" align="left" width="115">
<label for="ReportType"><b>Report type</b></label>
</td><td valign="center" align="left" height="30">
<p>
<input id="ReportHost" type="radio" name="ReportType" value="host" title="Generate report on HOST" checked="checked" />Host
<input id="ReportHostGroup" type="radio" name="ReportType" value="hostgroup" title="Generate report on GROUP" />Host Group
</p>
コード例 #3
0
ファイル: createpdf.php プロジェクト: itnihao/Zabbix_
        exit;
    }
    $hosts = ZabbixAPI::fetch_array('host', 'get', array('output' => array('hostid', 'name'), 'with_graphs' => 'true', 'hostids' => $hostid)) or die('Unable to get hosts: ' . print_r(ZabbixAPI::getLastError(), true));
    //var_dump($hosts);
    // Get name to be used in PLACEHOLDER-part of filename
    $name = $hosts[0]['name'];
    $reportname = str_replace(" ", "_", $name);
    CreatePDF($hosts);
} elseif ($reporttype == 'hostgroup') {
    if (!is_numeric($groupid)) {
        echo "ERROR: Need groupid for group report!</br>\n";
        exit;
    }
    $hosts = ZabbixAPI::fetch_array('host', 'get', array('output' => array('hostid', 'name'), 'with_graphs' => 'true', 'groupids' => $groupid)) or die('Unable to get hosts: ' . print_r(ZabbixAPI::getLastError(), true));
    //var_dump($hosts);
    $hostgroupname = ZabbixAPI::fetch_array('hostgroup', 'get', array('output' => array('name'), 'groupids' => $groupid)) or die('Unable to get hostgroup: ' . print_r(ZabbixAPI::getLastError(), true));
    //var_dump($hostgroupname);
    $name = $hostgroupname[0]['name'];
    $reportname = str_replace(" ", "_", $name);
    CreatePDF($hosts);
} else {
    echo "Report type not selected!\n";
    exit;
}
//
// Create PDF
//
if (!file_exists($tmp_pdf_data)) {
    echo "Report {$tmp_pdf_data} not found! Cannot continue to create PDF.";
    exit;
}
コード例 #4
0
ファイル: example.php プロジェクト: jonathangl/PHP-Zabbix-API
<?php

require_once "ZabbixAPI.class.php";
// This enables debugging, this is rather verbose but can help debug problems
//ZabbixAPI::debugEnabled(TRUE);
// This logs into Zabbix, and returns false if it fails
ZabbixAPI::login('http://genbook/zabbix/', 'apiuser', 'ap1') or die('Unable to login: '******'apiinfo', 'version') or die('Unable to get Zabbix Version: ' . print_r(ZabbixAPI::getLastError(), true));
echo "Server running Zabbix API Version: {$version}\n<br>";
// Fetch the user ids on the server, fetch_column ensures we just get the first item
// if you want to understand why I do this, put fetch_array instead and see!
$users = ZabbixAPI::fetch_column('user', 'get') or die('Unable to get user ids: ' . print_r(ZabbixAPI::getLastError(), true));
echo "User IDs found: " . implode($users, ',') . "\n<br>";
// Fetch hosts, but with extend option to get more data, and limit records returned
$five_hosts = ZabbixAPI::fetch_array('host', 'get', array('extendoutput' => 1, 'limit' => 5)) or die('Unable to get hosts: ' . print_r(ZabbixAPI::getLastError(), true));
echo "Retrieved maximum of five hosts: " . print_r($five_hosts, true) . "\n<br>";
// Do a simple update of userid = 1, set refresh = 1000
// NOTE: If this fails, it's because your API user is not a super-admin
ZabbixAPI::query('user', 'update', array('userid' => 1, 'refresh' => 1000)) or die('Unable to update: ' . print_r(ZabbixAPI::getLastError(), true));
echo "Updated userid 1 with refresh value of 1000!\n";