From 5c26586f89ac1486f036984e9312f9963e6f8741 Mon Sep 17 00:00:00 2001 From: Rosiak Date: Thu, 4 Aug 2016 22:34:29 +0200 Subject: [PATCH 01/15] Comware Version Fix Be able to discover the version && features on older versions && newer. --- includes/polling/os/comware.inc.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/polling/os/comware.inc.php b/includes/polling/os/comware.inc.php index c7b2195a27..556c46e31c 100644 --- a/includes/polling/os/comware.inc.php +++ b/includes/polling/os/comware.inc.php @@ -8,5 +8,6 @@ echo 'Comware OS...'; $hardware = snmp_get($device, 'sysObjectID.0', '-Osqv', 'SNMPv2-MIB:HH3C-PRODUCT-ID-MIB'); -preg_match('/Software Version (.+), Release ([a-zA-Z0-9]+)/', $poll_device['sysDescr'], $match); -list(,$version,$features) = $match; +$data = str_replace(",","",$poll_device['sysDescr']); +$version = $data['6']; +$features = $data['8']; From e19a25f4cd45c6d150ff67115a42ea0d9789efc9 Mon Sep 17 00:00:00 2001 From: Rosiak Date: Thu, 4 Aug 2016 23:11:10 +0200 Subject: [PATCH 02/15] Brain Fart --- includes/polling/os/comware.inc.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/polling/os/comware.inc.php b/includes/polling/os/comware.inc.php index 556c46e31c..54010085ed 100644 --- a/includes/polling/os/comware.inc.php +++ b/includes/polling/os/comware.inc.php @@ -9,5 +9,6 @@ echo 'Comware OS...'; $hardware = snmp_get($device, 'sysObjectID.0', '-Osqv', 'SNMPv2-MIB:HH3C-PRODUCT-ID-MIB'); $data = str_replace(",","",$poll_device['sysDescr']); -$version = $data['6']; -$features = $data['8']; +$explodeddata = explode(" ", $data); +$version = $explodeddata['6']; +$features = $explodeddata['8']; From a2e7726cd09569cc9a08dcc40468f40f08b49d99 Mon Sep 17 00:00:00 2001 From: crcro Date: Sun, 7 Aug 2016 06:24:34 +0300 Subject: [PATCH 03/15] fixes for general apps page --- .../{dhcp-stats.inc.php => dhcp-stats_stats.inc.php} | 0 .../{os-updates.inc.php => os-updates_packages.inc.php} | 0 html/pages/apps.inc.php | 8 ++++++-- html/pages/device/apps/dhcp-stats.inc.php | 2 +- html/pages/device/apps/os-updates.inc.php | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) rename html/includes/graphs/application/{dhcp-stats.inc.php => dhcp-stats_stats.inc.php} (100%) rename html/includes/graphs/application/{os-updates.inc.php => os-updates_packages.inc.php} (100%) diff --git a/html/includes/graphs/application/dhcp-stats.inc.php b/html/includes/graphs/application/dhcp-stats_stats.inc.php similarity index 100% rename from html/includes/graphs/application/dhcp-stats.inc.php rename to html/includes/graphs/application/dhcp-stats_stats.inc.php diff --git a/html/includes/graphs/application/os-updates.inc.php b/html/includes/graphs/application/os-updates_packages.inc.php similarity index 100% rename from html/includes/graphs/application/os-updates.inc.php rename to html/includes/graphs/application/os-updates_packages.inc.php diff --git a/html/pages/apps.inc.php b/html/pages/apps.inc.php index 0a48bd432a..04c4cc21ed 100644 --- a/html/pages/apps.inc.php +++ b/html/pages/apps.inc.php @@ -76,8 +76,12 @@ $graphs['nfs-v3-stats'] = array( 'rpc', ); -$graphs['os-updates'] = array(''); -$graphs['dhcp-stats'] = array(''); +$graphs['os-updates'] = array( + 'packages', +); +$graphs['dhcp-stats'] = array( + 'stats', +); print_optionbar_start(); diff --git a/html/pages/device/apps/dhcp-stats.inc.php b/html/pages/device/apps/dhcp-stats.inc.php index debe352ffc..707d55c95a 100644 --- a/html/pages/device/apps/dhcp-stats.inc.php +++ b/html/pages/device/apps/dhcp-stats.inc.php @@ -3,7 +3,7 @@ global $config; $graphs = array( - 'dhcp-stats' => 'DHCP Stats', + 'dhcp-stats_stats' => 'DHCP Stats', ); foreach ($graphs as $key => $text) { diff --git a/html/pages/device/apps/os-updates.inc.php b/html/pages/device/apps/os-updates.inc.php index 31ba45b92a..772dc85d1e 100644 --- a/html/pages/device/apps/os-updates.inc.php +++ b/html/pages/device/apps/os-updates.inc.php @@ -3,7 +3,7 @@ global $config; $graphs = array( - 'os-updates' => 'OS updates', + 'os-updates_packages' => 'OS updates', ); foreach ($graphs as $key => $text) { From 330910b4e39ebe20fd3f363f4417d9b2a5ac7f9d Mon Sep 17 00:00:00 2001 From: vitalisator Date: Sun, 7 Aug 2016 17:47:25 +0200 Subject: [PATCH 04/15] Fix a bug in syslog since PR #3812 syslog writes to wrong device id in syslog table. this happens on all devices where inet_pton() returns false. --- includes/syslog.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/includes/syslog.php b/includes/syslog.php index ab4d1e2a12..fa0eacacae 100644 --- a/includes/syslog.php +++ b/includes/syslog.php @@ -13,7 +13,12 @@ function get_cache($host, $value) { case 'device_id': // Try by hostname $ip = inet_pton($host); - $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM devices WHERE `hostname` = ? OR `sysName` = ? OR `ip` = ?', array($host, $host, $ip)); + if (var_export(inet_ntop($ip),1) == 'false') { + $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM devices WHERE `hostname` = ? OR `sysName` = ?', array($host, $host)); + } + else { + $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM devices WHERE `hostname` = ? OR `sysName` = ? OR `ip` = ?', array($host, $host, $ip)); + } // If failed, try by IP if (!is_numeric($dev_cache[$host]['device_id'])) { $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM `ipv4_addresses` AS A, `ports` AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id', array($host)); From f3fc6f2906a6792e20790334906ea2cd69a7b26e Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Sun, 7 Aug 2016 12:16:40 -0500 Subject: [PATCH 05/15] Use Exceptions Use exceptions for addHost() Gets rid of silly mixed return and only returns the device_id. Throwing an exception if we run into any issues. Slightly modifies api add host output again to include device_id --- addhost.php | 30 +++++++++++++---------- html/includes/api_functions.inc.php | 11 ++++----- html/pages/addhost.inc.php | 15 ++++++++---- includes/discovery/functions.inc.php | 13 +++++----- includes/functions.php | 36 +++++++++++++++++----------- snmp-scan.php | 27 +++++++++++++-------- 6 files changed, 77 insertions(+), 55 deletions(-) diff --git a/addhost.php b/addhost.php index 8e799174df..d82b03241e 100755 --- a/addhost.php +++ b/addhost.php @@ -49,7 +49,7 @@ if (isset ($options['p'])) { if (! in_array ($port_assoc_mode, $valid_assoc_modes)) { echo "Invalid port association mode '" . $port_assoc_mode . "'\n"; echo 'Valid modes: ' . join (', ', $valid_assoc_modes) . "\n"; - exit(2); + exit(1); } $cmd = array_shift($argv); @@ -115,7 +115,7 @@ if (!empty($argv[1])) { $v3['authalgo'] = $arg; } else { echo 'Invalid argument: '.$arg."\n"; - exit(2); + exit(1); } } @@ -139,7 +139,7 @@ if (!empty($argv[1])) { $v3['cryptoalgo'] = $arg; } else { echo 'Invalid argument: '.$arg."\n"; - exit(2); + exit(1); } }//end while @@ -165,16 +165,20 @@ if (!empty($argv[1])) { } }//end if - $result = addHost($host, $snmpver, $port, $transport, 0, $poller_group, $force_add, $port_assoc_mode); - - if (is_numeric($result)) { - $device = device_by_id_cache($result); - echo 'Added device '.$device['hostname'].' ('.$result.")\n"; + try { + $device_id = addHost($host, $snmpver, $port, $transport, $poller_group, $force_add, $port_assoc_mode); + $device = device_by_id_cache($device_id); + echo "Added device {$device['hostname']} ($device_id)\n"; exit(0); - } - else { - print $console_color->convert("%rWe couldn't add this device:\n " . $result . "%n\n"); - exit(1); + } catch (HostUnreachableException $e) { + print_error($e->getMessage()); + foreach ($e->getReasons() as $reason) { + echo " $reason\n"; + } + exit(2); + } catch (Exception $e){ + print_error($e->getMessage()); + exit(3); } } else { @@ -197,5 +201,5 @@ if (!empty($argv[1])) { %rRemember to run discovery for the host afterwards.%n ' ); - exit(2); + exit(1); } diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index d06d625f5b..11b6132c01 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -289,14 +289,13 @@ function add_device() { $message = "You haven't specified an SNMP version to use"; } if (empty($message)) { - $result = addHost($hostname, $snmpver, $port, $transport, 1, $poller_group, $force_add); - if (is_numeric($result)) { + try { + $device_id = addHost($hostname, $snmpver, $port, $transport, $poller_group, $force_add); $code = 201; $status = 'ok'; - $message = "Device $hostname has been added successfully"; - } - else { - $message = $result; + $message = "Device $hostname ($device_id) has been added successfully"; + } catch (Exception $e) { + $message = $e->getMessage(); } } diff --git a/html/pages/addhost.inc.php b/html/pages/addhost.inc.php index f2bf274e6d..947478ee62 100644 --- a/html/pages/addhost.inc.php +++ b/html/pages/addhost.inc.php @@ -66,11 +66,16 @@ if ($_POST['hostname']) { } $port_assoc_mode = $_POST['port_assoc_mode']; - $result = addHost($hostname, $snmpver, $port, $transport, 0, $poller_group, $force_add, $port_assoc_mode); - if (is_numeric($result)) { - print_message("Device added ($result)"); - } else { - print_error('Error: ' . $result); + try { + $device_id = addHost($hostname, $snmpver, $port, $transport, $poller_group, $force_add, $port_assoc_mode); + print_message("Device added ($device_id)"); + } catch (HostUnreachableException $e) { + print_error($e->getMessage()); + foreach ($e->getReasons() as $reason) { + print_error($reason); + } + } catch (Exception $e){ + print_error($e->getMessage()); } } else { diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 460ef4cc2c..4e1a3ff603 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -53,9 +53,8 @@ function discover_new_device($hostname, $device = '', $method = '', $interface = } if (match_network($config['nets'], $ip)) { - $result = addHost($dst_host, '', '161', 'udp', '0', $config['distributed_poller_group']); - if (is_numeric($result)) { - $remote_device_id = $result; + try { + $remote_device_id = addHost($dst_host, '', '161', 'udp', $config['distributed_poller_group']); $remote_device = device_by_id_cache($remote_device_id, 1); echo '+[' . $remote_device['hostname'] . '(' . $remote_device['device_id'] . ')]'; discover_device($remote_device); @@ -73,10 +72,10 @@ function discover_new_device($hostname, $device = '', $method = '', $interface = } return $remote_device_id; - } else { - if(substr($result, 0, 12) !== 'Already have') { - log_event("$method discovery of " . $dst_host . " ($ip) failed - " . $result); - } + } catch (HostExistsException $e) { + // already have this device + } catch (Exception $e) { + log_event("$method discovery of " . $dst_host . " ($ip) failed - " . $e->getMessage()); } } else { d_echo("$ip not in a matched network - skipping\n"); diff --git a/includes/functions.php b/includes/functions.php index b7ce3b20f1..819511f7fb 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -17,7 +17,8 @@ include_once("Net/IPv4.php"); include_once("Net/IPv6.php"); -// Observium Includes +// Includes +include_once($config['install_dir'] . "/includes/exceptions.inc.php"); include_once($config['install_dir'] . "/includes/dbFacile.php"); include_once($config['install_dir'] . "/includes/common.php"); @@ -253,23 +254,30 @@ function delete_device($id) { * @param string $snmp_version If this is empty, try v2c,v3,v1. Otherwise, use this specific version. * @param string $port the port to connect to for snmp * @param string $transport udp or tcp - * @param int $quiet don't output anything * @param string $poller_group the poller group this device will belong to * @param string $force_add add even if the device isn't pingable * @param string $port_assoc_mode snmp field to use to determine unique ports - * @return int|string returns the id of the added device, otherwise an error message + * + * @return int returns the device_id of the added device + * + * @throws HostExistsException This hostname already exists + * @throws HostIpExistsException We already have a host with this IP + * @throws HostUnreachableException We could not reach this device is some way + * @throws HostUnreachablePingException We could not ping the device + * @throws InvalidPortAssocModeException The given port association mode was invalid + * @throws SnmpVersionUnsupportedException The given snmp version was invalid */ -function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $quiet = 0, $poller_group = '0', $force_add = '0', $port_assoc_mode = 'ifIndex') { +function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $poller_group = '0', $force_add = '0', $port_assoc_mode = 'ifIndex') { global $config; // Test Database Exists if (host_exists($host) === true) { - return "Already have host $host"; + throw new HostExistsException("Already have host $host"); } // Valid port assoc mode if (!is_valid_port_assoc_mode($port_assoc_mode)) { - return "Invalid port association_mode '$port_assoc_mode'. Valid modes are: " . join(', ', get_port_assoc_modes()); + throw new InvalidPortAssocModeException("Invalid port association_mode '$port_assoc_mode'. Valid modes are: " . join(', ', get_port_assoc_modes())); } // check if we have the host by IP @@ -279,14 +287,14 @@ function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $ $ip = $host; } if (ip_exists($ip)) { - return "Already have host with this IP $host"; + throw new HostIpExistsException("Already have host with this IP $host"); } // Test reachability $address_family = snmpTransportToAddressFamily($transport); $ping_result = isPingable($host, $address_family); if ($force_add == 1 || !$ping_result['result']) { - return "Could not ping $host"; + throw new HostUnreachablePingException("Could not ping $host"); } // if $snmpver isn't set, try each version of snmp @@ -296,13 +304,13 @@ function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $ $snmpvers = array($snmp_version); } + $host_unreachable_exception = new HostUnreachableException("Could not connect, please check the snmp details and snmp reachability"); // try different snmp variables to add the device foreach ($snmpvers as $snmpver) { if ($snmpver === "v3") { // Try each set of parameters from config foreach ($config['snmp']['v3'] as $v3) { $device = deviceArray($host, null, $snmpver, $port, $transport, $v3, $port_assoc_mode); - print_message("Trying v3 parameters " . $v3['authname'] . "/" . $v3['authlevel'] . " ... ", $quiet); if ($force_add == 1 || isSNMPable($device)) { $snmphost = snmp_get($device, "sysName.0", "-Oqv", "SNMPv2-MIB"); $result = createHost($host, null, $snmpver, $port, $transport, $v3, $poller_group, $port_assoc_mode, $snmphost); @@ -310,14 +318,14 @@ function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $ return $result; } } else { - print_error("No reply on credentials " . $v3['authname'] . "/" . $v3['authlevel'] . " using $snmpver", $quiet); + $host_unreachable_exception->addReason("SNMP $snmpver: No reply with credentials " . $v3['authname'] . "/" . $v3['authlevel']); } } } elseif ($snmpver === "v2c" || $snmpver === "v1") { // try each community from config foreach ($config['snmp']['community'] as $community) { $device = deviceArray($host, $community, $snmpver, $port, $transport, null, $port_assoc_mode); - print_message("Trying community $community ...", $quiet); + if ($force_add == 1 || isSNMPable($device)) { $snmphost = snmp_get($device, "sysName.0", "-Oqv", "SNMPv2-MIB"); $result = createHost($host, $community, $snmpver, $port, $transport, array(), $poller_group, $port_assoc_mode, $snmphost); @@ -325,15 +333,15 @@ function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $ return $result; } } else { - print_error("No reply on community $community using $snmpver", $quiet); + $host_unreachable_exception->addReason("SNMP $snmpver: No reply with community $community"); } } } else { - return "Unsupported SNMP Version \"$snmpver\", must be v1, v2c, or v3"; + throw new SnmpVersionUnsupportedException("Unsupported SNMP Version \"$snmpver\", must be v1, v2c, or v3"); } } - return "Could not connect, please check the snmp details and snmp reachability"; + throw $host_unreachable_exception; } function deviceArray($host, $community, $snmpver, $port = 161, $transport = 'udp', $v3, $port_assoc_mode = 'ifIndex') { diff --git a/snmp-scan.php b/snmp-scan.php index 4f38f69750..fb864f9492 100755 --- a/snmp-scan.php +++ b/snmp-scan.php @@ -42,7 +42,7 @@ require 'includes/functions.php'; require 'includes/discovery/functions.inc.php'; function perform_snmp_scan($net) { - global $stats, $config, $quiet; + global $stats, $config, $debug; echo 'Range: '.$net->network.'/'.$net->bitmask.PHP_EOL; $config['snmp']['timeout'] = 1; $config['snmp']['retries'] = 0; @@ -63,22 +63,30 @@ function perform_snmp_scan($net) { continue; } foreach (array('udp','tcp') as $transport) { - $result = addHost(gethostbyaddr($host), '', $config['snmp']['port'], $transport, $quiet, $config['distributed_poller_group'], 0); - if (is_numeric($result)) { + try { + addHost(gethostbyaddr($host), '', $config['snmp']['port'], $transport, $config['distributed_poller_group']); $stats['added']++; echo '+'; break; - } elseif (substr($result, 0, 12) === 'Already have') { + } catch (HostExistsException $e) { $stats['known']++; echo '*'; break; - } elseif (substr($result, 0 , 14) === 'Could not ping') { + } catch (HostUnreachablePingException $e) { echo '.'; break; - } elseif ($transport == 'tcp') { - // tried both udp and tcp without success - $stats['failed']++; - echo '-'; + } catch (HostUnreachableException $e) { + if ($debug) { + print_error($e->getMessage() . " over $transport"); + foreach ($e->getReasons() as $reason) { + echo " $reason\n"; + } + } + if ($transport == 'tcp') { + // tried both udp and tcp without success + $stats['failed']++; + echo '-'; + } } } } @@ -104,7 +112,6 @@ if (isset($opts['h']) || (empty($opts) && (!isset($config['nets']) || empty($con } if (isset($opts['d'])) { $debug = true; - $quiet = 0; } if (isset($opts['l'])) { echo ' * = Known Device; . = Unpingable Device; + = Added Device; - = Failed To Add Device;'.PHP_EOL; From d65364c8efab5d387b521245a9106efec0bf3329 Mon Sep 17 00:00:00 2001 From: Rosiak Date: Sun, 7 Aug 2016 23:40:12 +0200 Subject: [PATCH 06/15] Fix Dell PowerConnect Discovery #3995 --- includes/discovery/os/radlan.inc.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/includes/discovery/os/radlan.inc.php b/includes/discovery/os/radlan.inc.php index da34ae5223..1474289736 100644 --- a/includes/discovery/os/radlan.inc.php +++ b/includes/discovery/os/radlan.inc.php @@ -1,10 +1,6 @@ Date: Sun, 7 Aug 2016 20:28:53 -0500 Subject: [PATCH 07/15] Update docs --- doc/API/API-Docs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/API/API-Docs.md b/doc/API/API-Docs.md index fed298f941..445fd6e22e 100644 --- a/doc/API/API-Docs.md +++ b/doc/API/API-Docs.md @@ -629,7 +629,7 @@ Output: ```text { "status": "ok", - "message": "Device localhost.localdomain has been added successfully" + "message": "Device localhost.localdomain (57) has been added successfully" } ``` From b438e94771800ad72ecce5de3a1b2b70f888949b Mon Sep 17 00:00:00 2001 From: vitalisator Date: Mon, 8 Aug 2016 17:36:19 +0200 Subject: [PATCH 08/15] reduction, thx an @murrant --- includes/syslog.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/syslog.php b/includes/syslog.php index fa0eacacae..26b7ba7901 100644 --- a/includes/syslog.php +++ b/includes/syslog.php @@ -13,7 +13,7 @@ function get_cache($host, $value) { case 'device_id': // Try by hostname $ip = inet_pton($host); - if (var_export(inet_ntop($ip),1) == 'false') { + if (inet_ntop($ip) === false) { $dev_cache[$host]['device_id'] = dbFetchCell('SELECT `device_id` FROM devices WHERE `hostname` = ? OR `sysName` = ?', array($host, $host)); } else { From 057d78aab792b49a1a7743c82059d4c97f43ad60 Mon Sep 17 00:00:00 2001 From: Rosiak Date: Mon, 8 Aug 2016 18:34:30 +0200 Subject: [PATCH 09/15] Remove more code --- includes/polling/os/radlan.inc.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/includes/polling/os/radlan.inc.php b/includes/polling/os/radlan.inc.php index aa0da3818a..2935cc92df 100644 --- a/includes/polling/os/radlan.inc.php +++ b/includes/polling/os/radlan.inc.php @@ -1,16 +1,8 @@ Date: Mon, 8 Aug 2016 19:53:04 +0100 Subject: [PATCH 10/15] Added php lint checking for travis --- .travis.yml | 26 +++++++++++++-------- html/includes/graphs/port/pagp_bits.inc.php | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 36f9fbddea..16a2eb9a55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,19 @@ language: php - -php: - - '5.3' - - '5.4' - - '5.5' - - '5.6' - - '7.0' - - hhvm - matrix: + fast_finish: true + include: + - php: 5.3 + script: find . -path './lib/influxdb-php' -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1 + - php: 5.4 + script: find . -path './lib/influxdb-php' -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1 + - php: 5.5 + script: find . -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1 + - php: 5.6 + script: find . -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1 + - php: 7.0 + script: find . -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1 + - php: hhvm + script: find . -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1 allow_failures: - - php: 7.0 + - php: 7.0 + - php: hhvm diff --git a/html/includes/graphs/port/pagp_bits.inc.php b/html/includes/graphs/port/pagp_bits.inc.php index 7cce013217..450edde0f9 100644 --- a/html/includes/graphs/port/pagp_bits.inc.php +++ b/html/includes/graphs/port/pagp_bits.inc.php @@ -3,7 +3,7 @@ // Generate a list of ports and then call the multi_bits grapher to generate from the list $i = 0; foreach (dbFetchRows('SELECT * FROM `ports` WHERE `device_id` = ? AND `pagpGroupIfIndex` = ?', array($port['device_id'], $port['ifIndex'])) as $int) { - $rrd_file = get_port_rrdfile_path ($hostname, int['port_id']); + $rrd_file = get_port_rrdfile_path ($hostname, $int['port_id']); if (is_file($rrd_file)) { $rrd_list[$i]['filename'] = $rrd_file; $rrd_list[$i]['descr'] = $int['ifDescr']; From 544fd95a635d3166f572145bbc4de9df4cf7d4f5 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 8 Aug 2016 20:03:40 +0100 Subject: [PATCH 11/15] Updated to support php 5.3 --- includes/polling/applications/proxmox.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/polling/applications/proxmox.inc.php b/includes/polling/applications/proxmox.inc.php index c1e366b362..c86a6e5a92 100644 --- a/includes/polling/applications/proxmox.inc.php +++ b/includes/polling/applications/proxmox.inc.php @@ -51,7 +51,7 @@ if (!is_dir($pmxcdir)) { dbUpdate(array('device_id' => $device['device_id'], 'app_type' => 'proxmox', 'app_instance' => $pmxcluster), 'applications', '`device_id` = ? AND `app_type` = ?', array($device['device_id'], 'proxmox')); if (count($pmxlines) > 0) { - $pmxcache = []; + $pmxcache = array(); foreach ($pmxlines as $vm) { list($vmid, $vmport, $vmpin, $vmpout, $vmdesc) = explode('/', $vm, 5); From bcd2476f321295256e80e5dd67248491c9918ac1 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 8 Aug 2016 20:13:33 +0100 Subject: [PATCH 12/15] Updated travis + added build icons --- .travis.yml | 2 +- README.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 16a2eb9a55..a3ea97cf9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ matrix: - php: 7.0 script: find . -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1 - php: hhvm - script: find . -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1 + script: find . -path './lib/influxdb-php' -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1 allow_failures: - php: 7.0 - php: hhvm diff --git a/README.md b/README.md index 2d3555809b..926658660a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://scrutinizer-ci.com/g/librenms/librenms/badges/build.png?b=master)](https://scrutinizer-ci.com/g/librenms/librenms/build-status/master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/librenms/librenms/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/librenms/librenms/?branch=master) [![Build Status](https://travis-ci.org/librenms/librenms.svg?branch=master)](https://travis-ci.org/librenms/librenms) + Introduction ------------ From 34feda861370ec961c7161303d70bf85aea55d4c Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 8 Aug 2016 20:20:18 +0100 Subject: [PATCH 13/15] Fixed ./includes/polling/applications/rrdcached.inc.php for php 53 --- includes/polling/applications/rrdcached.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/polling/applications/rrdcached.inc.php b/includes/polling/applications/rrdcached.inc.php index 21bb5e4684..f37136402b 100644 --- a/includes/polling/applications/rrdcached.inc.php +++ b/includes/polling/applications/rrdcached.inc.php @@ -53,7 +53,8 @@ if ($agent_data['app']['rrdcached']) { while ($max == -1 || $count < $max) { $data .= fgets($sock, 128); if ($max == -1) { - $max = explode(' ', $data)[0] + 1; + $tmp_max = explode(' ', $data); + $max = $tmp_max[0]+1; } $count++; } From 09eb5ca1e94d4c9e970b174f817225331f6199c9 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 8 Aug 2016 20:26:44 +0100 Subject: [PATCH 14/15] Fixed ./includes/polling/os/infinity.inc.php for php 53 --- includes/polling/os/infinity.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/polling/os/infinity.inc.php b/includes/polling/os/infinity.inc.php index bf4d70981c..61c11edec7 100644 --- a/includes/polling/os/infinity.inc.php +++ b/includes/polling/os/infinity.inc.php @@ -10,6 +10,6 @@ * the source code distribution for details. */ -$version = $poll_device['sysDescr']; -$version = explode(' ', $version)[2]; +$version = explode(' ', $poll_device['sysDescr']); +$version = $version[2]; $hardware = snmp_get($device, 'IEEE802dot11-MIB::dot11manufacturerProductName.5', '-Ovq'); From 5643d3710d42f3efdd15d936fe7ed3f9a555a60f Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Mon, 8 Aug 2016 15:47:35 -0500 Subject: [PATCH 15/15] Actually add the exceptions --- includes/exceptions.inc.php | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 includes/exceptions.inc.php diff --git a/includes/exceptions.inc.php b/includes/exceptions.inc.php new file mode 100644 index 0000000000..4964c3683b --- /dev/null +++ b/includes/exceptions.inc.php @@ -0,0 +1,70 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2016 Tony Murray + * @author Tony Murray + */ + + +// ---- addHost Excpetions ---- +class HostExistsException extends Exception {} + +class HostIpExistsException extends HostExistsException {} + +class InvalidPortAssocModeException extends Exception {} + +class SnmpVersionUnsupportedException extends Exception {} + +class HostUnreachableException extends Exception +{ + protected $reasons = array(); + + public function __toString() + { + $string = __CLASS__ . ": [{$this->code}]: {$this->message}\n"; + foreach ($this->reasons as $reason) { + $string .= " $reason\n"; + } + return $string; + } + + /** + * Add additional reasons + * @param $message + */ + public function addReason($message) + { + $this->reasons[] = $message; + } + + /** + * Get the reasons + * @return array + */ + public function getReasons() + { + return $this->reasons; + } +} + +class HostUnreachablePingException extends HostUnreachableException {} + +class HostUnreachableSnmpException extends HostUnreachableException {}