From 06b0906aaef25fdfc47b5fdd8eb2437a98445db6 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sun, 2 Oct 2016 08:25:48 +0100 Subject: [PATCH 01/10] fix: Fixed SQL query for bgpPeers check to remove stale sessions (#4697) --- includes/discovery/bgp-peers.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index 6edcfc14a0..cc1903f534 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -214,7 +214,7 @@ if ($config['enable_bgp']) { } // Delete removed peers - $sql = "SELECT * FROM bgpPeers WHERE device_id = '".$device['device_id']."' AND context_name = '".$device['context_name']."'"; + $sql = "SELECT * FROM bgpPeers WHERE device_id = '".$device['device_id']."' AND (context_name = '".$device['context_name']."' OR context_name IS NULL)"; foreach (dbFetchRows($sql) as $entry) { unset($exists); From f14335b7a5972b6b6721fe55a54ce4ccf3c44ae6 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sun, 2 Oct 2016 08:27:12 +0100 Subject: [PATCH 02/10] doc: Added FAQ for why interfaces are missing from overall traffic graphs (#4696) --- doc/Support/FAQ.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/doc/Support/FAQ.md b/doc/Support/FAQ.md index 5b571f02b2..6dc97884d3 100644 --- a/doc/Support/FAQ.md +++ b/doc/Support/FAQ.md @@ -20,6 +20,7 @@ source: Support/FAQ.md - [Things aren't working correctly?](#faq18) - [What do the values mean in my graphs?](#faq21) - [Why does a device show as a warning?](#faq22) + - [Why do I not see all interfaces in the Overall traffic graph for a device?](#faq23) ### Developing - [How do I add support for a new OS?](#faq8) @@ -169,6 +170,39 @@ here are those values: This is indicating that the device has rebooted within the last 24 hours (by default). If you want to adjust this threshold then you can do so by setting `$config['uptime_warning']` in config.php. The value must be in seconds. +#### Why do I not see all interfaces in the Overall traffic graph for a device? + +By default numerous interface types and interface descriptions are excluded from this graph. The excluded defailts are: + +```php +$config['device_traffic_iftype'][] = '/loopback/'; +$config['device_traffic_iftype'][] = '/tunnel/'; +$config['device_traffic_iftype'][] = '/virtual/'; +$config['device_traffic_iftype'][] = '/mpls/'; +$config['device_traffic_iftype'][] = '/ieee8023adLag/'; +$config['device_traffic_iftype'][] = '/l2vlan/'; +$config['device_traffic_iftype'][] = '/ppp/'; + +$config['device_traffic_descr'][] = '/loopback/'; +$config['device_traffic_descr'][] = '/vlan/'; +$config['device_traffic_descr'][] = '/tunnel/'; +$config['device_traffic_descr'][] = '/bond/'; +$config['device_traffic_descr'][] = '/null/'; +$config['device_traffic_descr'][] = '/dummy/'; +``` + +If you would like to re-include l2vlan interfaces for instance, you first need to `unset` the config array and set your options: + +```php +unset($config['device_traffic_iftype']); +$config['device_traffic_iftype'][] = '/loopback/'; +$config['device_traffic_iftype'][] = '/tunnel/'; +$config['device_traffic_iftype'][] = '/virtual/'; +$config['device_traffic_iftype'][] = '/mpls/'; +$config['device_traffic_iftype'][] = '/ieee8023adLag/'; +$config['device_traffic_iftype'][] = '/ppp/'; +``` + #### How do I add support for a new OS? The easiest way to show you how to do that is to link to an existing pull request that has been merged in on [GitHub](https://github.com/librenms/librenms/pull/352/files) From f4bbba1b7d11e661221500a47014aea03e1fb7d4 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sun, 2 Oct 2016 08:28:22 +0100 Subject: [PATCH 03/10] fix: Updated edit snmp to set default poller_group (#4694) --- html/pages/device/edit/snmp.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/pages/device/edit/snmp.inc.php b/html/pages/device/edit/snmp.inc.php index d7a8a21e26..f4dcaa75fd 100644 --- a/html/pages/device/edit/snmp.inc.php +++ b/html/pages/device/edit/snmp.inc.php @@ -8,7 +8,7 @@ if ($_POST['editing']) { $port = $_POST['port'] ? mres($_POST['port']) : $config['snmp']['port']; $timeout = mres($_POST['timeout']); $retries = mres($_POST['retries']); - $poller_group = mres($_POST['poller_group']); + $poller_group = isset($_POST['poller_group']) ? mres($_POST['poller_group']) : 0; $port_assoc_mode = mres($_POST['port_assoc_mode']); $max_repeaters = mres($_POST['max_repeaters']); $v3 = array( From 0f417a30fab3e604d6c6b6c5a4d24e4cc70df91a Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sun, 2 Oct 2016 08:36:51 +0100 Subject: [PATCH 04/10] doc: Added clarity on using addhost with communities and special chars (#4693) --- doc/Support/FAQ.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/Support/FAQ.md b/doc/Support/FAQ.md index 6dc97884d3..d32be9e891 100644 --- a/doc/Support/FAQ.md +++ b/doc/Support/FAQ.md @@ -44,6 +44,8 @@ You have two options for adding a new device into LibreNMS. ./addhost.php [community] [v1|v2c] [port] [udp|udp6|tcp|tcp6] ``` +> Please note that if the community contains special characters such as `$` then you will need to wrap it in `'`. I.e: `'Pa$$w0rd'`. + 2. Using the web interface, go to Devices and then Add Device. Enter the details required for the device that you want to add and then click 'Add Host'. #### How do I get help? From 44f8fd333238d8c5fed6e506252af2677b2fcc44 Mon Sep 17 00:00:00 2001 From: Ryan Gibbons Date: Sun, 2 Oct 2016 02:41:48 -0500 Subject: [PATCH 05/10] doc: Include PHP Install instructions for MySQL app * Include php install instructions for MySQL This step is skimmed over frequently, by including the code blocks I'm hoping to make this step more noticeable. * I agree to the conditions of the Contributor Agreement contained in doc/General/Contributing.md. --- AUTHORS.md | 1 + doc/Extensions/Applications.md | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/AUTHORS.md b/AUTHORS.md index 70b46bf4a8..66656de978 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -135,6 +135,7 @@ LibreNMS contributors: - Florent Bruchez (ftbz) - Bartosz Radwan (bartoszradwan) - Kate Gerry (kate66) +- Ryan Gibbons (rtgibbons) [1]: http://observium.org/ "Observium web site" Observium was written by: diff --git a/doc/Extensions/Applications.md b/doc/Extensions/Applications.md index 94ec4b8993..c344287da8 100644 --- a/doc/Extensions/Applications.md +++ b/doc/Extensions/Applications.md @@ -130,6 +130,16 @@ extend memcached /etc/snmp/memcached The MySQL script requires PHP-CLI and the PHP MySQL extension, so please verify those are installed. +CentOS +``` +yum install php-cli php-mysql +``` + +Debian +``` +apt-get install php5-cli php5-mysql +``` + Unlike most other scripts, the MySQL script requires a configuration file `/usr/lib/check_mk_agent/local/mysql.cnf` with following content: ```php From 609ded49fa614af01e2b9e9e6fe9a0e11568d319 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sun, 2 Oct 2016 13:03:29 +0100 Subject: [PATCH 06/10] Updated changelog for 201609 release (#4699) --- doc/General/Changelog.md | 147 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/doc/General/Changelog.md b/doc/General/Changelog.md index e5f4d3606d..b960c2395c 100644 --- a/doc/General/Changelog.md +++ b/doc/General/Changelog.md @@ -1,4 +1,151 @@ source: General/Changelog.md +## Release: 201609 +*September 2016* + +#### Features +* Added alerts output to capture system ([#4574](https://github.com/librenms/librenms/issues/4574)) +* Add support for ups-apcups via snmp +* Add snmpsim to Travis automated testing. Update to check new setting for true and isset +* use snmpsim for testing fallback feature so we don't have to run snmpsim on devel computers, should be adequate for now ./scripts/pre-commit.php -u -snmpsim will start an snmpsimd.py process automatically +* Improved readability for snmp debug output +* Add last changed, connected, and mtu to all ports data +* Add temp & state sensors to Riverbed +* Added support for all OS tests +* Added Runtime support for APC ups +* Capture device troubleshooting info (discovery, poller, snmpwalk) +* Add temp & state sensors to Riverbed +* Add more state sensors to Dell iDrac +* Allow scripts to be run from any working directory ([#4437](https://github.com/librenms/librenms/issues/4437)) +* New app: ups-nut ([#4386](https://github.com/librenms/librenms/issues/4386)) +* Added new discovery-wrapper.py script to replicate poller-wrapper.py ([#4351](https://github.com/librenms/librenms/issues/4351)) +* Extended graphing for sla - icmp-jitter [#4341](https://github.com/librenms/librenms/issues/4341) +* Added Cisco Stackwise Support [#4301](https://github.com/librenms/librenms/issues/4301) +* Add Cisco WAAS Optimized TCP Connections Graph ([#4645](https://github.com/librenms/librenms/issues/4645)) + +#### Bugfixes +* Toner nrg os capacity ([#4177](https://github.com/librenms/librenms/issues/4177)) +* Fixed swos detection [#4533](https://github.com/librenms/librenms/issues/4533) +* Updated edit snmp to set default poller_group ([#4694](https://github.com/librenms/librenms/issues/4694)) +* Fixed SQL query for bgpPeers check to remove stale sessions ([#4697](https://github.com/librenms/librenms/issues/4697)) +* Netonix version display ([#4672](https://github.com/librenms/librenms/issues/4672)) +* FreeBSD variants ([#4661](https://github.com/librenms/librenms/issues/4661)) +* unix-agent handling of reported time values from check_mk [#4652](https://github.com/librenms/librenms/issues/4652) +* Add checks for devices with no uptime over snmp [#4587](https://github.com/librenms/librenms/issues/4587) +* stop qnap discovery from running for every device +* Fixed the old port rrd migration code to work with new rrdtool functions ([#4616](https://github.com/librenms/librenms/issues/4616)) +* Run cleanup for ipmi sensor discovery ([#4582](https://github.com/librenms/librenms/issues/4582)) +* Numerous availability-map bug fixes +* AD auth stop alerts being generated +* Possible additional fix for non-terminating rrdtool processes. +* AD auth stop alerts being generated +* APC runtime graph missing in device>health>overview +* LibreNMS/Proc improvements Should fix sending rrdtool the quit command without a newline at the end. (not sure if this is an issue) +* Port ifLastChange polling now usable ([#4541](https://github.com/librenms/librenms/issues/4541)) +* brother toner levels ([#4526](https://github.com/librenms/librenms/issues/4526)) +* poweralert ups divisor +* Update Fortinet Logo +* Change CiscoSB devices to use ifEntry +* Disable refreshing on window resize when $no_refresh is set. +* Fix quota bills showing 0/0 for in/out ([#4462](https://github.com/librenms/librenms/issues/4462)) +* This removes stale entries in the mac_ipv4 table ([#4444](https://github.com/librenms/librenms/issues/4444)) +* Swos os discovery fixes [#3593](https://github.com/librenms/librenms/issues/3593) +* Vyos discovery fix [#4486](https://github.com/librenms/librenms/issues/4486) +* Toner descr that contain invalid characters [#4464](https://github.com/librenms/librenms/issues/4464) +* Alert statics not showing data +* Ubnt bad edgeswitch uptime [#4470](https://github.com/librenms/librenms/issues/4470) +* New installs would have multiple entries in dbSchema table ([#4460](https://github.com/librenms/librenms/issues/4460)) +* Force add now ignores all snmp queries +* Clean up errors in the webui ([#4438](https://github.com/librenms/librenms/issues/4438)) +* Reduce mib graph queries ([#4439](https://github.com/librenms/librenms/issues/4439)) +* Ports page includes disabled, ignored, and deleted ports ([#4419](https://github.com/librenms/librenms/issues/4419)) +* RRDTool call was always being done to check for local files ([#4427](https://github.com/librenms/librenms/issues/4427)) +* MikroTik OS detection [#3593](https://github.com/librenms/librenms/issues/3593) +* Added cisco886Va to bad_ifXEntry for cisco os ([#4374](https://github.com/librenms/librenms/issues/4374)) +* Stop irc bot crashing on .reload [#4353](https://github.com/librenms/librenms/issues/4353) +* Quanta blade switches are now being correctly detected as Quanta switches ([#4358](https://github.com/librenms/librenms/issues/4358)) +* Added options to make temperature graphs display y-axis correctly [#4350](https://github.com/librenms/librenms/issues/4350) +* Added options to make voltage graphs display y-axis correctly [#4326](https://github.com/librenms/librenms/issues/4326) +* Calling rrdtool_pipe_open() instead of rrdtool_initialize(); ([#4343](https://github.com/librenms/librenms/issues/4343)) +* Enterasys use ifname for port names [#3263](https://github.com/librenms/librenms/issues/3263) +* Ricoh/nrg toner levels [#4177](https://github.com/librenms/librenms/issues/4177) +* Availability map device box reverted to original size, fixes for device groups ([#4334](https://github.com/librenms/librenms/issues/4334)) +* Remove Cisco remote access stats graph transparency ([#4331](https://github.com/librenms/librenms/issues/4331)) +* Cisco remote access stats bugfix [#4293](https://github.com/librenms/librenms/issues/4293) ([#4309](https://github.com/librenms/librenms/issues/4309)) +* Added ability to force devices to use ifEntry instead of ifXEntry ([#4100](https://github.com/librenms/librenms/issues/4100)) +* Don’t add Cisco VSS sensors if VSS is not running [#4111](https://github.com/librenms/librenms/issues/4111) +* Always validate the default dashboard_id to make sure it still exists +* NRG Toner detection [#4250](https://github.com/librenms/librenms/issues/4250) +* Missing variable in services api call +* Added influxdb options to check-services.php + +#### Documentation +* Include PHP Install instructions for MySQL app +* Added FAQ for why interfaces are missing from overall traffic graphs ([#4696](https://github.com/librenms/librenms/issues/4696)) +* Updated Applications to clarify apache setup +* Update apache applications to detail testing and additional requirements.md +* Updated release doc with more information on stable / dev branches +* Corrected the rsyslog documentation to be compatible with logrotate +* Fixed centos snmp path +* Updated to include info on how to use git hook to validate code ([#4484](https://github.com/librenms/librenms/issues/4484)) +* Added info on how to perform unit testing +* Added faq to explain why devices show as warning ([#4449](https://github.com/librenms/librenms/issues/4449)) +* Standardize snmp extend script location to /etc/snmp/ ([#4418](https://github.com/librenms/librenms/issues/4418)) +* Added NFSen docs + update general config docs ([#4412](https://github.com/librenms/librenms/issues/4412)) +* Clarify install docs to run validate as root [#4286](https://github.com/librenms/librenms/issues/4286) +* Added example to alerting doc for using variables of similar name [#4264](https://github.com/librenms/librenms/issues/4264) +* Added docs + file changes to support creating new releases/changelog +* Update snmpd setup in Installation-Ubuntu-1604 docs [#4243](https://github.com/librenms/librenms/issues/4243) + +#### Refactoring +* Centralize MIB include directory specification ([#4603](https://github.com/librenms/librenms/issues/4603)) +* OS discovery files (a-z) +* F5 device discovery cleanup + test unit +* Remove external uses of GenGroupSQL() +* consolidate snmpcmd generation +* consolidate snmpcmd generation I needed to generate an snmpcmd for an upcoming PR, so I figured I'd save a little code duplication. +* Refactored new helper functions for case sensitivity [#4283](https://github.com/librenms/librenms/issues/4283) +* Final PSR2 cleanup +* Moved IRCBot class to LibreNMS namespace [#4246](https://github.com/librenms/librenms/issues/4246) +* Update code in /includes to be psr2 compliant [#4220](https://github.com/librenms/librenms/issues/4220) + +#### Devices +* Samsung Printer Discovery [#4251](https://github.com/librenms/librenms/issues/4251) ([#4258](https://github.com/librenms/librenms/issues/4258)) +* HP 1820 Discovery [#3933](https://github.com/librenms/librenms/issues/3933) ([#4259](https://github.com/librenms/librenms/issues/4259)) +* Added support for Cisco Callmanager +* Edge Core ES3528M - base support +* Added support for Cisco IPS ([#4561](https://github.com/librenms/librenms/issues/4561)) +* Added MGE detection +* Netonix switch data collection update +* Eaton PowerXpert +* Added Datacom Dbm Support +* Updated Edgerouter lite detection +* Added support for Cisco Callmanager +* Procurve 5400R series [#4375](https://github.com/librenms/librenms/issues/4375) +* hp online admin cpu and mem [#4327](https://github.com/librenms/librenms/issues/4327) +* Added support for Foundry Networks [#4311](https://github.com/librenms/librenms/issues/4311) +* Added Cisco Stackwise Support [#4301](https://github.com/librenms/librenms/issues/4301) +* Added support for PLANET Networking & Communication switches ([#4308](https://github.com/librenms/librenms/issues/4308)) +* Added support for Fujitsu Primergy switches [#4277](https://github.com/librenms/librenms/issues/4277) ([#4280](https://github.com/librenms/librenms/issues/4280)) +* Added support for Lanier printers [#4267](https://github.com/librenms/librenms/issues/4267) +* Added Temp and State support for EdgeSwitch OS [#4265](https://github.com/librenms/librenms/issues/4265) +* Added support for DDN Storage [#2737](https://github.com/librenms/librenms/issues/2737) ([#4261](https://github.com/librenms/librenms/issues/4261)) +* Improved support for UBNT EdgeSwitch OS [#4249](https://github.com/librenms/librenms/issues/4249) +* Improved support for Avaya VSP [#4237](https://github.com/librenms/librenms/issues/4237) +* Added support for macOS Sierra ([#4557](https://github.com/librenms/librenms/issues/4557)) +* Improve BDCOM detection ([#4329](https://github.com/librenms/librenms/issues/4329)) + +#### WebUI +* top devices enhancement [#4447](https://github.com/librenms/librenms/issues/4447) +* Individual devices now use bootgrid syslog ([#4584](https://github.com/librenms/librenms/issues/4584)) +* added amazon server icon +* Update all glyphicon to font awesome +* Relocate Alerts menu +* Updated force add option for addhost.php to be present in all instances ([#4428](https://github.com/librenms/librenms/issues/4428)) +* Add check to display make bill on port page only if billing is enabled ([#4361](https://github.com/librenms/librenms/issues/4361)) +* Added Pagination and server side search via Ajax to NTP ([#4330](https://github.com/librenms/librenms/issues/4330)) + +--- + ### August 2016 #### Bug fixes From 0856c5675e0b8ecf17b1fcc99df0d685fc3d92a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Drago=C8=99=20Vasiloi?= <3XTron@users.noreply.github.com> Date: Sun, 2 Oct 2016 15:05:20 +0300 Subject: [PATCH 07/10] fix missed key (#4698) --- doc/Extensions/Auto-Discovery.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Extensions/Auto-Discovery.md b/doc/Extensions/Auto-Discovery.md index e5aa9b3018..c4760b59b1 100644 --- a/doc/Extensions/Auto-Discovery.md +++ b/doc/Extensions/Auto-Discovery.md @@ -86,7 +86,7 @@ It's designed to scan through all of the subnets in your config or what you have to automatically add devices. An example of it's usage is: ```bash -./snmp-scan.php r 192.168.0.0/24 +./snmp-scan.php -r 192.168.0.0/24 ``` #### Discovering devices by IP From d712f4ca69af405167b4d3ad8aef2162b1415c4e Mon Sep 17 00:00:00 2001 From: FTBZ Date: Mon, 3 Oct 2016 18:33:23 +0200 Subject: [PATCH 08/10] Added Active GlobalProtect Tunnels graph to PANOS (#4654) feature: Added GlobalProtect sessions to PANOS --- .../graphs/device/panos_activetunnels.inc.php | 16 ++++++++++++++++ includes/definitions.inc.php | 5 +++++ includes/polling/os/panos.inc.php | 15 +++++++++++++++ sql-schema/141.sql | 1 + 4 files changed, 37 insertions(+) create mode 100644 html/includes/graphs/device/panos_activetunnels.inc.php create mode 100644 sql-schema/141.sql diff --git a/html/includes/graphs/device/panos_activetunnels.inc.php b/html/includes/graphs/device/panos_activetunnels.inc.php new file mode 100644 index 0000000000..4f7644a72d --- /dev/null +++ b/html/includes/graphs/device/panos_activetunnels.inc.php @@ -0,0 +1,16 @@ + $activetunnels, + ); + + $tags = compact('rrd_def'); + data_update($device, 'panos-activetunnels', $tags, $fields); + + $graphs['panos_activetunnels'] = true; +} diff --git a/sql-schema/141.sql b/sql-schema/141.sql new file mode 100644 index 0000000000..63aff0fbdb --- /dev/null +++ b/sql-schema/141.sql @@ -0,0 +1 @@ +INSERT INTO `graph_types`(`graph_type`, `graph_subtype`, `graph_section`, `graph_descr`, `graph_order`) VALUES ('device', 'panos_activetunnels', 'firewall', 'Active GlobalProtect Tunnels', ''); From c5177c26af78b3e8bf0fe0b7eb05aba15bafb112 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Mon, 3 Oct 2016 11:48:19 -0500 Subject: [PATCH 09/10] feature: validate.php: check poller and discovery status (#4663) --- includes/common.php | 2 +- validate.php | 155 +++++++++++++++++++++++++++----------------- 2 files changed, 97 insertions(+), 60 deletions(-) diff --git a/includes/common.php b/includes/common.php index f6c0d13ffb..b7229f43cb 100644 --- a/includes/common.php +++ b/includes/common.php @@ -1118,7 +1118,7 @@ function version_info($remote = true) $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'); + $output['netsnmp_ver'] = str_replace('version: ', '', rtrim(shell_exec($config['snmpget'].' --version 2>&1'))); return $output; }//end version_info() diff --git a/validate.php b/validate.php index 50e197dbbf..9f72f4453c 100755 --- a/validate.php +++ b/validate.php @@ -15,6 +15,9 @@ chdir(__DIR__); // cwd to the directory containing this script +require_once 'includes/defaults.inc.php'; +require_once 'includes/common.php'; + $options = getopt('m:h::'); if (isset($options['h'])) { @@ -35,20 +38,62 @@ if (isset($options['h'])) { exit; } -if (strstr(`php -ln config.php`, 'No syntax errors detected')) { - $first_line = `head -n1 config.php`; - $last_lines = explode(PHP_EOL, `tail -n2 config.php`); - if (substr($first_line, 0, 5) !== '' && $last_lines[1] == '') { - print_fail('config.php contains a new line at the end, please remove any whitespace at the end of the file and also remove ?>'); - } elseif ($last_lines[1] == '?>') { - print_warn("It looks like you have ?> at the end of config.php, it is suggested you remove this"); - } -} else { - print_fail('Syntax error in config.php'); +$console_color = new Console_Color2(); + +// critical config.php checks +if (!file_exists('config.php')) { + print_fail('config.php does not exist, please copy config.php.default to config.php'); + exit; } +$config_failed = false; +$syntax_check = `php -ln config.php`; +if (!str_contains($syntax_check, 'No syntax errors detected')) { + print_fail('Syntax error in config.php'); + echo $syntax_check; + $config_failed = true; +} + +$first_line = rtrim(`head -n1 config.php`); +if (!starts_with($first_line, '')) { + print_fail("Remove the ?> at the end of config.php"); + $config_failed = true; +} + +if ($config_failed) { + exit; +} + +// load config.php now +require_once 'config.php'; + +// make sure install_dir is set correctly, or the next includes will fail +if (!file_exists($config['install_dir'].'/config.php')) { + print_fail('$config[\'install_dir\'] is not set correctly. It should probably be set to: ' . getcwd()); + exit; +} + +// continue loading includes +require_once 'includes/definitions.inc.php'; +require_once 'includes/functions.php'; +require_once 'includes/alerts.inc.php'; + +$versions = version_info(); +$cur_sha = $versions['local_sha']; + +echo "==========================================================\n"; +echo "LibreNMS Version: $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"; +echo "==========================================================\n\n"; + // Check we are running this as the root user if (function_exists('posix_getpwuid')) { $userinfo = posix_getpwuid(posix_geteuid()); @@ -60,53 +105,10 @@ if ($username !== 'root') { print_fail("You need to run this script as root"); } -// load config.php now -require_once 'includes/defaults.inc.php'; -require_once 'config.php'; - -// make sure install_dir is set correctly, or the next includes will fail -if (!file_exists($config['install_dir'].'/config.php')) { - print_fail('$config[\'install_dir\'] is not set correctly. It should probably be set to: ' . getcwd()); - exit; -} - -// continue loading includes -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 "====================================\n"; -echo "Version info:\n"; -$cur_sha = $versions['local_sha']; if ($config['update_channel'] == 'master' && $cur_sha != $versions['github']['sha']) { $commit_date = new DateTime('@'.$versions['local_date'], new DateTimeZone(date_default_timezone_get())); - print_warn("Your install is out of date: $cur_sha " . $commit_date->format('(r)')); -} else { - echo "Commit SHA: $cur_sha\n"; + print_warn("Your install is out of date, last update: " . $commit_date->format('r')); } -if ($versions['local_branch'] != 'master') { - print_warn("Your local git branch is not master, this will prevent automatic updates."); -} - -// check for modified files -$modifiedcmd = 'git diff --name-only --exit-code'; -if ($username === 'root') { - $modifiedcmd = 'su '.$config['user'].' -c "'.$modifiedcmd.'"'; -} -exec($modifiedcmd, $cmdoutput, $code); -if ($code !== 0 && !empty($cmdoutput)) { - print_warn("Your local git contains modified files, this could prevent automatic updates.\nModified files:"); - echo(' ' . implode("\n ", $cmdoutput) . "\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"; -echo "====================================\n"; // Check php modules we use to make sure they are loaded $extensions = array('pcre','curl','session','snmp','mcrypt'); @@ -226,6 +228,41 @@ if (!function_exists('openssl_random_pseudo_bytes')) { } } +// check discovery last run +if (dbFetchCell('SELECT COUNT(`device_id`) FROM `devices` WHERE `last_discovered` IS NOT NULL') == 0) { + print_fail('Discovery has never run, check the cron job'); +} elseif (dbFetchCell("SELECT COUNT(`device_id`) FROM `devices` WHERE `last_discovered` <= DATE_ADD(NOW(), INTERVAL - 24 hours) AND `ignore` = 0 AND `disabled` = 0 AND `status` = 1") > 0) { + print_fail("Discovery has not run in the last 24 hours, check the cron job"); +} + +// check poller +if (dbFetchCell('SELECT COUNT(`device_id`) FROM `devices` WHERE `last_polled` IS NOT NULL') == 0) { + print_fail('The poller has never run, check the cron job'); +} elseif (dbFetchCell("SELECT COUNT(`device_id`) FROM `devices` WHERE `last_polled` <= DATE_ADD(NOW(), INTERVAL - 5 minute) AND `ignore` = 0 AND `disabled` = 0 AND `status` = 1") > 0) { + print_fail("The poller has not run in the last 5 minutes, check the cron job"); +} elseif (dbFetchCell("SELECT COUNT(`device_id`) FROM `devices` WHERE (`last_polled` <= DATE_ADD(NOW(), INTERVAL - 5 minute) OR `last_polled` IS NULL) AND `ignore` = 0 AND `disabled` = 0 AND `status` = 1") > 0) { + print_warn("Some devices have not been polled in the last 5 minutes, check your poll log"); +} + +if (dbFetchCell('SELECT COUNT(`device_id`) FROM `devices` WHERE last_polled_timetaken > 300 AND `ignore` = 0 AND `disabled` = 0 AND `status` = 1') > 0) { + print_fail("Some devices have not completed their polling run in 5 minutes, this will create gaps in data.\n Check your poll log and refer to http://docs.librenms.org/Support/Performance/"); +} + +if ($versions['local_branch'] != 'master') { + print_warn("Your local git branch is not master, this will prevent automatic updates."); +} + +// check for modified files +$modifiedcmd = 'git diff --name-only --exit-code'; +if ($username === 'root') { + $modifiedcmd = 'su '.$config['user'].' -c "'.$modifiedcmd.'"'; +} +exec($modifiedcmd, $cmdoutput, $code); +if ($code !== 0 && !empty($cmdoutput)) { + print_warn("Your local git contains modified files, this could prevent automatic updates.\nModified files:"); + echo(' ' . implode("\n ", $cmdoutput) . "\n"); +} + // Modules test $modules = explode(',', $options['m']); foreach ($modules as $module) { @@ -339,19 +376,19 @@ foreach ($modules as $module) { function print_ok($msg) { - echo "[OK] $msg\n"; + c_echo("[%gOK%n] $msg\n"); }//end print_ok() function print_fail($msg) { - echo "[FAIL] $msg\n"; + c_echo("[%RFAIL%n] $msg\n"); }//end print_fail() function print_warn($msg) { - echo "[WARN] $msg\n"; + c_echo("[%YWARN%n] $msg\n"); }//end print_warn() function check_rrdcached() From 5c761eb1c7697292dbd00163e74ddda0141f6a18 Mon Sep 17 00:00:00 2001 From: crcro Date: Mon, 3 Oct 2016 19:49:23 +0300 Subject: [PATCH 10/10] Updated toner discovery (#4637) --- includes/discovery/functions.inc.php | 65 ++++++++++++++++++++++++++++ includes/discovery/toner.inc.php | 63 +++++++-------------------- 2 files changed, 81 insertions(+), 47 deletions(-) diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 57fb44a872..7ef5227c76 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -891,3 +891,68 @@ function get_device_divisor($device, $serial, $sensor) } return $divisor; } + +/** + * @param $device + * @param $capacity_oid + * @return int + */ +function get_toner_capacity($device, $capacity_oid) +{ + if ($device['os'] == 'ricoh' || $device['os'] == 'nrg' || $device['os'] == 'lanier') { + $capacity = 100; + } else { + $capacity = snmp_get($device, $capacity_oid, '-Oqv'); + } + + return $capacity; +} + +/** + * @param $device + * @param $oid_value + * @param $oid_capacity + * @return float|int + */ +function get_toner_levels($device, $oid_value, $oid_capacity) +{ + if ($device['os'] == 'ricoh' || $device['os'] == 'nrg' || $device['os'] == 'lanier') { + if ($oid_value == '-3') { + $current = 50; + } elseif ($oid_value == '-100') { + $current = 0; + } else { + $current = ($oid_value / $oid_capacity * 100); + } + } elseif ($device['os'] == 'brother') { + if (str_contains($device['hardware'], 'NC-8600h')) { + switch ($oid_value) { + case '0': + $current = 0; + break; + case '-3': + $current = 50; + break; + } + } else { + switch ($oid_value) { + case '0': + $current = 100; + break; + case '1': + $current = 5; + break; + case '2': + $current = 0; + break; + case '3': + $current = 1; + break; + } + } + } else { + $current = ($oid_value / $oid_capacity * 100); + } + + return $current; +} diff --git a/includes/discovery/toner.inc.php b/includes/discovery/toner.inc.php index 15d8ec807e..049f81ff52 100644 --- a/includes/discovery/toner.inc.php +++ b/includes/discovery/toner.inc.php @@ -8,7 +8,7 @@ if ($device['os_group'] == 'printer') { $oids = trim(snmp_walk($device, 'SNMPv2-SMI::mib-2.43.11.1.1.2.1 ', '-OsqnU')); } - d_echo($oids."\n"); + d_echo($oids . "\n"); if ($oids) { echo 'Jetdirect '; @@ -17,60 +17,29 @@ if ($device['os_group'] == 'printer') { foreach (explode("\n", $oids) as $data) { $data = trim($data); if ($data) { - list($oid,$role) = explode(' ', $data); - $split_oid = explode('.', $oid); - $index = $split_oid[(count($split_oid) - 1)]; + list($oid, $role) = explode(' ', $data); + $split_oid = explode('.', $oid); + $index = $split_oid[(count($split_oid) - 1)]; if (is_numeric($role)) { //ricoh using private oids to expose toner levels if ($os == 'ricoh' || $os == 'nrg' || $os == 'lanier') { $toner_oid = ".1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.$index"; $descr_oid = ".1.3.6.1.4.1.367.3.2.1.2.24.1.1.3.$index"; + $capacity_oid = ''; } else { - $toner_oid = ".1.3.6.1.2.1.43.11.1.1.9.1.$index"; - $descr_oid = ".1.3.6.1.2.1.43.11.1.1.6.1.$index"; + $toner_oid = ".1.3.6.1.2.1.43.11.1.1.9.1.$index"; + $descr_oid = ".1.3.6.1.2.1.43.11.1.1.6.1.$index"; $capacity_oid = ".1.3.6.1.2.1.43.11.1.1.8.1.$index"; } $descr = trim(str_replace("\n", '', preg_replace('/[^ \w]+/', '', snmp_get($device, $descr_oid, '-Oqv')))); if ($descr != '') { - $current = snmp_get($device, $toner_oid, '-Oqv'); + $oid_toner = snmp_get($device, $toner_oid, '-Oqv'); + $oid_capacity = snmp_get($device, $capacity_oid, '-Oqv'); - //ricoh private mibs returns values as percent, no capacity is disclosed as it is not needed - if ($os == 'ricoh' || $os == 'nrg' || $os == 'lanier') { - $capacity = 100; - } else { - $capacity = snmp_get($device, $capacity_oid, '-Oqv'); - } - - //fix for ricoh devices returning garbage and devices returning percentage - if ($os == 'ricoh' || $os == 'nrg' || $os == 'lanier') { - if ($current == '-3') { - $current = 50; - } elseif ($current == '-100') { - $current = 0; - } else { - $current = ($current / $capacity * 100); - } - } elseif ($os == 'brother') { - switch ($current) { - case '0': - $current = 100; - break; - case '1': - $current = 5; - break; - case '2': - $current = 0; - break; - case '3': - $current = 1; - break; - } - } else { - //normal devices returning toner values - $current = ($current / $capacity * 100); - } + $capacity = get_toner_capacity($device, $oid_capacity); + $current = get_toner_levels($device, $oid_toner, $oid_capacity); $type = 'jetdirect'; if (isHexString($descr)) { @@ -80,18 +49,18 @@ if ($device['os_group'] == 'printer') { discover_toner($valid_toner, $device, $toner_oid, $index, $type, $descr, $capacity_oid, $capacity, $current); } } - }//end if - }//end foreach -}//end if + } + } +} // Delete removed toners d_echo("\n Checking ... \n"); d_echo($valid_toner); -$sql = "SELECT * FROM toner WHERE device_id = '".$device['device_id']."'"; +$sql = "SELECT * FROM toner WHERE device_id = '" . $device['device_id'] . "'"; foreach (dbFetchRows($sql) as $test_toner) { $toner_index = $test_toner['toner_index']; - $toner_type = $test_toner['toner_type']; + $toner_type = $test_toner['toner_type']; if (!$valid_toner[$toner_type][$toner_index]) { echo '-'; dbDelete('toner', '`toner_id` = ?', array($test_toner['toner_id']));