function pdfGen($group_name, $mode = NULL, $start_date, $end_date, $stats, $l, $title, $path_www) { global $centreon_path; // create new PDF document $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator("PDF Reports Module"); $pdf->SetAuthor(getGeneralOptInfo("pdfreports_report_author")); //$pdf->SetAuthor('Fully Automated Nagios'); $pdfTitle = $title . " " . $group_name; //$pdfTitle = "Rapport de supervision du hostgroup ".$group_name; $pdf->SetTitle($pdfTitle); //$pdf->SetSubject('TCPDF Tutorial'); //$pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // define default header data $header = $title . " " . $group_name; //$header = "Rapport de supervision du hostgroup ".$group_name; //$ip = $_SERVER['HOSTNAME']; $startDate = date("d/m/Y", $start_date); $time = time(); $endDate = date("d/m/Y", $time); $string = _("From") . " " . strftime("%A", $start_date) . " " . $startDate . " " . _("to") . " " . strftime("%A", $time) . " " . $endDate . "\n"; // set default header data $pdf->SetHeaderData('../../../img/headers/' . getGeneralOptInfo("pdfreports_report_header_logo"), PDF_HEADER_LOGO_WIDTH, $header, $string); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); // --------------------------------------------------------- // set font $pdf->SetFont('helvetica', '', 12); // add a page $pdf->AddPage(); //Column titles $header = array('Status', 'Time', 'Total Time', 'Mean Time', 'Alert'); // Pie chart Generation $piechart_img = pieGen($stats, $mode); //Data loading $data = $pdf->LoadData($stats); // print colored table //$pdf->ColoredTable($header, $data,$chart_img); if ($mode == "hgs") { // Hostgroup $pdf->ColoredTable($header, $data, $piechart_img, $path_www); } else { if ($mode == "sgs") { // Servicegroup $pdf->ServicesColoredTable($header, $data, $piechart_img, $path_www); } } // --------------------------------------------------------- //génération d'un nom de pdf $endDay = date("d", $time); $endYear = date("Y", $time); $endMonth = date("m", $time); $pdfDirName = getGeneralOptInfo("pdfreports_path_gen") . $endYear . $endMonth . $endDay . "/"; $pdfFileName = $pdfDirName . $endYear . "-" . $endMonth . "-" . $endDay . "_" . $group_name . ".pdf"; if (!is_dir($pdfDirName)) { mkdir($pdfDirName); } //Close and output PDF document $pdf->Output($pdfFileName, 'F'); return $pdfFileName; }
} } // Generate servicegroup reports if (isset($services) && count($services) > 0) { foreach ($services['report_sg'] as $sg_id) { $sg_stats = array(); $sg_stats = getLogInDbForServicesGroup($sg_id, $start_date, $end_date, $reportingTimePeriod); //print_r($stats); //tableau contenant la liste des pdf générés $Allfiles[] = pdfGen(getMyServiceGroupName($sg_id), 'sgs', $start_date, $end_date, $sg_stats, $l, $reportinfo["report_title"], ""); //$Allfiles[] = pdfGen( getMyServiceGroupName($sg_id), 'sgs', $start_date, $end_date, $sg_stats, $l, getGeneralOptInfo("pdfreports_report_header_logo") , $reportinfo["report_title"] ); //print_r($Allfiles); } } $emails = getReportContactEmail($report_id); //print_r( $emails ); $files = array(); foreach ($Allfiles as $file) { $files[basename($file)]["url"] = $file; } //print_r($files); mailer(getGeneralOptInfo("pdfreports_report_author"), getGeneralOptInfo("pdfreports_email_sender"), $emails, $reportinfo['subject'], $reportinfo['mail_body'], getGeneralOptInfo("pdfreports_smtp_server_address"), $files, $reportinfo['name']); $files = null; $Allfiles = null; $emails = null; $services = null; $hosts = null; } } catch (Exception $e) { programExit($e->getMessage()); }
function RunNowReportInDB($report_id = null, $report_arr = array()) { if (!$report_id && !count($report_arr)) { return; } global $pearDB, $oreon; $hosts = array(); $reportinfo = array(); $hosts = getHostReport($report_id); $reportinfo = getReportInfo($report_id); $services = getServiceGroupReport($report_id); $dates = getPeriodToReportFork($reportinfo['period']); $start_date = $dates[0]; $end_date = $dates[1]; $reportingTimePeriod = getreportingTimePeriod(); if (isset($_SERVER['DOCUMENT_ROOT'])) { $nb_folders = count(explode("/", $_SERVER['DOCUMENT_ROOT'])); $path_www = "/" . implode("/", array_fill(0, intval($nb_folders) - 1, '..')); //echo $_SERVER['DOCUMENT_ROOT'] . " " . intval($nb_folders) -1 . " " . $path_www . "<br />"; } if (isset($hosts) && count($hosts) > 0) { foreach ($hosts['report_hgs'] as $hgs_id) { $stats = array(); $stats = getLogInDbForHostGroup($hgs_id, $start_date, $end_date, $reportingTimePeriod); $Allfiles[] = pdfGen($report_id, getMyHostGroupName($hgs_id), 'hgs', $start_date, $end_date, $stats, "", $reportinfo["report_title"], $path_www); // "/../.." //print_r($Allfiles); } } if (isset($services) && count($services) > 0) { foreach ($services['report_sg'] as $sg_id) { $sg_stats = array(); $sg_stats = getLogInDbForServicesGroup($sg_id, $start_date, $end_date, $reportingTimePeriod); $Allfiles[] = pdfGen($report_id, getMyServiceGroupName($sg_id), 'sgs', $start_date, $end_date, $sg_stats, $l, $reportinfo["report_title"], $path_www); } } $emails = getReportContactEmail($report_id); $files = array(); foreach ($Allfiles as $file) { $files[basename($file)]["url"] = $file; } mailer(getGeneralOptInfo("pdfreports_report_author"), getGeneralOptInfo("pdfreports_email_sender"), $emails, $reportinfo['subject'], $reportinfo['mail_body'], getGeneralOptInfo("pdfreports_smtp_server_address"), $files, $reportinfo['name']); $files = null; $Allfiles = null; $emails = null; $services = null; $hosts = null; }
$oreon = new Oreon($user); } require_once $centreonClasspath . '/centreonACL.class.php'; /* * Main */ global $pearDB, $pearDBndo, $pearDBO, $oreon; $reports = array(); $reports = getActiveReports($period_arg); $reportsFiles = array(); foreach ($reports as $report_id => $name) { $reportinfo = array(); $reportinfo = getReportInfo($report_id); $is_not_an_report = array(".", "..", "README", "readme", "LICENCE", "licence"); $is_a_valid_report = array('pdf'); $pdfDirName = getGeneralOptInfo("pdfreports_path_gen") . $reportinfo['report_id'] . "/"; if (!($dh = @opendir($pdfDirName))) { // error_log("WARNING: can't open directory '".$rep."'",0); return; //break; } while (false !== ($filename = readdir($dh))) { if ($filename == "." || $filename == "..") { continue; } if (in_array($filename, $is_not_an_report)) { continue; } $pinfo = pathinfo($filename); if (isset($pinfo["extension"]) && isset($is_a_valid_report[$pinfo["extension"]])) { continue;