You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.9 KiB
PHP
75 lines
2.9 KiB
PHP
<?php
|
|
|
|
$root = dirname(__DIR__);
|
|
$mainSql = file_get_contents($root . '/sql/cloud.sql');
|
|
if (!is_string($mainSql)) {
|
|
throw new RuntimeException('Unable to read cloud schema');
|
|
}
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$tables = [
|
|
'cloud_network_monitor_hosts',
|
|
'cloud_network_instance_ledger',
|
|
'cloud_network_daily_summaries',
|
|
'cloud_network_findings',
|
|
'cloud_network_alert_events',
|
|
'cloud_network_alert_deliveries',
|
|
];
|
|
foreach ($tables as $table) {
|
|
$assert(
|
|
preg_match('/CREATE TABLE ' . preg_quote($table, '/')
|
|
. ' \\((.*?)\\) ENGINE=/s', $mainSql, $matches) === 1,
|
|
'Missing compact abuse table: ' . $table
|
|
);
|
|
$definitions[$table] = $matches[1];
|
|
}
|
|
|
|
$ledger = $definitions['cloud_network_instance_ledger'];
|
|
$assert(str_contains($ledger, 'instance_id BIGINT UNSIGNED NOT NULL PRIMARY KEY')
|
|
&& str_contains($ledger, 'detector_state_json JSON NOT NULL')
|
|
&& str_contains($ledger, 'current_day_json JSON NOT NULL'),
|
|
'Instance ledger lost its single-row detector contract.');
|
|
|
|
$daily = $definitions['cloud_network_daily_summaries'];
|
|
$assert(str_contains($daily, 'PRIMARY KEY (instance_id, day_start)')
|
|
&& str_contains($daily, 'cloud_network_daily_retention')
|
|
&& str_contains($daily, 'sample_count INT UNSIGNED NOT NULL'),
|
|
'Daily abuse summaries lost their bounded instance/day identity.');
|
|
|
|
$finding = $definitions['cloud_network_findings'];
|
|
$event = $definitions['cloud_network_alert_events'];
|
|
$assert(str_contains($finding, 'id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT')
|
|
&& str_contains($finding, 'cloud_network_finding_scope')
|
|
&& str_contains($event, 'id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT')
|
|
&& str_contains($event, 'cloud_network_alert_finding_revision'),
|
|
'Sparse findings or transitions lost their numeric identity.');
|
|
|
|
foreach (array_keys($definitions) as $table) {
|
|
$definition = $definitions[$table];
|
|
foreach ([
|
|
'sample_key', 'placement_key', 'window_id', 'vm_uuid',
|
|
'policy_hash',
|
|
] as $legacyIdentity) {
|
|
$assert(!str_contains($definition, $legacyIdentity),
|
|
$table . ' retained high-rate legacy identity '
|
|
. $legacyIdentity . '.');
|
|
}
|
|
}
|
|
|
|
$assert(str_contains($definitions['cloud_network_alert_deliveries'],
|
|
"state IN ('pending','dispatching','sent','failed','unknown','skipped')")
|
|
&& str_contains($definitions['cloud_network_alert_deliveries'],
|
|
'content_hash CHAR(64)')
|
|
&& str_contains($definitions['cloud_network_alert_deliveries'],
|
|
'chk_cloud_network_alert_delivery_destination')
|
|
&& str_contains($definitions['cloud_network_alert_deliveries'],
|
|
'chk_cloud_network_alert_delivery_shape'),
|
|
'Telegram delivery lost its conservative unknown-effect fence.');
|
|
|
|
echo "Compact abuse monitoring schema contract passed.\n";
|