{ "name": "Backup_Check", "isActive": "1", "group": "Backup", "mode": "schedule", "schedule": "0 9 * * *", "trigger": [ "" ], "timeout": "0", "isVisible": "0", "display": { "name": "", "icon": "<\/i>" }, "order": "9999", "description": "", "configuration": { "timeDependency": 0, "has_return": 0, "logmode": "default", "allowMultiInstance": "0", "syncmode": "0", "timeline::enable": "0", "timeline::folder": "" }, "elements": [ { "name": null, "type": "action", "options": [], "order": "0", "subElements": [ { "name": null, "type": "action", "subtype": "action", "options": { "collapse": "0", "enable": "1" }, "order": "0", "expressions": [ { "type": "action", "subtype": null, "expression": "tag", "options": { "enable": "1", "background": "0", "name": "cmdListe", "value": "#[Infra St Etienne][Backup GDrive][Liste_Gdrive]#" }, "order": "0" }, { "type": "action", "subtype": null, "expression": "tag", "options": { "enable": "1", "background": "0", "name": "seuilTailleMin", "value": "200" }, "order": "1" }, { "type": "action", "subtype": null, "expression": "tag", "options": { "enable": "1", "background": "0", "name": "seuilTailleMax", "value": "300" }, "order": "2" }, { "type": "action", "subtype": null, "expression": "tag", "options": { "enable": "1", "background": "0", "name": "AlerteCentreMsg", "value": "1" }, "order": "3" }, { "type": "action", "subtype": null, "expression": "tag", "options": { "enable": "1", "background": "0", "name": "AlerteNotifJC", "value": "1" }, "order": "4" }, { "type": "action", "subtype": null, "expression": "tag", "options": { "enable": "1", "background": "0", "name": "cmdNotifJC", "value": "#[Norbert][JC_Norbert][Notif_Defaut_Infra]#" }, "order": "5" } ] } ] }, { "name": null, "type": "code", "options": [], "order": "0", "subElements": [ { "name": null, "type": "code", "subtype": "action", "options": { "collapse": "0", "enable": "1" }, "order": "0", "expressions": [ { "type": "code", "subtype": null, "expression": "\/\/ version bloc code\n$version = '03\/05\/2023 19:00';\n$scenario->setLog('┌──────────── Logs bloc code - version du ' . $version);\n\n\/**\n* Class and Function List:\n* Function list:\n* - csv_to_array()\n* Classes list:\n*\/\n\nfunction csv_to_array($filename = '', $delimiter = ',') {\n if (!file_exists($filename) || !is_readable($filename)) return false;\n\n $header = array(\n 'taille',\n 'date',\n 'heure',\n 'file'\n );\n $data = array();\n if (($handle = fopen($filename, 'r')) !== false) {\n while (($row = fgetcsv($handle, 1000, $delimiter)) !== false) {\n if (!$header) $header = $row;\n else $data[] = array_combine($header, $row);\n }\n fclose($handle);\n }\n return $data;\n}\n\n\/\/ parametres\n$tags = $scenario->getTags(); \/\/récupère la liste des tags\n$cmdIdListe = str_replace('#', '', $tags['#cmdListe#']);\n$seuilTailleMax = $tags['#seuilTailleMax#'];\n$seuilTailleMin = $tags['#seuilTailleMin#'];\n$AlerteCentreMsg = $tags['#AlerteCentreMsg#'];\n$AlerteNotifJC = $tags['#AlerteNotifJC#'];\n$fichierListe = '\/var\/www\/html\/log\/cloudsyncpro.#' . $cmdIdListe;\nif ($AlerteNotifJC) $cmdNotifJC = cmd::byId(str_replace('#', '', $tags['#cmdNotifJC#']));\n\n$scenario->setLog('| Fichier log : ' . $fichierListe);\n$scenario->setLog('| Taille min : ' . $seuilTailleMin . 'Mo');\n$scenario->setLog('| Taille max : ' . $seuilTailleMax . 'Mo');\n\n\/\/ mise à jour de la liste\ncmd::byId($cmdIdListe)->execCmd();\n\nif (!file_exists($fichierListe) || !is_readable($fichierListe)) {\n $scenario->setLog('| \/!\\ le fichier ' . $fichierListe . ' n\\'existe pas ou n\\'est pas lisible');\n if ($AlerteCentreMsg) message::add('Backup', 'Vérification des backups, ERREUR : le fichier ' . $fichierListe . ' n\\'existe pas ou n\\'est pas lisible');\n if ($AlerteNotifJC) $cmdNotifJC->execCmd($options = array(\n 'title' => 'title=Defaut BACKUP ' . $site,\n 'message' => 'Vérification des backups, ERREUR : le fichier ' . $fichierListe . ' n\\'existe pas ou n\\'est pas lisible'\n ) , $cache = 0);\n}\nelse {\n \/\/ mise à jour de la liste\n cmd::byId($cmdIdListe)->execCmd();\n\n \/\/ Extraction des données du fichier dans un tableau\n $data = csv_to_array($fichierListe, ' ');\n\n \/\/ suppression des lignes vides\n for ($n = 0;$n < count($data);$n++) {\n if (empty($data[$n]['taille'])) {\n array_splice($data, $n, 1);\n }\n }\n\n \/\/ recherche des sites de backup concernés\n for ($n = 0;$n < count($data);$n++) {\n $file = explode('-', $data[$n]['file']);\n $sites[] = $file[1];\n }\n $sites = array_unique($sites);\n\n foreach ($sites as $site) {\n $nbBackup = 0;\n $tailleTotale = 0;\n $tailleMax = '';\n $tailleMin = '';\n $backupToday = 0;\n $tailleFirstBackup\t = 0;\n $tailleLastBackup\t = 0;\n $timestampFirstBackup = '';\n $timestampLastBackup = '';\n\n for ($n = 0;$n < count($data);$n++) {\n $file = explode('-', $data[$n]['file']);\n if ($site == $file[1]) {\n \/\/ $scenario->setLog($site.' - '.$file[1]) ;\n $taille = round($data[$n]['taille'] \/ 1024 \/ 1024);\n $file = explode('-', $data[$n]['file']);\n $jeedom = $file[1];\n $version = $file[2];\n\n \/\/ $scenario->setLog($jeedom.' version '.$version.' taille '.$taille.'Mo '.date(\"d\/m\/y\", $date));\n \/\/ nb de backup, taille totale et taille des backups\n $nbBackup++;\n $tailleTotale = $tailleTotale + $taille;\n if ($taille > $tailleMax || empty($tailleMax)) $tailleMax = $taille;\n if ($taille < $tailleMin || empty($tailleMin)) $tailleMin = $taille;\n\n \/\/ date des backu^p\n $timestampBackup = mktime(0, 0, 0, $file[4], $file[5], $file[3]); \/\/ timstamp du backup )à 0à:00\n $timestampNow = mktime(0, 0, 0, date('m') , date('d') , date('Y'));\n if ($timestampBackup == $timestampNow) $backupToday = 1;\n if ($timestampBackup <= $timestampFirstBackup || empty($timestampFirstBackup)) {\n $timestampFirstBackup = $timestampBackup;\n $tailleFirstBackup = $taille ;\n }\n if ($timestampBackup >= $timestampLastBackup || empty($timestampLastBackup)) {\n $timestampLastBackup = $timestampBackup;\n $tailleLastBackup = $taille ;\n }\n \n\n }\n }\n $scenario->setLog('| Résumé : ' . $site . ' (Version : ' . $version . ')');\n $scenario->setLog('| Nb backup presents : ' . $nbBackup);\n $scenario->setLog('| 1er backup dispo : ' . date('d\/m\/Y', $timestampFirstBackup).' ('.$tailleFirstBackup.'Mo)');\n $scenario->setLog('| dernier backup dispo : ' . date('d\/m\/Y', $timestampLastBackup).' ('.$tailleLastBackup.'Mo)');\n $scenario->setLog('| Taille moyenne : ' . round($tailleTotale \/ $nbBackup) . 'Mo');\n\n \/\/ gestion des erreurs\n if ($tailleMax >= $seuilTailleMax || $tailleMin <= $seuilTailleMin) {\n $scenario->setLog('| \/!\\ Pb de taille sur un backup - merci de verifier (taille min : ' . $tailleMin . 'Mb, max :' . $tailleMax . 'Mb)');\n if ($AlerteCentreMsg) message::add('Backup', $site . ' - Pb de taille sur une sauvegarde - merci de verifier (taille min : ' . $tailleMin . 'Mb, max :' . $tailleMax . 'Mb)');\n if ($AlerteNotifJC) $cmdNotifJC->execCmd($options = array(\n 'title' => 'title=Defaut BACKUP ' . $site,\n 'message' => 'Pb de taille sur un backup
Taille min : ' . $tailleMin . 'Mb
Taille max :' . $tailleMax . 'Mb'\n ) , $cache = 0);\n }\n if ( !$backupToday) {\n $scenario->setLog('| \/!\\ Pas de backup aujourd\\'hui');\n if ($AlerteCentreMsg) message::add('Backup', $site . ' - Pas de backup aujourd\\'hui, dernier backup : ' . date('d\/m\/Y', $timestampLastBackup));\n if ($AlerteNotifJC) $cmdNotifJC->execCmd($options = array(\n 'title' => 'title=Defaut BACKUP ' . $site,\n 'message' => 'Pas de backup aujourd\\'hui
Dernier backup : ' . date('d\/m\/Y', $timestampLastBackup)\n ) , $cache = 0);\n }\n }\n}\n\n$scenario->setLog('└───────────────────────────');\n\n", "options": [], "order": "0" } ] } ] } ] }