mirror of
https://github.com/rsyslog/loganalyzer.git
synced 2025-09-26 03:09:21 +02:00
Added command line based report generator
This commit is contained in:
parent
c23a349168
commit
979aaa4db5
195
src/cron/cmdreportgen.php
Normal file
195
src/cron/cmdreportgen.php
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
*********************************************************************
|
||||||
|
* phpLogCon - http://www.phplogcon.org
|
||||||
|
* -----------------------------------------------------------------
|
||||||
|
* Command Report Generator File
|
||||||
|
*
|
||||||
|
* -> This file is meant to run on command line, or via CRON / task Scheduler
|
||||||
|
*
|
||||||
|
* All directives are explained within this file
|
||||||
|
*
|
||||||
|
* Copyright (C) 2008-2009 Adiscon GmbH.
|
||||||
|
*
|
||||||
|
* This file is part of phpLogCon.
|
||||||
|
*
|
||||||
|
* PhpLogCon 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* PhpLogCon 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 phpLogCon. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* A copy of the GPL can be found in the file "COPYING" in this
|
||||||
|
* distribution
|
||||||
|
*********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
// *** Default includes and procedures *** //
|
||||||
|
define('IN_PHPLOGCON', true);
|
||||||
|
$gl_root_path = './../';
|
||||||
|
|
||||||
|
// Now include necessary include files!
|
||||||
|
include_once($gl_root_path . 'include/functions_common.php');
|
||||||
|
include_once($gl_root_path . 'include/functions_frontendhelpers.php');
|
||||||
|
include_once($gl_root_path . 'include/functions_filters.php');
|
||||||
|
|
||||||
|
// Include LogStream facility
|
||||||
|
include_once($gl_root_path . 'classes/logstream.class.php');
|
||||||
|
|
||||||
|
// Set commandline mode for the script
|
||||||
|
define('IN_PHPLOGCON_COMMANDLINE', true);
|
||||||
|
$content['IN_PHPLOGCON_COMMANDLINE'] = true;
|
||||||
|
InitPhpLogCon();
|
||||||
|
InitSourceConfigs();
|
||||||
|
InitFilterHelpers(); // Helpers for frontend filtering!
|
||||||
|
|
||||||
|
// Firts of all init List of Reports!
|
||||||
|
InitReportModules();
|
||||||
|
// ---
|
||||||
|
|
||||||
|
// --- Helper functions
|
||||||
|
/*
|
||||||
|
* Cleans data in desired logstream
|
||||||
|
*/
|
||||||
|
function RunReport()
|
||||||
|
{
|
||||||
|
global $content, $gl_root_path;
|
||||||
|
|
||||||
|
// Get Reference to report!
|
||||||
|
$myReport = $content['REPORTS'][ $content['reportid'] ];
|
||||||
|
|
||||||
|
// Get reference to savedreport
|
||||||
|
$mySavedReport = $myReport['SAVEDREPORTS'][ $content['savedreportid'] ];
|
||||||
|
|
||||||
|
// Get Objectreference to report
|
||||||
|
$myReportObj = $myReport["ObjRef"];
|
||||||
|
|
||||||
|
// Set SavedReport Settings!
|
||||||
|
$myReportObj->InitFromSavedReport($mySavedReport);
|
||||||
|
|
||||||
|
//Debug Output
|
||||||
|
PrintHTMLDebugInfo( DEBUG_INFO, "RunReport", GetAndReplaceLangStr($content["LN_CMD_RUNREPORT"], $mySavedReport['customTitle']) );
|
||||||
|
|
||||||
|
// Perform check
|
||||||
|
$res = $myReportObj->verifyDataSource();
|
||||||
|
if ( $res != SUCCESS )
|
||||||
|
{
|
||||||
|
// Print error and die!
|
||||||
|
$szError = GetAndReplaceLangStr( $content['LN_REPORTS_ERROR_ERRORCHECKINGSOURCE'], GetAndReplaceLangStr( GetErrorMessage($res), $mySavedReport['sourceid']) );
|
||||||
|
if ( isset($extraErrorDescription) )
|
||||||
|
$szError .= "<br><br>" . GetAndReplaceLangStr( $content['LN_SOURCES_ERROR_EXTRAMSG'], $extraErrorDescription);
|
||||||
|
DieWithErrorMsg( $szError );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Call processing part now!
|
||||||
|
$res = $myReportObj->startDataProcessing();
|
||||||
|
if ( $res != SUCCESS )
|
||||||
|
DieWithErrorMsg( GetAndReplaceLangStr( $content['LN_GEN_ERROR_REPORTGENFAILED'], $mySavedReport['customTitle'], GetErrorMessage($res) );
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// --- Perform report output
|
||||||
|
|
||||||
|
// Init IncludePath
|
||||||
|
$reportIncludePath = $myReportObj->GetReportIncludePath();
|
||||||
|
|
||||||
|
// Include Custom language file if available
|
||||||
|
$myReportObj->InitReportLanguageFile($reportIncludePath);
|
||||||
|
|
||||||
|
// Init template Parser
|
||||||
|
$page = new Template();
|
||||||
|
$page -> set_path ( $reportIncludePath );
|
||||||
|
|
||||||
|
// Parse template
|
||||||
|
$page -> parser($content, $myReportObj->GetBaseFileName());
|
||||||
|
|
||||||
|
// Output the result
|
||||||
|
$res = $myReportObj->OutputReport( $page ->result(), $szErrorStr );
|
||||||
|
if ( $res == SUCCESS && $myReportObj->GetOutputTarget() != REPORT_TARGET_STDOUT )
|
||||||
|
{
|
||||||
|
//Debug Output
|
||||||
|
PrintHTMLDebugInfo( DEBUG_INFO, "RunReport", GetAndReplaceLangStr($content["LN_GEN_SUCCESS_REPORTWASGENERATED_DETAILS"], $szErrorStr) );
|
||||||
|
}
|
||||||
|
else if ( $res == ERROR )
|
||||||
|
{
|
||||||
|
// Debug Error
|
||||||
|
PrintHTMLDebugInfo( DEBUG_ERROR, "RunReport", GetAndReplaceLangStr($content["LN_GEN_ERROR_REPORTFAILEDTOGENERATE"], $szErrorStr) );
|
||||||
|
}
|
||||||
|
// ---
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ---
|
||||||
|
|
||||||
|
|
||||||
|
// --- BEGIN Custom Code
|
||||||
|
//Additional Includes
|
||||||
|
include($gl_root_path . 'include/functions_debugoutput.php');
|
||||||
|
|
||||||
|
// Run into Commandline part now!
|
||||||
|
/* Only run if we are in command line mode
|
||||||
|
*
|
||||||
|
* Possible Operation Types:
|
||||||
|
* runreport = To create a report, use this operation type.
|
||||||
|
* Sample 1: Run report from type "monilog" with savedreportid 3
|
||||||
|
* php cmdreportgen.php runreport monilog 3
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Init DebugHeader
|
||||||
|
PrintDebugInfoHeader();
|
||||||
|
|
||||||
|
// --- Now read command line args!
|
||||||
|
// Operation argv
|
||||||
|
if ( isset($_SERVER["argv"][1]) )
|
||||||
|
$operation = $_SERVER["argv"][1];
|
||||||
|
else
|
||||||
|
DieWithErrorMsg( $content["LN_CMD_NOOP"] );
|
||||||
|
|
||||||
|
// SavedReportID argv
|
||||||
|
if ( isset($_SERVER["argv"][2]) )
|
||||||
|
{
|
||||||
|
// Set to SourceID property!
|
||||||
|
$content['reportid'] = $_SERVER["argv"][2];
|
||||||
|
|
||||||
|
// Check if exists
|
||||||
|
if ( !isset($content['REPORTS'][ $content['reportid'] ]) )
|
||||||
|
DieWithErrorMsg( GetAndReplaceLangStr($content["LN_CMD_LOGSTREAMNOTFOUND"], $content['reportid']) );
|
||||||
|
|
||||||
|
// Get Reference to report!
|
||||||
|
$myReport = $content['REPORTS'][ $content['reportid'] ];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
DieWithErrorMsg( $content["LN_CMD_NOREPORTID"] );
|
||||||
|
|
||||||
|
// SavedReportID argv
|
||||||
|
if ( isset($_SERVER["argv"][3]) )
|
||||||
|
{
|
||||||
|
// Set to SourceID property!
|
||||||
|
$content['savedreportid'] = intval( $_SERVER["argv"][3] );
|
||||||
|
|
||||||
|
// Check if exists
|
||||||
|
if ( !isset($myReport['SAVEDREPORTS'][ $content['savedreportid'] ]) )
|
||||||
|
DieWithErrorMsg( GetAndReplaceLangStr($content["LN_CMD_LOGSTREAMNOTFOUND"], $content['savedreportid']) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
DieWithErrorMsg( $content["LN_CMD_NOSAVEDREPORTID"] );
|
||||||
|
// ---
|
||||||
|
|
||||||
|
// --- Operation Handling now
|
||||||
|
if ( $operation == "runreport" )
|
||||||
|
{
|
||||||
|
// Create Report
|
||||||
|
RunReport();
|
||||||
|
}
|
||||||
|
// ---
|
||||||
|
// ---
|
||||||
|
|
||||||
|
?>
|
@ -384,7 +384,9 @@ function InitReportModules()
|
|||||||
// Add all savedreports
|
// Add all savedreports
|
||||||
foreach ($myrows as &$mySavedReport)
|
foreach ($myrows as &$mySavedReport)
|
||||||
{
|
{
|
||||||
// TODO: Perform whatever needs to be performed
|
// Set default properties if not set!
|
||||||
|
if (!isset($mySavedReport['outputTarget']) || strlen($mySavedReport['outputTarget']) <= 0 )
|
||||||
|
$mySavedReport['outputTarget'] = REPORT_TARGET_STDOUT;
|
||||||
|
|
||||||
// Add saved report into global array
|
// Add saved report into global array
|
||||||
$content['REPORTS'][$myReportID]['SAVEDREPORTS'][ $mySavedReport['SavedReportID'] ] = $mySavedReport;
|
$content['REPORTS'][$myReportID]['SAVEDREPORTS'][ $mySavedReport['SavedReportID'] ] = $mySavedReport;
|
||||||
|
@ -98,7 +98,7 @@ if ( !$content['error_occured'] )
|
|||||||
// Check if report exists
|
// Check if report exists
|
||||||
if ( isset($content['REPORTS'][ $content['reportid'] ]) )
|
if ( isset($content['REPORTS'][ $content['reportid'] ]) )
|
||||||
{
|
{
|
||||||
// Get Reference to parser!
|
// Get Reference to report!
|
||||||
$myReport = $content['REPORTS'][ $content['reportid'] ];
|
$myReport = $content['REPORTS'][ $content['reportid'] ];
|
||||||
|
|
||||||
// Now check if the saved report is available
|
// Now check if the saved report is available
|
||||||
|
Loading…
x
Reference in New Issue
Block a user