class UltimateCronErrorsSensorPlugin in Monitoring 8
Monitors the ultimate cron errors.
Plugin annotation
@SensorPlugin(
id = "ultimate_cron_errors",
provider = "ultimate_cron",
label = @Translation("Ultimate cron errors"),
description = @Translation("Provides insight on the cron processes."),
addable = FALSE
)
Hierarchy
- class \Drupal\monitoring\SensorPlugin\SensorPluginBase implements SensorPluginInterface uses MessengerTrait, StringTranslationTrait
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\UltimateCronErrorsSensorPlugin implements ExtendedInfoSensorPluginInterface
Expanded class hierarchy of UltimateCronErrorsSensorPlugin
File
- src/
Plugin/ monitoring/ SensorPlugin/ UltimateCronErrorsSensorPlugin.php, line 23
Namespace
Drupal\monitoring\Plugin\monitoring\SensorPluginView source
class UltimateCronErrorsSensorPlugin extends SensorPluginBase implements ExtendedInfoSensorPluginInterface {
/**
* The error log entries.
*
* @var array
*/
protected $logEntries;
/**
* {@inheritdoc}
*/
public function runSensor(SensorResultInterface $result) {
$this->logEntries = $this
->getErrorLogEntries();
$result
->setValue(count($this->logEntries));
}
/**
* {@inheritdoc}
*/
public function resultVerbose(SensorResultInterface $result) {
$rows = [];
foreach ($this->logEntries as $log_entry) {
$rows[] = [
'name' => $log_entry->job
->label() . ' (' . $log_entry->job
->getModuleName() . ')',
'message' => strip_tags($log_entry->message),
'logs' => Link::createFromRoute($this
->t('View logs'), 'entity.ultimate_cron_job.logs', [
'ultimate_cron_job' => $log_entry->name,
]),
];
}
$header = [
'name' => $this
->t('Cron job'),
'message' => $this
->t('Message'),
'logs' => $this
->t('Logs'),
];
$output['log_entries'] = [
'#type' => 'verbose_table_result',
'#title' => $this
->t('Log entries'),
'#header' => $header,
'#rows' => $rows,
];
return $output;
}
/**
* Returns error log entries.
*
* @return array
* An array of log entries.
*/
public function getErrorLogEntries() {
// Loads active cron jobs.
$job_ids = \Drupal::entityQuery('ultimate_cron_job')
->condition('status', TRUE)
->execute();
$jobs = CronJob::loadMultiple($job_ids);
$log_entries = [];
/** @var \Drupal\ultimate_cron\Entity\CronJob $job */
foreach ($jobs as $job) {
$job_entries = $job
->getLogEntries(ULTIMATE_CRON_LOG_TYPE_ALL, 10);
foreach ($job_entries as $job_entry) {
if ($job_entry->severity == RfcLogLevel::ERROR) {
$job_entry->job = $job;
$log_entries[] = $job_entry;
}
}
}
return $log_entries;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
SensorPluginBase:: |
protected | property | Allows plugins to control if the value type can be configured. | 6 |
SensorPluginBase:: |
protected | property | The plugin implementation definition. | |
SensorPluginBase:: |
protected | property | The plugin_id. | |
SensorPluginBase:: |
protected | property | Current sensor config object. | |
SensorPluginBase:: |
protected | property | ||
SensorPluginBase:: |
public | function |
Service setter. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
13 |
SensorPluginBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides SensorPluginInterface:: |
4 |
SensorPluginBase:: |
public static | function |
Creates an instance of the sensor with config. Overrides SensorPluginInterface:: |
7 |
SensorPluginBase:: |
public | function |
Configurable value type. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Default configuration for a sensor. Overrides SensorPluginInterface:: |
8 |
SensorPluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
SensorPluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
SensorPluginBase:: |
public | function |
Gets sensor name (not the label). Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
@todo: Replace with injection Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Determines if sensor is enabled. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
3 |
SensorPluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
2 |
SensorPluginBase:: |
function | Instantiates a sensor object. | 8 | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UltimateCronErrorsSensorPlugin:: |
protected | property | The error log entries. | |
UltimateCronErrorsSensorPlugin:: |
public | function | Returns error log entries. | |
UltimateCronErrorsSensorPlugin:: |
public | function |
Provide additional info about sensor call. Overrides ExtendedInfoSensorPluginInterface:: |
|
UltimateCronErrorsSensorPlugin:: |
public | function |
Runs the sensor, updating $sensor_result. Overrides SensorPluginInterface:: |