v.0.11.4
This commit is contained in:
+29
-3
@@ -61,6 +61,8 @@ class RuleManager:
|
||||
"items": [],
|
||||
}
|
||||
self._last_result = "not changed"
|
||||
self._vendor_rule_cache_key: tuple[int, int, int] | None = None
|
||||
self._vendor_rule_cache_count = 0
|
||||
self._snapshot_dir = Path(self.config.suricata_custom_rules).parent / "rule-snapshots"
|
||||
self._snapshot_dir.mkdir(parents=True, exist_ok=True)
|
||||
self._ensure_files()
|
||||
@@ -78,6 +80,7 @@ class RuleManager:
|
||||
last_result = self._last_result
|
||||
vendor_root = self.config.suricata_persist_lib_dir
|
||||
vendor_rules = os.path.join(vendor_root, "rules", "suricata.rules")
|
||||
vendor_rules_size, vendor_rules_updated_at, vendor_rule_count = self._vendor_rule_metadata(vendor_rules)
|
||||
source_index = _first_existing_path(
|
||||
os.path.join(vendor_root, "rules", ".cache", "index.yaml"),
|
||||
os.path.join(vendor_root, "update", "cache", "index.yaml"),
|
||||
@@ -94,15 +97,38 @@ class RuleManager:
|
||||
"threshold_entry_count": _count_config_entries(threshold),
|
||||
"suppressed_sids": _suppressed_sids(threshold),
|
||||
"vendor_rules_path": vendor_rules,
|
||||
"vendor_rules_size_bytes": _file_size(vendor_rules),
|
||||
"vendor_rule_count": _count_rule_file(vendor_rules),
|
||||
"vendor_rules_updated_at": _file_mtime_iso(vendor_rules),
|
||||
"vendor_rules_size_bytes": vendor_rules_size,
|
||||
"vendor_rule_count": vendor_rule_count,
|
||||
"vendor_rules_updated_at": vendor_rules_updated_at,
|
||||
"source_index_updated_at": _file_mtime_iso(source_index) if source_index else None,
|
||||
"source_index_url": self.SOURCE_INDEX_URL,
|
||||
"last_result": last_result,
|
||||
"snapshots": len(self.list_snapshots()),
|
||||
}
|
||||
|
||||
def _vendor_rule_metadata(self, path: str) -> tuple[int, str | None, int]:
|
||||
try:
|
||||
stat = os.stat(path)
|
||||
except OSError:
|
||||
with self._lock:
|
||||
self._vendor_rule_cache_key = None
|
||||
self._vendor_rule_cache_count = 0
|
||||
return 0, None, 0
|
||||
|
||||
cache_key = (int(stat.st_ino), int(stat.st_mtime_ns), int(stat.st_size))
|
||||
with self._lock:
|
||||
if cache_key == self._vendor_rule_cache_key:
|
||||
count = self._vendor_rule_cache_count
|
||||
else:
|
||||
count = -1
|
||||
if count < 0:
|
||||
count = _count_rule_file(path)
|
||||
with self._lock:
|
||||
self._vendor_rule_cache_key = cache_key
|
||||
self._vendor_rule_cache_count = count
|
||||
updated_at = datetime.fromtimestamp(stat.st_mtime, timezone.utc).isoformat()
|
||||
return int(stat.st_size), updated_at, count
|
||||
|
||||
def content(self) -> dict:
|
||||
return {
|
||||
"custom_rules": self._read(self.config.suricata_custom_rules),
|
||||
|
||||
Reference in New Issue
Block a user