Skip to content

Commit

Permalink
Merge pull request #17 from wunderio/feature/dynamic-versining
Browse files Browse the repository at this point in the history
Proper JSON termination.
  • Loading branch information
ragnarkurmwunder authored Feb 27, 2023
2 parents c4bd352 + 0609ec0 commit 78299d1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ As an alternative there is Warden, but it lacks highly configurable alerting.
On hourly basis it logs the differences of the statuses of modules like this (if there are any changes):

```
---- -------------- ------------- ---------- -------------------------------------------------------------------
---- -------------- ------------- ---------- ---------------------------------------------------------------------
ID Date Type Severity Message
---- -------------- ------------- ---------- -------------------------------------------------------------------
1 01/Jul 15:43 updates_log Info updates_log={"project":"drupal","old":"CURRENT","new":"NOT_SECURE"}
---- -------------- ------------- ---------- -------------------------------------------------------------------
---- -------------- ------------- ---------- ---------------------------------------------------------------------
1 01/Jul 15:43 updates_log Info updates_log={"project":"drupal","old":"CURRENT","new":"NOT_SECURE"}==
---- -------------- ------------- ---------- ---------------------------------------------------------------------
```

`old` and `new` denote statuses.
Expand Down Expand Up @@ -71,7 +71,11 @@ The diff log entries may be generated as often as once per hour.

`updates_log.statuses` - Module "current" statuses are kept in this state variable. Required to be able to perform diff. To observe the contents of it run the following command: `drush sget updates_log.statuses --format=json`.

## Output: Diff
## Output

The generic format is `id={json}==`. There are two equal-signs at the end to mark the end of the JSON. It is needed, because in some logging environment there is additional encapsulation used which makes parsing impossible.

### Diff

When there are any changes in module statuses, then their output in the logs looks as follows:

Expand All @@ -80,12 +84,12 @@ updates_log={
project: "webform",
old: "NOT_CURRENT",
new: "CURRENT"
}
}==
```

Every state change will have its own log entry.

## Output: Statistics
### Statistics

The module also logs "Statistics" once in 24h that gives a quick overview about how many modules there are and in what statuses.
```
Expand All @@ -109,7 +113,7 @@ updates_log_statistics={
"admin_toolbar": "3.1.0"
}
}
}
}==
```

The "prefix" (`updates_log_statistics=`) is there to help filter and parse the data from the log entry.
Expand Down
4 changes: 2 additions & 2 deletions src/UpdatesLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function logDiff(array $statuses): void {
catch (\Exception $exception) {
$json = $exception->getMessage();
}
$this->logger->info('updates_log=@placeholder', ["@placeholder" => $json]);
$this->logger->info('updates_log=@placeholder==', ["@placeholder" => $json]);
}
}

Expand Down Expand Up @@ -504,7 +504,7 @@ public function logStatistics(array $statistics): void {
catch (\Exception $exception) {
$json = $exception->getMessage();
}
$this->logger->info('updates_log_statistics=@placeholder', ["@placeholder" => $json]);
$this->logger->info('updates_log_statistics=@placeholder==', ["@placeholder" => $json]);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Kernel/LogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testLogDiff(): void {
$log = reset($result);

$this->assertEquals('updates_log', $log->type);
$this->assertEquals('updates_log=@placeholder', $log->message);
$this->assertEquals('updates_log=@placeholder==', $log->message);
$this->assertEquals('a:1:{s:12:"@placeholder";s:44:"{"project":"drupal","old":"old","new":"new"}";}', $log->variables);
$this->assertEquals(6, $log->severity);
$this->assertGreaterThan(time() - 5, $log->timestamp);
Expand Down Expand Up @@ -104,7 +104,7 @@ public function testLogStatistics(): void {
$log = reset($result);

$this->assertEquals('updates_log', $log->type);
$this->assertEquals('updates_log_statistics=@placeholder', $log->message);
$this->assertEquals('updates_log_statistics=@placeholder==', $log->message);
$this->assertEquals('a:1:{s:12:"@placeholder";s:497:"{"updates_log":"2.0","last_check_epoch":' . $time . ',"last_check_human":"' . gmdate('Y-m-d\Th:i:sZT', $time) . '","last_check_ago":1,"summary":{"CURRENT":2,"NOT_CURRENT":1,"NOT_SECURE":0,"NOT_SUPPORTED":1,"REVOKED":0,"UNKNOWN":1},"details":{"x":{"status":"NOT_CURRENT","version_used":"x"},"y":{"status":"NOT_SUPPORTED","version_used":"x"},"z":{"status":"NOT_SECURE","version_used":"x"},"a":{"status":"CURRENT","version_used":"x"},"b":{"status":"CURRENT","version_used":"x"},"c":{"status":"???","version_used":"x"}}}";}', $log->variables);
$this->assertEquals(6, $log->severity);
$this->assertGreaterThan(time() - 5, $log->timestamp);
Expand Down
2 changes: 1 addition & 1 deletion updates_log.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ description: "Log module update info"
core: 8.x
core_version_requirement: ^8 || ^9 || ^10
package: Development
version: 2.0.2
version: 2.0.3
dependencies:
- drupal:update

0 comments on commit 78299d1

Please sign in to comment.