function sendMail(eZMail $mail) { $ini = eZINI::instance(); $parameters = array(); $parameters['host'] = $ini->variable('MailSettings', 'TransportServer'); $parameters['helo'] = $ini->variable('MailSettings', 'SenderHost'); $parameters['port'] = $ini->variable('MailSettings', 'TransportPort'); $parameters['connectionType'] = $ini->variable('MailSettings', 'TransportConnectionType'); $user = $ini->variable('MailSettings', 'TransportUser'); $password = $ini->variable('MailSettings', 'TransportPassword'); if ($user and $password) { $parameters['auth'] = true; $parameters['user'] = $user; $parameters['pass'] = $password; } /* If email sender hasn't been specified or is empty * we substitute it with either MailSettings.EmailSender or AdminEmail. */ if (!$mail->senderText()) { $emailSender = $ini->variable('MailSettings', 'EmailSender'); if (!$emailSender) { $emailSender = $ini->variable('MailSettings', 'AdminEmail'); } eZMail::extractEmail($emailSender, $emailSenderAddress, $emailSenderName); if (!eZMail::validate($emailSenderAddress)) { $emailSender = false; } if ($emailSender) { $mail->setSenderText($emailSender); } } $excludeHeaders = $ini->variable('MailSettings', 'ExcludeHeaders'); if (count($excludeHeaders) > 0) { $mail->Mail->appendExcludeHeaders($excludeHeaders); } $options = new ezcMailSmtpTransportOptions(); if ($parameters['connectionType']) { $options->connectionType = $parameters['connectionType']; } $smtp = new ezcMailSmtpTransport($parameters['host'], $user, $password, $parameters['port'], $options); // If in debug mode, send to debug email address and nothing else if ($ini->variable('MailSettings', 'DebugSending') == 'enabled') { $mail->Mail->to = array(new ezcMailAddress($ini->variable('MailSettings', 'DebugReceiverEmail'))); $mail->Mail->cc = array(); $mail->Mail->bcc = array(); } // send() from ezcMailSmtpTransport doesn't return anything (it uses exceptions in case // something goes bad) try { eZPerfLogger::accumulatorStart('mail_sent'); $smtp->send($mail->Mail); eZPerfLogger::accumulatorStop('mail_sent'); } catch (ezcMailException $e) { eZPerfLogger::accumulatorStop('mail_send'); eZDebug::writeError($e->getMessage(), __METHOD__); return false; } // return true in case of no exceptions return true; }
function parseFile($fileName) { eZPerfLogger::accumulatorStart('binaryfile_metadataextractions'); $result = parent::parseFile($fileName); eZPerfLogger::accumulatorStop('binaryfile_metadataextractions'); return $result; }
/** * For statsd, we use a different logic than for other loggers: * in the name of the KPI we embed some variable data, such as f.e. * content-class name. This allows better grouping and filtering of data * in the Graphite console. * * @see ezperformancelogger.ini * * We cache internally prefix and postfix for optimal performances */ public static function transformVarName($var, $default = null) { if (self::$prefix === null || self::$postfix === null) { $strip = eZPerfLoggerINI::variable('StatsdSettings', 'RemoveEmptyTokensInVariable') == 'enabled'; foreach (array(eZPerfLoggerINI::variable('StatsdSettings', 'VariablePrefix'), eZPerfLoggerINI::variable('StatsdSettings', 'VariablePostfix')) as $i => $string) { if (strpos($string, '$') !== false) { $tokens = explode('.', $string); foreach ($tokens as $j => &$token) { if (strlen($token) && $token[0] == '$') { $token = str_replace('.', '_', eZPerfLogger::getModuleData(substr($token, 1), $default)); if ($strip && $token == '') { unset($tokens[$j]); } } } $string = implode('.', $tokens); } if ($i) { self::$postfix = $string; } else { self::$prefix = $string; } } } return self::$prefix . $var . self::$postfix; }
/** Executes the needed operator(s). Checks operator names, and calls the appropriate functions. */ function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters) { switch ($operatorName) { case 'xhprof_start': eZXHProfLogger::start($namedParameters['flags'], $namedParameters['options']); $operatorValue = null; break; case 'xhprof_stop': eZXHProfLogger::stop($namedParameters['dosave']); $operatorValue = null; break; case 'record_value': eZPerfLogger::recordValue($namedParameters['name'], $operatorValue); $operatorValue = null; break; case 'make_global': /// @todo investigate: shal we use copy if $operatorValue is an object? $GLOBALS[$namedParameters['name']] = $namedParameters['value']; $operatorValue = null; } }
public static function measure() { return eZPerfLoggerGenericTracer::StdKPIsFromAccumulators(array('mysqli_connection', 'mysqli_query', 'mysqli_loop', 'mysqli_conversion'), eZPerfLogger::TimeAccumulatorList()); }
public static function measure() { return eZPerfLoggerGenericTracer::StdKPIsFromAccumulators(array('mysql_cluster_cache_waits'), eZPerfLogger::TimeAccumulatorList()); }
public static function measure($output, $returnCode = null) { return eZPerfLoggerGenericTracer::StdKPIsFromAccumulators(array('mail_sent'), eZPerfLogger::TimeAccumulatorList()); }
/** * Reset accumulators values so far: either a single one or all of them. * NB: also clears the ezdebug accumulators */ public static function accumulatorReset($val = null) { if ($val === null) { self::$timeAccumulatorList = array(); if (eZPerfLoggerDebug::isDebugEnabled()) { $debug = eZDebug::instance(); $debug->TimeAccumulatorList = array(); } } else { unset(self::$timeAccumulatorList[$val]); } }
public static function measure() { return eZPerfLoggerGenericTracer::StdKPIsFromAccumulators(array('oracle_cluster_query', 'oracle_cluster_connect'), eZPerfLogger::TimeAccumulatorList()); }
public static function measure($output, $returnCode = null) { return eZPerfLoggerGenericTracer::StdKPIsFromAccumulators(array('binaryfile_metadataextractions'), eZPerfLogger::TimeAccumulatorList()); }
function sendMail(eZMail $mail) { $ini = eZINI::instance(); $sendmailOptions = ''; $emailFrom = $mail->sender(); $emailSender = isset($emailFrom['email']) ? $emailFrom['email'] : false; if (!$emailSender || count($emailSender) <= 0) { $emailSender = $ini->variable('MailSettings', 'EmailSender'); } if (!$emailSender) { $emailSender = $ini->variable('MailSettings', 'AdminEmail'); } if (!eZMail::validate($emailSender)) { $emailSender = false; } $isSafeMode = ini_get('safe_mode') != 0; $sendmailOptionsArray = $ini->variable('MailSettings', 'SendmailOptions'); if (is_array($sendmailOptionsArray)) { $sendmailOptions = implode(' ', $sendmailOptionsArray); } elseif (!is_string($sendmailOptionsArray)) { $sendmailOptions = $sendmailOptionsArray; } if (!$isSafeMode and $emailSender) { $sendmailOptions .= ' -f' . $emailSender; } if ($isSafeMode and $emailSender and $mail->sender() == false) { $mail->setSenderText($emailSender); } if (function_exists('mail')) { $message = $mail->body(); $sys = eZSys::instance(); $excludeHeaders = array('Subject'); // If not Windows PHP mail() implementation, we can not specify a To: header in the $additional_headers parameter, // because then there will be 2 To: headers in the resulting e-mail. // However, we can use "undisclosed-recipients:;" in $to. if ($sys->osType() != 'win32') { $excludeHeaders[] = 'To'; $receiverEmailText = count($mail->ReceiverElements) > 0 ? $mail->receiverEmailText() : 'undisclosed-recipients:;'; } else { $receiverEmailText = $mail->receiverEmailText(); } // If in debug mode, send to debug email address and nothing else if ($ini->variable('MailSettings', 'DebugSending') == 'enabled') { $receiverEmailText = $ini->variable('MailSettings', 'DebugReceiverEmail'); $excludeHeaders[] = 'To'; $excludeHeaders[] = 'Cc'; $excludeHeaders[] = 'Bcc'; } $extraHeaders = $mail->headerText(array('exclude-headers' => $excludeHeaders)); eZPerfLogger::accumulatorStart('mail_sent'); $returnedValue = mail($receiverEmailText, $mail->subject(), $message, $extraHeaders, $sendmailOptions); eZPerfLogger::accumulatorStop('mail_sent'); if ($returnedValue === false) { eZDebug::writeError('An error occurred while sending e-mail. Check the Sendmail error message for further information (usually in /var/log/messages)', __METHOD__); } return $returnedValue; } else { eZDebug::writeWarning("Unable to send mail: 'mail' function is not compiled into PHP.", __METHOD__); } return false; }
public static function measure() { return eZPerfLoggerGenericTracer::StdKPIsFromAccumulators(array('imagemagick_image_conversion'), eZPerfLogger::TimeAccumulatorList()); }
/** * On the pre-handling hook, we need to reset all counters, otherwise we get data polluted from the daemon process * * @param $objectId * @param $objectVersion * @param $pid */ public static function preHandlingHook($objectId, $objectVersion, $pid) { eZPerfLogger::reset(); }
} // the way that munin wildcard plugins work is that many symlinks are created to the // plugin, appending graph name to the original plugin file name. The shell script // will pass us its own filename in the 'variable' option $variable = isset($options['variable']) ? $options['variable'] : ''; $variable = preg_replace('/^ezmuninperflogger_/', '', $variable); // default munin range: 5 minutes $range = $options['range'] ? $options['range'] : 60 * 5; $ini = eZINI::instance('ezperformancelogger.ini'); switch ($command) { case 'autoconf': // This command is called by munin to know if all config needed by this plugin has been done right. // If the php script can actually run succesfully, this means it has (config is needed to tell // Munin where php is and where this script is) $siteIni = eZINI::instance(); if (!eZPerfLogger::isEnabled()) { $cli->output("no (extension ezperformancelogger not enabled)"); $script->shutdown(); } if (!in_array('csv', $ini->variable('GeneralSettings', 'LogMethods'))) { $cli->output("no (extension ezperformancelogger is not logging data to csv log files)"); $script->shutdown(); } $cli->output("yes"); $script->shutdown(); break; case 'suggest': // This command is called by munin to get a list of graphs that this plugin supports // See http://munin-monitoring.org/wiki/ConcisePlugins foreach (array_merge($ini->variable('GeneralSettings', 'TrackVariables'), array('pageviews')) as $var) { echo "{$var}\n";