ajout du script check_smart

This commit is contained in:
2026-03-18 08:06:25 +01:00
parent b2c083eb8d
commit 8074151300
3 changed files with 133 additions and 1 deletions

View File

@@ -140,6 +140,54 @@ function update_one_file($expected_hash, $mode, $rel_path) {
return false;
}
/**
* Vérifie et ajoute les tâches cron si elles sont absentes
*/
function ensure_crontab_entries() {
global $MONITORING_BASE_DIR;
// Définition des tâches souhaitées (Format: "cron_schedule command")
$required_jobs = [
"*/5 * * * * php {$MONITORING_BASE_DIR}/bin/check_disk.php > /dev/null 2>&1",
"*/5 * * * * php {$MONITORING_BASE_DIR}/bin/check_ram.php > /dev/null 2>&1",
"10 3 * * * php {$MONITORING_BASE_DIR}/bin/monitoring-update.php > /dev/null 2>&1",
"* * * * * php {$MONITORING_BASE_DIR}/bin/alert-engine.php > /dev/null 2>&1"
];
// Récupération du crontab actuel de root
$current_cron = shell_exec("crontab -l 2>/dev/null") ?: "";
$lines = explode("\n", trim($current_cron));
$updated = false;
foreach ($required_jobs as $job) {
// On extrait la commande sans les arguments de temps pour la recherche
// On cherche si le chemin du script est déjà présent
$script_path = explode(' ', $job)[5];
$found = false;
foreach ($lines as $line) {
if (strpos($line, $script_path) !== false) {
$found = true;
break;
}
}
if (!$found) {
log_notice("cron_added", "Ajout d'une tâche au crontab", ["job" => $job]);
$lines[] = $job;
$updated = true;
}
}
if ($updated) {
// Réécriture du crontab
$tmp_cron = tempnam(sys_get_temp_dir(), 'cron');
file_put_contents($tmp_cron, implode("\n", $lines) . "\n");
exec("crontab " . escapeshellarg($tmp_cron));
unlink($tmp_cron);
}
}
/**
* Suppression des fichiers obsolètes
*/
@@ -209,6 +257,7 @@ foreach ($manifest as $item) {
delete_extra_files($remote_paths);
run_local_conf_sync();
ensure_crontab_entries();
if ($failed > 0) {
log_warning("update_finished_with_errors", "Mise à jour terminée avec erreurs", ["total=$total", "failed=$failed"]);