You are here

protected function MonitoringPastTest::createEvents in Monitoring 8

Creates some sample events.

1 call to MonitoringPastTest::createEvents()
MonitoringPastTest::testPastSensors in tests/src/Kernel/MonitoringPastTest.php
Tests the sensors that monitors past events.

File

tests/src/Kernel/MonitoringPastTest.php, line 68
Contains \Drupal\Tests\monitoring\Kernel\MonitoringPastTest.

Class

MonitoringPastTest
Tests for the past sensors in monitoring.

Namespace

Drupal\Tests\monitoring\Kernel

Code

protected function createEvents($count = 20) {

  // Set some for log creation.
  $machine_name = 'machine name';
  $severities = RfcLogLevel::getLevels();
  $severities_codes = array_keys($severities);
  $severities_count = count($severities);
  $event_desc = 'message #';

  // Prepare some logs.
  for ($i = 0; $i <= $count; $i++) {
    $event = past_event_create('past_db', $machine_name, $event_desc . ($i + 1), [
      'timestamp' => \Drupal::time()
        ->getRequestTime(),
    ]);
    $event
      ->setReferer('http://example.com/test-referer');
    $event
      ->setLocation('http://example.com/this-url-gets-heavy-long/testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttest-testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttest-testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttest-testtesttesttesttesttesttest/seeme.htm');
    $event
      ->addArgument('arg1', 'First Argument');
    $event
      ->addArgument('arg2', new \stdClass());
    $event
      ->addArgument('arg3', FALSE);
    $event
      ->setSeverity($severities_codes[$i % $severities_count]);
    $event
      ->save();
  }
}