SensorUserFailedLogins.php in Monitoring 7
File
lib/Drupal/monitoring/Sensor/Sensors/SensorUserFailedLogins.php
View source
<?php
namespace Drupal\monitoring\Sensor\Sensors;
use Drupal\monitoring\Result\SensorResultInterface;
class SensorUserFailedLogins extends SensorDatabaseAggregator {
public function buildQuery() {
$query = parent::buildQuery();
$query
->addField('watchdog', 'variables');
$query
->groupBy('watchdog.variables');
return $query;
}
public function runSensor(SensorResultInterface $result) {
$records_count = 0;
foreach ($this
->getQueryResult()
->fetchAll() as $row) {
$records_count += $row->records_count;
$variables = unserialize($row->variables);
$result
->addStatusMessage('@user: @count', array(
'@user' => $variables['%user'],
'@count' => $row->records_count,
));
}
$result
->setValue($records_count);
}
}