Dblog404SensorPlugin.php in Monitoring 8
File
src/Plugin/monitoring/SensorPlugin/Dblog404SensorPlugin.php
View source
<?php
namespace Drupal\monitoring\Plugin\monitoring\SensorPlugin;
use Drupal\monitoring\Result\SensorResultInterface;
class Dblog404SensorPlugin extends WatchdogAggregatorSensorPlugin {
protected $configurableConditions = FALSE;
protected $configurableVerboseOutput = FALSE;
public function getAggregateQuery() {
$query = parent::getAggregateQuery();
$query
->addField('watchdog', 'location');
$query
->groupBy('location');
$query
->orderBy('records_count', 'DESC');
$query
->range(0, 1);
return $query;
}
public function getQuery() {
$query = parent::getQuery();
$this
->addAggregateExpression($query);
$query
->groupBy('location');
$fields =& $query
->getFields();
unset($fields['timestamp']);
$query
->addExpression('MAX(timestamp)', 'timestamp');
$order =& $query
->getOrderBy();
$order = [];
$query
->orderBy('records_count', 'DESC');
$query
->range(0, 20);
return $query;
}
protected function buildTableHeader($rows = []) {
$header = parent::buildTableHeader($rows);
if (isset($header['location'])) {
$header['location'] = $this
->t('Path');
$header['records_count'] = $this
->t('Count');
$header['timestamp'] = $this
->t('Last access');
}
return $header;
}
public function runSensor(SensorResultInterface $result) {
parent::runSensor($result);
if (!empty($this->fetchedObject) && !empty($this->fetchedObject->location)) {
$result
->addStatusMessage($this->fetchedObject->location);
}
}
}