diff --git a/.gitignore b/.gitignore index aa8811c..674e142 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +data/log.php +data/status.php ################# ## Eclipse diff --git a/check.php b/check.php index 2046512..b0ff3c6 100644 --- a/check.php +++ b/check.php @@ -129,108 +129,7 @@ function print_status ($status) { $array['page']['title'] = 'Доступность ресурсов'; $array['page']['timestamp'] = strtotime( 'now' ); -$data = array( - array( - "name" => "proxy:3129", - "type" => "host-port", - "host" => "proxy.stok.local", - "port" => 3129, - "desc" => "прокси" - ), - array( - "name" => "base", - "type" => "host-port", - "host" => "base.stok.local", - "port" => 80, - //"link" => "http://base/", - "desc" => "вебсервер" - ), - array( - "name" => "terminal", - "type" => "host-port", - "host" => "terminal.stok.local", - "port" => 3389, - //"link" => "rdp://terminal", - "desc" => "Терминальный сервер, 1С" - ), - array( - "name" => "znago", - "type" => "ping", - "host" => "znago.stok.local", - //"link" => "vnc://znago", - "desc" => "сервер ЗНиАГО" - ), - array( - "name" => "sto3", - "type" => "ping", - "host" => "sto3.stok.local", - //"link" => "vnc://sto3", - "desc" => "автосфера" - ), - array( - "name" => "proxy", - "type" => "ping", - "host" => "proxy.stok.local", - //"link" => "vnc://proxy", - "desc" => "шлюз в Интернет" - ), - /* array( - "name" => "videosrv", - "type" => "host-port-off", - "host" => "videosrv.stok.local", - "port" => 21400, - //"link" => "vnc://videosrv", - "desc" => "видеосервер" - ), - array( - "name" => "garantia2", - "type" => "host-port-off", - "host" => "garantia2.stok.local", - "port" => 21400, - //"link" => "vnc://garantia2", - "desc" => "видеосервер" - ), */ - array( - "name" => "tportal.vaz.ru", - "type" => "host-port", - "host" => "tportal.vaz.ru", - "port" => 80, - "link" => "http://tportal.vaz.ru/", - "desc" => "технопортал" - ), - array( - "name" => "autosphere.ru", - "type" => "ping", - "host" => "vpn.autosphere.ru", - //"link" => "http://www.autosphere.ru/", - "desc" => "автосфера" - ), - /* array( - "name" => "util.minprom.gov.ru", - "type" => "util-minprom", - "link" => "http://util.minprom.gov.ru/", - "desc" => "утилизация" - ), */ - array( - "name" => "lada-direct.ru", - "type" => "lada-direct", - "link" => "http://lada-direct.ru/", - "desc" => "продажи Гранты" - ), - array( - "name" => "Интернет", - "type" => "internet" - ), - array( - "name" => "mail.stok.local:110", - "type" => "host-port", - "host" => "mail.stok.local", - "port" => 110, - "desc" => "почтовый сервер" - ) -); - - +$data = load( 'data/config.php' ); foreach ( $data as &$item ) { switch ($item['type']) { @@ -261,13 +160,55 @@ function print_status ($status) { $array['data'] = $data; -$array_old = load( 'status.php' ); +$array_old = load( 'data/status.php' ); +$array_log = load( 'data/log.php' ); + +function array_diff_assoc_recursive($array1, $array2) +{ + foreach ($array1 as $key => $value) + { + if (is_array($value)) + { + if (!array_key_exists($key, $array2)) + { + $difference[$key] = $value; + } + elseif (!is_array($array2[$key])) + { + $difference[$key] = $value; + } + else + { + $new_diff = array_diff_assoc_recursive($value, $array2[$key]); + if ($new_diff != FALSE) + { + $difference[$key] = $new_diff; + } + } + } + elseif (!array_key_exists($key, $array2) || $array2[$key] != $value) + { + $difference[$key] = $value; + } + } + return !isset($difference) ? FALSE : $difference; +} -$array_diff[] = array_diff($array, $array_old); +array_unshift( + $array_log, + array( + 'timestamp' => strtotime( 'now' ), + 'data' => array_diff_assoc_recursive( + $array, + $array_old + ) + ) +); +$array_log = array_slice($array_log, 0, 14); chdir( dirname( __FILE__ ) ); -save( 'log.php', $array_diff ); -save( 'status.php', $array ); +save( 'data/log.php', $array_log ); +save( 'data/status.php', $array ); //return $array; //$perf->text(); diff --git a/index.php b/index.php index ccf3d83..b98134a 100644 --- a/index.php +++ b/index.php @@ -5,10 +5,10 @@ require_once( 'inc/utils.php' ); //$perf = new perf_timer(); -$array = load( 'status.php' ); +$array = load( 'data/status.php' ); if ( ( strtotime( 'now' ) - $array['page']['timestamp'] ) > 150 ){ require( 'check.php' ); - $array = load( 'status.php' ); + $array = load( 'data/status.php' ); } $data = $array['data']; $page = $array['page']; diff --git a/log.php b/log.php deleted file mode 100644 index be896b3..0000000 --- a/log.php +++ /dev/null @@ -1,6 +0,0 @@ - - array ( - ), -); \ No newline at end of file diff --git a/status.php b/status.php deleted file mode 100644 index 55e0959..0000000 --- a/status.php +++ /dev/null @@ -1,147 +0,0 @@ - - array ( - 'title' => 'Доступность ресурсов', - 'timestamp' => 1337777100, - ), - 'data' => - array ( - 0 => - array ( - 'name' => 'proxy:3129', - 'type' => 'host-port', - 'host' => 'proxy.stok.local', - 'port' => 3129, - 'desc' => 'прокси', - 'stat' => - array ( - 'code' => 'good', - 'text' => 'Доступен', - ), - ), - 1 => - array ( - 'name' => 'base', - 'type' => 'host-port', - 'host' => 'base.stok.local', - 'port' => 80, - 'desc' => 'вебсервер', - 'stat' => - array ( - 'code' => 'good', - 'text' => 'Доступен', - ), - ), - 2 => - array ( - 'name' => 'terminal', - 'type' => 'host-port', - 'host' => 'terminal.stok.local', - 'port' => 3389, - 'desc' => 'Терминальный сервер, 1С', - 'stat' => - array ( - 'code' => 'good', - 'text' => 'Доступен', - ), - ), - 3 => - array ( - 'name' => 'znago', - 'type' => 'ping', - 'host' => 'znago.stok.local', - 'desc' => 'сервер ЗНиАГО', - 'stat' => - array ( - 'code' => 'good', - 'text' => 'Доступен, <1 мс', - ), - ), - 4 => - array ( - 'name' => 'sto3', - 'type' => 'ping', - 'host' => 'sto3.stok.local', - 'desc' => 'автосфера', - 'stat' => - array ( - 'code' => 'good', - 'text' => 'Доступен, <1 мс', - ), - ), - 5 => - array ( - 'name' => 'proxy', - 'type' => 'ping', - 'host' => 'proxy.stok.local', - 'desc' => 'шлюз в Интернет', - 'stat' => - array ( - 'code' => 'good', - 'text' => 'Доступен, <1 мс', - ), - ), - 6 => - array ( - 'name' => 'tportal.vaz.ru', - 'type' => 'host-port', - 'host' => 'tportal.vaz.ru', - 'port' => 80, - 'link' => 'http://tportal.vaz.ru/', - 'desc' => 'технопортал', - 'stat' => - array ( - 'code' => 'good', - 'text' => 'Доступен', - ), - ), - 7 => - array ( - 'name' => 'autosphere.ru', - 'type' => 'ping', - 'host' => 'vpn.autosphere.ru', - 'desc' => 'автосфера', - 'stat' => - array ( - 'code' => 'good', - 'text' => 'Доступен, 27 мс', - ), - ), - 8 => - array ( - 'name' => 'lada-direct.ru', - 'type' => 'lada-direct', - 'link' => 'http://lada-direct.ru/', - 'desc' => 'продажи Гранты', - 'stat' => - array ( - 'code' => 'good', - 'text' => 'Нет', - ), - ), - 9 => - array ( - 'name' => 'Интернет', - 'type' => 'internet', - 'stat' => - array ( - 'code' => 'good', - 'text' => 'Доступен, 23 мс', - ), - ), - 10 => - array ( - 'name' => 'mail.stok.local:110', - 'type' => 'host-port', - 'host' => 'mail.stok.local', - 'port' => 110, - 'desc' => 'почтовый сервер', - 'stat' => - array ( - 'code' => 'good', - 'text' => 'Доступен', - ), - ), - ), -); \ No newline at end of file