You are here

class NonExistingUserFailedLoginsSensorPlugin in Monitoring 8

Monitors non existing user failed login from dblog messages.

@SensorPlugin( id = "user_void_failed_logins", label = @Translation("Non Existing User Failed Logins"), description = @Translation("Monitors non existing user failed login from dblog messages."), provider = "dblog", addable = FALSE )

Helps to identify bots or brute force attacks.

Hierarchy

Expanded class hierarchy of NonExistingUserFailedLoginsSensorPlugin

File

src/Plugin/monitoring/SensorPlugin/NonExistingUserFailedLoginsSensorPlugin.php, line 24
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\NonExistingUserFailedLoginsSensorPlugin.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin
View source
class NonExistingUserFailedLoginsSensorPlugin extends WatchdogAggregatorSensorPlugin {

  /**
   * {@inheritdoc}
   */
  public function getAggregateQuery() {
    $query = parent::getAggregateQuery();
    $query
      ->addField('watchdog', 'variables');
    $query
      ->groupBy('variables');
    $query
      ->orderBy('records_count', 'DESC');
    return $query;
  }

  /**
   * {@inheritdoc}
   */
  public function runSensor(SensorResultInterface $result) {
    $records_count = 0;
    foreach ($this
      ->getAggregateQuery()
      ->execute() as $row) {
      $records_count += $row->records_count;
      $variables = unserialize($row->variables);
      $result
        ->addStatusMessage('@ip: @count', array(
        '@ip' => $variables['%ip'],
        '@count' => $row->records_count,
      ));
    }
    $result
      ->setValue($records_count);
  }

  /**
   * {@inheritdoc}
   */
  public function resultVerbose(SensorResultInterface $result) {

    // The unaggregated result in a fieldset.
    $output = parent::resultVerbose($result);

    // The result aggregated per ip.
    $this
      ->verboseResultCounting($output);
    return $output;
  }

  /**
   * Get the verbose results of the attempts per ip.
   *
   * @param array $output
   *   The output array, at which we will add the attempts per user result.
   */
  public function verboseResultCounting(array &$output) {
    if ($this->sensorConfig
      ->getSetting('verbose_fields')) {

      // Fetch the last 20 matching entries, aggregated.
      $query = $this
        ->getAggregateQuery();
      $query_result = $query
        ->range(0, 20)
        ->execute();
      $this->queryString = $query_result
        ->getQueryString();
      $rows = $this
        ->buildTableRows($query_result
        ->fetchAll());
      $results = [];
      foreach ($rows as $key => $row) {
        $results[$key] = [];
        $variables = unserialize($row['variables']);
        $results[$key]['ip'] = $variables['%ip'];
        $results[$key]['attempts'] = $row['records_count'];
      }
      $output['attempts_per_ip'] = array(
        '#type' => 'verbose_table_result',
        '#title' => t('Attempts per ip'),
        '#rows' => $results,
        '#header' => $this
          ->buildTableHeader($results),
        '#query' => $query_result
          ->getQueryString(),
        '#query_args' => $query
          ->getArguments(),
      );
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DatabaseAggregatorSensorPlugin::$configurableConditions protected property Allows plugins to control if the conditions table should be shown. 5
DatabaseAggregatorSensorPlugin::$configurableVerboseOutput protected property Allows plugins to control if the verbose output table should be shown. 5
DatabaseAggregatorSensorPlugin::$executedQuery protected property The arguments of the executed query.
DatabaseAggregatorSensorPlugin::$fetchedObject protected property The fetched object from the query result.
DatabaseAggregatorSensorPlugin::$queryArguments protected property The arguments of the executed query.
DatabaseAggregatorSensorPlugin::$queryString protected property The query string of the executed query.
DatabaseAggregatorSensorPlugin::addAggregateExpression protected function Adds the aggregate expression to the select query. 2
DatabaseAggregatorSensorPlugin::addConditionSubmit public function Add row to table when pressing 'Add another condition' and rebuild.
DatabaseAggregatorSensorPlugin::addFieldSubmit public function Adds another field to the keys table when pressing 'Add another key'.
DatabaseAggregatorSensorPlugin::buildConfigurationForm public function Adds UI for variables table, conditions and keys. Overrides DatabaseAggregatorSensorPluginBase::buildConfigurationForm 1
DatabaseAggregatorSensorPlugin::buildTableHeader protected function Builds the header for a table based on rows. 3
DatabaseAggregatorSensorPlugin::buildTableRows protected function Builds the rows of a table. 1
DatabaseAggregatorSensorPlugin::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides SensorPluginBase::calculateDependencies
DatabaseAggregatorSensorPlugin::conditionsReplace public function Returns the updated 'conditions' fieldset for replacement by ajax.
DatabaseAggregatorSensorPlugin::fieldsReplace public function Returns the updated 'output_table' fieldset for replacement by ajax.
DatabaseAggregatorSensorPlugin::getConditionsOperators protected function Provides list of operators for conditions.
DatabaseAggregatorSensorPlugin::getHistoryQuery protected function Builds history query over one db table.
DatabaseAggregatorSensorPlugin::getOldestEntry protected function Get the timestamp of the oldest entry that fits owr conditions.
DatabaseAggregatorSensorPlugin::getQuery protected function Builds the query for verbose output. 4
DatabaseAggregatorSensorPlugin::submitConfigurationForm public function Form submission handler. Overrides DatabaseAggregatorSensorPluginBase::submitConfigurationForm
DatabaseAggregatorSensorPlugin::translateCondition protected function Translates the string operators to SQL equivalents.
DatabaseAggregatorSensorPlugin::validateConfigurationForm public function Form validation handler. Overrides SensorPluginBase::validateConfigurationForm
DatabaseAggregatorSensorPluginBase::$configurableValueType protected property Allows plugins to control if the value type can be configured. Overrides SensorPluginBase::$configurableValueType
DatabaseAggregatorSensorPluginBase::getConditions protected function Gets conditions to be used in the select query.
DatabaseAggregatorSensorPluginBase::getTimeIntervalField protected function Gets the time field.
DatabaseAggregatorSensorPluginBase::getTimeIntervalOptions protected function Returns time interval options.
DatabaseAggregatorSensorPluginBase::getTimeIntervalValue protected function Gets the time interval value.
DependencyTrait::$dependencies protected property The object's dependencies.
DependencyTrait::addDependencies protected function Adds multiple dependencies.
DependencyTrait::addDependency protected function Adds a dependency.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
NonExistingUserFailedLoginsSensorPlugin::getAggregateQuery public function Builds simple aggregate query over one db table. Overrides DatabaseAggregatorSensorPlugin::getAggregateQuery
NonExistingUserFailedLoginsSensorPlugin::resultVerbose public function Provide additional info about sensor call. Overrides DatabaseAggregatorSensorPlugin::resultVerbose
NonExistingUserFailedLoginsSensorPlugin::runSensor public function Runs the sensor, updating $sensor_result. Overrides DatabaseAggregatorSensorPlugin::runSensor
NonExistingUserFailedLoginsSensorPlugin::verboseResultCounting public function Get the verbose results of the attempts per ip.
SensorPluginBase::$pluginDefinition protected property The plugin implementation definition.
SensorPluginBase::$pluginId protected property The plugin_id.
SensorPluginBase::$sensorConfig protected property Current sensor config object.
SensorPluginBase::$services protected property
SensorPluginBase::addService public function Service setter. Overrides SensorPluginInterface::addService
SensorPluginBase::create public static function Creates an instance of the sensor with config. Overrides SensorPluginInterface::create 7
SensorPluginBase::getConfigurableValueType public function Configurable value type. Overrides SensorPluginInterface::getConfigurableValueType
SensorPluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
SensorPluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
SensorPluginBase::getSensorId public function Gets sensor name (not the label). Overrides SensorPluginInterface::getSensorId
SensorPluginBase::getService public function @todo: Replace with injection Overrides SensorPluginInterface::getService
SensorPluginBase::isEnabled public function Determines if sensor is enabled. Overrides SensorPluginInterface::isEnabled
SensorPluginBase::__construct function Instantiates a sensor object. 8
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
WatchdogAggregatorSensorPlugin::$configurableTable protected property Allows plugins to control if the table can be configured. Overrides DatabaseAggregatorSensorPlugin::$configurableTable
WatchdogAggregatorSensorPlugin::$configurableTimestampField protected property Allows plugins to control if a timestamp field can be configured. Overrides DatabaseAggregatorSensorPluginBase::$configurableTimestampField
WatchdogAggregatorSensorPlugin::getDefaultConfiguration public function Default configuration for a sensor. Overrides DatabaseAggregatorSensorPlugin::getDefaultConfiguration
WatchdogAggregatorSensorPlugin::verboseResultHistory public function Adds history verbose output to the render array $output. Overrides DatabaseAggregatorSensorPlugin::verboseResultHistory
WatchdogAggregatorSensorPlugin::verboseResultUnaggregated public function Adds unaggregated verbose output to the render array $output. Overrides DatabaseAggregatorSensorPlugin::verboseResultUnaggregated 2