From c52564a2bc387174b755fa94c97005e4b5a0b407 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Mon, 14 Oct 2024 01:29:06 +0200 Subject: [PATCH] host_info_backup --- etc/dbq/data.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/etc/dbq/data.php b/etc/dbq/data.php index e9ef679b..34cdb11f 100644 --- a/etc/dbq/data.php +++ b/etc/dbq/data.php @@ -1,5 +1,17 @@ 1024); + + #return Math.max(SizeInBytes, 0.1).toFixed(1) + byteUnits[i]; + return floor($SizeInBytes).$byteUnits[$i]; +} + $DBQ['data'] = [ 'tables' => [ 'host_info_err' => [ @@ -7,6 +19,40 @@ $DBQ['data'] = [ ." OR (key LIKE '%.exit_code' AND val<> '0')" , ], + 'host_info_backup' => [ + 'sql' => preg_replace('/[\t\r\n]/',''," + SELECT host + ,REPLACE(REPLACE(hi.key,'backup_servers.',''),'.dirs','') as server + ,'' as time + ,'' as files_transfer + ,'' as files_total + ,'' as bytes_transfer + ,'' as bytes_total + ,max(updated) as updated + FROM host_info hi + WHERE key LIKE 'backup_servers.%.dirs' + GROUP BY host,server ORDER BY updated DESC, host +"), + 'row_parse_pre' => function(&$row,$t) { + + $sql = "SELECT key,val FROM host_info WHERE host=".$t->db()->quote($row['host']) + ." AND key LIKE 'backup_servers.".$row['server'].".%'"; + ; + $rows = $t->db()->rows($sql,PDO::FETCH_ASSOC); + foreach($rows as $info) { + $info['key'] = preg_replace('/^.*\.([^\.]+)$/','$1',$info['key']); + if (preg_match('/^bytes/',$info['key'])) + #if (preg_match('/(total|transfer)$/',$info['key'])) + $info['val'] = bytes2h( $info['val'] ) + ; + if (isset($row[ $info['key'] ])) $row[ $info['key'] ] = $info['val']; + } + + foreach ($row as $k=>$v) { + if (strpos($k,'updated') !== false) $row[$k] = preg_replace('/\..*$/','',$v); + } + }, + ], 'host_info_git' => [ 'sql' => preg_replace('/[\t\r\n]/',''," SELECT host -- 2.47.3