From fdc0eca44de14c2793df57155f3d63d96aaf783d Mon Sep 17 00:00:00 2001 From: laf Date: Wed, 6 Jan 2016 00:14:35 +0000 Subject: [PATCH] Centralised version info + used in output --- discovery.php | 10 +++++++++- html/pages/about.inc.php | 11 ++++++----- includes/common.php | 26 ++++++++++++++++++++++++++ includes/defaults.inc.php | 1 + includes/functions.php | 4 ---- poller.php | 10 +++++++++- validate.php | 20 +++++++++++++++++--- 7 files changed, 68 insertions(+), 14 deletions(-) diff --git a/discovery.php b/discovery.php index 5b65b05563..02a1a0c70b 100755 --- a/discovery.php +++ b/discovery.php @@ -27,7 +27,15 @@ $options = getopt('h:m:i:n:d::a::q',array('os:','type:')); if (!isset($options['q'])) { echo $config['project_name_version']." Discovery\n"; - echo get_last_commit()."\n"; + $versions = version_info(false); + echo "Version info:\n"; + $cur_sha = $versions['local_sha']; + echo "Commit SHA: $cur_sha\n"; + echo "DB Schema: ".$versions['db_schema']."\n"; + echo "PHP: ".$versions['php_ver']."\n"; + echo "MySQL: ".$versions['mysql_ver']."\n"; + echo "RRDTool: ".$versions['rrdtool_ver']."\n"; + echo "SNMP: ".$versions['netsnmp_ver']."\n"; } if (isset($options['h'])) { diff --git a/html/pages/about.inc.php b/html/pages/about.inc.php index 8d131d5b5f..fef100db63 100644 --- a/html/pages/about.inc.php +++ b/html/pages/about.inc.php @@ -145,14 +145,15 @@ echo "

LibreNMS is an autodiscovering PHP/MySQL-based network monitoring system.

&1'); -$rrdtool_version = implode(' ', array_slice(explode(' ', shell_exec($config['rrdtool'].' --version |head -n1')), 1, 1)); -$schema_version = dbFetchCell('SELECT version FROM dbSchema'); +$php_version = $versions['php_ver']; +$mysql_version = $versions['mysql_ver']; +$netsnmp_version = $versions['netsnmp_ver']; +$rrdtool_version = $versions['rrdtool_ver']; +$schema_version = $versions['db_schema']; $version = `git rev-parse --short HEAD`; diff --git a/includes/common.php b/includes/common.php index de68cfd788..82d908d635 100644 --- a/includes/common.php +++ b/includes/common.php @@ -807,3 +807,29 @@ function parse_location($location) { return array('lat' => $tmp_loc[2], 'lng' => $tmp_loc[3]); } }//end parse_location() + +/** + * Returns version info + * @return array +**/ +function version_info($remote=true) { + global $config; + $output = array(); + if ($remote === true && $config['update_channel'] == 'master') { + $api = curl_init(); + set_curl_proxy($api); + curl_setopt($api, CURLOPT_USERAGENT,'LibreNMS'); + curl_setopt($api, CURLOPT_URL, $config['github_api'].'commits/master'); + curl_setopt($api, CURLOPT_RETURNTRANSFER, 1); + $output['github'] = json_decode(curl_exec($api),true); + } + $output['local_sha'] = chop(`git rev-parse HEAD`); + $output['db_schema'] = dbFetchCell('SELECT version FROM dbSchema'); + $output['php_ver'] = phpversion(); + $output['mysql_ver'] = dbFetchCell('SELECT version()'); + $output['rrdtool_ver'] = implode(' ', array_slice(explode(' ', shell_exec($config['rrdtool'].' --version |head -n1')), 1, 1)); + $output['netsnmp_ver'] = shell_exec($config['snmpget'].' --version 2>&1'); + + return $output; + +}//end version_info() diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 189dc6a92d..7e6ac8ad09 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -106,6 +106,7 @@ if (isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT'])) { $config['project_home'] = 'http://www.librenms.org/'; $config['project_issues'] = 'https://github.com/librenms/librenms/issues'; +$config['github_api'] = 'https://api.github.com/repos/librenms/librenms/'; $config['site_style'] = 'light'; // Options are dark or light $config['stylesheet'] = 'css/styles.css'; diff --git a/includes/functions.php b/includes/functions.php index 318656fc1a..a8eb15e5ad 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1230,10 +1230,6 @@ function function_check($function) { return function_exists($function); } -function get_last_commit() { - return `git log -n 1|head -n1`; -}//end get_last_commit - /** * Try to determine the address family (IPv4 or IPv6) associated with an SNMP * transport specifier (like "udp", "udp6", etc.). diff --git a/poller.php b/poller.php index 6412c37be9..f8d74b6e45 100755 --- a/poller.php +++ b/poller.php @@ -23,7 +23,15 @@ require 'includes/alerts.inc.php'; $poller_start = utime(); echo $config['project_name_version']." Poller\n"; -echo get_last_commit()."\n"; +$versions = version_info(false); +echo "Version info:\n"; +$cur_sha = $versions['local_sha']; +echo "Commit SHA: $cur_sha\n"; +echo "DB Schema: ".$versions['db_schema']."\n"; +echo "PHP: ".$versions['php_ver']."\n"; +echo "MySQL: ".$versions['mysql_ver']."\n"; +echo "RRDTool: ".$versions['rrdtool_ver']."\n"; +echo "SNMP: ".$versions['netsnmp_ver']."\n"; $options = getopt('h:m:i:n:r::d::a::'); diff --git a/validate.php b/validate.php index 6e0405fbc9..6bb3f60472 100755 --- a/validate.php +++ b/validate.php @@ -44,9 +44,6 @@ if (strstr(`php -ln config.php`, 'No syntax errors detected')) { else if ($last_lines[1] == '?>') { print_warn("It looks like you have ?> at the end of config.php, it's suggested you remove this"); } - else { - print_ok('config.php tested ok'); - } } else { print_fail('Syntax error in config.php'); @@ -63,8 +60,25 @@ require_once 'includes/defaults.inc.php'; require_once 'config.php'; require_once 'includes/definitions.inc.php'; require_once 'includes/functions.php'; +require_once 'includes/common.php'; require_once $config['install_dir'].'/includes/alerts.inc.php'; +$versions = version_info(); +echo "Version info:\n"; +$cur_sha = $versions['local_sha']; +if ($config['update_channel'] == 'master' && $cur_sha != $versions['github']['sha']) { + print_warn("Your install is out of date: $cur_sha"); +} +else { + echo "Commit SHA: $cur_sha\n"; +} +echo "DB Schema: ".$versions['db_schema']."\n"; +echo "PHP: ".$versions['php_ver']."\n"; +echo "MySQL: ".$versions['mysql_ver']."\n"; +echo "RRDTool: ".$versions['rrdtool_ver']."\n"; +echo "SNMP: ".$versions['netsnmp_ver']."\n"; + + // Check php modules we use to make sure they are loaded $extensions = array('pcre','curl','session','snmp','mcrypt'); foreach ($extensions as $extension) {