From 63cdd8210d5a731f91692bceca94073545897764 Mon Sep 17 00:00:00 2001 From: Mickael Marchand Date: Thu, 25 Aug 2016 12:55:27 +0200 Subject: [PATCH 01/69] fix ifName randomly defined, breaking influxdb updates (#4202) --- includes/polling/ports.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index 8cfaaa16ca..4855fdc120 100644 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -641,6 +641,7 @@ foreach ($ports as $port) { } $port_descr_type = $port['port_descr_type']; + $ifName = $port['ifName']; $tags = compact('ifName', 'port_descr_type', 'rrd_name', 'rrd_def'); rrdtool_data_update($device, 'ports', $tags, $fields); From f119a7c362586798dcce0d74bba3af9832abf2f0 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Thu, 25 Aug 2016 09:42:18 -0500 Subject: [PATCH 02/69] Only push the toc down, not the content the toc is on top when the header switches to two lines, so we only need to push that down. --- doc/librenms.css | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/librenms.css b/doc/librenms.css index fea7803bb8..ba686743f6 100644 --- a/doc/librenms.css +++ b/doc/librenms.css @@ -8,10 +8,9 @@ body { overflow-x: hidden !important; } -/* pushdown the content when the header flows to two lines */ -.navbar-fixed-top { - top: -70px; - position: relative; +/* push down the content when the header flows to two lines */ +.bs-sidebar { + margin-top: 45px; } /* hide the menu called hidden, used to generate unlinked docs */ From 9f1930a81ee76afe0945ba160453356d7b4a0b01 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Fri, 26 Aug 2016 00:40:11 +0100 Subject: [PATCH 03/69] More more docs (#4197) * Updated docs + some small code changes * Added validating code doc for developers * Doc updates * Updates and improvements --- .gitignore | 1 + .travis.yml | 2 +- composer.json | 11 +++++-- config.php.default | 19 +++++------- doc/Developing/Using-Git.md | 18 +++++------- doc/Developing/Validating-Code.md | 28 ++++++++++++++++++ doc/Extensions/Device-Groups.md | 8 ++--- doc/Extensions/Globe-Frontpage.md | 24 ++++----------- doc/Extensions/Memcached.md | 3 ++ doc/Extensions/Oxidized.md | 4 +-- doc/Extensions/Plugin-System.md | 2 ++ doc/General/Acknowledgement.md | 2 -- doc/General/Contributing.md | 6 ++-- doc/General/Credits.md | 6 ---- doc/General/Updating.md | 6 ++-- doc/General/Welcome-to-Observium-users.md | 2 -- doc/Support/Discovery Support.md | 33 +++++++++++---------- doc/Support/Install Validation.md | 12 ++++---- doc/Support/Poller Support.md | 10 ++++--- doc/Support/Support-New-OS.md | 2 -- html/install.php | 3 -- librenms.cron | 1 + librenms.nonroot.cron | 4 +++ scripts/pre-commit.php | 36 +++++++++++++++++++++++ 24 files changed, 145 insertions(+), 98 deletions(-) create mode 100644 doc/Developing/Validating-Code.md create mode 100755 scripts/pre-commit.php diff --git a/.gitignore b/.gitignore index 8025a1d7e0..2f7c08a528 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ nbproject patches rrd /vendor +composer.phar diff --git a/.travis.yml b/.travis.yml index 7a27f95828..7f5496165f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,5 +46,5 @@ after_success: script: - if [[ $PHP_L == 1 ]]; then find . -path './vendor' -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1; fi - if [[ $PHP_L_OLD == 1 ]]; then find . -regextype posix-extended -regex "\./(lib/influxdb-php|vendor)" -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1; fi - - if [[ $PHP_CS == 1 ]]; then vendor/bin/phpcs -n -p --colors --extensions=php --standard=PSR2 --ignore=html/lib/* html; fi + - if [[ $PHP_CS == 1 ]]; then vendor/bin/phpcs -n -p --colors --extensions=php --standard=PSR2 --ignore=html/lib/* --ignore=html/plugins/* html; fi - phpunit diff --git a/composer.json b/composer.json index 2dd4acf45c..098e4829b3 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,10 @@ { - "require": { - "squizlabs/php_codesniffer": "*" - } + "require": { + "squizlabs/php_codesniffer": "*" + }, + "require-dev": { + "squizlabs/php_codesniffer": "*", + "phpunit/phpunit": "4.*" + } } + diff --git a/config.php.default b/config.php.default index c8ac44a2bf..3332ccb7d9 100755 --- a/config.php.default +++ b/config.php.default @@ -9,21 +9,13 @@ $config['db_pass'] = 'PASSWORD'; $config['db_name'] = 'librenms'; $config['db']['extension'] = 'mysqli';// mysql or mysqli -### Memcached config - We use this to store realtime usage -$config['memcached']['enable'] = FALSE; -$config['memcached']['host'] = 'localhost'; -$config['memcached']['port'] = 11211; - // This is the user LibreNMS will run as //Please ensure this user is created and has the correct permissions to your install $config['user'] = 'librenms'; -### Locations - it is recommended to keep the default -#$config['install_dir'] = "/opt/librenms"; - ### This should *only* be set if you want to *force* a particular hostname/port ### It will prevent the web interface being usable form any other hostname -#$config['base_url'] = "http://librenms.company.com"; +$config['base_url'] = "/"; ### Enable this to use rrdcached. Be sure rrd_dir is within the rrdcached dir ### and that your web server has permission to talk to rrdcached. @@ -41,9 +33,6 @@ $config['auth_mechanism'] = "mysql"; # default, other options: ldap, http-auth #$config['nets'][] = "172.16.0.0/12"; #$config['nets'][] = "192.168.0.0/16"; -# following is necessary for poller-wrapper -# poller-wrapper is released public domain -$config['poller-wrapper']['alerter'] = FALSE; # Uncomment the next line to disable daily updates #$config['update'] = 0; @@ -55,3 +44,9 @@ $config['rrd_purge'] = 0; # Set default port association mode for new devices (default: ifIndex) #$config['default_port_association_mode'] = 'ifIndex'; + +# Enable the in-built billing extension +$config['enable_billing'] = 1; + +# Enable the in-built services support (Nagios plugins) +$config['show_services'] = 1; diff --git a/doc/Developing/Using-Git.md b/doc/Developing/Using-Git.md index 35738285e6..c0dddd3a9e 100644 --- a/doc/Developing/Using-Git.md +++ b/doc/Developing/Using-Git.md @@ -80,11 +80,13 @@ pull request then commit away. ```bash git add path/to/new/files/or/folders git commit -a -m 'Added feature to do X, Y and Z' -git checkout master +git push origin issue-123 +``` + +If you need to rebase against master then you can do this with: + +```bash git pull upstream master -git push origin master -git checkout issue-123 -git pull origin master git push origin issue-123 ``` @@ -97,13 +99,7 @@ Now you will be ready to submit a pull request from within GitHub. To do this, g repo. Now select the branch you have just been working on (issue-123) from the drop down to the left and then click 'Pull Request'. Fill in the details to describe the work you have done and click 'Create pull request'. -Thanks for your first pull request :) Now, that might have been a simple update, if things get a bit more complicated -then you will need to break down your pull request into separate commits (still a single pull request). This is usually -done when: - -- You want to add / update MIBS. Do this in a separate commit including the link to where you got them from. -- You are adding say 3 related features in one go, try and break them down into 3 separate commits. -- Icons for new OS support need to be added as a separate commit including a link to where you got the logo from. +Thanks for your first pull request :) Ok, that should get you started on the contributing path. If you have any other questions then stop by our IRC Channel on Freenode ##librenms. diff --git a/doc/Developing/Validating-Code.md b/doc/Developing/Validating-Code.md new file mode 100644 index 0000000000..885c738f82 --- /dev/null +++ b/doc/Developing/Validating-Code.md @@ -0,0 +1,28 @@ +source: Developing/Validating-Code.md + +As part of the pull request process with GitHub we run some automated build tests to ensure that +the code is error free, standards [compliant](http://docs.librenms.org/Developing/Code-Guidelines/) +and our test suite builds successfully. + +Rather than submit a pull request and wait for the results, you can run these checks yourself to ensure +a more seamless merge. + +> All of these commands should be run from within the librenms directory and can be run as the librenms user +unless otherwise noted. + +Install composer (you can skip this if composer is already installed). + +`curl -sS https://getcomposer.org/installer | php` + +Composer will now be installed into /opt/librenms/composer.phar. + +Now install the dependencies we require: + +`composer install` + +Once composer is installed you can now run the code validation script: + +`./scripts/pre-commit.php` + +If you see `Tests ok, submit away :)` then all is well. If you see other output then it should contain +what you need to resolve the issues and re-test. diff --git a/doc/Extensions/Device-Groups.md b/doc/Extensions/Device-Groups.md index ae2ebe8982..cf10427a2e 100644 --- a/doc/Extensions/Device-Groups.md +++ b/doc/Extensions/Device-Groups.md @@ -9,12 +9,12 @@ Patterns work in the same was as Entities within the alerting system, the format as __tablename.columnname__. If you are ensure of what the entity is you want then have a browse around inside MySQL using `show tables` and `desc `. As a working example and a common question, let's assume you want to group devices by hostname. If you hostname format is dcX.[devicetype].example.com. You would use the pattern -devices.hostname. Select the condition which in this case would Like and then enter `dc1\..*\.example.com`. This would then match dc1.sw01.example.com, dc1.rtr01.example.com but not +`devices.hostname`. Select the condition which in this case would be `Like` and then enter `dc1\..*\.example.com`. This would then match dc1.sw01.example.com, dc1.rtr01.example.com but not dc2.sw01.example.com. #### Wildcards -As with alerts, the `Like` operation allows RegExp. +As with alerts, the `Like` operation allows MySQL Regular expressions. A list of common entities is maintained in our [Alerting docs](http://docs.librenms.org/Extensions/Alerting/#entities). @@ -25,7 +25,7 @@ Please see our [Alerting docs](http://docs.librenms.org/Extensions/Alerting/#syn ### Connection If you only want to group based on one pattern then select And. If however you want to build a group based on multiple patterns then you can build a SQL like -query using And / Or. As an example, we want to base our group on the devices hostname AND it's type. Use the pattern as before, devices.hostname, select the condition which in this case would Like and then enter dc1.@.example.com then click And. Now enter devices.type in the pattern, select Equals and enter firewall. This would then match dc1.fw01.example.com but not dc1.sw01.example.com as that is a network type. +query using And / Or. As an example, we want to base our group on the devices hostname AND it's type. Use the pattern as before, `devices.hostname`, select the condition which in this case would be `Like` and then enter `dc1.@.example.com` then click And. Now enter `devices.type` in the pattern, select `Equals` and enter `firewall`. This would then match dc1.fw01.example.com but not dc1.sw01.example.com as that is a network type. You can now select this group from the Devices -> All Devices link in the navigation at the top. You can also use the group to map alert rules to by creating an alert mapping -Overview -> Alerts -> Rule Mapping. +`Overview -> Alerts -> Rule Mapping`. diff --git a/doc/Extensions/Globe-Frontpage.md b/doc/Extensions/Globe-Frontpage.md index c9f391bfd5..74b29df279 100644 --- a/doc/Extensions/Globe-Frontpage.md +++ b/doc/Extensions/Globe-Frontpage.md @@ -1,23 +1,21 @@ source: Extensions/Globe-Frontpage.md # Globe Frontpage Configuration -LibreNMS comes with a configurable geochart based frontpage to visualize where your gear is located geographically. +LibreNMS comes with a configurable geochart based widget to visualize where your equipment is located geographically. -### Experimental map +### World Map -An new experimental map is available, this requires you to have properly formatted addresses in sysLocation or sysLocation override. As part of the standard poller these addresses will be Geocoded by Google and stored in the database. To enable this please set the following config: +An new map is available, this requires you to have properly formatted addresses in sysLocation or sysLocation override. As part of the standard poller these addresses will be Geocoded by Google and stored in the database. To enable this please set the following config: ```php -$config['front_page'] = "pages/front/map.php"; $config['geoloc']['latlng'] = true; $config['geoloc']['engine'] = "google";//Only one available at present ``` Location resolution happens as follows (when `$config['geoloc']['latlng'] == true;`): - 1. if `device['location']` contains `[lat, lng]` (note the square brackets), that is used - 1. if there is a location overide in the `locations` table where `locations.location == device['location']`, that is used - * currently, no web UI - 1. attempt to resolve lat, lng using `$config['geoloc']['engine']` + 1. If `device['location']` contains `[lat, lng]` (note the square brackets), that is used + 1. If there is a location overide for the device in the WebUI and it contains `[lat, lng]` (note the square brackets), that is used. + 1. Attempt to resolve lat, lng using `$config['geoloc']['engine']` We have two current mapping engines available: @@ -56,13 +54,3 @@ $config['mapael']['default_zoom'] = 20; ``` A list of maps can be found in html/js/maps/ or html/js/mapael-maps/. - -### Standard Globe map - -To enable it, set `$config['front_page'] = "pages/front/globe.php";` in your `config.php`. - -You can use any of these config-parameters to adjust some aspects of it: - -- `$config['frontpage_globe']['markers']` is used to change what is being shown on the Markers of the map. It can be either `devices` or `ports` -- `$config['frontpage_globe']['region']` defines the Region to chart. Any region supported by Google's GeoChart API is allowed (https://developers.google.com/chart/interactive/docs/gallery/geochart#continent-hierarchy-and-codes) -- `$config['frontpage_globe']['resolution']` can be 'countries', 'provinces' or 'metros' (latter two are mostly US only due to google-limits). diff --git a/doc/Extensions/Memcached.md b/doc/Extensions/Memcached.md index 5b852f7d4c..036fd6259d 100644 --- a/doc/Extensions/Memcached.md +++ b/doc/Extensions/Memcached.md @@ -12,6 +12,9 @@ $config['memcached']['port'] = 11211; ``` By default values are kept for 4 Minutes inside the memcached, you can adjust this retention time by modifying the `$config['memcached']['ttl']` value to any desired amount of seconds. + +> This means that you can see what appears to be stale data for up to 4 minutes. If you edit an alert rule for example then those changes may not show immediately. + It's strongly discouraged to set this above `300` (5 Minutes) to avoid interference with the polling, discovery and alerting processes. If you use the Distributed Poller, you can point this to the same memcached instance. However a local memcached will perform better in any case. diff --git a/doc/Extensions/Oxidized.md b/doc/Extensions/Oxidized.md index 29161206c9..cba3b94be5 100644 --- a/doc/Extensions/Oxidized.md +++ b/doc/Extensions/Oxidized.md @@ -57,13 +57,13 @@ LibreNMS is able to reload the Oxidized list of nodes, each time a device is add To do so, edit the option in Global Settings>External Settings>Oxidized Integration or add the following to your config.php. ```php -$config['oxidized']['reload_nodes'] = TRUE; +$config['oxidized']['reload_nodes'] = true; ``` #### Using Groups -To return a group to Oxidized you can do this by matching a regex for either hostname, os or location. The order is hostname is matched first, if nothing is found then os is tried and then location is attempted. +To return a group to Oxidized you can do this by matching a regex for either `hostname`, `os` or `location`. The order is `hostname` is matched first, if nothing is found then `os` is tried and then `location` is attempted. The first match found will be used. To match on the device hostnames that contain 'lon-sw' or if the location contains 'London' then you would place the following within config.php: ```php diff --git a/doc/Extensions/Plugin-System.md b/doc/Extensions/Plugin-System.md index 446422fc6c..b905f8c32d 100644 --- a/doc/Extensions/Plugin-System.md +++ b/doc/Extensions/Plugin-System.md @@ -1,6 +1,8 @@ source: Extensions/Plugin-System.md # Developing for the Plugin System +> This will most likely be deprecated in favour of adding the possible extensions to the core code base. + This documentation will hopefully give you a basis for how to write a plugin for LibreNMS. A test plugin is available on GitHub: https://github.com/laf/Test diff --git a/doc/General/Acknowledgement.md b/doc/General/Acknowledgement.md index 67fb3479ba..d8b80bffcd 100644 --- a/doc/General/Acknowledgement.md +++ b/doc/General/Acknowledgement.md @@ -35,5 +35,3 @@ LibreNMS 3rd party acknowledgements - html/graph-realtime.php: BSD (original?) - html/includes/collectd/: GPLv2 only - overLIB (html/js/overlib_mini.js): modified Artistic 1.0? - - scripts/*/mysql: GPLv2 only - - check_mk (scripts/check_mk*): GPLv2 diff --git a/doc/General/Contributing.md b/doc/General/Contributing.md index b875441353..7268c2c42d 100644 --- a/doc/General/Contributing.md +++ b/doc/General/Contributing.md @@ -34,9 +34,9 @@ To agree with these assertions, please submit a GitHub pull request against [AUTHORS.md][5], adding or altering a **single line** *containing your name, email address, and GitHub user id* in the file (so that it can be matched to your commits), and stating in the *commit log* (not the pull request text): + ``` - I agree to the conditions of the Contributor Agreement - contained in doc/General/Contributing.md. +I agree to the conditions of the Contributor Agreement contained in doc/General/Contributing.md. ``` Local patches @@ -61,8 +61,6 @@ the package information to the header. ``` - * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your diff --git a/doc/General/Credits.md b/doc/General/Credits.md index fc0a05e95e..253c68ac4f 100644 --- a/doc/General/Credits.md +++ b/doc/General/Credits.md @@ -50,9 +50,3 @@ Other components (needs details filled in): - html/includes/collectd/: GPLv2 only - overLIB (html/js/overlib_mini.js): modified Artistic 1.0? - -- scripts/*/mysql: GPLv2 only - -- check_mk (scripts/observium_agent*): GPLv2 - -- qTip (html/css/jquery.qtip.min.css and html/js/qtip/jquery.qtip.min.js): GPLv2 diff --git a/doc/General/Updating.md b/doc/General/Updating.md index 9c56e32625..fcffdc9b5a 100644 --- a/doc/General/Updating.md +++ b/doc/General/Updating.md @@ -4,7 +4,7 @@ source: General/Updating.md If you would like to perform a manual update then you can do this by running the following command as the **librenms** user: - ./daily.sh +`./daily.sh` This will update both the core LibreNMS files but also update the database structure if updates are available. @@ -13,12 +13,12 @@ structure if updates are available. LibreNMS follows the master branch on github for daily updates. You can change to the monthly releases by setting: - $config['update_channel'] = 'release'; +`$config['update_channel'] = 'release';` ## Disabling automatic updates ## LibreNMS by default performs updates on a daily basis. This can be disabled by ensuring: - $config['update'] = 0; +`$config['update'] = 0;` is no longer commented out. diff --git a/doc/General/Welcome-to-Observium-users.md b/doc/General/Welcome-to-Observium-users.md index 89874c88b8..b374833e4a 100644 --- a/doc/General/Welcome-to-Observium-users.md +++ b/doc/General/Welcome-to-Observium-users.md @@ -59,8 +59,6 @@ Reasons why you might want to use LibreNMS instead of Observium: "LibreNMS README" [3]: http://fisheye.observium.org/rdiff/Observium?csid=3251&u&N "Link to Observium license change" -[4]: https://github.com/librenms/librenms/blob/master/doc/General/Roadmap.md -"LibreNMS ROADMAP" [5]: https://github.com/librenms/librenms/blob/master/LICENSE.txt "LibreNMS copy of GPL v3" [6]: http://www.gnu.org/philosophy/free-sw.html diff --git a/doc/Support/Discovery Support.md b/doc/Support/Discovery Support.md index 1fc6ae4c9c..3086a25b9a 100644 --- a/doc/Support/Discovery Support.md +++ b/doc/Support/Discovery Support.md @@ -6,18 +6,21 @@ This document will explain how to use discovery.php to debug issues or manually #### Command options ```bash -h | Poll single device - -h odd Poll odd numbered devices (same as -i 2 -n 0) - -h even Poll even numbered devices (same as -i 2 -n 1) - -h all Poll all devices - -h new Poll all devices that have not had a discovery run before +-h odd Poll odd numbered devices (same as -i 2 -n 0) +-h even Poll even numbered devices (same as -i 2 -n 1) +-h all Poll all devices +-h new Poll all devices that have not had a discovery run before +--os Poll devices only with specified operating system +--type Poll devices only with specified type +-i -n Poll as instance of + Instances start at 0. 0-3 for -n 4 - -i -n Poll as instance of - Instances start at 0. 0-3 for -n 4 +Debugging and testing options: +-d Enable debugging output +-v Enable verbose debugging output +-m Specify single module to be run - Debugging and testing options: - -d Enable debugging output - -m Specify single module to be run ``` `-h` Use this to specify a device via either id or hostname (including wildcard using *). You can also specify odd and @@ -26,15 +29,16 @@ new will poll only those devices that have recently been added or have been sele `-i` This can be used to stagger the discovery process. -`-d` Enables debugging output (verbose output) so that you can see what is happening during a discovery run. This includes -things like rrd updates, SQL queries and response from snmp. +`-d` Enables debugging output (verbose output but with most sensitive data masked) so that you can see what is happening during a discovery run. This includes things like rrd updates, SQL queries and response from snmp. + +`-v` Enables verbose debugging output with all data in tact. `-m` This enables you to specify the module you want to run for discovery. #### Discovery config These are the default discovery config items. You can globally disable a module by setting it to 0. If you just want to -disable it for one device then you can do this within the WebUI -> Settings -> Modules. +disable it for one device then you can do this within the WebUI -> Device -> Settings -> Modules. ```php $config['discovery_modules']['os'] = 1; @@ -160,15 +164,12 @@ Multiple Modules ./discovery.php -h localhost -m ports,entity-physical -d ``` -It is then advisable to sanitise the output before pasting it somewhere as the debug output will contain snmp details -amongst other items including port descriptions. +Using `-d` shouldn't output much sensitive information, `-v` will so it is then advisable to sanitise the output before pasting it somewhere as the debug output will contain snmp details amongst other items including port descriptions. The output will contain: DB Updates -RRD Updates - SNMP Response ### SNMP Scan diff --git a/doc/Support/Install Validation.md b/doc/Support/Install Validation.md index 248ec8d0d1..67eeb9b6c7 100644 --- a/doc/Support/Install Validation.md +++ b/doc/Support/Install Validation.md @@ -2,7 +2,7 @@ source: Install Validation.md Install validation ------------------ -With a lot of configuration possibilities and at present the only way to do this being by manually editing config.php then it's not +With a lot of configuration possibilities, manually editing config.php means it's not uncommon that mistakes get made. It's also impossible to validate user input in config.php when you're just using a text editor :) So, to try and help with some of the general issues people come across we've put together a simple validation tool which at present will: @@ -22,10 +22,12 @@ Optionally you can also pass -m and a module name for that to be tested. Current - dist-poller - This will test your distributed poller configuration. - rrdcheck - This will test your rrd files to see if they are unreadable or corrupted (source of broken graphs). -Output, this is color coded to try and make things a little easier: +You can run validate.php as `root` by executing `./validate.php` within your install directory. -Green OK - This is a good thing, you can skip over these :) +The output will provide you either a clean bill of health or a list of things you need to fix: -Yellow WARN - You probably want to check this out. +OK - This is a good thing, you can skip over these :) -Red FAIL - This is going to need your attention! +WARN - You probably want to check this out. + +FAIL - This is going to need your attention! diff --git a/doc/Support/Poller Support.md b/doc/Support/Poller Support.md index 591d789623..a906b246ef 100644 --- a/doc/Support/Poller Support.md +++ b/doc/Support/Poller Support.md @@ -17,7 +17,9 @@ This document will explain how to use poller.php to debug issues or manually run Debugging and testing options: -r Do not create or update RRDs +-f Do not insert data into InfluxDB -d Enable debugging output +-v Enable verbose debugging output -m Specify module(s) to be run ``` @@ -28,8 +30,9 @@ even. all will run poller against all devices. `-r` This option will suppress the creation or update of RRD files. -`-d` Enables debugging output (verbose output) so that you can see what is happening during a poller run. This includes -things like rrd updates, SQL queries and response from snmp. +`-d` Enables debugging output (verbose output but with most sensitive data masked) so that you can see what is happening during a poller run. This includes things like rrd updates, SQL queries and response from snmp. + +`-v` Enables verbose debugging output with all data in tact. `-m` This enables you to specify the module you want to run for poller. @@ -170,8 +173,7 @@ Multiple Modules ./poller.php -h localhost -m ports,entity-physical -d ``` -It is then advisable to sanitise the output before pasting it somewhere as the debug output will contain snmp details -amongst other items including port descriptions. +Using `-d` shouldn't output much sensitive information, `-v` will so it is then advisable to sanitise the output before pasting it somewhere as the debug output will contain snmp details amongst other items including port descriptions. The output will contain: diff --git a/doc/Support/Support-New-OS.md b/doc/Support/Support-New-OS.md index 64d6141ef3..f60924ee7b 100644 --- a/doc/Support/Support-New-OS.md +++ b/doc/Support/Support-New-OS.md @@ -105,8 +105,6 @@ Polling At this step we should see all the values retrieved in LibreNMS. - - #### FULL SUPPORT FOR A NEW OS ### MIB diff --git a/html/install.php b/html/install.php index e4d03b4496..8212237012 100644 --- a/html/install.php +++ b/html/install.php @@ -397,9 +397,6 @@ $config_file = <<<"EOD" #\$config\['nets'\]\[\] = "172.16.0.0/12"; #\$config\['nets'\]\[\] = "192.168.0.0/16"; -# following is necessary for poller-wrapper -# poller-wrapper is released public domain -\$config\['poller-wrapper'\]\['alerter'\] = FALSE; # Uncomment the next line to disable daily updates #\$config\['update'\] = 0; EOD; diff --git a/librenms.cron b/librenms.cron index f03f5316da..d9254a30d4 100644 --- a/librenms.cron +++ b/librenms.cron @@ -1,4 +1,5 @@ # It's recommended not to run this cron anymore - please see librenms.nonroot.cron +# PLEASE DO NOT USE THIS FILE 33 */6 * * * root /opt/librenms/discovery.php -h all >> /dev/null 2>&1 */5 * * * * root /opt/librenms/discovery.php -h new >> /dev/null 2>&1 diff --git a/librenms.nonroot.cron b/librenms.nonroot.cron index 3c83bf8b1b..73dcc8bb4c 100644 --- a/librenms.nonroot.cron +++ b/librenms.nonroot.cron @@ -5,3 +5,7 @@ */5 * * * * librenms /opt/librenms/cronic /opt/librenms/poller-wrapper.py 16 15 0 * * * librenms /opt/librenms/daily.sh >> /dev/null 2>&1 * * * * * librenms /opt/librenms/alerts.php >> /dev/null 2>&1 +*/5 * * * * librenms /opt/librenms/poll-billing.php >> /dev/null 2>&1 +01 * * * * librenms /opt/librenms/billing-calculate.php >> /dev/null 2>&1 +*/5 * * * * librenms /opt/librenms/check-services.php >> /dev/null 2>&1 + diff --git a/scripts/pre-commit.php b/scripts/pre-commit.php new file mode 100755 index 0000000000..dac7566e3d --- /dev/null +++ b/scripts/pre-commit.php @@ -0,0 +1,36 @@ +#!/usr/bin/env php += 0) { + $lint = `find . -path './vendor' -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1`; +} else { + $lint = `find . -regextype posix-extended -regex "\./(lib/influxdb-php|vendor)" -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1`; +} + +if (!empty($lint)) { + echo "lint check has failed\n"; + print_r($lint); + $failed = true; +} + +$phpcs = `./vendor/bin/phpcs -n -p --colors --extensions=php --standard=PSR2 --ignore=html/lib/* --ignore=html/plugins/ html`; + +if (!empty($phpcs)) { + echo "PSR2 check has failed\n"; + print_r($phpcs); + $failed = true; +} + +$phpunit = `./vendor/bin/phpunit`; + +if(!strstr($phpunit, "OK")) { + echo "phpunit tests have failed\n"; + print_r($phpunit); + $failed = true; +} + +if ($failed === false) { + echo "Tests ok, submit away :)\n"; +} From 3d0edb46ccf0e832480c2bd22369cb94c24b4ed6 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Thu, 25 Aug 2016 18:43:56 -0500 Subject: [PATCH 04/69] Add ntpd to the list of agentapps (#4194) --- includes/polling/unix-agent.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/polling/unix-agent.inc.php b/includes/polling/unix-agent.inc.php index 6456f205a3..ebd5dad27b 100644 --- a/includes/polling/unix-agent.inc.php +++ b/includes/polling/unix-agent.inc.php @@ -58,6 +58,7 @@ if ($device['os_group'] == 'unix') { "ceph", "mysql", "nginx", + "ntpd", "powerdns", "powerdns-recursor", "proxmox", From 53b07d7a2ab57a18462b4987b5aa29798de940bb Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 26 Aug 2016 00:35:09 -0500 Subject: [PATCH 05/69] Fix deprecated constructors This small change should't prevent easy updates to libraries and fixes the lint check on php7 --- html/lib/PasswordHash.php | 2 +- html/lib/geshi/geshi.php | 4 ++-- html/lib/jpgraph/imgdata_squares.inc.php | 4 ++-- html/lib/jpgraph/jpgraph_bar.php | 2 +- html/lib/jpgraph/jpgraph_flags.php | 4 ++-- html/lib/jpgraph/jpgraph_line.php | 2 +- html/lib/jpgraph/jpgraph_log.php | 2 +- includes/console_table.php | 2 +- lib/pure_php_radius/radius.class.php | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/html/lib/PasswordHash.php b/html/lib/PasswordHash.php index 914ab2e4d4..f4d7d6eb6f 100644 --- a/html/lib/PasswordHash.php +++ b/html/lib/PasswordHash.php @@ -30,7 +30,7 @@ class PasswordHash { var $portable_hashes; var $random_state; - function PasswordHash($iteration_count_log2, $portable_hashes) + function __construct($iteration_count_log2, $portable_hashes) { $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; diff --git a/html/lib/geshi/geshi.php b/html/lib/geshi/geshi.php index 22b2ae7a3f..4f36b78c0e 100644 --- a/html/lib/geshi/geshi.php +++ b/html/lib/geshi/geshi.php @@ -588,7 +588,7 @@ class GeSHi { * {@link GeSHi->set_language_path()} * @since 1.0.0 */ - function GeSHi($source = '', $language = '', $path = '') { + function __construct($source = '', $language = '', $path = '') { if (!empty($source)) { $this->set_source($source); } @@ -4616,4 +4616,4 @@ if (!function_exists('geshi_highlight')) { } } -?> \ No newline at end of file +?> diff --git a/html/lib/jpgraph/imgdata_squares.inc.php b/html/lib/jpgraph/imgdata_squares.inc.php index e420b0a243..3d25b3d2eb 100644 --- a/html/lib/jpgraph/imgdata_squares.inc.php +++ b/html/lib/jpgraph/imgdata_squares.inc.php @@ -43,7 +43,7 @@ class ImgData_Squares extends ImgData { protected $maxidx = 7 ; protected $imgdata ; - function ImgData_Squares () { + function __construct() { //========================================================== //sq_lblue.png //========================================================== @@ -171,4 +171,4 @@ class ImgData_Squares extends ImgData { } } -?> \ No newline at end of file +?> diff --git a/html/lib/jpgraph/jpgraph_bar.php b/html/lib/jpgraph/jpgraph_bar.php index 92d8eb7868..0f77e8444a 100644 --- a/html/lib/jpgraph/jpgraph_bar.php +++ b/html/lib/jpgraph/jpgraph_bar.php @@ -652,7 +652,7 @@ class GroupBarPlot extends BarPlot { private $plots, $nbrplots=0; //--------------- // CONSTRUCTOR - function GroupBarPlot($plots) { + function __construct($plots) { $this->width=0.7; $this->plots = $plots; $this->nbrplots = count($plots); diff --git a/html/lib/jpgraph/jpgraph_flags.php b/html/lib/jpgraph/jpgraph_flags.php index 85295b1457..6a55fd2933 100644 --- a/html/lib/jpgraph/jpgraph_flags.php +++ b/html/lib/jpgraph/jpgraph_flags.php @@ -291,7 +291,7 @@ class FlagImages { private $iFlagData ; private $iOrdIdx=array(); - function FlagImages($aSize=FLAGSIZE1) { + function __construct($aSize=FLAGSIZE1) { switch($aSize) { case FLAGSIZE1 : case FLAGSIZE2 : @@ -397,4 +397,4 @@ class FlagImages { -?> \ No newline at end of file +?> diff --git a/html/lib/jpgraph/jpgraph_line.php b/html/lib/jpgraph/jpgraph_line.php index ef72f057c2..1a1d0c6661 100644 --- a/html/lib/jpgraph/jpgraph_line.php +++ b/html/lib/jpgraph/jpgraph_line.php @@ -59,7 +59,7 @@ class LinePlot extends Plot{ //--------------- // CONSTRUCTOR - function LinePlot($datay,$datax=false) { + function __construct($datay,$datax=false) { parent::__construct($datay,$datax); $this->mark = new PlotMark() ; $this->color = ColorFactory::getColor(); diff --git a/html/lib/jpgraph/jpgraph_log.php b/html/lib/jpgraph/jpgraph_log.php index 82b48d6a6c..eaa8e9eb69 100644 --- a/html/lib/jpgraph/jpgraph_log.php +++ b/html/lib/jpgraph/jpgraph_log.php @@ -155,7 +155,7 @@ class LogTicks extends Ticks{ private $ticklabels_pos = array(); //--------------- // CONSTRUCTOR - function LogTicks() { + function __construct() { } //--------------- // PUBLIC METHODS diff --git a/includes/console_table.php b/includes/console_table.php index aff8c9b084..ebc42c02ae 100644 --- a/includes/console_table.php +++ b/includes/console_table.php @@ -171,7 +171,7 @@ class Console_Table * extension. * @param boolean $color Whether the data contains ansi color codes. */ - function Console_Table( + function __construct( $align=CONSOLE_TABLE_ALIGN_LEFT, $border=CONSOLE_TABLE_BORDER_ASCII, $padding=1, diff --git a/lib/pure_php_radius/radius.class.php b/lib/pure_php_radius/radius.class.php index b56f061aff..4feb33fcd7 100644 --- a/lib/pure_php_radius/radius.class.php +++ b/lib/pure_php_radius/radius.class.php @@ -227,7 +227,7 @@ class Radius * @param integer accounting port * @return NULL *********************************************************************/ - public function Radius($ip_radius_server = '127.0.0.1', $shared_secret = '', $radius_suffix = '', $udp_timeout = 5, $authentication_port = 1812, $accounting_port = 1813) + public function __construct($ip_radius_server = '127.0.0.1', $shared_secret = '', $radius_suffix = '', $udp_timeout = 5, $authentication_port = 1812, $accounting_port = 1813) { $this->_radius_packet_info[1] = 'Access-Request'; $this->_radius_packet_info[2] = 'Access-Accept'; From e588c171e2137fc27f4b3454f7c9ef715711927e Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 26 Aug 2016 00:36:46 -0500 Subject: [PATCH 06/69] Don't allow php7 failures anymore --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7a27f95828..c373dea6bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,6 @@ matrix: EXECUTE_BUILD_DOCS=false allow_failures: - - php: 7.0 - php: hhvm cache: From 200e67031556f25eb125669ba201373b8b017591 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 26 Aug 2016 01:50:29 -0500 Subject: [PATCH 07/69] Fix defunct process issues: create Proc class (#4210) * Proc class Encapsulate processes in a class, when they go out of scope, we can use the __destruct() process to make sure the process terminates. * Fix rrdtool_last checks failing * Don't close rrdtool in rrd_graph Try to start rrdtool process if they haven't been started yet Remove some extra debug output * phpdocs added several cleanups should still be functioning the same Only open one rrdtool process for graph.php --- LibreNMS/Proc.php | 237 +++++++++++++++++++++++++++++++++++++++ check-services.php | 2 +- html/graph.php | 7 +- includes/rrdtool.inc.php | 136 ++++++++-------------- poll-billing.php | 2 +- poller.php | 2 +- 6 files changed, 294 insertions(+), 92 deletions(-) create mode 100644 LibreNMS/Proc.php diff --git a/LibreNMS/Proc.php b/LibreNMS/Proc.php new file mode 100644 index 0000000000..4c2050ffc9 --- /dev/null +++ b/LibreNMS/Proc.php @@ -0,0 +1,237 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2016 Tony Murray + * @author Tony Murray + */ + +namespace LibreNMS; + +use Exception; + +class Proc +{ + /** + * @var resource the process this object is responsible for + */ + private $_process; + /** + * @var array array of process pipes [stdin,stdout,stderr] + */ + private $_pipes; + + /** + * @var bool if this process is synchronous (waits for output) + */ + private $_synchronous; + + /** + * Create and run a new process + * Most arguments match proc_open() + * + * @param string $cmd the command to execute + * @param array $descriptorspec the definition of pipes to initialize + * @param null $cwd working directory to change to + * @param array|null $env array of environment variables to set + * @param bool $blocking set the output pipes to blocking (default: false) + * @throws Exception the command was unable to execute + */ + public function __construct($cmd, $descriptorspec, $cwd = null, $env = null, $blocking = false) + { + $this->_process = proc_open($cmd, $descriptorspec, $this->_pipes, $cwd, $env); + if (!is_resource($this->_process)) { + throw new Exception("Command failed: $cmd"); + } + stream_set_blocking($this->_pipes[1], $blocking); + stream_set_blocking($this->_pipes[2], $blocking); + $this->_synchronous = true; + } + + /** + * Called when this object goes out of scope or php exits + * If it is still running, terminate the process + */ + public function __destruct() + { + if ($this->isRunning()) { + $this->terminate(); + } + } + + /** + * Get one of the pipes + * 0 - stdin + * 1 - stdout + * 2 - stderr + * + * @param int $nr pipe number (0-2) + * @return resource the pipe handle + */ + public function pipe($nr) + { + return $this->_pipes[$nr]; + } + + + /** + * Send a command to this process and return the output + * the output may not correspond to this command if this + * process is not synchronous + * If the command isn't terminated with a newline, add one + * + * @param $command + * @return array + */ + public function sendCommand($command) + { + if (!ends_with($command, PHP_EOL)) { + $command .= PHP_EOL; + } + $this->sendInput($command); + + return $this->getOutput(); + } + + /** + * Send data to stdin + * + * @param string $data the string to send + */ + public function sendInput($data) + { + fwrite($this->_pipes[0], $data); + } + + /** + * Gets the current output of the process + * If this process is set to synchronous, wait for output + * + * @param int $timeout time to wait for output, only applies if this process is synchronous + * @return array [stdout, stderr] + */ + public function getOutput($timeout = 15) + { + if ($this->_synchronous) { + $pipes = array($this->_pipes[1], $this->_pipes[2]); + $w = null; + $x = null; + + stream_select($pipes, $w, $x, $timeout); + } + return array(stream_get_contents($this->_pipes[1]), stream_get_contents($this->_pipes[2])); + } + + /** + * Attempt to gracefully close this process + * optionally send one last piece of input + * such as a quit command + * + * @param string $cmd the final command to send + * @return int the exit status of this process (-1 means error) + */ + public function close($cmd = null) + { + if (isset($cmd)) { + $this->sendInput($cmd); + } + + fclose($this->_pipes[0]); + fclose($this->_pipes[1]); + fclose($this->_pipes[2]); + + return proc_close($this->_process); + } + + /** + * Forcibly close this process + * Please attempt to run close() instead of this + * This will be called when this object is destroyed if the process is still running + * + * @param int $signal the signal to send + * @throws Exception + */ + public function terminate($signal = 15) + { + $status = $this->getStatus(); + + fclose($this->_pipes[1]); + fclose($this->_pipes[2]); + + $closed = proc_terminate($this->_process, $signal); + + if (!$closed) { + // try harder + $pid = $status['pid']; + $killed = posix_kill($pid, 9); //9 is the SIGKILL signal + proc_close($this->_process); + + if (!$killed) { + throw new Exception("Terminate failed!"); + } + } + } + + /** + * Get the status of this process + * see proc_get_status() + * + * @return array status array + */ + public function getStatus() + { + return proc_get_status($this->_process); + } + + /** + * Check if this process is running + * + * @return bool + */ + public function isRunning() + { + if(!is_resource($this->_process)) { + return false; + } + $st = $this->getStatus(); + return isset($st['running']); + } + + /** + * If this process waits for output + * @return boolean + */ + public function isSynchronous() + { + return $this->_synchronous; + } + + /** + * Set this process as synchronous, by default processes are synchronous + * It is advisable not to change this mid way as output could get mixed up + * or you could end up blocking until the getOutput timeout expires + * + * @param boolean $synchronous + */ + public function setSynchronous($synchronous) + { + $this->_synchronous = $synchronous; + } +} diff --git a/check-services.php b/check-services.php index e418c8d385..d2aec7fc65 100755 --- a/check-services.php +++ b/check-services.php @@ -53,4 +53,4 @@ foreach (dbFetchRows('SELECT * FROM `devices` AS D, `services` AS S WHERE S.devi poll_service($service); } //end foreach -rrdtool_terminate(); +rrdtool_close(); diff --git a/html/graph.php b/html/graph.php index 84ed9bfd3d..8411fca3dd 100644 --- a/html/graph.php +++ b/html/graph.php @@ -32,9 +32,9 @@ if (isset($_GET['debug'])) { require_once '../includes/defaults.inc.php'; require_once '../config.php'; +require_once '../includes/common.php'; require_once '../includes/definitions.inc.php'; -require_once '../includes/common.php'; require_once '../includes/dbFacile.php'; require_once '../includes/rewrites.php'; require_once 'includes/functions.inc.php'; @@ -42,9 +42,12 @@ require_once '../includes/rrdtool.inc.php'; if ($config['allow_unauth_graphs'] != true) { require_once 'includes/authenticate.inc.php'; } + +rrdtool_initialize(false); + require 'includes/graphs/graph.inc.php'; -$console_color = new Console_Color2(); +rrdtool_close(); $end = microtime(true); $run = ($end - $start); diff --git a/includes/rrdtool.inc.php b/includes/rrdtool.inc.php index a09a7e00b7..73a56a359f 100644 --- a/includes/rrdtool.inc.php +++ b/includes/rrdtool.inc.php @@ -2,7 +2,7 @@ /** * rrdtool.inc.php * - * Helper for processing rrd requests efficiently + * Helper for processing rrdtool requests efficiently * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ */ use LibreNMS\Exceptions\FileExistsException; +use LibreNMS\Proc; /** * Opens up a pipe to RRDTool using handles provided @@ -35,7 +36,7 @@ use LibreNMS\Exceptions\FileExistsException; */ function rrdtool_initialize($dual_process = true) { - global $config, $rrd_async_process, $rrd_async_pipes, $rrd_sync_process, $rrd_sync_pipes; + global $config, $rrd_sync_process, $rrd_async_process; $command = $config['rrdtool'] . ' -'; @@ -46,66 +47,46 @@ function rrdtool_initialize($dual_process = true) ); $cwd = $config['rrd_dir']; - $env = array(); - if(!is_resource($rrd_async_process)) { - $rrd_async_process = proc_open($command, $descriptor_spec, $rrd_async_pipes, $cwd, $env); - stream_set_blocking($rrd_async_pipes[1], false); - stream_set_blocking($rrd_async_pipes[2], false); + if (!rrdtool_running($rrd_sync_process)) { + $rrd_sync_process = new Proc($command, $descriptor_spec, $cwd); } - if ($dual_process && !is_resource($rrd_sync_process)) { - $rrd_sync_process = proc_open($command, $descriptor_spec, $rrd_sync_pipes, $cwd, $env); - stream_set_blocking($rrd_sync_pipes[1], false); - stream_set_blocking($rrd_sync_pipes[2], false); + if ($dual_process && !rrdtool_running($rrd_async_process)) { + $rrd_async_process = new Proc($command, $descriptor_spec, $cwd); + $rrd_async_process->setSynchronous(false); } - return is_resource($rrd_async_process) && ($dual_process ? is_resource($rrd_sync_process) : true); + return rrdtool_running($rrd_sync_process) && ($dual_process ? rrdtool_running($rrd_async_process) : true); +} + +/** + * Checks if the variable is a running rrdtool process + * + * @param $process + * @return bool + */ +function rrdtool_running(&$process) +{ + return isset($process) && $process instanceof Proc && $process->isRunning(); } /** * Close all open rrdtool processes. * This should be done before exiting a script that has called rrdtool_initilize() - * - * @return bool indicates success */ -function rrdtool_terminate() { - global $rrd_async_process, $rrd_async_pipes, $rrd_sync_process, $rrd_sync_pipes; - - $ret = rrdtool_pipe_close($rrd_async_process, $rrd_async_pipes); - if ($rrd_sync_pipes) { - $ret = rrdtool_pipe_close($rrd_sync_process, $rrd_sync_pipes) && $ret; - } - - return $ret; -} - -/** - * Closes the pipe to RRDTool - * - * @internal - * @param resource $rrd_process - * @param array $rrd_pipes - * @return integer - */ -function rrdtool_pipe_close($rrd_process, &$rrd_pipes) +function rrdtool_close() { - global $vdebug; - if ($vdebug) { - d_echo(stream_get_contents($rrd_pipes[1])); - d_echo(stream_get_contents($rrd_pipes[2])); + global $rrd_sync_process, $rrd_async_process; + + if (rrdtool_running($rrd_sync_process)) { + $rrd_sync_process->close('quit'); + } + if (rrdtool_running($rrd_async_process)) { + $rrd_async_process->close('quit'); } - - fclose($rrd_pipes[0]); - fclose($rrd_pipes[1]); - fclose($rrd_pipes[2]); - - // It is important that you close any pipes before calling - // proc_close in order to avoid a deadlock - return proc_terminate($rrd_process); } - /** * Generates a graph file at $graph_file using $options * Opens its own rrdtool pipe. @@ -116,37 +97,19 @@ function rrdtool_pipe_close($rrd_process, &$rrd_pipes) */ function rrdtool_graph($graph_file, $options) { - global $config, $debug, $rrd_async_pipes; + global $debug, $rrd_sync_process; if (rrdtool_initialize(false)) { - if ($config['rrdcached']) { - $options = str_replace(array($config['rrd_dir'].'/', $config['rrd_dir']), '', $options); - fwrite($rrd_async_pipes[0], 'graph --daemon ' . $config['rrdcached'] . " $graph_file $options"); - } else { - fwrite($rrd_async_pipes[0], "graph $graph_file $options"); - } + $cmd = rrdtool_build_command('graph', $graph_file, $options); - fclose($rrd_async_pipes[0]); - - $line = ""; - $data = ""; - while (strlen($line) < 1) { - $line = fgets($rrd_async_pipes[1], 1024); - $data .= $line; - } - - $return_value = rrdtool_terminate(); + $output = implode($rrd_sync_process->sendCommand($cmd)); if ($debug) { - echo '

'; - echo "graph $graph_file $options"; - - echo '

'; - echo "command returned $return_value ($data)\n"; - echo '

'; + echo "

$cmd

"; + echo "

command returned ($output)

"; } - return $data; + return $output; } else { return 0; } @@ -161,13 +124,12 @@ function rrdtool_graph($graph_file, $options) * @param string $filename The full patth to the rrd file * @param string $options rrdtool command options * @return array the output of stdout and stderr in an array - * @global $config - * @global $debug - * @global $rrd_pipes + * @throws FileExistsException thrown when a create command is set to rrdtool < 1.4 and the rrd already exists + * @throws Exception thrown when the rrdtool process(s) cannot be started */ function rrdtool($command, $filename, $options) { - global $config, $debug, $vdebug, $rrd_async_pipes, $rrd_sync_pipes; + global $config, $debug, $vdebug, $rrd_async_process, $rrd_sync_process; try { $cmd = rrdtool_build_command($command, $filename, $options); @@ -180,22 +142,20 @@ function rrdtool($command, $filename, $options) // do not write rrd files, but allow read-only commands $ro_commands = array('graph', 'graphv', 'dump', 'fetch', 'first', 'last', 'lastupdate', 'info', 'xport'); - if ($config['norrd'] && !in_array($command, $ro_commands)) { + if (!empty($config['norrd']) && !in_array($command, $ro_commands)) { c_echo('[%rRRD Disabled%n]'); return array(null, null); } // send the command! - if($command == 'last' && $rrd_sync_pipes) { - fwrite($rrd_sync_pipes[0], $cmd . "\n"); - - // this causes us to block until we receive output for up to the timeout in seconds - stream_select($r = $rrd_sync_pipes, $w = null, $x = null, 10); - $output = array(stream_get_contents($rrd_sync_pipes[1]), stream_get_contents($rrd_sync_pipes[2])); - + if ($command == 'last' && rrdtool_initialize(false)) { + // send this to our synchronous process so output is guaranteed + $output = $rrd_sync_process->sendCommand($cmd); + } elseif (rrdtool_initialize()) { + // don't care about the return of other commands, so send them to the faster async process + $output = $rrd_async_process->sendCommand($cmd); } else { - fwrite($rrd_async_pipes[0], $cmd . "\n"); - $output = array(stream_get_contents($rrd_async_pipes[1]), stream_get_contents($rrd_async_pipes[2])); + throw new Exception('rrdtool could not start'); } if ($vdebug) { @@ -241,6 +201,7 @@ function rrdtool_build_command($command, $filename, $options) ) { // only relative paths if using rrdcached $filename = str_replace(array($config['rrd_dir'].'/', $config['rrd_dir']), '', $filename); + $options = str_replace(array($config['rrd_dir'].'/', $config['rrd_dir']), '', $options); return "$command $filename $options --daemon " . $config['rrdcached']; } @@ -347,7 +308,8 @@ function rrd_name($host, $extra, $extension = ".rrd") * @param $vmport * @return string full path to the rrd. */ -function proxmox_rrd_name($pmxcluster, $vmid, $vmport) { +function proxmox_rrd_name($pmxcluster, $vmid, $vmport) +{ global $config; $pmxcdir = join('/', array($config['rrd_dir'], 'proxmox', safename($pmxcluster))); @@ -422,7 +384,7 @@ function rrdtool_data_update($device, $measurement, $tags, $fields) $rrd_name = $tags['rrd_name'] ?: $measurement; $step = $tags['rrd_step'] ?: 300; $oldname = $tags['rrd_oldname']; - if (isset($oldname) && !empty($oldname)) { + if (!empty($oldname)) { rrd_file_rename($device, $oldname, $rrd_name); } diff --git a/poll-billing.php b/poll-billing.php index f1a29d4c5c..55ece83b25 100755 --- a/poll-billing.php +++ b/poll-billing.php @@ -158,4 +158,4 @@ if ($poller_time > 300) { } echo "\nCompleted in $poller_time sec\n"; -rrdtool_terminate(); \ No newline at end of file +rrdtool_close(); diff --git a/poller.php b/poller.php index 5a6d5b47dc..0868dde869 100755 --- a/poller.php +++ b/poller.php @@ -158,7 +158,7 @@ echo ("\n".'MySQL: Cell['.($db_stats['fetchcell'] + 0).'/'.round(($db_stats['fet echo "\n"; logfile($string); -rrdtool_terminate(); +rrdtool_close(); unset($config); // Remove this for testing // print_r(get_defined_vars()); From d26a1ff2a80df37ea4d89a17eb370ac212f2122f Mon Sep 17 00:00:00 2001 From: nerdalertdk Date: Fri, 26 Aug 2016 09:17:01 +0200 Subject: [PATCH 08/69] Get services from API /services = list all services /services/:hostname = get services by host --- html/api_v0.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/html/api_v0.php b/html/api_v0.php index 7ee1053870..92688c7b7a 100644 --- a/html/api_v0.php +++ b/html/api_v0.php @@ -154,6 +154,15 @@ $app->group( } ); // End Resources + // Service section + $app->group( + '/services', + function () use ($app) { + $app->get('/:hostname', 'authToken', 'list_services')->name('get_service_for_host'); + } + ); + $app->get('/services', 'authToken', 'list_services')->name('list_services'); + // End Service } ); $app->get('/v0', 'authToken', 'show_endpoints'); From 0f12c612590590cbb2b71f6aea438a161e7107a1 Mon Sep 17 00:00:00 2001 From: nerdalertdk Date: Fri, 26 Aug 2016 09:19:05 +0200 Subject: [PATCH 09/69] list_services /services?state = filter by service state /service?type = filter by service type --- html/includes/api_functions.inc.php | 63 +++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index 7d0fcbf302..1f56b2cf1d 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -1299,3 +1299,66 @@ function list_arp() $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); } +function list_services() +{ + global $config; + $app = \Slim\Slim::getInstance(); + $router = $app->router()->getCurrentRoute()->getParams(); + $status = 'ok'; + $code = 200; + $message = ''; + + // Filter BY STATE + if (isset($_GET['state'])) { + $where = " AND S.service_status= ? AND S.service_disabled='0' AND S.service_ignore='0'"; + $host_par[] = $_GET['state']; + + if (!is_numeric($_GET['state'])) { + $status = 'error'; + $message = "No valid service state provided, valid option is 0=Ok, 1=Warning, 2=Critical"; + } + } + + // GET BY HOST + if(isset($router['hostname'])) { + $hostname = $router['hostname']; + $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); + + $where .= " AND S.device_id = ?"; + $host_par[] = $device_id; + + if (!is_numeric($device_id)) { + $status = 'error'; + $message = "No valid hostname or device id provided"; + } + } + + // DEVICE + $host_sql = 'SELECT * FROM devices AS D, services AS S WHERE D.device_id = S.device_id '.$where.' GROUP BY D.hostname ORDER BY D.hostname'; + + // SERVICE + $shift = 1; + foreach (dbFetchRows($host_sql, $host_par) as $device) { + $device_id = $device['device_id']; + $sql_param[0] = $device_id; + + // FILTER BY TYPE + if (isset($_GET['type'])) { + $devicewhere = " AND `service_type` LIKE ?"; + $sql_param[1] = $_GET['type']; + } + + $services[] = dbFetchRows("SELECT * FROM `services` WHERE `device_id` = ?".$devicewhere, $sql_param); + } + $count = count($services); + $output = array( + 'status' => $status, + 'err-msg' => $message, + 'count' => $count, + 'services' => $services, + ); + + $app->response->setStatus($code); + $app->response->headers->set('Content-Type', 'application/json'); + echo _json_encode($output); +} From 1bf6ed6bd671bc89982ff4514c4496b27c3da943 Mon Sep 17 00:00:00 2001 From: nerdalertdk Date: Fri, 26 Aug 2016 09:22:20 +0200 Subject: [PATCH 10/69] Update AUTHORS.md --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index d570321879..6b4d4cc4a0 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -121,6 +121,7 @@ LibreNMS contributors: - Phil Regnauld (reegnauld) - Russell Morris (arrmo) - Bennett Blodinger (benwa) +- Michael Hansen (nerdalertdk) [1]: http://observium.org/ "Observium web site" Observium was written by: From c873a3556e6fee9c44806738b4ea4292418a4b8e Mon Sep 17 00:00:00 2001 From: nerdalertdk Date: Fri, 26 Aug 2016 09:26:52 +0200 Subject: [PATCH 11/69] use space not tabs --- html/includes/api_functions.inc.php | 92 ++++++++++++++--------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index 1f56b2cf1d..5308c6c4c1 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -1301,64 +1301,64 @@ function list_arp() } function list_services() { - global $config; + global $config; $app = \Slim\Slim::getInstance(); $router = $app->router()->getCurrentRoute()->getParams(); - $status = 'ok'; + $status = 'ok'; $code = 200; $message = ''; - - // Filter BY STATE - if (isset($_GET['state'])) { - $where = " AND S.service_status= ? AND S.service_disabled='0' AND S.service_ignore='0'"; - $host_par[] = $_GET['state']; - - if (!is_numeric($_GET['state'])) { - $status = 'error'; - $message = "No valid service state provided, valid option is 0=Ok, 1=Warning, 2=Critical"; - } - } - - // GET BY HOST - if(isset($router['hostname'])) { - $hostname = $router['hostname']; - $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); - - $where .= " AND S.device_id = ?"; - $host_par[] = $device_id; - - if (!is_numeric($device_id)) { - $status = 'error'; - $message = "No valid hostname or device id provided"; - } - } + + // Filter BY STATE + if (isset($_GET['state'])) { + $where = " AND S.service_status= ? AND S.service_disabled='0' AND S.service_ignore='0'"; + $host_par[] = $_GET['state']; + + if (!is_numeric($_GET['state'])) { + $status = 'error'; + $message = "No valid service state provided, valid option is 0=Ok, 1=Warning, 2=Critical"; + } + } + + // GET BY HOST + if(isset($router['hostname'])) { + $hostname = $router['hostname']; + $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); + + $where .= " AND S.device_id = ?"; + $host_par[] = $device_id; + + if (!is_numeric($device_id)) { + $status = 'error'; + $message = "No valid hostname or device id provided"; + } + } - // DEVICE - $host_sql = 'SELECT * FROM devices AS D, services AS S WHERE D.device_id = S.device_id '.$where.' GROUP BY D.hostname ORDER BY D.hostname'; - - // SERVICE - $shift = 1; - foreach (dbFetchRows($host_sql, $host_par) as $device) { - $device_id = $device['device_id']; - $sql_param[0] = $device_id; - - // FILTER BY TYPE - if (isset($_GET['type'])) { - $devicewhere = " AND `service_type` LIKE ?"; - $sql_param[1] = $_GET['type']; - } + // DEVICE + $host_sql = 'SELECT * FROM devices AS D, services AS S WHERE D.device_id = S.device_id '.$where.' GROUP BY D.hostname ORDER BY D.hostname'; + + // SERVICE + $shift = 1; + foreach (dbFetchRows($host_sql, $host_par) as $device) { + $device_id = $device['device_id']; + $sql_param[0] = $device_id; + + // FILTER BY TYPE + if (isset($_GET['type'])) { + $devicewhere = " AND `service_type` LIKE ?"; + $sql_param[1] = $_GET['type']; + } - $services[] = dbFetchRows("SELECT * FROM `services` WHERE `device_id` = ?".$devicewhere, $sql_param); - } + $services[] = dbFetchRows("SELECT * FROM `services` WHERE `device_id` = ?".$devicewhere, $sql_param); + } $count = count($services); - $output = array( + $output = array( 'status' => $status, - 'err-msg' => $message, + 'err-msg' => $message, 'count' => $count, 'services' => $services, ); - $app->response->setStatus($code); + $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); } From 4db541cc3284055a5fecd04213838cc1d249ac0a Mon Sep 17 00:00:00 2001 From: nerdalertdk Date: Fri, 26 Aug 2016 10:10:29 +0200 Subject: [PATCH 12/69] tabs to spaces --- html/api_v0.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/html/api_v0.php b/html/api_v0.php index 92688c7b7a..dbfba3cb05 100644 --- a/html/api_v0.php +++ b/html/api_v0.php @@ -156,10 +156,10 @@ $app->group( // End Resources // Service section $app->group( - '/services', - function () use ($app) { - $app->get('/:hostname', 'authToken', 'list_services')->name('get_service_for_host'); - } + '/services', + function () use ($app) { + $app->get('/:hostname', 'authToken', 'list_services')->name('get_service_for_host'); + } ); $app->get('/services', 'authToken', 'list_services')->name('list_services'); // End Service From feb6696026005cc8bf1a6a9220fe87fb9894e253 Mon Sep 17 00:00:00 2001 From: nerdalertdk Date: Fri, 26 Aug 2016 10:11:20 +0200 Subject: [PATCH 13/69] tabs to spaces --- html/includes/api_functions.inc.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index 5308c6c4c1..4f32d5026a 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -1320,7 +1320,7 @@ function list_services() } // GET BY HOST - if(isset($router['hostname'])) { + if (isset($router['hostname'])) { $hostname = $router['hostname']; $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); @@ -1339,8 +1339,8 @@ function list_services() // SERVICE $shift = 1; foreach (dbFetchRows($host_sql, $host_par) as $device) { - $device_id = $device['device_id']; - $sql_param[0] = $device_id; + $device_id = $device['device_id']; + $sql_param[0] = $device_id; // FILTER BY TYPE if (isset($_GET['type'])) { @@ -1348,7 +1348,7 @@ function list_services() $sql_param[1] = $_GET['type']; } - $services[] = dbFetchRows("SELECT * FROM `services` WHERE `device_id` = ?".$devicewhere, $sql_param); + $services[] = dbFetchRows("SELECT * FROM `services` WHERE `device_id` = ?".$devicewhere, $sql_param); } $count = count($services); $output = array( From 562737a528523e5db1d5166cfa320191a0df5483 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 26 Aug 2016 04:13:56 -0500 Subject: [PATCH 14/69] include common.php in definitions.inc.php (#4198) definitions.inc.php makes a call to dbFetchRow, which uses c_echo() It is safe to include common.php here as it only has function definitions. --- includes/definitions.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index b2b52ecde0..124a5de8ef 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -1,5 +1,6 @@ Date: Fri, 26 Aug 2016 04:30:43 -0500 Subject: [PATCH 15/69] Use pre-commit.php in for travis-ci tests (#4212) --- .travis.yml | 21 +---- composer.json | 3 - scripts/pre-commit.php | 179 +++++++++++++++++++++++++++++++++++------ 3 files changed, 158 insertions(+), 45 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6ceeb29388..0ab420a850 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,30 +3,14 @@ matrix: fast_finish: true include: - php: 7.0 - env: - PHP_L=1 - EXECUTE_BUILD_DOCS=false - php: 5.3 - env: - PHP_L_OLD=1 - EXECUTE_BUILD_DOCS=false - php: 5.4 - env: - PHP_L_OLD=1 - EXECUTE_BUILD_DOCS=false - php: 5.5 - env: - PHP_L=1 - EXECUTE_BUILD_DOCS=false - php: 5.6 env: - PHP_L=1 PHP_CS=1 EXECUTE_BUILD_DOCS=true - php: hhvm - env: - PHP_L_OLD=1 - EXECUTE_BUILD_DOCS=false allow_failures: - php: hhvm @@ -43,7 +27,6 @@ after_success: - test $TRAVIS_PULL_REQUEST == "false" && test $TRAVIS_BRANCH == "master" && test $EXECUTE_BUILD_DOCS == "true" && bash scripts/deploy-docs.sh script: - - if [[ $PHP_L == 1 ]]; then find . -path './vendor' -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1; fi - - if [[ $PHP_L_OLD == 1 ]]; then find . -regextype posix-extended -regex "\./(lib/influxdb-php|vendor)" -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1; fi - - if [[ $PHP_CS == 1 ]]; then vendor/bin/phpcs -n -p --colors --extensions=php --standard=PSR2 --ignore=html/lib/* --ignore=html/plugins/* html; fi + - php scripts/pre-commit.php -l + - if [[ $PHP_CS == 1 ]]; then php scripts/pre-commit.php -p -s; fi - phpunit diff --git a/composer.json b/composer.json index 098e4829b3..6ca49b6e1a 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,4 @@ { - "require": { - "squizlabs/php_codesniffer": "*" - }, "require-dev": { "squizlabs/php_codesniffer": "*", "phpunit/phpunit": "4.*" diff --git a/scripts/pre-commit.php b/scripts/pre-commit.php index dac7566e3d..bfdaf4ec14 100755 --- a/scripts/pre-commit.php +++ b/scripts/pre-commit.php @@ -1,36 +1,169 @@ #!/usr/bin/env php = 0) { - $lint = `find . -path './vendor' -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1`; -} else { - $lint = `find . -regextype posix-extended -regex "\./(lib/influxdb-php|vendor)" -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v '^No syntax errors detected' ; test $? -eq 1`; +$short_opts = 'lsuph'; +$long_opts = array( + 'lint', + 'style', + 'unit', + 'passthru', + 'help', +); +$parameters = array( + 'p', + 'passthru', +); + +$options = getopt($short_opts, $long_opts); + +if (check_opt($options, 'h', 'help')) { + echo "LibreNMS Code Tests Script +Running $filename without options runs all checks. + -l, --lint Run php lint checks to test for valid syntax. + -s, --style Run phpcs check to check for PSR-2 compliance. + -u, --unit Run phpunit tests. + -h, --help Show this help text.\n"; + exit(); } -if (!empty($lint)) { - echo "lint check has failed\n"; - print_r($lint); - $failed = true; +// set up some variables +$passthru = check_opt($options, 'p', 'passthru'); +$commands = array_diff($options, $parameters); +$all = empty($commands); +$ret = 0; + + +// run tests +if ($all || check_opt($commands, 'l', 'lint')) { + $ret += check_lint(); } -$phpcs = `./vendor/bin/phpcs -n -p --colors --extensions=php --standard=PSR2 --ignore=html/lib/* --ignore=html/plugins/ html`; - -if (!empty($phpcs)) { - echo "PSR2 check has failed\n"; - print_r($phpcs); - $failed = true; +if ($all || check_opt($commands, 's', 'style')) { + $ret += check_style($passthru); } -$phpunit = `./vendor/bin/phpunit`; - -if(!strstr($phpunit, "OK")) { - echo "phpunit tests have failed\n"; - print_r($phpunit); - $failed = true; +if ($all || check_opt($commands, 'u', 'unit')) { + $ret += check_unit($passthru); } -if ($failed === false) { - echo "Tests ok, submit away :)\n"; + +// output Tests ok, if no arguments passed +if ($all && $ret === 0) { + echo "\033[32mTests ok, submit away :)\033[0m \n"; +} +exit($ret); //return the combined/single return value of tests + + +/** + * Check if the given options array contains any of the $opts specified + * + * @param array $options the array from getopt() + * @param string $opts,... options to check for + * @return bool If one of the specified options is set + */ +function check_opt($options) +{ + $args = func_get_args(); + array_shift($args); + + $intersect = array_intersect(array_keys($options), $args); + return !empty($intersect); +} + + +/** + * Runs php -l and tests for any syntax errors + * + * @return int the return value from running php -l (0 = success) + */ +function check_lint() +{ + echo "Running lint check... \n"; + + if (version_compare(PHP_VERSION, '5.6') >= 0) { + $lint_exclude = 'vendor'; + } else { + $lint_exclude = 'vendor|lib/influxdb-php'; + } + $lint_cmd = 'find . -regextype posix-extended -regex "\./('; + $lint_cmd .= $lint_exclude; + $lint_cmd .= ')" -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l '; + $lint_cmd .= '| grep -v "^No syntax errors detected"; test $? -eq 1'; + + exec($lint_cmd, $lint_output, $lint_ret); + + if ($lint_ret > 0) { + print(implode(PHP_EOL, $lint_output) . PHP_EOL); + } else { + echo "success\n"; + } + + return $lint_ret; +} + +/** + * Runs phpcs --standard=PSR2 against the code base + * + * @param bool $passthru display the output as comes in + * @return int the return value from phpcs (0 = success) + */ +function check_style($passthru = false) +{ + echo 'Checking PSR-2 style...'.($passthru ? "\n" : ' '); + + + $cs_exclude = '--ignore=html/lib/* --ignore=html/plugins/'; + $cs_cmd = "./vendor/bin/phpcs -n -p --colors --extensions=php --standard=PSR2 $cs_exclude html"; + + $cs_output = ''; + if ($passthru) { + passthru($cs_cmd, $cs_ret); + } else { + exec($cs_cmd, $cs_output, $cs_ret); + } + + if (!$passthru) { + if ($cs_ret > 0) { + echo "failed\n"; + print(implode(PHP_EOL, $cs_output) . PHP_EOL); + } else { + echo "success\n"; + } + } + + return $cs_ret; +} + +/** + * Runs phpunit + * + * @param bool $passthru display the output as comes in + * @return int the return value from phpunit (0 = success) + */ +function check_unit($passthru = false) +{ + echo 'Running unit tests...'.($passthru ? "\n" : ' '); + $phpunit_cmd = './vendor/bin/phpunit --colors=always'; + + $phpunit_output = ''; + if ($passthru) { + passthru($phpunit_cmd, $phpunit_ret); + } else { + exec($phpunit_cmd, $phpunit_output, $phpunit_ret); + } + + if (!$passthru) { + if ($phpunit_ret > 0) { + echo "failed\n"; + print(implode(PHP_EOL, $phpunit_output) . PHP_EOL); + } else { + echo "success\n"; + } + } + + return $phpunit_ret; } From 8a6ad076e2219ecb3b9717b884e5df26dd74d6df Mon Sep 17 00:00:00 2001 From: nerdalertdk Date: Fri, 26 Aug 2016 11:45:25 +0200 Subject: [PATCH 16/69] Update api_functions.inc.php --- html/includes/api_functions.inc.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index 4f32d5026a..8966b4806e 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -1307,6 +1307,11 @@ function list_services() $status = 'ok'; $code = 200; $message = ''; + $host_par = array(); + $sql_param = array(); + $services = array(); + $where = ''; + $devicewhere = ''; // Filter BY STATE if (isset($_GET['state'])) { @@ -1337,7 +1342,6 @@ function list_services() $host_sql = 'SELECT * FROM devices AS D, services AS S WHERE D.device_id = S.device_id '.$where.' GROUP BY D.hostname ORDER BY D.hostname'; // SERVICE - $shift = 1; foreach (dbFetchRows($host_sql, $host_par) as $device) { $device_id = $device['device_id']; $sql_param[0] = $device_id; From cd7cf30c00c70dec69779b657515ec8210951316 Mon Sep 17 00:00:00 2001 From: nerdalertdk Date: Fri, 26 Aug 2016 12:01:33 +0200 Subject: [PATCH 17/69] services docs --- doc/API/API-Docs.md | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/doc/API/API-Docs.md b/doc/API/API-Docs.md index 1afa98fe03..01a4b9e821 100644 --- a/doc/API/API-Docs.md +++ b/doc/API/API-Docs.md @@ -52,6 +52,10 @@ source: API/API-Docs.md - [`get_bill`](#api-route-23) - [`resources`](#api-resources) - [`list_arp`](#api-resources-list_arp) + - [`services`](#api-services) + - [`list_services`](#api-services-list_services) + - [`get_service_for_host`](#api-services-get_service_for_host) + Describes the API structure. # `Structure` [`top`](#top) @@ -1440,3 +1444,68 @@ Output: ] } ``` + +### Function: `list_services` [`top`](#top) + +Retrieve all services + +Route: /api/v0/services + +Input: + + - state: only which have a certain state (valid options are 0=Ok, 1=Warning, 2=Critical). + - type: service type, used sql LIKE to find services, so for tcp, use type=tcp for http use type=http + +Example: +```curl +curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/services +curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/services?state=2 +curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/services?state=0&type=tcp +``` + +Output: +```text +{ + "status": "ok", + "err-msg": "", + "count": 1, + "services": [ + { + "Need example" + } + ] +} +``` +### Function: `get_service_for_host` [`top`](#top) + +Retrieve services for device + +Route: /api/v0/services/:hostname + + - id or hostname is the specific device + +Input: + + - state: only which have a certain state (valid options are 0=Ok, 1=Warning, 2=Critical). + - type: service type, used sql LIKE to find services, so for tcp, use type=tcp for http use type=http + +Example: +```curl +curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/services/:hostname +curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/services/:hostname?state=2 +curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/services/:hostname?state=0&type=tcp +``` + +Output: +```text +{ + "status": "ok", + "err-msg": "", + "count": 1, + "services": [ + { + "Need example" + } + ] +} +``` From 19f231d40898f47a226a7f269d822b980c4f0ed5 Mon Sep 17 00:00:00 2001 From: Tatermen Date: Fri, 26 Aug 2016 12:08:48 +0100 Subject: [PATCH 18/69] Freeswitch support (#4203) * Added support for freeswitch via unix_agent * Fixed display of graphs on apps overview * Removed tab indents * Fixed not sending port_descr_type (#4188) * Removed / Updated version info to just be LibreNMS (#4193) * Remove requirement for ['enable_printers'] (#4192) * ricoh devices returning garbage as toner level (#4180) * ricoh devices returning garbage as toner level * ricoh toner extra check * more ricoh rules * Fix remote rrdtool_check_rrd_exists() calls (#4196) It was comparing with the full name when rrdcached only printed out the relative name. Thanks mikmak on irc for lots of troubleshooting. * check for no motd line (#4200) Fixes #4199 * Only push the toc down, not the content the toc is on top when the header switches to two lines, so we only need to push that down. * IRC bot - detect lost communication Force reconnect if no data received from server for config['irc_conn_timeout'] seconds (that may happen when network/VPN goes down - in such case IRC bot won't get immediately notification that connection was lost, at least till it tries to send anything). * Update irc.php * Update irc.php * Update irc.php * Update irc.php * fix ifName randomly defined, breaking influxdb updates (#4202) * IRC bot - allow to disable ssl check In PHP 5.6.x stream wrappers verify peer certificates and host names by default when using SSL. That fix allows to turn off that verification with config option $config['irc_disable_ssl_check'] = true; It is useful when you want to use self generated certificate for your own IRC server. * Update irc.php * More more docs (#4197) * Updated docs + some small code changes * Added validating code doc for developers * Doc updates * Updates and improvements * Add ntpd to the list of agentapps (#4194) * Fix deprecated constructors This small change should't prevent easy updates to libraries and fixes the lint check on php7 * Don't allow php7 failures anymore * Fix defunct process issues: create Proc class (#4210) * Proc class Encapsulate processes in a class, when they go out of scope, we can use the __destruct() process to make sure the process terminates. * Fix rrdtool_last checks failing * Don't close rrdtool in rrd_graph Try to start rrdtool process if they haven't been started yet Remove some extra debug output * phpdocs added several cleanups should still be functioning the same Only open one rrdtool process for graph.php * include common.php in definitions.inc.php (#4198) definitions.inc.php makes a call to dbFetchRow, which uses c_echo() It is safe to include common.php here as it only has function definitions. * Use pre-commit.php in for travis-ci tests (#4212) --- .../application/freeswitch_callsIn.inc.php | 35 +++++++++++++++++ .../application/freeswitch_callsOut.inc.php | 35 +++++++++++++++++ .../application/freeswitch_peak.inc.php | 14 +++++++ html/pages/apps.inc.php | 6 +++ html/pages/device/apps/freeswitch.inc.php | 28 +++++++++++++ .../polling/applications/freeswitch.inc.php | 39 +++++++++++++++++++ 6 files changed, 157 insertions(+) create mode 100644 html/includes/graphs/application/freeswitch_callsIn.inc.php create mode 100644 html/includes/graphs/application/freeswitch_callsOut.inc.php create mode 100644 html/includes/graphs/application/freeswitch_peak.inc.php create mode 100644 html/pages/device/apps/freeswitch.inc.php create mode 100644 includes/polling/applications/freeswitch.inc.php diff --git a/html/includes/graphs/application/freeswitch_callsIn.inc.php b/html/includes/graphs/application/freeswitch_callsIn.inc.php new file mode 100644 index 0000000000..3a3a7e5153 --- /dev/null +++ b/html/includes/graphs/application/freeswitch_callsIn.inc.php @@ -0,0 +1,35 @@ + array( + 'descr' => 'Okay', + 'colour' => '008800FF', + ), + 'in_failed' => array( + 'descr' => 'Failed', + 'colour' => '880000FF', + ), + ); + +$i = 0; + +if (rrdtool_check_rrd_exists($rrd_filename)) { + foreach ($array as $ds => $vars) { + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = $vars['descr']; + $rrd_list[$i]['ds'] = $ds; + $rrd_list[$i]['colour'] = $vars['colour']; + $i++; + } +} else { + echo "file missing: $file"; +} + +require 'includes/graphs/generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/application/freeswitch_callsOut.inc.php b/html/includes/graphs/application/freeswitch_callsOut.inc.php new file mode 100644 index 0000000000..c8653abced --- /dev/null +++ b/html/includes/graphs/application/freeswitch_callsOut.inc.php @@ -0,0 +1,35 @@ + array( + 'descr' => 'Okay', + 'colour' => '008800FF', + ), + 'out_failed' => array( + 'descr' => 'Failed', + 'colour' => '880000FF', + ), + ); + +$i = 0; + +if (rrdtool_check_rrd_exists($rrd_filename)) { + foreach ($array as $ds => $vars) { + $rrd_list[$i]['filename'] = $rrd_filename; + $rrd_list[$i]['descr'] = $vars['descr']; + $rrd_list[$i]['ds'] = $ds; + $rrd_list[$i]['colour'] = $vars['colour']; + $i++; + } +} else { + echo "file missing: $file"; +} + +require 'includes/graphs/generic_multi_simplex_seperated.inc.php'; diff --git a/html/includes/graphs/application/freeswitch_peak.inc.php b/html/includes/graphs/application/freeswitch_peak.inc.php new file mode 100644 index 0000000000..d09674b536 --- /dev/null +++ b/html/includes/graphs/application/freeswitch_peak.inc.php @@ -0,0 +1,14 @@ +Apps » "; diff --git a/html/pages/device/apps/freeswitch.inc.php b/html/pages/device/apps/freeswitch.inc.php new file mode 100644 index 0000000000..a1edb5d557 --- /dev/null +++ b/html/pages/device/apps/freeswitch.inc.php @@ -0,0 +1,28 @@ + 'Freeswitch - Peak Calls', + 'freeswitch_callsIn' => 'Freeswitch - Inbound Calls', + 'freeswitch_callsOut' => 'Freeswitch - Outbound Calls' + ); +foreach ($graphs as $key => $text) { + $graph_type = $key; + $graph_array['height'] = '100'; + $graph_array['width'] = '215'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $app['app_id']; + $graph_array['type'] = 'application_'.$key; + + echo '
+
+

'.$text.'

+
+
+
'; + include 'includes/print-graphrow.inc.php'; + echo '
'; + echo '
'; + echo '
'; +} diff --git a/includes/polling/applications/freeswitch.inc.php b/includes/polling/applications/freeswitch.inc.php new file mode 100644 index 0000000000..9b3dd2f6c9 --- /dev/null +++ b/includes/polling/applications/freeswitch.inc.php @@ -0,0 +1,39 @@ + $freeswitch['Calls'], + 'channels' => $freeswitch['Channels'], + 'peak' => $freeswitch['Peak'], + 'in_failed' => $freeswitch['InFailed'], + 'in_okay' => $freeswitch['InTotal']-$freeswitch['InFailed'], + 'out_failed' => $freeswitch['OutFailed'], + 'out_okay' => $freeswitch['OutTotal']-$freeswitch['OutFailed'] + ); +$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def'); +data_update($device, 'app', $tags, $fields); +unset($lines , $freeswitch, $rrd_name, $rrd_def, $fields, $tags); From 863073915fe1ed307de0b271e4b8c845d2e0b5af Mon Sep 17 00:00:00 2001 From: nerdalertdk Date: Fri, 26 Aug 2016 13:17:46 +0200 Subject: [PATCH 19/69] I agree to the conditions of the Contributor Agreement contained in doc/General/Contributing.md. --- AUTHORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index 6b4d4cc4a0..b6ff814f31 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -121,7 +121,7 @@ LibreNMS contributors: - Phil Regnauld (reegnauld) - Russell Morris (arrmo) - Bennett Blodinger (benwa) -- Michael Hansen (nerdalertdk) +- Michael Hansen (nerdalertdk) [1]: http://observium.org/ "Observium web site" Observium was written by: From de84a8142f896406e5ecbf03f399bd0e511f9c08 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Fri, 26 Aug 2016 13:39:24 +0100 Subject: [PATCH 20/69] Update mkdocs.yml --- mkdocs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/mkdocs.yml b/mkdocs.yml index 948b1fe3ee..10c09ac899 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -76,6 +76,7 @@ pages: - Developing/Sensor-State-Support.md - Developing/Style-Guidelines.md - Developing/Using-Git.md + - Developing/Validating-Code.md - API: API/API-Docs.md - Support: - Support/Configuration.md From 8973a78664af07ea581960781d45aaefec0c2eaf Mon Sep 17 00:00:00 2001 From: nerdalertdk Date: Fri, 26 Aug 2016 14:40:05 +0200 Subject: [PATCH 21/69] Update API-Docs.md (#4218) --- doc/API/API-Docs.md | 54 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/doc/API/API-Docs.md b/doc/API/API-Docs.md index 01a4b9e821..1122fa01d8 100644 --- a/doc/API/API-Docs.md +++ b/doc/API/API-Docs.md @@ -1470,9 +1470,38 @@ Output: "err-msg": "", "count": 1, "services": [ - { - "Need example" - } + [ + { + "service_id": "13", + "device_id": "1", + "service_ip": "demo1.yourdomian.net", + "service_type": "ntp_peer", + "service_desc": "NTP", + "service_param": "-H 192.168.1.10", + "service_ignore": "0", + "service_status": "0", + "service_changed": "1470962470", + "service_message": "NTP OK: Offset -0.000717 secs", + "service_disabled": "0", + "service_ds": "{\"offset\":\"s\"}" + } + ], + [ + { + "service_id": "2", + "device_id": "2", + "service_ip": "demo2.yourdomian.net", + "service_type": "esxi_hardware.py", + "service_desc": "vmware hardware", + "service_param": "-H 192.168.1.11 -U USER -P PASS -p", + "service_ignore": "0", + "service_status": "0", + "service_changed": "1471702206", + "service_message": "OK - Server: Supermicro X9SCL/X9SCM s/n: 0123456789 System BIOS: 2.2 2015-02-20", + "service_disabled": "0", + "service_ds": "{\"P2Vol_0_Processor_1_Vcore\":\"\",\"P2Vol_1_System_Board_1_-12V\":\"\",\"P2Vol_2_System_Board_1_12V\":\"\",\"P2Vol_3_System_Board_1_3.3VCC\":\"\",\"P2Vol_4_System_Board_1_5VCC\":\"\",\"P2Vol_5_System_Board_1_AVCC\":\"\",\"P2Vol_6_System_Board_1_VBAT\":\"\",\"P2Vol_7_System_Board_1_" + } + ] ] } ``` @@ -1503,9 +1532,22 @@ Output: "err-msg": "", "count": 1, "services": [ - { - "Need example" - } + [ + { + "service_id": "2", + "device_id": "2", + "service_ip": "demo2.yourdomian.net", + "service_type": "esxi_hardware.py", + "service_desc": "vmware hardware", + "service_param": "-H 192.168.1.11 -U USER -P PASS -p", + "service_ignore": "0", + "service_status": "0", + "service_changed": "1471702206", + "service_message": "OK - Server: Supermicro X9SCL/X9SCM s/n: 0123456789 System BIOS: 2.2 2015-02-20", + "service_disabled": "0", + "service_ds": "{\"P2Vol_0_Processor_1_Vcore\":\"\",\"P2Vol_1_System_Board_1_-12V\":\"\",\"P2Vol_2_System_Board_1_12V\":\"\",\"P2Vol_3_System_Board_1_3.3VCC\":\"\",\"P2Vol_4_System_Board_1_5VCC\":\"\",\"P2Vol_5_System_Board_1_AVCC\":\"\",\"P2Vol_6_System_Board_1_VBAT\":\"\",\"P2Vol_7_System_Board_1_" + } + ] ] } ``` From 15b0cd68ea05e913e94e28d1e8daee69c08cfd8f Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 26 Aug 2016 08:04:21 -0500 Subject: [PATCH 22/69] Move libraries in /includes to /lib (#4217) --- dist-pollers.php | 1 - includes/defaults.inc.php | 8 ++++---- {includes => lib}/console_colour.php | 0 {includes => lib}/console_table.php | 0 {includes => lib}/phpmailer/PHPMailerAutoload.php | 0 {includes => lib}/phpmailer/class.phpmailer.php | 0 {includes => lib}/phpmailer/class.smtp.php | 0 7 files changed, 4 insertions(+), 5 deletions(-) rename {includes => lib}/console_colour.php (100%) rename {includes => lib}/console_table.php (100%) rename {includes => lib}/phpmailer/PHPMailerAutoload.php (100%) rename {includes => lib}/phpmailer/class.phpmailer.php (100%) rename {includes => lib}/phpmailer/class.smtp.php (100%) diff --git a/dist-pollers.php b/dist-pollers.php index e3f016af4d..1e3934ffcc 100755 --- a/dist-pollers.php +++ b/dist-pollers.php @@ -21,7 +21,6 @@ require 'includes/definitions.inc.php'; require 'includes/functions.php'; require 'includes/polling/functions.inc.php'; require 'includes/alerts.inc.php'; -require 'includes/console_table.php'; $options = getopt('l:u:r::'); diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index f692b14ce0..1f3a6d28b3 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -39,10 +39,10 @@ $config['install_dir'] = realpath(__DIR__ . '/..'); // initialize the class loader and add custom mappings require_once $config['install_dir'] . '/LibreNMS/ClassLoader.php'; $classLoader = new LibreNMS\ClassLoader(); -$classLoader->registerClass('Console_Color2', $config['install_dir'] . '/includes/console_colour.php'); -$classLoader->registerClass('Console_Table', $config['install_dir'] . '/includes/console_table.php'); -$classLoader->registerClass('PHPMailer', $config['install_dir'] . "/includes/phpmailer/class.phpmailer.php"); -$classLoader->registerClass('SMTP', $config['install_dir'] . "/includes/phpmailer/class.smtp.php"); +$classLoader->registerClass('Console_Color2', $config['install_dir'] . '/lib/console_colour.php'); +$classLoader->registerClass('Console_Table', $config['install_dir'] . '/lib/console_table.php'); +$classLoader->registerClass('PHPMailer', $config['install_dir'] . "/lib/phpmailer/class.phpmailer.php"); +$classLoader->registerClass('SMTP', $config['install_dir'] . "/lib/phpmailer/class.smtp.php"); $classLoader->registerClass('PasswordHash', $config['install_dir'] . '/html/lib/PasswordHash.php'); $classLoader->register(); diff --git a/includes/console_colour.php b/lib/console_colour.php similarity index 100% rename from includes/console_colour.php rename to lib/console_colour.php diff --git a/includes/console_table.php b/lib/console_table.php similarity index 100% rename from includes/console_table.php rename to lib/console_table.php diff --git a/includes/phpmailer/PHPMailerAutoload.php b/lib/phpmailer/PHPMailerAutoload.php similarity index 100% rename from includes/phpmailer/PHPMailerAutoload.php rename to lib/phpmailer/PHPMailerAutoload.php diff --git a/includes/phpmailer/class.phpmailer.php b/lib/phpmailer/class.phpmailer.php similarity index 100% rename from includes/phpmailer/class.phpmailer.php rename to lib/phpmailer/class.phpmailer.php diff --git a/includes/phpmailer/class.smtp.php b/lib/phpmailer/class.smtp.php similarity index 100% rename from includes/phpmailer/class.smtp.php rename to lib/phpmailer/class.smtp.php From e2a043125b2d4e8adb1154001fe58f371d9a0c2a Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 26 Aug 2016 09:37:00 -0500 Subject: [PATCH 23/69] influx-db, commas should be periods (#4222) Noticed this while looking at psr-2 changes --- includes/influxdb.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/influxdb.inc.php b/includes/influxdb.inc.php index 34f64aadd7..5325871f86 100644 --- a/includes/influxdb.inc.php +++ b/includes/influxdb.inc.php @@ -82,7 +82,7 @@ function influx_update($device,$measurement,$tags=array(),$fields) { try { $result = $influxdb->writePoints($points); } catch (Exception $e) { - d_echo("Caught exception: ", $e->getMessage(), "\n"); + d_echo("Caught exception: " . $e->getMessage() . PHP_EOL); d_echo($e->getTrace()); } } From 4838f905e3a633c00e237bf3296a530d49c2160d Mon Sep 17 00:00:00 2001 From: cromagdk Date: Fri, 26 Aug 2016 20:07:16 +0200 Subject: [PATCH 24/69] Update Applications.md (#4226) --- doc/Extensions/Applications.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/Extensions/Applications.md b/doc/Extensions/Applications.md index 54e457a992..6c388d050a 100644 --- a/doc/Extensions/Applications.md +++ b/doc/Extensions/Applications.md @@ -28,7 +28,7 @@ Different applications support a variety of ways collect data: by direct connect ##### SNMP Extend 1. Download the script onto the desired host (the host must be added to LibreNMS devices) ``` -wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/apache-stats.py -o /etc/snmp/apache-stats.py +wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/apache-stats.py -O /etc/snmp/apache-stats.py ``` 2. Make the script executable (chmod +x /etc/snmp/apache-stats.py) 3. Edit your snmpd.conf file (usually /etc/snmp/snmpd.conf) and add: @@ -37,7 +37,7 @@ extend apache /etc/snmp/apache-stats.py ``` 4. Restart snmpd on your host 5. On the device page in Librenms, edit your host and check the `Apache` under the Applications tab. - +(In some cases urlgrabber needs to be installed, in Debian it can be achieved by: apt-get install python-urlgrabber) ### BIND9 aka named From aee05e858f52a50cd88dc71bf7c3f26b50314f95 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 26 Aug 2016 13:08:31 -0500 Subject: [PATCH 25/69] Fix wget option wget -o -> wget -O --- doc/Extensions/Applications.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/Extensions/Applications.md b/doc/Extensions/Applications.md index 6c388d050a..bc2361123b 100644 --- a/doc/Extensions/Applications.md +++ b/doc/Extensions/Applications.md @@ -88,7 +88,7 @@ extend dhcpstats /opt/dhcp-status.sh ##### SNMP Extend 1. Download the script onto the desired host (the host must be added to LibreNMS devices) ``` -wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/mailscanner.php -o /etc/snmp/mailscanner.php +wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/mailscanner.php -O /etc/snmp/mailscanner.php ``` 2. Make the script executable (chmod +x /etc/snmp/mailscanner.php) 3. Edit your snmpd.conf file (usually /etc/snmp/snmpd.conf) and add: @@ -158,7 +158,7 @@ Supports NTPD Server (not client, that is separate) ##### SNMP Extend 1. Download the script onto the desired host (the host must be added to LibreNMS devices) ``` -wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/ntpd-server.php -o /etc/snmp/ntpd-server.php +wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/ntpd-server.php -O /etc/snmp/ntpd-server.php ``` 2. Make the script executable (chmod +x /etc/snmp/ntdp-server.php) 3. Edit your snmpd.conf file (usually /etc/snmp/snmpd.conf) and add: @@ -222,7 +222,7 @@ This script uses `rec_control get-all` to collect stats. ### Proxmox 1. Download the script onto the desired host (the host must be added to LibreNMS devices) -`wget https://github.com/librenms/librenms-agent/blob/master/agent-local/proxmox -o /usr/local/bin/proxmox` +`wget https://github.com/librenms/librenms-agent/blob/master/agent-local/proxmox -O /usr/local/bin/proxmox` 2. Make the script executable: `chmod +x /usr/local/proxmox` 3. Edit your snmpd.conf file (usually `/etc/snmp/snmpd.conf`) and add: `extend proxmox /usr/local/bin/proxmox` From acde0db434d864c0308d7041eedb5d3cc8a1a0a5 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sat, 27 Aug 2016 00:09:58 +0100 Subject: [PATCH 26/69] More doc updates --- .gitignore | 1 + AUTHORS.md | 7 ++--- doc/Developing/Creating-Documentation.md | 33 ++++++++++++++++++++++++ doc/Support/FAQ.md | 15 ++++++++++- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 2f7c08a528..320f355c89 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ patches rrd /vendor composer.phar +/librenms_theme diff --git a/AUTHORS.md b/AUTHORS.md index b6ff814f31..5a5de4f33d 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -1,6 +1,4 @@ -LibreNMS is a fork of [Observium][1]. - -LibreNMS core team: +### LibreNMS core team: - Paul Gear (paulgear) - Neil Lathwood (laf) - Daniel Preussker (f0o) @@ -8,7 +6,7 @@ LibreNMS core team: - Mike Rostermund (SaaldjorMike) - Tony Murray (murrant) -LibreNMS contributors: +### LibreNMS contributors: - Bohdan Sanders (bohdan-s) - Toni Cunyat (elbuit) - Tuomas Riihimäki (tuomari) @@ -123,7 +121,6 @@ LibreNMS contributors: - Bennett Blodinger (benwa) - Michael Hansen (nerdalertdk) -[1]: http://observium.org/ "Observium web site" Observium was written by: - Adam Armstrong - Tom Laermans diff --git a/doc/Developing/Creating-Documentation.md b/doc/Developing/Creating-Documentation.md index 98787952dd..4f0a29576c 100644 --- a/doc/Developing/Creating-Documentation.md +++ b/doc/Developing/Creating-Documentation.md @@ -1,6 +1,7 @@ source: Developing/Creating-Documentation.md # Creating Documentation +### Writing documentation One of the goals of the LibreNMS project is to enable users to get all of the help they need from our documentation. When you are adding a new feature or extension, we need to have full documentation to go along with it. It's quite @@ -16,3 +17,35 @@ simple to do this: Please ensure you add the document to the relevant section within `pages` of `mkdocs.yml` so that it's in the correct menu and is built. Forgetting this step will result in your document never seeing the light of day :) + +### Building documentation +Our build process in GitHub automatically builds http://docs.librenms.org from everything in the `doc/` folder. You can simulate this +process to test what the docs will look like before you submit your PR. + +We use [mkdocs](http://www.mkdocs.org/) to build the documentation so you need to install that first (we assume you have `pip` installed): + +```bash +pip install --user mkdocs +pip install --user pymdown-extensions +``` + +Now you will need to install the LibreNMS theme: + +```bash +git clone https://github.com/librenms-docs/librenms_theme.git +``` + +Now you are ready to build your docs and check them, you can do this with mkdocs: + +```bash +mkdocs serve +``` + +This will launch a web service on localhost port 8000. You can change the port or bind the web server to a different IP by adding +` -a 0.0.0.0:8080` + +You can also build the documentation as html files to place them somewhere to test. To do this run: + +```bash +mkdocs build --clean +``` diff --git a/doc/Support/FAQ.md b/doc/Support/FAQ.md index 2321c0c22b..5e7c0e22c8 100644 --- a/doc/Support/FAQ.md +++ b/doc/Support/FAQ.md @@ -19,6 +19,7 @@ source: Support/FAQ.md - [My device doesn't finish polling within 300 seconds](#faq19) - [Things aren't working correctly?](#faq18) - [What do the values mean in my graphs?](#faq21) + - [How can I move my LibreNMS install to another server?](#faq22) ### Developing - [How do I add support for a new OS?](#faq8) @@ -143,7 +144,7 @@ Re-run `./validate.php` once you've resolved any issues raised. You have an odd issue - we'd suggest you join our irc channel to discuss. -#### What do the values mean in my graphs? +#### What do the values mean in my graphs? The values you see are reported as metric values. Thanks to a post on [Reddit](https://www.reddit.com/r/networking/comments/4xzpfj/rrd_graph_interface_error_label_what_is_the_m/) here are those values: @@ -163,6 +164,18 @@ here are those values: 10^15 P - peta ``` +#### How can I move my LibreNMS install to another server? + +If you are moving from one CPU architecture to another then you will need to dump the rrd files and re-create them. If you are in +this scenario then you can use [Dan Brown's migration scripts](How can I move my LibreNMS install to another server?). + +If you are just moving to another server with the same CPU architecture then the following steps should be all that's needed: + + - Install LibreNMS as per our normal documentation, you don't need to run through the web installer or building the sql schema. + - Dump the MySQL database `librenms` and import this into your new server. + - Copy the `rrd/` folder to the new server. + - Copy the `config.php` file to the new server. + #### 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 5d51d888f65af1bca9f79b8711e5404d036a7c3c Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sat, 27 Aug 2016 13:42:45 +0100 Subject: [PATCH 27/69] Corrected link --- doc/Support/FAQ.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Support/FAQ.md b/doc/Support/FAQ.md index 5e7c0e22c8..609e42d919 100644 --- a/doc/Support/FAQ.md +++ b/doc/Support/FAQ.md @@ -167,7 +167,7 @@ here are those values: #### How can I move my LibreNMS install to another server? If you are moving from one CPU architecture to another then you will need to dump the rrd files and re-create them. If you are in -this scenario then you can use [Dan Brown's migration scripts](How can I move my LibreNMS install to another server?). +this scenario then you can use [Dan Brown's migration scripts](https://vlan50.com/2015/04/17/migrating-from-observium-to-librenms/). If you are just moving to another server with the same CPU architecture then the following steps should be all that's needed: From 2c0b57d61edcd3c182b8c51f8b49ef0d59c9737b Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sat, 27 Aug 2016 13:53:45 +0100 Subject: [PATCH 28/69] chore(release): 201607 --- CHANGELOG.md | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 10 +++++ 2 files changed, 118 insertions(+) create mode 100644 CHANGELOG.md create mode 100644 package.json diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000..042f669a44 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,108 @@ +# Change Log + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + + +# (2016-08-27) + + +### Bug Fixes + +* add resize.min_size option to default config object ([5672edb](https://github.com/laf/librenms/commit/5672edb)) +* Apply fix from [#22](https://github.com/librenms/librenms/issues/22) to vertical positioning ([dfc6491](https://github.com/laf/librenms/commit/dfc6491)) +* convert from JQury to DOM ([4936ef8](https://github.com/laf/librenms/commit/4936ef8)) +* fixes and improvements in widget-resizing. Closes [#32](https://github.com/librenms/librenms/issues/32) ([ae02b32](https://github.com/laf/librenms/commit/ae02b32)) +* forgot about the nicecase ([a6e72db](https://github.com/laf/librenms/commit/a6e72db)) +* recalculate grid width when adding widgets ([4774597](https://github.com/laf/librenms/commit/4774597)) +* **draggable:** namespace events with unique ids ([79aff38](https://github.com/laf/librenms/commit/79aff38)) +* sensor id for rrd file ([b201e64](https://github.com/laf/librenms/commit/b201e64)) +* setting user port permissions fails ([b52b493](https://github.com/laf/librenms/commit/b52b493)) +* strstr won't return anything if nfsensuffix is empty ([7817021](https://github.com/laf/librenms/commit/7817021)) +* **gridster:** sort widgets appropriately when reading them from DOM ([5c6d25c](https://github.com/laf/librenms/commit/5c6d25c)) +* use entPhysicalDescr if entPhysicalName is empty ([ad4562d](https://github.com/laf/librenms/commit/ad4562d)) +* **autogrow:** refining autogrow_cols behavior and grid width issues ([835c2df](https://github.com/laf/librenms/commit/835c2df)) +* **draggable:** bind drag events to $document ([dd6c742](https://github.com/laf/librenms/commit/dd6c742)) +* **draggable:** fix offset during drag ([c726c4a](https://github.com/laf/librenms/commit/c726c4a)) +* **draggable:** handle both touch and click events ([021a6c2](https://github.com/laf/librenms/commit/021a6c2)), closes [#207](https://github.com/laf/librenms/issues/207) [#236](https://github.com/laf/librenms/issues/236) [#329](https://github.com/laf/librenms/issues/329) [#380](https://github.com/laf/librenms/issues/380) +* **draggable:** replaced scrollX/Y with scrollLeft/Top ([bb7463a](https://github.com/laf/librenms/commit/bb7463a)) +* **generated-styles:** cleaning cached serializations properly ([f8b04f2](https://github.com/laf/librenms/commit/f8b04f2)) +* **gridster:** `resize_widget` also accepts HTMLElements ([cda560f](https://github.com/laf/librenms/commit/cda560f)) +* **gridster:** Add additiona error checking on widgets removal ([2b0f996](https://github.com/laf/librenms/commit/2b0f996)) +* **gridster:** adding bower.json file ([7654437](https://github.com/laf/librenms/commit/7654437)) +* **gridster:** adding bower.json file ([fa29663](https://github.com/laf/librenms/commit/fa29663)) +* **gridster:** changed "instanceof jQuery" to "instanceof $" ([c622630](https://github.com/laf/librenms/commit/c622630)) +* **gridster:** changed the way widgets were getting positioned so that margins are actually the same size that the user specified all the way around the grid ([a391304](https://github.com/laf/librenms/commit/a391304)) +* **gridster:** custom `ignore_dragging` overwrites the default value ([6bcfa6e](https://github.com/laf/librenms/commit/6bcfa6e)) +* **gridster:** destroy resize_api ([b162932](https://github.com/laf/librenms/commit/b162932)), closes [#473](https://github.com/laf/librenms/issues/473) +* **gridster:** ensure coords instances are destroyed on widgets ([576b5ae](https://github.com/laf/librenms/commit/576b5ae)) +* **gridster:** ensure widget dimensions and coords are always ints ([595a94f](https://github.com/laf/librenms/commit/595a94f)) +* **gridster:** fire `positionschanged` when widget orig position changes ([9926cef](https://github.com/laf/librenms/commit/9926cef)) +* **gridster:** fix add_widget to use correct size_y when adding rows ([7d22e6c](https://github.com/laf/librenms/commit/7d22e6c)) +* **gridster:** fixed bugs in centering_widgets (widgets were getting smushed when being resized) and fixed bug with min_width ([86053f8](https://github.com/laf/librenms/commit/86053f8)) +* **gridster:** fixed expand_widget bug not expanding full width of window ([dbc226d](https://github.com/laf/librenms/commit/dbc226d)) +* **gridster:** fixes bug where widgets would overlay other widgets after a resize ([61572cd](https://github.com/laf/librenms/commit/61572cd)) +* **gridster:** fixing drag limit issues when using autogrow_cols ([afd83fe](https://github.com/laf/librenms/commit/afd83fe)) +* **gridster:** fixing resize limits when in fixed width mode ([6bb47dc](https://github.com/laf/librenms/commit/6bb47dc)) +* **gridster:** forcing height of gridster container to auto when in collapsed mode ([749f37a](https://github.com/laf/librenms/commit/749f37a)) +* **gridster:** leaking options with multiple Gridster instances ([7ed79e5](https://github.com/laf/librenms/commit/7ed79e5)) +* **gridster:** Orphan preview holder when dragging is interrupted ([1b13617](https://github.com/laf/librenms/commit/1b13617)) +* **gridster:** overlapping widget problem ([31fd8d6](https://github.com/laf/librenms/commit/31fd8d6)) +* **gridster:** preventing gridster from adding extra resize handles ([9d077da](https://github.com/laf/librenms/commit/9d077da)) +* **gridster:** remove_widget Returns the instance of the Gridster Class ([5bfbc5c](https://github.com/laf/librenms/commit/5bfbc5c)) +* **gridster:** Removing previously added style tags before adding new one. ([93c46ff](https://github.com/laf/librenms/commit/93c46ff)), closes [#211](https://github.com/laf/librenms/issues/211) [#294](https://github.com/laf/librenms/issues/294) +* **gridster:** resize.axes default option only 'both' ([e9dc513](https://github.com/laf/librenms/commit/e9dc513)) +* **gridster:** responsive width now resizes based off wrapper not window ([e69c3e8](https://github.com/laf/librenms/commit/e69c3e8)) +* **gridster:** serialize returns an Array object, not a jQuery object ([93df6cf](https://github.com/laf/librenms/commit/93df6cf)), closes [#394](https://github.com/laf/librenms/issues/394) +* wrong variable used ([87eb2a6](https://github.com/laf/librenms/commit/87eb2a6)) +* **gridster:** the preview holder should not always use `li` ([1ade74e](https://github.com/laf/librenms/commit/1ade74e)) +* **gridster:** wrong addition solved in add_faux_rows/cols by adding parseInt ([d947175](https://github.com/laf/librenms/commit/d947175)), closes [#426](https://github.com/laf/librenms/issues/426) [#425](https://github.com/laf/librenms/issues/425) +* **licenses:** add required copyright message for underscore ([6f20723](https://github.com/laf/librenms/commit/6f20723)) +* **readme:** link title jsfiddle -> jsbin, edit 5) of process steps ([e9d8d8d](https://github.com/laf/librenms/commit/e9d8d8d)) +* **resize.stop:** Call resize.stop at the latest possible moment ([e21f63a](https://github.com/laf/librenms/commit/e21f63a)) + + +### Chores + +* **css naming:** `gs_w` to `gs-w` following CSS naming conventions ([c1668d9](https://github.com/laf/librenms/commit/c1668d9)) +* **draggable:** jQuery adapter returns Draggable instance ([d0ca628](https://github.com/laf/librenms/commit/d0ca628)) + + +### Features + +* **collision:** overlapping region as a config option ([720d487](https://github.com/laf/librenms/commit/720d487)) +* **coords:** add destroy method ([fdeee4f](https://github.com/laf/librenms/commit/fdeee4f)) +* **coords:** allow both (left/x1) and (top/y1) attr keys ([6f22217](https://github.com/laf/librenms/commit/6f22217)) +* **draggable:** Add toggle draggable method. ([073fdc4](https://github.com/laf/librenms/commit/073fdc4)) +* **draggable:** allow ignore_dragging config option to be a function ([69fcfe4](https://github.com/laf/librenms/commit/69fcfe4)) +* **draggable:** autoscrolling ([d3f25f3](https://github.com/laf/librenms/commit/d3f25f3)) +* **draggable:** CSS selectors support in `ignore_dragging` config opt ([0f95624](https://github.com/laf/librenms/commit/0f95624)) +* **draggable:** Don't start new drag if previous one hasn't stopped ([91ca657](https://github.com/laf/librenms/commit/91ca657)) +* **draggable:** keep container position prop if different than static ([04868a3](https://github.com/laf/librenms/commit/04868a3)) +* **draggable:** method to set drag limits dynamically ([8fa3ad2](https://github.com/laf/librenms/commit/8fa3ad2)) +* **draggable:** new config option to move or not the dragged element ([4d9b2a8](https://github.com/laf/librenms/commit/4d9b2a8)) +* **draggable:** option to not remove helper on drag stop ([03910df](https://github.com/laf/librenms/commit/03910df)) +* **draggable:** pass previous position to the drag callback ([055cc0e](https://github.com/laf/librenms/commit/055cc0e)) +* **draggable:** pass useful data to all drag callbacks ([8dda241](https://github.com/laf/librenms/commit/8dda241)) +* **draggable:** support horizontal scrolling while dragging ([b0b4464](https://github.com/laf/librenms/commit/b0b4464)) +* **gridster:** add config to set custom show/hide widget methods ([7de5bba](https://github.com/laf/librenms/commit/7de5bba)) +* **gridster:** browserify compatibility ([43148b8](https://github.com/laf/librenms/commit/43148b8)) +* **gridster:** Common.js support ([446852a](https://github.com/laf/librenms/commit/446852a)), closes [#434](https://github.com/laf/librenms/issues/434) +* **gridster:** destroy element's data and optionally remove from DOM ([dc09f19](https://github.com/laf/librenms/commit/dc09f19)) +* **gridster:** drag-and-drop widget resizing ([e192405](https://github.com/laf/librenms/commit/e192405)) +* **gridster:** increase grid width when dragging or resizing ([b65a802](https://github.com/laf/librenms/commit/b65a802)) +* **gridster:** move widget up when added if there is space available ([8ec307b](https://github.com/laf/librenms/commit/8ec307b)) +* **gridster.css:** remove possible default pading ([2002c45](https://github.com/laf/librenms/commit/2002c45)) +* **resize:** add option to set min_size of a widget ([429c776](https://github.com/laf/librenms/commit/429c776)) +* **resize:** Add start/stop/resize callbacks ([d4ec714](https://github.com/laf/librenms/commit/d4ec714)) +* **resize:** add start/stop/resize event triggers ([7ca8dee](https://github.com/laf/librenms/commit/7ca8dee)) +* **utils:** add delay helper to utils ([faa6c5d](https://github.com/laf/librenms/commit/faa6c5d)) +* make gridster AMD compatible ([589d7fd](https://github.com/laf/librenms/commit/589d7fd)) + + +### BREAKING CHANGES + +* draggable: If you was accessing to Draggable instances through +.data('drag') you should remove the `data` getter. Since now the instance +is returned directly. +* css naming: If you are using `gs_w` classes somewhere, replace +them with `gs-w` diff --git a/package.json b/package.json new file mode 100644 index 0000000000..7fbd8c27c9 --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "name": "LibreNMS", + "version": "201607", + "description": "LibreNMS is an autodiscovering network monitoring system", + "repository": { + "type": "git", + "url": "git+https://github.com/librenms/librenms.git" + }, + "license": "GPLv3" +} From 8924e954c4ce18e3428fd4b225b871c89b701969 Mon Sep 17 00:00:00 2001 From: nerdalertdk Date: Sat, 27 Aug 2016 15:46:54 +0200 Subject: [PATCH 29/69] Missing variable in services api call fix: Missing variable in services api call --- doc/API/API-Docs.md | 61 ++++++----------------------- html/includes/api_functions.inc.php | 3 +- 2 files changed, 14 insertions(+), 50 deletions(-) diff --git a/doc/API/API-Docs.md b/doc/API/API-Docs.md index 1122fa01d8..320c434285 100644 --- a/doc/API/API-Docs.md +++ b/doc/API/API-Docs.md @@ -790,56 +790,19 @@ Output: ```text [ { - "status": "error", - "message": "Found 1 in group LinuxServers", - "count": 1, + "status": "ok", + "message": "Found 3 in group LinuxServers", + "count": 3, "devices": [ - { - "device_id": "1", - "hostname": "localhost", - "sysName": "hostname", - "community": "librenms", - "authlevel": null, - "authname": null, - "authpass": null, - "authalgo": null, - "cryptopass": null, - "cryptoalgo": null, - "snmpver": "v2c", - "port": "161", - "transport": "udp", - "timeout": null, - "retries": null, - "bgpLocalAs": null, - "sysObjectID": ".1.3.6.1.4.1.8072.3.2.10", - "sysDescr": "Linux li1045-133.members.linode.com 4.1.5-x86_64-linode61 #7 SMP Mon Aug 24 13:46:31 EDT 2015 x86_64", - "sysContact": "", - "version": "4.1.5-x86_64-linode61", - "hardware": "Generic x86 64-bit", - "features": "CentOS 7.1.1503", - "location": "", - "os": "linux", - "status": "1", - "status_reason": "", - "ignore": "0", - "disabled": "0", - "uptime": "4615964", - "agent_uptime": "0", - "last_polled": "2015-12-12 13:20:04", - "last_poll_attempted": null, - "last_polled_timetaken": "1.90", - "last_discovered_timetaken": "79.53", - "last_discovered": "2015-12-12 12:34:21", - "last_ping": "2015-12-12 13:20:04", - "last_ping_timetaken": "0.08", - "purpose": null, - "type": "server", - "serial": null, - "icon": null, - "poller_group": "0", - "override_sysLocation": "0", - "notes": "Nope" - } + { + "device_id": "15" + }, + { + "device_id": "18" + }, + { + "device_id": "20" + } ] } ] diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index 8966b4806e..46c91f82ac 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -1222,6 +1222,7 @@ function get_devices_by_group() $message = 'No devices found in group ' . $name; } else { $message = "Found $count in group $name"; + $status = 'ok'; $code = 200; } } @@ -1352,7 +1353,7 @@ function list_services() $sql_param[1] = $_GET['type']; } - $services[] = dbFetchRows("SELECT * FROM `services` WHERE `device_id` = ?".$devicewhere, $sql_param); + $services = dbFetchRows("SELECT * FROM `services` WHERE `device_id` = ?".$devicewhere, $sql_param); } $count = count($services); $output = array( From 87745cad7af2d8125c400b0141c6c2ec47e9f82f Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sat, 27 Aug 2016 15:31:51 +0100 Subject: [PATCH 30/69] Removed option to mkdocs build from creating-documentation.md --- doc/Developing/Creating-Documentation.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/Developing/Creating-Documentation.md b/doc/Developing/Creating-Documentation.md index 4f0a29576c..c8058671d9 100644 --- a/doc/Developing/Creating-Documentation.md +++ b/doc/Developing/Creating-Documentation.md @@ -44,8 +44,3 @@ mkdocs serve This will launch a web service on localhost port 8000. You can change the port or bind the web server to a different IP by adding ` -a 0.0.0.0:8080` -You can also build the documentation as html files to place them somewhere to test. To do this run: - -```bash -mkdocs build --clean -``` From dcff4d3ed138dc4ae738cc0364ef5680c7afcedb Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sat, 27 Aug 2016 22:12:44 +0100 Subject: [PATCH 31/69] Revert "Some more doc updates" (#4231) --- .gitignore | 1 - AUTHORS.md | 7 +- CHANGELOG.md | 108 ----------------------- doc/Developing/Creating-Documentation.md | 28 ------ doc/Support/FAQ.md | 15 +--- package.json | 10 --- 6 files changed, 6 insertions(+), 163 deletions(-) delete mode 100644 CHANGELOG.md delete mode 100644 package.json diff --git a/.gitignore b/.gitignore index 320f355c89..2f7c08a528 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,3 @@ patches rrd /vendor composer.phar -/librenms_theme diff --git a/AUTHORS.md b/AUTHORS.md index 5a5de4f33d..b6ff814f31 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -1,4 +1,6 @@ -### LibreNMS core team: +LibreNMS is a fork of [Observium][1]. + +LibreNMS core team: - Paul Gear (paulgear) - Neil Lathwood (laf) - Daniel Preussker (f0o) @@ -6,7 +8,7 @@ - Mike Rostermund (SaaldjorMike) - Tony Murray (murrant) -### LibreNMS contributors: +LibreNMS contributors: - Bohdan Sanders (bohdan-s) - Toni Cunyat (elbuit) - Tuomas Riihimäki (tuomari) @@ -121,6 +123,7 @@ - Bennett Blodinger (benwa) - Michael Hansen (nerdalertdk) +[1]: http://observium.org/ "Observium web site" Observium was written by: - Adam Armstrong - Tom Laermans diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 042f669a44..0000000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,108 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. - - -# (2016-08-27) - - -### Bug Fixes - -* add resize.min_size option to default config object ([5672edb](https://github.com/laf/librenms/commit/5672edb)) -* Apply fix from [#22](https://github.com/librenms/librenms/issues/22) to vertical positioning ([dfc6491](https://github.com/laf/librenms/commit/dfc6491)) -* convert from JQury to DOM ([4936ef8](https://github.com/laf/librenms/commit/4936ef8)) -* fixes and improvements in widget-resizing. Closes [#32](https://github.com/librenms/librenms/issues/32) ([ae02b32](https://github.com/laf/librenms/commit/ae02b32)) -* forgot about the nicecase ([a6e72db](https://github.com/laf/librenms/commit/a6e72db)) -* recalculate grid width when adding widgets ([4774597](https://github.com/laf/librenms/commit/4774597)) -* **draggable:** namespace events with unique ids ([79aff38](https://github.com/laf/librenms/commit/79aff38)) -* sensor id for rrd file ([b201e64](https://github.com/laf/librenms/commit/b201e64)) -* setting user port permissions fails ([b52b493](https://github.com/laf/librenms/commit/b52b493)) -* strstr won't return anything if nfsensuffix is empty ([7817021](https://github.com/laf/librenms/commit/7817021)) -* **gridster:** sort widgets appropriately when reading them from DOM ([5c6d25c](https://github.com/laf/librenms/commit/5c6d25c)) -* use entPhysicalDescr if entPhysicalName is empty ([ad4562d](https://github.com/laf/librenms/commit/ad4562d)) -* **autogrow:** refining autogrow_cols behavior and grid width issues ([835c2df](https://github.com/laf/librenms/commit/835c2df)) -* **draggable:** bind drag events to $document ([dd6c742](https://github.com/laf/librenms/commit/dd6c742)) -* **draggable:** fix offset during drag ([c726c4a](https://github.com/laf/librenms/commit/c726c4a)) -* **draggable:** handle both touch and click events ([021a6c2](https://github.com/laf/librenms/commit/021a6c2)), closes [#207](https://github.com/laf/librenms/issues/207) [#236](https://github.com/laf/librenms/issues/236) [#329](https://github.com/laf/librenms/issues/329) [#380](https://github.com/laf/librenms/issues/380) -* **draggable:** replaced scrollX/Y with scrollLeft/Top ([bb7463a](https://github.com/laf/librenms/commit/bb7463a)) -* **generated-styles:** cleaning cached serializations properly ([f8b04f2](https://github.com/laf/librenms/commit/f8b04f2)) -* **gridster:** `resize_widget` also accepts HTMLElements ([cda560f](https://github.com/laf/librenms/commit/cda560f)) -* **gridster:** Add additiona error checking on widgets removal ([2b0f996](https://github.com/laf/librenms/commit/2b0f996)) -* **gridster:** adding bower.json file ([7654437](https://github.com/laf/librenms/commit/7654437)) -* **gridster:** adding bower.json file ([fa29663](https://github.com/laf/librenms/commit/fa29663)) -* **gridster:** changed "instanceof jQuery" to "instanceof $" ([c622630](https://github.com/laf/librenms/commit/c622630)) -* **gridster:** changed the way widgets were getting positioned so that margins are actually the same size that the user specified all the way around the grid ([a391304](https://github.com/laf/librenms/commit/a391304)) -* **gridster:** custom `ignore_dragging` overwrites the default value ([6bcfa6e](https://github.com/laf/librenms/commit/6bcfa6e)) -* **gridster:** destroy resize_api ([b162932](https://github.com/laf/librenms/commit/b162932)), closes [#473](https://github.com/laf/librenms/issues/473) -* **gridster:** ensure coords instances are destroyed on widgets ([576b5ae](https://github.com/laf/librenms/commit/576b5ae)) -* **gridster:** ensure widget dimensions and coords are always ints ([595a94f](https://github.com/laf/librenms/commit/595a94f)) -* **gridster:** fire `positionschanged` when widget orig position changes ([9926cef](https://github.com/laf/librenms/commit/9926cef)) -* **gridster:** fix add_widget to use correct size_y when adding rows ([7d22e6c](https://github.com/laf/librenms/commit/7d22e6c)) -* **gridster:** fixed bugs in centering_widgets (widgets were getting smushed when being resized) and fixed bug with min_width ([86053f8](https://github.com/laf/librenms/commit/86053f8)) -* **gridster:** fixed expand_widget bug not expanding full width of window ([dbc226d](https://github.com/laf/librenms/commit/dbc226d)) -* **gridster:** fixes bug where widgets would overlay other widgets after a resize ([61572cd](https://github.com/laf/librenms/commit/61572cd)) -* **gridster:** fixing drag limit issues when using autogrow_cols ([afd83fe](https://github.com/laf/librenms/commit/afd83fe)) -* **gridster:** fixing resize limits when in fixed width mode ([6bb47dc](https://github.com/laf/librenms/commit/6bb47dc)) -* **gridster:** forcing height of gridster container to auto when in collapsed mode ([749f37a](https://github.com/laf/librenms/commit/749f37a)) -* **gridster:** leaking options with multiple Gridster instances ([7ed79e5](https://github.com/laf/librenms/commit/7ed79e5)) -* **gridster:** Orphan preview holder when dragging is interrupted ([1b13617](https://github.com/laf/librenms/commit/1b13617)) -* **gridster:** overlapping widget problem ([31fd8d6](https://github.com/laf/librenms/commit/31fd8d6)) -* **gridster:** preventing gridster from adding extra resize handles ([9d077da](https://github.com/laf/librenms/commit/9d077da)) -* **gridster:** remove_widget Returns the instance of the Gridster Class ([5bfbc5c](https://github.com/laf/librenms/commit/5bfbc5c)) -* **gridster:** Removing previously added style tags before adding new one. ([93c46ff](https://github.com/laf/librenms/commit/93c46ff)), closes [#211](https://github.com/laf/librenms/issues/211) [#294](https://github.com/laf/librenms/issues/294) -* **gridster:** resize.axes default option only 'both' ([e9dc513](https://github.com/laf/librenms/commit/e9dc513)) -* **gridster:** responsive width now resizes based off wrapper not window ([e69c3e8](https://github.com/laf/librenms/commit/e69c3e8)) -* **gridster:** serialize returns an Array object, not a jQuery object ([93df6cf](https://github.com/laf/librenms/commit/93df6cf)), closes [#394](https://github.com/laf/librenms/issues/394) -* wrong variable used ([87eb2a6](https://github.com/laf/librenms/commit/87eb2a6)) -* **gridster:** the preview holder should not always use `li` ([1ade74e](https://github.com/laf/librenms/commit/1ade74e)) -* **gridster:** wrong addition solved in add_faux_rows/cols by adding parseInt ([d947175](https://github.com/laf/librenms/commit/d947175)), closes [#426](https://github.com/laf/librenms/issues/426) [#425](https://github.com/laf/librenms/issues/425) -* **licenses:** add required copyright message for underscore ([6f20723](https://github.com/laf/librenms/commit/6f20723)) -* **readme:** link title jsfiddle -> jsbin, edit 5) of process steps ([e9d8d8d](https://github.com/laf/librenms/commit/e9d8d8d)) -* **resize.stop:** Call resize.stop at the latest possible moment ([e21f63a](https://github.com/laf/librenms/commit/e21f63a)) - - -### Chores - -* **css naming:** `gs_w` to `gs-w` following CSS naming conventions ([c1668d9](https://github.com/laf/librenms/commit/c1668d9)) -* **draggable:** jQuery adapter returns Draggable instance ([d0ca628](https://github.com/laf/librenms/commit/d0ca628)) - - -### Features - -* **collision:** overlapping region as a config option ([720d487](https://github.com/laf/librenms/commit/720d487)) -* **coords:** add destroy method ([fdeee4f](https://github.com/laf/librenms/commit/fdeee4f)) -* **coords:** allow both (left/x1) and (top/y1) attr keys ([6f22217](https://github.com/laf/librenms/commit/6f22217)) -* **draggable:** Add toggle draggable method. ([073fdc4](https://github.com/laf/librenms/commit/073fdc4)) -* **draggable:** allow ignore_dragging config option to be a function ([69fcfe4](https://github.com/laf/librenms/commit/69fcfe4)) -* **draggable:** autoscrolling ([d3f25f3](https://github.com/laf/librenms/commit/d3f25f3)) -* **draggable:** CSS selectors support in `ignore_dragging` config opt ([0f95624](https://github.com/laf/librenms/commit/0f95624)) -* **draggable:** Don't start new drag if previous one hasn't stopped ([91ca657](https://github.com/laf/librenms/commit/91ca657)) -* **draggable:** keep container position prop if different than static ([04868a3](https://github.com/laf/librenms/commit/04868a3)) -* **draggable:** method to set drag limits dynamically ([8fa3ad2](https://github.com/laf/librenms/commit/8fa3ad2)) -* **draggable:** new config option to move or not the dragged element ([4d9b2a8](https://github.com/laf/librenms/commit/4d9b2a8)) -* **draggable:** option to not remove helper on drag stop ([03910df](https://github.com/laf/librenms/commit/03910df)) -* **draggable:** pass previous position to the drag callback ([055cc0e](https://github.com/laf/librenms/commit/055cc0e)) -* **draggable:** pass useful data to all drag callbacks ([8dda241](https://github.com/laf/librenms/commit/8dda241)) -* **draggable:** support horizontal scrolling while dragging ([b0b4464](https://github.com/laf/librenms/commit/b0b4464)) -* **gridster:** add config to set custom show/hide widget methods ([7de5bba](https://github.com/laf/librenms/commit/7de5bba)) -* **gridster:** browserify compatibility ([43148b8](https://github.com/laf/librenms/commit/43148b8)) -* **gridster:** Common.js support ([446852a](https://github.com/laf/librenms/commit/446852a)), closes [#434](https://github.com/laf/librenms/issues/434) -* **gridster:** destroy element's data and optionally remove from DOM ([dc09f19](https://github.com/laf/librenms/commit/dc09f19)) -* **gridster:** drag-and-drop widget resizing ([e192405](https://github.com/laf/librenms/commit/e192405)) -* **gridster:** increase grid width when dragging or resizing ([b65a802](https://github.com/laf/librenms/commit/b65a802)) -* **gridster:** move widget up when added if there is space available ([8ec307b](https://github.com/laf/librenms/commit/8ec307b)) -* **gridster.css:** remove possible default pading ([2002c45](https://github.com/laf/librenms/commit/2002c45)) -* **resize:** add option to set min_size of a widget ([429c776](https://github.com/laf/librenms/commit/429c776)) -* **resize:** Add start/stop/resize callbacks ([d4ec714](https://github.com/laf/librenms/commit/d4ec714)) -* **resize:** add start/stop/resize event triggers ([7ca8dee](https://github.com/laf/librenms/commit/7ca8dee)) -* **utils:** add delay helper to utils ([faa6c5d](https://github.com/laf/librenms/commit/faa6c5d)) -* make gridster AMD compatible ([589d7fd](https://github.com/laf/librenms/commit/589d7fd)) - - -### BREAKING CHANGES - -* draggable: If you was accessing to Draggable instances through -.data('drag') you should remove the `data` getter. Since now the instance -is returned directly. -* css naming: If you are using `gs_w` classes somewhere, replace -them with `gs-w` diff --git a/doc/Developing/Creating-Documentation.md b/doc/Developing/Creating-Documentation.md index c8058671d9..98787952dd 100644 --- a/doc/Developing/Creating-Documentation.md +++ b/doc/Developing/Creating-Documentation.md @@ -1,7 +1,6 @@ source: Developing/Creating-Documentation.md # Creating Documentation -### Writing documentation One of the goals of the LibreNMS project is to enable users to get all of the help they need from our documentation. When you are adding a new feature or extension, we need to have full documentation to go along with it. It's quite @@ -17,30 +16,3 @@ simple to do this: Please ensure you add the document to the relevant section within `pages` of `mkdocs.yml` so that it's in the correct menu and is built. Forgetting this step will result in your document never seeing the light of day :) - -### Building documentation -Our build process in GitHub automatically builds http://docs.librenms.org from everything in the `doc/` folder. You can simulate this -process to test what the docs will look like before you submit your PR. - -We use [mkdocs](http://www.mkdocs.org/) to build the documentation so you need to install that first (we assume you have `pip` installed): - -```bash -pip install --user mkdocs -pip install --user pymdown-extensions -``` - -Now you will need to install the LibreNMS theme: - -```bash -git clone https://github.com/librenms-docs/librenms_theme.git -``` - -Now you are ready to build your docs and check them, you can do this with mkdocs: - -```bash -mkdocs serve -``` - -This will launch a web service on localhost port 8000. You can change the port or bind the web server to a different IP by adding -` -a 0.0.0.0:8080` - diff --git a/doc/Support/FAQ.md b/doc/Support/FAQ.md index 609e42d919..2321c0c22b 100644 --- a/doc/Support/FAQ.md +++ b/doc/Support/FAQ.md @@ -19,7 +19,6 @@ source: Support/FAQ.md - [My device doesn't finish polling within 300 seconds](#faq19) - [Things aren't working correctly?](#faq18) - [What do the values mean in my graphs?](#faq21) - - [How can I move my LibreNMS install to another server?](#faq22) ### Developing - [How do I add support for a new OS?](#faq8) @@ -144,7 +143,7 @@ Re-run `./validate.php` once you've resolved any issues raised. You have an odd issue - we'd suggest you join our irc channel to discuss. -#### What do the values mean in my graphs? +#### What do the values mean in my graphs? The values you see are reported as metric values. Thanks to a post on [Reddit](https://www.reddit.com/r/networking/comments/4xzpfj/rrd_graph_interface_error_label_what_is_the_m/) here are those values: @@ -164,18 +163,6 @@ here are those values: 10^15 P - peta ``` -#### How can I move my LibreNMS install to another server? - -If you are moving from one CPU architecture to another then you will need to dump the rrd files and re-create them. If you are in -this scenario then you can use [Dan Brown's migration scripts](https://vlan50.com/2015/04/17/migrating-from-observium-to-librenms/). - -If you are just moving to another server with the same CPU architecture then the following steps should be all that's needed: - - - Install LibreNMS as per our normal documentation, you don't need to run through the web installer or building the sql schema. - - Dump the MySQL database `librenms` and import this into your new server. - - Copy the `rrd/` folder to the new server. - - Copy the `config.php` file to the new server. - #### 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) diff --git a/package.json b/package.json deleted file mode 100644 index 7fbd8c27c9..0000000000 --- a/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "LibreNMS", - "version": "201607", - "description": "LibreNMS is an autodiscovering network monitoring system", - "repository": { - "type": "git", - "url": "git+https://github.com/librenms/librenms.git" - }, - "license": "GPLv3" -} From 60332cd919ec59cb3413030692b50b3bda1657b4 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sun, 28 Aug 2016 14:56:02 +0100 Subject: [PATCH 32/69] August changelog (#4234) --- doc/General/Changelog.md | 86 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/doc/General/Changelog.md b/doc/General/Changelog.md index 0cfa0b08e1..6be053db02 100644 --- a/doc/General/Changelog.md +++ b/doc/General/Changelog.md @@ -1,4 +1,90 @@ source: General/Changelog.md +### August 2016 + +#### Bug fixes + - WebUI + - Fix Infoblox dhcp messages graph ([PR3898](https://github.com/librenms/librenms/pull/3898)) + - Fix version_info output in Safari ([PR3914](https://github.com/librenms/librenms/pull/3914)) + - Added missing apps to Application page ([PR3964](https://github.com/librenms/librenms/pull/3964)) + - Discovery / Polling + - Clear our stale IPSEC sessions from the DB ([PR3904](https://github.com/librenms/librenms/pull/3904)) + - Fixed some InfluxDB bugs in check-services and ports ([PR4031](https://github.com/librenms/librenms/pull/4031)) + - Fixed Promox and Ceph rrd's ([PR4038](https://github.com/librenms/librenms/pull/4038), [PR4037](https://github.com/librenms/librenms/pull/4037), [PR4047](https://github.com/librenms/librenms/pull/4047), [PR4041](https://github.com/librenms/librenms/pull/4041)) + - Fixed LLDP Remote port in discovery-protocols module ([PR4070](https://github.com/librenms/librenms/pull/4070)) + - Billing + - Check if ifSpeed is returned for calculating billing ([PR3921](https://github.com/librenms/librenms/pull/3921)) + - Applications + - NFS-V3 stats fixed ([PR3963](https://github.com/librenms/librenms/pull/3963)) + - Misc + - Dell Equallogic storage fix ([PR3956](https://github.com/librenms/librenms/pull/3956)) + - Fix syslog bug where entries would log to the wrong device ([PR3996](https://github.com/librenms/librenms/pull/3996)) + +#### Improvements + - Added / improved detection for: + - Cisco WAAS / WAVE ([PR3899](https://github.com/librenms/librenms/pull/3899)) + - Maipu MyPower ([PR3909](https://github.com/librenms/librenms/pull/3909)) + - TPLink Switches ([PR3919](https://github.com/librenms/librenms/pull/3919)) + - Dell N3024 ([PR3941](https://github.com/librenms/librenms/pull/3941)) + - Cisco FXOS ([PR3943](https://github.com/librenms/librenms/pull/3943)) + - Brocade FABOS ([PR3959](https://github.com/librenms/librenms/pull/3959), [PR3988](https://github.com/librenms/librenms/pull/3988)) + - JunOS ([PR3976](https://github.com/librenms/librenms/pull/3976)) + - Dell PowerConnect ([PR3998](https://github.com/librenms/librenms/pull/3998), [PR4007](https://github.com/librenms/librenms/pull/4007)) + - Commware ([PR3967](https://github.com/librenms/librenms/pull/3967)) + - Calix E5 ([PR3864](https://github.com/librenms/librenms/pull/3864)) + - Raisecom ([PR3992](https://github.com/librenms/librenms/pull/3864)) + - Cisco ISE ([PR4063](https://github.com/librenms/librenms/pull/4063)) + - Acano ([PR4064](https://github.com/librenms/librenms/pull/4064)) + - McAfee SIEM Nitro ([PR4066](https://github.com/librenms/librenms/pull/4064)) + - HP Bladesystem C3000/C7000 OA ([PR4035](https://github.com/librenms/librenms/pull/4035)) + - Cisco VCS (Expressway) ([PR4086](https://github.com/librenms/librenms/pull/4086)) + - Cisco Telepresence Conductor ([PR4087](https://github.com/librenms/librenms/pull/4087)) + - Avaya VSP ([PR4048](https://github.com/librenms/librenms/pull/4048)) + - Cisco/Tandberg Video Conferencing ([PR4065](https://github.com/librenms/librenms/pull/4065)) + - Cisco Prime Infrastructure ([PR4088](https://github.com/librenms/librenms/pull/4088)) + - HWGroup STE2 ([PR4116](https://github.com/librenms/librenms/pull/4116)) + - HP 2530 Procurve / Arube ([PR4119](https://github.com/librenms/librenms/pull/4119)) + - Brother Printers ([PR4141](https://github.com/librenms/librenms/pull/4141)) + - Hytera Repeater ([PR4163](https://github.com/librenms/librenms/pull/4163)) + - Sonus ([PR4176](https://github.com/librenms/librenms/pull/4176)) + - Freeswitch ([PR4203](https://github.com/librenms/librenms/pull/4203)) + - WebUI + - Improved OSPF display ([PR3908](https://github.com/librenms/librenms/pull/3908)) + - Improved Apps overview page ([PR3954](https://github.com/librenms/librenms/pull/3954)) + - Improved Syslog page ([PR3955](https://github.com/librenms/librenms/pull/3955), [PR3971](https://github.com/librenms/librenms/pull/3971)) + - Rewrite availability map ([PR4043](https://github.com/librenms/librenms/pull/4043)) + - Add predicated usage to billing overview ([PR4049](https://github.com/librenms/librenms/pull/4049)) + - API + - Added services calls to API ([PR4215](https://github.com/librenms/librenms/pull/4215)) + - Discovery / Polling + - Added CPU detection for Dell PowerConnect 8024F ([PR3966](https://github.com/librenms/librenms/pull/3966)) + - Cisco VSS state discovery ([PR3977](https://github.com/librenms/librenms/pull/3977)) + - Refactor of BGP Discovery and Polling (mainly JunOS) ([PR3938](https://github.com/librenms/librenms/pull/3938)) + - Added Sensors for Brocade NOS ([PR3969](https://github.com/librenms/librenms/pull/3969)) + - Cisco ASA HA States ([PR4012](https://github.com/librenms/librenms/pull/4012)) + - Improved IPSLA Support ([PR4006](https://github.com/librenms/librenms/pull/4006)) + - Added support for CISCO-NTP-MIB ([PR4005](https://github.com/librenms/librenms/pull/4005)) + - Improved toner support for Ricoh devices ([PR4180](https://github.com/librenms/librenms/pull/4180)) + - Documentation + - New doc site live http://docs.librenms.org/ + - Added rsyslog 5 example to syslog docs ([PR3912](https://github.com/librenms/librenms/pull/3912)) + - Application doc updates ([PR3928](https://github.com/librenms/librenms/pull/3928)) + - Applications + - App OS Updates support ([PR3935](https://github.com/librenms/librenms/pull/3935)) + - PowerDNS Recursor improvements ([PR3932](https://github.com/librenms/librenms/pull/3932)) + - Add DHCP Stats support ([PR3970](https://github.com/librenms/librenms/pull/3970)) + - Added snmp support to Memcached ([PR3949](https://github.com/librenms/librenms/pull/3949)) + - Added Unbound support ([PR4074](https://github.com/librenms/librenms/pull/4074)) + - Added snmp support to Proxmox ([PR4052](https://github.com/librenms/librenms/pull/4052)) + - Added Raspberry Pi Sensor support ([PR4057](https://github.com/librenms/librenms/pull/4057)) + - Updated NTPD support ([PR4077](https://github.com/librenms/librenms/pull/4077)) + - Misc + - Added cleanup of old RRD files to daily.sh ([PR3907](https://github.com/librenms/librenms/pull/3907)) + - Refactored addHost event logs ([PR3929](https://github.com/librenms/librenms/pull/3929), [PR3997](https://github.com/librenms/librenms/pull/3997)) + - Refactored RRD Functions ([PR3800](https://github.com/librenms/librenms/pull/3800), [PR4081](https://github.com/librenms/librenms/pull/4081)) + - Added support for nets-exclude in snmp-scan ([PR4000](https://github.com/librenms/librenms/pull/4045)) + - Refactored files in html (Libraries and PSR2 style ([PR4071](https://github.com/librenms/librenms/pull/4071), [PR4101](https://github.com/librenms/librenms/pull/4101), [PR4117](https://github.com/librenms/librenms/pull/4117)) + - Various IRC updates and fixes ([PR4200](https://github.com/librenms/librenms/pull/4200), [PR4204](https://github.com/librenms/librenms/pull/4204), [PR4201](https://github.com/librenms/librenms/pull/4201)) + ### July 2016 #### Bug fixes From 3c0fcdd46b19987ea24d6687e9e239b6a7a8f344 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Sun, 28 Aug 2016 09:43:35 -0500 Subject: [PATCH 33/69] Spelling corrections --- doc/General/Changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/General/Changelog.md b/doc/General/Changelog.md index 6be053db02..e5f4d3606d 100644 --- a/doc/General/Changelog.md +++ b/doc/General/Changelog.md @@ -29,7 +29,7 @@ source: General/Changelog.md - Brocade FABOS ([PR3959](https://github.com/librenms/librenms/pull/3959), [PR3988](https://github.com/librenms/librenms/pull/3988)) - JunOS ([PR3976](https://github.com/librenms/librenms/pull/3976)) - Dell PowerConnect ([PR3998](https://github.com/librenms/librenms/pull/3998), [PR4007](https://github.com/librenms/librenms/pull/4007)) - - Commware ([PR3967](https://github.com/librenms/librenms/pull/3967)) + - Comware ([PR3967](https://github.com/librenms/librenms/pull/3967)) - Calix E5 ([PR3864](https://github.com/librenms/librenms/pull/3864)) - Raisecom ([PR3992](https://github.com/librenms/librenms/pull/3864)) - Cisco ISE ([PR4063](https://github.com/librenms/librenms/pull/4063)) @@ -52,7 +52,7 @@ source: General/Changelog.md - Improved Apps overview page ([PR3954](https://github.com/librenms/librenms/pull/3954)) - Improved Syslog page ([PR3955](https://github.com/librenms/librenms/pull/3955), [PR3971](https://github.com/librenms/librenms/pull/3971)) - Rewrite availability map ([PR4043](https://github.com/librenms/librenms/pull/4043)) - - Add predicated usage to billing overview ([PR4049](https://github.com/librenms/librenms/pull/4049)) + - Add predicted usage to billing overview ([PR4049](https://github.com/librenms/librenms/pull/4049)) - API - Added services calls to API ([PR4215](https://github.com/librenms/librenms/pull/4215)) - Discovery / Polling From 4dea6fadbc8f2f095cb6d9a1b0613086b2b65a11 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Sun, 28 Aug 2016 16:43:11 +0100 Subject: [PATCH 34/69] Added docs + file changes to support creating new releases/changelog --- composer.json | 3 ++- doc/Developing/Creating-Release.md | 28 +++++++++++++++++++++++++ doc/Developing/Merging-Pull-Requests.md | 26 +++++++++++++++++++++++ doc/General/Releases.md | 16 ++++++++++++++ mkdocs.yml | 3 +++ readmegen.yml | 22 +++++++++++++++++++ 6 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 doc/Developing/Creating-Release.md create mode 100644 doc/Developing/Merging-Pull-Requests.md create mode 100644 doc/General/Releases.md create mode 100644 readmegen.yml diff --git a/composer.json b/composer.json index 6ca49b6e1a..070f0447ca 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,8 @@ { "require-dev": { "squizlabs/php_codesniffer": "*", - "phpunit/phpunit": "4.*" + "phpunit/phpunit": "4.*", + "fojuth/readmegen": "1.*" } } diff --git a/doc/Developing/Creating-Release.md b/doc/Developing/Creating-Release.md new file mode 100644 index 0000000000..d53752ec23 --- /dev/null +++ b/doc/Developing/Creating-Release.md @@ -0,0 +1,28 @@ +Developing/Creating-Release.md +# Creating a release + +### GitHub +You can create a new release on [GitHub](https://github.com/librenms/librenms/releases/new). + +Enter the tag version that month, i.e for September 2016 you would enter `201609`. + +Enter a title, we usually use `August 2016 Release` + +Enter a placeholder for the body, we will edit this later. + +### Create changelog +We utilise [Readmegen](https://github.com/fojuth/readmegen) to automatically populate the Changelog. + +Install `readmegen` using `composer`: + +```bash +./composer.phar update +``` + +You can now create the update change log by running (201608 was our last release): + +```bash +./vendor/bin/readmegen --from 201608 --release 201609 +``` + +Now commit and push the change that has been made to `doc\General\Changelog.md` diff --git a/doc/Developing/Merging-Pull-Requests.md b/doc/Developing/Merging-Pull-Requests.md new file mode 100644 index 0000000000..2afa85f611 --- /dev/null +++ b/doc/Developing/Merging-Pull-Requests.md @@ -0,0 +1,26 @@ +Developing/Merging-Pull-Requests.md +# Merging Pull Requests + +### GitHub +We will now build the monthly change log from our GitHub commits. When merging a commit, please +ensure you: + + - Click the `Merge pull request` button + - Give the merge a descriptive but short title + - For the commit message prepend it with one of the following tags for the pull request to appear in the changelog: + - devices: or newdevice: For new device support. + - feature: or feat: To indicate this is a new or updated feature + - fix: or bugfix: To show this is a bug fix. + - refactoring: or refactor: When the changes are refactoring a large portion of code + - You can reference an issue number with `#xyz`, i.e `#1234` + - Use the `Confirm squash and merge` button to merge. + +### Example commits + +#### Feature + +feature: Added new availability map #4401 + +#### New device + +newdevice: Added support for Cisco ASA #4402 diff --git a/doc/General/Releases.md b/doc/General/Releases.md new file mode 100644 index 0000000000..2e3636c4a4 --- /dev/null +++ b/doc/General/Releases.md @@ -0,0 +1,16 @@ +source: General/Releases.md +# LibreNMS Releases + +We try to ensure that breaking changes aren't introduced by utilising various automated +code testing, syntax testing and unit testing along with manual code review. However +bugs can and do get introduced as well as major refactoring to improve the quality of +the code base. + +With this in mind, we provide a monthly stable release which is released on or around +the last Sunday of the month. Code pull requests (aside from Bug fixes) are stopped days +leading up to the release to ensure that we have a clean working branch at that point. + +The releases are titled after that month in the format `YYYYMM`, i.e `201608`. The +Changelog is also updated and will reference the release number and date so you can see +what changes have been made since the last release. + diff --git a/mkdocs.yml b/mkdocs.yml index 10c09ac899..89857939b9 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -32,6 +32,7 @@ pages: - General/Contributing.md - General/Credits.md - General/Updating.md + - General/Releases.md - General/Welcome-to-Observium-users.md - Extensions: - Extensions/Alerting.md @@ -72,6 +73,8 @@ pages: - Developing/Code-Guidelines.md - Developing/Code-Structure.md - Developing/Creating-Documentation.md + - Developing/Merging-Pull-Requests.md + - Developing/Creating-Release.md - Developing/Dynamic-Config.md - Developing/Sensor-State-Support.md - Developing/Style-Guidelines.md diff --git a/readmegen.yml b/readmegen.yml new file mode 100644 index 0000000000..c96b7de6f7 --- /dev/null +++ b/readmegen.yml @@ -0,0 +1,22 @@ +vcs: git +format: md +issue_tracker_pattern: https://github.com/librenms/librenms/issues/\1 +break: "## Changelog" +output_file_name: "doc/General/Changelog.md" +message_groups: + Devices: + - devices + - newdevice + Features: + - feature + - feat + Bugfixes: + - fix + - bugfix + Documentation: + - docs + - doc + - documentation + Refactoring: + - refactoring + - refactor From 9284bc60ff1c9384a16fb8863074ccd0de31c54a Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Sun, 28 Aug 2016 12:32:58 -0500 Subject: [PATCH 35/69] Update code in includes to be PSR-2 compliant (#4220) refactor: Update code in /includes to be psr2 compliant #4220 --- includes/alerts.inc.php | 198 +++--- includes/billing.php | 62 +- includes/caches/devices.inc.php | 3 +- includes/caches/notifications.inc.php | 1 - includes/caches/ports.inc.php | 3 +- includes/caches/services.inc.php | 3 +- includes/callback.php | 3 +- includes/common.php | 514 ++++++++------- includes/datastore.inc.php | 1 - includes/dbFacile.mysql.php | 111 ++-- includes/dbFacile.mysqli.php | 113 ++-- includes/dbFacile.php | 3 +- includes/defaults.inc.php | 11 +- includes/definitions.inc.php | 48 +- includes/device-groups.inc.php | 61 +- includes/discovery/arp-table.inc.php | 120 ++-- includes/discovery/bgp-peers.inc.php | 393 ++++++------ includes/discovery/cisco-cbqos.inc.php | 29 +- .../discovery/cisco-mac-accounting.inc.php | 4 +- includes/discovery/cisco-otv.inc.php | 27 +- includes/discovery/cisco-pw.inc.php | 3 +- includes/discovery/cisco-sla.inc.php | 15 +- includes/discovery/cisco-vrf-lite.inc.php | 16 +- includes/discovery/cisco-vrf.inc.php | 15 +- .../discovery/discovery-protocols.inc.php | 33 +- includes/discovery/entity-physical.inc.php | 26 +- includes/discovery/functions.inc.php | 91 +-- includes/discovery/hr-device.inc.php | 3 +- includes/discovery/ipv4-addresses.inc.php | 18 +- includes/discovery/ipv6-addresses.inc.php | 8 +- includes/discovery/libvirt-vminfo.inc.php | 9 +- .../discovery/mempools/adtran-aos.inc.php | 1 - includes/discovery/mempools/binos.inc.php | 2 +- includes/discovery/mempools/binox.inc.php | 2 +- includes/discovery/mempools/ciscowlc.inc.php | 2 +- includes/discovery/mempools/hrstorage.inc.php | 26 +- .../discovery/mempools/ironware-dyn.inc.php | 29 +- includes/discovery/mempools/nos.inc.php | 10 +- includes/discovery/mempools/pbn.inc.php | 2 - includes/discovery/mempools/zywall.inc.php | 2 +- includes/discovery/ntp/cisco.inc.php | 10 +- includes/discovery/os/3com.inc.php | 6 +- includes/discovery/os/acano.inc.php | 2 +- includes/discovery/os/acs.inc.php | 7 +- includes/discovery/os/adtran-aos.inc.php | 5 +- includes/discovery/os/alcatel-lucent.inc.php | 10 +- includes/discovery/os/avaya-ers.inc.php | 3 +- includes/discovery/os/avaya-vsp.inc.php | 2 +- includes/discovery/os/avtech.inc.php | 1 - includes/discovery/os/barracuda.inc.php | 1 - includes/discovery/os/cambium.inc.php | 18 +- includes/discovery/os/canopy.inc.php | 5 +- includes/discovery/os/comware.inc.php | 6 +- includes/discovery/os/deliberant.inc.php | 2 +- includes/discovery/os/developprinter.inc.php | 2 +- includes/discovery/os/engenius.inc.php | 6 +- includes/discovery/os/enterasys.inc.php | 2 +- includes/discovery/os/fiberhome.inc.php | 4 +- includes/discovery/os/freebsd.inc.php | 7 +- includes/discovery/os/hpmsm.inc.php | 2 +- includes/discovery/os/hytera.inc.php | 1 - includes/discovery/os/ios.inc.php | 9 +- includes/discovery/os/ise.inc.php | 2 +- includes/discovery/os/lenovoemc.inc.php | 8 +- includes/discovery/os/linux.inc.php | 45 +- includes/discovery/os/netgear.inc.php | 3 +- includes/discovery/os/nos.inc.php | 2 +- includes/discovery/os/papouch-tme.inc.php | 3 +- includes/discovery/os/perle.inc.php | 2 +- includes/discovery/os/procurve.inc.php | 3 +- includes/discovery/os/samsungprinter.inc.php | 2 +- includes/discovery/os/sentry3.inc.php | 1 - includes/discovery/os/serveriron.inc.php | 3 +- includes/discovery/os/sonus-gsx.inc.php | 2 +- includes/discovery/os/sonus-sbc.inc.php | 2 +- includes/discovery/os/speedtouch.inc.php | 6 +- includes/discovery/os/tplink.inc.php | 2 +- includes/discovery/os/xirrus.inc.php | 3 +- includes/discovery/os/zynos.inc.php | 5 +- includes/discovery/ports-stack.inc.php | 6 +- includes/discovery/ports.inc.php | 23 +- .../discovery/processors/adtran-aos.inc.php | 2 - includes/discovery/processors/aen.inc.php | 4 +- .../discovery/processors/aos-device.inc.php | 3 +- includes/discovery/processors/binos.inc.php | 2 - includes/discovery/processors/binox.inc.php | 7 +- includes/discovery/processors/calix.inc.php | 1 - includes/discovery/processors/cambium.inc.php | 14 +- includes/discovery/processors/dnos.inc.php | 1 - .../discovery/processors/hrdevice.inc.php | 3 +- includes/discovery/processors/ios.inc.php | 3 +- .../discovery/processors/ironware.inc.php | 3 +- includes/discovery/processors/nos.inc.php | 4 +- includes/discovery/processors/pbn.inc.php | 2 - .../discovery/processors/powerconnect.inc.php | 6 +- includes/discovery/processors/pulse.inc.php | 14 +- .../discovery/processors/serveriron.inc.php | 3 +- .../discovery/processors/viprinux.inc.php | 17 +- includes/discovery/route.inc.php | 20 +- includes/discovery/sensors/charge/apc.inc.php | 3 +- .../sensors/cisco-entity-sensor.inc.php | 7 +- .../discovery/sensors/current/apc.inc.php | 9 +- .../sensors/current/gamatronicups.inc.php | 38 +- .../discovery/sensors/current/junos.inc.php | 2 - .../discovery/sensors/current/mgeups.inc.php | 2 +- .../sensors/current/netvision.inc.php | 38 +- .../discovery/sensors/current/pbn.inc.php | 2 - includes/discovery/sensors/dbm/junos.inc.php | 2 - includes/discovery/sensors/dbm/pbn.inc.php | 1 - .../discovery/sensors/entity-sensor.inc.php | 3 +- .../sensors/fanspeeds/extreme.inc.php | 2 +- .../sensors/fanspeeds/ibm-amm.inc.php | 2 - .../discovery/sensors/fanspeeds/nos.inc.php | 4 +- .../discovery/sensors/fanspeeds/qnap.inc.php | 1 - .../sensors/frequencies/linux.inc.php | 7 +- .../sensors/frequencies/mgeups.inc.php | 2 +- .../sensors/frequencies/netvision.inc.php | 38 +- .../discovery/sensors/humidity/akcp.inc.php | 19 +- .../sensors/humidity/netbotz.inc.php | 19 +- .../sensors/humidity/sentry3.inc.php | 20 +- includes/discovery/sensors/load/apc.inc.php | 6 +- includes/discovery/sensors/netscaler.inc.php | 28 +- .../discovery/sensors/power/extreme.inc.php | 2 +- .../discovery/sensors/power/hpblmos.inc.php | 1 - .../discovery/sensors/power/rfc1628.inc.php | 30 +- .../sensors/pre-cache/comware.inc.php | 3 - .../discovery/sensors/pre-cache/junos.inc.php | 2 - .../discovery/sensors/pre-cache/pbn.inc.php | 2 - includes/discovery/sensors/signal.inc.php | 2 +- .../discovery/sensors/signal/cambium.inc.php | 60 +- .../discovery/sensors/signal/canopy.inc.php | 54 +- includes/discovery/sensors/states/asa.inc.php | 11 +- .../discovery/sensors/states/avtech.inc.php | 3 +- .../discovery/sensors/states/cisco.inc.php | 10 +- .../discovery/sensors/states/comware.inc.php | 8 +- .../discovery/sensors/states/dell.inc.php | 99 +-- .../discovery/sensors/states/drac.inc.php | 3 +- includes/discovery/sensors/states/dsm.inc.php | 3 +- .../sensors/states/equallogic.inc.php | 8 +- .../discovery/sensors/states/hpblmos.inc.php | 5 +- .../discovery/sensors/states/hwg-ste.inc.php | 3 +- .../discovery/sensors/states/ibm-amm.inc.php | 40 +- .../discovery/sensors/states/ironware.inc.php | 9 +- .../discovery/sensors/states/juniper.inc.php | 12 +- .../discovery/sensors/states/linux.inc.php | 4 +- .../discovery/sensors/states/netonix.inc.php | 3 +- .../discovery/sensors/states/pcoweb.inc.php | 2 +- .../sensors/states/serveriron.inc.php | 21 +- .../discovery/sensors/states/waas.inc.php | 3 +- .../sensors/temperatures/akcp.inc.php | 2 +- .../sensors/temperatures/aos-device.inc.php | 19 +- .../sensors/temperatures/apc.inc.php | 9 +- .../sensors/temperatures/areca.inc.php | 38 +- .../sensors/temperatures/avaya-ers.inc.php | 19 +- .../sensors/temperatures/avtech.inc.php | 9 +- .../sensors/temperatures/binos.inc.php | 1 - .../sensors/temperatures/binox.inc.php | 2 +- .../sensors/temperatures/cambium.inc.php | 19 +- .../sensors/temperatures/canopy.inc.php | 20 +- .../temperatures/cometsystem-p85xx.inc.php | 19 +- .../sensors/temperatures/comware.inc.php | 2 - .../sensors/temperatures/dell.inc.php | 2 +- .../sensors/temperatures/dnos.inc.php | 24 +- .../sensors/temperatures/extreme.inc.php | 8 +- .../sensors/temperatures/hpblmos.inc.php | 1 - .../sensors/temperatures/hwg-ste.inc.php | 1 - .../sensors/temperatures/hytera.inc.php | 9 +- .../sensors/temperatures/ibm-amm.inc.php | 1 - .../sensors/temperatures/ironware.inc.php | 19 +- .../sensors/temperatures/junos.inc.php | 19 +- .../sensors/temperatures/linux.inc.php | 2 +- .../sensors/temperatures/lm-sensors.inc.php | 19 +- .../sensors/temperatures/netapp.inc.php | 10 +- .../sensors/temperatures/netbotz.inc.php | 19 +- .../sensors/temperatures/nos.inc.php | 4 +- .../sensors/temperatures/papouch-tme.inc.php | 19 +- .../sensors/temperatures/pbn.inc.php | 2 - .../sensors/temperatures/powerconnect.inc.php | 28 +- .../sensors/temperatures/sentry3.inc.php | 20 +- .../sensors/temperatures/sentry4.inc.php | 20 +- .../sensors/temperatures/sub10.inc.php | 20 +- .../sensors/temperatures/supermicro.inc.php | 19 +- .../sensors/temperatures/xups.inc.php | 19 +- .../sensors/temperatures/zyxel-ies.inc.php | 19 +- .../discovery/sensors/voltages/drac.inc.php | 8 +- .../sensors/voltages/gamatronicups.inc.php | 38 +- .../discovery/sensors/voltages/hytera.inc.php | 9 +- .../discovery/sensors/voltages/linux.inc.php | 6 +- .../sensors/voltages/mikrotik.inc.php | 13 +- .../sensors/voltages/netvision.inc.php | 57 +- .../discovery/sensors/voltages/pbn.inc.php | 2 - .../sensors/voltages/sentry3.inc.php | 19 +- includes/discovery/services.inc.php | 1 - .../discovery/storage/eql-storage.inc.php | 3 +- includes/discovery/storage/hrstorage.inc.php | 26 +- .../discovery/storage/netapp-storage.inc.php | 3 +- includes/discovery/stp.inc.php | 31 +- includes/discovery/ucd-diskio.inc.php | 3 +- includes/discovery/vlans.inc.php | 3 +- includes/discovery/vlans/cisco-vtp.inc.php | 3 +- includes/discovery/vlans/q-bridge-mib.inc.php | 5 +- includes/discovery/vmware-vminfo.inc.php | 3 +- includes/functions.php | 585 +++++++++--------- includes/influxdb.inc.php | 28 +- includes/load_db_graph_types.inc.php | 3 +- includes/mergecnf.inc.php | 16 +- includes/notifications.php | 32 +- includes/polling/altiga-ssl.inc.php | 3 +- includes/polling/applications.inc.php | 3 +- includes/polling/applications/apache.inc.php | 4 +- includes/polling/applications/bind.inc.php | 7 +- includes/polling/applications/ceph.inc.php | 18 +- .../polling/applications/dhcp-stats.inc.php | 74 +-- .../polling/applications/freeswitch.inc.php | 14 +- .../polling/applications/mailscanner.inc.php | 1 - .../polling/applications/memcached.inc.php | 1 - includes/polling/applications/mysql.inc.php | 4 +- .../polling/applications/nfs-stats.inc.php | 2 +- .../polling/applications/nfs-v3-stats.inc.php | 2 +- includes/polling/applications/nginx.inc.php | 3 +- .../polling/applications/ntp-client.inc.php | 1 - .../polling/applications/os-updates.inc.php | 36 +- .../polling/applications/powerdns.inc.php | 4 +- includes/polling/applications/proxmox.inc.php | 22 +- .../polling/applications/shoutcast.inc.php | 1 - includes/polling/applications/tinydns.inc.php | 1 - includes/polling/applications/unbound.inc.php | 90 +-- includes/polling/aruba-controller.inc.php | 9 +- includes/polling/bgp-peers.inc.php | 44 +- includes/polling/cipsec-tunnels.inc.php | 10 +- .../polling/cisco-ace-loadbalancer.inc.php | 8 +- .../polling/cisco-ace-serverfarms.inc.php | 6 +- includes/polling/cisco-asa-firewall.inc.php | 5 +- includes/polling/cisco-cbqos.inc.php | 6 +- includes/polling/cisco-cef.inc.php | 3 +- .../polling/cisco-ipsec-flow-monitor.inc.php | 2 +- includes/polling/cisco-mac-accounting.inc.php | 2 +- includes/polling/cisco-otv.inc.php | 24 +- .../cisco-remote-access-monitor.inc.php | 2 +- includes/polling/cisco-sla.inc.php | 6 +- includes/polling/cisco-voice.inc.php | 78 ++- .../polling/cisco-voice/cisco-iosdsp.inc.php | 6 +- .../polling/cisco-voice/cisco-iosmtp.inc.php | 6 +- .../polling/cisco-voice/cisco-iospri.inc.php | 6 +- .../cisco-voice/cisco-iosxcode.inc.php | 6 +- includes/polling/cisco-vpdn.inc.php | 2 +- includes/polling/core.inc.php | 3 +- includes/polling/entity-physical.inc.php | 6 +- includes/polling/functions.inc.php | 114 ++-- includes/polling/hr-mib.inc.php | 4 +- includes/polling/ipSystemStats.inc.php | 2 +- includes/polling/ipmi.inc.php | 2 +- includes/polling/junose-atm-vp.inc.php | 3 +- includes/polling/mempools.inc.php | 5 +- includes/polling/mempools/adtran-aos.inc.php | 1 - includes/polling/mempools/ciscowlc.inc.php | 12 +- includes/polling/mempools/hpGlobal.inc.php | 3 +- includes/polling/mempools/hpLocal.inc.php | 3 +- includes/polling/mempools/hrstorage.inc.php | 3 +- .../polling/mempools/ironware-dyn.inc.php | 4 - includes/polling/mempools/junos.inc.php | 3 +- includes/polling/mempools/netonix.inc.php | 1 - includes/polling/mempools/nos.inc.php | 6 +- includes/polling/mempools/pbn-mem.inc.php | 5 +- includes/polling/mempools/pulse-mem.inc.php | 19 +- includes/polling/mib/sub10-mib.inc.php | 1 - includes/polling/mib/ubnt-airmax-mib.inc.php | 1 - includes/polling/netscaler-stats.inc.php | 5 +- includes/polling/netscaler-vsvr.inc.php | 9 +- includes/polling/netstats-icmp.inc.php | 2 +- includes/polling/netstats-ip.inc.php | 4 +- includes/polling/netstats-ip_forward.inc.php | 5 +- includes/polling/netstats-snmp.inc.php | 2 +- includes/polling/netstats-tcp.inc.php | 3 +- includes/polling/netstats-udp.inc.php | 4 +- includes/polling/ntp/cisco.inc.php | 5 +- includes/polling/os.inc.php | 6 +- includes/polling/os/acs.inc.php | 6 +- includes/polling/os/akcp.inc.php | 4 +- includes/polling/os/apc.inc.php | 3 +- includes/polling/os/arubaos.inc.php | 3 +- includes/polling/os/asa.inc.php | 6 +- includes/polling/os/avtech.inc.php | 1 - includes/polling/os/binos.inc.php | 1 - includes/polling/os/calix.inc.php | 3 - includes/polling/os/cambium.inc.php | 17 +- includes/polling/os/canopy.inc.php | 44 +- includes/polling/os/ciscosb.inc.php | 5 +- includes/polling/os/ciscowlc.inc.php | 14 +- includes/polling/os/comware.inc.php | 2 +- includes/polling/os/datadomain.inc.php | 2 +- includes/polling/os/dell-laser.inc.php | 3 +- includes/polling/os/deltaups.inc.php | 6 +- includes/polling/os/develop.inc.php | 2 +- includes/polling/os/dnos.inc.php | 11 +- includes/polling/os/edgeswitch.inc.php | 8 +- includes/polling/os/engenius.inc.php | 60 +- includes/polling/os/extremeware.inc.php | 3 +- includes/polling/os/fabos.inc.php | 7 +- includes/polling/os/ftos.inc.php | 6 +- includes/polling/os/hwg-poseidon.inc.php | 2 +- includes/polling/os/hwg-ste2.inc.php | 2 +- includes/polling/os/ibmnos.inc.php | 7 +- includes/polling/os/ibmtl.inc.php | 6 +- includes/polling/os/ios.inc.php | 4 +- includes/polling/os/iosxr.inc.php | 3 +- includes/polling/os/junos.inc.php | 3 +- includes/polling/os/junose.inc.php | 3 +- includes/polling/os/lantronix-slc.inc.php | 4 +- includes/polling/os/ligoos.inc.php | 2 +- includes/polling/os/mellanox.inc.php | 4 +- includes/polling/os/mypoweros.inc.php | 2 +- includes/polling/os/nios.inc.php | 11 +- includes/polling/os/nos.inc.php | 6 +- includes/polling/os/pbn.inc.php | 3 +- includes/polling/os/perle.inc.php | 2 +- includes/polling/os/powerware.inc.php | 6 +- .../polling/os/primeinfrastructure.inc.php | 4 +- includes/polling/os/pulse.inc.php | 6 +- includes/polling/os/saf.inc.php | 1 - includes/polling/os/samsungprinter.inc.php | 2 +- includes/polling/os/serveriron.inc.php | 7 +- includes/polling/os/unix.inc.php | 78 +-- includes/polling/os/viprinux.inc.php | 8 +- includes/polling/os/windows.inc.php | 9 +- includes/polling/os/xirrus_aos.inc.php | 1 - includes/polling/ospf.inc.php | 32 +- includes/polling/port-etherlike.inc.php | 2 +- includes/polling/port-poe.inc.php | 2 +- includes/polling/ports.inc.php | 55 +- includes/polling/processors.inc.php | 5 +- includes/polling/processors/dnos-cpu.inc.php | 1 - .../polling/processors/extreme-cpu.inc.php | 1 - includes/polling/processors/nos.inc.php | 2 +- includes/polling/processors/pbn-cpu.inc.php | 2 - .../polling/processors/powerconnect.inc.php | 2 +- includes/polling/processors/viprinux.inc.php | 2 +- includes/polling/signal/cambium.inc.php | 22 +- includes/polling/signal/canopy.inc.php | 34 +- includes/polling/storage.inc.php | 3 +- includes/polling/storage/eql-storage.inc.php | 28 +- .../polling/storage/netapp-storage.inc.php | 3 +- includes/polling/stp.inc.php | 24 +- includes/polling/temperatures/cambium.inc.php | 2 +- includes/polling/temperatures/canopy.inc.php | 2 +- includes/polling/temperatures/hytera.inc.php | 2 +- includes/polling/ucd-diskio.inc.php | 1 - includes/polling/ucd-mib.inc.php | 2 +- includes/polling/unix-agent.inc.php | 10 +- .../polling/unix-agent/munin-plugins.inc.php | 11 +- includes/polling/unix-agent/packages.inc.php | 15 +- includes/polling/voltages/hytera.inc.php | 2 +- includes/polling/wifi.inc.php | 1 - includes/polling/wireless/cambium-250.inc.php | 12 +- includes/polling/wireless/cambium-650.inc.php | 67 +- .../polling/wireless/cambium-epmp.inc.php | 14 +- .../polling/wireless/cambium-generic.inc.php | 117 ++-- .../polling/wireless/canopy-generic.inc.php | 40 +- includes/polling/wireless/cisco-wwan.inc.php | 4 +- includes/polling/wireless/xirrus.inc.php | 23 +- includes/rewrites.php | 496 ++++++++------- includes/services.inc.php | 41 +- includes/services/check_dns.inc.php | 12 +- includes/services/check_domain_expire.inc.php | 6 +- includes/services/check_icmp.inc.php | 8 +- includes/services/check_mysql.inc.php | 6 +- includes/services/check_ssl_cert.inc.php | 6 +- includes/services/check_telnet.inc.php | 6 +- includes/snmp.inc.php | 215 +++---- includes/snmptrap/linkUp.inc.php | 10 +- includes/sql-schema/update.php | 29 +- includes/syslog.php | 72 +-- scripts/pre-commit.php | 2 +- 373 files changed, 3509 insertions(+), 3498 deletions(-) diff --git a/includes/alerts.inc.php b/includes/alerts.inc.php index c18131f3bc..7d4c2fe315 100644 --- a/includes/alerts.inc.php +++ b/includes/alerts.inc.php @@ -31,53 +31,53 @@ include_once($config['install_dir'].'/html/includes/authentication/'.$config['au * @param string $rule Rule to generate SQL for * @return string|boolean */ -function GenSQL($rule) { +function GenSQL($rule) +{ $rule = RunMacros($rule); - if( empty($rule) ) { + if (empty($rule)) { //Cannot resolve Macros due to recursion. Rule is invalid. return false; } //Pretty-print rule to dissect easier $pretty = array('*' => '*', '(' => ' ( ', ')' => ' ) ', '/' => '/', '&&' => ' && ', '||' => ' || ', 'DATE_SUB ( NOW ( )' => 'DATE_SUB( NOW()'); - $rule = str_replace(array_keys($pretty),$pretty,$rule); - $tmp = explode(" ",$rule); + $rule = str_replace(array_keys($pretty), $pretty, $rule); + $tmp = explode(" ", $rule); $tables = array(); - foreach( $tmp as $opt ) { - if( strstr($opt,'%') && strstr($opt,'.') ) { - $tmpp = explode(".",$opt,2); - $tmpp[0] = str_replace("%","",$tmpp[0]); - $tables[] = mres(str_replace("(","",$tmpp[0])); - $rule = str_replace($opt,$tmpp[0].'.'.$tmpp[1],$rule); + foreach ($tmp as $opt) { + if (strstr($opt, '%') && strstr($opt, '.')) { + $tmpp = explode(".", $opt, 2); + $tmpp[0] = str_replace("%", "", $tmpp[0]); + $tables[] = mres(str_replace("(", "", $tmpp[0])); + $rule = str_replace($opt, $tmpp[0].'.'.$tmpp[1], $rule); } } $tables = array_keys(array_flip($tables)); - if( dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?',array($tables[0],'device_id')) != 1 ) { + if (dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?', array($tables[0],'device_id')) != 1) { //Our first table has no valid glue, append the 'devices' table to it! array_unshift($tables, 'devices'); } $x = sizeof($tables)-1; $i = 0; $join = ""; - while( $i < $x ) { - if( isset($tables[$i+1]) ) { - $gtmp = ResolveGlues(array($tables[$i+1]),'device_id'); - if( $gtmp === false ) { + while ($i < $x) { + if (isset($tables[$i+1])) { + $gtmp = ResolveGlues(array($tables[$i+1]), 'device_id'); + if ($gtmp === false) { //Cannot resolve glue-chain. Rule is invalid. return false; } $last = ""; $qry = ""; - foreach( $gtmp as $glue ) { - if( empty($last) ) { - list($tmp,$last) = explode('.',$glue); + foreach ($gtmp as $glue) { + if (empty($last)) { + list($tmp,$last) = explode('.', $glue); $qry .= $glue.' = '; - } - else { - list($tmp,$new) = explode('.',$glue); + } else { + list($tmp,$new) = explode('.', $glue); $qry .= $tmp.'.'.$last.' && '.$tmp.'.'.$new.' = '; $last = $new; } - if( !in_array($tmp, $tables) ) { + if (!in_array($tmp, $tables)) { $tables[] = $tmp; } } @@ -85,7 +85,7 @@ function GenSQL($rule) { } $i++; } - $sql = "SELECT * FROM ".implode(",",$tables)." WHERE (".$join."".str_replace("(","",$tables[0]).".device_id = ?) && (".str_replace(array("%","@","!~","~"),array("",".*","NOT REGEXP","REGEXP"),$rule).")"; + $sql = "SELECT * FROM ".implode(",", $tables)." WHERE (".$join."".str_replace("(", "", $tables[0]).".device_id = ?) && (".str_replace(array("%","@","!~","~"), array("",".*","NOT REGEXP","REGEXP"), $rule).")"; return $sql; } @@ -95,19 +95,19 @@ function GenSQL($rule) { * @param int $x Recursion-Anchor * @return string|boolean */ -function RunMacros($rule,$x=1) { +function RunMacros($rule, $x = 1) +{ global $config; krsort($config['alert']['macros']['rule']); - foreach( $config['alert']['macros']['rule'] as $macro=>$value ) { - if( !strstr($macro," ") ) { - $rule = str_replace('%macros.'.$macro,'('.$value.')',$rule); + foreach ($config['alert']['macros']['rule'] as $macro => $value) { + if (!strstr($macro, " ")) { + $rule = str_replace('%macros.'.$macro, '('.$value.')', $rule); } } - if( strstr($rule,"%macros") ) { - if( ++$x < 30 ) { - $rule = RunMacros($rule,$x); - } - else { + if (strstr($rule, "%macros")) { + if (++$x < 30) { + $rule = RunMacros($rule, $x); + } else { return false; } } @@ -119,15 +119,16 @@ function RunMacros($rule,$x=1) { * @param int $device Device-ID * @return array */ -function GetRules($device) { +function GetRules($device) +{ $groups = GetGroupsFromDevice($device); $params = array($device,$device); $where = ""; - foreach( $groups as $group ) { + foreach ($groups as $group) { $where .= " || alert_map.target = ?"; $params[] = 'g'.$group; } - return dbFetchRows('SELECT alert_rules.* FROM alert_rules LEFT JOIN alert_map ON alert_rules.id=alert_map.rule WHERE alert_rules.disabled = 0 && ( (alert_rules.device_id = -1 || alert_rules.device_id = ? ) || alert_map.target = ? '.$where.' )',$params); + return dbFetchRows('SELECT alert_rules.* FROM alert_rules LEFT JOIN alert_map ON alert_rules.id=alert_map.rule WHERE alert_rules.disabled = 0 && ( (alert_rules.device_id = -1 || alert_rules.device_id = ? ) || alert_map.target = ? '.$where.' )', $params); } /** @@ -135,15 +136,16 @@ function GetRules($device) { * @param int $device Device-ID * @return int */ -function IsMaintenance( $device ) { +function IsMaintenance($device) +{ $groups = GetGroupsFromDevice($device); $params = array($device); $where = ""; - foreach( $groups as $group ) { + foreach ($groups as $group) { $where .= " || alert_schedule_items.target = ?"; $params[] = 'g'.$group; } - return dbFetchCell('SELECT alert_schedule.schedule_id FROM alert_schedule LEFT JOIN alert_schedule_items ON alert_schedule.schedule_id=alert_schedule_items.schedule_id WHERE ( alert_schedule_items.target = ?'.$where.' ) && NOW() BETWEEN alert_schedule.start AND alert_schedule.end LIMIT 1',$params); + return dbFetchCell('SELECT alert_schedule.schedule_id FROM alert_schedule LEFT JOIN alert_schedule_items ON alert_schedule.schedule_id=alert_schedule_items.schedule_id WHERE ( alert_schedule_items.target = ?'.$where.' ) && NOW() BETWEEN alert_schedule.start AND alert_schedule.end LIMIT 1', $params); } /** @@ -151,64 +153,57 @@ function IsMaintenance( $device ) { * @param int $device Device-ID * @return void */ -function RunRules($device) { - if( IsMaintenance($device) > 0 ) { +function RunRules($device) +{ + if (IsMaintenance($device) > 0) { echo "Under Maintenance, Skipping alerts.\r\n"; return false; } - foreach( GetRules($device) as $rule ) { + foreach (GetRules($device) as $rule) { echo " #".$rule['id'].":"; - $inv = json_decode($rule['extra'],true); - if( isset($inv['invert']) ) { + $inv = json_decode($rule['extra'], true); + if (isset($inv['invert'])) { $inv = (bool) $inv['invert']; - } - else { + } else { $inv = false; } $chk = dbFetchRow("SELECT state FROM alerts WHERE rule_id = ? && device_id = ? ORDER BY id DESC LIMIT 1", array($rule['id'], $device)); $sql = GenSQL($rule['rule']); - $qry = dbFetchRows($sql,array($device)); + $qry = dbFetchRows($sql, array($device)); if (isset($qry[0]['ip'])) { $qry[0]['ip'] = inet6_ntop($qry[0]['ip']); } $s = sizeof($qry); - if( $s == 0 && $inv === false ) { + if ($s == 0 && $inv === false) { + $doalert = false; + } elseif ($s > 0 && $inv === false) { + $doalert = true; + } elseif ($s == 0 && $inv === true) { + $doalert = true; + } else { //( $s > 0 && $inv == false ) { $doalert = false; } - elseif( $s > 0 && $inv === false ) { - $doalert = true; - } - elseif( $s == 0 && $inv === true ) { - $doalert = true; - } - else { //( $s > 0 && $inv == false ) { - $doalert = false; - } - if( $doalert ) { - if( $chk['state'] === "2" ) { + if ($doalert) { + if ($chk['state'] === "2") { echo " SKIP "; - } - elseif( $chk['state'] >= "1" ) { + } elseif ($chk['state'] >= "1") { echo " NOCHG "; - } - else { - $extra = gzcompress(json_encode(array('contacts' => GetContacts($qry), 'rule'=>$qry)),9); - if( dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'details' => $extra),'alert_log') ) { - if( !dbUpdate(array('state' => 1, 'open' => 1),'alerts','device_id = ? && rule_id = ?', array($device,$rule['id'])) ) { - dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1,'alerted' => 0),'alerts'); + } else { + $extra = gzcompress(json_encode(array('contacts' => GetContacts($qry), 'rule'=>$qry)), 9); + if (dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'details' => $extra), 'alert_log')) { + if (!dbUpdate(array('state' => 1, 'open' => 1), 'alerts', 'device_id = ? && rule_id = ?', array($device,$rule['id']))) { + dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1,'alerted' => 0), 'alerts'); } echo " ALERT "; } } - } - else { - if( $chk['state'] === "0" ) { + } else { + if ($chk['state'] === "0") { echo " NOCHG "; - } - else { - if( dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id']),'alert_log') ){ - if( !dbUpdate(array('state' => 0, 'open' => 1),'alerts','device_id = ? && rule_id = ?', array($device,$rule['id'])) ) { - dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1, 'alerted' => 0),'alerts'); + } else { + if (dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id']), 'alert_log')) { + if (!dbUpdate(array('state' => 0, 'open' => 1), 'alerts', 'device_id = ? && rule_id = ?', array($device,$rule['id']))) { + dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1, 'alerted' => 0), 'alerts'); } echo " OK "; } @@ -222,62 +217,59 @@ function RunRules($device) { * @param array $results Rule-Result * @return array */ -function GetContacts($results) { +function GetContacts($results) +{ global $config; - if( sizeof($results) == 0 ) { + if (sizeof($results) == 0) { return array(); } - if( $config['alert']['default_only'] == true || $config['alerts']['email']['default_only'] == true ) { + if ($config['alert']['default_only'] == true || $config['alerts']['email']['default_only'] == true) { return array(''.($config['alert']['default_mail'] ? $config['alert']['default_mail'] : $config['alerts']['email']['default']) => 'NOC'); } $users = get_userlist(); $contacts = array(); $uids = array(); - foreach( $results as $result ) { - $tmp = NULL; - if( is_numeric($result["bill_id"]) ) { - $tmpa = dbFetchRows("SELECT user_id FROM bill_perms WHERE bill_id = ?",array($result["bill_id"])); - foreach( $tmpa as $tmp ) { + foreach ($results as $result) { + $tmp = null; + if (is_numeric($result["bill_id"])) { + $tmpa = dbFetchRows("SELECT user_id FROM bill_perms WHERE bill_id = ?", array($result["bill_id"])); + foreach ($tmpa as $tmp) { $uids[$tmp['user_id']] = $tmp['user_id']; } } - if( is_numeric($result["port_id"]) ) { - $tmpa = dbFetchRows("SELECT user_id FROM ports_perms WHERE access_level >= 0 AND port_id = ?",array($result["port_id"])); - foreach( $tmpa as $tmp ) { + if (is_numeric($result["port_id"])) { + $tmpa = dbFetchRows("SELECT user_id FROM ports_perms WHERE access_level >= 0 AND port_id = ?", array($result["port_id"])); + foreach ($tmpa as $tmp) { $uids[$tmp['user_id']] = $tmp['user_id']; } } - if( is_numeric($result["device_id"]) ) { - if( $config['alert']['syscontact'] == true ) { - if( dbFetchCell("SELECT attrib_value FROM devices_attribs WHERE attrib_type = 'override_sysContact_bool' AND device_id = ?",array($result["device_id"])) === "1" ) { - $tmpa = dbFetchCell("SELECT attrib_value FROM devices_attribs WHERE attrib_type = 'override_sysContact_string' AND device_id = ?",array($result["device_id"])); - } - else { - $tmpa = dbFetchCell("SELECT sysContact FROM devices WHERE device_id = ?",array($result["device_id"])); + if (is_numeric($result["device_id"])) { + if ($config['alert']['syscontact'] == true) { + if (dbFetchCell("SELECT attrib_value FROM devices_attribs WHERE attrib_type = 'override_sysContact_bool' AND device_id = ?", array($result["device_id"])) === "1") { + $tmpa = dbFetchCell("SELECT attrib_value FROM devices_attribs WHERE attrib_type = 'override_sysContact_string' AND device_id = ?", array($result["device_id"])); + } else { + $tmpa = dbFetchCell("SELECT sysContact FROM devices WHERE device_id = ?", array($result["device_id"])); } $contacts[$tmpa] = "NOC"; } $tmpa = dbFetchRows("SELECT user_id FROM devices_perms WHERE access_level >= 0 AND device_id = ?", array($result["device_id"])); - foreach( $tmpa as $tmp ) { + foreach ($tmpa as $tmp) { $uids[$tmp['user_id']] = $tmp['user_id']; } } } - foreach( $users as $user ) { - if( empty($user['email']) ) { + foreach ($users as $user) { + if (empty($user['email'])) { continue; - } - elseif( empty($user['realname']) ) { + } elseif (empty($user['realname'])) { $user['realname'] = $user['username']; } $user['level'] = get_userlevel($user['username']); - if( $config["alert"]["globals"] && ( $user['level'] >= 5 && $user['level'] < 10 ) ) { + if ($config["alert"]["globals"] && ( $user['level'] >= 5 && $user['level'] < 10 )) { $contacts[$user['email']] = $user['realname']; - } - elseif( $config["alert"]["admins"] && $user['level'] == 10 ) { + } elseif ($config["alert"]["admins"] && $user['level'] == 10) { $contacts[$user['email']] = $user['realname']; - } - elseif( in_array($user['user_id'],$uids) ) { + } elseif (in_array($user['user_id'], $uids)) { $contacts[$user['email']] = $user['realname']; } } @@ -287,7 +279,7 @@ function GetContacts($results) { if (strstr($email, ',')) { $split_contacts = preg_split("/[,\s]+/", $email); foreach ($split_contacts as $split_email) { - if(!empty($split_email)) { + if (!empty($split_email)) { $tmp_contacts[$split_email] = $name; } } diff --git a/includes/billing.php b/includes/billing.php index 639aca9cc1..3e6934b55c 100644 --- a/includes/billing.php +++ b/includes/billing.php @@ -1,23 +1,24 @@ diff($start)->format("%a"); $since = $now->diff($start)->format("%a"); return($cur_used/$since*$total); - } -function getValue($host, $port, $id, $inout) { +function getValue($host, $port, $id, $inout) +{ global $config; $oid = 'IF-MIB::ifHC'.$inout.'Octets.'.$id; @@ -87,10 +87,10 @@ function getValue($host, $port, $id, $inout) { } return $value; - }//end getValue() -function getLastPortCounter($port_id, $bill_id) { +function getLastPortCounter($port_id, $bill_id) +{ $return = array(); $row = dbFetchRow("SELECT timestamp, in_counter, in_delta, out_counter, out_delta FROM bill_port_counters WHERE `port_id` = ? AND `bill_id` = ?", array($port_id, $bill_id)); if (!is_null($row)) { @@ -100,15 +100,15 @@ function getLastPortCounter($port_id, $bill_id) { $return[out_counter] = $row['out_counter']; $return[out_delta] = $row['out_delta']; $return[state] = 'ok'; - } - else { + } else { $return[state] = 'failed'; } return $return; }//end getLastPortCounter() -function getLastMeasurement($bill_id) { +function getLastMeasurement($bill_id) +{ $return = array(); $row = dbFetchRow("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id = ? ORDER BY timestamp DESC LIMIT 1", array($bill_id)); if (!is_null($row)) { @@ -117,15 +117,15 @@ function getLastMeasurement($bill_id) { $return[delta_out] = $row['delta_out']; $return[timestamp] = $row['timestamp']; $return[state] = 'ok'; - } - else { + } else { $return[state] = 'failed'; } return ($return); }//end getLastMeasurement() -function get95thin($bill_id, $datefrom, $dateto) { +function get95thin($bill_id, $datefrom, $dateto) +{ $mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = '".mres($bill_id)."'"; $mq_sql .= " AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'"; $measurements = dbFetchCell($mq_sql); @@ -137,11 +137,11 @@ function get95thin($bill_id, $datefrom, $dateto) { $m_95th = $a_95th[$measurement_95th]; return (round($m_95th, 2)); - }//end get95thin() -function get95thout($bill_id, $datefrom, $dateto) { +function get95thout($bill_id, $datefrom, $dateto) +{ $mq_sql = "SELECT count(delta) FROM bill_data WHERE bill_id = '".mres($bill_id)."'"; $mq_sql .= " AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'"; $measurements = dbFetchCell($mq_sql); @@ -154,11 +154,11 @@ function get95thout($bill_id, $datefrom, $dateto) { $m_95th = $a_95th[$measurement_95th]; return (round($m_95th, 2)); - }//end get95thout() -function getRates($bill_id, $datefrom, $dateto) { +function getRates($bill_id, $datefrom, $dateto) +{ $data = array(); $mq_text = 'SELECT count(delta) FROM bill_data '; $mq_text .= " WHERE bill_id = '".mres($bill_id)."'"; @@ -184,8 +184,7 @@ function getRates($bill_id, $datefrom, $dateto) { if ($data['rate_95th_out'] > $data['rate_95th_in']) { $data['rate_95th'] = $data['rate_95th_out']; $data['dir_95th'] = 'out'; - } - else { + } else { $data['rate_95th'] = $data['rate_95th_in']; $data['dir_95th'] = 'in'; } @@ -199,26 +198,25 @@ function getRates($bill_id, $datefrom, $dateto) { // print_r($data); return ($data); - }//end getRates() -function getTotal($bill_id, $datefrom, $dateto) { +function getTotal($bill_id, $datefrom, $dateto) +{ $mtot = dbFetchCell("SELECT SUM(delta) FROM bill_data WHERE bill_id = '".mres($bill_id)."' AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'"); return ($mtot); - }//end getTotal() -function getSum($bill_id, $datefrom, $dateto) { +function getSum($bill_id, $datefrom, $dateto) +{ $sum = dbFetchRow("SELECT SUM(period) as period, SUM(delta) as total, SUM(in_delta) as inbound, SUM(out_delta) as outbound FROM bill_data WHERE bill_id = '".mres($bill_id)."' AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'"); return ($sum); - }//end getSum() -function getPeriod($bill_id, $datefrom, $dateto) { +function getPeriod($bill_id, $datefrom, $dateto) +{ $ptot = dbFetchCell("SELECT SUM(period) FROM bill_data WHERE bill_id = '".mres($bill_id)."' AND timestamp > '".mres($datefrom)."' AND timestamp <= '".mres($dateto)."'"); return ($ptot); - }//end getPeriod() diff --git a/includes/caches/devices.inc.php b/includes/caches/devices.inc.php index fae5b1315c..e7fdec80b5 100644 --- a/includes/caches/devices.inc.php +++ b/includes/caches/devices.inc.php @@ -10,8 +10,7 @@ if ($_SESSION['userlevel'] >= 5) { $data['ignored'] = array('query' => "SELECT COUNT(*) FROM devices WHERE `ignore` = '1' AND `disabled` = '0'"); $data['disabled'] = array('query' => "SELECT COUNT(*) FROM devices WHERE `disabled` = '1'"); -} -else { +} else { $data['count'] = array( 'query' => 'SELECT COUNT(*) FROM devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id`', 'params' => array($_SESSION['user_id']), diff --git a/includes/caches/notifications.inc.php b/includes/caches/notifications.inc.php index 0716010a4a..5b099aee47 100644 --- a/includes/caches/notifications.inc.php +++ b/includes/caches/notifications.inc.php @@ -44,4 +44,3 @@ $data['read'] = array( 'query' => 'select notifications.* from notifications inner join notifications_attribs on notifications.notifications_id = notifications_attribs.notifications_id where notifications_attribs.user_id = ? && ( notifications_attribs.key = "read" && notifications_attribs.value = 1) && not exists( select 1 from notifications_attribs where notifications.notifications_id = notifications_attribs.notifications_id and notifications_attribs.key = "sticky" && notifications_attribs.value = "1") order by notifications_attribs.attrib_id desc', 'params' => array( $_SESSION['user_id'] ) ); - diff --git a/includes/caches/ports.inc.php b/includes/caches/ports.inc.php index 2bd97a19d2..3ae9728da9 100644 --- a/includes/caches/ports.inc.php +++ b/includes/caches/ports.inc.php @@ -12,8 +12,7 @@ if ($_SESSION['userlevel'] >= 5) { $data['errored'] = array('query' => "SELECT COUNT(*) FROM ports AS I, devices AS D WHERE I.`deleted` = '0' AND D.`device_id` = I.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"); $data['ignored'] = array('query' => "SELECT COUNT(*) FROM ports AS I, devices AS D WHERE I.`deleted` = '0' AND D.`device_id` = I.`device_id` AND (I.`ignore` = '1' OR D.`ignore` = '1')"); -} -else { +} else { $data['count'] = array( 'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE I.`deleted` = '0' AND P.`user_id` = ? AND P.`device_id` = D.`device_id` AND I.`device_id` = D.`device_id`", 'params' => array($_SESSION['user_id']), diff --git a/includes/caches/services.inc.php b/includes/caches/services.inc.php index 65fa421b4a..741e49c5a6 100644 --- a/includes/caches/services.inc.php +++ b/includes/caches/services.inc.php @@ -6,8 +6,7 @@ if ($_SESSION['userlevel'] >= 5) { $data['down'] = array( 'query' => "SELECT COUNT(*) FROM services WHERE `service_ignore` = '0' AND `service_disabled` = '0' AND `service_status` = '2'"); $data['ignored'] = array( 'query' => "SELECT COUNT(*) FROM services WHERE `service_ignore` = '1' AND `service_disabled` = '0'"); $data['disabled'] = array( 'query' => "SELECT COUNT(*) FROM services WHERE `service_disabled` = '1'"); -} -else { +} else { $data['count'] = array( 'query' => 'SELECT COUNT(*) FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id`', 'params' => array($_SESSION['user_id']), diff --git a/includes/callback.php b/includes/callback.php index 18ae71b6e3..bcc2f183b0 100644 --- a/includes/callback.php +++ b/includes/callback.php @@ -91,8 +91,7 @@ if ($enabled == 1) { curl_setopt($post, CURLOPT_POSTFIELDS, $fields); curl_setopt($post, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($post); -} -else if ($enabled == 2) { +} elseif ($enabled == 2) { $uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'"); $fields = "uuid=$uuid"; diff --git a/includes/common.php b/includes/common.php index 9d79a0936d..98d0eaf756 100644 --- a/includes/common.php +++ b/includes/common.php @@ -16,7 +16,8 @@ * the source code distribution for details. */ -function generate_priority_icon($priority) { +function generate_priority_icon($priority) +{ $map = array( "emerg" => "server_delete", "alert" => "cancel", @@ -31,30 +32,30 @@ function generate_priority_icon($priority) { return ''; } -function format_number_short($number, $sf) { +function format_number_short($number, $sf) +{ // This formats a number so that we only send back three digits plus an optional decimal point. // Example: 723.42 -> 723 72.34 -> 72.3 2.23 -> 2.23 - list($whole, $decimal) = explode (".", $number); + list($whole, $decimal) = explode(".", $number); if (strlen($whole) >= $sf || !is_numeric($decimal)) { $number = $whole; - } - elseif(strlen($whole) < $sf) { + } elseif (strlen($whole) < $sf) { $diff = $sf - strlen($whole); $number = $whole .".".substr($decimal, 0, $diff); } return $number; } -function external_exec($command) { +function external_exec($command) +{ global $debug,$vdebug; if ($debug && !$vdebug) { - $debug_command = preg_replace('/-c [\S]+/','-c COMMUNITY',$command); - $debug_command = preg_replace('/(udp|udp6|tcp|tcp6):(.*):([\d]+)/','\1:HOSTNAME:\3',$debug_command); + $debug_command = preg_replace('/-c [\S]+/', '-c COMMUNITY', $command); + $debug_command = preg_replace('/(udp|udp6|tcp|tcp6):(.*):([\d]+)/', '\1:HOSTNAME:\3', $debug_command); d_echo($debug_command); - } - elseif ($vdebug) { + } elseif ($vdebug) { d_echo($command."\n"); } @@ -63,18 +64,19 @@ function external_exec($command) { if ($debug && !$vdebug) { $debug_output = preg_replace('/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/', '*', $output); d_echo("$debug_output\n"); - } - elseif ($vdebug) { + } elseif ($vdebug) { d_echo($output."\n"); } return $output; } -function shorthost($hostname, $len=12) { +function shorthost($hostname, $len = 12) +{ // IP addresses should not be shortened - if (filter_var($hostname, FILTER_VALIDATE_IP)) + if (filter_var($hostname, FILTER_VALIDATE_IP)) { return $hostname; + } $parts = explode(".", $hostname); $shorthost = $parts[0]; @@ -86,34 +88,35 @@ function shorthost($hostname, $len=12) { return ($shorthost); } -function isCli() { +function isCli() +{ if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { return true; - } - else { + } else { return false; } } -function print_error($text) { +function print_error($text) +{ if (isCli()) { c_echo("%r".$text."%n\n"); - } - else { + } else { echo('
'.$text.'
'); } } -function print_message($text) { +function print_message($text) +{ if (isCli()) { c_echo("%g".$text."%n\n"); - } - else { + } else { echo('
'.$text.'
'); } } -function delete_port($int_id) { +function delete_port($int_id) +{ $interface = dbFetchRow("SELECT * FROM `ports` AS P, `devices` AS D WHERE P.port_id = ? AND D.device_id = P.device_id", array($int_id)); $interface_tables = array('adjacencies', 'ipaddr', 'ip6adjacencies', 'ip6addr', 'mac_accounting', 'bill_ports', 'pseudowires', 'ports'); @@ -126,17 +129,16 @@ function delete_port($int_id) { dbDelete('links', "`remote_port_id` = ?", array($int_id)); dbDelete('bill_ports', "`port_id` = ?", array($int_id)); - unlink(get_port_rrdfile_path ($interface['hostname'], $interface['port_id'])); + unlink(get_port_rrdfile_path($interface['hostname'], $interface['port_id'])); } -function sgn($int) { +function sgn($int) +{ if ($int < 0) { return -1; - } - elseif ($int == 0) { + } elseif ($int == 0) { return 0; - } - else { + } else { return 1; } } @@ -146,7 +148,8 @@ function get_sensor_rrd($device, $sensor) return rrd_name($device['hostname'], get_sensor_rrd_name($device, $sensor)); } -function get_sensor_rrd_name($device, $sensor) { +function get_sensor_rrd_name($device, $sensor) +{ global $config; # For IPMI, sensors tend to change order, and there is no index, so we prefer to use the description as key here. @@ -157,26 +160,27 @@ function get_sensor_rrd_name($device, $sensor) { } } -function getPortRrdName($port_id, $suffix='') +function getPortRrdName($port_id, $suffix = '') { - if(!empty($suffix)) { + if (!empty($suffix)) { $suffix = '-' . $suffix; } return "port-id$port_id$suffix"; } -function get_port_rrdfile_path ($hostname, $port_id, $suffix = '') { +function get_port_rrdfile_path($hostname, $port_id, $suffix = '') +{ return rrd_name($hostname, getPortRrdName($port_id, $suffix)); } -function get_port_by_index_cache($device_id, $ifIndex) { +function get_port_by_index_cache($device_id, $ifIndex) +{ global $port_index_cache; if (isset($port_index_cache[$device_id][$ifIndex]) && is_array($port_index_cache[$device_id][$ifIndex])) { $port = $port_index_cache[$device_id][$ifIndex]; - } - else { + } else { $port = get_port_by_ifIndex($device_id, $ifIndex); $port_index_cache[$device_id][$ifIndex] = $port; } @@ -184,11 +188,13 @@ function get_port_by_index_cache($device_id, $ifIndex) { return $port; } -function get_port_by_ifIndex($device_id, $ifIndex) { +function get_port_by_ifIndex($device_id, $ifIndex) +{ return dbFetchRow("SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?", array($device_id, $ifIndex)); } -function get_all_devices($device, $type = "") { +function get_all_devices($device, $type = "") +{ global $cache; $devices = array(); @@ -197,8 +203,7 @@ function get_all_devices($device, $type = "") { if (isset($cache['devices']['hostname'])) { $devices = array_keys($cache['devices']['hostname']); - } - else { + } else { foreach (dbFetchRows("SELECT `hostname` FROM `devices`") as $data) { $devices[] = $data['hostname']; } @@ -207,96 +212,98 @@ function get_all_devices($device, $type = "") { return $devices; } -function port_by_id_cache($port_id) { +function port_by_id_cache($port_id) +{ return get_port_by_id_cache('port', $port_id); } -function table_from_entity_type($type) { +function table_from_entity_type($type) +{ // Fuck you, english pluralisation. if ($type == "storage") { return $type; - } - else { + } else { return $type."s"; } } -function get_entity_by_id_cache($type, $id) { +function get_entity_by_id_cache($type, $id) +{ global $entity_cache; $table = table_from_entity_type($type); if (is_array($entity_cache[$type][$id])) { $entity = $entity_cache[$type][$id]; - } - else { + } else { $entity = dbFetchRow("SELECT * FROM `".$table."` WHERE `".$type."_id` = ?", array($id)); $entity_cache[$type][$id] = $entity; } return $entity; } -function get_port_by_id($port_id) { +function get_port_by_id($port_id) +{ if (is_numeric($port_id)) { $port = dbFetchRow("SELECT * FROM `ports` WHERE `port_id` = ?", array($port_id)); if (is_array($port)) { return $port; - } - else { - return FALSE; + } else { + return false; } } } -function get_application_by_id($application_id) { +function get_application_by_id($application_id) +{ if (is_numeric($application_id)) { $application = dbFetchRow("SELECT * FROM `applications` WHERE `app_id` = ?", array($application_id)); if (is_array($application)) { return $application; - } - else { - return FALSE; + } else { + return false; } } } -function get_sensor_by_id($sensor_id) { +function get_sensor_by_id($sensor_id) +{ if (is_numeric($sensor_id)) { $sensor = dbFetchRow("SELECT * FROM `sensors` WHERE `sensor_id` = ?", array($sensor_id)); if (is_array($sensor)) { return $sensor; - } - else { - return FALSE; + } else { + return false; } } } -function get_device_id_by_port_id($port_id) { +function get_device_id_by_port_id($port_id) +{ if (is_numeric($port_id)) { $device_id = dbFetchCell("SELECT `device_id` FROM `ports` WHERE `port_id` = ?", array($port_id)); if (is_numeric($device_id)) { return $device_id; - } - else { - return FALSE; + } else { + return false; } } } -function get_device_id_by_app_id($app_id) { +function get_device_id_by_app_id($app_id) +{ if (is_numeric($app_id)) { $device_id = dbFetchCell("SELECT `device_id` FROM `applications` WHERE `app_id` = ?", array($app_id)); if (is_numeric($device_id)) { return $device_id; - } - else { - return FALSE; + } else { + return false; } } } -function ifclass($ifOperStatus, $ifAdminStatus) { +function ifclass($ifOperStatus, $ifAdminStatus) +{ $ifclass = "interface-upup"; if ($ifAdminStatus == "down") { $ifclass = "interface-admindown"; @@ -310,40 +317,41 @@ function ifclass($ifOperStatus, $ifAdminStatus) { return $ifclass; } -function device_by_name($name, $refresh = 0) { +function device_by_name($name, $refresh = 0) +{ // FIXME - cache name > id too. return device_by_id_cache(getidbyname($name), $refresh); } -function accesspoint_by_id($ap_id, $refresh = '0') { +function accesspoint_by_id($ap_id, $refresh = '0') +{ $ap = dbFetchRow("SELECT * FROM `access_points` WHERE `accesspoint_id` = ?", array($ap_id)); return $ap; - } -function device_by_id_cache($device_id, $refresh = '0') { +function device_by_id_cache($device_id, $refresh = '0') +{ global $cache; if (!$refresh && isset($cache['devices']['id'][$device_id]) && is_array($cache['devices']['id'][$device_id])) { $device = $cache['devices']['id'][$device_id]; - } - else { + } else { $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id)); - - //order vrf_lite_cisco with context, this will help to get the vrf_name and instance_name all the time - $vrfs_lite_cisco = dbFetchRows("SELECT * FROM `vrf_lite_cisco` WHERE `device_id` = ?", array($device_id)); - if(!empty($vrfs_lite_cisco)){ - $device['vrf_lite_cisco'] = array(); - foreach ($vrfs_lite_cisco as $vrf){ - $device['vrf_lite_cisco'][$vrf['context_name']] = $vrf; - } - } + + //order vrf_lite_cisco with context, this will help to get the vrf_name and instance_name all the time + $vrfs_lite_cisco = dbFetchRows("SELECT * FROM `vrf_lite_cisco` WHERE `device_id` = ?", array($device_id)); + if (!empty($vrfs_lite_cisco)) { + $device['vrf_lite_cisco'] = array(); + foreach ($vrfs_lite_cisco as $vrf) { + $device['vrf_lite_cisco'][$vrf['context_name']] = $vrf; + } + } - if(!empty($device['ip'])) { + if (!empty($device['ip'])) { $device['ip'] = inet6_ntop($device['ip']); } $cache['devices']['id'][$device_id] = $device; @@ -351,51 +359,52 @@ function device_by_id_cache($device_id, $refresh = '0') { return $device; } -function truncate($substring, $max = 50, $rep = '...') { +function truncate($substring, $max = 50, $rep = '...') +{ if (strlen($substring) < 1) { $string = $rep; - } - else { + } else { $string = $substring; } - $leave = $max - strlen ($rep); + $leave = $max - strlen($rep); if (strlen($string) > $max) { return substr_replace($string, $rep, $leave); - } - else { + } else { return $string; } } -function mres($string) { +function mres($string) +{ // short function wrapper because the real one is stupidly long and ugly. aesthetics. global $config, $database_link; if ($config['db']['extension'] == 'mysqli') { - return mysqli_real_escape_string($database_link,$string); - } - else { + return mysqli_real_escape_string($database_link, $string); + } else { return mysql_real_escape_string($string); } } -function getifhost($id) { +function getifhost($id) +{ return dbFetchCell("SELECT `device_id` from `ports` WHERE `port_id` = ?", array($id)); } -function gethostbyid($id) { +function gethostbyid($id) +{ global $cache; if (isset($cache['devices']['id'][$id]['hostname'])) { $hostname = $cache['devices']['id'][$id]['hostname']; - } - else { + } else { $hostname = dbFetchCell("SELECT `hostname` FROM `devices` WHERE `device_id` = ?", array($id)); } return $hostname; } -function strgen ($length = 16) { +function strgen($length = 16) +{ $entropy = array(0,1,2,3,4,5,6,7,8,9,'a','A','b','B','c','C','d','D','e', 'E','f','F','g','G','h','H','i','I','j','J','k','K','l','L','m','M','n', 'N','o','O','p','P','q','Q','r','R','s','S','t','T','u','U','v','V','w', @@ -403,60 +412,66 @@ function strgen ($length = 16) { $string = ""; for ($i=0; $i<$length; $i++) { - $key = mt_rand(0,61); + $key = mt_rand(0, 61); $string .= $entropy[$key]; } return $string; } -function getpeerhost($id) { +function getpeerhost($id) +{ return dbFetchCell("SELECT `device_id` from `bgpPeers` WHERE `bgpPeer_id` = ?", array($id)); } -function getifindexbyid($id) { +function getifindexbyid($id) +{ return dbFetchCell("SELECT `ifIndex` FROM `ports` WHERE `port_id` = ?", array($id)); } -function getifbyid($id) { +function getifbyid($id) +{ return dbFetchRow("SELECT * FROM `ports` WHERE `port_id` = ?", array($id)); } -function getifdescrbyid($id) { +function getifdescrbyid($id) +{ return dbFetchCell("SELECT `ifDescr` FROM `ports` WHERE `port_id` = ?", array($id)); } -function getidbyname($hostname) { +function getidbyname($hostname) +{ global $cache; if (isset($cache['devices']['hostname'][$hostname])) { $id = $cache['devices']['hostname'][$hostname]; - } - else { + } else { $id = dbFetchCell("SELECT `device_id` FROM `devices` WHERE `hostname` = ?", array($hostname)); } return $id; } -function gethostosbyid($id) { +function gethostosbyid($id) +{ global $cache; if (isset($cache['devices']['id'][$id]['os'])) { $os = $cache['devices']['id'][$id]['os']; - } - else { + } else { $os = dbFetchCell("SELECT `os` FROM `devices` WHERE `device_id` = ?", array($id)); } return $os; } -function safename($name) { +function safename($name) +{ return preg_replace('/[^a-zA-Z0-9,._\-]/', '_', $name); } -function zeropad($num, $length = 2) { +function zeropad($num, $length = 2) +{ while (strlen($num) < $length) { $num = '0'.$num; } @@ -464,17 +479,18 @@ function zeropad($num, $length = 2) { return $num; } -function set_dev_attrib($device, $attrib_type, $attrib_value) { +function set_dev_attrib($device, $attrib_type, $attrib_value) +{ if (dbFetchCell("SELECT COUNT(*) FROM devices_attribs WHERE `device_id` = ? AND `attrib_type` = ?", array($device['device_id'],$attrib_type))) { $return = dbUpdate(array('attrib_value' => $attrib_value), 'devices_attribs', 'device_id=? and attrib_type=?', array($device['device_id'], $attrib_type)); - } - else { + } else { $return = dbInsert(array('device_id' => $device['device_id'], 'attrib_type' => $attrib_type, 'attrib_value' => $attrib_value), 'devices_attribs'); } return $return; } -function get_dev_attribs($device) { +function get_dev_attribs($device) +{ $attribs = array(); foreach (dbFetchRows("SELECT * FROM devices_attribs WHERE `device_id` = ?", array($device)) as $entry) { $attribs[$entry['attrib_type']] = $entry['attrib_value']; @@ -482,7 +498,8 @@ function get_dev_attribs($device) { return $attribs; } -function get_dev_entity_state($device) { +function get_dev_entity_state($device) +{ $state = array(); foreach (dbFetchRows("SELECT * FROM entPhysical_state WHERE `device_id` = ?", array($device)) as $entity) { $state['group'][$entity['group']][$entity['entPhysicalIndex']][$entity['subindex']][$entity['key']] = $entity['value']; @@ -491,7 +508,8 @@ function get_dev_entity_state($device) { return $state; } -function get_dev_attrib($device, $attrib_type, $attrib_value='') { +function get_dev_attrib($device, $attrib_type, $attrib_value = '') +{ $sql = ''; $params = array($device['device_id'], $attrib_type); if (!empty($attrib_value)) { @@ -500,39 +518,42 @@ function get_dev_attrib($device, $attrib_type, $attrib_value='') { } if ($row = dbFetchRow("SELECT attrib_value FROM devices_attribs WHERE `device_id` = ? AND `attrib_type` = ? $sql", $params)) { return $row['attrib_value']; - } - else { - return NULL; + } else { + return null; } } -function is_dev_attrib_enabled($device, $attrib, $default = true) { +function is_dev_attrib_enabled($device, $attrib, $default = true) +{ $val = get_dev_attrib($device, $attrib); if ($val != null) { // attribute is set return ($val != 0); - } - else { + } else { // attribute not set return $default; } } -function del_dev_attrib($device, $attrib_type) { +function del_dev_attrib($device, $attrib_type) +{ return dbDelete('devices_attribs', "`device_id` = ? AND `attrib_type` = ?", array($device['device_id'], $attrib_type)); } -function formatRates($value, $round = '2', $sf = '3') { +function formatRates($value, $round = '2', $sf = '3') +{ $value = format_si($value, $round, $sf) . "bps"; return $value; } -function formatStorage($value, $round = '2', $sf = '3') { +function formatStorage($value, $round = '2', $sf = '3') +{ $value = format_bi($value, $round) . "B"; return $value; } -function format_si($value, $round = '2', $sf = '3') { +function format_si($value, $round = '2', $sf = '3') +{ $neg = 0; if ($value < "0") { $neg = 1; @@ -540,15 +561,14 @@ function format_si($value, $round = '2', $sf = '3') { } if ($value >= "0.1") { - $sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E'); + $sizes = array('', 'k', 'M', 'G', 'T', 'P', 'E'); $ext = $sizes[0]; for ($i = 1; (($i < count($sizes)) && ($value >= 1000)); $i++) { $value = $value / 1000; $ext = $sizes[$i]; } - } - else { - $sizes = Array('', 'm', 'u', 'n'); + } else { + $sizes = array('', 'm', 'u', 'n'); $ext = $sizes[0]; for ($i = 1; (($i < count($sizes)) && ($value != 0) && ($value <= 0.1)); $i++) { $value = $value * 1000; @@ -560,15 +580,16 @@ function format_si($value, $round = '2', $sf = '3') { $value = $value * -1; } - return format_number_short(round($value, $round),$sf).$ext; + return format_number_short(round($value, $round), $sf).$ext; } -function format_bi($value, $round = '2', $sf = '3'){ +function format_bi($value, $round = '2', $sf = '3') +{ if ($value < "0") { $neg = 1; $value = $value * -1; } - $sizes = Array('', 'k', 'M', 'G', 'T', 'P', 'E'); + $sizes = array('', 'k', 'M', 'G', 'T', 'P', 'E'); $ext = $sizes[0]; for ($i = 1; (($i < count($sizes)) && ($value >= 1024)); $i++) { $value = $value / 1024; @@ -582,16 +603,17 @@ function format_bi($value, $round = '2', $sf = '3'){ return format_number_short(round($value, $round), $sf).$ext; } -function format_number($value, $base = '1000', $round=2, $sf=3) { +function format_number($value, $base = '1000', $round = 2, $sf = 3) +{ if ($base == '1000') { return format_si($value, $round, $sf); - } - else { + } else { return format_bi($value, $round, $sf); } } -function is_valid_hostname($hostname) { +function is_valid_hostname($hostname) +{ // The Internet standards (Request for Comments) for protocols mandate that // component hostname labels may contain only the ASCII letters 'a' through 'z' // (in a case-insensitive manner), the digits '0' through '9', and the hyphen @@ -602,23 +624,22 @@ function is_valid_hostname($hostname) { // white space are permitted. While a hostname may not contain other characters, // such as the underscore character (_), other DNS names may contain the underscore - return ctype_alnum(str_replace('_','',str_replace('-','',str_replace('.','',$hostname)))); + return ctype_alnum(str_replace('_', '', str_replace('-', '', str_replace('.', '', $hostname)))); } /* * convenience function - please use this instead of 'if ($debug) { echo ...; }' */ -function d_echo($text, $no_debug_text = null) { +function d_echo($text, $no_debug_text = null) +{ global $debug; if ($debug) { if (is_array($text)) { print_r($text); - } - else { + } else { echo "$text"; } - } - elseif ($no_debug_text) { + } elseif ($no_debug_text) { echo "$no_debug_text"; } } // d_echo @@ -632,12 +653,12 @@ function d_echo($text, $no_debug_text = null) { */ function c_echo($string, $enabled = true) { - if(!$enabled) { + if (!$enabled) { return; } global $console_color; - if($console_color) { + if ($console_color) { echo $console_color->convert($string); } else { echo preg_replace('/%((%)|.)/', '', $string); @@ -647,12 +668,12 @@ function c_echo($string, $enabled = true) /* * convenience function - please use this instead of 'if ($debug) { print_r ...; }' */ -function d_print_r($var, $no_debug_text = null) { +function d_print_r($var, $no_debug_text = null) +{ global $debug; if ($debug) { print_r($var); - } - elseif ($no_debug_text) { + } elseif ($no_debug_text) { echo "$no_debug_text"; } } // d_print_r @@ -661,7 +682,8 @@ function d_print_r($var, $no_debug_text = null) { /* * @return true if the given graph type is a dynamic MIB graph */ -function is_mib_graph($type, $subtype) { +function is_mib_graph($type, $subtype) +{ global $config; return $config['graph_types'][$type][$subtype]['section'] == 'mib'; } // is_mib_graph @@ -670,7 +692,8 @@ function is_mib_graph($type, $subtype) { /* * @return true if client IP address is authorized to access graphs */ -function is_client_authorized($clientip) { +function is_client_authorized($clientip) +{ global $config; if (isset($config['allow_unauth_graphs']) && $config['allow_unauth_graphs']) { @@ -731,7 +754,8 @@ function is_device_graph($device, $subtype) } // is_device_graph -function get_smokeping_files($device) { +function get_smokeping_files($device) +{ global $config; $smokeping_files = array(); if (isset($config['smokeping']['dir'])) { @@ -745,8 +769,7 @@ function get_smokeping_files($device) { $target = str_replace('_', '.', $target); $smokeping_files['in'][$target][$slave] = $file; $smokeping_files['out'][$slave][$target] = $file; - } - else { + } else { $target = str_replace('.rrd', '', $file); $target = str_replace('_', '.', $target); $smokeping_files['in'][$target][$config['own_hostname']] = $file; @@ -761,12 +784,12 @@ function get_smokeping_files($device) { } // end get_smokeping_files -function generate_smokeping_file($device,$file='') { +function generate_smokeping_file($device, $file = '') +{ global $config; if ($config['smokeping']['integration'] === true) { return $config['smokeping']['dir'] .'/'. $device['type'] .'/' . $file; - } - else { + } else { return $config['smokeping']['dir'] . '/' . $file; } } // generate_smokeping_file @@ -775,7 +798,8 @@ function generate_smokeping_file($device,$file='') { /* * @return rounded value to 10th/100th/1000th depending on input (valid: 10, 100, 1000) */ -function round_Nth($val = 0, $round_to) { +function round_Nth($val, $round_to) +{ if (($round_to == "10") || ($round_to == "100") || ($round_to == "1000")) { $diff = $val % $round_to; if ($diff >= ($round_to / 2)) { @@ -785,7 +809,7 @@ function round_Nth($val = 0, $round_to) { } return $ret; } -} // end round_Nth +} // end round_Nth /* @@ -885,10 +909,10 @@ function is_custom_graph($type, $subtype, $device) { if (is_mib_poller_enabled($device) && $device['os'] == 'ruckuswireless' && $type == 'device') { switch ($subtype) { - case 'cpumem': - case 'mempool': - case 'processor': - return true; + case 'cpumem': + case 'mempool': + case 'processor': + return true; } } return false; @@ -941,8 +965,7 @@ function object_is_cached($section, $obj) global $object_cache; if (array_key_exists($obj, $object_cache)) { return $object_cache[$section][$obj]; - } - else { + } else { return false; } } // object_is_cached @@ -955,12 +978,12 @@ function object_is_cached($section, $obj) * @param array $attribs Device attributes * @return bool **/ -function can_ping_device($attribs) { +function can_ping_device($attribs) +{ global $config; if ($config['icmp_check'] === true && $attribs['override_icmp_disable'] != "true") { return true; - } - else { + } else { return false; } } // end can_ping_device @@ -974,8 +997,7 @@ function is_module_enabled($type, $module) global $config; if (isset($config[$type.'_modules'][$module])) { return $config[$type.'_modules'][$module] == 1; - } - else { + } else { return false; } } // is_module_enabled @@ -1020,7 +1042,8 @@ function search_phrase_column($c) } // search_phrase_column -function print_mib_poller_disabled() { +function print_mib_poller_disabled() +{ echo '

MIB polling is not enabled

Set $config[\'poller_modules\'][\'mib\'] = 1; in config.php to enable. @@ -1033,14 +1056,14 @@ Set $config[\'poller_modules\'][\'mib\'] = 1; in config.php to * @param string $gtype The type of rrd we're looking for * @return string **/ -function ceph_rrd($gtype) { +function ceph_rrd($gtype) +{ global $device; global $vars; if ($gtype == "osd") { $var = $vars['osd']; - } - else { + } else { $var = $vars['pool']; } @@ -1052,7 +1075,8 @@ function ceph_rrd($gtype) { * @param string location The location field to look for coords in. * @return array Containing the lat and lng coords **/ -function parse_location($location) { +function parse_location($location) +{ preg_match('/(\[)(-?[0-9\. ]+),[ ]*(-?[0-9\. ]+)(\])/', $location, $tmp_loc); if (!empty($tmp_loc[2]) && !empty($tmp_loc[3])) { return array('lat' => $tmp_loc[2], 'lng' => $tmp_loc[3]); @@ -1063,16 +1087,17 @@ function parse_location($location) { * Returns version info * @return array **/ -function version_info($remote=true) { +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_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['github'] = json_decode(curl_exec($api), true); } list($local_sha, $local_date) = explode('|', rtrim(`git show --pretty='%H|%ct' -s HEAD`)); $output['local_sha'] = $local_sha; @@ -1086,7 +1111,6 @@ function version_info($remote=true) { $output['netsnmp_ver'] = shell_exec($config['snmpget'].' --version 2>&1'); return $output; - }//end version_info() /** @@ -1095,7 +1119,8 @@ function version_info($remote=true) { * @return string Empty if not valid. */ // Fuction is from http://uk3.php.net/manual/en/function.inet-ntop.php -function inet6_ntop($ip) { +function inet6_ntop($ip) +{ $l = strlen($ip); if ($l == 4 or $l == 16) { return inet_ntop(pack('A' . $l, $ip)); @@ -1109,7 +1134,8 @@ function inet6_ntop($ip) { * @param string ip address * @return string **/ -function ip_to_sysname($device,$ip) { +function ip_to_sysname($device, $ip) +{ global $config; if ($config['force_ip_to_sysname'] === true) { if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) == true || filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) == true) { @@ -1124,21 +1150,25 @@ function ip_to_sysname($device,$ip) { * @param bool $no_cache No-Cache flag (optional, default false) * @return array */ -function get_port_assoc_modes ($no_cache = false) { +function get_port_assoc_modes($no_cache = false) +{ global $config; if ($config['memcached']['enable'] && $no_cache === false) { - $assoc_modes = $config['memcached']['resource']->get (hash ('sha512', "port_assoc_modes")); - if (! empty ($assoc_modes)) + $assoc_modes = $config['memcached']['resource']->get(hash('sha512', "port_assoc_modes")); + if (! empty($assoc_modes)) { return $assoc_modes; + } } - $assoc_modes = Null; - foreach (dbFetchRows ("SELECT `name` FROM `port_association_mode` ORDER BY pom_id") as $row) + $assoc_modes = null; + foreach (dbFetchRows("SELECT `name` FROM `port_association_mode` ORDER BY pom_id") as $row) { $assoc_modes[] = $row['name']; + } - if ($config['memcached']['enable'] && $no_cache === false) - $config['memcached']['resource']->set (hash ('sha512', "port_assoc_modes"), $assoc_modes, $config['memcached']['ttl']); + if ($config['memcached']['enable'] && $no_cache === false) { + $config['memcached']['resource']->set(hash('sha512', "port_assoc_modes"), $assoc_modes, $config['memcached']['ttl']); + } return $assoc_modes; } @@ -1148,8 +1178,9 @@ function get_port_assoc_modes ($no_cache = false) { * @param string $port_assoc_mode * @return bool */ -function is_valid_port_assoc_mode ($port_assoc_mode) { - return in_array ($port_assoc_mode, get_port_assoc_modes ()); +function is_valid_port_assoc_mode($port_assoc_mode) +{ + return in_array($port_assoc_mode, get_port_assoc_modes()); } /** @@ -1157,21 +1188,24 @@ function is_valid_port_assoc_mode ($port_assoc_mode) { * @param string $port_assoc_mode * @param bool $no_cache No-Cache flag (optional, default false) */ -function get_port_assoc_mode_id ($port_assoc_mode, $no_cache = false) { +function get_port_assoc_mode_id($port_assoc_mode, $no_cache = false) +{ global $config; if ($config['memcached']['enable'] && $no_cache === false) { - $id = $config['memcached']['resource']->get (hash ('sha512', "port_assoc_mode_id|$port_assoc_mode")); - if (! empty ($id)) + $id = $config['memcached']['resource']->get(hash('sha512', "port_assoc_mode_id|$port_assoc_mode")); + if (! empty($id)) { return $id; + } } - $id = Null; - $row = dbFetchRow ("SELECT `pom_id` FROM `port_association_mode` WHERE name = ?", array ($port_assoc_mode)); + $id = null; + $row = dbFetchRow("SELECT `pom_id` FROM `port_association_mode` WHERE name = ?", array ($port_assoc_mode)); if ($row) { $id = $row['pom_id']; - if ($config['memcached']['enable'] && $no_cache === false) - $config['memcached']['resource']->set (hash ('sha512', "port_assoc_mode_id|$port_assoc_mode"), $id, $config['memcached']['ttl']); + if ($config['memcached']['enable'] && $no_cache === false) { + $config['memcached']['resource']->set(hash('sha512', "port_assoc_mode_id|$port_assoc_mode"), $id, $config['memcached']['ttl']); + } } return $id; @@ -1183,21 +1217,24 @@ function get_port_assoc_mode_id ($port_assoc_mode, $no_cache = false) { * @param bool $no_cache No-Cache flag (optional, default false) * @return bool */ -function get_port_assoc_mode_name ($port_assoc_mode_id, $no_cache = false) { +function get_port_assoc_mode_name($port_assoc_mode_id, $no_cache = false) +{ global $config; if ($config['memcached']['enable'] && $no_cache === false) { - $name = $config['memcached']['resource']->get (hash ('sha512', "port_assoc_mode_name|$port_assoc_mode_id")); - if (! empty ($name)) + $name = $config['memcached']['resource']->get(hash('sha512', "port_assoc_mode_name|$port_assoc_mode_id")); + if (! empty($name)) { return $name; + } } - $name = Null; - $row = dbFetchRow ("SELECT `name` FROM `port_association_mode` WHERE pom_id = ?", array ($port_assoc_mode_id)); + $name = null; + $row = dbFetchRow("SELECT `name` FROM `port_association_mode` WHERE pom_id = ?", array ($port_assoc_mode_id)); if ($row) { $name = $row['name']; - if ($config['memcached']['enable'] && $no_cache === false) - $config['memcached']['resource']->set (hash ('sha512', "port_assoc_mode_name|$port_assoc_mode_id"), $name, $config['memcached']['ttl']); + if ($config['memcached']['enable'] && $no_cache === false) { + $config['memcached']['resource']->set(hash('sha512', "port_assoc_mode_name|$port_assoc_mode_id"), $name, $config['memcached']['ttl']); + } } return $name; @@ -1211,7 +1248,8 @@ function get_port_assoc_mode_name ($port_assoc_mode_id, $no_cache = false) { * @param bool $with_statistics Query port statistics, too. (optional, default false) * @return array */ -function get_ports_mapped ($device_id, $with_statistics = false) { +function get_ports_mapped($device_id, $with_statistics = false) +{ $ports = array(); $maps = array( 'ifIndex' => array(), @@ -1228,7 +1266,7 @@ function get_ports_mapped ($device_id, $with_statistics = false) { // Query known ports in order of discovery to make sure the latest // discoverd/polled port is in the mapping tables. - foreach (dbFetchRows ($query, array ($device_id)) as $port) { + foreach (dbFetchRows($query, array ($device_id)) as $port) { // Store port information by ports port_id from DB $ports[$port['port_id']] = $port; @@ -1251,9 +1289,10 @@ function get_ports_mapped ($device_id, $with_statistics = false) { * @param string $port_association_mode Port association mode to use for mapping * @return int port_id (or Null) */ -function get_port_id ($ports_mapped, $port, $port_association_mode) { +function get_port_id($ports_mapped, $port, $port_association_mode) +{ // Get port_id according to port_association_mode used for this device - $port_id = Null; + $port_id = null; /* * Information an all ports is available through $ports_mapped['ports'] @@ -1264,7 +1303,7 @@ function get_port_id ($ports_mapped, $port, $port_association_mode) { */ $maps = $ports_mapped['maps']; - if (in_array ($port_association_mode, array ('ifIndex', 'ifName', 'ifDescr', 'ifAlias'))) { + if (in_array($port_association_mode, array ('ifIndex', 'ifName', 'ifDescr', 'ifAlias'))) { $port_id = $maps[$port_association_mode][$port[$port_association_mode]]; } @@ -1280,50 +1319,47 @@ function get_port_id ($ports_mapped, $port, $port_association_mode) { * @param array $last Glues on the fringe * @return string|boolean */ -function ResolveGlues($tables,$target,$x=0,$hist=array(),$last=array()) { - if( sizeof($tables) == 1 && $x != 0 ) { - if( dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?',array($tables[0],$target)) == 1 ) { - return array_merge($last,array($tables[0].'.'.$target)); - } - else { +function ResolveGlues($tables, $target, $x = 0, $hist = array(), $last = array()) +{ + if (sizeof($tables) == 1 && $x != 0) { + if (dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?', array($tables[0],$target)) == 1) { + return array_merge($last, array($tables[0].'.'.$target)); + } else { return false; } - } - else { + } else { $x++; - if( $x > 30 ) { + if ($x > 30) { //Too much recursion. Abort. return false; } - foreach( $tables as $table ) { - $glues = dbFetchRows('SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME LIKE "%\_id"',array($table)); - if( sizeof($glues) == 1 && $glues[0]['COLUMN_NAME'] != $target ) { + foreach ($tables as $table) { + $glues = dbFetchRows('SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME LIKE "%\_id"', array($table)); + if (sizeof($glues) == 1 && $glues[0]['COLUMN_NAME'] != $target) { //Search for new candidates to expand $ntables = array(); - list($tmp) = explode('_',$glues[0]['COLUMN_NAME'],2); + list($tmp) = explode('_', $glues[0]['COLUMN_NAME'], 2); $ntables[] = $tmp; $ntables[] = $tmp.'s'; - $tmp = dbFetchRows('SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_NAME LIKE "'.substr($table,0,-1).'_%" && TABLE_NAME != "'.$table.'"'); - foreach( $tmp as $expand ) { + $tmp = dbFetchRows('SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_NAME LIKE "'.substr($table, 0, -1).'_%" && TABLE_NAME != "'.$table.'"'); + foreach ($tmp as $expand) { $ntables[] = $expand['TABLE_NAME']; } - $tmp = ResolveGlues($ntables,$target,$x++,array_merge($tables,$ntables),array_merge($last,array($table.'.'.$glues[0]['COLUMN_NAME']))); - if( is_array($tmp) ) { + $tmp = ResolveGlues($ntables, $target, $x++, array_merge($tables, $ntables), array_merge($last, array($table.'.'.$glues[0]['COLUMN_NAME']))); + if (is_array($tmp)) { return $tmp; } - } - else { - foreach( $glues as $glue ) { - if( $glue['COLUMN_NAME'] == $target ) { - return array_merge($last,array($table.'.'.$target)); - } - else { - list($tmp) = explode('_',$glue['COLUMN_NAME']); + } else { + foreach ($glues as $glue) { + if ($glue['COLUMN_NAME'] == $target) { + return array_merge($last, array($table.'.'.$target)); + } else { + list($tmp) = explode('_', $glue['COLUMN_NAME']); $tmp .= 's'; - if( !in_array($tmp,$tables) && !in_array($tmp,$hist) ) { + if (!in_array($tmp, $tables) && !in_array($tmp, $hist)) { //Expand table - $tmp = ResolveGlues(array($tmp),$target,$x++,array_merge($tables,array($tmp)),array_merge($last,array($table.'.'.$glue['COLUMN_NAME']))); - if( is_array($tmp) ) { + $tmp = ResolveGlues(array($tmp), $target, $x++, array_merge($tables, array($tmp)), array_merge($last, array($table.'.'.$glue['COLUMN_NAME']))); + if (is_array($tmp)) { return $tmp; } } diff --git a/includes/datastore.inc.php b/includes/datastore.inc.php index 756deb7b4f..37d18d0458 100644 --- a/includes/datastore.inc.php +++ b/includes/datastore.inc.php @@ -71,4 +71,3 @@ function data_update($device, $measurement, $tags, $fields) rrdtool_data_update($device, $measurement, $tags, $fields); influx_update($device, $measurement, rrd_array_filter($tags), $fields); } // data_update - diff --git a/includes/dbFacile.mysql.php b/includes/dbFacile.mysql.php index 026412d474..1d7fa5a2dc 100644 --- a/includes/dbFacile.mysql.php +++ b/includes/dbFacile.mysql.php @@ -23,19 +23,18 @@ * */ -function dbQuery($sql, $parameters=array()) { +function dbQuery($sql, $parameters = array()) +{ global $fullSql, $debug, $sql_debug; $fullSql = dbMakeQuery($sql, $parameters); if ($debug) { if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { - if (preg_match('/(INSERT INTO `alert_log`).*(details)/i',$fullSql)) { + if (preg_match('/(INSERT INTO `alert_log`).*(details)/i', $fullSql)) { echo "\nINSERT INTO `alert_log` entry masked due to binary data\n"; - } - else { + } else { c_echo("\nSQL[%y".$fullSql.'%n] '); } - } - else { + } else { $sql_debug[] = $fullSql; } } @@ -60,7 +59,6 @@ function dbQuery($sql, $parameters=array()) { } return $result; - }//end dbQuery() @@ -70,7 +68,8 @@ function dbQuery($sql, $parameters=array()) { * */ -function dbInsert($data, $table) { +function dbInsert($data, $table) +{ global $fullSql; global $db_stats; // the following block swaps the parameters if they were given in the wrong order. @@ -93,8 +92,7 @@ function dbInsert($data, $table) { $id = mysql_insert_id(); dbCommitTransaction(); // return $id; - } - else { + } else { if ($table != 'Contact') { trigger_error('QDB - Insert failed.', E_USER_WARNING); } @@ -109,7 +107,6 @@ function dbInsert($data, $table) { $db_stats['insert']++; return $id; - }//end dbInsert() @@ -120,7 +117,8 @@ function dbInsert($data, $table) { * */ -function dbBulkInsert($data, $table) { +function dbBulkInsert($data, $table) +{ global $db_stats; // the following block swaps the parameters if they were given in the wrong order. // it allows the method to work for those that would rather it (or expect it to) @@ -164,7 +162,6 @@ function dbBulkInsert($data, $table) { $db_stats['insert']++; return $result; - }//end dbBulkInsert() @@ -174,7 +171,8 @@ function dbBulkInsert($data, $table) { * */ -function dbUpdate($data, $table, $where=null, $parameters=array()) { +function dbUpdate($data, $table, $where = null, $parameters = array()) +{ global $fullSql; global $db_stats; // the following block swaps the parameters if they were given in the wrong order. @@ -205,8 +203,7 @@ function dbUpdate($data, $table, $where=null, $parameters=array()) { $time_start = microtime(true); if (dbQuery($sql, $data)) { $return = mysql_affected_rows(); - } - else { + } else { // echo("$fullSql"); trigger_error('QDB - Update failed.', E_USER_WARNING); $return = false; @@ -217,11 +214,11 @@ function dbUpdate($data, $table, $where=null, $parameters=array()) { $db_stats['update']++; return $return; - }//end dbUpdate() -function dbDelete($table, $where=null, $parameters=array()) { +function dbDelete($table, $where = null, $parameters = array()) +{ $sql = 'DELETE FROM `'.$table.'`'; if ($where) { $sql .= ' WHERE '.$where; @@ -229,11 +226,9 @@ function dbDelete($table, $where=null, $parameters=array()) { if (dbQuery($sql, $parameters)) { return mysql_affected_rows(); - } - else { + } else { return false; } - }//end dbDelete() @@ -243,11 +238,12 @@ function dbDelete($table, $where=null, $parameters=array()) { * */ -function dbFetchRows($sql, $parameters=array(), $nocache=false) { +function dbFetchRows($sql, $parameters = array(), $nocache = false) +{ global $db_stats, $config; if ($config['memcached']['enable'] && $nocache === false) { - $result = $config['memcached']['resource']->get(hash('sha512',$sql.'|'.serialize($parameters))); + $result = $config['memcached']['resource']->get(hash('sha512', $sql.'|'.serialize($parameters))); if (!empty($result)) { return $result; } @@ -264,7 +260,7 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) { mysql_free_result($result); if ($config['memcached']['enable'] && $nocache === false) { - $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']); + $config['memcached']['resource']->set(hash('sha512', $sql.'|'.serialize($parameters)), $rows, $config['memcached']['ttl']); } return $rows; } @@ -278,7 +274,6 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) { // no records, thus return empty array // which should evaluate to false, and will prevent foreach notices/warnings return array(); - }//end dbFetchRows() @@ -288,7 +283,8 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) { * */ -function dbFetch($sql, $parameters=array(), $nocache=false) { +function dbFetch($sql, $parameters = array(), $nocache = false) +{ return dbFetchRows($sql, $parameters, $nocache); /* // for now, don't do the iterator thing @@ -300,7 +296,6 @@ function dbFetch($sql, $parameters=array(), $nocache=false) { return null; // ?? } */ - }//end dbFetch() @@ -310,11 +305,12 @@ function dbFetch($sql, $parameters=array(), $nocache=false) { * */ -function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { +function dbFetchRow($sql = null, $parameters = array(), $nocache = false) +{ global $db_stats, $config; if ($config['memcached']['enable'] && $nocache === false) { - $result = $config['memcached']['resource']->get(hash('sha512',$sql.'|'.serialize($parameters))); + $result = $config['memcached']['resource']->get(hash('sha512', $sql.'|'.serialize($parameters))); if (!empty($result)) { return $result; } @@ -331,16 +327,14 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { $db_stats['fetchrow']++; if ($config['memcached']['enable'] && $nocache === false) { - $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']); + $config['memcached']['resource']->set(hash('sha512', $sql.'|'.serialize($parameters)), $row, $config['memcached']['ttl']); } return $row; - } - else { + } else { return null; } $time_start = microtime(true); - }//end dbFetchRow() @@ -349,7 +343,8 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { * */ -function dbFetchCell($sql, $parameters=array(), $nocache=false) { +function dbFetchCell($sql, $parameters = array(), $nocache = false) +{ global $db_stats; $time_start = microtime(true); $row = dbFetchRow($sql, $parameters, $nocache); @@ -364,7 +359,6 @@ function dbFetchCell($sql, $parameters=array(), $nocache=false) { $db_stats['fetchcell']++; return null; - }//end dbFetchCell() @@ -374,7 +368,8 @@ function dbFetchCell($sql, $parameters=array(), $nocache=false) { * */ -function dbFetchColumn($sql, $parameters=array(), $nocache=false) { +function dbFetchColumn($sql, $parameters = array(), $nocache = false) +{ global $db_stats; $time_start = microtime(true); $cells = array(); @@ -388,7 +383,6 @@ function dbFetchColumn($sql, $parameters=array(), $nocache=false) { $db_stats['fetchcol']++; return $cells; - }//end dbFetchColumn() @@ -399,7 +393,8 @@ function dbFetchColumn($sql, $parameters=array(), $nocache=false) { */ -function dbFetchKeyValue($sql, $parameters=array()) { +function dbFetchKeyValue($sql, $parameters = array()) +{ $data = array(); foreach (dbFetch($sql, $parameters) as $row) { $key = array_shift($row); @@ -407,8 +402,7 @@ function dbFetchKeyValue($sql, $parameters=array()) { // if there were only 2 fields in the result // use the second for the value $data[$key] = array_shift($row); - } - else { + } else { // if more than 2 fields were fetched // use the array of the rest as the value $data[$key] = $row; @@ -416,7 +410,6 @@ function dbFetchKeyValue($sql, $parameters=array()) { } return $data; - }//end dbFetchKeyValue() @@ -426,7 +419,8 @@ function dbFetchKeyValue($sql, $parameters=array()) { */ -function dbMakeQuery($sql, $parameters) { +function dbMakeQuery($sql, $parameters) +{ // bypass extra logic if we have no parameters if (sizeof($parameters) == 0) { return $sql; @@ -439,8 +433,7 @@ function dbMakeQuery($sql, $parameters) { foreach ($parameters as $key => $value) { if (is_numeric($key)) { $questionParams[] = $value; - } - else { + } else { $namedParams[':'.$key] = $value; } } @@ -462,19 +455,18 @@ function dbMakeQuery($sql, $parameters) { $test = $result[$j]; if ($test == '?') { $query .= array_shift($questionParams); - } - else { + } else { $query .= $namedParams[$test]; } } } return $query; - }//end dbMakeQuery() -function dbPrepareData($data) { +function dbPrepareData($data) +{ $values = array(); foreach ($data as $key => $value) { @@ -493,14 +485,12 @@ function dbPrepareData($data) { // continue; if ($escape) { $values[$key] = "'".mysql_real_escape_string($value)."'"; - } - else { + } else { $values[$key] = $value; } } return $values; - }//end dbPrepareData() @@ -510,37 +500,36 @@ function dbPrepareData($data) { */ -function dbPlaceHolders($values) { +function dbPlaceHolders($values) +{ $data = array(); foreach ($values as $key => $value) { if (is_numeric($key)) { $data[] = '?'; - } - else { + } else { $data[] = ':'.$key; } } return $data; - }//end dbPlaceHolders() -function dbBeginTransaction() { +function dbBeginTransaction() +{ mysql_query('begin'); - }//end dbBeginTransaction() -function dbCommitTransaction() { +function dbCommitTransaction() +{ mysql_query('commit'); - }//end dbCommitTransaction() -function dbRollbackTransaction() { +function dbRollbackTransaction() +{ mysql_query('rollback'); - }//end dbRollbackTransaction() diff --git a/includes/dbFacile.mysqli.php b/includes/dbFacile.mysqli.php index 4ff60930d3..296092b4a0 100644 --- a/includes/dbFacile.mysqli.php +++ b/includes/dbFacile.mysqli.php @@ -23,19 +23,18 @@ * */ -function dbQuery($sql, $parameters=array()) { +function dbQuery($sql, $parameters = array()) +{ global $fullSql, $debug, $sql_debug, $database_link; $fullSql = dbMakeQuery($sql, $parameters); if ($debug) { if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) { - if (preg_match('/(INSERT INTO `alert_log`).*(details)/i',$fullSql)) { + if (preg_match('/(INSERT INTO `alert_log`).*(details)/i', $fullSql)) { echo "\nINSERT INTO `alert_log` entry masked due to binary data\n"; - } - else { + } else { c_echo("\nSQL[%y".$fullSql.'%n] '); } - } - else { + } else { $sql_debug[] = $fullSql; } } @@ -60,7 +59,6 @@ function dbQuery($sql, $parameters=array()) { } return $result; - }//end dbQuery() @@ -70,7 +68,8 @@ function dbQuery($sql, $parameters=array()) { * */ -function dbInsert($data, $table) { +function dbInsert($data, $table) +{ global $fullSql, $database_link; global $db_stats; // the following block swaps the parameters if they were given in the wrong order. @@ -93,8 +92,7 @@ function dbInsert($data, $table) { $id = mysqli_insert_id($database_link); dbCommitTransaction(); // return $id; - } - else { + } else { if ($table != 'Contact') { trigger_error('QDB - Insert failed.', E_USER_WARNING); } @@ -109,7 +107,6 @@ function dbInsert($data, $table) { $db_stats['insert']++; return $id; - }//end dbInsert() @@ -120,7 +117,8 @@ function dbInsert($data, $table) { * */ -function dbBulkInsert($data, $table) { +function dbBulkInsert($data, $table) +{ global $db_stats; // the following block swaps the parameters if they were given in the wrong order. // it allows the method to work for those that would rather it (or expect it to) @@ -164,7 +162,6 @@ function dbBulkInsert($data, $table) { $db_stats['insert']++; return $result; - }//end dbBulkInsert() @@ -174,7 +171,8 @@ function dbBulkInsert($data, $table) { * */ -function dbUpdate($data, $table, $where=null, $parameters=array()) { +function dbUpdate($data, $table, $where = null, $parameters = array()) +{ global $fullSql, $database_link; global $db_stats; // the following block swaps the parameters if they were given in the wrong order. @@ -205,8 +203,7 @@ function dbUpdate($data, $table, $where=null, $parameters=array()) { $time_start = microtime(true); if (dbQuery($sql, $data)) { $return = mysqli_affected_rows($database_link); - } - else { + } else { // echo("$fullSql"); trigger_error('QDB - Update failed.', E_USER_WARNING); $return = false; @@ -217,11 +214,11 @@ function dbUpdate($data, $table, $where=null, $parameters=array()) { $db_stats['update']++; return $return; - }//end dbUpdate() -function dbDelete($table, $where=null, $parameters=array()) { +function dbDelete($table, $where = null, $parameters = array()) +{ global $database_link; $sql = 'DELETE FROM `'.$table.'`'; if ($where) { @@ -230,11 +227,9 @@ function dbDelete($table, $where=null, $parameters=array()) { if (dbQuery($sql, $parameters)) { return mysqli_affected_rows($database_link); - } - else { + } else { return false; } - }//end dbDelete() @@ -244,11 +239,12 @@ function dbDelete($table, $where=null, $parameters=array()) { * */ -function dbFetchRows($sql, $parameters=array(), $nocache=false) { +function dbFetchRows($sql, $parameters = array(), $nocache = false) +{ global $db_stats, $config; if ($config['memcached']['enable'] && $nocache === false) { - $result = $config['memcached']['resource']->get(hash('sha512',$sql.'|'.serialize($parameters))); + $result = $config['memcached']['resource']->get(hash('sha512', $sql.'|'.serialize($parameters))); if (!empty($result)) { return $result; } @@ -265,7 +261,7 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) { mysqli_free_result($result); if ($config['memcached']['enable'] && $nocache === false) { - $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']); + $config['memcached']['resource']->set(hash('sha512', $sql.'|'.serialize($parameters)), $rows, $config['memcached']['ttl']); } return $rows; } @@ -279,7 +275,6 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) { // no records, thus return empty array // which should evaluate to false, and will prevent foreach notices/warnings return array(); - }//end dbFetchRows() @@ -289,7 +284,8 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) { * */ -function dbFetch($sql, $parameters=array(), $nocache=false) { +function dbFetch($sql, $parameters = array(), $nocache = false) +{ return dbFetchRows($sql, $parameters, $nocache); /* // for now, don't do the iterator thing @@ -301,7 +297,6 @@ function dbFetch($sql, $parameters=array(), $nocache=false) { return null; // ?? } */ - }//end dbFetch() @@ -311,11 +306,12 @@ function dbFetch($sql, $parameters=array(), $nocache=false) { * */ -function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { +function dbFetchRow($sql = null, $parameters = array(), $nocache = false) +{ global $db_stats, $config; if ($config['memcached']['enable'] && $nocache === false) { - $result = $config['memcached']['resource']->get(hash('sha512',$sql.'|'.serialize($parameters))); + $result = $config['memcached']['resource']->get(hash('sha512', $sql.'|'.serialize($parameters))); if (!empty($result)) { return $result; } @@ -332,16 +328,14 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { $db_stats['fetchrow']++; if ($config['memcached']['enable'] && $nocache === false) { - $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']); + $config['memcached']['resource']->set(hash('sha512', $sql.'|'.serialize($parameters)), $row, $config['memcached']['ttl']); } return $row; - } - else { + } else { return null; } $time_start = microtime(true); - }//end dbFetchRow() @@ -350,7 +344,8 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { * */ -function dbFetchCell($sql, $parameters=array(), $nocache=false) { +function dbFetchCell($sql, $parameters = array(), $nocache = false) +{ global $db_stats, $config; $time_start = microtime(true); @@ -366,7 +361,6 @@ function dbFetchCell($sql, $parameters=array(), $nocache=false) { $db_stats['fetchcell']++; return null; - }//end dbFetchCell() @@ -376,7 +370,8 @@ function dbFetchCell($sql, $parameters=array(), $nocache=false) { * */ -function dbFetchColumn($sql, $parameters=array(), $nocache=false) { +function dbFetchColumn($sql, $parameters = array(), $nocache = false) +{ global $db_stats; $time_start = microtime(true); $cells = array(); @@ -390,7 +385,6 @@ function dbFetchColumn($sql, $parameters=array(), $nocache=false) { $db_stats['fetchcol']++; return $cells; - }//end dbFetchColumn() @@ -401,7 +395,8 @@ function dbFetchColumn($sql, $parameters=array(), $nocache=false) { */ -function dbFetchKeyValue($sql, $parameters=array(), $nocache=false) { +function dbFetchKeyValue($sql, $parameters = array(), $nocache = false) +{ $data = array(); foreach (dbFetch($sql, $parameters, $nocache) as $row) { $key = array_shift($row); @@ -409,8 +404,7 @@ function dbFetchKeyValue($sql, $parameters=array(), $nocache=false) { // if there were only 2 fields in the result // use the second for the value $data[$key] = array_shift($row); - } - else { + } else { // if more than 2 fields were fetched // use the array of the rest as the value $data[$key] = $row; @@ -418,7 +412,6 @@ function dbFetchKeyValue($sql, $parameters=array(), $nocache=false) { } return $data; - }//end dbFetchKeyValue() @@ -428,7 +421,8 @@ function dbFetchKeyValue($sql, $parameters=array(), $nocache=false) { */ -function dbMakeQuery($sql, $parameters) { +function dbMakeQuery($sql, $parameters) +{ // bypass extra logic if we have no parameters if (sizeof($parameters) == 0) { return $sql; @@ -441,8 +435,7 @@ function dbMakeQuery($sql, $parameters) { foreach ($parameters as $key => $value) { if (is_numeric($key)) { $questionParams[] = $value; - } - else { + } else { $namedParams[':'.$key] = $value; } } @@ -464,19 +457,18 @@ function dbMakeQuery($sql, $parameters) { $test = $result[$j]; if ($test == '?') { $query .= array_shift($questionParams); - } - else { + } else { $query .= $namedParams[$test]; } } } return $query; - }//end dbMakeQuery() -function dbPrepareData($data) { +function dbPrepareData($data) +{ global $database_link; $values = array(); @@ -495,15 +487,13 @@ function dbPrepareData($data) { // if(!in_array($key, $columns)) // skip invalid fields // continue; if ($escape) { - $values[$key] = "'".mysqli_real_escape_string($database_link,$value)."'"; - } - else { + $values[$key] = "'".mysqli_real_escape_string($database_link, $value)."'"; + } else { $values[$key] = $value; } } return $values; - }//end dbPrepareData() @@ -513,40 +503,39 @@ function dbPrepareData($data) { */ -function dbPlaceHolders($values) { +function dbPlaceHolders($values) +{ $data = array(); foreach ($values as $key => $value) { if (is_numeric($key)) { $data[] = '?'; - } - else { + } else { $data[] = ':'.$key; } } return $data; - }//end dbPlaceHolders() -function dbBeginTransaction() { +function dbBeginTransaction() +{ global $database_link; mysqli_query($database_link, 'begin'); - }//end dbBeginTransaction() -function dbCommitTransaction() { +function dbCommitTransaction() +{ global $database_link; mysqli_query($database_link, 'commit'); - }//end dbCommitTransaction() -function dbRollbackTransaction() { +function dbRollbackTransaction() +{ global $database_link; mysqli_query($database_link, 'rollback'); - }//end dbRollbackTransaction() diff --git a/includes/dbFacile.php b/includes/dbFacile.php index 7e7989bcab..f8fdbd057a 100644 --- a/includes/dbFacile.php +++ b/includes/dbFacile.php @@ -2,8 +2,7 @@ if (file_exists($config['install_dir'].'/includes/dbFacile.'.$config['db']['extension'].'.php')) { require_once $config['install_dir'].'/includes/dbFacile.'.$config['db']['extension'].'.php'; -} -else { +} else { echo $config['db']['extension'] . " extension not found\n"; exit; } diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 1f3a6d28b3..c3cda7161f 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -23,7 +23,8 @@ // error_reporting(E_ERROR|E_PARSE|E_CORE_ERROR|E_COMPILE_ERROR); -function set_debug($debug) { +function set_debug($debug) +{ if (isset($debug)) { ini_set('display_errors', 1); ini_set('display_startup_errors', 0); @@ -107,8 +108,7 @@ if (isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT'])) { if (strpos($_SERVER['SERVER_NAME'], ':')) { // Literal IPv6 $config['base_url'] = 'http://['.$_SERVER['SERVER_NAME'].']'.($_SERVER['SERVER_PORT'] != 80 ? ':'.$_SERVER['SERVER_PORT'] : '').'/'; - } - else { + } else { $config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].($_SERVER['SERVER_PORT'] != 80 ? ':'.$_SERVER['SERVER_PORT'] : '').'/'; } } @@ -172,7 +172,7 @@ $config['show_services'] = 0; $config['ports_page_default'] = 'details'; // eg "details" or "basic" // Adding Host Settings -$config['addhost_alwayscheckip'] = FALSE; # TRUE - check for duplicate ips even when adding host by name. FALSE- only check when adding host by ip. +$config['addhost_alwayscheckip'] = false; # TRUE - check for duplicate ips even when adding host by name. FALSE- only check when adding host by ip. // SNMP Settings - Timeouts/Retries disabled as default // $config['snmp']['timeout'] = 1; # timeout in seconds // $config['snmp']['retries'] = 5; # how many times to retry the query @@ -883,7 +883,7 @@ $config['update_channel'] = 'master'; $config['default_port_association_mode'] = 'ifIndex'; // Ignore ports which can't be mapped using a devices port_association_mode // See include/polling/ports.inc.php for a lenghty explanation. -$config['ignore_unmapable_port'] = False; +$config['ignore_unmapable_port'] = false; // InfluxDB default configuration $config['influxdb']['timeout'] = 0; @@ -891,4 +891,3 @@ $config['influxdb']['verifySSL'] = false; // Xirrus - Disable station/client polling if true as it may take a long time on larger/heavily used APs. $config['xirrus_disable_stations'] = false; - diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index 124a5de8ef..d036fe9e56 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -7,8 +7,7 @@ require_once $config['install_dir'].'/includes/mergecnf.inc.php'; // Connect to database if ($config['db']['extension'] == 'mysqli') { $database_link = mysqli_connect('p:'.$config['db_host'], $config['db_user'], $config['db_pass']); -} -else { +} else { $database_link = mysql_pconnect($config['db_host'], $config['db_user'], $config['db_pass']); } @@ -16,17 +15,15 @@ if (!$database_link) { echo '

MySQL Error

'; if ($config['db']['extension'] == 'mysqli') { echo mysqli_error($database_link); - } - else { + } else { echo mysql_error(); } -die; + die; } if ($config['db']['extension'] == 'mysqli') { $database_db = mysqli_select_db($database_link, $config['db_name']); -} -else { +} else { $database_db = mysql_select_db($config['db_name'], $database_link); } @@ -35,8 +32,7 @@ if ($config['memcached']['enable'] === true) { $config['memcached']['ttl'] = 60; $config['memcached']['resource'] = new Memcached(); $config['memcached']['resource']->addServer($config['memcached']['host'], $config['memcached']['port']); - } - else { + } else { echo "WARNING: You have enabled memcached but have not installed the PHP bindings. Disabling memcached support.\n"; echo "Try 'apt-get install php5-memcached' or 'pecl install memcached'. You will need the php5-dev and libmemcached-dev packages to use pecl.\n\n"; $config['memcached']['enable'] = 0; @@ -576,9 +572,9 @@ $config['os'][$os]['over'][4]['text'] = 'Number of Clients'; $config['os'][$os]['icon'] = 'cisco'; $os = 'vcs'; -$config['os'][$os]['text'] = 'Video Communication Server'; -$config['os'][$os]['type'] = 'collaboration'; -$config['os'][$os]['icon'] = 'cisco'; +$config['os'][$os]['text'] = 'Video Communication Server'; +$config['os'][$os]['type'] = 'collaboration'; +$config['os'][$os]['icon'] = 'cisco'; $os = 'acano'; $config['os'][$os]['group'] = 'cisco'; @@ -631,22 +627,22 @@ $config['os'][$os]['over'][2]['graph'] = 'device_mempool'; $config['os'][$os]['over'][2]['text'] = 'Memory Usage'; $os = 'primeinfrastructure'; -$config['os'][$os]['text'] = 'Prime Infrastructure'; -$config['os'][$os]['type'] = 'server'; -$config['os'][$os]['icon'] = 'cisco'; -$config['os'][$os]['over'][0]['graph'] = 'device_bits'; -$config['os'][$os]['over'][0]['text'] = 'Device Traffic'; -$config['os'][$os]['over'][1]['graph'] = 'device_processor'; -$config['os'][$os]['over'][1]['text'] = 'CPU Usage'; -$config['os'][$os]['over'][2]['graph'] = 'device_mempool'; -$config['os'][$os]['over'][2]['text'] = 'Memory Usage'; -$config['os'][$os]['over'][3]['graph'] = 'device_storage'; -$config['os'][$os]['over'][3]['text'] = 'Storage Usage'; +$config['os'][$os]['text'] = 'Prime Infrastructure'; +$config['os'][$os]['type'] = 'server'; +$config['os'][$os]['icon'] = 'cisco'; +$config['os'][$os]['over'][0]['graph'] = 'device_bits'; +$config['os'][$os]['over'][0]['text'] = 'Device Traffic'; +$config['os'][$os]['over'][1]['graph'] = 'device_processor'; +$config['os'][$os]['over'][1]['text'] = 'CPU Usage'; +$config['os'][$os]['over'][2]['graph'] = 'device_mempool'; +$config['os'][$os]['over'][2]['text'] = 'Memory Usage'; +$config['os'][$os]['over'][3]['graph'] = 'device_storage'; +$config['os'][$os]['over'][3]['text'] = 'Storage Usage'; $os = 'tpconductor'; -$config['os'][$os]['text'] = 'TelePresence Conductor'; -$config['os'][$os]['type'] = 'collaboration'; -$config['os'][$os]['icon'] = 'cisco'; +$config['os'][$os]['text'] = 'TelePresence Conductor'; +$config['os'][$os]['type'] = 'collaboration'; +$config['os'][$os]['icon'] = 'cisco'; // Brocade NOS $os = 'nos'; diff --git a/includes/device-groups.inc.php b/includes/device-groups.inc.php index e023a96376..8adb08e114 100644 --- a/includes/device-groups.inc.php +++ b/includes/device-groups.inc.php @@ -76,10 +76,11 @@ function EditDeviceGroup($group_id, $name = null, $desc = null, $pattern = null) * @param string $search What to searchid for * @return string */ -function GenGroupSQL($pattern, $search='',$extra=0) { +function GenGroupSQL($pattern, $search = '', $extra = 0) +{ $pattern = RunGroupMacros($pattern); if ($pattern === false) { - return false; + return false; } $tmp = explode(' ', $pattern); $tables = array(); @@ -96,33 +97,32 @@ function GenGroupSQL($pattern, $search='',$extra=0) { $pattern = rtrim($pattern, '||'); $tables = array_keys(array_flip($tables)); - if( dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?',array($tables[0],'device_id')) != 1 ) { + if (dbFetchCell('SELECT 1 FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME = ?', array($tables[0],'device_id')) != 1) { //Our first table has no valid glue, append the 'devices' table to it! array_unshift($tables, 'devices'); } $x = sizeof($tables)-1; $i = 0; $join = ""; - while( $i < $x ) { - if( isset($tables[$i+1]) ) { - $gtmp = ResolveGlues(array($tables[$i+1]),'device_id'); - if( $gtmp === false ) { + while ($i < $x) { + if (isset($tables[$i+1])) { + $gtmp = ResolveGlues(array($tables[$i+1]), 'device_id'); + if ($gtmp === false) { //Cannot resolve glue-chain. Rule is invalid. return false; } $last = ""; $qry = ""; - foreach( $gtmp as $glue ) { - if( empty($last) ) { - list($tmp,$last) = explode('.',$glue); + foreach ($gtmp as $glue) { + if (empty($last)) { + list($tmp,$last) = explode('.', $glue); $qry .= $glue.' = '; - } - else { - list($tmp,$new) = explode('.',$glue); + } else { + list($tmp,$new) = explode('.', $glue); $qry .= $tmp.'.'.$last.' && '.$tmp.'.'.$new.' = '; $last = $new; } - if( !in_array($tmp, $tables) ) { + if (!in_array($tmp, $tables)) { $tables[] = $tmp; } } @@ -134,14 +134,13 @@ function GenGroupSQL($pattern, $search='',$extra=0) { $sql_extra = ",`devices`.*"; } if (!empty($search)) { - $search = str_replace("(","",$tables[0]).'.'.$search. ' AND'; + $search = str_replace("(", "", $tables[0]).'.'.$search. ' AND'; } if (!empty($join)) { $join = '('.rtrim($join, ' && ').') &&'; } $sql = 'SELECT DISTINCT('.str_replace('(', '', $tables[0]).'.device_id)'.$sql_extra.' FROM '.implode(',', $tables).' WHERE '.$join.' '.$search.' ('.str_replace(array('%', '@', '!~', '~'), array('', '.*', 'NOT REGEXP', 'REGEXP'), $pattern).')'; return $sql; - }//end GenGroupSQL() @@ -160,7 +159,6 @@ function QueryDevicesFromGroup($group_id) } return false; - }//end QueryDevicesFromGroup() /** @@ -183,9 +181,9 @@ function GetDevicesFromGroup($group_id, $nested = false) * Get all Device-Groups * @return array */ -function GetDeviceGroups() { +function GetDeviceGroups() +{ return dbFetchRows('SELECT * FROM device_groups ORDER BY name'); - }//end GetDeviceGroups() /** @@ -194,21 +192,20 @@ function GetDeviceGroups() { * @param int $extra Return extra info about the groups (name, desc, pattern) * @return array */ -function QueryGroupsFromDevice($device_id,$extra=0) { +function QueryGroupsFromDevice($device_id, $extra = 0) +{ $ret = array(); foreach (GetDeviceGroups() as $group) { - if (dbFetchCell(GenGroupSQL($group['pattern'], 'device_id=?',$extra).' LIMIT 1', array($device_id)) == $device_id) { + if (dbFetchCell(GenGroupSQL($group['pattern'], 'device_id=?', $extra).' LIMIT 1', array($device_id)) == $device_id) { if ($extra === 0) { $ret[] = $group['id']; - } - else { + } else { $ret[] = $group; } } } return $ret; - }//end QueryGroupsFromDevice() /** @@ -234,17 +231,18 @@ function GetGroupsFromDevice($device_id, $extra = 0) * @param int $x Recursion-Anchor * @return string|boolean */ -function RunGroupMacros($rule,$x=1) { +function RunGroupMacros($rule, $x = 1) +{ global $config; krsort($config['alert']['macros']['group']); - foreach( $config['alert']['macros']['group'] as $macro=>$value ) { - if( !strstr($macro," ") ) { - $rule = str_replace('%macros.'.$macro,'('.$value.')',$rule); + foreach ($config['alert']['macros']['group'] as $macro => $value) { + if (!strstr($macro, " ")) { + $rule = str_replace('%macros.'.$macro, '('.$value.')', $rule); } } - if( strstr($rule,"%macros") ) { - if( ++$x < 30 ) { - $rule = RunGroupMacros($rule,$x); + if (strstr($rule, "%macros")) { + if (++$x < 30) { + $rule = RunGroupMacros($rule, $x); } else { return false; } @@ -279,7 +277,6 @@ function UpdateGroupsForDevice($device_id) if (!empty($removed_groups)) { dbDelete('device_group_device', '`device_id`=? AND `device_group_id` IN (?)', array($device_id, array(implode(',', $removed_groups)))); } - } /** diff --git a/includes/discovery/arp-table.inc.php b/includes/discovery/arp-table.inc.php index 73de45f2c0..812430e640 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -2,90 +2,88 @@ unset($mac_table); -if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ +if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0)) { $vrfs_lite_cisco = $device['vrf_lite_cisco']; -} -else { +} else { $vrfs_lite_cisco = array(array('context_name'=>null)); } foreach ($vrfs_lite_cisco as $vrf) { $device['context_name']=$vrf['context_name']; -$ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB'); -$ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data)); -$ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data)); + $ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB'); + $ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data)); + $ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data)); -foreach (explode("\n", $ipNetToMedia_data) as $data) { - list($oid, $mac) = explode(' ', $data); - list($if, $first, $second, $third, $fourth) = explode('.', $oid); - $ip = $first.'.'.$second.'.'.$third.'.'.$fourth; - if ($ip != '...') { - $interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if)); + foreach (explode("\n", $ipNetToMedia_data) as $data) { + list($oid, $mac) = explode(' ', $data); + list($if, $first, $second, $third, $fourth) = explode('.', $oid); + $ip = $first.'.'.$second.'.'.$third.'.'.$fourth; + if ($ip != '...') { + $interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if)); - list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac); - $m_a = zeropad($m_a); - $m_b = zeropad($m_b); - $m_c = zeropad($m_c); - $m_d = zeropad($m_d); - $m_e = zeropad($m_e); - $m_f = zeropad($m_f); - $md_a = hexdec($m_a); - $md_b = hexdec($m_b); - $md_c = hexdec($m_c); - $md_d = hexdec($m_d); - $md_e = hexdec($m_e); - $md_f = hexdec($m_f); - $mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f"; + list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac); + $m_a = zeropad($m_a); + $m_b = zeropad($m_b); + $m_c = zeropad($m_c); + $m_d = zeropad($m_d); + $m_e = zeropad($m_e); + $m_f = zeropad($m_f); + $md_a = hexdec($m_a); + $md_b = hexdec($m_b); + $md_c = hexdec($m_c); + $md_d = hexdec($m_d); + $md_e = hexdec($m_e); + $md_f = hexdec($m_f); + $mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f"; - $mac_table[$if][$mac]['ip'] = $ip; - $mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f"; - $clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f; - $mac_table[$if][$mac]['cleanmac'] = $clean_mac; - $port_id = $interface['port_id']; - $mac_table[$port_id][$clean_mac] = 1; + $mac_table[$if][$mac]['ip'] = $ip; + $mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f"; + $clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f; + $mac_table[$if][$mac]['cleanmac'] = $clean_mac; + $port_id = $interface['port_id']; + $mac_table[$port_id][$clean_mac] = 1; - if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ?', array($interface['port_id'], $ip))) { - // Commented below, no longer needed but leaving for reference. - // $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'"; - $old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=?', array($ip, $interface['port_id'])); + if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ?', array($interface['port_id'], $ip))) { + // Commented below, no longer needed but leaving for reference. + // $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'"; + $old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=?', array($ip, $interface['port_id'])); - if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') { - d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n"); + if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') { + d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n"); - log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']); - } + log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']); + } - dbUpdate(array('mac_address' => $clean_mac, 'context_name' => $device['context_name']), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip)); - echo '.'; - } - else if (isset($interface['port_id'])) { - echo '+'; - // echo("Add MAC $mac\n"); - $insert_data = array( + dbUpdate(array('mac_address' => $clean_mac, 'context_name' => $device['context_name']), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip)); + echo '.'; + } elseif (isset($interface['port_id'])) { + echo '+'; + // echo("Add MAC $mac\n"); + $insert_data = array( 'port_id' => $interface['port_id'], 'mac_address' => $clean_mac, 'ipv4_address' => $ip, 'context_name' => $device['context_name'], ); - dbInsert($insert_data, 'ipv4_mac'); + dbInsert($insert_data, 'ipv4_mac'); + }//end if }//end if - }//end if -}//end foreach + }//end foreach -$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '".$device['device_id']."'"; -foreach (dbFetchRows($sql) as $entry) { - $entry_mac = $entry['mac_address']; - $entry_if = $entry['port_id']; - if (!$mac_table[$entry_if][$entry_mac]) { - dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if, $entry_mac)); - d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']); + $sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '".$device['device_id']."'"; + foreach (dbFetchRows($sql) as $entry) { + $entry_mac = $entry['mac_address']; + $entry_if = $entry['port_id']; + if (!$mac_table[$entry_if][$entry_mac]) { + dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if, $entry_mac)); + d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']); - echo '-'; + echo '-'; + } } -} -echo "\n"; -unset($mac); + echo "\n"; + unset($mac); unset($device['context_name']); } unset($vrfs_c); diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index c312527a0f..ae941351d3 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -2,10 +2,9 @@ if ($config['enable_bgp']) { // Discover BGP peers - if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0)) { $vrfs_lite_cisco = $device['vrf_lite_cisco']; - } - else{ + } else { $vrfs_lite_cisco = array(array('context_name'=>null)); } @@ -13,232 +12,228 @@ if ($config['enable_bgp']) { foreach ($vrfs_lite_cisco as $vrf) { $device['context_name'] = $vrf['context_name']; - if (is_numeric($bgpLocalAs)) { - echo "AS$bgpLocalAs "; - if ($bgpLocalAs != $device['bgpLocalAs']) { - dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id'])); - echo 'Updated AS '; + if (is_numeric($bgpLocalAs)) { + echo "AS$bgpLocalAs "; + if ($bgpLocalAs != $device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id'])); + echo 'Updated AS '; + } + + $peer2 = false; + if ($device['os'] !== 'junos') { + $peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']); + if (empty($peers_data)) { + $peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']); + } else { + $peer2 = true; } - $peer2 = false; - if ($device['os'] !== 'junos') { - $peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']); - if (empty($peers_data)) { - $peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']); - } - else { - $peer2 = true; + d_echo("Peers : $peers_data \n"); + + $peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data)); + $peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers)); + + foreach (explode("\n", $peers) as $peer) { + if ($peer2 === true) { + list($ver, $peer) = explode('.', $peer, 2); } - d_echo("Peers : $peers_data \n"); + list($peer_ip, $peer_as) = explode(' ', $peer); + if (strstr($peer_ip, ':')) { + $peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip); + $peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp); + $peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip)); + } - $peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data)); - $peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers)); + if ($peer && $peer_ip != '0.0.0.0') { + d_echo("Found peer $peer_ip (AS$peer_as)\n"); + + $peerlist[] = array( + 'ip' => $peer_ip, + 'as' => $peer_as, + 'ver' => $ver, + ); + } + } + } elseif ($device['os'] == 'junos') { + // Juniper BGP4-V2 MIB + // FIXME: needs a big cleanup! also see below. + // FIXME: is .0.ipv6 the only possible value here? + $result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + $peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.', '', $result)); + foreach (explode("\n", $peers) as $peer) { + list($peer_ip_snmp, $peer_as) = explode(' ', $peer); + // Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs. + $octets = count(explode(".", $peer_ip_snmp)); + if ($octets > 11) { + // ipv6 + $peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16))))); + } else { + // ipv4 + $peer_ip = implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 4))); + } + + if ($peer) { + d_echo("Found peer $peer_ip (AS$peer_as)\n"); + + $peerlist[] = array( + 'ip' => $peer_ip, + 'as' => $peer_as, + ); + } + } + } + } else { + echo 'No BGP on host'; + if ($device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); + echo ' (Removed ASN) '; + } + } + + // Process disovered peers + if (isset($peerlist)) { + foreach ($peerlist as $peer) { + $astext = get_astext($peer['as']); + + if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') { + $add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as'], 'context_name' => $device['context_name']), 'bgpPeers'); + if ($config['autodiscovery']['bgp'] === true) { + $name = gethostbyaddr($peer['ip']); + $remote_device_id = discover_new_device($name, $device, 'BGP'); + } + + echo '+'; + } else { + $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); + echo '.'; + } + + if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { + if ($device['os_group'] == 'cisco') { + // Get afi/safi and populate cbgp on cisco ios (xe/xr) + unset($af_list); - foreach (explode("\n", $peers) as $peer) { if ($peer2 === true) { - list($ver, $peer) = explode('.', $peer, 2); - } - - list($peer_ip, $peer_as) = explode(' ', $peer); - if (strstr($peer_ip, ':')) { - $peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip); - $peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp); - $peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip)); - } - - if ($peer && $peer_ip != '0.0.0.0') { - d_echo("Found peer $peer_ip (AS$peer_as)\n"); - - $peerlist[] = array( - 'ip' => $peer_ip, - 'as' => $peer_as, - 'ver' => $ver, - ); - } - } - } elseif ($device['os'] == 'junos') { - // Juniper BGP4-V2 MIB - // FIXME: needs a big cleanup! also see below. - // FIXME: is .0.ipv6 the only possible value here? - $result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - $peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.', '', $result)); - foreach (explode("\n", $peers) as $peer) { - list($peer_ip_snmp, $peer_as) = explode(' ', $peer); - // Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs. - $octets = count(explode(".", $peer_ip_snmp)); - if ($octets > 11) { - // ipv6 - $peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16))))); + $af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); } else { - // ipv4 - $peer_ip = implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 4))); + $af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); } - if ($peer) { - d_echo("Found peer $peer_ip (AS$peer_as)\n"); - - $peerlist[] = array( - 'ip' => $peer_ip, - 'as' => $peer_as, - ); - } - } - } - } - else { - echo 'No BGP on host'; - if ($device['bgpLocalAs']) { - dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); - echo ' (Removed ASN) '; - } - } - - // Process disovered peers - if (isset($peerlist)) { - foreach ($peerlist as $peer) { - $astext = get_astext($peer['as']); - - if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') { - $add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as'], 'context_name' => $device['context_name']), 'bgpPeers'); - if ($config['autodiscovery']['bgp'] === true) { - $name = gethostbyaddr($peer['ip']); - $remote_device_id = discover_new_device($name, $device, 'BGP'); - } - - echo '+'; - } - else { - $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); - echo '.'; - } - - if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { - if ($device['os_group'] == 'cisco') { - // Get afi/safi and populate cbgp on cisco ios (xe/xr) - unset($af_list); + d_echo('afi data :: '); + d_echo($af_data); + foreach ($af_data as $k => $v) { if ($peer2 === true) { - $af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); - } - else { - $af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); + list(,$k) = explode('.', $k, 2); } - d_echo('afi data :: '); - d_echo($af_data); + d_echo("AFISAFI = $k\n"); - foreach ($af_data as $k => $v) { - if ($peer2 === true) { - list(,$k) = explode('.', $k, 2); - } - - d_echo("AFISAFI = $k\n"); - - $afisafi_tmp = explode('.', $k); - $safi = array_pop($afisafi_tmp); - $afi = array_pop($afisafi_tmp); - $bgp_ip = str_replace(".$afi.$safi", '', $k); - $bgp_ip = preg_replace('/:/', ' ', $bgp_ip); - $bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip); - $bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip)); - if ($afi && $safi && $bgp_ip == $peer['ip']) { - $af_list[$bgp_ip][$afi][$safi] = 1; - if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) { - dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi, 'context_name' => $device['context_name']), 'bgpPeers_cbgp'); - } - } - } - } - - if ($device['os'] == 'junos') { - $safis[1] = 'unicast'; - $safis[2] = 'multicast'; - - if (!isset($j_peerIndexes)) { - $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerEntry', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - print_r($j_bgp); - foreach ($j_bgp as $index => $entry) { - switch ($entry['jnxBgpM2PeerRemoteAddrType']) { - case 'ipv4': - $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr'])); - d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n"); - - $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex']; - break; - - case 'ipv6': - $ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"'); - $ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4); - $ip6 = Net_IPv6::compress($ip6); - d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n"); - - $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; - break; - - default: - echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; - break; - } - } - } - - if (!isset($j_afisafi)) { - $j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - foreach (array_keys($j_prefixes) as $key) { - list($index,$afisafi) = explode('.', $key, 2); - $j_afisafi[$index][] = $afisafi; - } - } - - foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) { - list ($afi,$safi) = explode('.', $afisafi); - $safi = $safis[$safi]; - $af_list[$afi][$safi] = 1; + $afisafi_tmp = explode('.', $k); + $safi = array_pop($afisafi_tmp); + $afi = array_pop($afisafi_tmp); + $bgp_ip = str_replace(".$afi.$safi", '', $k); + $bgp_ip = preg_replace('/:/', ' ', $bgp_ip); + $bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip); + $bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip)); + if ($afi && $safi && $bgp_ip == $peer['ip']) { + $af_list[$bgp_ip][$afi][$safi] = 1; if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) { - dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp'); + dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi, 'context_name' => $device['context_name']), 'bgpPeers_cbgp'); } } } - - $af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'"; - foreach (dbFetchRows($af_query) as $entry) { - $afi = $entry['afi']; - $safi = $entry['safi']; - if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) { - dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)); - } - } } - } - unset($j_afisafi); - unset($j_prefixes); - unset($j_bgp); - unset($j_peerIndexes); + if ($device['os'] == 'junos') { + $safis[1] = 'unicast'; + $safis[2] = 'multicast'; + + if (!isset($j_peerIndexes)) { + $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerEntry', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + print_r($j_bgp); + foreach ($j_bgp as $index => $entry) { + switch ($entry['jnxBgpM2PeerRemoteAddrType']) { + case 'ipv4': + $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr'])); + d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n"); + + $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex']; + break; + + case 'ipv6': + $ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"'); + $ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4); + $ip6 = Net_IPv6::compress($ip6); + d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n"); + + $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; + break; + + default: + echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; + break; + } + } + } + + if (!isset($j_afisafi)) { + $j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + foreach (array_keys($j_prefixes) as $key) { + list($index,$afisafi) = explode('.', $key, 2); + $j_afisafi[$index][] = $afisafi; + } + } + + foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) { + list ($afi,$safi) = explode('.', $afisafi); + $safi = $safis[$safi]; + $af_list[$afi][$safi] = 1; + if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) { + dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp'); + } + } + } + + $af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'"; + foreach (dbFetchRows($af_query) as $entry) { + $afi = $entry['afi']; + $safi = $entry['safi']; + if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) { + dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)); + } + } + } } + unset($j_afisafi); + unset($j_prefixes); + unset($j_bgp); + unset($j_peerIndexes); + } + // Delete removed peers $sql = "SELECT * FROM bgpPeers WHERE device_id = '".$device['device_id']."' AND context_name = '".$device['context_name']."'"; - foreach (dbFetchRows($sql) as $entry) { - unset($exists); - $i = 0; - while ($i < count($peerlist) && !isset($exists)) { - if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) { - $exists = 1; - } - - $i++; + foreach (dbFetchRows($sql) as $entry) { + unset($exists); + $i = 0; + while ($i < count($peerlist) && !isset($exists)) { + if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) { + $exists = 1; } - if (!isset($exists)) { - dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); - dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); - echo '-'; - } + $i++; } + if (!isset($exists)) { + dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); + dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); + echo '-'; + } + } + unset($peerlist); echo "\n"; diff --git a/includes/discovery/cisco-cbqos.inc.php b/includes/discovery/cisco-cbqos.inc.php index e87fccda60..e61b62f80a 100644 --- a/includes/discovery/cisco-cbqos.inc.php +++ b/includes/discovery/cisco-cbqos.inc.php @@ -12,11 +12,10 @@ */ if ($device['os_group'] == 'cisco') { - $module = 'Cisco-CBQOS'; $component = new LibreNMS\Component(); - $components = $component->getComponents($device['device_id'],array('type'=>$module)); + $components = $component->getComponents($device['device_id'], array('type'=>$module)); // We only care about our device id. $components = $components[$device['device_id']]; @@ -36,16 +35,14 @@ if ($device['os_group'] == 'cisco') { * False == no object found - this is not an error, there is no QOS configured * null == timeout or something else that caused an error, there may be QOS configured but we couldn't get it. */ - if ( is_null($tblcbQosServicePolicy) || is_null($tblcbQosObjects) || is_null($tblcbQosPolicyMapCfg) || is_null($tblcbQosClassMapCfg) || is_null($tblcbQosMatchStmtCfg) ) { + if (is_null($tblcbQosServicePolicy) || is_null($tblcbQosObjects) || is_null($tblcbQosPolicyMapCfg) || is_null($tblcbQosClassMapCfg) || is_null($tblcbQosMatchStmtCfg)) { // We have to error here or we will end up deleting all our QoS components. echo "Error\n"; - } - else { + } else { // No Error, lets process things. d_echo("QoS Objects Found:\n"); foreach ($tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.2'] as $spid => $array) { - foreach ($array as $spobj => $index) { $result = array(); @@ -88,17 +85,15 @@ if ($device['os_group'] == 'cisco') { d_echo(" If-Index: ".$result['ifindex']."\n"); d_echo(" Type: 2 - Class-Map\n"); $result['label'] = $tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.1'][$index]; - if($tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.2'][$index] != "") { + if ($tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.2'][$index] != "") { $result['label'] .= " - ".$tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.2'][$index]; } d_echo(" Label: ".$result['label']."\n"); if ($tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.3'][$index] == 2) { $result['map-type'] = 'Match-All'; - } - elseif ($tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.3'][$index] == 3) { + } elseif ($tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.3'][$index] == 3) { $result['map-type'] = 'Match-Any'; - } - else { + } else { $result['map-type'] = 'None'; } @@ -131,7 +126,7 @@ if ($device['os_group'] == 'cisco') { $component_key = false; // Loop over our components to determine if the component exists, or we need to add it. - foreach ($components as $compid => $child) { + foreach ($components as $compid => $child) { if ($child['UID'] === $array['UID']) { $component_key = $compid; } @@ -139,17 +134,15 @@ if ($device['os_group'] == 'cisco') { if (!$component_key) { // The component doesn't exist, we need to ADD it - ADD. - $new_component = $component->createComponent($device['device_id'],$module); + $new_component = $component->createComponent($device['device_id'], $module); $component_key = key($new_component); $components[$component_key] = array_merge($new_component[$component_key], $array); echo "+"; - } - else { + } else { // The component does exist, merge the details in - UPDATE. $components[$component_key] = array_merge($components[$component_key], $array); echo "."; } - } /* @@ -174,9 +167,7 @@ if ($device['os_group'] == 'cisco') { } // Write the Components back to the DB. - $component->setComponentPrefs($device['device_id'],$components); + $component->setComponentPrefs($device['device_id'], $components); echo "\n"; - } // End if not error - } diff --git a/includes/discovery/cisco-mac-accounting.inc.php b/includes/discovery/cisco-mac-accounting.inc.php index 89047a454e..28f472760c 100644 --- a/includes/discovery/cisco-mac-accounting.inc.php +++ b/includes/discovery/cisco-mac-accounting.inc.php @@ -1,7 +1,6 @@ $interface['port_id'], 'mac' => $clean_mac), 'mac_accounting'); echo '+'; diff --git a/includes/discovery/cisco-otv.inc.php b/includes/discovery/cisco-otv.inc.php index 065da5a455..20abcedbf9 100644 --- a/includes/discovery/cisco-otv.inc.php +++ b/includes/discovery/cisco-otv.inc.php @@ -12,7 +12,6 @@ */ if ($device['os_group'] == 'cisco') { - // Define some error messages $error_vpn = array(); $error_vpn[0] = "Other"; @@ -60,7 +59,7 @@ if ($device['os_group'] == 'cisco') { $module = 'Cisco-OTV'; $component = new LibreNMS\Component(); - $components = $component->getComponents($device['device_id'],array('type'=>$module)); + $components = $component->getComponents($device['device_id'], array('type'=>$module)); // We only care about our device id. $components = $components[$device['device_id']]; @@ -78,11 +77,10 @@ if ($device['os_group'] == 'cisco') { * False == no object found - this is not an error, there is no QOS configured * null == timeout or something else that caused an error, there may be QOS configured but we couldn't get it. */ - if ( is_null($tblOverlayEntry) || is_null($tblAdjacencyDatabaseEntry) || is_null($tblAdjacentDevName) ) { + if (is_null($tblOverlayEntry) || is_null($tblAdjacencyDatabaseEntry) || is_null($tblAdjacentDevName)) { // We have to error here or we will end up deleting all our components. echo "Error\n"; - } - else { + } else { // No Error, lets process things. // Add each overlay to the array. @@ -93,8 +91,7 @@ if ($device['os_group'] == 'cisco') { $result['label'] = $name; if ($tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.15'][$index] == 1) { $result['transport'] = 'Multicast'; - } - else { + } else { $result['transport'] = 'Unicast'; } $result['otvtype'] = 'overlay'; @@ -116,8 +113,7 @@ if ($device['os_group'] == 'cisco') { if ($message !== false) { $result['error'] = $message; $result['status'] = 2; - } - else { + } else { $result['error'] = ""; $result['status'] = 0; } @@ -154,8 +150,7 @@ if ($device['os_group'] == 'cisco') { if ($message !== false) { $result['error'] = $message; $result['status'] = 1; - } - else { + } else { $result['error'] = ""; $result['status'] = 0; } @@ -215,17 +210,15 @@ if ($device['os_group'] == 'cisco') { if (!$component_key) { // The component doesn't exist, we need to ADD it - ADD. - $new_component = $component->createComponent($device['device_id'],$module); + $new_component = $component->createComponent($device['device_id'], $module); $component_key = key($new_component); $components[$component_key] = array_merge($new_component[$component_key], $array); echo "+"; - } - else { + } else { // The component does exist, merge the details in - UPDATE. $components[$component_key] = array_merge($components[$component_key], $array); echo "."; } - } /* @@ -250,9 +243,7 @@ if ($device['os_group'] == 'cisco') { } // Write the Components back to the DB. - $component->setComponentPrefs($device['device_id'],$components); + $component->setComponentPrefs($device['device_id'], $components); echo "\n"; - } // End if not error - } diff --git a/includes/discovery/cisco-pw.inc.php b/includes/discovery/cisco-pw.inc.php index 9f1eac88bf..0abf6c681f 100644 --- a/includes/discovery/cisco-pw.inc.php +++ b/includes/discovery/cisco-pw.inc.php @@ -29,8 +29,7 @@ if ($config['enable_pseudowires'] && $device['os_group'] == 'cisco') { if (!empty($device['pws_db'][$pw['cpwVcID']])) { $pseudowire_id = $device['pws_db'][$pw['cpwVcID']]; echo '.'; - } - else { + } else { $pseudowire_id = dbInsert( array( 'device_id' => $device['device_id'], diff --git a/includes/discovery/cisco-sla.inc.php b/includes/discovery/cisco-sla.inc.php index 9f9359c3c7..3c1fed5a13 100644 --- a/includes/discovery/cisco-sla.inc.php +++ b/includes/discovery/cisco-sla.inc.php @@ -1,7 +1,6 @@ $device['device_id'])); foreach ($sla_table as $sla_nr => $sla_config) { - $query_data = array( + $query_data = array( 'device_id' => $device['device_id'], 'sla_nr' => $sla_nr, ); @@ -52,24 +51,23 @@ if ($config['enable_sla'] && $device['os_group'] == 'cisco') { switch ($data['rtt_type']) { case 'http': $data['tag'] = $sla_config['rttMonEchoAdminURL']; - break; + break; case 'dns': $data['tag'] = $sla_config['rttMonEchoAdminTargetAddressString']; - break; + break; case 'echo': $parts = explode(' ', $sla_config['rttMonEchoAdminTargetAddress']); if (count($parts) == 4) { // IPv4 $data['tag'] = implode('.', array_map('hexdec', $parts)); - } - else if (count($parts) == 16) { + } elseif (count($parts) == 16) { // IPv6 $data['tag'] = $parts[0].$parts[1].':'.$parts[2].$parts[3].':'.$parts[4].$parts[5].':'.$parts[6].$parts[7].':'.$parts[8].$parts[9].':'.$parts[10].$parts[11].':'.$parts[12].$parts[13].':'.$parts[14].$parts[15]; $data['tag'] = preg_replace('/:0*([0-9])/', ':$1', $data['tag']); } - break; + break; case 'jitter': $data['tag'] = $sla_config['rttMonEchoAdminCodecType'] ." (". preg_replace('/milliseconds/', 'ms', $sla_config['rttMonEchoAdminCodecInterval']) .")"; @@ -80,8 +78,7 @@ if ($config['enable_sla'] && $device['os_group'] == 'cisco') { if (!$sla_id) { $sla_id = dbInsert($data, 'slas'); echo '+'; - } - else { + } else { // Remove from the list $existing_slas = array_diff($existing_slas, array($sla_id)); diff --git a/includes/discovery/cisco-vrf-lite.inc.php b/includes/discovery/cisco-vrf-lite.inc.php index 49f16707fe..22a752d975 100644 --- a/includes/discovery/cisco-vrf-lite.inc.php +++ b/includes/discovery/cisco-vrf-lite.inc.php @@ -19,7 +19,6 @@ global $debug; // This one only will work with the CISCO-CONTEXT-MAPPING-MIB V2 of cisco if ($config['enable_vrf_lite_cisco']) { - $ids = array(); // For the moment only will be cisco and the version 3 @@ -27,7 +26,7 @@ if ($config['enable_vrf_lite_cisco']) { $mib = "SNMP-COMMUNITY-MIB"; $mib = "CISCO-CONTEXT-MAPPING-MIB"; //-Osq because if i put the n the oid from the first command is not the same of this one - $listVrf = snmp_walk($device, "cContextMappingVrfName", "-Osq -Ln", $mib, NULL); + $listVrf = snmp_walk($device, "cContextMappingVrfName", "-Osq -Ln", $mib, null); $listVrf = str_replace("cContextMappingVrfName.", "", $listVrf); $listVrf = str_replace('"', "", $listVrf); $listVrf = trim($listVrf); @@ -45,13 +44,13 @@ if ($config['enable_vrf_lite_cisco']) { } unset($listVrf); - $listIntance = snmp_walk($device, "cContextMappingProtoInstName", "-Osq -Ln", $mib, NULL); + $listIntance = snmp_walk($device, "cContextMappingProtoInstName", "-Osq -Ln", $mib, null); $listIntance = str_replace("cContextMappingProtoInstName.", "", $listIntance); $listIntance = str_replace('"', "", $listIntance); $listIntance = trim($listIntance); - d_echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); - d_echo ("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n"); + d_echo("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + d_echo("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n"); foreach (explode("\n", $listIntance) as $lineIntance) { $tmpIntance = explode(" ", $lineIntance, 2); @@ -76,12 +75,12 @@ if ($config['enable_vrf_lite_cisco']) { $vrfUpdate=array(); foreach ($vrfUpdate as $key => $value) { - if($vrf[$key]!=$value){ + if ($vrf[$key]!=$value) { $vrfUpdate[$key]=$value; } } if (!empty($vrfUpdate)) { - dbUpdate($vrfUpdate, 'vrf_lite_cisco', 'vrf_lite_cisco_id=?', array( + dbUpdate($vrfUpdate, 'vrf_lite_cisco', 'vrf_lite_cisco_id=?', array( $tmp['vrf_lite_cisco_id'] )); } @@ -98,7 +97,7 @@ if ($config['enable_vrf_lite_cisco']) { unset($tableVrf); } - //get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work + //get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work $tmpVrfC = dbFetchRows("SELECT * FROM vrf_lite_cisco WHERE device_id = ? ", array( $device ['device_id'])); $device['vrf_lite_cisco'] = $tmpVrfC; @@ -115,4 +114,3 @@ if ($config['enable_vrf_lite_cisco']) { unset($ids); unset($tmpVrfC); } // enable_vrf_lite_cisco - diff --git a/includes/discovery/cisco-vrf.inc.php b/includes/discovery/cisco-vrf.inc.php index 1651db2219..8f8a9ff8bb 100644 --- a/includes/discovery/cisco-vrf.inc.php +++ b/includes/discovery/cisco-vrf.inc.php @@ -23,8 +23,7 @@ if ($config['enable_vrfs']) { $descrs_oid = '.1.3.6.1.3.118.1.2.2.1.2'; $ports_oid = '.1.3.6.1.3.118.1.2.1.1.2'; - } - else { + } else { $vpnmib = 'MPLS-L3VPN-STD-MIB'; $rds = str_replace('.1.3.6.1.2.1.10.166.11.1.2.2.1.4.', '', $rds); @@ -59,8 +58,7 @@ if ($config['enable_vrfs']) { if (empty($port_table[$vrf_oid])) { $port_table[$vrf_oid][0] = $port_id; - } - else { + } else { array_push($port_table[$vrf_oid], $port_id); } } @@ -94,8 +92,7 @@ if ($config['enable_vrfs']) { if (dbFetchCell('SELECT COUNT(*) FROM vrfs WHERE device_id = ? AND `vrf_oid`=?', array($device['device_id'], $vrf_oid))) { dbUpdate(array('mplsVpnVrfDescription' => $descr_table[$vrf_oid], 'mplsVpnVrfRouteDistinguisher' => $vrf_rd), 'vrfs', 'device_id=? AND vrf_oid=?', array($device['device_id'], $vrf_oid)); - } - else { + } else { dbInsert(array('vrf_oid' => $vrf_oid, 'vrf_name' => $vrf_name, 'mplsVpnVrfRouteDistinguisher' => $vrf_rd, 'mplsVpnVrfDescription' => $descr_table[$vrf_oid], 'device_id' => $device['device_id']), 'vrfs'); } @@ -123,8 +120,7 @@ if ($config['enable_vrfs']) { if (!$valid_vrf_if[$vrf_id][$if]) { echo '-'; dbUpdate(array('ifVrf' => 'NULL'), 'ports', 'port_id=?', array($if)); - } - else { + } else { echo '.'; } } @@ -136,8 +132,7 @@ if ($config['enable_vrfs']) { if (!$valid_vrf[$vrf_id]) { echo '-'; dbDelete('vrfs', '`vrf_id` = ?', array($vrf_id)); - } - else { + } else { echo '.'; } } diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index ac7135ab2f..73ad4bf136 100644 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -25,8 +25,7 @@ if ($device['os'] == 'ironware' && $config['autodiscovery']['xdp'] === true) { if ($remote_device_id) { $if = $fdp['snFdpCacheDevicePort']; $remote_port_id = dbFetchCell('SELECT port_id FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ?) AND `device_id` = ?', array($if, $if, $remote_device_id)); - } - else { + } else { $remote_port_id = '0'; } @@ -53,10 +52,9 @@ if ($config['autodiscovery']['xdp'] === true) { $remote_device_id = dbFetchCell('SELECT `device_id` FROM `devices` WHERE `sysName` = ? OR `hostname` = ?', array($cdp['cdpCacheDeviceId'], $cdp['cdpCacheDeviceId'])); if (!$remote_device_id) { - if($config['discovery_by_ip'] !== true) { + if ($config['discovery_by_ip'] !== true) { $remote_device_id = discover_new_device($cdp['cdpCacheDeviceId'], $device, 'CDP', $interface); - } - else { + } else { $ip_arr = explode(" ", $cdp['cdpCacheAddress']); $a = hexdec($ip_arr[0]); @@ -73,16 +71,14 @@ if ($config['autodiscovery']['xdp'] === true) { if ($remote_device_id) { $if = $cdp['cdpCacheDevicePort']; $remote_port_id = dbFetchCell('SELECT port_id FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ?) AND `device_id` = ?', array($if, $if, $remote_device_id)); - } - else { + } else { $remote_port_id = '0'; } if ($interface['port_id'] && $cdp['cdpCacheDeviceId'] && $cdp['cdpCacheDevicePort']) { discover_link($interface['port_id'], 'cdp', $remote_port_id, $cdp['cdpCacheDeviceId'], $cdp['cdpCacheDevicePort'], $cdp['cdpCachePlatform'], $cdp['cdpCacheVersion'], $device['device_id'], $remote_device_id); } - } - else { + } else { echo 'X'; }//end if }//end foreach @@ -94,8 +90,7 @@ if ($config['autodiscovery']['xdp'] === true) { unset($lldp_array); if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { - - echo ' NMS-LLDP-MIB: '; + echo ' NMS-LLDP-MIB: '; $mibdir = $config['mibdir'].'/pbn'.':'.$config['mibdir']; $lldp_array = snmpwalk_cache_oid($device, 'lldpRemoteSystemsData', array(), 'NMS-LLDP-MIB', $mibdir); d_echo($lldp_array); @@ -115,8 +110,7 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { $if = $lldp['lldpRemPortDesc']; $id = $lldp['lldpRemPortId']; $remote_port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ? OR `ifDescr` = ? OR `ifName` = ?) AND `device_id` = ?', array($if, $if, $id, $id, $remote_device_id)); - } - else { + } else { $remote_port_id = '0'; } @@ -125,9 +119,7 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { } }//end foreach }//end if - } elseif ($config['autodiscovery']['xdp'] === true) { - echo ' LLDP-MIB: '; $lldp_array = snmpwalk_cache_threepart_oid($device, 'lldpRemoteSystemsData', array(), 'LLDP-MIB'); d_echo($lldp_array); @@ -141,8 +133,7 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { foreach (array_keys($lldp_if_array) as $entry_key) { if (is_numeric($dot1d_array[$entry_key]['dot1dBasePortIfIndex'])) { $ifIndex = $dot1d_array[$entry_key]['dot1dBasePortIfIndex']; - } - else { + } else { $ifIndex = $entry_key; } @@ -166,7 +157,7 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { $remote_device_id = dbFetchCell('SELECT `device_id` FROM `ports` WHERE ifPhysAddress = ? AND `deleted` = ?', array($remote_port_mac_address, '0')); if ($remote_device_id) { $remote_device_hostname = dbFetchRow('SELECT `hostname` FROM `devices` WHERE `device_id` = ?', array($remote_device_id)); - } + } if ($remote_device_hostname['hostname']) { $lldp['lldpRemSysName'] = $remote_device_hostname['hostname']; } @@ -175,8 +166,7 @@ if ($device['os'] == 'pbn' && $config['autodiscovery']['xdp'] === true) { $if = $lldp['lldpRemPortDesc']; $id = $lldp['lldpRemPortId']; $remote_port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE (`ifDescr` = ? OR `ifName` = ? OR `ifDescr` = ? OR `ifName` = ? OR `ifPhysAddress` = ?) AND `device_id` = ?', array($if, $if, $id, $id, $remote_port_mac_address, $remote_device_id)); - } - else { + } else { $remote_port_id = '0'; } @@ -208,8 +198,7 @@ if ($config['autodiscovery']['ospf'] === true) { $name = gethostbyaddr($ip); $remote_device_id = discover_new_device($name, $device, 'OSPF'); } -} -else { +} else { echo "disabled\n"; } diff --git a/includes/discovery/entity-physical.inc.php b/includes/discovery/entity-physical.inc.php index 0bf25eae20..89a13240c6 100644 --- a/includes/discovery/entity-physical.inc.php +++ b/includes/discovery/entity-physical.inc.php @@ -1,20 +1,17 @@ $device['device_id'], 'entPhysicalIndex' => $entPhysicalIndex, @@ -155,8 +148,7 @@ if ($config['enable_inventory']) { $valid[$entPhysicalIndex] = 1; }//end if }//end foreach -} -else { +} else { echo 'Disabled!'; }//end if diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 1945d74247..f4da615b52 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -14,7 +14,8 @@ use LibreNMS\Exceptions\HostExistsException; -function discover_new_device($hostname, $device = '', $method = '', $interface = '') { +function discover_new_device($hostname, $device = '', $method = '', $interface = '') +{ global $config; if (!empty($config['mydomain']) && isDomainResolves($hostname . '.' . $config['mydomain'])) { @@ -86,7 +87,8 @@ function discover_new_device($hostname, $device = '', $method = '', $interface = //end discover_new_device() -function discover_device($device, $options = null) { +function discover_device($device, $options = null) +{ global $config, $valid; $valid = array(); @@ -141,7 +143,7 @@ function discover_device($device, $options = null) { $module_time = substr($module_time, 0, 5); echo "\n>> Runtime for discovery module '$module': $module_time seconds\n"; echo "#### Unload disco module $module ####\n\n"; - } else if (isset($attribs['discover_' . $module]) && $attribs['discover_' . $module] == '0') { + } elseif (isset($attribs['discover_' . $module]) && $attribs['discover_' . $module] == '0') { echo "Module [ $module ] disabled on host.\n\n"; } else { echo "Module [ $module ] disabled globally.\n\n"; @@ -171,7 +173,8 @@ function discover_device($device, $options = null) { // Discover sensors -function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = '1', $multiplier = '1', $low_limit = null, $low_warn_limit = null, $warn_limit = null, $high_limit = null, $current = null, $poller_type = 'snmp', $entPhysicalIndex = null, $entPhysicalIndex_measured = null) { +function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = '1', $multiplier = '1', $low_limit = null, $low_warn_limit = null, $warn_limit = null, $high_limit = null, $current = null, $poller_type = 'snmp', $entPhysicalIndex = null, $entPhysicalIndex_measured = null) +{ global $config; d_echo("Discover sensor: $oid, $index, $type, $descr, $poller_type, $precision, $entPhysicalIndex\n"); @@ -180,7 +183,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, // Warn limits only make sense when we have both a high and a low limit $low_warn_limit = null; $warn_limit = null; - } else if ($low_warn_limit > $warn_limit) { + } elseif ($low_warn_limit > $warn_limit) { // Fix high/low thresholds (i.e. on negative numbers) list($warn_limit, $low_warn_limit) = array($low_warn_limit, $warn_limit); } @@ -316,7 +319,8 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, //end discover_sensor() -function sensor_low_limit($class, $current) { +function sensor_low_limit($class, $current) +{ $limit = null; switch ($class) { @@ -362,7 +366,8 @@ function sensor_low_limit($class, $current) { //end sensor_low_limit() -function sensor_limit($class, $current) { +function sensor_limit($class, $current) +{ $limit = null; switch ($class) { @@ -398,7 +403,7 @@ function sensor_limit($class, $current) { $limit = ($current * 1.50); break; - case 'signal'; + case 'signal': $limit = -30; break; }//end switch @@ -408,7 +413,8 @@ function sensor_limit($class, $current) { //end sensor_limit() -function check_valid_sensors($device, $class, $valid, $poller_type = 'snmp') { +function check_valid_sensors($device, $class, $valid, $poller_type = 'snmp') +{ $entries = dbFetchRows('SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class=? AND S.device_id = D.device_id AND D.device_id = ? AND S.poller_type = ?', array($class, $device['device_id'], $poller_type)); if (count($entries)) { @@ -435,7 +441,8 @@ function check_valid_sensors($device, $class, $valid, $poller_type = 'snmp') { //end check_valid_sensors() -function discover_juniAtmVp(&$valid, $port_id, $vp_id, $vp_descr) { +function discover_juniAtmVp(&$valid, $port_id, $vp_id, $vp_descr) +{ global $config; if (dbFetchCell('SELECT COUNT(*) FROM `juniAtmVp` WHERE `port_id` = ? AND `vp_id` = ?', array($port_id, $vp_id)) == '0') { @@ -453,19 +460,21 @@ function discover_juniAtmVp(&$valid, $port_id, $vp_id, $vp_descr) { //end discover_juniAtmVp() -function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostname, $remote_port, $remote_platform, $remote_version, $local_device_id, $remote_device_id) { +function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostname, $remote_port, $remote_platform, $remote_version, $local_device_id, $remote_device_id) +{ global $config, $link_exists; d_echo("$local_port_id, $protocol, $remote_port_id, $remote_hostname, $remote_port, $remote_platform, $remote_version"); if (dbFetchCell( - 'SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?', array( + 'SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?', + array( $remote_hostname, $local_port_id, $protocol, $remote_port, ) - ) == '0') { + ) == '0') { $insert_data = array( 'local_port_id' => $local_port_id, 'local_device_id' => $local_device_id, @@ -512,7 +521,8 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn //end discover_link() -function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size, $units, $used = null) { +function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size, $units, $used = null) +{ global $config; d_echo("$device, $index, $type, $mib, $descr, $units, $used, $size\n"); @@ -521,7 +531,7 @@ function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size, $storage = dbFetchRow('SELECT * FROM `storage` WHERE `storage_index` = ? AND `device_id` = ? AND `storage_mib` = ?', array($index, $device['device_id'], $mib)); if ($storage === false || !count($storage)) { $insert = dbInsert( - array( + array( 'device_id' => $device['device_id'], 'storage_descr' => $descr, 'storage_index' => $index, @@ -530,7 +540,8 @@ function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size, 'storage_units' => $units, 'storage_size' => $size, 'storage_used' => $used, - ), 'storage' + ), + 'storage' ); echo '+'; @@ -549,7 +560,8 @@ function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size, //end discover_storage() -function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $precision = '1', $current = null, $entPhysicalIndex = null, $hrDeviceIndex = null) { +function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $precision = '1', $current = null, $entPhysicalIndex = null, $hrDeviceIndex = null) +{ global $config; d_echo("$device, $oid, $index, $type, $descr, $precision, $current, $entPhysicalIndex, $hrDeviceIndex\n"); @@ -593,7 +605,8 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec //end discover_processor() -function discover_mempool(&$valid, $device, $index, $type, $descr, $precision = '1', $entPhysicalIndex = null, $hrDeviceIndex = null) { +function discover_mempool(&$valid, $device, $index, $type, $descr, $precision = '1', $entPhysicalIndex = null, $hrDeviceIndex = null) +{ global $config; d_echo("$device, $oid, $index, $type, $descr, $precision, $current, $entPhysicalIndex, $hrDeviceIndex\n"); @@ -646,7 +659,8 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision = //end discover_mempool() -function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity_oid = null, $capacity = null, $current = null) { +function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity_oid = null, $capacity = null, $current = null) +{ global $config; d_echo("$oid, $index, $type, $descr, $capacity, $capacity_oid\n"); @@ -670,7 +684,8 @@ function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity //end discover_toner() -function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $context_name = '') { +function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $context_name = '') +{ global $device, $config; $ipv6_network = Net_IPv6::getNetmask("$ipv6_address/$ipv6_prefixlen") . '/' . $ipv6_prefixlen; @@ -709,7 +724,6 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen $valid_address = $full_address . '-' . $port_id; $valid['ipv6'][$valid_address] = 1; }//end if - }//end discover_process_ipv6() /* @@ -721,14 +735,15 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen * @return bool true if sensor is valid * false if sensor is invalid */ -function check_entity_sensor($string, $device) { +function check_entity_sensor($string, $device) +{ global $config; $valid = true; $string = strtolower($string); if (is_array($config['bad_entity_sensor_regex'])) { $fringe = $config['bad_entity_sensor_regex']; if (is_array($config['os'][$device['os']]['bad_entity_sensor_regex'])) { - $fringe = array_merge($config['bad_entity_sensor_regex'],$config['os'][$device['os']]['bad_entity_sensor_regex']); + $fringe = array_merge($config['bad_entity_sensor_regex'], $config['os'][$device['os']]['bad_entity_sensor_regex']); } foreach ($fringe as $bad) { if (preg_match($bad . "i", $string)) { @@ -748,14 +763,14 @@ function check_entity_sensor($string, $device) { * @param (device) array - device array * @param (sensor) array(id, oid, type, descr, descr_oid, min, max, divisor) */ -function avtech_add_sensor($device, $sensor) { +function avtech_add_sensor($device, $sensor) +{ global $valid; // set the id, must be unique if (isset($sensor['id'])) { $id = $sensor['id']; - } - else { + } else { d_echo('Error: No id set for this sensor' . "\n"); return false; } @@ -765,8 +780,7 @@ function avtech_add_sensor($device, $sensor) { // set the sensor oid if ($sensor['oid']) { $oid = $sensor['oid']; - } - else { + } else { d_echo('Error: No oid set for this sensor' . "\n"); return false; } @@ -799,7 +813,7 @@ function avtech_add_sensor($device, $sensor) { array($state_index_id,'Off',1,0,-1), array($state_index_id,'On',1,1,0), ); - foreach($states as $value){ + foreach ($states as $value) { $insert = array( 'state_index_id' => $value[0], 'state_descr' => $value[1], @@ -815,11 +829,9 @@ function avtech_add_sensor($device, $sensor) { // set the description if ($sensor['descr_oid']) { $descr = trim(snmp_get($device, $sensor['descr_oid'], '-OvQ'), '"'); - } - elseif ($sensor['descr']) { + } elseif ($sensor['descr']) { $descr = $sensor['descr']; - } - else { + } else { d_echo('Error: No description set for this sensor' . "\n"); return false; } @@ -828,11 +840,9 @@ function avtech_add_sensor($device, $sensor) { // set divisor if ($sensor['divisor']) { $divisor = $sensor['divisor']; - } - elseif ($type == 'temperature') { + } elseif ($type == 'temperature') { $divisor = 100; - } - else { + } else { $divisor = 1; } d_echo('Sensor divisor: ' . $divisor . "\n"); @@ -841,8 +851,7 @@ function avtech_add_sensor($device, $sensor) { // set min for alarm if ($sensor['min_oid']) { $min = snmp_get($device, $sensor['min_oid'], '-OvQ') / $divisor; - } - else { + } else { $min = null; } d_echo('Sensor alarm min: ' . $min . "\n"); @@ -850,8 +859,7 @@ function avtech_add_sensor($device, $sensor) { // set max for alarm if ($sensor['max_oid']) { $max = snmp_get($device, $sensor['max_oid'], '-OvQ') / $divisor; - } - else { + } else { $max = null; } d_echo('Sensor alarm max: ' . $max . "\n"); @@ -865,4 +873,3 @@ function avtech_add_sensor($device, $sensor) { return true; } - diff --git a/includes/discovery/hr-device.inc.php b/includes/discovery/hr-device.inc.php index 868989dc55..f784051159 100644 --- a/includes/discovery/hr-device.inc.php +++ b/includes/discovery/hr-device.inc.php @@ -30,8 +30,7 @@ if (is_array($hrDevices)) { dbUpdate($update_array, 'hrDevice', 'device_id=? AND hrDeviceIndex=?', array($device['device_id'], $hrDevice['hrDeviceIndex'])); echo '.'; - } - else { + } else { $inserted_rows = dbInsert(array('hrDeviceIndex' => mres($hrDevice['hrDeviceIndex']), 'device_id' => mres($device['device_id']), 'hrDeviceType' => mres($hrDevice['hrDeviceType']), 'hrDeviceDescr' => mres($hrDevice['hrDeviceDescr']), 'hrDeviceStatus' => mres($hrDevice['hrDeviceStatus']), 'hrDeviceErrors' => (int) mres($hrDevice['hrDeviceErrors'])), 'hrDevice'); echo '+'; d_echo($hrDevice); diff --git a/includes/discovery/ipv4-addresses.inc.php b/includes/discovery/ipv4-addresses.inc.php index a96530338e..b0a31445e8 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -1,9 +1,8 @@ null)); } foreach ($vrfs_lite_cisco as $vrf) { @@ -26,10 +25,9 @@ foreach ($vrfs_lite_cisco as $vrf) { dbInsert(array('ipv4_network' => $network,'context_name' => $device['context_name']), 'ipv4_networks'); // echo("Create Subnet $network\n"); echo 'S'; - } - else { + } else { //Update Context - dbUpdate(array('context_name' => $device['context_name']), 'ipv4_networks', '`ipv4_network` = ?', array($network) ); + dbUpdate(array('context_name' => $device['context_name']), 'ipv4_networks', '`ipv4_network` = ?', array($network)); echo 's'; } @@ -39,17 +37,15 @@ foreach ($vrfs_lite_cisco as $vrf) { dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id, 'context_name' => $device['context_name']), 'ipv4_addresses'); // echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n"); echo '+'; - } - else { + } else { //Update Context - dbUpdate(array('context_name' => $device['context_name']), 'ipv4_addresses', 'ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?',array($oid, $cidr, $port_id) ); + dbUpdate(array('context_name' => $device['context_name']), 'ipv4_addresses', 'ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?', array($oid, $cidr, $port_id)); echo '.'; } $full_address = "$oid/$cidr|$ifIndex"; $valid_v4[$full_address] = 1; - } - else { + } else { echo '!'; }//end if }//end foreach diff --git a/includes/discovery/ipv6-addresses.inc.php b/includes/discovery/ipv6-addresses.inc.php index b57900b355..09b58253da 100644 --- a/includes/discovery/ipv6-addresses.inc.php +++ b/includes/discovery/ipv6-addresses.inc.php @@ -1,9 +1,8 @@ null)); } foreach ($vrfs_lite_cisco as $vrf) { @@ -33,8 +32,7 @@ foreach ($vrfs_lite_cisco as $vrf) { if ($do == 2) { $adsep = ':'; $do = '0'; - } - else { + } else { $adsep = ''; } } diff --git a/includes/discovery/libvirt-vminfo.inc.php b/includes/discovery/libvirt-vminfo.inc.php index ec6c08a0ee..40c5263c3a 100644 --- a/includes/discovery/libvirt-vminfo.inc.php +++ b/includes/discovery/libvirt-vminfo.inc.php @@ -15,8 +15,7 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == 'linux') { foreach ($config['libvirt_protocols'] as $method) { if (strstr($method, 'qemu')) { $uri = $method.'://'.$userHostname.'/system'; - } - else { + } else { $uri = $method.'://'.$userHostname; } @@ -78,8 +77,7 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == 'linux') { $inserted_id = dbInsert(array('device_id' => $device['device_id'], 'vm_type' => 'libvirt', 'vmwVmVMID' => $dom_id, 'vmwVmDisplayName' => mres($vmwVmDisplayName), 'vmwVmGuestOS' => mres($vmwVmGuestOS), 'vmwVmMemSize' => mres($vmwVmMemSize), 'vmwVmCpus' => mres($vmwVmCpus), 'vmwVmState' => mres($vmwVmState)), 'vminfo'); echo '+'; log_event("Virtual Machine added: $vmwVmDisplayName ($vmwVmMemSize MB)", $device, 'vm', $inserted_id); - } - else { + } else { if ($result['vmwVmState'] != $vmwVmState || $result['vmwVmDisplayName'] != $vmwVmDisplayName || $result['vmwVmCpus'] != $vmwVmCpus @@ -89,8 +87,7 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == 'linux') { dbUpdate(array('vmwVmState' => mres($vmwVmState), 'vmwVmGuestOS' => mres($vmwVmGuestOS), 'vmwVmDisplayName' => mres($vmwVmDisplayName), 'vmwVmMemSize' => mres($vmwVmMemSize), 'vmwVmCpus' => mres($vmwVmCpus)), 'vminfo', "device_id=? AND vm_type='libvirt' AND vmwVmVMID=?", array($device['device_id'], $dom_id)); echo 'U'; // FIXME eventlog - } - else { + } else { echo '.'; } } diff --git a/includes/discovery/mempools/adtran-aos.inc.php b/includes/discovery/mempools/adtran-aos.inc.php index 0775daf18c..004bd3ec3b 100644 --- a/includes/discovery/mempools/adtran-aos.inc.php +++ b/includes/discovery/mempools/adtran-aos.inc.php @@ -31,4 +31,3 @@ if ($device['os'] == 'adtran-aos') { discover_mempool($valid_mempool, $device, 0, 'adtran-aos', 'Memory', '1', null, null); } } - diff --git a/includes/discovery/mempools/binos.inc.php b/includes/discovery/mempools/binos.inc.php index b53a9836fc..2f87eb951f 100644 --- a/includes/discovery/mempools/binos.inc.php +++ b/includes/discovery/mempools/binos.inc.php @@ -23,6 +23,6 @@ if ($device['os'] == "binos") { $percent = (($used / $total) * 100); if (is_numeric($used)) { - discover_mempool($valid_mempool, $device, 0, "binos", "Memory", "1", NULL, NULL); + discover_mempool($valid_mempool, $device, 0, "binos", "Memory", "1", null, null); } } diff --git a/includes/discovery/mempools/binox.inc.php b/includes/discovery/mempools/binox.inc.php index 76f66870ff..984462a99f 100644 --- a/includes/discovery/mempools/binox.inc.php +++ b/includes/discovery/mempools/binox.inc.php @@ -25,6 +25,6 @@ if ($device['os'] == "binox") { $percent = $used; if (is_numeric($used)) { - discover_mempool($valid_mempool, $device, 0, "binox", "Memory", "1", NULL, NULL); + discover_mempool($valid_mempool, $device, 0, "binox", "Memory", "1", null, null); } } diff --git a/includes/discovery/mempools/ciscowlc.inc.php b/includes/discovery/mempools/ciscowlc.inc.php index b966bdfff2..b962b3ebc7 100644 --- a/includes/discovery/mempools/ciscowlc.inc.php +++ b/includes/discovery/mempools/ciscowlc.inc.php @@ -7,6 +7,6 @@ if ($device['os'] == 'ciscowlc') { $avail = str_replace('"', "", snmp_get($device, "1.3.6.1.4.1.14179.1.1.5.2.0", '-OvQ')); if ((is_numeric($total)) && (is_numeric($avail))) { - discover_mempool($valid_mempool, $device, 0, 'ciscowlc', 'Memory', '1', null, null); + discover_mempool($valid_mempool, $device, 0, 'ciscowlc', 'Memory', '1', null, null); } } diff --git a/includes/discovery/mempools/hrstorage.inc.php b/includes/discovery/mempools/hrstorage.inc.php index 5a853245a6..0b2270a309 100644 --- a/includes/discovery/mempools/hrstorage.inc.php +++ b/includes/discovery/mempools/hrstorage.inc.php @@ -14,21 +14,19 @@ if (is_array($storage_array)) { switch ($fstype) { case 'hrStorageVirtualMemory': - case 'hrStorageRam'; - case 'nwhrStorageDOSMemory'; - case 'nwhrStorageMemoryAlloc'; - case 'nwhrStorageMemoryPermanent'; - case 'nwhrStorageMemoryAlloc'; - case 'nwhrStorageCacheBuffers'; - case 'nwhrStorageCacheMovable'; - case 'nwhrStorageCacheNonMovable'; - case 'nwhrStorageCodeAndDataMemory'; - case 'nwhrStorageDOSMemory'; - case 'nwhrStorageIOEngineMemory'; - case 'nwhrStorageMSEngineMemory'; - case 'nwhrStorageUnclaimedMemory'; + case 'hrStorageRam': + case 'nwhrStorageDOSMemory': + case 'nwhrStorageMemoryAlloc': + case 'nwhrStorageMemoryPermanent': + case 'nwhrStorageCacheBuffers': + case 'nwhrStorageCacheMovable': + case 'nwhrStorageCacheNonMovable': + case 'nwhrStorageCodeAndDataMemory': + case 'nwhrStorageIOEngineMemory': + case 'nwhrStorageMSEngineMemory': + case 'nwhrStorageUnclaimedMemory': $deny = 0; - break; + break; } if ($device['os'] == 'vmware' && $descr == 'Real Memory') { diff --git a/includes/discovery/mempools/ironware-dyn.inc.php b/includes/discovery/mempools/ironware-dyn.inc.php index 8f8966ef04..22c6a01e1b 100644 --- a/includes/discovery/mempools/ironware-dyn.inc.php +++ b/includes/discovery/mempools/ironware-dyn.inc.php @@ -1,11 +1,9 @@ $entry) { + if (is_array($ni_mempools_array)) { + foreach ($ni_mempools_array as $index => $entry) { + d_echo($index.' '.$entry['snAgentBrdMainBrdDescription'].' -> '.$entry['snAgentBrdMemoryUtil100thPercent']."\n"); - d_echo($index.' '.$entry['snAgentBrdMainBrdDescription'].' -> '.$entry['snAgentBrdMemoryUtil100thPercent']."\n"); - - $usage_oid = '.1.3.6.1.4.1.1991.1.1.2.2.1.1.28.'.$index; - $descr = $entry['snAgentBrdMainBrdDescription']; - $usage = ($entry['snAgentBrdMemoryUtil100thPercent'] / 100); - if (!strstr($descr, 'No') && !strstr($usage, 'No') && $descr != '') { - discover_mempool($valid_mempool, $device, $index, 'ironware-dyn', $descr, '1', null, null); - } //end_if - } //end_foreach + $usage_oid = '.1.3.6.1.4.1.1991.1.1.2.2.1.1.28.'.$index; + $descr = $entry['snAgentBrdMainBrdDescription']; + $usage = ($entry['snAgentBrdMemoryUtil100thPercent'] / 100); + if (!strstr($descr, 'No') && !strstr($usage, 'No') && $descr != '') { + discover_mempool($valid_mempool, $device, $index, 'ironware-dyn', $descr, '1', null, null); + } //end_if + } //end_foreach } //end_if - } //end_else + } //end_else } //end_if - - - diff --git a/includes/discovery/mempools/nos.inc.php b/includes/discovery/mempools/nos.inc.php index a801e52af4..2d06705591 100644 --- a/includes/discovery/mempools/nos.inc.php +++ b/includes/discovery/mempools/nos.inc.php @@ -3,13 +3,13 @@ if ($device['os'] == "nos") { echo("nos: "); - $used = snmp_get($device, "1.3.6.1.4.1.1588.2.1.1.1.26.6.0", "-Ovq"); - $total = "100"; - $free = ($total - $used); + $used = snmp_get($device, "1.3.6.1.4.1.1588.2.1.1.1.26.6.0", "-Ovq"); + $total = "100"; + $free = ($total - $used); - $percent = $used; + $percent = $used; if (is_numeric($used)) { - discover_mempool($valid_mempool, $device, 0, "nos", "Memory", "1", NULL, NULL); + discover_mempool($valid_mempool, $device, 0, "nos", "Memory", "1", null, null); } } diff --git a/includes/discovery/mempools/pbn.inc.php b/includes/discovery/mempools/pbn.inc.php index 1737cc7957..f9241f9be0 100644 --- a/includes/discovery/mempools/pbn.inc.php +++ b/includes/discovery/mempools/pbn.inc.php @@ -1,6 +1,5 @@ = 16607) { - $mibdir = $config['mibdir'].'/pbn'.':'.$config['mibdir']; $usage = snmp_get($device, 'nmsMemoryPoolUtilization.0', '-OUvQ', 'NMS-MEMORY-POOL-MIB', $mibdir); diff --git a/includes/discovery/mempools/zywall.inc.php b/includes/discovery/mempools/zywall.inc.php index 94a506fd83..5a8b34682c 100644 --- a/includes/discovery/mempools/zywall.inc.php +++ b/includes/discovery/mempools/zywall.inc.php @@ -15,7 +15,7 @@ if ($device['os'] == 'zywall') { echo 'Zywall mempool: '; $oid = '.1.3.6.1.4.1.890.1.6.22.1.2.0'; - $usage = snmp_get($device,$oid, '-Ovq'); + $usage = snmp_get($device, $oid, '-Ovq'); if (is_numeric($usage)) { discover_mempool($valid_mempool, $device, $oid, 'zywall', 'Memory', '1', null, null); } diff --git a/includes/discovery/ntp/cisco.inc.php b/includes/discovery/ntp/cisco.inc.php index 5d2379f1df..ede7ec8c59 100644 --- a/includes/discovery/ntp/cisco.inc.php +++ b/includes/discovery/ntp/cisco.inc.php @@ -14,7 +14,7 @@ $module = 'ntp'; $component = new LibreNMS\Component(); -$components = $component->getComponents($device['device_id'],array('type'=>$module)); +$components = $component->getComponents($device['device_id'], array('type'=>$module)); // We only care about our device id. $components = $components[$device['device_id']]; @@ -32,7 +32,7 @@ $cntpPeersVarEntry = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.168.1.2.1.1', * False == no object found - this is not an error, no objects exist * null == timeout or something else that caused an error, there may be objects but we couldn't get it. */ -if ( is_null($cntpPeersVarEntry) ) { +if (is_null($cntpPeersVarEntry)) { // We have to error here or we will end up deleting all our components. echo "Error\n"; } else { @@ -81,7 +81,7 @@ if ( is_null($cntpPeersVarEntry) ) { if (!$component_key) { // The component doesn't exist, we need to ADD it - ADD. - $new_component = $component->createComponent($device['device_id'],$module); + $new_component = $component->createComponent($device['device_id'], $module); $component_key = key($new_component); $components[$component_key] = array_merge($new_component[$component_key], $array); echo "+"; @@ -90,7 +90,6 @@ if ( is_null($cntpPeersVarEntry) ) { $components[$component_key] = array_merge($components[$component_key], $array); echo "."; } - } /* @@ -115,9 +114,8 @@ if ( is_null($cntpPeersVarEntry) ) { } // Write the Components back to the DB. - $component->setComponentPrefs($device['device_id'],$components); + $component->setComponentPrefs($device['device_id'], $components); echo "\n"; - } // End if not error $module = strtolower($module); diff --git a/includes/discovery/os/3com.inc.php b/includes/discovery/os/3com.inc.php index f024f98986..de81425115 100644 --- a/includes/discovery/os/3com.inc.php +++ b/includes/discovery/os/3com.inc.php @@ -3,11 +3,9 @@ if (!$os) { if (strstr($sysDescr, '3Com Switch ')) { $os = '3com'; - } - else if (strstr($sysDescr, '3Com SuperStack')) { + } elseif (strstr($sysDescr, '3Com SuperStack')) { $os = '3com'; - } - else if (strstr($sysDescr, '3Com Baseline')) { + } elseif (strstr($sysDescr, '3Com Baseline')) { $os = '3com'; } } diff --git a/includes/discovery/os/acano.inc.php b/includes/discovery/os/acano.inc.php index 9b7986cce4..3de6aa07fe 100644 --- a/includes/discovery/os/acano.inc.php +++ b/includes/discovery/os/acano.inc.php @@ -1,7 +1,7 @@ = 40 && $model_oid < 60 || $model_oid = 67) { $os = 'hpmsm'; diff --git a/includes/discovery/os/hytera.inc.php b/includes/discovery/os/hytera.inc.php index 5c6cb423fd..db54d5b0b4 100644 --- a/includes/discovery/os/hytera.inc.php +++ b/includes/discovery/os/hytera.inc.php @@ -5,4 +5,3 @@ if (!$os) { $os = "hytera"; } } - diff --git a/includes/discovery/os/ios.inc.php b/includes/discovery/os/ios.inc.php index 04d399d481..caedad1d9f 100644 --- a/includes/discovery/os/ios.inc.php +++ b/includes/discovery/os/ios.inc.php @@ -3,14 +3,11 @@ if (empty($os)) { if (strstr($sysDescr, 'Cisco Internetwork Operating System Software')) { $os = 'ios'; - } - else if (strstr($sysDescr, 'IOS (tm)')) { + } elseif (strstr($sysDescr, 'IOS (tm)')) { $os = 'ios'; - } - else if (strstr($sysDescr, 'Cisco IOS Software')) { + } elseif (strstr($sysDescr, 'Cisco IOS Software')) { $os = 'ios'; - } - else if (strstr($sysDescr, 'Global Site Selector')) { + } elseif (strstr($sysDescr, 'Global Site Selector')) { $os = 'ios'; } diff --git a/includes/discovery/os/ise.inc.php b/includes/discovery/os/ise.inc.php index 6f97e7509a..ea22af8d2d 100644 --- a/includes/discovery/os/ise.inc.php +++ b/includes/discovery/os/ise.inc.php @@ -1,7 +1,7 @@ "IOMEGANAS-MIB", - "tempValue" => "IOMEGANAS-MIB", - "raidStatus" => "IOMEGANAS-MIB", - "diskStatus" => "IOMEGANAS-MIB" + "fanValue" => "IOMEGANAS-MIB", + "tempValue" => "IOMEGANAS-MIB", + "raidStatus" => "IOMEGANAS-MIB", + "diskStatus" => "IOMEGANAS-MIB" ); register_mibs($device, $lenovoemc_mibs, "includes/discovery/os/lenovoemc.inc.php"); } diff --git a/includes/discovery/os/linux.inc.php b/includes/discovery/os/linux.inc.php index f505b43935..9c7a4ab8fb 100644 --- a/includes/discovery/os/linux.inc.php +++ b/includes/discovery/os/linux.inc.php @@ -18,41 +18,30 @@ if (!$os) { if (strstr($sysObjectId, '.1.3.6.1.4.1.5528.100.20.10.2014') || strstr($sysObjectId, '.1.3.6.1.4.1.5528.100.20.10.2016')) { $os = 'netbotz'; - } - elseif (strstr($sysDescr, 'endian')) { + } elseif (strstr($sysDescr, 'endian')) { $os = 'endian'; - } - elseif (preg_match('/Cisco Small Business/', $sysDescr)) { + } elseif (preg_match('/Cisco Small Business/', $sysDescr)) { $os = 'ciscosmblinux'; - } - elseif (strpos($entPhysicalMfgName, 'QNAP') !== false) { + } elseif (strpos($entPhysicalMfgName, 'QNAP') !== false) { $os = 'qnap'; - } - elseif (stristr($sysObjectId, 'packetlogic') || strstr($sysObjectId, '.1.3.6.1.4.1.15397.2')) { + } elseif (stristr($sysObjectId, 'packetlogic') || strstr($sysObjectId, '.1.3.6.1.4.1.15397.2')) { $os = 'procera'; - } - elseif (strstr($sysObjectId, '.1.3.6.1.4.1.10002.1') || strstr($sysObjectId, '.1.3.6.1.4.1.41112.1.4') || strpos(trim(snmp_get($device, 'dot11manufacturerName.5', '-Osqnv', 'IEEE802dot11-MIB')), 'Ubiquiti') !== false) { + } elseif (strstr($sysObjectId, '.1.3.6.1.4.1.10002.1') || strstr($sysObjectId, '.1.3.6.1.4.1.41112.1.4') || strpos(trim(snmp_get($device, 'dot11manufacturerName.5', '-Osqnv', 'IEEE802dot11-MIB')), 'Ubiquiti') !== false) { $os = 'airos'; if (strpos(trim(snmp_get($device, 'dot11manufacturerProductName.5', '-Osqnv', 'IEEE802dot11-MIB')), 'UAP') !== false) { $os = 'unifi'; - } - elseif (strpos(trim(snmp_get($device, 'dot11manufacturerProductName.2', '-Osqnv', 'IEEE802dot11-MIB')), 'UAP') !== false) { + } elseif (strpos(trim(snmp_get($device, 'dot11manufacturerProductName.2', '-Osqnv', 'IEEE802dot11-MIB')), 'UAP') !== false) { $os = 'unifi'; - } - elseif (strpos(trim(snmp_get($device, 'dot11manufacturerProductName.3', '-Osqnv', 'IEEE802dot11-MIB')), 'UAP') !== false) { + } elseif (strpos(trim(snmp_get($device, 'dot11manufacturerProductName.3', '-Osqnv', 'IEEE802dot11-MIB')), 'UAP') !== false) { $os = 'unifi'; - } - elseif (strpos(trim(snmp_get($device, 'dot11manufacturerProductName.4', '-Osqnv', 'IEEE802dot11-MIB')), 'UAP') !== false) { + } elseif (strpos(trim(snmp_get($device, 'dot11manufacturerProductName.4', '-Osqnv', 'IEEE802dot11-MIB')), 'UAP') !== false) { $os = 'unifi'; - } - elseif (strpos(trim(snmp_get($device, 'dot11manufacturerProductName.6', '-Osqnv', 'IEEE802dot11-MIB')), 'UAP') !== false) { + } elseif (strpos(trim(snmp_get($device, 'dot11manufacturerProductName.6', '-Osqnv', 'IEEE802dot11-MIB')), 'UAP') !== false) { $os = 'unifi'; - } - elseif (trim(snmp_get($device, 'fwVersion.1', '-Osqnv', 'UBNT-AirFIBER-MIB')) != '') { + } elseif (trim(snmp_get($device, 'fwVersion.1', '-Osqnv', 'UBNT-AirFIBER-MIB')) != '') { $os = 'airos-af'; } - } - elseif (snmp_get($device, 'GANDI-MIB::rxCounter.0', '-Osqnv', 'GANDI-MIB') !== false) { + } elseif (snmp_get($device, 'GANDI-MIB::rxCounter.0', '-Osqnv', 'GANDI-MIB') !== false) { $os = 'pktj'; $pktj_mibs = array ( "rxCounter" => "GANDI-MIB", // RX Packets @@ -65,21 +54,17 @@ if (!$os) { "KNIdropCounter" => "GANDI-MIB", // KNI DROP counter ); register_mibs($device, $pktj_mibs, "include/discovery/os/linux.inc.php"); - } - elseif (stristr($sysObjectId, 'cumulusMib') || strstr($sysObjectId, '.1.3.6.1.4.1.40310')) { + } elseif (stristr($sysObjectId, 'cumulusMib') || strstr($sysObjectId, '.1.3.6.1.4.1.40310')) { $os = 'cumulus'; - } - elseif (strstr($sysDescr, 'g56fa85e') || strstr($sysDescr, 'gc80f187') || strstr($sysDescr, 'g829be90') || strstr($sysDescr, 'g63c0044')) { + } elseif (strstr($sysDescr, 'g56fa85e') || strstr($sysDescr, 'gc80f187') || strstr($sysDescr, 'g829be90') || strstr($sysDescr, 'g63c0044')) { $os = 'sophos'; - } - else { + } else { // Check for Synology DSM $hrSystemInitialLoadParameters = trim(snmp_get($device, 'HOST-RESOURCES-MIB::hrSystemInitialLoadParameters.0', '-Osqnv')); if (strpos($hrSystemInitialLoadParameters, 'syno_hw_version') !== false) { $os = 'dsm'; - } - else { + } else { // Check for Carel PCOweb $roomTemp = trim(snmp_get($device, 'roomTemp.0', '-OqvU', 'CAREL-ug40cdz-MIB')); diff --git a/includes/discovery/os/netgear.inc.php b/includes/discovery/os/netgear.inc.php index 21068df051..35e1d614c5 100644 --- a/includes/discovery/os/netgear.inc.php +++ b/includes/discovery/os/netgear.inc.php @@ -3,8 +3,7 @@ if (!$os) { if (stristr($sysDescr, 'ProSafe')) { $os = 'netgear'; - } - elseif (strpos($sysObjectId, '1.3.6.1.4.1.4526') !== FALSE) { + } elseif (strpos($sysObjectId, '1.3.6.1.4.1.4526') !== false) { $os = 'netgear'; } } diff --git a/includes/discovery/os/nos.inc.php b/includes/discovery/os/nos.inc.php index 43751e6e5b..99aa1c8b02 100644 --- a/includes/discovery/os/nos.inc.php +++ b/includes/discovery/os/nos.inc.php @@ -2,6 +2,6 @@ if (!$os) { if (strstr($sysDescr, "Brocade VDX")||strstr($sysDescr, "BR-VDX")||strstr($sysDescr, "VDX67")) { - $os = "nos"; + $os = "nos"; } } diff --git a/includes/discovery/os/papouch-tme.inc.php b/includes/discovery/os/papouch-tme.inc.php index 8195dbdcb6..ab3091f881 100644 --- a/includes/discovery/os/papouch-tme.inc.php +++ b/includes/discovery/os/papouch-tme.inc.php @@ -3,8 +3,7 @@ if (!$os) { if ($sysDescr == 'SNMP TME') { $os = 'papouch-tme'; - } - else if ($sysDescr == 'TME') { + } elseif ($sysDescr == 'TME') { $os = 'papouch-tme'; } } diff --git a/includes/discovery/os/perle.inc.php b/includes/discovery/os/perle.inc.php index 768afe08d7..2ff1da924e 100644 --- a/includes/discovery/os/perle.inc.php +++ b/includes/discovery/os/perle.inc.php @@ -13,4 +13,4 @@ if (!$os) { if (stristr($sysDescr, 'Perle MCR-MGT')) { $os = 'perle'; } -} \ No newline at end of file +} diff --git a/includes/discovery/os/procurve.inc.php b/includes/discovery/os/procurve.inc.php index f426670f29..06f1eea9bb 100644 --- a/includes/discovery/os/procurve.inc.php +++ b/includes/discovery/os/procurve.inc.php @@ -3,8 +3,7 @@ if (!$os) { if (stristr($sysDescr, 'ProCurve')) { $os = 'procurve'; - } - else if (preg_match('/eCos-[0-9.]+/', $sysDescr)) { + } elseif (preg_match('/eCos-[0-9.]+/', $sysDescr)) { $os = 'procurve'; } elseif (preg_match('/HP(.+)2530(.+)/', $sysDescr)) { //hp aruba 2530 series diff --git a/includes/discovery/os/samsungprinter.inc.php b/includes/discovery/os/samsungprinter.inc.php index 553f96019f..723b693cb5 100644 --- a/includes/discovery/os/samsungprinter.inc.php +++ b/includes/discovery/os/samsungprinter.inc.php @@ -1,6 +1,6 @@ "FOUNDRY-SN-SW-L4-SWITCH-GROUP-MIB", // Unsuccessfull connection ); - register_mibs($device, $serviron_mibs, "includes/discovery/os/serveriron.inc.php"); - + register_mibs($device, $serviron_mibs, "includes/discovery/os/serveriron.inc.php"); } } diff --git a/includes/discovery/os/sonus-gsx.inc.php b/includes/discovery/os/sonus-gsx.inc.php index e0fce2e46e..1379db3713 100644 --- a/includes/discovery/os/sonus-gsx.inc.php +++ b/includes/discovery/os/sonus-gsx.inc.php @@ -14,4 +14,4 @@ if (!$os) { if (strstr($sysObjectId, '.1.3.6.1.4.1.2879.1.1.2')) { $os = 'sonus-gsx'; } -} \ No newline at end of file +} diff --git a/includes/discovery/os/sonus-sbc.inc.php b/includes/discovery/os/sonus-sbc.inc.php index 45087a3cbf..cddd44588d 100644 --- a/includes/discovery/os/sonus-sbc.inc.php +++ b/includes/discovery/os/sonus-sbc.inc.php @@ -14,4 +14,4 @@ if (!$os) { if (strstr($sysObjectId, '.1.3.6.1.4.1.2879.1.9.2')) { $os = 'sonus-sbc'; } -} \ No newline at end of file +} diff --git a/includes/discovery/os/speedtouch.inc.php b/includes/discovery/os/speedtouch.inc.php index af9ba41a7c..e51e02e261 100644 --- a/includes/discovery/os/speedtouch.inc.php +++ b/includes/discovery/os/speedtouch.inc.php @@ -3,11 +3,9 @@ if (!$os) { if (strstr($sysDescr, 'TG585v7')) { $os = 'speedtouch'; - } - else if (strstr($sysDescr, 'SpeedTouch ')) { + } elseif (strstr($sysDescr, 'SpeedTouch ')) { $os = 'speedtouch'; - } - else if (preg_match('/^ST\d/', $sysDescr)) { + } elseif (preg_match('/^ST\d/', $sysDescr)) { $os = 'speedtouch'; } } diff --git a/includes/discovery/os/tplink.inc.php b/includes/discovery/os/tplink.inc.php index 58db944cbc..ed8318dce2 100644 --- a/includes/discovery/os/tplink.inc.php +++ b/includes/discovery/os/tplink.inc.php @@ -1,6 +1,6 @@ $entry_high) { if (isset($stack_db_array[$port_id_high][$port_id_low])) { if ($stack_db_array[$port_id_high][$port_id_low]['ifStackStatus'] == $ifStackStatus) { echo '.'; - } - else { + } else { dbUpdate(array('ifStackStatus' => $ifStackStatus), 'ports_stack', 'device_id=? AND port_id_high=? AND `port_id_low`=?', array($device['device_id'], $port_id_high, $port_id_low)); echo 'U'; } unset($stack_db_array[$port_id_high][$port_id_low]); - } - else { + } else { dbInsert(array('device_id' => $device['device_id'], 'port_id_high' => $port_id_high, 'port_id_low' => $port_id_low, 'ifStackStatus' => $ifStackStatus), 'ports_stack'); echo '+'; } diff --git a/includes/discovery/ports.inc.php b/includes/discovery/ports.inc.php index 6a0d0a5cd6..f8afcec7e9 100644 --- a/includes/discovery/ports.inc.php +++ b/includes/discovery/ports.inc.php @@ -17,11 +17,12 @@ d_echo($port_stats); // or maybe other means in the future. The default port association mode still is ifIndex for // compatibility reasons. $port_association_mode = $config['default_port_association_mode']; -if ($device['port_association_mode']) - $port_association_mode = get_port_assoc_mode_name ($device['port_association_mode']); +if ($device['port_association_mode']) { + $port_association_mode = get_port_assoc_mode_name($device['port_association_mode']); +} // Build array of ports in the database and an ifIndex/ifName -> port_id map -$ports_mapped = get_ports_mapped ($device['device_id']); +$ports_mapped = get_ports_mapped($device['device_id']); $ports_db = $ports_mapped['ports']; // @@ -43,32 +44,26 @@ foreach ($port_stats as $ifIndex => $port) { $ifName = $port['ifName']; // Get port_id according to port_association_mode used for this device - $port_id = get_port_id ($ports_mapped, $port, $port_association_mode); + $port_id = get_port_id($ports_mapped, $port, $port_association_mode); if (is_port_valid($port, $device)) { - // Port newly discovered? if (! is_array($ports_db[$port_id])) { $port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex, 'ifName' => $ifName), 'ports'); $ports[$port_id] = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $port_id)); echo 'Adding: '.$ifName.'('.$ifIndex.')('.$port_id.')'; - } - - // Port re-discovered after previous deletion? - else if ($ports_db[$port_id]['deleted'] == '1') { + } // Port re-discovered after previous deletion? + elseif ($ports_db[$port_id]['deleted'] == '1') { dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($port_id)); $ports_db[$port_id]['deleted'] = '0'; echo 'U'; - } - else { + } else { echo '.'; } // We've seen it. Remove it from the cache. unset($ports_l[$ifIndex]); - } - - // Port vanished (mark as deleted) + } // Port vanished (mark as deleted) else { if (is_array($ports_db[$port_id])) { if ($ports_db[$port_id]['deleted'] != '1') { diff --git a/includes/discovery/processors/adtran-aos.inc.php b/includes/discovery/processors/adtran-aos.inc.php index d0cb140381..ff2705447e 100644 --- a/includes/discovery/processors/adtran-aos.inc.php +++ b/includes/discovery/processors/adtran-aos.inc.php @@ -14,7 +14,6 @@ if ($device['os'] == 'adtran-aos') { - echo 'ADTRAN AOS:'; $descr = 'Processor'; $usage = snmp_get($device, '.1.3.6.1.4.1.664.5.53.1.4.1.0', '-Ovq'); @@ -24,4 +23,3 @@ if ($device['os'] == 'adtran-aos') { discover_processor($valid['processor'], $device, '.1.3.6.1.4.1.664.5.53.1.4.1.0', '0', 'adtran-aos', $descr, '1', $usage, null, null); } } - diff --git a/includes/discovery/processors/aen.inc.php b/includes/discovery/processors/aen.inc.php index ff5b284857..8285cb2520 100644 --- a/includes/discovery/processors/aen.inc.php +++ b/includes/discovery/processors/aen.inc.php @@ -15,8 +15,8 @@ if ($device['os'] == 'aen') { - if ($device['version'] == 'AEN_5.3.1_22558') { - } // don't poll v5.3.1_22558 devices due to bug that crashes snmpd + if ($device['version'] == 'AEN_5.3.1_22558') { + } // don't poll v5.3.1_22558 devices due to bug that crashes snmpd else { echo 'Accedian MetroNID:'; $descr = 'Processor'; diff --git a/includes/discovery/processors/aos-device.inc.php b/includes/discovery/processors/aos-device.inc.php index 38aa438b5d..b44ed84cc4 100644 --- a/includes/discovery/processors/aos-device.inc.php +++ b/includes/discovery/processors/aos-device.inc.php @@ -9,8 +9,7 @@ if ($device['os'] == 'aos') { if (is_numeric($usage)) { discover_processor($valid['processor'], $device, '1.3.6.1.4.1.6486.800.1.2.1.16.1.1.1.13.0', '0', 'aos-system', $descr, '1', $usage, null, null); - } - else { + } else { // AOS7 devices use a different OID for CPU load. Not all Switches have // healthModuleCpuLatest so we use healthModuleCpu1MinAvg which makes no // difference for a 5 min. polling interval. diff --git a/includes/discovery/processors/binos.inc.php b/includes/discovery/processors/binos.inc.php index f9fa27ff4b..86feace082 100644 --- a/includes/discovery/processors/binos.inc.php +++ b/includes/discovery/processors/binos.inc.php @@ -15,7 +15,6 @@ if ($device['os'] == 'binos') { if (strpos($device['sysObjectID'], 'enterprises.738.1.5.100') !== false) { - echo 'Telco Systems:'; $descr = 'Processor'; $usage = snmp_get($device, '.1.3.6.1.4.1.738.1.111.3.1.2.1.0', '-Ovq'); @@ -26,4 +25,3 @@ if ($device['os'] == 'binos') { } } } - diff --git a/includes/discovery/processors/binox.inc.php b/includes/discovery/processors/binox.inc.php index 28c926382e..227e6f3e37 100644 --- a/includes/discovery/processors/binox.inc.php +++ b/includes/discovery/processors/binox.inc.php @@ -14,9 +14,8 @@ if ($device['os'] == 'binox') { - if (strpos($device['sysObjectID'], 'enterprises.738.10.5.100') !== false) { + if (strpos($device['sysObjectID'], 'enterprises.738.10.5.100') !== false) { if ($device['version'] == '2.4.R3.1.1') { - echo 'Telco Systems:'; $descr = 'Processor'; $usage = snmp_get($device, '.1.3.6.1.4.1.738.10.111.1.1.3.1.1.0', '-Ovq'); @@ -25,9 +24,7 @@ if ($device['os'] == 'binox') { if (is_numeric($usage)) { discover_processor($valid['processor'], $device, '.1.3.6.1.4.1.738.10.111.1.1.3.1.1.0', '0', 'binox', $descr, '1', $usage, null, null); } - } - - else { + } else { echo 'Telco Systems:'; $descr = 'Processor'; $usage = snmp_get($device, '.1.3.6.1.4.1.738.10.111.3.1.1.0', '-Ovq'); diff --git a/includes/discovery/processors/calix.inc.php b/includes/discovery/processors/calix.inc.php index d5bce767ed..2cf44c3cc5 100644 --- a/includes/discovery/processors/calix.inc.php +++ b/includes/discovery/processors/calix.inc.php @@ -24,4 +24,3 @@ if ($device['os'] == 'calix') { discover_processor($valid['processor'], $device, '.1.3.6.1.2.1.25.3.3.1.2.768', '0', 'calix', $descr, '1', $usage, null, null); } } - diff --git a/includes/discovery/processors/cambium.inc.php b/includes/discovery/processors/cambium.inc.php index c2b330717d..2b0882f5de 100644 --- a/includes/discovery/processors/cambium.inc.php +++ b/includes/discovery/processors/cambium.inc.php @@ -14,7 +14,17 @@ if ($device['os'] == 'cambium') { $usage = str_replace('"', "", snmp_get($device, 'CAMBIUM-PMP80211-MIB::sysCPUUsage.0', '-OvQ')); if (is_numeric($usage)) { - discover_processor($valid['processor'], $device, 'CAMBIUM-PMP80211-MIB::sysCPUUsage.0', '0', 'cambium-cpu', $descr, - '100', $usage, null, null); + discover_processor( + $valid['processor'], + $device, + 'CAMBIUM-PMP80211-MIB::sysCPUUsage.0', + '0', + 'cambium-cpu', + $descr, + '100', + $usage, + null, + null + ); } } diff --git a/includes/discovery/processors/dnos.inc.php b/includes/discovery/processors/dnos.inc.php index bfe98860e6..bb1eb6d7c3 100644 --- a/includes/discovery/processors/dnos.inc.php +++ b/includes/discovery/processors/dnos.inc.php @@ -7,5 +7,4 @@ if ($device['os'] == 'dnos') { $usage = $matches[0]; discover_processor($valid['processor'], $device, '.1.3.6.1.4.1.674.10895.5000.2.6132.1.1.1.1.4.9.0', '0', 'dnos-cpu', $descr, '1', $usage, null, null); - } diff --git a/includes/discovery/processors/hrdevice.inc.php b/includes/discovery/processors/hrdevice.inc.php index 361d6acb27..a408270ec3 100644 --- a/includes/discovery/processors/hrdevice.inc.php +++ b/includes/discovery/processors/hrdevice.inc.php @@ -28,8 +28,7 @@ if (is_array($hrDevice_array)) { $descr_array = explode(':', $entry['hrDeviceDescr']); if ($descr_array['1']) { $descr = $descr_array['1']; - } - else { + } else { $descr = $descr_array['0']; } diff --git a/includes/discovery/processors/ios.inc.php b/includes/discovery/processors/ios.inc.php index 41cc66c0c9..c2859d3f41 100644 --- a/includes/discovery/processors/ios.inc.php +++ b/includes/discovery/processors/ios.inc.php @@ -12,8 +12,7 @@ if ($device['os_group'] == 'cisco' || $device['os'] == 'acsw') { if (isset($entry['cpmCPUTotal5minRev'])) { $usage_oid = '.1.3.6.1.4.1.9.9.109.1.1.1.1.8.'.$index; $usage = $entry['cpmCPUTotal5minRev']; - } - else if (isset($entry['cpmCPUTotal5min'])) { + } elseif (isset($entry['cpmCPUTotal5min'])) { $usage_oid = '.1.3.6.1.4.1.9.9.109.1.1.1.1.5.'.$index; $usage = $entry['cpmCPUTotal5min']; } diff --git a/includes/discovery/processors/ironware.inc.php b/includes/discovery/processors/ironware.inc.php index 7acb763d75..01e0976a80 100644 --- a/includes/discovery/processors/ironware.inc.php +++ b/includes/discovery/processors/ironware.inc.php @@ -12,8 +12,7 @@ if ($device['os'] == 'ironware' || $device['os_group'] == 'ironware') { $usage_oid = '.1.3.6.1.4.1.1991.1.1.2.11.1.1.6.'.$index; $usage = $entry['snAgentCpuUtil100thPercent']; $precision = 100; - } - else if ($entry['snAgentCpuUtilValue']) { + } elseif ($entry['snAgentCpuUtilValue']) { $usage_oid = '.1.3.6.1.4.1.1991.1.1.2.11.1.1.4.'.$index; $usage = $entry['snAgentCpuUtilValue']; $precision = 100; diff --git a/includes/discovery/processors/nos.inc.php b/includes/discovery/processors/nos.inc.php index c0051e466d..6ce0583aaf 100644 --- a/includes/discovery/processors/nos.inc.php +++ b/includes/discovery/processors/nos.inc.php @@ -7,8 +7,8 @@ if ($device['os'] == "nos") { $usage = snmp_get($device, "1.3.6.1.4.1.1588.2.1.1.1.26.1.0", "-Ovq"); if (is_numeric($usage)) { - discover_processor($valid['processor'], $device, "1.3.6.1.4.1.1588.2.1.1.1.26.1", "0", "nos", $descr, "1", $usage, NULL, NULL); + discover_processor($valid['processor'], $device, "1.3.6.1.4.1.1588.2.1.1.1.26.1", "0", "nos", $descr, "1", $usage, null, null); } } -unset ($processors_array); +unset($processors_array); diff --git a/includes/discovery/processors/pbn.inc.php b/includes/discovery/processors/pbn.inc.php index ada86365b1..3905ce131d 100644 --- a/includes/discovery/processors/pbn.inc.php +++ b/includes/discovery/processors/pbn.inc.php @@ -1,13 +1,11 @@ \d+)/', $device['version'], $version); d_echo($version); // specified MIB supported since build 16607 if ($version[build] >= 16607) { - echo 'PBN : '; $descr = 'Processor'; diff --git a/includes/discovery/processors/powerconnect.inc.php b/includes/discovery/processors/powerconnect.inc.php index 01b91772ad..73a8585b63 100644 --- a/includes/discovery/processors/powerconnect.inc.php +++ b/includes/discovery/processors/powerconnect.inc.php @@ -7,11 +7,11 @@ if ($device['os'] == 'powerconnect') { discover_processor($valid['processor'], $device, '.1.3.6.1.4.1.89.1.7.0', '0', 'powerconnect', 'Processor', '1', $usage, null, null); } elseif (strpos($device["sysObjectID"], "enterprises.674.10895.3024") !== false) { d_echo("Dell Powerconnect 8024F"); - $usage = trim(snmp_get($device,'.1.3.6.1.4.1.674.10895.5000.2.6132.1.1.1.1.4.9.0', '-Ovq'), '"'); - $usage = ltrim($usage,' '); + $usage = trim(snmp_get($device, '.1.3.6.1.4.1.674.10895.5000.2.6132.1.1.1.1.4.9.0', '-Ovq'), '"'); + $usage = ltrim($usage, ' '); if (substr($usage, 0, 5) == '5 Sec') { discover_processor($valid['processor'], $device, '.1.3.6.1.4.1.674.10895.5000.2.6132.1.1.1.1.4.9.0', '0', 'powerconnect', 'Processor', '1', $usage, null, null); - } + } } else { $descr = 'Processor'; $usage = trim(snmp_get($device, 'dellLanExtension.6132.1.1.1.1.4.4.0', '-OQUvs', 'Dell-Vendor-MIB'), '"'); diff --git a/includes/discovery/processors/pulse.inc.php b/includes/discovery/processors/pulse.inc.php index 4faa47dbb5..164a71bbe3 100644 --- a/includes/discovery/processors/pulse.inc.php +++ b/includes/discovery/processors/pulse.inc.php @@ -19,7 +19,17 @@ if ($device['os'] == 'pulse') { $usage = str_replace('"', "", snmp_get($device, 'PULSESECURE-PSG-MIB::iveCpuUtil.0', '-OvQ')); if (is_numeric($usage)) { - discover_processor($valid['processor'], $device, 'PULSESECURE-PSG-MIB::iveCpuUtil.0', '0', 'pulse-cpu', $descr, - '100', $usage, null, null); + discover_processor( + $valid['processor'], + $device, + 'PULSESECURE-PSG-MIB::iveCpuUtil.0', + '0', + 'pulse-cpu', + $descr, + '100', + $usage, + null, + null + ); } } diff --git a/includes/discovery/processors/serveriron.inc.php b/includes/discovery/processors/serveriron.inc.php index e1d86daf9c..5b55c9ecee 100644 --- a/includes/discovery/processors/serveriron.inc.php +++ b/includes/discovery/processors/serveriron.inc.php @@ -12,8 +12,7 @@ if ($device['os'] == 'serveriron') { $usage_oid = '.1.3.6.1.4.1.1991.1.1.2.11.1.1.6.'.$index; $usage = $entry['snAgentCpuUtil100thPercent']; $precision = 100; - } - else if ($entry['snAgentCpuUtilValue']) { + } elseif ($entry['snAgentCpuUtilValue']) { $usage_oid = '.1.3.6.1.4.1.1991.1.1.2.11.1.1.4.'.$index; $usage = $entry['snAgentCpuUtilValue']; $precision = 100; diff --git a/includes/discovery/processors/viprinux.inc.php b/includes/discovery/processors/viprinux.inc.php index df3aca0877..5485045ac7 100644 --- a/includes/discovery/processors/viprinux.inc.php +++ b/includes/discovery/processors/viprinux.inc.php @@ -1,14 +1,23 @@ null)); } @@ -50,7 +47,7 @@ if ($device['os_group'] == "cisco") { ////////////////ipRouteDest////////////////// $oid = '.1.3.6.1.2.1.4.21.1.1'; - $resultHelp = snmp_walk($device, $oid, "-Osqn", $mib, NULL); + $resultHelp = snmp_walk($device, $oid, "-Osqn", $mib, null); $resultHelp = trim($resultHelp); $resultHelp = str_replace("$oid.", "", $resultHelp); @@ -61,7 +58,7 @@ if ($device['os_group'] == "cisco") { /////////////////ipRouteIfIndex////////////// $oid = '.1.3.6.1.2.1.4.21.1.2'; - $resultHelp = snmp_walk($device, $oid, "-Osqn", $mib, NULL); + $resultHelp = snmp_walk($device, $oid, "-Osqn", $mib, null); $resultHelp = trim($resultHelp); $resultHelp = str_replace("$oid.", "", $resultHelp); @@ -72,7 +69,7 @@ if ($device['os_group'] == "cisco") { ///////////////ipRouteMetric1/////////////// $oid = '.1.3.6.1.2.1.4.21.1.3'; - $resultHelp = snmp_walk($device, $oid, "-Osqn", $mib, NULL); + $resultHelp = snmp_walk($device, $oid, "-Osqn", $mib, null); $resultHelp = trim($resultHelp); $resultHelp = str_replace("$oid.", "", $resultHelp); @@ -83,7 +80,7 @@ if ($device['os_group'] == "cisco") { ////////////ipRouteNextHop////////////////// $oid = '.1.3.6.1.2.1.4.21.1.7'; - $resultHelp = snmp_walk($device, $oid, "-Osqn", $mib, NULL); + $resultHelp = snmp_walk($device, $oid, "-Osqn", $mib, null); $resultHelp = trim($resultHelp); $resultHelp = str_replace("$oid.", "", $resultHelp); foreach (explode("\n", $resultHelp) as $ipRouteNextHop) { @@ -93,7 +90,7 @@ if ($device['os_group'] == "cisco") { ////////////ipRouteType///////////////////// $oid = '.1.3.6.1.2.1.4.21.1.8'; - $resultHelp = snmp_walk($device, $oid, "-Osqn", $mib, NULL); + $resultHelp = snmp_walk($device, $oid, "-Osqn", $mib, null); $resultHelp = trim($resultHelp); $resultHelp = str_replace("$oid.", "", $resultHelp); @@ -104,7 +101,7 @@ if ($device['os_group'] == "cisco") { ///////////ipRouteProto////////////////////// $oid = '.1.3.6.1.2.1.4.21.1.9'; - $resultHelp = snmp_walk($device, $oid, "-Osqn", $mib, NULL); + $resultHelp = snmp_walk($device, $oid, "-Osqn", $mib, null); $resultHelp = trim($resultHelp); $resultHelp = str_replace("$oid.", "", $resultHelp); @@ -127,7 +124,7 @@ if ($device['os_group'] == "cisco") { ///////////ipRouteMask////////////////////// $oid = '.1.3.6.1.2.1.4.21.1.11'; - $resultHelp = snmp_walk($device, $oid, "-Osqn -Ln", $mib, NULL); + $resultHelp = snmp_walk($device, $oid, "-Osqn -Ln", $mib, null); $resultHelp = trim($resultHelp); $resultHelp = str_replace("$oid.", "", $resultHelp); @@ -159,7 +156,6 @@ if ($device['os_group'] == "cisco") { dbUpdate($changeRoute, 'route', 'device_id = ? and ipRouteDest = ? and context_name = ?', array($device['device_id'], $ipRoute['ipRouteDest'], $device['context_name'])); } } else { - $toInsert = array_merge($ipRoute, array('device_id' => $device['device_id'], 'context_name' => $device['context_name'], 'discoveredAt' => time())); dbInsert($toInsert, 'route'); } diff --git a/includes/discovery/sensors/charge/apc.inc.php b/includes/discovery/sensors/charge/apc.inc.php index ce98b4b9d2..7094b6cf57 100644 --- a/includes/discovery/sensors/charge/apc.inc.php +++ b/includes/discovery/sensors/charge/apc.inc.php @@ -21,8 +21,7 @@ if ($device['os'] == 'apc') { $descr = 'Battery Charge'; discover_sensor($valid['sensor'], 'charge', $device, $current_oid, $index, $sensorType, $descr, $precision, '1', $lowlimit, $warnlimit, null, $limit, $current_val); - } - else { + } else { // Try to just get capacity $oids = snmp_get($device, '1.3.6.1.4.1.318.1.1.1.2.2.1.0', '-OsqnU', ''); d_echo($oids."\n"); diff --git a/includes/discovery/sensors/cisco-entity-sensor.inc.php b/includes/discovery/sensors/cisco-entity-sensor.inc.php index 138cb5db3a..061bb4401b 100644 --- a/includes/discovery/sensors/cisco-entity-sensor.inc.php +++ b/includes/discovery/sensors/cisco-entity-sensor.inc.php @@ -53,8 +53,7 @@ if ($device['os_group'] == 'cisco') { $entPhysicalIndex = $index; if ($entity_array[$index]['entPhysicalName'] || $device['os'] == 'iosxr') { $descr = rewrite_entity_descr($entity_array[$index]['entPhysicalName']); - } - else { + } else { $descr = rewrite_entity_descr($entity_array[$index]['entPhysicalDescr']); } @@ -162,14 +161,14 @@ if ($device['os_group'] == 'cisco') { if ($ok) { discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current, 'snmp', $entPhysicalIndex, $entry['entSensorMeasuredEntity']); #Cisco IOS-XR : add a fake sensor to graph as dbm - if ($type == "power" and $device['os'] == "iosxr" and preg_match ("/power (R|T)x/i", $descr) ) { + if ($type == "power" and $device['os'] == "iosxr" and preg_match("/power (R|T)x/i", $descr)) { // convert Watts to dbm $type = "dbm"; $limit_low = 10 * log10($limit_low*1000); $warn_limit_low = 10 * log10($warn_limit_low*1000); $warn_limit = 10 * log10($warn_limit*1000); $limit = 10 * log10($limit*1000); - $current = round(10 * log10($current*1000),3); + $current = round(10 * log10($current*1000), 3); $multiplier = 1; $divisor = 1; //echo("\n".$valid['sensor'].", $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current"); diff --git a/includes/discovery/sensors/current/apc.inc.php b/includes/discovery/sensors/current/apc.inc.php index 76e0006a69..8784d89c1e 100644 --- a/includes/discovery/sensors/current/apc.inc.php +++ b/includes/discovery/sensors/current/apc.inc.php @@ -45,8 +45,7 @@ if ($device['os'] == 'apc') { // No / $precision here! Nice, APC! if (count(explode("\n", $oids)) != 1) { $descr = "Phase $phase"; - } - else { + } else { $descr = 'Output'; } @@ -228,8 +227,7 @@ if ($device['os'] == 'apc') { if (empty($oids)) { $oids = snmp_get($device, $item['AdvOid'].'.'.$item['index'], '-OsqnU', $item['mib']); $current_oid = $item['AdvOid']; - } - else { + } else { $current_oid = $item['HighPrecOid']; } @@ -243,8 +241,7 @@ if ($device['os'] == 'apc') { if (stristr($current_oid, 'HighPrec')) { $current = ($oids / $item['divisor']); - } - else { + } else { $current = $oids; $item['divisor'] = 1; } diff --git a/includes/discovery/sensors/current/gamatronicups.inc.php b/includes/discovery/sensors/current/gamatronicups.inc.php index 3c63720b23..f13466a8e1 100644 --- a/includes/discovery/sensors/current/gamatronicups.inc.php +++ b/includes/discovery/sensors/current/gamatronicups.inc.php @@ -12,9 +12,22 @@ if ($device['os'] == 'gamatronicups') { $warnlimit = null; $limit = null; - discover_sensor($valid['sensor'], 'current', $device, - $current_oid, $index, $type, - $descr, '1', '1', $lowlimit, null, null, null, $current); + discover_sensor( + $valid['sensor'], + 'current', + $device, + $current_oid, + $index, + $type, + $descr, + '1', + '1', + $lowlimit, + null, + null, + null, + $current + ); } for ($i = 1; $i <= 3; $i++) { @@ -28,8 +41,21 @@ if ($device['os'] == 'gamatronicups') { $warnlimit = null; $limit = null; - discover_sensor($valid['sensor'], 'current', $device, - $current_oid, $index, $type, - $descr, '1', '1', $lowlimit, null, null, null, $current); + discover_sensor( + $valid['sensor'], + 'current', + $device, + $current_oid, + $index, + $type, + $descr, + '1', + '1', + $lowlimit, + null, + null, + null, + $current + ); } } diff --git a/includes/discovery/sensors/current/junos.inc.php b/includes/discovery/sensors/current/junos.inc.php index bd17e80064..f77e5d50f2 100644 --- a/includes/discovery/sensors/current/junos.inc.php +++ b/includes/discovery/sensors/current/junos.inc.php @@ -28,7 +28,5 @@ if ($device['os'] == 'junos' || $device['os_group'] == 'junos') { $entPhysicalIndex_measured = 'ports'; discover_sensor($valid['sensor'], 'current', $device, $oid, 'rx-'.$index, 'junos', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current, 'snmp', $entPhysicalIndex, $entPhysicalIndex_measured); } - } - } diff --git a/includes/discovery/sensors/current/mgeups.inc.php b/includes/discovery/sensors/current/mgeups.inc.php index bc80a0b162..521abc67af 100644 --- a/includes/discovery/sensors/current/mgeups.inc.php +++ b/includes/discovery/sensors/current/mgeups.inc.php @@ -8,7 +8,7 @@ if ($device['os'] == 'mgeups') { $numPhase = count(explode("\n", $oids)); for ($i = 1; $i <= $numPhase; $i++) { - unset($current); + unset($current); $current_oid = ".1.3.6.1.4.1.705.1.7.2.1.5.$i"; $descr = 'Output'; if ($numPhase > 1) { diff --git a/includes/discovery/sensors/current/netvision.inc.php b/includes/discovery/sensors/current/netvision.inc.php index 6381a62e7b..964d76e651 100644 --- a/includes/discovery/sensors/current/netvision.inc.php +++ b/includes/discovery/sensors/current/netvision.inc.php @@ -12,9 +12,22 @@ if ($device['os'] == 'netvision') { $warnlimit = null; $limit = null; - discover_sensor($valid['sensor'], 'current', $device, - $current_oid, $index, $type, - $descr, '10', '1', $lowlimit, null, null, null, $current); + discover_sensor( + $valid['sensor'], + 'current', + $device, + $current_oid, + $index, + $type, + $descr, + '10', + '1', + $lowlimit, + null, + null, + null, + $current + ); } for ($i = 1; $i <= 3; $i++) { @@ -28,8 +41,21 @@ if ($device['os'] == 'netvision') { $warnlimit = null; $limit = null; - discover_sensor($valid['sensor'], 'current', $device, - $current_oid, $index, $type, - $descr, '10', '1', $lowlimit, null, null, null, $current); + discover_sensor( + $valid['sensor'], + 'current', + $device, + $current_oid, + $index, + $type, + $descr, + '10', + '1', + $lowlimit, + null, + null, + null, + $current + ); } } diff --git a/includes/discovery/sensors/current/pbn.inc.php b/includes/discovery/sensors/current/pbn.inc.php index c105d43b52..b8fc4af1d3 100644 --- a/includes/discovery/sensors/current/pbn.inc.php +++ b/includes/discovery/sensors/current/pbn.inc.php @@ -27,7 +27,5 @@ if ($device['os'] == 'pbn' || $device['os_group'] == 'pbn') { $entPhysicalIndex_measured = 'ports'; discover_sensor($valid['sensor'], 'current', $device, $oid, ''.$index, 'pbn', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $value, 'snmp', $entPhysicalIndex, $entPhysicalIndex_measured); } - } - } diff --git a/includes/discovery/sensors/dbm/junos.inc.php b/includes/discovery/sensors/dbm/junos.inc.php index e9cd00986d..678e61509c 100644 --- a/includes/discovery/sensors/dbm/junos.inc.php +++ b/includes/discovery/sensors/dbm/junos.inc.php @@ -41,7 +41,5 @@ if ($device['os'] == 'junos' || $device['os_group'] == 'junos') { $entPhysicalIndex_measured = 'ports'; discover_sensor($valid['sensor'], 'dbm', $device, $oid, 'tx-'.$index, 'junos', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current, 'snmp', $entPhysicalIndex, $entPhysicalIndex_measured); } - } - } diff --git a/includes/discovery/sensors/dbm/pbn.inc.php b/includes/discovery/sensors/dbm/pbn.inc.php index 78cd431579..dad5defa2e 100644 --- a/includes/discovery/sensors/dbm/pbn.inc.php +++ b/includes/discovery/sensors/dbm/pbn.inc.php @@ -41,5 +41,4 @@ if ($device['os'] == 'pbn' || $device['os_group'] == 'pbn') { discover_sensor($valid['sensor'], 'dbm', $device, $oid, 'tx-'.$index, 'pbn', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $value, 'snmp', $entPhysicalIndex, $entPhysicalIndex_measured); } } - } diff --git a/includes/discovery/sensors/entity-sensor.inc.php b/includes/discovery/sensors/entity-sensor.inc.php index 0e5eb383a7..fb23b4fe1f 100644 --- a/includes/discovery/sensors/entity-sensor.inc.php +++ b/includes/discovery/sensors/entity-sensor.inc.php @@ -44,8 +44,7 @@ if (is_array($oids)) { // if ($descr || $device['os'] == "iosxr") if ($descr) { $descr = rewrite_entity_descr($descr); - } - else { + } else { $descr = $entity_array[$index]['entPhysicalDescr']; $descr = rewrite_entity_descr($descr); } diff --git a/includes/discovery/sensors/fanspeeds/extreme.inc.php b/includes/discovery/sensors/fanspeeds/extreme.inc.php index 983172d850..1cfa622bb1 100644 --- a/includes/discovery/sensors/fanspeeds/extreme.inc.php +++ b/includes/discovery/sensors/fanspeeds/extreme.inc.php @@ -8,7 +8,7 @@ if ($device['os'] == 'xos') { $oids = snmpwalk_cache_multi_oid($device, $oid, array(), "EXTREME-BASE-MIB"); foreach ($oids as $index => $entry) { - // fix index to a proper int + // fix index to a proper int preg_match('/^.*\.([^\.]*)$/', "$index", $matches); $index = $matches[1]; // substract 100 from index to start from 1 instead of 101 diff --git a/includes/discovery/sensors/fanspeeds/ibm-amm.inc.php b/includes/discovery/sensors/fanspeeds/ibm-amm.inc.php index b9d6729af3..11e7435f1a 100644 --- a/includes/discovery/sensors/fanspeeds/ibm-amm.inc.php +++ b/includes/discovery/sensors/fanspeeds/ibm-amm.inc.php @@ -11,7 +11,6 @@ */ if ($device['os'] == 'ibm-amm') { - $descr_prefix = 'Blower '; $oids = array( '.1.3.6.1.4.1.2.3.51.2.2.3.20.0', // BLADE-MIB:blower1speedRPM @@ -29,5 +28,4 @@ if ($device['os'] == 'ibm-amm') { discover_sensor($valid['sensor'], 'fanspeed', $device, $oid, $index, 'snmp', $descr, 1, 1, null, null, null, null, $value); } } - } diff --git a/includes/discovery/sensors/fanspeeds/nos.inc.php b/includes/discovery/sensors/fanspeeds/nos.inc.php index 110da51aad..5e500146a6 100644 --- a/includes/discovery/sensors/fanspeeds/nos.inc.php +++ b/includes/discovery/sensors/fanspeeds/nos.inc.php @@ -17,12 +17,12 @@ if ($device['os'] == "nos") { $oids = trim($oids); foreach (explode("\n", $oids) as $data) { $data = trim($data); - if ($data AND $data[37] == "2") { + if ($data and $data[37] == "2") { $value_oid = ".1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.".$data[35]; $descr_oid = ".1.3.6.1.4.1.1588.2.1.1.1.1.22.1.5.".$data[35]; $value = snmp_get($device, $value_oid, '-Oqv'); $descr = snmp_get($device, $descr_oid, '-Oqv'); - if (!strstr($descr, 'No') AND !strstr($value, 'No')) { + if (!strstr($descr, 'No') and !strstr($value, 'No')) { $descr = str_replace('"', '', $descr); $descr = trim($descr); discover_sensor($valid['sensor'], 'temperature', $device, $value_oid, $data[35], 'nos', $descr, '1', '1', null, null, '80', '100', $value); diff --git a/includes/discovery/sensors/fanspeeds/qnap.inc.php b/includes/discovery/sensors/fanspeeds/qnap.inc.php index 2f06661fa4..922b14048a 100644 --- a/includes/discovery/sensors/fanspeeds/qnap.inc.php +++ b/includes/discovery/sensors/fanspeeds/qnap.inc.php @@ -19,5 +19,4 @@ if ($device['os'] == 'qnap') { discover_sensor($valid['sensor'], 'fanspeed', $device, $fan_oid, $fan_number, 'snmp', $fan_information, '1', '1', null, null, null, null, $fan_speed); } } - }//end if diff --git a/includes/discovery/sensors/frequencies/linux.inc.php b/includes/discovery/sensors/frequencies/linux.inc.php index f49a9ff1f7..eca6072de6 100644 --- a/includes/discovery/sensors/frequencies/linux.inc.php +++ b/includes/discovery/sensors/frequencies/linux.inc.php @@ -9,9 +9,8 @@ if (preg_match("/(bcm).+(boardrev)/", $raspberry)) { $sensor_type = "raspberry_freq"; $oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.'; - for($freq = 6; $freq < 8; $freq++) { - switch($freq) - { + for ($freq = 6; $freq < 8; $freq++) { + switch ($freq) { case "6": $descr = "ARM"; break; @@ -22,4 +21,4 @@ if (preg_match("/(bcm).+(boardrev)/", $raspberry)) { $value = snmp_get($device, $oid.$freq, '-Oqve'); discover_sensor($valid['sensor'], 'frequency', $device, $oid.$freq, $freq, $sensor_type, $descr, 1, 1, null, null, null, null, $value); } -} \ No newline at end of file +} diff --git a/includes/discovery/sensors/frequencies/mgeups.inc.php b/includes/discovery/sensors/frequencies/mgeups.inc.php index 1815a30c6a..64efa49cc1 100644 --- a/includes/discovery/sensors/frequencies/mgeups.inc.php +++ b/includes/discovery/sensors/frequencies/mgeups.inc.php @@ -8,7 +8,7 @@ if ($device['os'] == 'mgeups') { $numPhase = count(explode("\n", $oids)); for ($i = 1; $i <= $numPhase; $i++) { - $freq_oid = ".1.3.6.1.4.1.705.1.7.2.1.3.$i"; + $freq_oid = ".1.3.6.1.4.1.705.1.7.2.1.3.$i"; $descr = 'Output'; if ($numPhase > 1) { $descr .= " Phase $i"; diff --git a/includes/discovery/sensors/frequencies/netvision.inc.php b/includes/discovery/sensors/frequencies/netvision.inc.php index e26fef8c65..e4b353b089 100644 --- a/includes/discovery/sensors/frequencies/netvision.inc.php +++ b/includes/discovery/sensors/frequencies/netvision.inc.php @@ -7,9 +7,22 @@ if ($device['os'] == 'netvision') { $type = 'netvision'; $divisor = 10; $index = '3.2.0'; - discover_sensor($valid['sensor'], 'frequency', $device, - $freq_oid, $index, $type, - $descr, $divisor, '1', null, null, null, null, $current); + discover_sensor( + $valid['sensor'], + 'frequency', + $device, + $freq_oid, + $index, + $type, + $descr, + $divisor, + '1', + null, + null, + null, + null, + $current + ); $freq_oid = '1.3.6.1.4.1.4555.1.1.1.1.4.2.0'; $descr = 'Output'; @@ -17,7 +30,20 @@ if ($device['os'] == 'netvision') { $type = 'netvision'; $divisor = 10; $index = '4.2.0'; - discover_sensor($valid['sensor'], 'frequency', $device, - $freq_oid, $index, $type, - $descr, $divisor, '1', null, null, null, null, $current); + discover_sensor( + $valid['sensor'], + 'frequency', + $device, + $freq_oid, + $index, + $type, + $descr, + $divisor, + '1', + null, + null, + null, + null, + $current + ); } diff --git a/includes/discovery/sensors/humidity/akcp.inc.php b/includes/discovery/sensors/humidity/akcp.inc.php index d32406ba28..30760c3c7f 100644 --- a/includes/discovery/sensors/humidity/akcp.inc.php +++ b/includes/discovery/sensors/humidity/akcp.inc.php @@ -31,9 +31,22 @@ if ($device['os'] == 'akcp' || $device['os'] == 'minkelsrms') { $lowlimit = snmp_get($device, $lowlimit_oid, '-Oqv', ''); $warnlowlimit = snmp_get($device, $warnlowlimit_oid, '-Oqv', ''); - discover_sensor($valid['sensor'], 'humidity', $device, - $oid, $index, 'akcp', - $descr, '1', '1', $lowlimit, $warnlowlimit, $limit, $warnlimit, $humidity); + discover_sensor( + $valid['sensor'], + 'humidity', + $device, + $oid, + $index, + 'akcp', + $descr, + '1', + '1', + $lowlimit, + $warnlowlimit, + $limit, + $warnlimit, + $humidity + ); } } } diff --git a/includes/discovery/sensors/humidity/netbotz.inc.php b/includes/discovery/sensors/humidity/netbotz.inc.php index e3f686fd94..e16c5b09bd 100644 --- a/includes/discovery/sensors/humidity/netbotz.inc.php +++ b/includes/discovery/sensors/humidity/netbotz.inc.php @@ -17,9 +17,22 @@ if ($device['os'] == 'netbotz') { $descr = str_replace('"', '', $descr); $descr = trim($descr); if ($humidity >= 0) { - discover_sensor($valid['sensor'], 'humidity', $device, - $humidity_oid, $humidity_id, 'netbotz', - $descr, '1', '1', null, null, null, null, $humidity); + discover_sensor( + $valid['sensor'], + 'humidity', + $device, + $humidity_oid, + $humidity_id, + 'netbotz', + $descr, + '1', + '1', + null, + null, + null, + null, + $humidity + ); } } diff --git a/includes/discovery/sensors/humidity/sentry3.inc.php b/includes/discovery/sensors/humidity/sentry3.inc.php index e1417993c9..8b2092f01e 100644 --- a/includes/discovery/sensors/humidity/sentry3.inc.php +++ b/includes/discovery/sensors/humidity/sentry3.inc.php @@ -28,10 +28,22 @@ if ($device['os'] == 'sentry3') { $current = snmp_get($device, "$humidity_oid", '-Ovq', 'Sentry3-MIB'); if ($current >= 0) { - discover_sensor($valid['sensor'], 'humidity', $device, - $humidity_oid, $index, 'sentry3', - $descr, $divisor, $multiplier, $low_limit, $low_warn_limit, - $high_warn_limit, $high_limit, $current); + discover_sensor( + $valid['sensor'], + 'humidity', + $device, + $humidity_oid, + $index, + 'sentry3', + $descr, + $divisor, + $multiplier, + $low_limit, + $low_warn_limit, + $high_warn_limit, + $high_limit, + $current + ); } } diff --git a/includes/discovery/sensors/load/apc.inc.php b/includes/discovery/sensors/load/apc.inc.php index 1d0c7ce5ec..91affa0bea 100644 --- a/includes/discovery/sensors/load/apc.inc.php +++ b/includes/discovery/sensors/load/apc.inc.php @@ -24,8 +24,7 @@ if ($device['os'] == 'apc') { if (empty($oids)) { $oids = snmp_get($device, $item['AdvOid'].'.'.$item['index'], '-OsqnU', $item['mib']); $current_oid = $item['AdvOid']; - } - else { + } else { $current_oid = $item['HighPrecOid']; } @@ -39,8 +38,7 @@ if ($device['os'] == 'apc') { if (stristr($current_oid, 'HighPrec')) { $current = ($oids / $item['divisor']); - } - else { + } else { $current = $oids; $item['divisor'] = 1; } diff --git a/includes/discovery/sensors/netscaler.inc.php b/includes/discovery/sensors/netscaler.inc.php index 8470bb2a96..6dac8c2787 100644 --- a/includes/discovery/sensors/netscaler.inc.php +++ b/includes/discovery/sensors/netscaler.inc.php @@ -19,18 +19,15 @@ foreach ($ns_sensor_array as $descr => $data) { $divisor = 0; $multiplier = 0; $type = 'temperature'; - } - else if (strpos($descr, 'Fan') !== false) { + } elseif (strpos($descr, 'Fan') !== false) { $divisor = 0; $multiplier = 0; $type = 'fanspeed'; - } - else if (strpos($descr, 'Volt') !== false) { + } elseif (strpos($descr, 'Volt') !== false) { $divisor = 1000; $multiplier = 0; $type = 'voltage'; - } - else if (strpos($descr, 'Vtt') !== false) { + } elseif (strpos($descr, 'Vtt') !== false) { $divisor = 1000; $multiplier = 0; $type = 'voltage'; @@ -40,9 +37,22 @@ foreach ($ns_sensor_array as $descr => $data) { $current = ($current / $divisor); }; - discover_sensor($valid['sensor'], $type, $device, - $oid, $descr, 'netscaler-health', - $descr, $divisor, $multiplier, null, null, null, null, $current); + discover_sensor( + $valid['sensor'], + $type, + $device, + $oid, + $descr, + 'netscaler-health', + $descr, + $divisor, + $multiplier, + null, + null, + null, + null, + $current + ); } unset($ns_sensor_array); diff --git a/includes/discovery/sensors/power/extreme.inc.php b/includes/discovery/sensors/power/extreme.inc.php index f15be4cd15..e88c7ad1cf 100644 --- a/includes/discovery/sensors/power/extreme.inc.php +++ b/includes/discovery/sensors/power/extreme.inc.php @@ -10,7 +10,7 @@ if ($device['os'] == 'xos') { $divisor = "1000"; if (is_numeric($value)) { - $value = ($value / $divisor); // Nasty hack to divide the first value by 1000 since the divisor only works for polling after the sensor has been added + $value = ($value / $divisor); // Nasty hack to divide the first value by 1000 since the divisor only works for polling after the sensor has been added discover_sensor($valid['sensor'], 'power', $device, $oid, '1', 'extreme-power', $descr, $divisor, 1, null, null, null, null, $value); // No limits have been specified since all equipment is different and will use different amount of Watts } } diff --git a/includes/discovery/sensors/power/hpblmos.inc.php b/includes/discovery/sensors/power/hpblmos.inc.php index 366244171d..baf9b6ddd0 100644 --- a/includes/discovery/sensors/power/hpblmos.inc.php +++ b/includes/discovery/sensors/power/hpblmos.inc.php @@ -1,6 +1,5 @@ 1) $descr .= " Phase $i"; + if ($numPhase > 1) { + $descr .= " Phase $i"; + } $current = snmp_get($device, $current_oid, "-Oqv"); $type = "rfc1628"; $precision = 1; $index = 300+$i; - discover_sensor($valid['sensor'], 'power', $device, $current_oid, $index, $type, $descr, '1', '1', NULL, NULL, NULL, NULL, $current); + discover_sensor($valid['sensor'], 'power', $device, $current_oid, $index, $type, $descr, '1', '1', null, null, null, null, $current); } $oids = trim(snmp_walk($device, "1.3.6.1.2.1.33.1.3.2.0", "-OsqnU")); d_echo($oids."\n"); - list($unused,$numPhase) = explode(' ',$oids); - for($i = 1; $i <= $numPhase;$i++) { + list($unused,$numPhase) = explode(' ', $oids); + for ($i = 1; $i <= $numPhase; $i++) { $current_oid = "1.3.6.1.2.1.33.1.3.3.1.5.$i"; $descr = "Input"; - if ($numPhase > 1) $descr .= " Phase $i"; + if ($numPhase > 1) { + $descr .= " Phase $i"; + } $current = snmp_get($device, $current_oid, "-Oqv"); $type = "rfc1628"; $precision = 1; $index = 100+$i; - discover_sensor($valid['sensor'], 'power', $device, $current_oid, $index, $type, $descr, '1', '1', NULL, NULL, NULL, NULL, $current); + discover_sensor($valid['sensor'], 'power', $device, $current_oid, $index, $type, $descr, '1', '1', null, null, null, null, $current); } $oids = trim(snmp_walk($device, "1.3.6.1.2.1.33.1.5.2.0", "-OsqnU")); d_echo($oids."\n"); - list($unused,$numPhase) = explode(' ',$oids); - for($i = 1; $i <= $numPhase;$i++) { + list($unused,$numPhase) = explode(' ', $oids); + for ($i = 1; $i <= $numPhase; $i++) { $current_oid = ".1.3.6.1.2.1.33.1.5.3.1.4.$i"; $descr = "Bypass"; - if ($numPhase > 1) $descr .= " Phase $i"; + if ($numPhase > 1) { + $descr .= " Phase $i"; + } $current = snmp_get($device, $current_oid, "-Oqv"); $type = "rfc1628"; $precision = 1; $index = 200+$i; - discover_sensor($valid['sensor'], 'power', $device, $current_oid, $index, $type, $descr, '1', '1', NULL, NULL, NULL, NULL, $current); + discover_sensor($valid['sensor'], 'power', $device, $current_oid, $index, $type, $descr, '1', '1', null, null, null, null, $current); } } diff --git a/includes/discovery/sensors/pre-cache/comware.inc.php b/includes/discovery/sensors/pre-cache/comware.inc.php index ecfeabe095..920ff01592 100644 --- a/includes/discovery/sensors/pre-cache/comware.inc.php +++ b/includes/discovery/sensors/pre-cache/comware.inc.php @@ -11,13 +11,10 @@ */ if ($device['os'] == 'comware') { - echo 'Pre-cache Comware: '; $comware_oids = array(); echo 'Caching OIDs:'; $comware_oids = snmpwalk_cache_multi_oid($device, 'hh3cTransceiverInfoTable', array(), 'HH3C-TRANSCEIVER-INFO-MIB'); - } - diff --git a/includes/discovery/sensors/pre-cache/junos.inc.php b/includes/discovery/sensors/pre-cache/junos.inc.php index 76f86779e1..60abdbd177 100644 --- a/includes/discovery/sensors/pre-cache/junos.inc.php +++ b/includes/discovery/sensors/pre-cache/junos.inc.php @@ -11,12 +11,10 @@ */ if ($device['os'] == 'junos') { - echo 'Pre-cache JunOS: '; $junos_oids = array(); echo 'Caching OIDs:'; $junos_oids = snmpwalk_cache_multi_oid($device, 'JnxDomCurrentEntry', array(), 'JUNIPER-DOM-MIB', $config['mib_dir'].':'.$config['mib_dir'].'/junos'); - } diff --git a/includes/discovery/sensors/pre-cache/pbn.inc.php b/includes/discovery/sensors/pre-cache/pbn.inc.php index bc3e0ae985..018960ca75 100644 --- a/includes/discovery/sensors/pre-cache/pbn.inc.php +++ b/includes/discovery/sensors/pre-cache/pbn.inc.php @@ -10,12 +10,10 @@ */ if ($device['os'] == 'pbn') { - echo 'Pre-cache PBN: '; $pbn_oids = array(); echo 'Caching OIDs:'; $pbn_oids = snmpwalk_cache_multi_oid($device, 'ifSfpParameterTable', array(), 'NMS-IF-MIB', $config['mib_dir'].':'.$config['mib_dir'].'/pbn'); - } diff --git a/includes/discovery/sensors/signal.inc.php b/includes/discovery/sensors/signal.inc.php index 39808c4d4a..55ab39291c 100644 --- a/includes/discovery/sensors/signal.inc.php +++ b/includes/discovery/sensors/signal.inc.php @@ -9,4 +9,4 @@ d_echo($valid['sensor']['signal']); check_valid_sensors($device, 'signal', $valid['sensor']); -echo "\n"; \ No newline at end of file +echo "\n"; diff --git a/includes/discovery/sensors/signal/cambium.inc.php b/includes/discovery/sensors/signal/cambium.inc.php index fac60b735c..739b84002b 100644 --- a/includes/discovery/sensors/signal/cambium.inc.php +++ b/includes/discovery/sensors/signal/cambium.inc.php @@ -2,38 +2,34 @@ if ($device['os'] == 'cambium') { $cambium_type = snmp_get($device, 'sysDescr.0', '-Oqv', ''); - $is_epmp = snmp_get($device, 'sysObjectID.0', '-Oqv', ''); - $divisor = 1; - if (strstr($cambium_type, 'Cambium PTP 50650')) { - $mib = 'CAMBIUM-PTP650-MIB'; - $oid = 'receivePower.0'; - $divisor = 10; - } - else if (strstr($cambium_type, 'PTP250')) { - $oid = 'receivePower.0'; - $mib = 'CAMBIUM-PTP250-MIB'; - $divisor = 10; - } - else if (strstr($is_epmp, '.17713.21')) { - $epmp_ap = snmp_get($device, 'wirelessInterfaceMode.0', '-Oqv', 'CAMBIUM-PMP80211-MIB'); - $epmp_number = snmp_get($device, 'cambiumSubModeType.0', '-Oqv', 'CAMBIUM-PMP80211-MIB'); - if ($epmp_ap == 1) { - if ($epmp_number != 1) { - $oid = 'cambiumSTADLRSSI.0'; - $mib = 'CAMBIUM-PMP80211-MIB'; - } - } - else { - $oid = 'cambiumSTADLRSSI.0'; - $mib = 'CAMBIUM-PMP80211-MIB'; - } - } - else { - $oid = '1.3.6.1.4.1.161.19.3.2.2.21.0'; - $mib = 'WHISP-BOX-MIBV2-MIB'; - } - - $oids = trim(str_replace('"', '', snmp_get($device, "$oid", '-OsqnU', $mib))); + $is_epmp = snmp_get($device, 'sysObjectID.0', '-Oqv', ''); + $divisor = 1; + if (strstr($cambium_type, 'Cambium PTP 50650')) { + $mib = 'CAMBIUM-PTP650-MIB'; + $oid = 'receivePower.0'; + $divisor = 10; + } elseif (strstr($cambium_type, 'PTP250')) { + $oid = 'receivePower.0'; + $mib = 'CAMBIUM-PTP250-MIB'; + $divisor = 10; + } elseif (strstr($is_epmp, '.17713.21')) { + $epmp_ap = snmp_get($device, 'wirelessInterfaceMode.0', '-Oqv', 'CAMBIUM-PMP80211-MIB'); + $epmp_number = snmp_get($device, 'cambiumSubModeType.0', '-Oqv', 'CAMBIUM-PMP80211-MIB'); + if ($epmp_ap == 1) { + if ($epmp_number != 1) { + $oid = 'cambiumSTADLRSSI.0'; + $mib = 'CAMBIUM-PMP80211-MIB'; + } + } else { + $oid = 'cambiumSTADLRSSI.0'; + $mib = 'CAMBIUM-PMP80211-MIB'; + } + } else { + $oid = '1.3.6.1.4.1.161.19.3.2.2.21.0'; + $mib = 'WHISP-BOX-MIBV2-MIB'; + } + + $oids = trim(str_replace('"', '', snmp_get($device, "$oid", '-OsqnU', $mib))); d_echo($oids."\n"); if (!empty($oids)) { diff --git a/includes/discovery/sensors/signal/canopy.inc.php b/includes/discovery/sensors/signal/canopy.inc.php index 6cc0a9286e..24981587bb 100644 --- a/includes/discovery/sensors/signal/canopy.inc.php +++ b/includes/discovery/sensors/signal/canopy.inc.php @@ -2,35 +2,31 @@ if ($device['os'] == 'canopy') { $cambium_type = snmp_get($device, 'sysDescr.0', '-Oqv', ''); - $divisor = 1; - if (strstr($cambium_type, 'BHUL450')) { - $masterSlaveMode = snmp_get($device, 'bhTimingMode.0', '-Oqv', 'WHISP-BOX-MIBV2-MIB'); - if ($masterSlaveMode == "timingMaster") { - $oid = 'lastPowerLevel.2'; - $mib = 'WHISP-APS-MIB'; - } - else { - $oid = 'radioDbmInt.0'; - $mib = 'WHISP-SM-MIB'; - } - } - else if (strstr($cambium_type, 'BHUL') || strstr($cambium_type, 'BH')) { - $masterSlaveMode = snmp_get($device, 'bhTimingMode.0', '-Oqv', 'WHISP-BOX-MIBV2-MIB'); - if ($masterSlaveMode == "timingMaster") { - $oid = 'lastPowerLevel.2'; - $mib = 'WHISP-APS-MIB'; - } - else { - $oid = '1.3.6.1.4.1.161.19.3.2.2.21.0'; - $mib = 'WHISP-BOX-MIBV2-MIB'; - } - } - else { - $oid = '1.3.6.1.4.1.161.19.3.2.2.21.0'; - $mib = 'WHISP-BOX-MIBV2-MIB'; - } - - $oids = trim(str_replace('"', '', snmp_get($device, "$oid", '-OsqnU', $mib))); + $divisor = 1; + if (strstr($cambium_type, 'BHUL450')) { + $masterSlaveMode = snmp_get($device, 'bhTimingMode.0', '-Oqv', 'WHISP-BOX-MIBV2-MIB'); + if ($masterSlaveMode == "timingMaster") { + $oid = 'lastPowerLevel.2'; + $mib = 'WHISP-APS-MIB'; + } else { + $oid = 'radioDbmInt.0'; + $mib = 'WHISP-SM-MIB'; + } + } elseif (strstr($cambium_type, 'BHUL') || strstr($cambium_type, 'BH')) { + $masterSlaveMode = snmp_get($device, 'bhTimingMode.0', '-Oqv', 'WHISP-BOX-MIBV2-MIB'); + if ($masterSlaveMode == "timingMaster") { + $oid = 'lastPowerLevel.2'; + $mib = 'WHISP-APS-MIB'; + } else { + $oid = '1.3.6.1.4.1.161.19.3.2.2.21.0'; + $mib = 'WHISP-BOX-MIBV2-MIB'; + } + } else { + $oid = '1.3.6.1.4.1.161.19.3.2.2.21.0'; + $mib = 'WHISP-BOX-MIBV2-MIB'; + } + + $oids = trim(str_replace('"', '', snmp_get($device, "$oid", '-OsqnU', $mib))); d_echo($oids."\n"); if (!empty($oids)) { diff --git a/includes/discovery/sensors/states/asa.inc.php b/includes/discovery/sensors/states/asa.inc.php index 321849ea18..f7a43d493f 100644 --- a/includes/discovery/sensors/states/asa.inc.php +++ b/includes/discovery/sensors/states/asa.inc.php @@ -11,14 +11,12 @@ */ if ($device['os_group'] == 'cisco' && $device['os'] == 'asa') { - $temp = snmpwalk_cache_multi_oid($device, 'cfwHardwareStatusTable', array(), 'CISCO-FIREWALL-MIB'); $cur_oid = '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.3.'; if (is_array($temp)) { //Create State Index if (strstr($temp['netInterface']['cfwHardwareStatusDetail'], 'not Configured') == false) { - $state_name = 'cfwHardwareStatus'; $state_index_id = create_state_index($state_name); @@ -36,7 +34,7 @@ if ($device['os_group'] == 'cisco' && $device['os'] == 'asa') { array($state_index_id,'active',0,9,0) , array($state_index_id,'standby',0,10,0) ); - foreach($states as $value){ + foreach ($states as $value) { $insert = array( 'state_index_id' => $value[0], 'state_descr' => $value[1], @@ -52,11 +50,9 @@ if ($device['os_group'] == 'cisco' && $device['os'] == 'asa') { $descr = ucwords(trim(preg_replace('/\s*\([^)]*\)/', '', $temp[$index]['cfwHardwareInformation']))); if ($index == 'netInterface') { $index = 4; - } - elseif ($index == 'primaryUnit') { + } elseif ($index == 'primaryUnit') { $index = 6; - } - elseif ($index == 'secondaryUnit') { + } elseif ($index == 'secondaryUnit') { $index = 7; } //Discover Sensors @@ -68,4 +64,3 @@ if ($device['os_group'] == 'cisco' && $device['os'] == 'asa') { } } } - diff --git a/includes/discovery/sensors/states/avtech.inc.php b/includes/discovery/sensors/states/avtech.inc.php index 1dd0745f7d..b2ad0f734e 100644 --- a/includes/discovery/sensors/states/avtech.inc.php +++ b/includes/discovery/sensors/states/avtech.inc.php @@ -14,8 +14,7 @@ if ($device['os'] == 'avtech') { 'descr_oid' => $device_oid.'1.2.2.0', ); avtech_add_sensor($device, $switch); - } - elseif (strpos($device['sysObjectID'], '.20916.1.6') !== false) { + } elseif (strpos($device['sysObjectID'], '.20916.1.6') !== false) { // RoomAlert 4E $device_oid = '.1.3.6.1.4.1.20916.1.6.'; diff --git a/includes/discovery/sensors/states/cisco.inc.php b/includes/discovery/sensors/states/cisco.inc.php index f1fcdb03a5..255456d607 100644 --- a/includes/discovery/sensors/states/cisco.inc.php +++ b/includes/discovery/sensors/states/cisco.inc.php @@ -11,7 +11,6 @@ */ if ($device['os_group'] == 'cisco') { - $tables = array( array('ciscoEnvMonVoltageStatusTable','.1.3.6.1.4.1.9.9.13.1.2.1.7.','ciscoEnvMonVoltageState','ciscoEnvMonVoltageStatusDescr', 'CISCO-ENVMON-MIB') , array('ciscoEnvMonTemperatureStatusTable','.1.3.6.1.4.1.9.9.13.1.3.1.6.','ciscoEnvMonTemperatureState','ciscoEnvMonTemperatureStatusDescr', 'CISCO-ENVMON-MIB') , @@ -19,10 +18,10 @@ if ($device['os_group'] == 'cisco') { array('ciscoEnvMonSupplyStatusTable','.1.3.6.1.4.1.9.9.13.1.5.1.3.','ciscoEnvMonSupplyState','ciscoEnvMonSupplyStatusDescr', 'CISCO-ENVMON-MIB') , array('cRFCfgRedundancyOperMode','.1.3.6.1.4.1.9.9.176.1.2.14.','cRFCfgRedundancyOperMode','VSS Mode', 'CISCO-RF-MIB') , array('cRFStatusUnitState','.1.3.6.1.4.1.9.9.176.1.1.2.','cRFStatusUnitState','VSS Device State', 'CISCO-RF-MIB') , - array('cRFStatusPeerUnitState','.1.3.6.1.4.1.9.9.176.1.1.4.','cRFStatusPeerUnitState','VSS Peer State', 'CISCO-RF-MIB') + array('cRFStatusPeerUnitState','.1.3.6.1.4.1.9.9.176.1.1.4.','cRFStatusPeerUnitState','VSS Peer State', 'CISCO-RF-MIB') ); - foreach($tables as $tablevalue){ + foreach ($tables as $tablevalue) { $temp = snmpwalk_cache_multi_oid($device, $tablevalue[0], array(), $tablevalue[4]); $cur_oid = $tablevalue[1]; @@ -51,8 +50,7 @@ if ($device['os_group'] == 'cisco') { array($state_index_id,'active',0,14,0) , array($state_index_id,'activeExtraload',0,15,1) , array($state_index_id,'activeHandback',0,16,1) - ); - + ); } elseif ($state_name == 'cRFCfgRedundancyOperMode') { $states = array( array($state_index_id,'nonRedundant',0,1,0) , @@ -75,7 +73,7 @@ if ($device['os_group'] == 'cisco') { ); } - foreach($states as $value){ + foreach ($states as $value) { $insert = array( 'state_index_id' => $value[0], 'state_descr' => $value[1], diff --git a/includes/discovery/sensors/states/comware.inc.php b/includes/discovery/sensors/states/comware.inc.php index 95e06f3594..aece664abd 100644 --- a/includes/discovery/sensors/states/comware.inc.php +++ b/includes/discovery/sensors/states/comware.inc.php @@ -11,13 +11,12 @@ */ if ($device['os'] == 'comware') { - $tables = array( array('hh3cdevMFanStatusTable','.1.3.6.1.4.1.25506.8.35.9.1.1.1.2.','hh3cDevMFanStatus') , - array('hh3cdevMPowerStatusTable','.1.3.6.1.4.1.25506.8.35.9.1.2.1.2.','hh3cDevMPowerStatus') + array('hh3cdevMPowerStatusTable','.1.3.6.1.4.1.25506.8.35.9.1.2.1.2.','hh3cDevMPowerStatus') ); - foreach($tables as $tablevalue){ + foreach ($tables as $tablevalue) { $temp = snmpwalk_cache_multi_oid($device, $tablevalue[0], array(), 'HH3C-LswDEVM-MIB'); $cur_oid = $tablevalue[1]; @@ -34,7 +33,7 @@ if ($device['os'] == 'comware') { array($state_index_id,'not-install',0,3,3) , array($state_index_id,'unsupport',0,4,1) ); - foreach($states as $value){ + foreach ($states as $value) { $insert = array( 'state_index_id' => $value[0], 'state_descr' => $value[1], @@ -60,4 +59,3 @@ if ($device['os'] == 'comware') { } } } - diff --git a/includes/discovery/sensors/states/dell.inc.php b/includes/discovery/sensors/states/dell.inc.php index 73caec3cef..edea2dbe89 100644 --- a/includes/discovery/sensors/states/dell.inc.php +++ b/includes/discovery/sensors/states/dell.inc.php @@ -19,11 +19,11 @@ d_echo($oids."\n"); $oids = trim($oids); - if ($oids) { - echo 'Dell '; +if ($oids) { + echo 'Dell '; - $state_name = 'dellVirtualDiskState'; - $state_index_id = create_state_index($state_name); + $state_name = 'dellVirtualDiskState'; + $state_index_id = create_state_index($state_name); /* -- 1.3.6.1.4.1.674.10893.1.20.140.1.1.4 virtualDiskState @@ -47,51 +47,52 @@ INTEGER permanentlyDegraded(52) } */ - if ($state_index_id) { - $states = array( - array($state_index_id,'unknown',0,0,3) , - array($state_index_id,'ready',1,1,0) , - array($state_index_id,'failed',1,2,2) , - array($state_index_id,'online',1,3,1) , - array($state_index_id,'offline',1,4,2) , - array($state_index_id,'degraded',1,6,2) , - array($state_index_id,'verifying',1,7,1) , - array($state_index_id,'resynching',1,15,1) , - array($state_index_id,'regenerating',1,16,1) , - array($state_index_id,'failedRedundancy',1,18,2) , - array($state_index_id,'rebuilding',1,24,1) , - array($state_index_id,'formatting',1,26,1) , - array($state_index_id,'reconstructing',1,32,1) , - array($state_index_id,'initializing',1,35,1) , - array($state_index_id,'backgroundInit',1,36,1) , - array($state_index_id,'permanentlyDegraded',1,52,2) - ); + if ($state_index_id) { + $states = array( + array($state_index_id,'unknown',0,0,3) , + array($state_index_id,'ready',1,1,0) , + array($state_index_id,'failed',1,2,2) , + array($state_index_id,'online',1,3,1) , + array($state_index_id,'offline',1,4,2) , + array($state_index_id,'degraded',1,6,2) , + array($state_index_id,'verifying',1,7,1) , + array($state_index_id,'resynching',1,15,1) , + array($state_index_id,'regenerating',1,16,1) , + array($state_index_id,'failedRedundancy',1,18,2) , + array($state_index_id,'rebuilding',1,24,1) , + array($state_index_id,'formatting',1,26,1) , + array($state_index_id,'reconstructing',1,32,1) , + array($state_index_id,'initializing',1,35,1) , + array($state_index_id,'backgroundInit',1,36,1) , + array($state_index_id,'permanentlyDegraded',1,52,2) + ); - foreach($states as $value){ - $insert = array( - 'state_index_id' => $value[0], - 'state_descr' => $value[1], - 'state_draw_graph' => $value[2], - 'state_value' => $value[3], - 'state_generic_value' => $value[4] - ); - dbInsert($insert, 'state_translations'); - } - } - - foreach (explode("\n", $oids) as $data) { - list($oid,$name) = explode(' ', $data, 2); - $name = trim($name,"\""); - if($oid==$name_oid) continue; // Something goes wrong, we should have $name_oid.$num_index in $oid - $split_oid = explode('.', $oid); - $num_index = $split_oid[(count($split_oid) - 1)]; - $index = (int)$num_index+0; - $oid = $main_oid.$num_index; - $low_limit = 0.5; - $high_limit = 1.5; - - $state_current = snmp_get($device, $oid, '-Oevq'); - discover_sensor($valid['sensor'], 'state', $device, $oid, $index, $state_name, $name, '1', '1', $low_limit, $low_limit, $high_limit, $high_limit, $state_current,'snmp',$index); - create_sensor_to_state_index($device, $state_name, $index); + foreach ($states as $value) { + $insert = array( + 'state_index_id' => $value[0], + 'state_descr' => $value[1], + 'state_draw_graph' => $value[2], + 'state_value' => $value[3], + 'state_generic_value' => $value[4] + ); + dbInsert($insert, 'state_translations'); } } + + foreach (explode("\n", $oids) as $data) { + list($oid,$name) = explode(' ', $data, 2); + $name = trim($name, "\""); + if ($oid==$name_oid) { + continue; // Something goes wrong, we should have $name_oid.$num_index in $oid + } $split_oid = explode('.', $oid); + $num_index = $split_oid[(count($split_oid) - 1)]; + $index = (int)$num_index+0; + $oid = $main_oid.$num_index; + $low_limit = 0.5; + $high_limit = 1.5; + + $state_current = snmp_get($device, $oid, '-Oevq'); + discover_sensor($valid['sensor'], 'state', $device, $oid, $index, $state_name, $name, '1', '1', $low_limit, $low_limit, $high_limit, $high_limit, $state_current, 'snmp', $index); + create_sensor_to_state_index($device, $state_name, $index); + } +} diff --git a/includes/discovery/sensors/states/drac.inc.php b/includes/discovery/sensors/states/drac.inc.php index bbb96d2756..88572a23d7 100644 --- a/includes/discovery/sensors/states/drac.inc.php +++ b/includes/discovery/sensors/states/drac.inc.php @@ -11,7 +11,6 @@ */ if ($device['os'] == 'drac') { - $temp = snmpwalk_cache_multi_oid($device, 'virtualDiskTable', array(), 'IDRAC-MIB-SMIv2'); $cur_oid = '.1.3.6.1.4.1.674.10892.5.5.1.20.140.1.1.4.'; @@ -28,7 +27,7 @@ if ($device['os'] == 'drac') { array($state_index_id,'failed',0,3,2) , array($state_index_id,'degraded',0,4,1) ); - foreach($states as $value){ + foreach ($states as $value) { $insert = array( 'state_index_id' => $value[0], 'state_descr' => $value[1], diff --git a/includes/discovery/sensors/states/dsm.inc.php b/includes/discovery/sensors/states/dsm.inc.php index 7cdd92d5a9..4c0c002f9e 100644 --- a/includes/discovery/sensors/states/dsm.inc.php +++ b/includes/discovery/sensors/states/dsm.inc.php @@ -45,8 +45,7 @@ if ($device['os'] == 'dsm') { // Temp because only support INT if ((string) $ups_status == '"OL"') { $ups_status = 1; - } - else { + } else { $ups_status = 2; } diff --git a/includes/discovery/sensors/states/equallogic.inc.php b/includes/discovery/sensors/states/equallogic.inc.php index cc249d7141..95111b2e69 100644 --- a/includes/discovery/sensors/states/equallogic.inc.php +++ b/includes/discovery/sensors/states/equallogic.inc.php @@ -51,7 +51,7 @@ The LibreNMS generic states is derived from Nagios: array($state_index_id,'warning',1,2,1) , array($state_index_id,'critical',1,3,2) ); - foreach($states as $value){ + foreach ($states as $value) { $insert = array( 'state_index_id' => $value[0], 'state_descr' => $value[1], @@ -108,7 +108,7 @@ eqlMemberHealthDetailsPowerSupplyCurrentState array($state_index_id1,'no-ac-power',1,2,1) , array($state_index_id1,'failed-or-no-data',1,3,2) ); - foreach($states1 as $value){ + foreach ($states1 as $value) { $insert = array( 'state_index_id' => $value[0], 'state_descr' => $value[1], @@ -132,8 +132,8 @@ eqlMemberHealthDetailsPowerSupplyCurrentState $oid = $base_oid.$num_index; $extra = snmp_get_multi($device, $oid, '-OQne', 'EQLMEMBER-MIB', $config['install_dir'].'/mibs/equallogic'); d_echo($extra); - if(!empty($extra)) { - list($foid,$pstatus) = explode(' = ',$extra,2); + if (!empty($extra)) { + list($foid,$pstatus) = explode(' = ', $extra, 2); $index = (100 + $index); $low_limit = 0.5; $high_limit = 1.5; diff --git a/includes/discovery/sensors/states/hpblmos.inc.php b/includes/discovery/sensors/states/hpblmos.inc.php index 9ff40fe131..9ed2771b78 100644 --- a/includes/discovery/sensors/states/hpblmos.inc.php +++ b/includes/discovery/sensors/states/hpblmos.inc.php @@ -1,6 +1,5 @@ $value[0], 'state_descr' => $value[1], diff --git a/includes/discovery/sensors/states/ibm-amm.inc.php b/includes/discovery/sensors/states/ibm-amm.inc.php index bbed4a2a7a..37f851ce22 100644 --- a/includes/discovery/sensors/states/ibm-amm.inc.php +++ b/includes/discovery/sensors/states/ibm-amm.inc.php @@ -11,7 +11,6 @@ */ if ($device['os'] == 'ibm-amm') { - $index = 1; $state_name = 'ibm-amm_BlowerState'; $state_descr = 'Blower '; @@ -33,11 +32,9 @@ if ($device['os'] == 'ibm-amm') { $descr = $state_descr . $index; if (!empty($state)) { - $state_index_id = create_state_index($state_name); if ($state_index_id) { - $states = array( array($state_index_id, 'unknown', 0, 0, 3), array($state_index_id, 'good', 1, 1, 0), @@ -45,7 +42,7 @@ if ($device['os'] == 'ibm-amm') { array($state_index_id, 'bad', 1, 3, 2), ); - foreach($states as $value) { + foreach ($states as $value) { $insert = array( 'state_index_id' => $value[0], 'state_descr' => $value[1], @@ -55,16 +52,13 @@ if ($device['os'] == 'ibm-amm') { ); dbInsert($insert, 'state_translations'); }//end foreach - }//end if discover_sensor($valid['sensor'], 'state', $device, $oid, $index, $state_name, $descr, '1', '1', null, null, null, null, $state, 'snmp', $index); //Create Sensor To State Index create_sensor_to_state_index($device, $state_name, $index); $index++; - }//end if - }//end foreach $index = 1; @@ -89,11 +83,9 @@ if ($device['os'] == 'ibm-amm') { $descr = $state_descr . $index; if (is_numeric($state) && $state != 2) { - $state_index_id = create_state_index($state_name); if ($state_index_id) { - $states = array( array($state_index_id, 'operational', 1, 0, 0), array($state_index_id, 'flashing', 1, 1, 1), @@ -102,7 +94,7 @@ if ($device['os'] == 'ibm-amm') { array($state_index_id, 'unknown', 0, 255, 3), ); - foreach($states as $value) { + foreach ($states as $value) { $insert = array( 'state_index_id' => $value[0], 'state_descr' => $value[1], @@ -112,16 +104,13 @@ if ($device['os'] == 'ibm-amm') { ); dbInsert($insert, 'state_translations'); }//end foreach - }//end if discover_sensor($valid['sensor'], 'state', $device, $oid, $index, $state_name, $descr, '1', '1', null, null, null, null, $state, 'snmp', $index); //Create Sensor To State Index create_sensor_to_state_index($device, $state_name, $index); $index++; - }//end if - }//end foreach $index = 1; @@ -142,11 +131,9 @@ if ($device['os'] == 'ibm-amm') { $descr = $state_descr . $index; if (is_numeric($state) && $state != 3) { - $state_index_id = create_state_index($state_name); if ($state_index_id) { - $states = array( array($state_index_id, 'unknown', 0, 0, 3), array($state_index_id, 'good', 1, 1, 0), @@ -165,16 +152,29 @@ if ($device['os'] == 'ibm-amm') { ); dbInsert($insert, 'state_translations'); }//end foreach - }//end if - discover_sensor($valid['sensor'], 'state', $device, $oid, $index, $state_name, $descr, '1', '1', null, null, - null, null, $state, 'snmp', $index); + discover_sensor( + $valid['sensor'], + 'state', + $device, + $oid, + $index, + $state_name, + $descr, + '1', + '1', + null, + null, + null, + null, + $state, + 'snmp', + $index + ); //Create Sensor To State Index create_sensor_to_state_index($device, $state_name, $index); $index++; - }//end if }//end foreach - }//end if diff --git a/includes/discovery/sensors/states/ironware.inc.php b/includes/discovery/sensors/states/ironware.inc.php index 1b88b02551..a8bc27a686 100644 --- a/includes/discovery/sensors/states/ironware.inc.php +++ b/includes/discovery/sensors/states/ironware.inc.php @@ -11,7 +11,6 @@ */ if ($device['os'] == 'ironware') { - $temp = snmpwalk_cache_multi_oid($device, 'snChasPwrSupplyTable', array(), 'FOUNDRY-SN-AGENT-MIB'); $cur_oid = '.1.3.6.1.4.1.1991.1.1.1.2.1.1.3.'; @@ -27,7 +26,7 @@ if ($device['os'] == 'ironware') { array($state_index_id,'normal',0,2,0) , array($state_index_id,'failure',0,3,2) ); - foreach($states as $value){ + foreach ($states as $value) { $insert = array( 'state_index_id' => $value[0], 'state_descr' => $value[1], @@ -42,9 +41,9 @@ if ($device['os'] == 'ironware') { foreach ($temp as $index => $entry) { //Discover Sensors $descr = $temp[$index]['snChasPwrSupplyDescription']; - if (empty($descr)) { - $descr = "Power Supply " . $index; - } + if (empty($descr)) { + $descr = "Power Supply " . $index; + } discover_sensor($valid['sensor'], 'state', $device, $cur_oid.$index, $index, $state_name, $descr, '1', '1', null, null, null, null, $temp[$index]['snChasPwrSupplyOperStatus'], 'snmp', $index); //Create Sensor To State Index diff --git a/includes/discovery/sensors/states/juniper.inc.php b/includes/discovery/sensors/states/juniper.inc.php index f641196089..b759b6110d 100644 --- a/includes/discovery/sensors/states/juniper.inc.php +++ b/includes/discovery/sensors/states/juniper.inc.php @@ -11,14 +11,13 @@ */ if ($device['os'] == 'junos') { - $tables = array( array('JUNIPER-MIB','jnxFruTable','.1.3.6.1.4.1.2636.3.1.15.1.8.','jnxFruState','jnxFruName') , array('JUNIPER-ALARM-MIB','jnxYellowAlarms','.1.3.6.1.4.1.2636.3.4.2.2.1.0','jnxYellowAlarmState') , - array('JUNIPER-ALARM-MIB','jnxRedAlarms','.1.3.6.1.4.1.2636.3.4.2.3.1.0','jnxRedAlarmState') + array('JUNIPER-ALARM-MIB','jnxRedAlarms','.1.3.6.1.4.1.2636.3.4.2.3.1.0','jnxRedAlarmState') ); - foreach($tables as $tablevalue){ + foreach ($tables as $tablevalue) { $temp = snmpwalk_cache_multi_oid($device, $tablevalue[1], array(), $tablevalue[0], $config['install_dir'].'/mibs/junos'); $cur_oid = $tablevalue[2]; @@ -42,15 +41,14 @@ if ($device['os'] == 'junos') { array($state_index_id,'diagnostic',0,9,3) , array($state_index_id,'standby',0,10,3) ); - } - else { + } else { $states = array( array($state_index_id,'other',0,1,3) , array($state_index_id,'off',0,2,0) , array($state_index_id,'on',0,3,2) ); } - foreach($states as $value){ + foreach ($states as $value) { $insert = array( 'state_index_id' => $value[0], 'state_descr' => $value[1], @@ -72,10 +70,8 @@ if ($device['os'] == 'junos') { if ($tablevalue[3] == 'jnxRedAlarmState') { $descr = 'Red Alarm'; } - } if (stripos($descr, 'Yellow Alarm') !== false || stripos($descr, 'Red Alarm') !== false || stripos($descr, 'cb') !== false || stripos($descr, 'pem') !== false || stripos($descr, 'fan') !== false || stripos($descr, 'power') !== false || preg_match('/Routing Engine [0|1]/', $descr)) { - //Discover Sensors discover_sensor($valid['sensor'], 'state', $device, $oid, $index, $state_name, $descr, '1', '1', null, null, null, null, $temp[$index][$tablevalue[3]], 'snmp', $index); diff --git a/includes/discovery/sensors/states/linux.inc.php b/includes/discovery/sensors/states/linux.inc.php index d04c83ac9c..69e975fc7a 100644 --- a/includes/discovery/sensors/states/linux.inc.php +++ b/includes/discovery/sensors/states/linux.inc.php @@ -9,7 +9,7 @@ if (preg_match("/(bcm).+(boardrev)/", $raspberry)) { $state = "raspberry_codec"; $oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.'; for ($codec = 8; $codec < 14; $codec++) { - switch($codec) { + switch ($codec) { case "8": $descr = "H264 codec"; break; @@ -54,4 +54,4 @@ if (preg_match("/(bcm).+(boardrev)/", $raspberry)) { discover_sensor($valid['sensor'], 'state', $device, $oid.$codec, $codec, $state, $descr, '1', '1', null, null, null, null, $value, 'snmp', $codec); create_sensor_to_state_index($device, $state, $codec); } -} \ No newline at end of file +} diff --git a/includes/discovery/sensors/states/netonix.inc.php b/includes/discovery/sensors/states/netonix.inc.php index 093e43b5be..0d721c567e 100644 --- a/includes/discovery/sensors/states/netonix.inc.php +++ b/includes/discovery/sensors/states/netonix.inc.php @@ -11,7 +11,6 @@ */ if ($device['os'] == 'netonix') { - $temp = snmpwalk_cache_multi_oid($device, '.1.3.6.1.4.1.46242.5.1.2', array()); $cur_oid = '.1.3.6.1.4.1.'; @@ -33,7 +32,7 @@ if ($device['os'] == 'netonix') { array($state_index_id,'24V',0,2,0) , array($state_index_id,'48V',0,3,1) , ); - foreach($states as $value){ + foreach ($states as $value) { $insert = array( 'state_index_id' => $value[0], 'state_descr' => $value[1], diff --git a/includes/discovery/sensors/states/pcoweb.inc.php b/includes/discovery/sensors/states/pcoweb.inc.php index 0bc8a6f122..f31a15788c 100644 --- a/includes/discovery/sensors/states/pcoweb.inc.php +++ b/includes/discovery/sensors/states/pcoweb.inc.php @@ -18,7 +18,7 @@ if ($device['os'] == "pcoweb") { ".1.3.6.1.4.1.9839.2.1.1.3.0", #compressore3.0 ".1.3.6.1.4.1.9839.2.1.1.4.0" #compressore4.0 ); - foreach($compressors as $compressor_oid) { + foreach ($compressors as $compressor_oid) { $current = snmp_get($device, $compressor_oid, '-OqvU', 'CAREL-ug40cdz-MIB'); $split_oid = explode('.', $compressor_oid); $number = $split_oid[count($split_oid) - 2]; diff --git a/includes/discovery/sensors/states/serveriron.inc.php b/includes/discovery/sensors/states/serveriron.inc.php index 37b63d38fc..f50f45407d 100644 --- a/includes/discovery/sensors/states/serveriron.inc.php +++ b/includes/discovery/sensors/states/serveriron.inc.php @@ -7,20 +7,19 @@ if ($device['os'] == 'serveriron') { // Power Supplies for ($i=1; $i != 3; $i++) { - $power_oid = 'FOUNDRY-SN-AGENT-MIB::snChasPwrSupplyOperStatus.'.$i; - $power_status = snmp_get($device, $power_oid, '-Oqv','FOUNDRY-SN-AGENT-MIB'); - if(!empty($power_status)) { - discover_sensor($valid['sensor'], 'state', $device, $power_oid, 'powerstatus'.$i, 'snmp', 'Power Supply '.$i.' Status', '1', '1', '1', null, null, '3', $power_status); - } + $power_oid = 'FOUNDRY-SN-AGENT-MIB::snChasPwrSupplyOperStatus.'.$i; + $power_status = snmp_get($device, $power_oid, '-Oqv', 'FOUNDRY-SN-AGENT-MIB'); + if (!empty($power_status)) { + discover_sensor($valid['sensor'], 'state', $device, $power_oid, 'powerstatus'.$i, 'snmp', 'Power Supply '.$i.' Status', '1', '1', '1', null, null, '3', $power_status); + } } // Fan status for ($i=1; $i != 7; $i++) { - $fan_oid = 'FOUNDRY-SN-AGENT-MIB::snChasFanOperStatus.'.$i; - $fan_status = snmp_get($device, $fan_oid, '-Oqv','FOUNDRY-SN-AGENT-MIB'); - if(!empty($fan_status)) { - discover_sensor($valid['sensor'], 'state', $device, $fan_oid, 'fanstatus'.$i, 'snmp', 'Fan '.$i.' Status', '1', '1', '1', null, null, '3', $fan_status); - } + $fan_oid = 'FOUNDRY-SN-AGENT-MIB::snChasFanOperStatus.'.$i; + $fan_status = snmp_get($device, $fan_oid, '-Oqv', 'FOUNDRY-SN-AGENT-MIB'); + if (!empty($fan_status)) { + discover_sensor($valid['sensor'], 'state', $device, $fan_oid, 'fanstatus'.$i, 'snmp', 'Fan '.$i.' Status', '1', '1', '1', null, null, '3', $fan_status); + } } - }//end if diff --git a/includes/discovery/sensors/states/waas.inc.php b/includes/discovery/sensors/states/waas.inc.php index c481713d65..ec72be82ab 100644 --- a/includes/discovery/sensors/states/waas.inc.php +++ b/includes/discovery/sensors/states/waas.inc.php @@ -11,7 +11,6 @@ */ if ($device['os_group'] == 'cisco' && $device['os'] == 'waas') { - $temp = snmp_get($device, "cwoTfoStatsLoadStatus.0", "-Ovqe", "CISCO-WAN-OPTIMIZATION-MIB"); $cur_oid = '.1.3.6.1.4.1.9.9.762.1.2.1.13.0'; $index = '0'; @@ -29,7 +28,7 @@ if ($device['os_group'] == 'cisco' && $device['os'] == 'waas') { array($state_index_id,'yellow',0,3,1) , array($state_index_id,'red',0,4,2) ); - foreach($states as $value){ + foreach ($states as $value) { $insert = array( 'state_index_id' => $value[0], 'state_descr' => $value[1], diff --git a/includes/discovery/sensors/temperatures/akcp.inc.php b/includes/discovery/sensors/temperatures/akcp.inc.php index b60e9ab878..b806a2d2ab 100644 --- a/includes/discovery/sensors/temperatures/akcp.inc.php +++ b/includes/discovery/sensors/temperatures/akcp.inc.php @@ -15,7 +15,7 @@ if ($device['os'] == 'akcp' || $device['os'] == 'minkelsrms') { list($oid,$status) = explode(' ', $data, 2); if ($status == 2) { // 2 = normal, 0 = not connected - $split_oid = explode('.', $oid); + $split_oid = explode('.', $oid); $temperature_id = $split_oid[(count($split_oid) - 1)]; $descr_oid = ".1.3.6.1.4.1.3854.1.2.2.1.16.1.1.$temperature_id"; $temperature_oid = ".1.3.6.1.4.1.3854.1.2.2.1.16.1.3.$temperature_id"; diff --git a/includes/discovery/sensors/temperatures/aos-device.inc.php b/includes/discovery/sensors/temperatures/aos-device.inc.php index b386c0823c..c8b5065a76 100644 --- a/includes/discovery/sensors/temperatures/aos-device.inc.php +++ b/includes/discovery/sensors/temperatures/aos-device.inc.php @@ -8,8 +8,21 @@ if ($device['os'] == 'aos') { if ($descr != '' && is_numeric($temperature) && $temperature > '0') { $temperature_oid = '.1.3.6.1.4.1.18248.1.1.1.0'; - discover_sensor($valid['sensor'], 'temperature', $device, - '.1.3.6.1.4.1.6486.800.1.2.1.16.1.1.1.17.0', '1', 'alcatel-device', - $descr, '1', '1', null, null, null, null, $temperature); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + '.1.3.6.1.4.1.6486.800.1.2.1.16.1.1.1.17.0', + '1', + 'alcatel-device', + $descr, + '1', + '1', + null, + null, + null, + null, + $temperature + ); } } diff --git a/includes/discovery/sensors/temperatures/apc.inc.php b/includes/discovery/sensors/temperatures/apc.inc.php index 4c7d53cc91..b842f46588 100644 --- a/includes/discovery/sensors/temperatures/apc.inc.php +++ b/includes/discovery/sensors/temperatures/apc.inc.php @@ -89,8 +89,7 @@ if ($device['os'] == 'apc') { list(, $set_point_raw) = explode(' ', $set_oids); $set_point = ($set_point_raw / $precision); $descr = 'Supply Temp - Setpoint: '.$set_point.'°C'; - } - else { + } else { $descr = 'Supply Temperature'; } @@ -112,8 +111,7 @@ if ($device['os'] == 'apc') { list(, $set_point_raw) = explode(' ', $set_oids); $set_point = ($set_point_raw / $precision); $descr = 'Return Temp - Setpoint: '.$set_point.'°C'; - } - else { + } else { $descr = 'Return Temperature'; } @@ -134,8 +132,7 @@ if ($device['os'] == 'apc') { list(, $set_point_raw) = explode(' ', $set_oids); $set_point = ($set_point_raw / $precision); $descr = 'Remote Temp - Setpoint: '.$set_point.'°C'; - } - else { + } else { $descr = 'Remote Temperature'; } diff --git a/includes/discovery/sensors/temperatures/areca.inc.php b/includes/discovery/sensors/temperatures/areca.inc.php index a286ad62fb..f13b2a04dd 100644 --- a/includes/discovery/sensors/temperatures/areca.inc.php +++ b/includes/discovery/sensors/temperatures/areca.inc.php @@ -19,9 +19,22 @@ if ($device['os'] == 'areca') { $temperature = snmp_get($device, $temperature_oid, '-Oqv', ''); $descr = "Hard disk $temperature_id"; if ($temperature != -128) { // -128 = not measured/present - discover_sensor($valid['sensor'], 'temperature', $device, $temperature_oid, - zeropad($temperature_id), 'areca', - $descr, '1', '1', null, null, null, null, $temperature); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + $temperature_oid, + zeropad($temperature_id), + 'areca', + $descr, + '1', + '1', + null, + null, + null, + null, + $temperature + ); } } } @@ -44,9 +57,22 @@ if ($device['os'] == 'areca') { $oid = '1.3.6.1.4.1.18928.1.2.2.1.10.1.3.'.$index; $current = snmp_get($device, $oid, '-Oqv', ''); - discover_sensor($valid['sensor'], 'temperature', $device, $oid, - $index, 'areca', - trim($descr, '"'), '1', '1', null, null, null, null, $current); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + $oid, + $index, + 'areca', + trim($descr, '"'), + '1', + '1', + null, + null, + null, + null, + $current + ); } } } diff --git a/includes/discovery/sensors/temperatures/avaya-ers.inc.php b/includes/discovery/sensors/temperatures/avaya-ers.inc.php index 9e066f01d0..ec0e58e0e9 100644 --- a/includes/discovery/sensors/temperatures/avaya-ers.inc.php +++ b/includes/discovery/sensors/temperatures/avaya-ers.inc.php @@ -16,9 +16,22 @@ if ($device['os'] == 'avaya-ers') { $val = $t[1]; // Sensors are reported as 2 * value $val = (trim($val) / 2); - discover_sensor($valid['sensor'], 'temperature', $device, - $oid, zeropad($i + 1), 'avaya-ers', - 'Unit '.($i + 1).' temperature', '2', '1', null, null, null, null, $val); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + $oid, + zeropad($i + 1), + 'avaya-ers', + 'Unit '.($i + 1).' temperature', + '2', + '1', + null, + null, + null, + null, + $val + ); } } } diff --git a/includes/discovery/sensors/temperatures/avtech.inc.php b/includes/discovery/sensors/temperatures/avtech.inc.php index da082cff72..125346fe29 100644 --- a/includes/discovery/sensors/temperatures/avtech.inc.php +++ b/includes/discovery/sensors/temperatures/avtech.inc.php @@ -27,8 +27,7 @@ if ($device['os'] == 'avtech') { 'descr_oid' => $device_oid.'1.2.2.3.0', ); avtech_add_sensor($device, $sen2); - } - elseif (strpos($device['sysObjectID'], '.20916.1.9') !== false) { + } elseif (strpos($device['sysObjectID'], '.20916.1.9') !== false) { // RoomAlert 3E $device_oid = '.1.3.6.1.4.1.20916.1.9.'; @@ -45,8 +44,7 @@ if ($device['os'] == 'avtech') { 'descr_oid' => $device_oid.'1.1.2.6.0', ); avtech_add_sensor($device, $sen1); - } - elseif (strpos($device['sysObjectID'], '.20916.1.1') !== false) { + } elseif (strpos($device['sysObjectID'], '.20916.1.1') !== false) { // TemPageR 4E $device_oid = '.1.3.6.1.4.1.20916.1.1.'; @@ -85,8 +83,7 @@ if ($device['os'] == 'avtech') { 'min_oid' => $device_oid.'3.8.0', ); avtech_add_sensor($device, $sen3); - } - elseif (strpos($device['sysObjectID'], '.20916.1.6') !== false) { + } elseif (strpos($device['sysObjectID'], '.20916.1.6') !== false) { // RoomAlert 4E $device_oid = '.1.3.6.1.4.1.20916.1.6.'; $divisor = 1; diff --git a/includes/discovery/sensors/temperatures/binos.inc.php b/includes/discovery/sensors/temperatures/binos.inc.php index 2d4196e1be..2aa8c1c108 100644 --- a/includes/discovery/sensors/temperatures/binos.inc.php +++ b/includes/discovery/sensors/temperatures/binos.inc.php @@ -15,7 +15,6 @@ if ($device['os'] == 'binos') { if (strpos($device['sysObjectID'], 'enterprises.738.1.5.100') !== false) { - echo("Telco Systems:"); // CPU temperature diff --git a/includes/discovery/sensors/temperatures/binox.inc.php b/includes/discovery/sensors/temperatures/binox.inc.php index e5a122dbd4..735f24b191 100644 --- a/includes/discovery/sensors/temperatures/binox.inc.php +++ b/includes/discovery/sensors/temperatures/binox.inc.php @@ -31,6 +31,6 @@ if ($device['os'] == 'binox') { if (is_numeric($value)) { discover_sensor($valid['sensor'], 'temperature', $device, $valueoid, 1, 'binox', $descr, '1', '1', $low_limit, $low_warn_limit, $high_warn_limit, $high_limit, $value); - } + } } } diff --git a/includes/discovery/sensors/temperatures/cambium.inc.php b/includes/discovery/sensors/temperatures/cambium.inc.php index 335bd04aa3..a9795de84f 100644 --- a/includes/discovery/sensors/temperatures/cambium.inc.php +++ b/includes/discovery/sensors/temperatures/cambium.inc.php @@ -5,17 +5,16 @@ if ($device['os'] == 'cambium') { $oids = trim(str_replace('"', '', snmp_get($device, "$oid", '-OsqnU', 'WHISP-BOX-MIBV2-MIB'))); d_echo($oids."\n"); - if (!empty($oids)) { - echo 'Cambium Temperature '; - } + if (!empty($oids)) { + echo 'Cambium Temperature '; + } $divisor = 1; $type = 'cambium'; - if (!empty($oids)) { - list(,$current) = explode(' ', $oids); - $index = $oid; - $descr = 'System Temp'; - discover_sensor($valid['sensor'], 'temperature', $device, $oid, $index, $type, $descr, $divisor, '1', null, null, null, null, $current); - } - + if (!empty($oids)) { + list(,$current) = explode(' ', $oids); + $index = $oid; + $descr = 'System Temp'; + discover_sensor($valid['sensor'], 'temperature', $device, $oid, $index, $type, $descr, $divisor, '1', null, null, null, null, $current); + } } diff --git a/includes/discovery/sensors/temperatures/canopy.inc.php b/includes/discovery/sensors/temperatures/canopy.inc.php index 7acf089c73..e40ce51788 100644 --- a/includes/discovery/sensors/temperatures/canopy.inc.php +++ b/includes/discovery/sensors/temperatures/canopy.inc.php @@ -5,16 +5,16 @@ if ($device['os'] == 'canopy') { $oids = trim(str_replace('"', '', snmp_get($device, "$oid", '-OsqnU', 'WHISP-BOX-MIBV2-MIB'))); d_echo($oids."\n"); - if (!empty($oids)) { - echo 'Canopy Temperature '; - } + if (!empty($oids)) { + echo 'Canopy Temperature '; + } $divisor = 1; $type = 'canopy'; - if (!empty($oids)) { - list(,$current) = explode(' ', $oids); - $index = $oid; - $descr = 'System Temp'; - discover_sensor($valid['sensor'], 'temperature', $device, $oid, $index, $type, $descr, $divisor, '1', -30, null, null, 50, $current); - } -} \ No newline at end of file + if (!empty($oids)) { + list(,$current) = explode(' ', $oids); + $index = $oid; + $descr = 'System Temp'; + discover_sensor($valid['sensor'], 'temperature', $device, $oid, $index, $type, $descr, $divisor, '1', -30, null, null, 50, $current); + } +} diff --git a/includes/discovery/sensors/temperatures/cometsystem-p85xx.inc.php b/includes/discovery/sensors/temperatures/cometsystem-p85xx.inc.php index 28e8f09085..1fc04ad0b9 100644 --- a/includes/discovery/sensors/temperatures/cometsystem-p85xx.inc.php +++ b/includes/discovery/sensors/temperatures/cometsystem-p85xx.inc.php @@ -44,9 +44,22 @@ if ($device['os'] == 'cometsystem-p85xx') { $limit = trim($sensor['limit_high'], ' "'); $temperature = $sensor['temp_intval']; - discover_sensor($valid['sensor'], 'temperature', $device, - $temperature_oid, $temperature_id, 'cometsystem-p85xx', - $descr, '10', '1', $lowlimit, null, null, $limit, $temperature); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + $temperature_oid, + $temperature_id, + 'cometsystem-p85xx', + $descr, + '10', + '1', + $lowlimit, + null, + null, + $limit, + $temperature + ); } } } diff --git a/includes/discovery/sensors/temperatures/comware.inc.php b/includes/discovery/sensors/temperatures/comware.inc.php index dbb7f0a059..8401025f11 100644 --- a/includes/discovery/sensors/temperatures/comware.inc.php +++ b/includes/discovery/sensors/temperatures/comware.inc.php @@ -18,7 +18,6 @@ if ($device['os'] == 'comware') { )); if (!empty($entphydata)) { - $tempdata = snmpwalk_cache_multi_oid($device, 'hh3cEntityExtTemperature', array(), 'HH3C-ENTITY-EXT-MIB'); foreach ($entphydata as $index) { @@ -28,7 +27,6 @@ if ($device['os'] == 'comware') { discover_sensor($valid['sensor'], 'temperature', $device, $cur_oid . $tempindex, 'temp-' . $tempindex, 'comware', $index['entPhysicalName'], '1', '1', null, null, null, null, $value['hh3cEntityExtTemperature'], 'snmp', $index); } } - } } diff --git a/includes/discovery/sensors/temperatures/dell.inc.php b/includes/discovery/sensors/temperatures/dell.inc.php index dcf6a3b9cb..c71178882c 100644 --- a/includes/discovery/sensors/temperatures/dell.inc.php +++ b/includes/discovery/sensors/temperatures/dell.inc.php @@ -35,7 +35,7 @@ if (strstr($device['hardware'], 'Dell')) { } foreach (explode("\n", $oids) as $data) { - $data = trim($data); + $data = trim($data); if ($data) { list($oid,$status) = explode(' ', $data, 2); d_echo('status : '.$status."\n"); diff --git a/includes/discovery/sensors/temperatures/dnos.inc.php b/includes/discovery/sensors/temperatures/dnos.inc.php index 827e42056b..bab0eaec1c 100644 --- a/includes/discovery/sensors/temperatures/dnos.inc.php +++ b/includes/discovery/sensors/temperatures/dnos.inc.php @@ -1,22 +1,36 @@ $t) { - $t = explode(' ',$t); + $t = explode(' ', $t); $oid = $t[0]; $val = $t[1]; if (substr($oid, -1) == '1') { // This code will only pull CPU temp for each stack member, but there is no reason why the additional values couldn't be graphed $counter = $counter + 1; - discover_sensor($valid['sensor'], 'temperature', $device, $oid, $counter, 'dnos', - 'Unit '.$counter.' CPU temperature', '1', '1', null, null, null, null, $val); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + $oid, + $counter, + 'dnos', + 'Unit '.$counter.' CPU temperature', + '1', + '1', + null, + null, + null, + null, + $val + ); } } } diff --git a/includes/discovery/sensors/temperatures/extreme.inc.php b/includes/discovery/sensors/temperatures/extreme.inc.php index ae1cf86b19..11dc0e56cc 100644 --- a/includes/discovery/sensors/temperatures/extreme.inc.php +++ b/includes/discovery/sensors/temperatures/extreme.inc.php @@ -4,10 +4,10 @@ if ($device['os'] == 'xos') { echo(" EXTREME-BASE-MIB "); // Chassis temperature - $high_limit = 65; - $high_warn_limit = 55; - $low_warn_limit = 15; - $low_limit = 5; + $high_limit = 65; + $high_warn_limit = 55; + $low_warn_limit = 15; + $low_limit = 5; $descr = "Chassis Temperature"; $oid = "1.3.6.1.4.1.1916.1.1.1.8.0"; // extremeCurrentTemperature diff --git a/includes/discovery/sensors/temperatures/hpblmos.inc.php b/includes/discovery/sensors/temperatures/hpblmos.inc.php index e5c74fd2b4..f598d6e325 100644 --- a/includes/discovery/sensors/temperatures/hpblmos.inc.php +++ b/includes/discovery/sensors/temperatures/hpblmos.inc.php @@ -1,6 +1,5 @@ 0) { discover_sensor($valid['sensor'], 'temperature', $device, $sensor_oid, 1, $sensor_type, $descr, 1, 1, null, null, null, null, $value); } -} \ No newline at end of file +} diff --git a/includes/discovery/sensors/temperatures/lm-sensors.inc.php b/includes/discovery/sensors/temperatures/lm-sensors.inc.php index 61e40adcc5..775e06a30a 100644 --- a/includes/discovery/sensors/temperatures/lm-sensors.inc.php +++ b/includes/discovery/sensors/temperatures/lm-sensors.inc.php @@ -21,9 +21,22 @@ if ($device['os'] == 'linux' || $device['os'] == 'pktj' || $device['os'] == 'cum $descr = str_ireplace('temp-', '', $descr); $descr = trim($descr); if ($temperature != '0' && $temperature <= '1000') { - discover_sensor($valid['sensor'], 'temperature', $device, - $temperature_oid, $temperature_id, 'lmsensors', - $descr, '1000', '1', null, null, null, null, $temperature); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + $temperature_oid, + $temperature_id, + 'lmsensors', + $descr, + '1000', + '1', + null, + null, + null, + null, + $temperature + ); } } } diff --git a/includes/discovery/sensors/temperatures/netapp.inc.php b/includes/discovery/sensors/temperatures/netapp.inc.php index bf488db9f5..989e17bcde 100644 --- a/includes/discovery/sensors/temperatures/netapp.inc.php +++ b/includes/discovery/sensors/temperatures/netapp.inc.php @@ -8,7 +8,7 @@ if ($device['os'] == "netapp") { if ($oids) { echo "NetApp "; foreach (explode("\n", $oids) as $data) { - list($oid,$descr) = explode(" ", $data,2); + list($oid,$descr) = explode(" ", $data, 2); $split_oid = explode('.', $oid); $temperature_id = $split_oid[count($split_oid)-1]; $x=1; @@ -19,10 +19,10 @@ if ($device['os'] == "netapp") { preg_match_all("/([0-9]+C)+/", snmp_get($device, $main_oid.'.29.'.$temperature_id, "-Ovq"), $under_warn); $x = 0; foreach ($temps[0] as $temperature) { - $low_limit = str_replace("C","",$under_fail[0][$x]); - $low_warn_limit = str_replace("C","",$under_warn[0][$x]); - $warn_limit = str_replace("C","",$over_warn[0][$x]); - $high_limit = str_replace("C","",$over_fail[0][$x]); + $low_limit = str_replace("C", "", $under_fail[0][$x]); + $low_warn_limit = str_replace("C", "", $under_warn[0][$x]); + $warn_limit = str_replace("C", "", $over_warn[0][$x]); + $high_limit = str_replace("C", "", $over_fail[0][$x]); $temperature_oid = $main_oid . ".25." . $temperature_id; $temp_id = $temperature_id . "." . $x; $descr = "Temp Sensor"; diff --git a/includes/discovery/sensors/temperatures/netbotz.inc.php b/includes/discovery/sensors/temperatures/netbotz.inc.php index a6c94320d1..a3bdbd7e54 100644 --- a/includes/discovery/sensors/temperatures/netbotz.inc.php +++ b/includes/discovery/sensors/temperatures/netbotz.inc.php @@ -17,9 +17,22 @@ if ($device['os'] == 'netbotz') { $descr = preg_replace('/Temperature /', '', $descr); $descr = trim($descr); if ($temperature != '0' && $temperature <= '1000') { - discover_sensor($valid['sensor'], 'temperature', $device, - $temperature_oid, $temperature_id, 'netbotz', - $descr, '1', '1', null, null, null, null, $temperature); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + $temperature_oid, + $temperature_id, + 'netbotz', + $descr, + '1', + '1', + null, + null, + null, + null, + $temperature + ); } } } diff --git a/includes/discovery/sensors/temperatures/nos.inc.php b/includes/discovery/sensors/temperatures/nos.inc.php index ae2cb8571c..0203f36f37 100644 --- a/includes/discovery/sensors/temperatures/nos.inc.php +++ b/includes/discovery/sensors/temperatures/nos.inc.php @@ -16,12 +16,12 @@ if ($device['os'] == "nos") { $oids = trim($oids); foreach (explode("\n", $oids) as $data) { $data = trim($data); - if ($data AND $data[37] == "1") { + if ($data and $data[37] == "1") { $value_oid = ".1.3.6.1.4.1.1588.2.1.1.1.1.22.1.4.".$data[35]; $descr_oid = ".1.3.6.1.4.1.1588.2.1.1.1.1.22.1.5.".$data[35]; $value = snmp_get($device, $value_oid, '-Oqv'); $descr = snmp_get($device, $descr_oid, '-Oqv'); - if (!strstr($descr, 'No') AND !strstr($value, 'No')) { + if (!strstr($descr, 'No') and !strstr($value, 'No')) { $descr = str_replace('"', '', $descr); $descr = trim($descr); discover_sensor($valid['sensor'], 'temperature', $device, $value_oid, $data[35], 'nos', $descr, '1', '1', null, null, '80', '100', $value); diff --git a/includes/discovery/sensors/temperatures/papouch-tme.inc.php b/includes/discovery/sensors/temperatures/papouch-tme.inc.php index adb126861b..2bef68ef54 100644 --- a/includes/discovery/sensors/temperatures/papouch-tme.inc.php +++ b/includes/discovery/sensors/temperatures/papouch-tme.inc.php @@ -9,8 +9,21 @@ if ($device['os'] == 'papouch-tme') { if ($descr != '' && is_numeric($temperature) && $temperature > '0') { $temperature_oid = '.1.3.6.1.4.1.18248.1.1.1.0'; $descr = trim(str_replace('"', '', $descr)); - discover_sensor($valid['sensor'], 'temperature', $device, - $temperature_oid, '1', 'papouch-tme', - $descr, '10', '1', null, null, null, null, $temperature); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + $temperature_oid, + '1', + 'papouch-tme', + $descr, + '10', + '1', + null, + null, + null, + null, + $temperature + ); } } diff --git a/includes/discovery/sensors/temperatures/pbn.inc.php b/includes/discovery/sensors/temperatures/pbn.inc.php index 6e2fe68a0f..965b61ad1c 100644 --- a/includes/discovery/sensors/temperatures/pbn.inc.php +++ b/includes/discovery/sensors/temperatures/pbn.inc.php @@ -27,7 +27,5 @@ if ($device['os'] == 'pbn' || $device['os_group'] == 'pbn') { $entPhysicalIndex_measured = 'ports'; discover_sensor($valid['sensor'], 'temperature', $device, $oid, ''.$index, 'pbn', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $value, 'snmp', $entPhysicalIndex, $entPhysicalIndex_measured); } - } - } diff --git a/includes/discovery/sensors/temperatures/powerconnect.inc.php b/includes/discovery/sensors/temperatures/powerconnect.inc.php index 46d334f39a..6cf50a5251 100644 --- a/includes/discovery/sensors/temperatures/powerconnect.inc.php +++ b/includes/discovery/sensors/temperatures/powerconnect.inc.php @@ -7,33 +7,33 @@ if ($device['os'] == 'powerconnect') { * Operating Temperature: 0º C to 45º C */ case '.1.3.6.1.4.1.674.10895.3031': - $temperature = trim(snmp_get($device, '.1.3.6.1.4.1.89.53.15.1.9.1', '-Ovq')); - discover_sensor($valid['sensor'], 'temperature', $device, '.1.3.6.1.4.1.89.53.15.1.9.1', 0, 'powerconnect', 'Internal Temperature', '1', '1', '0', null, null, '45', $temperature); - break; + $temperature = trim(snmp_get($device, '.1.3.6.1.4.1.89.53.15.1.9.1', '-Ovq')); + discover_sensor($valid['sensor'], 'temperature', $device, '.1.3.6.1.4.1.89.53.15.1.9.1', 0, 'powerconnect', 'Internal Temperature', '1', '1', '0', null, null, '45', $temperature); + break; /** * Dell Powerconnect 3548 * Operating Temperature: 0º C to 45º C */ case '.1.3.6.1.4.1.674.10895.3017': - $temperature = trim(snmp_get($device, ".1.3.6.1.4.1.89.53.15.1.9.1", "-Ovq")); - discover_sensor($valid['sensor'], 'temperature', $device, '.1.3.6.1.4.1.89.53.15.1.9.1', 0, 'powerconnect', 'Internal Temperature', '1', '1', '0', null, null, '45', $temperature); - break; + $temperature = trim(snmp_get($device, ".1.3.6.1.4.1.89.53.15.1.9.1", "-Ovq")); + discover_sensor($valid['sensor'], 'temperature', $device, '.1.3.6.1.4.1.89.53.15.1.9.1', 0, 'powerconnect', 'Internal Temperature', '1', '1', '0', null, null, '45', $temperature); + break; /** * Dell Powerconnect 3548P * Operating Temperature: 0º C to 45º C */ case '.1.3.6.1.4.1.674.10895.3019': - $temperature = trim(snmp_get($device, ".1.3.6.1.4.1.89.53.15.1.9.1", "-Ovq")); - discover_sensor($valid['sensor'], 'temperature', $device, '.1.3.6.1.4.1.89.53.15.1.9.1', 0, 'powerconnect', 'Internal Temperature', '1', '1', '0', null, null, '45', $temperature); - break; - default : + $temperature = trim(snmp_get($device, ".1.3.6.1.4.1.89.53.15.1.9.1", "-Ovq")); + discover_sensor($valid['sensor'], 'temperature', $device, '.1.3.6.1.4.1.89.53.15.1.9.1', 0, 'powerconnect', 'Internal Temperature', '1', '1', '0', null, null, '45', $temperature); + break; + default: /** * Default Temperature Discovery * Operating Temperature: 0º C to 45º C */ - $temperature = snmp_get($device, 'boxServicesTempSensorTemperature.0', '-Ovq','FASTPATH-BOXSERVICES-PRIVATE-MIB'); - if (is_numeric($temperature)) { - discover_sensor($valid['sensor'], 'temperature', $device, '.1.3.6.1.4.1.674.10895.5000.2.6132.1.1.43.1.8.1.4.0', 0, 'powerconnect', 'Internal Temperature', '1', '1', '0', null, null, '45', $temperature); - } + $temperature = snmp_get($device, 'boxServicesTempSensorTemperature.0', '-Ovq', 'FASTPATH-BOXSERVICES-PRIVATE-MIB'); + if (is_numeric($temperature)) { + discover_sensor($valid['sensor'], 'temperature', $device, '.1.3.6.1.4.1.674.10895.5000.2.6132.1.1.43.1.8.1.4.0', 0, 'powerconnect', 'Internal Temperature', '1', '1', '0', null, null, '45', $temperature); + } }//end switch }//end if diff --git a/includes/discovery/sensors/temperatures/sentry3.inc.php b/includes/discovery/sensors/temperatures/sentry3.inc.php index 40f57e9c76..c955e8250c 100644 --- a/includes/discovery/sensors/temperatures/sentry3.inc.php +++ b/includes/discovery/sensors/temperatures/sentry3.inc.php @@ -28,10 +28,22 @@ if ($device['os'] == 'sentry3') { $current = (snmp_get($device, "$temperature_oid", '-Ovq', 'Sentry3-MIB') / $divisor); if ($current >= 0) { - discover_sensor($valid['sensor'], 'temperature', $device, - $temperature_oid, $index, 'sentry3', - $descr, $divisor, $multiplier, $low_limit, $low_warn_limit, - $high_warn_limit, $high_limit, $current); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + $temperature_oid, + $index, + 'sentry3', + $descr, + $divisor, + $multiplier, + $low_limit, + $low_warn_limit, + $high_warn_limit, + $high_limit, + $current + ); } } } diff --git a/includes/discovery/sensors/temperatures/sentry4.inc.php b/includes/discovery/sensors/temperatures/sentry4.inc.php index 93b09940cd..9f6758fb3d 100644 --- a/includes/discovery/sensors/temperatures/sentry4.inc.php +++ b/includes/discovery/sensors/temperatures/sentry4.inc.php @@ -44,10 +44,22 @@ if ($device['os'] == 'sentry4') { $current = (snmp_get($device, "$temperature_oid", '-Ovq', 'Sentry4-MIB') / $divisor); if ($current >= 0) { - discover_sensor($valid['sensor'], 'temperature', $device, - $temperature_oid, $index, 'sentry4', - $descr, $divisor, $multiplier, $low_limit, $low_warn_limit, - $high_warn_limit, $high_limit, $current); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + $temperature_oid, + $index, + 'sentry4', + $descr, + $divisor, + $multiplier, + $low_limit, + $low_warn_limit, + $high_warn_limit, + $high_limit, + $current + ); } } } diff --git a/includes/discovery/sensors/temperatures/sub10.inc.php b/includes/discovery/sensors/temperatures/sub10.inc.php index e826ae2224..b50c970741 100644 --- a/includes/discovery/sensors/temperatures/sub10.inc.php +++ b/includes/discovery/sensors/temperatures/sub10.inc.php @@ -26,8 +26,20 @@ if ($device['os'] == 'sub10') { } // Create Sensor - discover_sensor($valid['sensor'], 'temperature', $device, $oid, $oid, - 'sub10', 'Modem', '1', '1', $thresholds[$indexes['low']], - null, null, $thresholds[$indexes['high']], - $current); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + $oid, + $oid, + 'sub10', + 'Modem', + '1', + '1', + $thresholds[$indexes['low']], + null, + null, + $thresholds[$indexes['high']], + $current + ); } diff --git a/includes/discovery/sensors/temperatures/supermicro.inc.php b/includes/discovery/sensors/temperatures/supermicro.inc.php index 9bb5a677e9..6ce53a3f51 100644 --- a/includes/discovery/sensors/temperatures/supermicro.inc.php +++ b/includes/discovery/sensors/temperatures/supermicro.inc.php @@ -27,9 +27,22 @@ if ($device['os'] == 'linux') { $monitor = snmp_get($device, $monitor_oid, '-Oqv', 'SUPERMICRO-HEALTH-MIB'); if ($monitor == 'true') { $descr = trim(str_ireplace('temperature', '', $descr)); - discover_sensor($valid['sensor'], 'temperature', $device, - $temperature_oid, trim($index, '.'), 'supermicro', - $descr, $divisor, '1', null, null, null, $limit, $temperature); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + $temperature_oid, + trim($index, '.'), + 'supermicro', + $descr, + $divisor, + '1', + null, + null, + null, + $limit, + $temperature + ); } } } diff --git a/includes/discovery/sensors/temperatures/xups.inc.php b/includes/discovery/sensors/temperatures/xups.inc.php index 5221994bfa..4a0b51a039 100644 --- a/includes/discovery/sensors/temperatures/xups.inc.php +++ b/includes/discovery/sensors/temperatures/xups.inc.php @@ -24,9 +24,22 @@ if ($device['os'] == 'powerware') { $temperature = snmp_get($device, $temperature_oid, '-Ovq'); $descr = 'Ambient'.(count(explode("\n", $oids)) == 1 ? '' : ' '.($temperature_id + 1)); - discover_sensor($valid['sensor'], 'temperature', $device, - $temperature_oid, '1.6.1.'.$temperature_id, 'powerware', - $descr, '1', '1', $lowlimit, null, null, $highlimit, $temperature); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + $temperature_oid, + '1.6.1.'.$temperature_id, + 'powerware', + $descr, + '1', + '1', + $lowlimit, + null, + null, + $highlimit, + $temperature + ); } } } diff --git a/includes/discovery/sensors/temperatures/zyxel-ies.inc.php b/includes/discovery/sensors/temperatures/zyxel-ies.inc.php index 09f4c72971..4bcc54cebc 100644 --- a/includes/discovery/sensors/temperatures/zyxel-ies.inc.php +++ b/includes/discovery/sensors/temperatures/zyxel-ies.inc.php @@ -15,9 +15,22 @@ if ($device['os'] == 'ies') { $oid = '.1.3.6.1.4.1.890.1.5.1.1.6.1.2.'.$index; $current = $entry['accessSwitchSysTempCurValue']; $divisor = '1'; - discover_sensor($valid['sensor'], 'temperature', $device, - $oid, $index, 'zyxel-ies', - $descr, '1', '1', null, $entry['accessSwitchSysTempHighThresh'], null, null, $current); + discover_sensor( + $valid['sensor'], + 'temperature', + $device, + $oid, + $index, + 'zyxel-ies', + $descr, + '1', + '1', + null, + $entry['accessSwitchSysTempHighThresh'], + null, + null, + $current + ); } } } diff --git a/includes/discovery/sensors/voltages/drac.inc.php b/includes/discovery/sensors/voltages/drac.inc.php index f009a74cb8..6637845874 100644 --- a/includes/discovery/sensors/voltages/drac.inc.php +++ b/includes/discovery/sensors/voltages/drac.inc.php @@ -11,17 +11,17 @@ if ($device['os'] == "drac") { $data = trim($data); if ($data) { list($oid,$kind) = explode(" ", $data); - $split_oid = explode('.',$oid); + $split_oid = explode('.', $oid); $index = $split_oid[count($split_oid)-1]; $voltage_oid = ".1.3.6.1.4.1.674.10892.5.4.600.12.1.16.1.$index"; $descr_oid = "powerSupplyLocationName.1.$index"; $limit_oid = "powerSupplyMaximumInputVoltage.1.$index"; - $descr = trim(snmp_get($device, $descr_oid, "-Oqv", "IDRAC-MIB-SMIv2"),'"'); - $descr = preg_replace("/(Status)/","", $descr); + $descr = trim(snmp_get($device, $descr_oid, "-Oqv", "IDRAC-MIB-SMIv2"), '"'); + $descr = preg_replace("/(Status)/", "", $descr); $current = snmp_get($device, $voltage_oid, "-Oqv", "IDRAC-MIB-SMIv2"); $high_limit = snmp_get($device, $limit_oid, "-Oqv", "IDRAC-MIB-SMIv2"); $divisor = "1"; - discover_sensor($valid['sensor'], 'voltage', $device, $voltage_oid, $index, 'drac', $descr, $divisor, '1', 0, NULL, NULL, $high_limit, $current); + discover_sensor($valid['sensor'], 'voltage', $device, $voltage_oid, $index, 'drac', $descr, $divisor, '1', 0, null, null, $high_limit, $current); } } } diff --git a/includes/discovery/sensors/voltages/gamatronicups.inc.php b/includes/discovery/sensors/voltages/gamatronicups.inc.php index 517bd7fd9a..8c5661d6dc 100644 --- a/includes/discovery/sensors/voltages/gamatronicups.inc.php +++ b/includes/discovery/sensors/voltages/gamatronicups.inc.php @@ -11,9 +11,22 @@ if ($device['os'] == 'gamatronicups') { $lowlimit = 0; $limit = null; - discover_sensor($valid['sensor'], 'voltage', $device, - $volt_oid, $index, $type, - $descr, $divisor, '1', null, null, null, null, $volt); + discover_sensor( + $valid['sensor'], + 'voltage', + $device, + $volt_oid, + $index, + $type, + $descr, + $divisor, + '1', + null, + null, + null, + null, + $volt + ); } for ($i = 1; $i <= 3; $i++) { @@ -26,8 +39,21 @@ if ($device['os'] == 'gamatronicups') { $lowlimit = 0; $limit = null; - discover_sensor($valid['sensor'], 'voltage', $device, - $volt_oid, $index, $type, - $descr, $divisor, '1', null, null, null, null, $volt); + discover_sensor( + $valid['sensor'], + 'voltage', + $device, + $volt_oid, + $index, + $type, + $descr, + $divisor, + '1', + null, + null, + null, + null, + $volt + ); } } diff --git a/includes/discovery/sensors/voltages/hytera.inc.php b/includes/discovery/sensors/voltages/hytera.inc.php index 4ad351884b..97241649ce 100644 --- a/includes/discovery/sensors/voltages/hytera.inc.php +++ b/includes/discovery/sensors/voltages/hytera.inc.php @@ -1,7 +1,7 @@ 'ssh', diff --git a/includes/discovery/storage/eql-storage.inc.php b/includes/discovery/storage/eql-storage.inc.php index d287613238..ad31aaedc1 100644 --- a/includes/discovery/storage/eql-storage.inc.php +++ b/includes/discovery/storage/eql-storage.inc.php @@ -24,8 +24,7 @@ if (is_array($eql_storage)) { $used = $storage['eqliscsiVolumeStatusAllocatedSpace'] * $units; if (is_int($index)) { discover_storage($valid_storage, $device, $index, $fstype, 'eql-storage', $descr, $size, $units, $used); - } - else { + } else { // Trying to search the last '.' and take something after it as index $arrindex = explode(".", $index); $newindex = (int)(end($arrindex))+0; diff --git a/includes/discovery/storage/hrstorage.inc.php b/includes/discovery/storage/hrstorage.inc.php index 83c38e0b45..b6f3cb4337 100644 --- a/includes/discovery/storage/hrstorage.inc.php +++ b/includes/discovery/storage/hrstorage.inc.php @@ -15,20 +15,18 @@ if (is_array($hrstorage_array)) { switch ($fstype) { case 'hrStorageVirtualMemory': - case 'hrStorageRam'; - case 'hrStorageOther'; - case 'nwhrStorageDOSMemory'; - case 'nwhrStorageMemoryAlloc'; - case 'nwhrStorageMemoryPermanent'; - case 'nwhrStorageMemoryAlloc'; - case 'nwhrStorageCacheBuffers'; - case 'nwhrStorageCacheMovable'; - case 'nwhrStorageCacheNonMovable'; - case 'nwhrStorageCodeAndDataMemory'; - case 'nwhrStorageDOSMemory'; - case 'nwhrStorageIOEngineMemory'; - case 'nwhrStorageMSEngineMemory'; - case 'nwhrStorageUnclaimedMemory'; + case 'hrStorageRam': + case 'hrStorageOther': + case 'nwhrStorageDOSMemory': + case 'nwhrStorageMemoryAlloc': + case 'nwhrStorageMemoryPermanent': + case 'nwhrStorageCacheBuffers': + case 'nwhrStorageCacheMovable': + case 'nwhrStorageCacheNonMovable': + case 'nwhrStorageCodeAndDataMemory': + case 'nwhrStorageIOEngineMemory': + case 'nwhrStorageMSEngineMemory': + case 'nwhrStorageUnclaimedMemory': $deny = 1; break; } diff --git a/includes/discovery/storage/netapp-storage.inc.php b/includes/discovery/storage/netapp-storage.inc.php index 49cd0d8035..a447abbf55 100644 --- a/includes/discovery/storage/netapp-storage.inc.php +++ b/includes/discovery/storage/netapp-storage.inc.php @@ -11,8 +11,7 @@ if (is_array($netapp_storage)) { if (isset($storage['df64TotalKBytes']) && is_numeric($storage['df64TotalKBytes'])) { $size = ($storage['df64TotalKBytes'] * $units); $used = ($storage['df64UsedKBytes'] * $units); - } - else { + } else { $size = ($storage['dfKBytesTotal'] * $units); $used = ($storage['dfKBytesUsed'] * $units); } diff --git a/includes/discovery/stp.inc.php b/includes/discovery/stp.inc.php index 2a441ed7d6..55c0a3dde0 100644 --- a/includes/discovery/stp.inc.php +++ b/includes/discovery/stp.inc.php @@ -23,7 +23,6 @@ $stpprotocol = snmp_get($device, 'dot1dStpProtocolSpecification.0', '-Oqv', 'RST // FIXME I don't know what "unknown" means, perhaps MSTP? (saw it on some cisco devices) // But we can try to retrieve data if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') { - // set time multiplier to convert from centiseconds to seconds // all time values are stored in databese as seconds $tm = '0.01'; @@ -62,20 +61,19 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') { $time_since_change = snmp_get($device, 'dot1dStpTimeSinceTopologyChange.0', '-Ovt', 'RSTP-MIB'); if ($time_since_change > '100') { $time_since_change = substr($time_since_change, 0, -2); // convert to seconds since change - } - else { + } else { $time_since_change = '0'; } $stp['timeSinceTopologyChange'] = $time_since_change; - // designated root is stored in format 2 octet bridge priority + MAC address, so we need to normalize it + // designated root is stored in format 2 octet bridge priority + MAC address, so we need to normalize it $dr = str_replace(array(' ', ':', '-'), '', strtolower($stp_raw[0]['dot1dStpDesignatedRoot'])); $dr = substr($dr, -12); //remove first two octets $stp['designatedRoot'] = $dr; // normalize the MAC $mac_array = explode(':', $mac_raw); - foreach($mac_array as &$octet) { + foreach ($mac_array as &$octet) { if (strlen($octet) < 2) { $octet = "0" . $octet; // add suppressed 0 } @@ -85,8 +83,7 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') { // I'm the boss? if ($stp['bridgeAddress'] == $stp['designatedRoot']) { $stp['rootBridge'] = '1'; - } - else { + } else { $stp['rootBridge'] = '0'; } @@ -94,25 +91,24 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') { if ($stp_raw[0]['version'] == '3') { echo "RSTP "; - } - else { + } else { echo "STP "; } if (!$stp_db['bridgeAddress'] && $stp['bridgeAddress']) { - dbInsert($stp,'stp'); + dbInsert($stp, 'stp'); log_event('STP added, bridge address: '.$stp['bridgeAddress'], $device, 'stp'); echo '+'; } if ($stp_db['bridgeAddress'] && !$stp['bridgeAddress']) { - dbDelete('stp','device_id = ?', array($device['device_id'])); + dbDelete('stp', 'device_id = ?', array($device['device_id'])); log_event('STP removed', $device, 'stp'); echo '-'; } // STP port related stuff - foreach ($stp_raw as $port => $value){ + foreach ($stp_raw as $port => $value) { if ($port) { // $stp_raw[0] ist not port related so we skip this one $stp_port = array( 'priority' => $stp_raw[$port]['dot1dStpPortPriority'], @@ -148,8 +144,7 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') { $dp = $stp_raw[$port]['dot1dStpPortDesignatedPort'] - $dp_value; $stp_port['designatedPort'] = $dp; } - } - else { + } else { // Port saved in format priority+port (ieee 802.1d-1998: clause 8.5.5.1) $dp = substr($stp_raw[$port]['dot1dStpPortDesignatedPort'], -2); //discard the first octet (priority part) $stp_port['designatedPort'] = hexdec($dp); @@ -159,18 +154,18 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') { // Write to db if (!dbFetchCell('SELECT 1 FROM `ports_stp` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $stp_port['port_id']))) { - dbInsert($stp_port,'ports_stp'); + dbInsert($stp_port, 'ports_stp'); echo '+'; } } } - // Delete STP ports from db if absent in SNMP query + // Delete STP ports from db if absent in SNMP query $stp_port_db = dbFetchRows('SELECT * FROM `ports_stp` WHERE `device_id` = ?', array($device['device_id'])); //d_echo($stp_port_db); - foreach($stp_port_db as $port => $value){ + foreach ($stp_port_db as $port => $value) { $if_index = dbFetchCell('SELECT `ifIndex` FROM `ports` WHERE `device_id` = ? AND `port_id` = ?', array($device['device_id'], $value['port_id'])); - if ($if_index != $stp_raw[$if_index]['dot1dStpPort']){ + if ($if_index != $stp_raw[$if_index]['dot1dStpPort']) { dbDelete('ports_stp', '`device_id` = ? AND `port_id` = ?', array($device['device_id'], $value['port_id'])); echo '-'; } diff --git a/includes/discovery/ucd-diskio.inc.php b/includes/discovery/ucd-diskio.inc.php index 97896a70fc..d569a4cb5a 100644 --- a/includes/discovery/ucd-diskio.inc.php +++ b/includes/discovery/ucd-diskio.inc.php @@ -11,8 +11,7 @@ if (is_array($diskio_array)) { $inserted = dbInsert(array('device_id' => $device['device_id'], 'diskio_index' => $index, 'diskio_descr' => $entry['diskIODevice']), 'ucd_diskio'); echo '+'; d_echo($sql." - $inserted inserted "); - } - else { + } else { echo '.'; // FIXME Need update code here! } diff --git a/includes/discovery/vlans.inc.php b/includes/discovery/vlans.inc.php index 6147f82f30..6741266bb4 100644 --- a/includes/discovery/vlans.inc.php +++ b/includes/discovery/vlans.inc.php @@ -55,8 +55,7 @@ foreach ($device['vlans'] as $domain_id => $vlans) { if ($from_db['port_vlan_id']) { dbUpdate($db_a, 'ports_vlans', '`port_vlan_id` = ?', array($from_db['port_vlan_id'])); echo 'Updated'; - } - else { + } else { dbInsert(array_merge($db_w, $db_a), 'ports_vlans'); echo 'Inserted'; } diff --git a/includes/discovery/vlans/cisco-vtp.inc.php b/includes/discovery/vlans/cisco-vtp.inc.php index acf3e01603..d1fa2f3cc7 100644 --- a/includes/discovery/vlans/cisco-vtp.inc.php +++ b/includes/discovery/vlans/cisco-vtp.inc.php @@ -16,8 +16,7 @@ if ($device['os_group'] == 'cisco') { echo " $vlan_id"; if (is_array($vlans_db[$vtpdomain_id][$vlan_id])) { echo '.'; - } - else { + } else { dbInsert(array('device_id' => $device['device_id'], 'vlan_domain' => $vtpdomain_id, 'vlan_vlan' => $vlan_id, 'vlan_name' => $vlan['vtpVlanName'], 'vlan_type' => $vlan['vtpVlanType']), 'vlans'); echo '+'; } diff --git a/includes/discovery/vlans/q-bridge-mib.inc.php b/includes/discovery/vlans/q-bridge-mib.inc.php index 6de0c9423e..8e6403cfdd 100644 --- a/includes/discovery/vlans/q-bridge-mib.inc.php +++ b/includes/discovery/vlans/q-bridge-mib.inc.php @@ -4,7 +4,7 @@ echo 'IEEE8021-Q-BRIDGE-MIB VLANs : '; $vlanversion = snmp_get($device, 'dot1qVlanVersionNumber.0', '-Oqv', 'IEEE8021-Q-BRIDGE-MIB'); -if ($vlanversion == 'version1' || $vlanversion == '2' ) { +if ($vlanversion == 'version1' || $vlanversion == '2') { echo "VLAN $vlanversion "; $vtpdomain_id = '1'; @@ -14,8 +14,7 @@ if ($vlanversion == 'version1' || $vlanversion == '2' ) { echo " $vlan_id"; if (is_array($vlans_db[$vtpdomain_id][$vlan_id])) { echo '.'; - } - else { + } else { dbInsert(array('device_id' => $device['device_id'], 'vlan_domain' => $vtpdomain_id, 'vlan_vlan' => $vlan_id, 'vlan_name' => $vlan['dot1qVlanStaticName'], 'vlan_type' => array('NULL')), 'vlans'); echo '+'; } diff --git a/includes/discovery/vmware-vminfo.inc.php b/includes/discovery/vmware-vminfo.inc.php index c5a8c0852d..617d40a570 100644 --- a/includes/discovery/vmware-vminfo.inc.php +++ b/includes/discovery/vmware-vminfo.inc.php @@ -45,8 +45,7 @@ if (($device['os'] == 'vmware') || ($device['os'] == 'linux')) { log_event(mres($vmwVmDisplayName)." ($vmwVmMemSize GB / $vmwVmCpus vCPU) Discovered", $device, 'system', $vmid); echo '+'; // FIXME eventlog - } - else { + } else { echo '.'; } diff --git a/includes/functions.php b/includes/functions.php index abcebbbc7d..bcb906d247 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -19,7 +19,6 @@ use LibreNMS\Exceptions\HostUnreachablePingException; use LibreNMS\Exceptions\InvalidPortAssocModeException; use LibreNMS\Exceptions\SnmpVersionUnsupportedException; - // Include from PEAR include_once("Net/IPv4.php"); @@ -38,7 +37,8 @@ include_once($config['install_dir'] . "/includes/services.inc.php"); $console_color = new Console_Color2(); -function array_sort($array, $on, $order=SORT_ASC) { +function array_sort($array, $on, $order = SORT_ASC) +{ $new_array = array(); $sortable_array = array(); @@ -50,19 +50,18 @@ function array_sort($array, $on, $order=SORT_ASC) { $sortable_array[$k] = $v2; } } - } - else { + } else { $sortable_array[$k] = $v; } } switch ($order) { - case SORT_ASC: - asort($sortable_array); - break; - case SORT_DESC: - arsort($sortable_array); - break; + case SORT_ASC: + asort($sortable_array); + break; + case SORT_DESC: + arsort($sortable_array); + break; } foreach ($sortable_array as $k => $v) { @@ -72,7 +71,8 @@ function array_sort($array, $on, $order=SORT_ASC) { return $new_array; } -function mac_clean_to_readable($mac) { +function mac_clean_to_readable($mac) +{ $r = substr($mac, 0, 2); $r .= ":".substr($mac, 2, 2); $r .= ":".substr($mac, 4, 2); @@ -83,23 +83,26 @@ function mac_clean_to_readable($mac) { return($r); } -function only_alphanumeric($string) { +function only_alphanumeric($string) +{ return preg_replace('/[^a-zA-Z0-9]/', '', $string); } -function logfile($string) { +function logfile($string) +{ global $config; - $fd = fopen($config['log_file'],'a'); - fputs($fd,$string . "\n"); + $fd = fopen($config['log_file'], 'a'); + fputs($fd, $string . "\n"); fclose($fd); } -function getHostOS($device){ +function getHostOS($device) +{ global $config; - $sysDescr = snmp_get ($device, "SNMPv2-MIB::sysDescr.0", "-Ovq"); - $sysObjectId = snmp_get ($device, "SNMPv2-MIB::sysObjectID.0", "-Ovqn"); + $sysDescr = snmp_get($device, "SNMPv2-MIB::sysDescr.0", "-Ovq"); + $sysObjectId = snmp_get($device, "SNMPv2-MIB::sysObjectID.0", "-Ovqn"); d_echo("| $sysDescr | $sysObjectId | "); @@ -114,13 +117,13 @@ function getHostOS($device){ if ($os) { return $os; - } - else { + } else { return "generic"; } } -function percent_colour($perc) { +function percent_colour($perc) +{ $r = min(255, 5 * ($perc - 25)); $b = max(0, 255 - (5 * ($perc + 25))); @@ -128,7 +131,8 @@ function percent_colour($perc) { } // Returns the last in/out errors value in RRD -function interface_errors($rrd_file, $period = '-1d') { +function interface_errors($rrd_file, $period = '-1d') +{ global $config; $errors = array(); @@ -147,17 +151,20 @@ function interface_errors($rrd_file, $period = '-1d') { return $errors; } -function getImage($device) { +function getImage($device) +{ return ''; } -function getImageSrc($device) { +function getImageSrc($device) +{ global $config; return 'images/os/' . getImageName($device) . '.png'; } -function getImageName($device, $use_database=true) { +function getImageName($device, $use_database = true) +{ global $config; $device['os'] = strtolower($device['os']); @@ -190,11 +197,12 @@ function getImageName($device, $use_database=true) { return 'generic'; } -function renamehost($id, $new, $source = 'console') { +function renamehost($id, $new, $source = 'console') +{ global $config; $host = dbFetchCell("SELECT `hostname` FROM `devices` WHERE `device_id` = ?", array($id)); - if (!is_dir($config['rrd_dir']."/$new") && rename($config['rrd_dir']."/$host", $config['rrd_dir']."/$new") === TRUE) { + if (!is_dir($config['rrd_dir']."/$new") && rename($config['rrd_dir']."/$host", $config['rrd_dir']."/$new") === true) { dbUpdate(array('hostname' => $new), 'devices', 'device_id=?', array($id)); log_event("Hostname changed -> $new ($source)", $id, 'system'); } else { @@ -203,18 +211,19 @@ function renamehost($id, $new, $source = 'console') { } } -function delete_device($id) { +function delete_device($id) +{ global $config, $debug; $ret = ''; $host = dbFetchCell("SELECT hostname FROM devices WHERE device_id = ?", array($id)); - if( empty($host) ) { + if (empty($host)) { return "No such host."; } // Remove IPv4/IPv6 addresses before removing ports as they depend on port_id - dbQuery("DELETE `ipv4_addresses` FROM `ipv4_addresses` INNER JOIN `ports` ON `ports`.`port_id`=`ipv4_addresses`.`port_id` WHERE `device_id`=?",array($id)); - dbQuery("DELETE `ipv6_addresses` FROM `ipv6_addresses` INNER JOIN `ports` ON `ports`.`port_id`=`ipv6_addresses`.`port_id` WHERE `device_id`=?",array($id)); + dbQuery("DELETE `ipv4_addresses` FROM `ipv4_addresses` INNER JOIN `ports` ON `ports`.`port_id`=`ipv4_addresses`.`port_id` WHERE `device_id`=?", array($id)); + dbQuery("DELETE `ipv6_addresses` FROM `ipv6_addresses` INNER JOIN `ports` ON `ports`.`port_id`=`ipv6_addresses`.`port_id` WHERE `device_id`=?", array($id)); foreach (dbFetch("SELECT * FROM `ports` WHERE `device_id` = ?", array($id)) as $int_data) { $int_if = $int_data['ifDescr']; @@ -224,19 +233,19 @@ function delete_device($id) { } $fields = array('device_id','host'); - foreach( $fields as $field ) { - foreach( dbFetch("SELECT table_name FROM information_schema.columns WHERE table_schema = ? AND column_name = ?",array($config['db_name'],$field)) as $table ) { + foreach ($fields as $field) { + foreach (dbFetch("SELECT table_name FROM information_schema.columns WHERE table_schema = ? AND column_name = ?", array($config['db_name'],$field)) as $table) { $table = $table['table_name']; $entries = (int) dbDelete($table, "`$field` = ?", array($id)); - if( $entries > 0 && $debug === true ) { + if ($entries > 0 && $debug === true) { $ret .= "$field@$table = #$entries\n"; } } } $ex = shell_exec("bash -c '( [ ! -d ".trim($config['rrd_dir'])."/".$host." ] || rm -vrf ".trim($config['rrd_dir'])."/".$host." 2>&1 ) && echo -n OK'"); - $tmp = explode("\n",$ex); - if( $tmp[sizeof($tmp)-1] != "OK" ) { + $tmp = explode("\n", $ex); + if ($tmp[sizeof($tmp)-1] != "OK") { $ret .= "Could not remove files:\n$ex\n"; } @@ -265,7 +274,8 @@ function delete_device($id) { * @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', $poller_group = '0', $force_add = false, $port_assoc_mode = 'ifIndex') { +function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $poller_group = '0', $force_add = false, $port_assoc_mode = 'ifIndex') +{ global $config; // Test Database Exists @@ -344,7 +354,8 @@ function addHost($host, $snmp_version = '', $port = '161', $transport = 'udp', $ throw $host_unreachable_exception; } -function deviceArray($host, $community, $snmpver, $port = 161, $transport = 'udp', $v3, $port_assoc_mode = 'ifIndex') { +function deviceArray($host, $community, $snmpver, $port = 161, $transport = 'udp', $v3 = array(), $port_assoc_mode = 'ifIndex') +{ $device = array(); $device['hostname'] = $host; $device['port'] = $port; @@ -352,15 +363,15 @@ function deviceArray($host, $community, $snmpver, $port = 161, $transport = 'udp /* Get port_assoc_mode id if neccessary * We can work with names of IDs here */ - if (! is_int ($port_assoc_mode)) - $port_assoc_mode = get_port_assoc_mode_id ($port_assoc_mode); + if (! is_int($port_assoc_mode)) { + $port_assoc_mode = get_port_assoc_mode_id($port_assoc_mode); + } $device['port_association_mode'] = $port_assoc_mode; $device['snmpver'] = $snmpver; if ($snmpver === "v2c" or $snmpver === "v1") { $device['community'] = $community; - } - elseif ($snmpver === "v3") { + } elseif ($snmpver === "v3") { $device['authlevel'] = $v3['authlevel']; $device['authname'] = $v3['authname']; $device['authpass'] = $v3['authpass']; @@ -372,16 +383,19 @@ function deviceArray($host, $community, $snmpver, $port = 161, $transport = 'udp return $device; } -function netmask2cidr($netmask) { +function netmask2cidr($netmask) +{ $addr = Net_IPv4::parseAddress("1.2.3.4/$netmask"); return $addr->bitmask; } -function cidr2netmask($netmask) { +function cidr2netmask($netmask) +{ return (long2ip(ip2long("255.255.255.255") << (32-$netmask))); } -function formatUptime($diff, $format="long") { +function formatUptime($diff, $format = "long") +{ $yearsDiff = floor($diff/31536000); $diff -= $yearsDiff*31536000; $daysDiff = floor($diff/86400); @@ -410,8 +424,7 @@ function formatUptime($diff, $format="long") { if ($secsDiff > '0') { $uptime .= $secsDiff . "s "; } - } - else { + } else { if ($yearsDiff > '0') { $uptime .= $yearsDiff . " years, "; } @@ -431,18 +444,18 @@ function formatUptime($diff, $format="long") { return trim($uptime); } -function isSNMPable($device) { +function isSNMPable($device) +{ global $config; $pos = snmp_get($device, "sysObjectID.0", "-Oqv", "SNMPv2-MIB"); - if(empty($pos)) { + if (empty($pos)) { // Support for Hikvision $pos = snmp_get($device, "SNMPv2-SMI::enterprises.39165.1.1.0", "-Oqv", "SNMPv2-MIB"); } if ($pos === '' || $pos === false) { return false; - } - else { + } else { return true; } } @@ -456,61 +469,58 @@ function isSNMPable($device) { * * @return array 'result' => bool pingable, 'last_ping_timetaken' => int time for last ping, 'db' => fping results */ -function isPingable($hostname, $address_family = AF_INET, $attribs = array()) { +function isPingable($hostname, $address_family = AF_INET, $attribs = array()) +{ global $config; $response = array(); if (can_ping_device($attribs) === true) { $fping_params = ''; - if(is_numeric($config['fping_options']['retries']) || $config['fping_options']['retries'] > 1) { + if (is_numeric($config['fping_options']['retries']) || $config['fping_options']['retries'] > 1) { $fping_params .= ' -r ' . $config['fping_options']['retries']; } - if(is_numeric($config['fping_options']['timeout']) || $config['fping_options']['timeout'] > 1) { + if (is_numeric($config['fping_options']['timeout']) || $config['fping_options']['timeout'] > 1) { $fping_params .= ' -t ' . $config['fping_options']['timeout']; } - if(is_numeric($config['fping_options']['count']) || $config['fping_options']['count'] > 0) { + if (is_numeric($config['fping_options']['count']) || $config['fping_options']['count'] > 0) { $fping_params .= ' -c ' . $config['fping_options']['count']; } - if(is_numeric($config['fping_options']['millisec']) || $config['fping_options']['millisec'] > 0) { + if (is_numeric($config['fping_options']['millisec']) || $config['fping_options']['millisec'] > 0) { $fping_params .= ' -p ' . $config['fping_options']['millisec']; } - $status = fping($hostname,$fping_params,$address_family); + $status = fping($hostname, $fping_params, $address_family); if ($status['loss'] == 100) { - $response['result'] = FALSE; - } - else { - $response['result'] = TRUE; + $response['result'] = false; + } else { + $response['result'] = true; } if (is_numeric($status['avg'])) { $response['last_ping_timetaken'] = $status['avg']; } $response['db'] = $status; - } - else { + } else { $response['result'] = true; $response['last_ping_timetaken'] = 0; } return($response); } -function getpollergroup($poller_group='0') { +function getpollergroup($poller_group = '0') +{ //Is poller group an integer if (is_int($poller_group) || ctype_digit($poller_group)) { return $poller_group; - } - else { + } else { //Check if it contains a comma - if (strpos($poller_group,',')!== FALSE) { + if (strpos($poller_group, ',')!== false) { //If it has a comma use the first element as the poller group - $poller_group_array=explode(',',$poller_group); + $poller_group_array=explode(',', $poller_group); return getpollergroup($poller_group_array[0]); - } - else { + } else { if ($config['distributed_poller_group']) { //If not use the poller's group from the config return getpollergroup($config['distributed_poller_group']); - } - else { + } else { //If all else fails use default return '0'; } @@ -518,7 +528,8 @@ function getpollergroup($poller_group='0') { } } -function createHost($host, $community = NULL, $snmpver, $port = 161, $transport = 'udp', $v3 = array(), $poller_group='0', $port_assoc_mode = 'ifIndex', $snmphost = '') { +function createHost($host, $community, $snmpver, $port = 161, $transport = 'udp', $v3 = array(), $poller_group = '0', $port_assoc_mode = 'ifIndex', $snmphost = '') +{ global $config; $host = trim(strtolower($host)); @@ -526,8 +537,9 @@ function createHost($host, $community = NULL, $snmpver, $port = 161, $transport /* Get port_assoc_mode id if necessary * We can work with names of IDs here */ - if (! is_int ($port_assoc_mode)) - $port_assoc_mode = get_port_assoc_mode_id ($port_assoc_mode); + if (! is_int($port_assoc_mode)) { + $port_assoc_mode = get_port_assoc_mode_id($port_assoc_mode); + } $device = array('hostname' => $host, 'sysName' => $host, @@ -559,20 +571,25 @@ function createHost($host, $community = NULL, $snmpver, $port = 161, $transport return false; } -function isDomainResolves($domain) { +function isDomainResolves($domain) +{ return (gethostbyname($domain) != $domain || count(dns_get_record($domain)) != 0); } -function hoststatus($id) { +function hoststatus($id) +{ return dbFetchCell("SELECT `status` FROM `devices` WHERE `device_id` = ?", array($id)); } -function match_network($nets, $ip, $first=false) { +function match_network($nets, $ip, $first = false) +{ $return = false; - if (!is_array ($nets)) $nets = array ($nets); + if (!is_array($nets)) { + $nets = array ($nets); + } foreach ($nets as $net) { - $rev = (preg_match ("/^\!/", $net)) ? true : false; - $net = preg_replace ("/^\!/", "", $net); + $rev = (preg_match("/^\!/", $net)) ? true : false; + $net = preg_replace("/^\!/", "", $net); $ip_arr = explode('/', $net); $net_long = ip2long($ip_arr[0]); $x = ip2long($ip_arr[1]); @@ -582,8 +599,7 @@ function match_network($nets, $ip, $first=false) { if (($ip_long & $mask) == ($net_long & $mask)) { return false; } - } - else { + } else { if (($ip_long & $mask) == ($net_long & $mask)) { $return = true; } @@ -596,8 +612,9 @@ function match_network($nets, $ip, $first=false) { return $return; } -function snmp2ipv6($ipv6_snmp) { - $ipv6 = explode('.',$ipv6_snmp); +function snmp2ipv6($ipv6_snmp) +{ + $ipv6 = explode('.', $ipv6_snmp); $ipv6_2 = array(); # Workaround stupid Microsoft bug in Windows 2008 -- this is fixed length! @@ -606,41 +623,44 @@ function snmp2ipv6($ipv6_snmp) { array_shift($ipv6); } - for ($i = 0;$i <= 15;$i++) { + for ($i = 0; $i <= 15; $i++) { $ipv6[$i] = zeropad(dechex($ipv6[$i])); } - for ($i = 0;$i <= 15;$i+=2) { + for ($i = 0; $i <= 15; $i+=2) { $ipv6_2[] = $ipv6[$i] . $ipv6[$i+1]; } - return implode(':',$ipv6_2); + return implode(':', $ipv6_2); } -function ipv62snmp($ipv6) { +function ipv62snmp($ipv6) +{ $ipv6_split = array(); - $ipv6_ex = explode(':',Net_IPv6::uncompress($ipv6)); - for ($i = 0;$i < 8;$i++) { - $ipv6_ex[$i] = zeropad($ipv6_ex[$i],4); + $ipv6_ex = explode(':', Net_IPv6::uncompress($ipv6)); + for ($i = 0; $i < 8; $i++) { + $ipv6_ex[$i] = zeropad($ipv6_ex[$i], 4); + } + $ipv6_ip = implode('', $ipv6_ex); + for ($i = 0; $i < 32; + $i+=2) { + $ipv6_split[] = hexdec(substr($ipv6_ip, $i, 2)); } - $ipv6_ip = implode('',$ipv6_ex); - for ($i = 0;$i < 32;$i+=2) $ipv6_split[] = hexdec(substr($ipv6_ip,$i,2)); - return implode('.',$ipv6_split); + return implode('.', $ipv6_split); } -function get_astext($asn) { +function get_astext($asn) +{ global $config,$cache; if (isset($config['astext'][$asn])) { return $config['astext'][$asn]; - } - else { + } else { if (isset($cache['astext'][$asn])) { return $cache['astext'][$asn]; - } - else { - $result = dns_get_record("AS$asn.asn.cymru.com",DNS_TXT); - $txt = explode('|',$result[0]['txt']); + } else { + $result = dns_get_record("AS$asn.asn.cymru.com", DNS_TXT); + $txt = explode('|', $result[0]['txt']); $result = trim(str_replace('"', '', $txt[4])); $cache['astext'][$asn] = $result; return $result; @@ -649,7 +669,8 @@ function get_astext($asn) { } # Use this function to write to the eventlog table -function log_event($text, $device = NULL, $type = NULL, $reference = NULL) { +function log_event($text, $device = null, $type = null, $reference = null) +{ if (!is_array($device)) { $device = device_by_id_cache($device); } @@ -665,7 +686,8 @@ function log_event($text, $device = NULL, $type = NULL, $reference = NULL) { } // Parse string with emails. Return array with email (as key) and name (as value) -function parse_email($emails) { +function parse_email($emails) +{ $result = array(); $regex = '/^[\"\']?([^\"\']+)[\"\']?\s{0,}<([^@]+@[^>]+)>$/'; if (is_string($emails)) { @@ -673,83 +695,83 @@ function parse_email($emails) { foreach ($emails as $email) { if (preg_match($regex, $email, $out, PREG_OFFSET_CAPTURE)) { $result[$out[2][0]] = $out[1][0]; - } - else { + } else { if (strpos($email, "@")) { - $result[$email] = NULL; + $result[$email] = null; } } } - } - else { + } else { // Return FALSE if input not string - return FALSE; + return false; } return $result; } -function send_mail($emails,$subject,$message,$html=false) { +function send_mail($emails, $subject, $message, $html = false) +{ global $config; - if( is_array($emails) || ($emails = parse_email($emails)) ) { + if (is_array($emails) || ($emails = parse_email($emails))) { $mail = new PHPMailer(); $mail->Hostname = php_uname('n'); - if (empty($config['email_from'])) + if (empty($config['email_from'])) { $config['email_from'] = '"' . $config['project_name'] . '" <' . $config['email_user'] . '@'.$mail->Hostname.'>'; - foreach (parse_email($config['email_from']) as $from => $from_name) + } + foreach (parse_email($config['email_from']) as $from => $from_name) { $mail->setFrom($from, $from_name); - foreach ($emails as $email => $email_name) + } + foreach ($emails as $email => $email_name) { $mail->addAddress($email, $email_name); + } $mail->Subject = $subject; $mail->XMailer = $config['project_name_version']; $mail->CharSet = 'utf-8'; $mail->WordWrap = 76; $mail->Body = $message; - if( $html ) + if ($html) { $mail->isHTML(true); + } switch (strtolower(trim($config['email_backend']))) { - case 'sendmail': - $mail->Mailer = 'sendmail'; - $mail->Sendmail = $config['email_sendmail_path']; - break; - case 'smtp': - $mail->isSMTP(); - $mail->Host = $config['email_smtp_host']; - $mail->Timeout = $config['email_smtp_timeout']; - $mail->SMTPAuth = $config['email_smtp_auth']; - $mail->SMTPSecure = $config['email_smtp_secure']; - $mail->Port = $config['email_smtp_port']; - $mail->Username = $config['email_smtp_username']; - $mail->Password = $config['email_smtp_password']; - $mail->SMTPDebug = false; - break; - default: - $mail->Mailer = 'mail'; - break; + case 'sendmail': + $mail->Mailer = 'sendmail'; + $mail->Sendmail = $config['email_sendmail_path']; + break; + case 'smtp': + $mail->isSMTP(); + $mail->Host = $config['email_smtp_host']; + $mail->Timeout = $config['email_smtp_timeout']; + $mail->SMTPAuth = $config['email_smtp_auth']; + $mail->SMTPSecure = $config['email_smtp_secure']; + $mail->Port = $config['email_smtp_port']; + $mail->Username = $config['email_smtp_username']; + $mail->Password = $config['email_smtp_password']; + $mail->SMTPDebug = false; + break; + default: + $mail->Mailer = 'mail'; + break; } return $mail->send() ? true : $mail->ErrorInfo; } } -function formatCiscoHardware(&$device, $short = false) { +function formatCiscoHardware(&$device, $short = false) +{ if ($device['os'] == "ios") { if ($device['hardware']) { if (preg_match("/^WS-C([A-Za-z0-9]+).*/", $device['hardware'], $matches)) { if (!$short) { $device['hardware'] = "Cisco " . $matches[1] . " (" . $device['hardware'] . ")"; - } - else { + } else { $device['hardware'] = "Cisco " . $matches[1]; } - } - elseif (preg_match("/^CISCO([0-9]+)$/", $device['hardware'], $matches)) { + } elseif (preg_match("/^CISCO([0-9]+)$/", $device['hardware'], $matches)) { $device['hardware'] = "Cisco " . $matches[1]; } - } - else { + } else { if (preg_match("/Cisco IOS Software, C([A-Za-z0-9]+) Software.*/", $device['sysDescr'], $matches)) { $device['hardware'] = "Cisco " . $matches[1]; - } - elseif (preg_match("/Cisco IOS Software, ([0-9]+) Software.*/", $device['sysDescr'], $matches)) { + } elseif (preg_match("/Cisco IOS Software, ([0-9]+) Software.*/", $device['sysDescr'], $matches)) { $device['hardware'] = "Cisco " . $matches[1]; } } @@ -757,7 +779,8 @@ function formatCiscoHardware(&$device, $short = false) { } # from http://ditio.net/2008/11/04/php-string-to-hex-and-hex-to-string-functions/ -function hex2str($hex) { +function hex2str($hex) +{ $string=''; for ($i = 0; $i < strlen($hex)-1; $i+=2) { @@ -768,17 +791,20 @@ function hex2str($hex) { } # Convert an SNMP hex string to regular string -function snmp_hexstring($hex) { - return hex2str(str_replace(' ','',str_replace(' 00','',$hex))); +function snmp_hexstring($hex) +{ + return hex2str(str_replace(' ', '', str_replace(' 00', '', $hex))); } # Check if the supplied string is an SNMP hex string -function isHexString($str) { - return preg_match("/^[a-f0-9][a-f0-9]( [a-f0-9][a-f0-9])*$/is",trim($str)); +function isHexString($str) +{ + return preg_match("/^[a-f0-9][a-f0-9]( [a-f0-9][a-f0-9])*$/is", trim($str)); } # Include all .inc.php files in $dir -function include_dir($dir, $regex = "") { +function include_dir($dir, $regex = "") +{ global $device, $config, $valid; if ($regex == "") { @@ -798,21 +824,21 @@ function include_dir($dir, $regex = "") { } } -function is_port_valid($port, $device) { +function is_port_valid($port, $device) +{ global $config; if (strstr($port['ifDescr'], "irtual")) { $valid = 0; - } - else { + } else { $valid = 1; $if = strtolower($port['ifDescr']); $ifname = strtolower($port['ifName']); $ifalias = strtolower($port['ifAlias']); $fringe = $config['bad_if']; - if( is_array($config['os'][$device['os']]['bad_if']) ) { - $fringe = array_merge($config['bad_if'],$config['os'][$device['os']]['bad_if']); + if (is_array($config['os'][$device['os']]['bad_if'])) { + $fringe = array_merge($config['bad_if'], $config['os'][$device['os']]['bad_if']); } foreach ($fringe as $bi) { if (stristr($if, $bi)) { @@ -822,8 +848,8 @@ function is_port_valid($port, $device) { } if (is_array($config['bad_if_regexp'])) { $fringe = $config['bad_if_regexp']; - if( is_array($config['os'][$device['os']]['bad_if_regexp']) ) { - $fringe = array_merge($config['bad_if_regexp'],$config['os'][$device['os']]['bad_if_regexp']); + if (is_array($config['os'][$device['os']]['bad_if_regexp'])) { + $fringe = array_merge($config['bad_if_regexp'], $config['os'][$device['os']]['bad_if_regexp']); } foreach ($fringe as $bi) { if (preg_match($bi ."i", $if)) { @@ -834,8 +860,8 @@ function is_port_valid($port, $device) { } if (is_array($config['bad_ifname_regexp'])) { $fringe = $config['bad_ifname_regexp']; - if( is_array($config['os'][$device['os']]['bad_ifname_regexp']) ) { - $fringe = array_merge($config['bad_ifname_regexp'],$config['os'][$device['os']]['bad_ifname_regexp']); + if (is_array($config['os'][$device['os']]['bad_ifname_regexp'])) { + $fringe = array_merge($config['bad_ifname_regexp'], $config['os'][$device['os']]['bad_ifname_regexp']); } foreach ($fringe as $bi) { if (preg_match($bi ."i", $ifname)) { @@ -846,8 +872,8 @@ function is_port_valid($port, $device) { } if (is_array($config['bad_ifalias_regexp'])) { $fringe = $config['bad_ifalias_regexp']; - if( is_array($config['os'][$device['os']]['bad_ifalias_regexp']) ) { - $fringe = array_merge($config['bad_ifalias_regexp'],$config['os'][$device['os']]['bad_ifalias_regexp']); + if (is_array($config['os'][$device['os']]['bad_ifalias_regexp'])) { + $fringe = array_merge($config['bad_ifalias_regexp'], $config['os'][$device['os']]['bad_ifalias_regexp']); } foreach ($fringe as $bi) { if (preg_match($bi ."i", $ifalias)) { @@ -858,8 +884,8 @@ function is_port_valid($port, $device) { } if (is_array($config['bad_iftype'])) { $fringe = $config['bad_iftype']; - if( is_array($config['os'][$device['os']]['bad_iftype']) ) { - $fringe = array_merge($config['bad_iftype'],$config['os'][$device['os']]['bad_iftype']); + if (is_array($config['os'][$device['os']]['bad_iftype'])) { + $fringe = array_merge($config['bad_iftype'], $config['os'][$device['os']]['bad_iftype']); } foreach ($fringe as $bi) { if (stristr($port['ifType'], $bi)) { @@ -882,21 +908,22 @@ function is_port_valid($port, $device) { return $valid; } -function scan_new_plugins() { +function scan_new_plugins() +{ global $config; $installed = 0; // Track how many plugins we install. - if(file_exists($config['plugin_dir'])) { + if (file_exists($config['plugin_dir'])) { $plugin_files = scandir($config['plugin_dir']); - foreach($plugin_files as $name) { - if(is_dir($config['plugin_dir'].'/'.$name)) { - if($name != '.' && $name != '..') { - if(is_file($config['plugin_dir'].'/'.$name.'/'.$name.'.php') && is_file($config['plugin_dir'].'/'.$name.'/'.$name.'.inc.php')) { + foreach ($plugin_files as $name) { + if (is_dir($config['plugin_dir'].'/'.$name)) { + if ($name != '.' && $name != '..') { + if (is_file($config['plugin_dir'].'/'.$name.'/'.$name.'.php') && is_file($config['plugin_dir'].'/'.$name.'/'.$name.'.inc.php')) { $plugin_id = dbFetchRow("SELECT `plugin_id` FROM `plugins` WHERE `plugin_name` = '$name'"); - if(empty($plugin_id)) { - if(dbInsert(array('plugin_name' => $name, 'plugin_active' => '0'), 'plugins')) { + if (empty($plugin_id)) { + if (dbInsert(array('plugin_name' => $name, 'plugin_active' => '0'), 'plugins')) { $installed++; } } @@ -907,21 +934,19 @@ function scan_new_plugins() { } return( $installed ); - } -function validate_device_id($id) { +function validate_device_id($id) +{ global $config; - if(empty($id) || !is_numeric($id)) { + if (empty($id) || !is_numeric($id)) { $return = false; - } - else { + } else { $device_id = dbFetchCell("SELECT `device_id` FROM `devices` WHERE `device_id` = ?", array($id)); - if($device_id == $id) { + if ($device_id == $id) { $return = true; - } - else { + } else { $return = false; } } @@ -931,23 +956,27 @@ function validate_device_id($id) { // The original source of this code is from Stackoverflow (www.stackoverflow.com). // http://stackoverflow.com/questions/6054033/pretty-printing-json-with-php // Answer provided by stewe (http://stackoverflow.com/users/3202187/ulk200 -if (!defined('JSON_UNESCAPED_SLASHES')) +if (!defined('JSON_UNESCAPED_SLASHES')) { define('JSON_UNESCAPED_SLASHES', 64); -if (!defined('JSON_PRETTY_PRINT')) +} +if (!defined('JSON_PRETTY_PRINT')) { define('JSON_PRETTY_PRINT', 128); -if (!defined('JSON_UNESCAPED_UNICODE')) +} +if (!defined('JSON_UNESCAPED_UNICODE')) { define('JSON_UNESCAPED_UNICODE', 256); +} -function _json_encode($data, $options = 448) { +function _json_encode($data, $options = 448) +{ if (version_compare(PHP_VERSION, '5.4', '>=')) { return json_encode($data, $options); - } - else { + } else { return _json_format(json_encode($data), $options); } } -function _json_format($json, $options = 448) { +function _json_format($json, $options = 448) +{ $prettyPrint = (bool) ($options & JSON_PRETTY_PRINT); $unescapeUnicode = (bool) ($options & JSON_UNESCAPED_UNICODE); $unescapeSlashes = (bool) ($options & JSON_UNESCAPED_SLASHES); @@ -978,33 +1007,33 @@ function _json_format($json, $options = 448) { $buffer .= $char; $noescape = '\\' === $char ? !$noescape : true; continue; - } - elseif ('' !== $buffer) { + } elseif ('' !== $buffer) { if ($unescapeSlashes) { $buffer = str_replace('\\/', '/', $buffer); } if ($unescapeUnicode && function_exists('mb_convert_encoding')) { // http://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-cha - $buffer = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', + $buffer = preg_replace_callback( + '/\\\\u([0-9a-f]{4})/i', function ($match) { return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE'); - }, $buffer); + }, + $buffer + ); } $result .= $buffer . $char; $buffer = ''; continue; - } - elseif(false !== strpos(" \t\r\n", $char)) { + } elseif (false !== strpos(" \t\r\n", $char)) { continue; } if (':' === $char) { // Add a space after the : character $char .= ' '; - } - elseif (('}' === $char || ']' === $char)) { + } elseif (('}' === $char || ']' === $char)) { $pos--; $prevChar = substr($json, $i - 1, 1); @@ -1015,8 +1044,7 @@ function _json_format($json, $options = 448) { for ($j = 0; $j < $pos; $j++) { $result .= $indentStr; } - } - else { + } else { // Collapse empty {} and [] $result = rtrim($result) . "\n\n" . $indentStr; } @@ -1047,27 +1075,25 @@ function _json_format($json, $options = 448) { return $result; } -function convert_delay($delay) { - $delay = preg_replace('/\s/','',$delay); - if(strstr($delay, 'm',TRUE)) { +function convert_delay($delay) +{ + $delay = preg_replace('/\s/', '', $delay); + if (strstr($delay, 'm', true)) { $delay_sec = $delay * 60; - } - elseif(strstr($delay, 'h',TRUE)) { + } elseif (strstr($delay, 'h', true)) { $delay_sec = $delay * 3600; - } - elseif(strstr($delay, 'd',TRUE)) { + } elseif (strstr($delay, 'd', true)) { $delay_sec = $delay * 86400; - } - elseif(is_numeric($delay)) { + } elseif (is_numeric($delay)) { $delay_sec = $delay; - } - else { + } else { $delay_sec = 300; } return($delay_sec); } -function guidv4($data) { +function guidv4($data) +{ // http://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid#15875555 // From: Jack http://stackoverflow.com/users/1338292/ja%CD%A2ck assert(strlen($data) == 16); @@ -1078,7 +1104,8 @@ function guidv4($data) { return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); } -function set_curl_proxy($post) { +function set_curl_proxy($post) +{ global $config; if (isset($_ENV['https_proxy'])) { $tmp = rtrim($_ENV['https_proxy'], "/"); @@ -1092,27 +1119,28 @@ function set_curl_proxy($post) { } } -function target_to_id($target) { - if( $target[0].$target[1] == "g:" ) { - $target = "g".dbFetchCell('SELECT id FROM device_groups WHERE name = ?',array(substr($target,2))); - } - else { - $target = dbFetchCell('SELECT device_id FROM devices WHERE hostname = ?',array($target)); +function target_to_id($target) +{ + if ($target[0].$target[1] == "g:") { + $target = "g".dbFetchCell('SELECT id FROM device_groups WHERE name = ?', array(substr($target, 2))); + } else { + $target = dbFetchCell('SELECT device_id FROM devices WHERE hostname = ?', array($target)); } return $target; } -function id_to_target($id) { - if( $id[0] == "g" ) { - $id = 'g:'.dbFetchCell("SELECT name FROM device_groups WHERE id = ?",array(substr($id,1))); - } - else { - $id = dbFetchCell("SELECT hostname FROM devices WHERE device_id = ?",array($id)); +function id_to_target($id) +{ + if ($id[0] == "g") { + $id = 'g:'.dbFetchCell("SELECT name FROM device_groups WHERE id = ?", array(substr($id, 1))); + } else { + $id = dbFetchCell("SELECT hostname FROM devices WHERE device_id = ?", array($id)); } return $id; } -function first_oid_match($device, $list) { +function first_oid_match($device, $list) +{ foreach ($list as $item) { $tmp = trim(snmp_get($device, $item, "-Ovq"), '" '); if (!empty($tmp)) { @@ -1121,9 +1149,10 @@ function first_oid_match($device, $list) { } } -function hex_to_ip($hex) { +function hex_to_ip($hex) +{ $return = ""; - if (filter_var($hex, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === FALSE && filter_var($hex, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === FALSE) { + if (filter_var($hex, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false && filter_var($hex, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { $hex_exp = explode(' ', $hex); foreach ($hex_exp as $item) { if (!empty($item) && $item != "\"") { @@ -1131,17 +1160,16 @@ function hex_to_ip($hex) { } } $return = substr($return, 0, -1); - } - else { + } else { $return = $hex; } return $return; } -function fix_integer_value($value) { +function fix_integer_value($value) +{ if ($value < 0) { $return = 4294967296+$value; - } - else { + } else { $return = $value; } return $return; @@ -1162,7 +1190,8 @@ function ip_exists($ip) return false; } -function fping($host,$params,$address_family = AF_INET) { +function fping($host, $params, $address_family = AF_INET) +{ global $config; @@ -1182,7 +1211,6 @@ function fping($host,$params,$address_family = AF_INET) { $read = ''; if (is_resource($process)) { - fclose($pipes[0]); while (!feof($pipes[1])) { @@ -1194,7 +1222,7 @@ function fping($host,$params,$address_family = AF_INET) { preg_match('/[0-9]+\/[0-9]+\/[0-9]+%/', $read, $loss_tmp); preg_match('/[0-9\.]+\/[0-9\.]+\/[0-9\.]*$/', $read, $latency); - $loss = preg_replace("/%/","",$loss_tmp[0]); + $loss = preg_replace("/%/", "", $loss_tmp[0]); list($xmt,$rcv,$loss) = preg_split("/\//", $loss); list($min,$avg,$max) = preg_split("/\//", $latency[0]); if ($loss < 0) { @@ -1206,11 +1234,13 @@ function fping($host,$params,$address_family = AF_INET) { return $response; } -function function_check($function) { +function function_check($function) +{ return function_exists($function); } -function force_influx_data($data) { +function force_influx_data($data) +{ /* * It is not trivial to detect if something is a float or an integer, and * therefore may cause breakages on inserts. @@ -1225,15 +1255,12 @@ function force_influx_data($data) { if (ctype_digit($data)) { return floatval($data); // Else it is a float - } - else { + } else { return floatval($data); } - } - else { + } else { return $data; } - }// end force_influx_data /** @@ -1248,7 +1275,8 @@ function force_influx_data($data) { * specifier: AF_INET for IPv4 (or local connections not associated * with an IP stack), AF_INET6 for IPv6. */ -function snmpTransportToAddressFamily($transport) { +function snmpTransportToAddressFamily($transport) +{ if (!isset($transport)) { $transport = 'udp'; } @@ -1257,8 +1285,7 @@ function snmpTransportToAddressFamily($transport) { if (in_array($transport, $ipv6_snmp_transport_specifiers)) { return AF_INET6; - } - else { + } else { return AF_INET; } } @@ -1271,19 +1298,18 @@ function snmpTransportToAddressFamily($transport) { * @return bool true if hostname already exists * false if hostname doesn't exist **/ -function host_exists($hostname, $snmphost='') { +function host_exists($hostname, $snmphost = '') +{ global $config; $count = dbFetchCell("SELECT COUNT(*) FROM `devices` WHERE `hostname` = ?", array($hostname)); if ($count > 0) { return true; - } - else { + } else { if ($config['allow_duplicate_sysName'] === false && !empty($snmphost)) { $count = dbFetchCell("SELECT COUNT(*) FROM `devices` WHERE `sysName` = ?", array($snmphost)); if ($count > 0) { return true; - } - else { + } else { return false; } } @@ -1296,7 +1322,8 @@ function host_exists($hostname, $snmphost='') { * * @return array including the current set size and the currently used buffer **/ -function innodb_buffer_check() { +function innodb_buffer_check() +{ $pool['size'] = dbFetchCell('SELECT @@innodb_buffer_pool_size'); // The following query is from the excellent mysqltuner.pl by Major Hayden https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl $pool['used'] = dbFetchCell('SELECT SUM(DATA_LENGTH+INDEX_LENGTH) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ("information_schema", "performance_schema", "mysql") AND ENGINE = "InnoDB" GROUP BY ENGINE ORDER BY ENGINE ASC'); @@ -1310,20 +1337,22 @@ function innodb_buffer_check() { * * @return string $output **/ -function warn_innodb_buffer($innodb_buffer) { +function warn_innodb_buffer($innodb_buffer) +{ $output = 'InnoDB Buffersize too small.'.PHP_EOL; $output .= 'Current size: '.($innodb_buffer['size'] / 1024 / 1024).' MiB'.PHP_EOL; $output .= 'Minimum Required: '.($innodb_buffer['used'] / 1024 / 1024).' MiB'.PHP_EOL; $output .= 'To ensure integrity, we\'re not going to pull any updates until the buffersize has been adjusted.'.PHP_EOL; - $output .= 'Config proposal: "innodb_buffer_pool_size = '.pow(2,ceil(log(($innodb_buffer['used'] / 1024 / 1024),2))).'M"'.PHP_EOL; + $output .= 'Config proposal: "innodb_buffer_pool_size = '.pow(2, ceil(log(($innodb_buffer['used'] / 1024 / 1024), 2))).'M"'.PHP_EOL; return $output; } -function oxidized_reload_nodes() { +function oxidized_reload_nodes() +{ global $config; - if ($config['oxidized']['enabled'] === TRUE && $config['oxidized']['reload_nodes'] === TRUE && isset($config['oxidized']['url'])) { + if ($config['oxidized']['enabled'] === true && $config['oxidized']['reload_nodes'] === true && isset($config['oxidized']['url'])) { $oxidized_reload_url = $config['oxidized']['url'] . '/reload?format=json'; $ch = curl_init($oxidized_reload_url); @@ -1345,7 +1374,8 @@ function oxidized_reload_nodes() { * @return string ip * **/ -function dnslookup($device,$type=false,$return=false) { +function dnslookup($device, $type = false, $return = false) +{ if (filter_var($device['hostname'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) == true || filter_var($device['hostname'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) == truee) { return ''; } @@ -1354,8 +1384,7 @@ function dnslookup($device,$type=false,$return=false) { if ($device['transport'] == 'udp6' || $device['transport'] == 'tcp6') { $type = DNS_AAAA; $return = 'ipv6'; - } - else { + } else { $type = DNS_A; $return = 'ip'; } @@ -1363,7 +1392,7 @@ function dnslookup($device,$type=false,$return=false) { if (empty($return)) { return ''; } - $record = dns_get_record($device['hostname'],$type); + $record = dns_get_record($device['hostname'], $type); return $record[0][$return]; }//end dnslookup @@ -1381,7 +1410,8 @@ function dnslookup($device,$type=false,$return=false) { * **/ -function rrdtest($path, &$stdOutput, &$stdError) { +function rrdtest($path, &$stdOutput, &$stdError) +{ global $config; //rrdtool info $command = $config['rrdtool'].' info '.escapeshellarg($path); @@ -1400,7 +1430,7 @@ function rrdtest($path, &$stdOutput, &$stdError) { } $status = proc_get_status($process); - while($status['running']) { + while ($status['running']) { usleep(2000); // Sleep 2000 microseconds or 2 milliseconds $status = proc_get_status($process); } @@ -1411,7 +1441,8 @@ function rrdtest($path, &$stdOutput, &$stdError) { return $status['exitcode']; } -function create_state_index($state_name) { +function create_state_index($state_name) +{ if (dbFetchRow('SELECT * FROM state_indexes WHERE state_name = ?', array($state_name)) !== true) { $insert = array('state_name' => $state_name); return dbInsert($insert, 'state_indexes'); @@ -1434,7 +1465,7 @@ function create_sensor_to_state_index($device, $state_name, $index) 'sensor_id' => $sensor_entry['sensor_id'], 'state_index_id' => $state_indexes_entry['state_index_id'], ); - foreach($insert as $key => $val_check) { + foreach ($insert as $key => $val_check) { if (!isset($val_check)) { unset($insert[$key]); } @@ -1444,19 +1475,20 @@ function create_sensor_to_state_index($device, $state_name, $index) } } -function delta_to_bits($delta,$period) { +function delta_to_bits($delta, $period) +{ return round(($delta * 8 / $period), 2); } -function report_this($message) { +function report_this($message) +{ global $config; return '

'.$message.' Please report this to the '.$config['project_name'].' developers.

'; - }//end report_this() -function hytera_h2f($number,$nd) +function hytera_h2f($number, $nd) { - if (strlen(str_replace(" ","",$number)) == 4) { + if (strlen(str_replace(" ", "", $number)) == 4) { $hex = ''; for ($i = 0; $i < strlen($number); $i++) { $byte = strtoupper(dechex(ord($number{$i}))); @@ -1476,7 +1508,7 @@ function hytera_h2f($number,$nd) $number = substr($r, 0, -1); //$number = str_replace(" ", "", $number); for ($i=0; $i $v) { - $v = preg_replace(array('/ /','/,/','/=/'),array('\ ','\,','\='), $v); + $v = preg_replace(array('/ /','/,/','/=/'), array('\ ','\,','\='), $v); if (empty($v)) { $v = '_blank_'; } @@ -59,9 +57,9 @@ function influx_update($device,$measurement,$tags=array(),$fields) { } foreach ($fields as $k => $v) { $tmp_fields[$k] = force_influx_data($v); - if( $tmp_fields[$k] === null) { - unset($tmp_fields[$k]); - } + if ($tmp_fields[$k] === null) { + unset($tmp_fields[$k]); + } } d_echo("\nInfluxDB data:\n"); @@ -85,10 +83,8 @@ function influx_update($device,$measurement,$tags=array(),$fields) { d_echo("Caught exception: " . $e->getMessage() . PHP_EOL); d_echo($e->getTrace()); } - } - else { + } else { c_echo("[%gInfluxDB Disabled%n]\n"); }//end if }//end if }// end influx_update - diff --git a/includes/load_db_graph_types.inc.php b/includes/load_db_graph_types.inc.php index dc7f605859..e970ada325 100644 --- a/includes/load_db_graph_types.inc.php +++ b/includes/load_db_graph_types.inc.php @@ -18,8 +18,7 @@ foreach (dbFetchRows('select * from graph_types') as $graph) { if (strpos($k, 'graph_') == 0) { // remove leading 'graph_' from column name $key = str_replace('graph_', '', $k); - } - else { + } else { $key = $k; } $g[$key] = $v; diff --git a/includes/mergecnf.inc.php b/includes/mergecnf.inc.php index 07ba8921d1..1ddb758d45 100644 --- a/includes/mergecnf.inc.php +++ b/includes/mergecnf.inc.php @@ -25,7 +25,8 @@ */ -function mergecnf($obj) { +function mergecnf($obj) +{ $pointer = array(); $val = $obj['config_value']; $obj = $obj['config_name']; @@ -33,25 +34,20 @@ function mergecnf($obj) { if (!isset($obj[1])) { if (filter_var($val, FILTER_VALIDATE_INT)) { $val = (int) $val; - } - else if (filter_var($val, FILTER_VALIDATE_FLOAT)) { + } elseif (filter_var($val, FILTER_VALIDATE_FLOAT)) { $val = (float) $val; - } - else if (filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null) { + } elseif (filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null) { $val = filter_var($val, FILTER_VALIDATE_BOOLEAN); } if (!empty($obj[0])) { return array($obj[0] => $val); - } - else { + } else { return array($val); } - } - else { + } else { $pointer[$obj[0]] = mergecnf(array('config_name' => $obj[1], 'config_value' => $val)); } return $pointer; - }//end mergecnf() diff --git a/includes/notifications.php b/includes/notifications.php index 9a7fa587fa..30bf7a525d 100644 --- a/includes/notifications.php +++ b/includes/notifications.php @@ -31,19 +31,22 @@ require_once $config['install_dir'].'/includes/functions.php'; * Pull notifications from remotes * @return array Notifications */ -function get_notifications() { +function get_notifications() +{ global $config; $obj = array(); - foreach ($config['notifications'] as $name=>$url) { + foreach ($config['notifications'] as $name => $url) { echo '[ '.date('r').' ] '.$url.' '; - $feed = json_decode(json_encode(simplexml_load_string(file_get_contents($url))),true); + $feed = json_decode(json_encode(simplexml_load_string(file_get_contents($url))), true); if (isset($feed['channel'])) { $feed = parse_rss($feed); } else { $feed = parse_atom($feed); } - array_walk($feed,function(&$items,$key,$url) { $items['source'] = $url; },$url); - $obj = array_merge($obj,$feed); + array_walk($feed, function (&$items, $key, $url) { + $items['source'] = $url; + }, $url); + $obj = array_merge($obj, $feed); echo '('.sizeof($obj).')'.PHP_EOL; } $obj = array_sort($obj, 'datetime'); @@ -54,11 +57,12 @@ function get_notifications() { * Post notifications to users * @return null */ -function post_notifications() { +function post_notifications() +{ $notifs = get_notifications(); echo '[ '.date('r').' ] Updating DB '; foreach ($notifs as $notif) { - if (dbFetchCell('select 1 from notifications where checksum = ?',array($notif['checksum'])) != 1 && dbInsert('notifications',$notif) > 0) { + if (dbFetchCell('select 1 from notifications where checksum = ?', array($notif['checksum'])) != 1 && dbInsert('notifications', $notif) > 0) { echo '.'; } } @@ -71,16 +75,17 @@ function post_notifications() { * @param array $feed RSS Object * @return array Parsed Object */ -function parse_rss($feed) { +function parse_rss($feed) +{ $obj = array(); - if( !array_key_exists('0',$feed['channel']['item']) ) { + if (!array_key_exists('0', $feed['channel']['item'])) { $feed['channel']['item'] = array( $feed['channel']['item'] ); } foreach ($feed['channel']['item'] as $item) { $obj[] = array( 'title'=>$item['title'], 'body'=>$item['description'], - 'checksum'=>hash('sha512',$item['title'].$item['description']), + 'checksum'=>hash('sha512', $item['title'].$item['description']), 'datetime'=>strftime('%F', strtotime($item['pubDate'])) ); } @@ -92,16 +97,17 @@ function parse_rss($feed) { * @param array $feed Atom Object * @return array Parsed Object */ -function parse_atom($feed) { +function parse_atom($feed) +{ $obj = array(); - if( !array_key_exists('0',$feed['entry']) ) { + if (!array_key_exists('0', $feed['entry'])) { $feed['entry'] = array( $feed['entry'] ); } foreach ($feed['entry'] as $item) { $obj[] = array( 'title'=>$item['title'], 'body'=>$item['content'], - 'checksum'=>hash('sha512',$item['title'].$item['content']), + 'checksum'=>hash('sha512', $item['title'].$item['content']), 'datetime'=>strftime('%F', strtotime($item['updated'])) ); } diff --git a/includes/polling/altiga-ssl.inc.php b/includes/polling/altiga-ssl.inc.php index dbcf9e1c45..e8ec9fe2ab 100644 --- a/includes/polling/altiga-ssl.inc.php +++ b/includes/polling/altiga-ssl.inc.php @@ -36,8 +36,7 @@ if ($device['os'] == 'asa' || $device['os'] == 'pix') { if ($value > 0) { $got_value = true; } - } - else { + } else { $value = '0'; } $fields[$oid] = $value; diff --git a/includes/polling/applications.inc.php b/includes/polling/applications.inc.php index 3e552a27fc..8a7410b9bc 100644 --- a/includes/polling/applications.inc.php +++ b/includes/polling/applications.inc.php @@ -10,8 +10,7 @@ if (count($app_rows)) { $app_include = $config['install_dir'].'/includes/polling/applications/'.$app['app_type'].'.inc.php'; if (is_file($app_include)) { include $app_include; - } - else { + } else { echo $app['app_type'].' include missing! '; } } diff --git a/includes/polling/applications/apache.inc.php b/includes/polling/applications/apache.inc.php index 4b1b2cbef7..93bc1fbefb 100644 --- a/includes/polling/applications/apache.inc.php +++ b/includes/polling/applications/apache.inc.php @@ -5,8 +5,7 @@ $name = 'apache'; $app_id = $app['app_id']; if (!empty($agent_data['app'][$name])) { $apache = $agent_data['app'][$name]; -} -else { +} else { $options = '-O qv'; $oid = 'nsExtendOutputFull.6.97.112.97.99.104.101'; $apache = snmp_get($device, $oid, $options); @@ -68,4 +67,3 @@ $fields = array( $tags = compact('name', 'app_id', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); - diff --git a/includes/polling/applications/bind.inc.php b/includes/polling/applications/bind.inc.php index 52a577a338..a25b2a50ba 100644 --- a/includes/polling/applications/bind.inc.php +++ b/includes/polling/applications/bind.inc.php @@ -44,8 +44,7 @@ if (!empty($agent_data['app'][$name]) && $app_id > 0) { if (!empty($matches)) { if ($matches[1] == 'default') { continue; - } - else { + } else { $view = $matches[1]; } } @@ -63,8 +62,7 @@ if (!empty($agent_data['app'][$name]) && $app_id > 0) { $item = str_replace(' ', '_', strtolower($matches[2])); if (!empty($view)) { $bind_parsed[$prefix][$view][$item] = $cnt; - } - else { + } else { $bind_parsed[$prefix][$item] = $cnt; } } @@ -99,5 +97,4 @@ if (!empty($agent_data['app'][$name]) && $app_id > 0) { $tags = compact('name', 'app_id', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); - }//end if diff --git a/includes/polling/applications/ceph.inc.php b/includes/polling/applications/ceph.inc.php index fc29364fa1..96de49513e 100644 --- a/includes/polling/applications/ceph.inc.php +++ b/includes/polling/applications/ceph.inc.php @@ -5,8 +5,9 @@ if (!empty($agent_data['app'][$name])) { $app_id = $app['app_id']; foreach (explode('<', $agent_data['app'][$name]) as $section) { - if (empty($section)) + if (empty($section)) { continue; + } list($section, $data) = explode('>', $section); if ($section == "poolstats") { @@ -17,8 +18,9 @@ if (!empty($agent_data['app'][$name])) { ); foreach (explode("\n", $data) as $line) { - if (empty($line)) + if (empty($line)) { continue; + } list($pool,$ops,$wrbytes,$rbytes) = explode(':', $line); $rrd_name = array('app', $name, $app_id, 'pool', $pool); @@ -31,16 +33,16 @@ if (!empty($agent_data['app'][$name])) { $tags = compact('name', 'app_id', 'pool', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); } - } - elseif ($section == "osdperformance") { + } elseif ($section == "osdperformance") { $rrd_def = array( 'DS:apply_ms:GAUGE:600:0:U', 'DS:commit_ms:GAUGE:600:0:U' ); foreach (explode("\n", $data) as $line) { - if (empty($line)) + if (empty($line)) { continue; + } list($osd,$apply,$commit) = explode(':', $line); $rrd_name = array('app', $name, $app_id, 'osd', $osd); @@ -52,8 +54,7 @@ if (!empty($agent_data['app'][$name])) { $tags = compact('name', 'app_id', 'osd', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); } - } - elseif ($section == "df") { + } elseif ($section == "df") { $rrd_def = array( 'DS:avail:GAUGE:600:0:U', 'DS:used:GAUGE:600:0:U', @@ -61,8 +62,9 @@ if (!empty($agent_data['app'][$name])) { ); foreach (explode("\n", $data) as $line) { - if (empty($line)) + if (empty($line)) { continue; + } list($df,$avail,$used,$objects) = explode(':', $line); $rrd_name = array('app', $name, $app_id, 'df', $df); diff --git a/includes/polling/applications/dhcp-stats.inc.php b/includes/polling/applications/dhcp-stats.inc.php index ba85fbbe86..d36a7508f7 100644 --- a/includes/polling/applications/dhcp-stats.inc.php +++ b/includes/polling/applications/dhcp-stats.inc.php @@ -1,37 +1,37 @@ - $dhcp_total, - 'dhcp_active' => $dhcp_active, - 'dhcp_expired' => $dhcp_expired, - 'dhcp_released' => $dhcp_released, - 'dhcp_abandoned' => $dhcp_abandoned, - 'dhcp_reset' => $dhcp_reset, - 'dhcp_bootp' => $dhcp_bootp, - 'dhcp_backup' => $dhcp_backup, - 'dhcp_free' => $dhcp_free, -); - -$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name); -data_update($device, 'app', $tags, $fields); + $dhcp_total, + 'dhcp_active' => $dhcp_active, + 'dhcp_expired' => $dhcp_expired, + 'dhcp_released' => $dhcp_released, + 'dhcp_abandoned' => $dhcp_abandoned, + 'dhcp_reset' => $dhcp_reset, + 'dhcp_bootp' => $dhcp_bootp, + 'dhcp_backup' => $dhcp_backup, + 'dhcp_free' => $dhcp_free, +); + +$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name); +data_update($device, 'app', $tags, $fields); diff --git a/includes/polling/applications/freeswitch.inc.php b/includes/polling/applications/freeswitch.inc.php index 9b3dd2f6c9..1fb19cb5c8 100644 --- a/includes/polling/applications/freeswitch.inc.php +++ b/includes/polling/applications/freeswitch.inc.php @@ -8,11 +8,11 @@ if (!empty($agent_data[$name])) { return; } # Format Data -$lines = explode("\n",$rawdata); +$lines = explode("\n", $rawdata); $freeswitch = array(); foreach ($lines as $line) { - list($var,$value) = explode('=',$line); - $freeswitch[$var] = $value; + list($var,$value) = explode('=', $line); + $freeswitch[$var] = $value; } # Freeswitch stats $rrd_name = array('app', $name, 'stats', $app_id); @@ -29,10 +29,10 @@ $fields = array ( 'calls' => $freeswitch['Calls'], 'channels' => $freeswitch['Channels'], 'peak' => $freeswitch['Peak'], - 'in_failed' => $freeswitch['InFailed'], - 'in_okay' => $freeswitch['InTotal']-$freeswitch['InFailed'], - 'out_failed' => $freeswitch['OutFailed'], - 'out_okay' => $freeswitch['OutTotal']-$freeswitch['OutFailed'] + 'in_failed' => $freeswitch['InFailed'], + 'in_okay' => $freeswitch['InTotal']-$freeswitch['InFailed'], + 'out_failed' => $freeswitch['OutFailed'], + 'out_okay' => $freeswitch['OutTotal']-$freeswitch['OutFailed'] ); $tags = compact('name', 'app_id', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); diff --git a/includes/polling/applications/mailscanner.inc.php b/includes/polling/applications/mailscanner.inc.php index 6dbb6977cb..601cfa7afd 100644 --- a/includes/polling/applications/mailscanner.inc.php +++ b/includes/polling/applications/mailscanner.inc.php @@ -36,4 +36,3 @@ $fields = array( $tags = compact('name', 'app_id', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); - diff --git a/includes/polling/applications/memcached.inc.php b/includes/polling/applications/memcached.inc.php index df538ccd3c..081904b3d5 100644 --- a/includes/polling/applications/memcached.inc.php +++ b/includes/polling/applications/memcached.inc.php @@ -58,4 +58,3 @@ $fields = array( $tags = compact('name', 'app_id', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); - diff --git a/includes/polling/applications/mysql.inc.php b/includes/polling/applications/mysql.inc.php index 1d15efa560..4cb1551637 100644 --- a/includes/polling/applications/mysql.inc.php +++ b/includes/polling/applications/mysql.inc.php @@ -5,8 +5,7 @@ $name = 'mysql'; $app_id = $app['app_id']; if (!empty($agent_data['app'][$name])) { $mysql = $agent_data['app'][$name]; -} -else { +} else { // Polls MySQL statistics from script via SNMP $mysql_cmd = $config['snmpget'].' -m NET-SNMP-EXTEND-MIB -O qv '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; $mysql_cmd .= ' nsExtendOutputFull.5.109.121.115.113.108'; @@ -228,4 +227,3 @@ foreach ($mapping_status as $desc => $id) { $status = true; $tags = compact('name', 'app_id', 'status', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); - diff --git a/includes/polling/applications/nfs-stats.inc.php b/includes/polling/applications/nfs-stats.inc.php index 95beeddd7c..ad2a5d93e9 100644 --- a/includes/polling/applications/nfs-stats.inc.php +++ b/includes/polling/applications/nfs-stats.inc.php @@ -48,4 +48,4 @@ $fields = array( $tags = compact('name', 'app_id', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); -unset($nfsstats, $rrd_name, $rrd_def, $data, $fields, $tags); \ No newline at end of file +unset($nfsstats, $rrd_name, $rrd_def, $data, $fields, $tags); diff --git a/includes/polling/applications/nfs-v3-stats.inc.php b/includes/polling/applications/nfs-v3-stats.inc.php index c01eb079a6..928cfad2d1 100644 --- a/includes/polling/applications/nfs-v3-stats.inc.php +++ b/includes/polling/applications/nfs-v3-stats.inc.php @@ -124,4 +124,4 @@ $fields = array( $tags = compact('name', 'app_id', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); -unset($nfsstats, $rrd_name, $rrd_def, $data, $fields, $tags); \ No newline at end of file +unset($nfsstats, $rrd_name, $rrd_def, $data, $fields, $tags); diff --git a/includes/polling/applications/nginx.inc.php b/includes/polling/applications/nginx.inc.php index 7a25e697ac..3e3f6f80b7 100644 --- a/includes/polling/applications/nginx.inc.php +++ b/includes/polling/applications/nginx.inc.php @@ -4,8 +4,7 @@ $name = 'nginx'; $app_id = $app['app_id']; if (!empty($agent_data['app'][$name])) { $nginx = $agent_data['app'][$name]; -} -else { +} else { // Polls nginx statistics from script via SNMP $nginx = snmp_get($device, 'nsExtendOutputFull.5.110.103.105.110.120', '-Ovq', 'NET-SNMP-EXTEND-MIB'); } diff --git a/includes/polling/applications/ntp-client.inc.php b/includes/polling/applications/ntp-client.inc.php index f8195b3de0..820648cf22 100644 --- a/includes/polling/applications/ntp-client.inc.php +++ b/includes/polling/applications/ntp-client.inc.php @@ -30,4 +30,3 @@ $fields = array( $tags = compact('name', 'app_id', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); - diff --git a/includes/polling/applications/os-updates.inc.php b/includes/polling/applications/os-updates.inc.php index 7bc14647f2..ddc5d27b43 100644 --- a/includes/polling/applications/os-updates.inc.php +++ b/includes/polling/applications/os-updates.inc.php @@ -1,18 +1,18 @@ - $osupdates,); - -$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name); -data_update($device, 'app', $tags, $fields); + $osupdates,); + +$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name); +data_update($device, 'app', $tags, $fields); diff --git a/includes/polling/applications/powerdns.inc.php b/includes/polling/applications/powerdns.inc.php index bf602d9f5f..de0d2ae13f 100644 --- a/includes/polling/applications/powerdns.inc.php +++ b/includes/polling/applications/powerdns.inc.php @@ -9,8 +9,7 @@ $name = 'powerdns'; $app_id = $app['app_id']; if ($agent_data['app'][$name]) { $powerdns = $agent_data['app'][$name]; -} -else { +} else { $powerdns = snmp_get($device, $oid, $options, $mib); } @@ -75,4 +74,3 @@ $fields = array( $tags = compact('name', 'app_id', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); - diff --git a/includes/polling/applications/proxmox.inc.php b/includes/polling/applications/proxmox.inc.php index 7f783a3b0c..45cf860d5a 100644 --- a/includes/polling/applications/proxmox.inc.php +++ b/includes/polling/applications/proxmox.inc.php @@ -7,7 +7,8 @@ * @param integer $i VM ID * @return integer|boolean The port-ID if the port exists, false if it doesn't exist */ -function proxmox_port_exists($i, $c, $p) { +function proxmox_port_exists($i, $c, $p) +{ if ($row = dbFetchRow("SELECT pmp.id FROM proxmox_ports pmp, proxmox pm WHERE pm.id = pmp.vm_id AND pmp.port = ? AND pm.cluster = ? AND pm.vmid = ?", array($p, $c, $i))) { return $row['id']; } @@ -22,7 +23,8 @@ function proxmox_port_exists($i, $c, $p) { * @param array $pmxcache Reference to the Proxmox VM Cache * @return boolean true if the VM exists, false if it doesn't */ -function proxmox_vm_exists($i, $c, &$pmxcache) { +function proxmox_vm_exists($i, $c, &$pmxcache) +{ if (isset($pmxcache[$c][$i]) && $pmxcache[$c][$i] > 0) { return true; @@ -51,8 +53,12 @@ if (isset($config['enable_proxmox']) && $config['enable_proxmox'] && !empty($age if ($proxmox) { $pmxlines = explode("\n", $proxmox); $pmxcluster = array_shift($pmxlines); - dbUpdate(array('device_id' => $device['device_id'], 'app_type' => $name, 'app_instance' => $pmxcluster), - 'applications', '`device_id` = ? AND `app_type` = ?', array($device['device_id'], $name)); + dbUpdate( + array('device_id' => $device['device_id'], 'app_type' => $name, 'app_instance' => $pmxcluster), + 'applications', + '`device_id` = ? AND `app_type` = ?', + array($device['device_id'], $name) + ); if (count($pmxlines) > 0) { $pmxcache = array(); @@ -94,8 +100,12 @@ if ($proxmox) { } if ($portid = proxmox_port_exists($vmid, $pmxcluster, $vmport) !== false) { - dbUpdate(array('last_seen' => array('NOW()')), 'proxmox_ports', '`vm_id` = ? AND `port` = ?', - array($pmxcache[$pmxcluster][$vmid], $vmport)); + dbUpdate( + array('last_seen' => array('NOW()')), + 'proxmox_ports', + '`vm_id` = ? AND `port` = ?', + array($pmxcache[$pmxcluster][$vmid], $vmport) + ); } else { dbInsert(array('vm_id' => $pmxcache[$pmxcluster][$vmid], 'port' => $vmport), 'proxmox_ports'); } diff --git a/includes/polling/applications/shoutcast.inc.php b/includes/polling/applications/shoutcast.inc.php index ceaa9f08eb..f5a9c0cc54 100644 --- a/includes/polling/applications/shoutcast.inc.php +++ b/includes/polling/applications/shoutcast.inc.php @@ -44,6 +44,5 @@ foreach ($servers as $item => $server) { $tags = compact('name', 'app_id', 'host', 'port', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); - }//end if }//end foreach diff --git a/includes/polling/applications/tinydns.inc.php b/includes/polling/applications/tinydns.inc.php index 677d5c21d7..8750e63c36 100644 --- a/includes/polling/applications/tinydns.inc.php +++ b/includes/polling/applications/tinydns.inc.php @@ -54,5 +54,4 @@ if (!empty($agent_data['app'][$name]) && $app_id > 0) { $tags = compact('name', 'app_id', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); - }//end if diff --git a/includes/polling/applications/unbound.inc.php b/includes/polling/applications/unbound.inc.php index ebb044ae16..d142d90fd5 100644 --- a/includes/polling/applications/unbound.inc.php +++ b/includes/polling/applications/unbound.inc.php @@ -3,59 +3,59 @@ $name = 'unbound'; $app_id = $app['app_id']; if (!empty($agent_data['app'][$name])) { $rawdata = $agent_data['app'][$name]; -}else{ - echo "Unbound Missing"; - return; +} else { + echo "Unbound Missing"; + return; } #Format Data -$lines = explode("\n",$rawdata); +$lines = explode("\n", $rawdata); $unbound = array(); foreach ($lines as $line) { - list($var,$value) = explode('=',$line); - $unbound[$var] = $value; + list($var,$value) = explode('=', $line); + $unbound[$var] = $value; } #Unbound Queries $rrd_name = array('app', $name,'queries',$app_id); $rrd_def = array( - 'DS:type0:DERIVE:600:0:125000000000', - 'DS:A:DERIVE:600:0:125000000000', - 'DS:NS:DERIVE:600:0:125000000000', - 'DS:CNAME:DERIVE:600:0:125000000000', - 'DS:SOA:DERIVE:600:0:125000000000', - 'DS:NULL:DERIVE:600:0:125000000000', - 'DS:WKS:DERIVE:600:0:125000000000', - 'DS:PTR:DERIVE:600:0:125000000000', - 'DS:MX:DERIVE:600:0:125000000000', - 'DS:TXT:DERIVE:600:0:125000000000', - 'DS:AAAA:DERIVE:600:0:125000000000', - 'DS:SRV:DERIVE:600:0:125000000000', - 'DS:NAPTR:DERIVE:600:0:125000000000', - 'DS:DS:DERIVE:600:0:125000000000', - 'DS:DNSKEY:DERIVE:600:0:125000000000', - 'DS:SPF:DERIVE:600:0:125000000000', - 'DS:ANY:DERIVE:600:0:125000000000', - 'DS:other:DERIVE:600:0:125000000000' - ); + 'DS:type0:DERIVE:600:0:125000000000', + 'DS:A:DERIVE:600:0:125000000000', + 'DS:NS:DERIVE:600:0:125000000000', + 'DS:CNAME:DERIVE:600:0:125000000000', + 'DS:SOA:DERIVE:600:0:125000000000', + 'DS:NULL:DERIVE:600:0:125000000000', + 'DS:WKS:DERIVE:600:0:125000000000', + 'DS:PTR:DERIVE:600:0:125000000000', + 'DS:MX:DERIVE:600:0:125000000000', + 'DS:TXT:DERIVE:600:0:125000000000', + 'DS:AAAA:DERIVE:600:0:125000000000', + 'DS:SRV:DERIVE:600:0:125000000000', + 'DS:NAPTR:DERIVE:600:0:125000000000', + 'DS:DS:DERIVE:600:0:125000000000', + 'DS:DNSKEY:DERIVE:600:0:125000000000', + 'DS:SPF:DERIVE:600:0:125000000000', + 'DS:ANY:DERIVE:600:0:125000000000', + 'DS:other:DERIVE:600:0:125000000000' + ); $fields = array ( - 'type0' => $unbound['num.query.type.TYPE0'], - 'a' => $unbound['num.query.type.A'], - 'ns' => $unbound['num.query.type.NS'], - 'cname' => $unbound['num.query.type.CNAME'], - 'soa' => $unbound['num.query.type.SOA'], - 'null' => $unbound['num.query.type.NULL'], - 'wks' => $unbound['num.query.type.WKS'], - 'ptr' => $unbound['num.query.type.PTR'], - 'mx' => $unbound['num.query.type.MX'], - 'txt' => $unbound['num.query.type.TXT'], - 'aaaa' => $unbound['num.query.type.AAAA'], - 'srv' => $unbound['num.query.type.SRV'], - 'naptr' => $unbound['num.query.type.NAPTR'], - 'ds' => $unbound['num.query.type.DS'], - 'dnskey' => $unbound['num.query.type.DNSKEY'], - 'spf' => $unbound['num.query.type.SPF'], - 'any' => $unbound['num.query.type.ANY'], - 'other' => $unbound['num.query.type.other'] - ); + 'type0' => $unbound['num.query.type.TYPE0'], + 'a' => $unbound['num.query.type.A'], + 'ns' => $unbound['num.query.type.NS'], + 'cname' => $unbound['num.query.type.CNAME'], + 'soa' => $unbound['num.query.type.SOA'], + 'null' => $unbound['num.query.type.NULL'], + 'wks' => $unbound['num.query.type.WKS'], + 'ptr' => $unbound['num.query.type.PTR'], + 'mx' => $unbound['num.query.type.MX'], + 'txt' => $unbound['num.query.type.TXT'], + 'aaaa' => $unbound['num.query.type.AAAA'], + 'srv' => $unbound['num.query.type.SRV'], + 'naptr' => $unbound['num.query.type.NAPTR'], + 'ds' => $unbound['num.query.type.DS'], + 'dnskey' => $unbound['num.query.type.DNSKEY'], + 'spf' => $unbound['num.query.type.SPF'], + 'any' => $unbound['num.query.type.ANY'], + 'other' => $unbound['num.query.type.other'] + ); $tags = compact('name', 'app_id', 'rrd_name', 'rrd_def'); data_update($device, 'app', $tags, $fields); -unset($lines , $unbound, $rrd_name, $rrd_def, $fields, $tags); \ No newline at end of file +unset($lines , $unbound, $rrd_name, $rrd_def, $fields, $tags); diff --git a/includes/polling/aruba-controller.inc.php b/includes/polling/aruba-controller.inc.php index 4c5a26ef12..78b5404b26 100644 --- a/includes/polling/aruba-controller.inc.php +++ b/includes/polling/aruba-controller.inc.php @@ -56,7 +56,7 @@ if ($device['type'] == 'wireless' && $device['os'] == 'arubaos') { ); $tags = compact('rrd_name', 'rrd_def'); - data_update($device,'aruba-controller',$tags,$fields); + data_update($device, 'aruba-controller', $tags, $fields); // also save the info about how many clients in the same place as the wireless module $rrd_name = 'wificlients-radio1'; @@ -71,7 +71,7 @@ if ($device['type'] == 'wireless' && $device['os'] == 'arubaos') { 'rrd_name' => $rrd_name, 'rrd_def' => $rrd_def ); - data_update($device,'wificlients',$tags,$fields); + data_update($device, 'wificlients', $tags, $fields); $graphs['wifi_clients'] = true; @@ -137,7 +137,7 @@ if ($device['type'] == 'wireless' && $device['os'] == 'arubaos') { 'rrd_def' => $rrd_def ); - data_update($device,'aruba',$tags,$fields); + data_update($device, 'aruba', $tags, $fields); } // generate the mac address @@ -164,8 +164,7 @@ if ($device['type'] == 'wireless' && $device['os'] == 'arubaos') { if ($foundid == 0) { $ap_id = dbInsert(array('device_id' => $device['device_id'], 'name' => $name, 'radio_number' => $radionum, 'type' => $type, 'mac_addr' => $mac, 'channel' => $channel, 'txpow' => $txpow, 'radioutil' => $radioutil, 'numasoclients' => $numasoclients, 'nummonclients' => $nummonclients, 'numactbssid' => $numactbssid, 'nummonbssid' => $nummonbssid, 'interference' => $interference), 'access_points'); - } - else { + } else { dbUpdate(array('mac_addr' => $mac, 'deleted' => 0, 'channel' => $channel, 'txpow' => $txpow, 'radioutil' => $radioutil, 'numasoclients' => $numasoclients, 'nummonclients' => $nummonclients, 'numactbssid' => $numactbssid, 'nummonbssid' => $nummonbssid, 'interference' => $interference), 'access_points', '`accesspoint_id` = ?', array($foundid)); } }//end foreach diff --git a/includes/polling/bgp-peers.inc.php b/includes/polling/bgp-peers.inc.php index 1d1dbee9dc..a037158a05 100644 --- a/includes/polling/bgp-peers.inc.php +++ b/includes/polling/bgp-peers.inc.php @@ -1,11 +1,9 @@ 0) { if (strstr($peer['bgpPeerIdentifier'], ':')) { $bgp_peer_ident = ipv62snmp($peer['bgpPeerIdentifier']); - } - else { + } else { $bgp_peer_ident = $peer['bgpPeerIdentifier']; } @@ -39,8 +36,7 @@ if ($config['enable_bgp']) { $ip_type = 2; $ip_len = 16; $ip_ver = 'ipv6'; - } - else { + } else { $ip_type = 1; $ip_len = 4; $ip_ver = 'ipv4'; @@ -64,16 +60,14 @@ if ($config['enable_bgp']) { $v = rtrim($v); $v = preg_replace('/(\S+\s+\S+)\s/', '$1:', $v); $v = strtolower($v); - } - else { + } else { $v = hex_to_ip($v); } } $peer_data .= "$v\n"; } - } - else { + } else { $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; $peer_cmd .= 'bgpPeerState.'.$peer['bgpPeerIdentifier'].' bgpPeerAdminStatus.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerOutUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerInTotalMessages.'.$peer['bgpPeerIdentifier'].' '; $peer_cmd .= 'bgpPeerOutTotalMessages.'.$peer['bgpPeerIdentifier'].' bgpPeerFsmEstablishedTime.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdateElapsedTime.'.$peer['bgpPeerIdentifier'].' '; @@ -83,9 +77,7 @@ if ($config['enable_bgp']) { d_echo($peer_data); list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); - } - elseif ($device['os'] == 'junos') { - + } elseif ($device['os'] == 'junos') { if (!isset($junos)) { echo "\nCaching Oids..."; // FIXME - needs moved to function @@ -147,11 +139,9 @@ if ($config['enable_bgp']) { if (!(is_array($config['alerts']['bgp']['whitelist']) && !in_array($peer['bgpPeerRemoteAs'], $config['alerts']['bgp']['whitelist'])) && ($bgpPeerFsmEstablishedTime < $peer['bgpPeerFsmEstablishedTime'] || $bgpPeerState != $peer['bgpPeerState'])) { if ($peer['bgpPeerState'] == $bgpPeerState) { log_event('BGP Session Flap: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); - } - else if ($bgpPeerState == 'established') { + } elseif ($bgpPeerState == 'established') { log_event('BGP Session Up: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); - } - else if ($peer['bgpPeerState'] == 'established') { + } elseif ($peer['bgpPeerState'] == 'established') { log_event('BGP Session Down: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); } } @@ -179,7 +169,7 @@ if ($config['enable_bgp']) { 'rrd_name' => $peer_rrd_name, 'rrd_def' => $peer_rrd_def ); - data_update($device,'bgp',$tags,$fields); + data_update($device, 'bgp', $tags, $fields); $peer['update']['bgpPeerState'] = $bgpPeerState; $peer['update']['bgpPeerAdminStatus'] = $bgpPeerAdminStatus; @@ -204,8 +194,7 @@ if ($config['enable_bgp']) { $ip_type = 2; $ip_len = 16; $ip_ver = 'ipv6'; - } - else { + } else { $ip_type = 1; $ip_len = 4; $ip_ver = 'ipv4'; @@ -214,11 +203,9 @@ if ($config['enable_bgp']) { $ip_cast = 1; if ($peer_afi['safi'] == 'multicast') { $ip_cast = 2; - } - else if ($peer_afi['safi'] == 'unicastAndMulticast') { + } elseif ($peer_afi['safi'] == 'unicastAndMulticast') { $ip_cast = 3; - } - else if ($peer_afi['safi'] == 'vpn') { + } elseif ($peer_afi['safi'] == 'vpn') { $ip_cast = 128; } @@ -250,8 +237,7 @@ if ($config['enable_bgp']) { } d_echo("$cbgp_data\n"); - } - else { + } else { // FIXME - move to function $oids = " cbgpPeerAcceptedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; $oids .= " cbgpPeerDeniedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; @@ -264,7 +250,7 @@ if ($config['enable_bgp']) { d_echo("$oids\n"); - $cbgp_data= snmp_get_multi($device,$oids,'-OUQs ','CISCO-BGP4-MIB'); + $cbgp_data= snmp_get_multi($device, $oids, '-OUQs ', 'CISCO-BGP4-MIB'); $cbgp_data= array_pop($cbgp_data); d_echo("$cbgp_data\n"); }//end if @@ -295,7 +281,6 @@ if ($config['enable_bgp']) { $cbgpPeerAcceptedPrefixes = array_shift($j_prefixes['1.3.6.1.4.1.2636.5.1.1.2.6.2.1.8.'.$junos[$peer_ip]['index'].".$afis[$afi].".$safis[$safi]]); $cbgpPeerDeniedPrefixes = array_shift($j_prefixes['1.3.6.1.4.1.2636.5.1.1.2.6.2.1.9.'.$junos[$peer_ip]['index'].".$afis[$afi].".$safis[$safi]]); $cbgpPeerAdvertisedPrefixes = array_shift($j_prefixes['1.3.6.1.4.1.2636.5.1.1.2.6.2.1.10.'.$junos[$peer_ip]['index'].".$afis[$afi].".$safis[$safi]]); - }//end if // FIXME THESE FIELDS DO NOT EXIST IN THE DATABASE! @@ -348,8 +333,7 @@ if ($config['enable_bgp']) { 'rrd_name' => $cbgp_rrd_name, 'rrd_def' => $cbgp_rrd_def ); - data_update($device,'cbgp',$tags,$fields); - + data_update($device, 'cbgp', $tags, $fields); } //end foreach } //end if echo "\n"; diff --git a/includes/polling/cipsec-tunnels.inc.php b/includes/polling/cipsec-tunnels.inc.php index b8643dd3e7..e75a0c720d 100644 --- a/includes/polling/cipsec-tunnels.inc.php +++ b/includes/polling/cipsec-tunnels.inc.php @@ -53,8 +53,7 @@ foreach ($ipsec_array as $index => $tunnel) { if (!is_array($tunnels[$tunnel['cikeTunRemoteValue']]) && !empty($tunnel['cikeTunRemoteValue'])) { $tunnel_id = dbInsert(array('device_id' => $device['device_id'], 'peer_addr' => $tunnel['cikeTunRemoteValue'], 'local_addr' => $tunnel['cikeTunLocalValue'], 'tunnel_name' => $tunnel['cikeTunLocalName']), 'ipsec_tunnels'); $valid_tunnels[] = $tunnel_id; - } - else { + } else { foreach ($db_oids as $db_oid => $db_value) { $db_update[$db_value] = $tunnel[$db_oid]; } @@ -86,8 +85,7 @@ foreach ($ipsec_array as $index => $tunnel) { foreach ($oids as $oid) { if (is_numeric($tunnel[$oid])) { $value = $tunnel[$oid]; - } - else { + } else { $value = '0'; } $fields[$oid] = $value; @@ -95,7 +93,7 @@ foreach ($ipsec_array as $index => $tunnel) { if (isset($tunnel['cikeTunRemoteValue'])) { $tags = compact('address', 'rrd_name', 'rrd_def'); - data_update($device,'ipsectunnel',$tags,$fields); + data_update($device, 'ipsectunnel', $tags, $fields); // $graphs['ipsec_tunnels'] = TRUE; } @@ -109,4 +107,4 @@ if (is_array($valid_tunnels)) { dbDelete('ipsec_tunnels', "`tunnel_id` NOT IN (".implode(',', $valid_tunnels).") AND `device_id`=?", array($device['device_id'])); } -unset($rrd_name,$rrd_def,$fields,$oids, $data, $data, $oid, $tunnel); \ No newline at end of file +unset($rrd_name,$rrd_def,$fields,$oids, $data, $data, $oid, $tunnel); diff --git a/includes/polling/cisco-ace-loadbalancer.inc.php b/includes/polling/cisco-ace-loadbalancer.inc.php index 7b00e588b7..460a331017 100644 --- a/includes/polling/cisco-ace-loadbalancer.inc.php +++ b/includes/polling/cisco-ace-loadbalancer.inc.php @@ -23,8 +23,7 @@ foreach ($rserver_array as $index => $serverfarm) { if (!is_array($serverfarms[$farm_id])) { $rserver_id = dbInsert(array('device_id' => $device['device_id'], 'farm_id' => $farm_id, 'StateDescr' => $serverfarm['cesServerFarmRserverStateDescr']), 'loadbalancer_rservers'); - } - else { + } else { foreach ($db_oids as $db_oid => $db_value) { $db_update[$db_value] = $serverfarm[$db_oid]; } @@ -45,8 +44,7 @@ foreach ($rserver_array as $index => $serverfarm) { foreach ($oids as $oid) { if (is_numeric($serverfarm[$oid])) { $value = $serverfarm[$oid]; - } - else { + } else { $value = '0'; } $fields[$oid] = $value; @@ -54,7 +52,7 @@ foreach ($rserver_array as $index => $serverfarm) { if (isset($serverfarms[$farm_id])) { $tags = compact('farm_id', 'rrd_name', 'rrd_def'); - data_update($device,'rservers',$tags,$fields); + data_update($device, 'rservers', $tags, $fields); } }//end foreach diff --git a/includes/polling/cisco-ace-serverfarms.inc.php b/includes/polling/cisco-ace-serverfarms.inc.php index 56f30ce1b6..83979d65cd 100644 --- a/includes/polling/cisco-ace-serverfarms.inc.php +++ b/includes/polling/cisco-ace-serverfarms.inc.php @@ -28,8 +28,7 @@ foreach ($serverfarm_array as $index => $vserver) { if (!is_array($classmaps[$classmap])) { $classmap_in = dbInsert(array('device_id' => $device['device_id'], 'classmap_id' => $classmap_id, 'classmap' => $classmap, 'serverstate' => $vserver['slbVServerState']), 'loadbalancer_vservers'); - } - else { + } else { foreach ($db_oids as $db_oid => $db_value) { $db_update[$db_value] = $vserver[$db_oid]; } @@ -48,8 +47,7 @@ foreach ($serverfarm_array as $index => $vserver) { foreach ($oids as $oid) { if (is_numeric($vserver[$oid])) { $value = $vserver[$oid]; - } - else { + } else { $value = '0'; } $fields[$oid] = $value; diff --git a/includes/polling/cisco-asa-firewall.inc.php b/includes/polling/cisco-asa-firewall.inc.php index a692d7b657..7470b0c0f0 100644 --- a/includes/polling/cisco-asa-firewall.inc.php +++ b/includes/polling/cisco-asa-firewall.inc.php @@ -21,8 +21,7 @@ if ($device['os_group'] == 'cisco' && $device['os'] == 'asa' && $device['type'] $asa_db = dbFetchCell('SELECT `ciscoASA_id` FROM `ciscoASA` WHERE `device_id` = ? AND `oid` = ?', array($device['device_id'], $oid)); if (!is_numeric($asa_db)) { $asa_db = dbInsert(array('device_id' => $device['device_id'], 'oid' => $oid, 'data' => $result['cfwConnectionStatValue']), 'ciscoASA'); - } - else { + } else { $asa_db = dbUpdate(array('data' => $result['cfwConnectionStatValue']), 'ciscoASA', 'device_id=?', array($device['device_id'])); } @@ -36,7 +35,7 @@ if ($device['os_group'] == 'cisco' && $device['os'] == 'asa' && $device['type'] ); $tags = compact('rrd_def'); - data_update($device,'asa_conns',$tags,$fields); + data_update($device, 'asa_conns', $tags, $fields); $graphs['asa_conns'] = true; echo ' ASA Connections'; diff --git a/includes/polling/cisco-cbqos.inc.php b/includes/polling/cisco-cbqos.inc.php index 807e2903e8..6201f2eb86 100644 --- a/includes/polling/cisco-cbqos.inc.php +++ b/includes/polling/cisco-cbqos.inc.php @@ -12,14 +12,13 @@ */ if ($device['os_group'] == "cisco") { - $module = 'Cisco-CBQOS'; $component = new LibreNMS\Component(); $options['filter']['type'] = array('=',$module); $options['filter']['disabled'] = array('=',0); $options['filter']['ignore'] = array('=',0); - $components = $component->getComponents($device['device_id'],$options); + $components = $component->getComponents($device['device_id'], $options); // We only care about our device id. $components = $components[$device['device_id']]; @@ -64,9 +63,8 @@ if ($device['os_group'] == "cisco") { data_update($device, 'cbqos', $tags, $fields); } } // End foreach components - } // end if count components // Clean-up after yourself! -unset($type, $components, $component, $options, $module); + unset($type, $components, $component, $options, $module); } diff --git a/includes/polling/cisco-cef.inc.php b/includes/polling/cisco-cef.inc.php index 0b65c28c8a..cde436989e 100644 --- a/includes/polling/cisco-cef.inc.php +++ b/includes/polling/cisco-cef.inc.php @@ -1,7 +1,6 @@ getComponents($device['device_id'],$options); + $components = $component->getComponents($device['device_id'], $options); // We only care about our device id. $components = $components[$device['device_id']]; @@ -81,11 +80,10 @@ if ($device['os_group'] == "cisco") { $count_mac[$v]++; } // Let's log some debugging - d_echo("\n\nMAC Addresses: ".print_r($count_mac,TRUE)); + d_echo("\n\nMAC Addresses: ".print_r($count_mac, true)); // Loop through the components and extract the data. foreach ($components as $key => &$array) { - if ($array['otvtype'] == 'overlay') { // Let's check the various status' of the overlay $message = false; @@ -106,8 +104,7 @@ if ($device['os_group'] == "cisco") { if ($message !== false) { $array['error'] = $message; $array['status'] = 2; - } - else { + } else { $array['error'] = ""; $array['status'] = 0; } @@ -138,9 +135,7 @@ if ($device['os_group'] == "cisco") { $tags = compact('label', 'rrd_name', 'rrd_def'); data_update($device, 'cisco-otv-vlan', $tags, $fields); - - } - elseif ($array['otvtype'] == 'adjacency') { + } elseif ($array['otvtype'] == 'adjacency') { $array['uptime'] = $tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.6.'.$array['index'].'.1.4.'.$array['endpoint']]; $message = false; if ($tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.5.'.$array['index'].'.1.4.'.$array['endpoint']] != 1) { @@ -154,8 +149,7 @@ if ($device['os_group'] == "cisco") { if ($message !== false) { $array['error'] = $message; $array['status'] = 1; - } - else { + } else { $array['error'] = ""; $array['status'] = 0; } @@ -166,8 +160,7 @@ if ($device['os_group'] == "cisco") { d_echo(" Index: ".$array['index']."\n"); d_echo(" Status: ".$array['status']."\n"); d_echo(" Message: ".$array['error']."\n"); - } - elseif ($array['otvtype'] == 'endpoint') { + } elseif ($array['otvtype'] == 'endpoint') { $count = 0; $endpoint = $array['endpoint']; @@ -188,14 +181,11 @@ if ($device['os_group'] == "cisco") { $tags = compact('endpoint', 'rrd_name', 'rrd_def'); data_update($device, 'cisco-otv-mac', $tags, $fields); - } // End If - } // End foreach components // Write the Components back to the DB. - $component->setComponentPrefs($device['device_id'],$components); - + $component->setComponentPrefs($device['device_id'], $components); } // end if count components // Clean-up after yourself! diff --git a/includes/polling/cisco-remote-access-monitor.inc.php b/includes/polling/cisco-remote-access-monitor.inc.php index f9eb30a6cf..932f1498a4 100644 --- a/includes/polling/cisco-remote-access-monitor.inc.php +++ b/includes/polling/cisco-remote-access-monitor.inc.php @@ -55,7 +55,7 @@ if ($device['os_group'] == 'cisco') { ); $tags = compact('rrd_def'); - data_update($device,'cras_sessions',$tags,$fields); + data_update($device, 'cras_sessions', $tags, $fields); $graphs['cras_sessions'] = true; } diff --git a/includes/polling/cisco-sla.inc.php b/includes/polling/cisco-sla.inc.php index 91588c590d..4b49dd914b 100644 --- a/includes/polling/cisco-sla.inc.php +++ b/includes/polling/cisco-sla.inc.php @@ -46,7 +46,7 @@ if (count($slas > 0)) { $rrd_name = array('sla', $sla_nr); $rrd_def = 'DS:rtt:GAUGE:600:0:300000'; $tags = compact('sla_nr', 'rrd_name', 'rrd_def'); - data_update($device,'sla',$tags,$fields); + data_update($device, 'sla', $tags, $fields); // Let's gather some per-type metrics. switch ($rtt_type) { @@ -79,8 +79,8 @@ if (count($slas > 0)) { 'DS:AvgDSJ:GAUGE:600:0:U', ); $tags = compact('rrd_name', 'rrd_def', 'sla_nr', 'rtt_type'); - data_update($device,'sla',$tags,$jitter); - $metrics = array_merge($metrics,$jitter); + data_update($device, 'sla', $tags, $jitter); + $metrics = array_merge($metrics, $jitter); break; } diff --git a/includes/polling/cisco-voice.inc.php b/includes/polling/cisco-voice.inc.php index fc47397465..b6a703a377 100644 --- a/includes/polling/cisco-voice.inc.php +++ b/includes/polling/cisco-voice.inc.php @@ -1,40 +1,38 @@ - - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. Please see LICENSE.txt at the top level of - * the source code distribution for details. - */ - -if ($device['os_group'] == "cisco") { - - /* - * Cisco PRI - * This module graphs the used and total DS0 channels on a Cisco Voice Gateway - */ - include "cisco-voice/cisco-iospri.inc.php"; - - /* - * Cisco DSP - * This module graphs the used and total DSP resources on a Cisco Voice Gateway - */ - include "cisco-voice/cisco-iosdsp.inc.php"; - - /* - * Cisco MTP - * This module graphs the used and total MTP resources on a Cisco Voice Gateway - */ - include "cisco-voice/cisco-iosmtp.inc.php"; - - /* - * Cisco XCode - * This module graphs the used and total Transcoder resources on a Cisco Voice Gateway - */ - include "cisco-voice/cisco-xcode.inc.php"; - -} \ No newline at end of file + + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if ($device['os_group'] == "cisco") { + /* + * Cisco PRI + * This module graphs the used and total DS0 channels on a Cisco Voice Gateway + */ + include "cisco-voice/cisco-iospri.inc.php"; + + /* + * Cisco DSP + * This module graphs the used and total DSP resources on a Cisco Voice Gateway + */ + include "cisco-voice/cisco-iosdsp.inc.php"; + + /* + * Cisco MTP + * This module graphs the used and total MTP resources on a Cisco Voice Gateway + */ + include "cisco-voice/cisco-iosmtp.inc.php"; + + /* + * Cisco XCode + * This module graphs the used and total Transcoder resources on a Cisco Voice Gateway + */ + include "cisco-voice/cisco-xcode.inc.php"; +} diff --git a/includes/polling/cisco-voice/cisco-iosdsp.inc.php b/includes/polling/cisco-voice/cisco-iosdsp.inc.php index c081e265b9..ea17b18ebb 100644 --- a/includes/polling/cisco-voice/cisco-iosdsp.inc.php +++ b/includes/polling/cisco-voice/cisco-iosdsp.inc.php @@ -14,14 +14,14 @@ if ($device['os_group'] == "cisco") { // Total $total = 0; - foreach (snmpwalk_cache_oid_num ($device, "1.3.6.1.4.1.9.9.86.1.2.1.1.6", NULL) as $key => $value) { + foreach (snmpwalk_cache_oid_num($device, "1.3.6.1.4.1.9.9.86.1.2.1.1.6", null) as $key => $value) { $total += $value['']; } if (isset($total) && ($total != "") && ($total != 0)) { // Active $active = 0; - foreach ( snmpwalk_cache_oid_num ($device, "1.3.6.1.4.1.9.9.86.1.2.1.1.7", NULL) as $key => $value) { + foreach (snmpwalk_cache_oid_num($device, "1.3.6.1.4.1.9.9.86.1.2.1.1.7", null) as $key => $value) { $active += $value['']; } @@ -38,7 +38,7 @@ if ($device['os_group'] == "cisco") { $tags = compact('rrd_def'); data_update($device, 'cisco-iosdsp', $tags, $fields); - $graphs['cisco-iosdsp'] = TRUE; + $graphs['cisco-iosdsp'] = true; echo (" Cisco IOS DSP "); } unset($rrd_def, $total, $active, $tags, $fields); diff --git a/includes/polling/cisco-voice/cisco-iosmtp.inc.php b/includes/polling/cisco-voice/cisco-iosmtp.inc.php index fdeec03805..3884da6508 100644 --- a/includes/polling/cisco-voice/cisco-iosmtp.inc.php +++ b/includes/polling/cisco-voice/cisco-iosmtp.inc.php @@ -13,12 +13,12 @@ if ($device['os_group'] == "cisco") { // Total - $total = snmpwalk_cache_oid_num ($device, "1.3.6.1.4.1.9.9.86.1.6.4.1.3", NULL); + $total = snmpwalk_cache_oid_num($device, "1.3.6.1.4.1.9.9.86.1.6.4.1.3", null); $total = $total['1.3.6.1.4.1.9.9.86.1.6.4.1.3']['']; if (isset($total) && ($total != "") && ($total != 0)) { // Available - $available = snmpwalk_cache_oid_num ($device, "1.3.6.1.4.1.9.9.86.1.6.4.1.4", NULL); + $available = snmpwalk_cache_oid_num($device, "1.3.6.1.4.1.9.9.86.1.6.4.1.4", null); $available = $available['1.3.6.1.4.1.9.9.86.1.6.4.1.4']['']; // Active @@ -37,7 +37,7 @@ if ($device['os_group'] == "cisco") { $tags = compact('rrd_def'); data_update($device, 'cisco-iosmtp', $tags, $fields); - $graphs['cisco-iosmtp'] = TRUE; + $graphs['cisco-iosmtp'] = true; echo (" Cisco IOS MTP "); } unset($rrd_def, $total, $active, $available, $fields, $tags); diff --git a/includes/polling/cisco-voice/cisco-iospri.inc.php b/includes/polling/cisco-voice/cisco-iospri.inc.php index a783c2df1e..24fede3b6d 100644 --- a/includes/polling/cisco-voice/cisco-iospri.inc.php +++ b/includes/polling/cisco-voice/cisco-iospri.inc.php @@ -16,7 +16,7 @@ if ($device['os_group'] == "cisco") { // Total $total = 0; - foreach ( snmpwalk_cache_oid_num ($device, "1.3.6.1.2.1.2.2.1.3", NULL) as $key => $value) { + foreach (snmpwalk_cache_oid_num($device, "1.3.6.1.2.1.2.2.1.3", null) as $key => $value) { // 81 is the ifType for DS0's if ($value[''] == "81") { $total++; @@ -24,7 +24,7 @@ if ($device['os_group'] == "cisco") { } // Active - $active = snmpwalk_cache_oid_num ($device, "1.3.6.1.4.1.9.10.19.1.1.4.0", NULL); + $active = snmpwalk_cache_oid_num($device, "1.3.6.1.4.1.9.10.19.1.1.4.0", null); $active = $active['1.3.6.1.4.1.9.10.19.1.1.4.0']['']; if (isset($active) && ($active != "") && ($total != 0)) { @@ -41,7 +41,7 @@ if ($device['os_group'] == "cisco") { $tags = compact('rrd_def'); data_update($device, 'cisco-iospri', $tags, $fields); - $graphs['cisco-iospri'] = TRUE; + $graphs['cisco-iospri'] = true; echo (" Cisco IOS PRI "); } unset($rrd_def, $total, $active, $fields, $tags); diff --git a/includes/polling/cisco-voice/cisco-iosxcode.inc.php b/includes/polling/cisco-voice/cisco-iosxcode.inc.php index 22044f98f9..bc83ce7a37 100644 --- a/includes/polling/cisco-voice/cisco-iosxcode.inc.php +++ b/includes/polling/cisco-voice/cisco-iosxcode.inc.php @@ -13,12 +13,12 @@ if ($device['os_group'] == "cisco") { // Total - $total = snmpwalk_cache_oid_num ($device, "1.3.6.1.4.1.9.9.86.1.7.1.0", NULL); + $total = snmpwalk_cache_oid_num($device, "1.3.6.1.4.1.9.9.86.1.7.1.0", null); $total = $total['1.3.6.1.4.1.9.9.86.1.7.1.0']['']; if (isset($total) && ($total != "") && ($total != 0)) { // Available - $available = snmpwalk_cache_oid_num ($device, "1.3.6.1.4.1.9.9.86.1.7.2.0", NULL); + $available = snmpwalk_cache_oid_num($device, "1.3.6.1.4.1.9.9.86.1.7.2.0", null); $available = $available['1.3.6.1.4.1.9.9.86.1.7.2.0']['']; // Active @@ -37,7 +37,7 @@ if ($device['os_group'] == "cisco") { $tags = compact('rrd_def'); dat_update($device, 'cisco-iosxcode', $tags, $fields); - $graphs['cisco-iosxcode'] = TRUE; + $graphs['cisco-iosxcode'] = true; echo (" Cisco IOS Transcoder "); } unset($rrd_def, $total, $active, $available, $fields, $tags); diff --git a/includes/polling/cisco-vpdn.inc.php b/includes/polling/cisco-vpdn.inc.php index ce6b80962a..ac0dd55138 100644 --- a/includes/polling/cisco-vpdn.inc.php +++ b/includes/polling/cisco-vpdn.inc.php @@ -27,7 +27,7 @@ if ($device['os_group'] == 'cisco') { $tags = compact('type', 'rrd_name', 'rrd_def'); - data_update($device,'vpdn',$tags,$fields); + data_update($device, 'vpdn', $tags, $fields); $graphs['vpdn_sessions_'.$type] = true; $graphs['vpdn_tunnels_'.$type] = true; diff --git a/includes/polling/core.inc.php b/includes/polling/core.inc.php index 30c26f0290..76ca88be5d 100644 --- a/includes/polling/core.inc.php +++ b/includes/polling/core.inc.php @@ -37,8 +37,7 @@ if (empty($uptime)) { $uptime = floor($hrSystemUptime / 100); echo 'Using hrSystemUptime ('.$uptime."s)\n"; - } - else { + } else { $uptime = floor($poll_device['sysUpTime'] / 100); echo 'Using SNMP Agent Uptime ('.$uptime."s)\n"; }//end if diff --git a/includes/polling/entity-physical.inc.php b/includes/polling/entity-physical.inc.php index 1724ad66a5..ee8ece2733 100644 --- a/includes/polling/entity-physical.inc.php +++ b/includes/polling/entity-physical.inc.php @@ -40,8 +40,7 @@ if ($device['os'] == 'ios') { ); $tags = compact('index', 'subindex', 'rrd_name', 'rrd_def'); - data_update($device,'c6kxbar',$tags,$fields); - + data_update($device, 'c6kxbar', $tags, $fields); }//end foreach // print_r($entPhysical_state); @@ -61,8 +60,7 @@ foreach (dbFetch('SELECT * FROM `entPhysical_state` WHERE `device_id` = ?', arra $entity['key'], ) ); - } - else { + } else { if ($entPhysical_state[$entity['entPhysicalIndex']][$entity['subindex']][$entity['group']][$entity['key']] != $entity['value']) { echo 'no match!'; } diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index 6235c8b539..3c9f5940eb 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -2,7 +2,8 @@ require_once $config['install_dir'].'/includes/device-groups.inc.php'; -function poll_sensor($device, $class, $unit) { +function poll_sensor($device, $class, $unit) +{ global $config, $memcache, $agent_sensors; foreach (dbFetchRows('SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ?', array($class, $device['device_id'])) as $sensor) { @@ -12,15 +13,13 @@ function poll_sensor($device, $class, $unit) { if ($sensor['poller_type'] == 'snmp') { if ($device['os'] == 'pbn') { $mibdir = $config['mibdir'].'/pbn'.':'.$config['mibdir']; - } - else { + } else { $mibdir = $config['mibdir']; } if ($device['os'] == 'siklu') { $mib = ':RADIO-BRIDGE-MIB'; - } - else { + } else { $mib = ''; } @@ -60,45 +59,37 @@ function poll_sensor($device, $class, $unit) { $sensor_value = $state_value; } } - } - else if ($class == 'signal') { - $currentOS = $device['os']; - include "includes/polling/signal/$currentOS.inc.php"; - $sensor_value = trim(str_replace('"', '', snmp_get($device, $sensor['sensor_oid'], '-OUqnv', "SNMPv2-MIB$mib", $mibdir))); - } - else if ($class == 'dbm') { + } elseif ($class == 'signal') { + $currentOS = $device['os']; + include "includes/polling/signal/$currentOS.inc.php"; + $sensor_value = trim(str_replace('"', '', snmp_get($device, $sensor['sensor_oid'], '-OUqnv', "SNMPv2-MIB$mib", $mibdir))); + } elseif ($class == 'dbm') { $sensor_value = trim(str_replace('"', '', snmp_get($device, $sensor['sensor_oid'], '-OUqnv', "SNMPv2-MIB$mib", $mibdir))); //iosxr does not expose dbm values through SNMP so we convert Watts to dbm to have a nice graph to show if ($device['os'] == "iosxr") { - $sensor_value = round(10*log10($sensor_value/1000),3); + $sensor_value = round(10*log10($sensor_value/1000), 3); } - } - else { + } else { if ($sensor['sensor_type'] == 'apc') { $sensor_value = trim(str_replace('"', '', snmp_walk($device, $sensor['sensor_oid'], '-OUqnv', "SNMPv2-MIB:PowerNet-MIB$mib", $mibdir))); - } - else { + } else { $sensor_value = trim(str_replace('"', '', snmp_get($device, $sensor['sensor_oid'], '-OUqnv', "SNMPv2-MIB$mib", $mibdir))); } }//end if unset($mib); unset($mibdir); - } - else if ($sensor['poller_type'] == 'agent') { + } elseif ($sensor['poller_type'] == 'agent') { if (isset($agent_sensors)) { $sensor_value = $agent_sensors[$class][$sensor['sensor_type']][$sensor['sensor_index']]['current']; - } - else { + } else { echo "no agent data!\n"; continue; } - } - else if ($sensor['poller_type'] == 'ipmi') { + } elseif ($sensor['poller_type'] == 'ipmi') { echo " already polled.\n"; // ipmi should probably move here from the ipmi poller file (FIXME) continue; - } - else { + } else { echo "unknown poller type!\n"; continue; }//end if @@ -133,14 +124,13 @@ function poll_sensor($device, $class, $unit) { 'rrd_name' => $rrd_name, 'rrd_def' => $rrd_def ); - data_update($device,'sensor',$tags,$fields); + data_update($device, 'sensor', $tags, $fields); // FIXME also warn when crossing WARN level!! if ($sensor['sensor_limit_low'] != '' && $sensor['sensor_current'] > $sensor['sensor_limit_low'] && $sensor_value < $sensor['sensor_limit_low'] && $sensor['sensor_alert'] == 1) { echo 'Alerting for '.$device['hostname'].' '.$sensor['sensor_descr']."\n"; log_event(ucfirst($class).' '.$sensor['sensor_descr'].' under threshold: '.$sensor_value." $unit (< ".$sensor['sensor_limit_low']." $unit)", $device, $class, $sensor['sensor_id']); - } - else if ($sensor['sensor_limit'] != '' && $sensor['sensor_current'] < $sensor['sensor_limit'] && $sensor_value > $sensor['sensor_limit'] && $sensor['sensor_alert'] == 1) { + } elseif ($sensor['sensor_limit'] != '' && $sensor['sensor_current'] < $sensor['sensor_limit'] && $sensor_value > $sensor['sensor_limit'] && $sensor['sensor_alert'] == 1) { echo 'Alerting for '.$device['hostname'].' '.$sensor['sensor_descr']."\n"; log_event(ucfirst($class).' '.$sensor['sensor_descr'].' above threshold: '.$sensor_value." $unit (> ".$sensor['sensor_limit']." $unit)", $device, $class, $sensor['sensor_id']); } @@ -151,11 +141,11 @@ function poll_sensor($device, $class, $unit) { dbUpdate(array('sensor_current' => $sensor_value, 'sensor_prev' => $sensor['sensor_current'], 'lastupdate' => array('NOW()')), 'sensors', '`sensor_class` = ? AND `sensor_id` = ?', array($class,$sensor['sensor_id'])); }//end foreach - }//end poll_sensor() -function poll_device($device, $options) { +function poll_device($device, $options) +{ global $config, $device, $polled_devices, $db_stats, $memcache; $attribs = get_dev_attribs($device['device_id']); @@ -213,14 +203,12 @@ function poll_device($device, $options) { if ($device['snmpable']) { $status = '1'; $response['status_reason'] = ''; - } - else { + } else { echo 'SNMP Unreachable'; $status = '0'; $response['status_reason'] = 'snmp'; } - } - else { + } else { echo 'Unpingable'; $status = '0'; $response['status_reason'] = 'icmp'; @@ -278,12 +266,10 @@ function poll_device($device, $options) { $oldrrd = rrd_name($device['hostname'], array('poller', $module, 'perf')); if (is_file($oldrrd)) { unlink($oldrrd); - } - } - elseif (isset($attribs['poll_'.$module]) && $attribs['poll_'.$module] == '0') { + } + } elseif (isset($attribs['poll_'.$module]) && $attribs['poll_'.$module] == '0') { echo "Module [ $module ] disabled on host.\n"; - } - else { + } else { echo "Module [ $module ] disabled globally.\n"; } } @@ -299,8 +285,7 @@ function poll_device($device, $options) { foreach (dbFetch('SELECT `graph` FROM `device_graphs` WHERE `device_id` = ?', array($device['device_id'])) as $graph) { if (isset($graphs[$graph['graph']])) { $oldgraphs[$graph['graph']] = true; - } - else { + } else { dbDelete('device_graphs', '`device_id` = ? AND `graph` = ?', array($device['device_id'], $graph['graph'])); } } @@ -365,19 +350,18 @@ function poll_device($device, $options) { unset($cache); // Clear cache (unify all things here?) }//end if - }//end poll_device() -function poll_mib_def($device, $mib_name_table, $mib_subdir, $mib_oids, $mib_graphs, &$graphs) { +function poll_mib_def($device, $mib_name_table, $mib_subdir, $mib_oids, $mib_graphs, &$graphs) +{ echo "This is poll_mib_def Processing\n"; $mib = null; if (stristr($mib_name_table, 'UBNT')) { list($mib,) = explode(':', $mib_name_table, 2); $measurement_name = strtolower($mib); - } - else { + } else { list($mib,$file) = explode(':', $mib_name_table, 2); $measurement_name = strtolower($file); } @@ -404,8 +388,7 @@ function poll_mib_def($device, $mib_name_table, $mib_subdir, $mib_oids, $mib_gra if ($oidindex != '') { $fulloid = $oid.'.'.$oidindex; - } - else { + } else { $fulloid = $oid; } @@ -430,43 +413,40 @@ function poll_mib_def($device, $mib_name_table, $mib_subdir, $mib_oids, $mib_gra $val = $snmpdata[$splitindex][$splitoid]; if (is_numeric($val)) { $fields[$oidnamelist[$oid_count]] = $val; - } - elseif (preg_match("/^\"(.*)\"$/", $val, $number) && is_numeric($number[1])) { + } elseif (preg_match("/^\"(.*)\"$/", $val, $number) && is_numeric($number[1])) { $fields[$oidnamelist[$oid_count]] = $number[1]; - } - else { + } else { $fields[$oidnamelist[$oid_count]] = 'U'; } $oid_count++; } $tags = compact('rrd_def'); - data_update($device,$measurement_name,$tags,$fields); + data_update($device, $measurement_name, $tags, $fields); foreach ($mib_graphs as $graphtoenable) { $graphs[$graphtoenable] = true; } return true; - }//end poll_mib_def() -function get_main_serial($device) { +function get_main_serial($device) +{ if ($device['os_group'] == 'cisco') { $serial_output = snmp_get_multi($device, 'entPhysicalSerialNum.1 entPhysicalSerialNum.1001', '-OQUs', 'ENTITY-MIB:OLD-CISCO-CHASSIS-MIB'); if (!empty($serial_output[1]['entPhysicalSerialNum'])) { return $serial_output[1]['entPhysicalSerialNum']; - } - else if (!empty($serial_output[1001]['entPhysicalSerialNum'])) { + } elseif (!empty($serial_output[1001]['entPhysicalSerialNum'])) { return $serial_output[1001]['entPhysicalSerialNum']; } } - }//end get_main_serial() -function location_to_latlng($device) { +function location_to_latlng($device) +{ global $config; if (function_check('curl_version') !== true) { d_echo("Curl support for PHP not enabled\n"); @@ -475,7 +455,7 @@ function location_to_latlng($device) { $bad_loc = false; $device_location = $device['location']; if (!empty($device_location)) { - $new_device_location = preg_replace("/ /","+",$device_location); + $new_device_location = preg_replace("/ /", "+", $device_location); // We have a location string for the device. $loc = parse_location($device_location); if (!is_array($loc)) { @@ -494,12 +474,12 @@ function location_to_latlng($device) { } else { $api_url = "https://maps.googleapis.com/maps/api/geocode/json?address=$new_device_location"; } - break; + break; } $curl_init = curl_init($api_url); set_curl_proxy($curl_init); curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, true); - $data = json_decode(curl_exec($curl_init),true); + $data = json_decode(curl_exec($curl_init), true); // Parse the data from the specific Geocode services. switch ($config['geoloc']['engine']) { case "google": @@ -509,25 +489,21 @@ function location_to_latlng($device) { } else { $bad_loc = true; } - break; + break; } if ($bad_loc === true) { d_echo("Bad lat / lng received\n"); - } - else { + } else { $loc['timestamp'] = array('NOW()'); $loc['location'] = $device_location; if (dbInsert($loc, 'locations')) { d_echo("Device lat/lng created\n"); - } - else { + } else { d_echo("Device lat/lng could not be created\n"); } } - } - else { + } else { d_echo("Using cached lat/lng from other device\n"); } } }// end location_to_latlng() - diff --git a/includes/polling/hr-mib.inc.php b/includes/polling/hr-mib.inc.php index 7a0cf780e9..1ec56d000a 100644 --- a/includes/polling/hr-mib.inc.php +++ b/includes/polling/hr-mib.inc.php @@ -13,7 +13,7 @@ if (is_numeric($hrSystem[0]['hrSystemProcesses'])) { 'procs' => $hrSystem[0]['hrSystemProcesses'], ); - data_update($device,'hr_processes',$tags,$fields); + data_update($device, 'hr_processes', $tags, $fields); $graphs['hr_processes'] = true; echo ' Processes'; @@ -27,7 +27,7 @@ if (is_numeric($hrSystem[0]['hrSystemNumUsers'])) { 'users' => $hrSystem[0]['hrSystemNumUsers'], ); - data_update($device,'hr_users',$tags,$fields); + data_update($device, 'hr_users', $tags, $fields); $graphs['hr_users'] = true; echo ' Users'; diff --git a/includes/polling/ipSystemStats.inc.php b/includes/polling/ipSystemStats.inc.php index 14aa6461bd..086b9ebcf0 100644 --- a/includes/polling/ipSystemStats.inc.php +++ b/includes/polling/ipSystemStats.inc.php @@ -108,7 +108,7 @@ if ($data) { } $tags = compact('af', 'rrd_name', 'rrd_def'); - data_update($device,'ipSystemStats',$tags,$fields); + data_update($device, 'ipSystemStats', $tags, $fields); // FIXME per-AF? $graphs['ipsystemstats_'.$af] = true; diff --git a/includes/polling/ipmi.inc.php b/includes/polling/ipmi.inc.php index 8ef47103d2..912f0f04ea 100644 --- a/includes/polling/ipmi.inc.php +++ b/includes/polling/ipmi.inc.php @@ -47,7 +47,7 @@ if ($ipmi['host'] = get_dev_attrib($device, 'ipmi_hostname')) { 'rrd_name' => $rrd_name, 'rrd_def' => $rrd_def ); - data_update($device,'ipmi',$tags,$fields); + data_update($device, 'ipmi', $tags, $fields); // FIXME warnings in event & mail not done here yet! dbUpdate(array('sensor_current' => $sensor, 'lastupdate' => array('NOW()')), 'sensors', 'poller_type = ? AND sensor_class = ? AND sensor_id = ?', array('ipmi', $ipmisensors['sensor_class'], $ipmisensors['sensor_id'])); diff --git a/includes/polling/junose-atm-vp.inc.php b/includes/polling/junose-atm-vp.inc.php index 3ebe02a3f7..e354b124a9 100644 --- a/includes/polling/junose-atm-vp.inc.php +++ b/includes/polling/junose-atm-vp.inc.php @@ -54,8 +54,7 @@ if (count($vp_rows)) { ); $tags = compact('ifIndex', 'vp_id', 'rrd_name', 'rrd_def'); - data_update($device,'atm-vp',$tags,$fields); - + data_update($device, 'atm-vp', $tags, $fields); }//end foreach echo "\n"; diff --git a/includes/polling/mempools.inc.php b/includes/polling/mempools.inc.php index 96f2ba6f4a..d887484899 100644 --- a/includes/polling/mempools.inc.php +++ b/includes/polling/mempools.inc.php @@ -13,8 +13,7 @@ foreach (dbFetchRows('SELECT * FROM mempools WHERE device_id = ?', array($device if ($mempool['total']) { $percent = round(($mempool['used'] / $mempool['total'] * 100), 2); - } - else { + } else { $percent = 0; } @@ -32,7 +31,7 @@ foreach (dbFetchRows('SELECT * FROM mempools WHERE device_id = ?', array($device ); $tags = compact('mempool_type', 'mempool_index', 'rrd_name', 'rrd_def'); - data_update($device,'mempool',$tags,$fields); + data_update($device, 'mempool', $tags, $fields); $mempool['state'] = array( 'mempool_used' => $mempool['used'], diff --git a/includes/polling/mempools/adtran-aos.inc.php b/includes/polling/mempools/adtran-aos.inc.php index cfa5ed8a2f..555e6c9aba 100644 --- a/includes/polling/mempools/adtran-aos.inc.php +++ b/includes/polling/mempools/adtran-aos.inc.php @@ -23,4 +23,3 @@ $mempool['used'] = snmp_get($device, 'adGenAOSHeapSize.0', '-OvQ', 'ADTRAN-AOSCPU'); $mempool['total'] = snmp_get($device, 'adGenAOSMemPool.0', '-OvQ', 'ADTRAN-AOSCPU'); $mempool['free'] = ($mempool['total'] - $mempool['used']); - diff --git a/includes/polling/mempools/ciscowlc.inc.php b/includes/polling/mempools/ciscowlc.inc.php index b8931e1303..4b07b3528d 100644 --- a/includes/polling/mempools/ciscowlc.inc.php +++ b/includes/polling/mempools/ciscowlc.inc.php @@ -1,12 +1,12 @@ \d+)/', $device['version'], $version); d_echo($version); @@ -20,7 +19,7 @@ if ($device['os'] == 'pbn') { $mempool['free'] = ($memory_available - $mempool['used']); } - echo "PERC " .$perc."%\n"; - echo "Avail " .$mempool['total']."\n"; + echo "PERC " .$perc."%\n"; + echo "Avail " .$mempool['total']."\n"; } } diff --git a/includes/polling/mempools/pulse-mem.inc.php b/includes/polling/mempools/pulse-mem.inc.php index cfee9f7ee5..dbd5637f41 100644 --- a/includes/polling/mempools/pulse-mem.inc.php +++ b/includes/polling/mempools/pulse-mem.inc.php @@ -15,16 +15,15 @@ echo 'Pulse Secure MemPool'.'\n'; if ($device['os'] == 'pulse') { - $perc = str_replace('"', "", snmp_get($device, "PULSESECURE-PSG-MIB::iveMemoryUtil.0", '-OvQ')); - $memory_available = str_replace('"', "", snmp_get($device, "UCD-SNMP-MIB::memTotalReal.0", '-OvQ')); - $mempool['total'] = $memory_available; + $perc = str_replace('"', "", snmp_get($device, "PULSESECURE-PSG-MIB::iveMemoryUtil.0", '-OvQ')); + $memory_available = str_replace('"', "", snmp_get($device, "UCD-SNMP-MIB::memTotalReal.0", '-OvQ')); + $mempool['total'] = $memory_available; - if (is_numeric($perc)) { - $mempool['used'] = ($memory_available / 100 * $perc); - $mempool['free'] = ($memory_available - $mempool['used']); - } - - echo "PERC " .$perc."%\n"; - echo "Avail " .$mempool['total']."\n"; + if (is_numeric($perc)) { + $mempool['used'] = ($memory_available / 100 * $perc); + $mempool['free'] = ($memory_available - $mempool['used']); + } + echo "PERC " .$perc."%\n"; + echo "Avail " .$mempool['total']."\n"; } diff --git a/includes/polling/mib/sub10-mib.inc.php b/includes/polling/mib/sub10-mib.inc.php index aa96a283b9..05ab8bb757 100644 --- a/includes/polling/mib/sub10-mib.inc.php +++ b/includes/polling/mib/sub10-mib.inc.php @@ -53,4 +53,3 @@ $mib_graphs = array( unset($graph, $oids, $oid); poll_mib_def($device, 'SUB10SYSTEMS-MIB:sub10Systems', 'sub10', $mib_oids, $mib_graphs, $graphs); - diff --git a/includes/polling/mib/ubnt-airmax-mib.inc.php b/includes/polling/mib/ubnt-airmax-mib.inc.php index 988971c287..43c0b092de 100644 --- a/includes/polling/mib/ubnt-airmax-mib.inc.php +++ b/includes/polling/mib/ubnt-airmax-mib.inc.php @@ -137,5 +137,4 @@ if (is_numeric(snmp_get($device, 'ubntRadioFreq.1', '-OUqnv', 'UBNT-AirMAX-MIB', unset($graph, $oids, $oid); poll_mib_def($device, 'UBNT-AirMAX-MIB:UBNT', 'ubiquiti', $mib_oids, $mib_graphs, $graphs); - }//end if diff --git a/includes/polling/netscaler-stats.inc.php b/includes/polling/netscaler-stats.inc.php index 85639d1c36..afb8f3fe03 100644 --- a/includes/polling/netscaler-stats.inc.php +++ b/includes/polling/netscaler-stats.inc.php @@ -111,15 +111,14 @@ if ($device['os'] == 'netscaler') { foreach ($oids as $oid) { if (is_numeric($data[0][$oid])) { $rrdupdate = ':'.$data[0][$oid]; - } - else { + } else { $rrdupdate = 'U'; } $fields[$oid] = $rrdupdate; } $tags = compact('rrd_def'); - data_update($device,'netscaler-stats-tcp',$tags,$fields); + data_update($device, 'netscaler-stats-tcp', $tags, $fields); $graphs['netscaler_tcp_conn'] = true; $graphs['netscaler_tcp_bits'] = true; diff --git a/includes/polling/netscaler-vsvr.inc.php b/includes/polling/netscaler-vsvr.inc.php index 7b3d8495ef..315f3d432d 100644 --- a/includes/polling/netscaler-vsvr.inc.php +++ b/includes/polling/netscaler-vsvr.inc.php @@ -31,7 +31,6 @@ // NS-ROOT-MIB::vsvrTotalClients."observium" = Counter64: 43023 // NS-ROOT-MIB::vsvrClientConnOpenRate."observium" = STRING: "0" if ($device['os'] == 'netscaler') { - $oids_gauge = array( 'vsvrCurClntConnections', 'vsvrCurSrvrConnections', @@ -83,8 +82,7 @@ if ($device['os'] == 'netscaler') { foreach ($oids as $oid) { if (is_numeric($vsvr[$oid])) { $fields[$oid] = $vsvr[$oid]; - } - else { + } else { $fields[$oid] = 'U'; } } @@ -94,7 +92,7 @@ if ($device['os'] == 'netscaler') { 'rrd_name' => $rrd_name, 'rrd_def' => $rrd_def ); - data_update($device,'netscaler-vsvr',$tags,$fields); + data_update($device, 'netscaler-vsvr', $tags, $fields); echo str_pad($vsvr['vsvrName'], 25).' | '.str_pad($vsvr['vsvrType'], 5).' | '.str_pad($vsvr['vsvrState'], 6).' | '.str_pad($vsvr['vsvrIpAddress'], 16).' | '.str_pad($vsvr['vsvrPort'], 5); echo ' | '.str_pad($vsvr['vsvrRequestRate'], 8).' | '.str_pad($vsvr['vsvrRxBytesRate'].'B/s', 8).' | '.str_pad($vsvr['vsvrTxBytesRate'].'B/s', 8); @@ -113,8 +111,7 @@ if ($device['os'] == 'netscaler') { $db_insert = array_merge(array('device_id' => $device['device_id'], 'vsvr_name' => $vsvr['vsvrName']), $db_update); $vsvr_id = dbInsert($db_insert, 'netscaler_vservers'); echo ' +'; - } - else { + } else { $updated = dbUpdate($db_update, 'netscaler_vservers', '`vsvr_id` = ?', array($vsvrs[$vsvr['vsvrName']]['vsvr_id'])); echo ' U'; } diff --git a/includes/polling/netstats-icmp.inc.php b/includes/polling/netstats-icmp.inc.php index d18d4e53fe..f411ab7d7b 100644 --- a/includes/polling/netstats-icmp.inc.php +++ b/includes/polling/netstats-icmp.inc.php @@ -46,7 +46,7 @@ if ($device['os'] != 'Snom') { } $tags = compact('rrd_def'); - data_update($device,'netstats-icmp',$tags,$fields); + data_update($device, 'netstats-icmp', $tags, $fields); $graphs['netstat_icmp'] = true; $graphs['netstat_icmp_info'] = true; diff --git a/includes/polling/netstats-ip.inc.php b/includes/polling/netstats-ip.inc.php index 3bbefc1521..b7d7e7697b 100644 --- a/includes/polling/netstats-ip.inc.php +++ b/includes/polling/netstats-ip.inc.php @@ -37,15 +37,13 @@ if ($device['os'] != 'Snom') { foreach ($oids as $oid) { if (is_numeric($data[0][$oid])) { $value = $data[0][$oid]; - } - else { + } else { $value = 'U'; } $fields[$oid] = $value; } if (isset($data[0]['ipOutRequests']) && isset($data[0]['ipInReceives'])) { - $tags = compact('rrd_def'); data_update($device, 'netstats-ip', $tags, $fields); diff --git a/includes/polling/netstats-ip_forward.inc.php b/includes/polling/netstats-ip_forward.inc.php index 9ca7bd1096..4e01591aa2 100644 --- a/includes/polling/netstats-ip_forward.inc.php +++ b/includes/polling/netstats-ip_forward.inc.php @@ -22,8 +22,7 @@ if ($device['os'] != 'Snom') { foreach ($oids as $oid) { if (is_numeric($data[0][$oid])) { $value = $data[0][$oid]; - } - else { + } else { $value = 'U'; } $fields[$oid] = $value; @@ -31,7 +30,7 @@ if ($device['os'] != 'Snom') { if (isset($data[0]['ipCidrRouteNumber'])) { $tags = compact('rrd_def'); - data_update($device,'netstats-ip_forward',$tags,$fields); + data_update($device, 'netstats-ip_forward', $tags, $fields); $graphs['netstat_ip_forward'] = true; } diff --git a/includes/polling/netstats-snmp.inc.php b/includes/polling/netstats-snmp.inc.php index 264f512a8b..90327347d2 100644 --- a/includes/polling/netstats-snmp.inc.php +++ b/includes/polling/netstats-snmp.inc.php @@ -48,7 +48,7 @@ if ($device['os'] != 'Snom') { } $tags = compact('rrd_def'); - data_update($device,'netstats-snmp',$tags,$fields); + data_update($device, 'netstats-snmp', $tags, $fields); $graphs['netstat_snmp'] = true; $graphs['netstat_snmp_pkt'] = true; diff --git a/includes/polling/netstats-tcp.inc.php b/includes/polling/netstats-tcp.inc.php index 383e15cdcb..9eedad9040 100644 --- a/includes/polling/netstats-tcp.inc.php +++ b/includes/polling/netstats-tcp.inc.php @@ -40,9 +40,8 @@ if ($device['os'] != 'Snom') { } if (isset($fields['tcpInSegs']) && isset($fields['tcpOutSegs'])) { - $tags = compact('rrd_def'); - data_update($device,'netstats-tcp',$tags,$fields); + data_update($device, 'netstats-tcp', $tags, $fields); $graphs['netstat_tcp'] = true; } diff --git a/includes/polling/netstats-udp.inc.php b/includes/polling/netstats-udp.inc.php index ddc27d9e7e..69231d84e2 100644 --- a/includes/polling/netstats-udp.inc.php +++ b/includes/polling/netstats-udp.inc.php @@ -25,15 +25,13 @@ if ($device['os'] != 'Snom') { foreach ($oids as $oid) { if (is_numeric($data[0][$oid])) { $value = $data[0][$oid]; - } - else { + } else { $value = 'U'; } $fields[$oid] = $value; } if (isset($data[0]['udpInDatagrams']) && isset($data[0]['udpOutDatagrams'])) { - $tags = compact('rrd_def'); data_update($device, 'netstats-udp', $tags, $fields); diff --git a/includes/polling/ntp/cisco.inc.php b/includes/polling/ntp/cisco.inc.php index 9ea95f6820..f081a77041 100644 --- a/includes/polling/ntp/cisco.inc.php +++ b/includes/polling/ntp/cisco.inc.php @@ -18,7 +18,7 @@ $options = array(); $options['filter']['type'] = array('=',$module); $options['filter']['disabled'] = array('=',0); $options['filter']['ignore'] = array('=',0); -$components = $component->getComponents($device['device_id'],$options); +$components = $component->getComponents($device['device_id'], $options); // We only care about our device id. $components = $components[$device['device_id']]; @@ -73,8 +73,7 @@ if (count($components > 0)) { } // End foreach components // Write the Components back to the DB. - $component->setComponentPrefs($device['device_id'],$components); - + $component->setComponentPrefs($device['device_id'], $components); } // end if count components // Clean-up after yourself! diff --git a/includes/polling/os.inc.php b/includes/polling/os.inc.php index fcbf24a656..b410512806 100644 --- a/includes/polling/os.inc.php +++ b/includes/polling/os.inc.php @@ -3,12 +3,10 @@ if (is_file($config['install_dir'].'/includes/polling/os/'.$device['os'].'.inc.php')) { // OS Specific include $config['install_dir'].'/includes/polling/os/'.$device['os'].'.inc.php'; -} -else if ($device['os_group'] && is_file($config['install_dir'].'/includes/polling/os/'.$device['os_group'].'.inc.php')) { +} elseif ($device['os_group'] && is_file($config['install_dir'].'/includes/polling/os/'.$device['os_group'].'.inc.php')) { // OS Group Specific include $config['install_dir'].'/includes/polling/os/'.$device['os_group'].'.inc.php'; -} -else { +} else { echo "Generic :(\n"; } diff --git a/includes/polling/os/acs.inc.php b/includes/polling/os/acs.inc.php index 7f5242d230..27c8fc9978 100644 --- a/includes/polling/os/acs.inc.php +++ b/includes/polling/os/acs.inc.php @@ -1,13 +1,11 @@ $value) { - $indexName = substr($key, 0, -2); $channel = str_replace('ch', '', $value['bsnAPIfPhyChannelNumber']); $mac = str_replace(' ', ':', $stats[$indexName]['bsnAPDot3MacAddress']); $name = $stats[$indexName]['bsnAPName']; $numasoclients = $value['bsnApIfNoOfUsers']; - $radioArray = explode('.',$key); + $radioArray = explode('.', $key); $radionum = array_pop($radioArray); $txpow = $value['bsnAPIfPhyTxPowerLevel']; $type = $value['bsnAPIfType']; @@ -145,7 +144,7 @@ foreach ($radios as $key => $value) { if ($foundid == 0) { $ap_id = dbInsert( - array( + array( 'device_id' => $device['device_id'], 'name' => $name, 'radio_number' => $radionum, @@ -159,8 +158,9 @@ foreach ($radios as $key => $value) { 'numactbssid' => $numactbssid, 'nummonbssid' => $nummonbssid, 'interference' => $interference - ), - 'access_points'); + ), + 'access_points' + ); } else { dbUpdate( array( @@ -177,7 +177,9 @@ foreach ($radios as $key => $value) { 'interference' => $interference ), 'access_points', - '`accesspoint_id` = ?', array($foundid)); + '`accesspoint_id` = ?', + array($foundid) + ); } }//end foreach diff --git a/includes/polling/os/comware.inc.php b/includes/polling/os/comware.inc.php index 54010085ed..f1bae1baf4 100644 --- a/includes/polling/os/comware.inc.php +++ b/includes/polling/os/comware.inc.php @@ -8,7 +8,7 @@ echo 'Comware OS...'; $hardware = snmp_get($device, 'sysObjectID.0', '-Osqv', 'SNMPv2-MIB:HH3C-PRODUCT-ID-MIB'); -$data = str_replace(",","",$poll_device['sysDescr']); +$data = str_replace(",", "", $poll_device['sysDescr']); $explodeddata = explode(" ", $data); $version = $explodeddata['6']; $features = $explodeddata['8']; diff --git a/includes/polling/os/datadomain.inc.php b/includes/polling/os/datadomain.inc.php index 9d4df63860..7dc65eeacb 100644 --- a/includes/polling/os/datadomain.inc.php +++ b/includes/polling/os/datadomain.inc.php @@ -4,4 +4,4 @@ preg_match('/Data Domain OS (.*)/', $poll_device['sysDescr'], $matches); $version = $matches[1]; -$hardware = trim(snmp_get($device, "systemHardwareDevice", "-OQv", "DATA-DOMAIN-MIB"),'"'); +$hardware = trim(snmp_get($device, "systemHardwareDevice", "-OQv", "DATA-DOMAIN-MIB"), '"'); diff --git a/includes/polling/os/dell-laser.inc.php b/includes/polling/os/dell-laser.inc.php index 05be449b85..61a0d99f9d 100644 --- a/includes/polling/os/dell-laser.inc.php +++ b/includes/polling/os/dell-laser.inc.php @@ -21,8 +21,7 @@ list(,$version) = explode('Engine ', $poll_device['sysDescr']); if ($version) { $version = 'Engine '.trim($version, ')'); -} -else { +} else { $version = trim(snmp_get($device, '1.3.6.1.4.1.674.10898.100.1.1.1.0', '-OQv'), '"'); if (!$version) { $version = trim(snmp_get($device, '1.3.6.1.4.1.641.1.1.1.0', '-OQv'), '"'); diff --git a/includes/polling/os/deltaups.inc.php b/includes/polling/os/deltaups.inc.php index fe66ba5597..d96bbc6f03 100644 --- a/includes/polling/os/deltaups.inc.php +++ b/includes/polling/os/deltaups.inc.php @@ -2,10 +2,10 @@ # DeltaUPS-MIB::dupsIdentManufacturer.0 = STRING: "Socomec" # DeltaUPS-MIB::dupsIdentModel.0 = STRING: "NETYS RT 1/1 UPS" -$hardware = trim(snmp_get($device, "dupsIdentManufacturer.0", "-OQv", "DeltaUPS-MIB", ""),'" '); -$hardware .= ' ' . trim(snmp_get($device, "dupsIdentModel.0", "-OQv", "DeltaUPS-MIB", ""),'" '); +$hardware = trim(snmp_get($device, "dupsIdentManufacturer.0", "-OQv", "DeltaUPS-MIB", ""), '" '); +$hardware .= ' ' . trim(snmp_get($device, "dupsIdentModel.0", "-OQv", "DeltaUPS-MIB", ""), '" '); # DeltaUPS-MIB::dupsIdentUPSSoftwareVersion.0 = STRING: "0.4" -$version = trim(snmp_get($device, "dupsIdentUPSSoftwareVersion.0", "-OQv", "DeltaUPS-MIB", ""),'" '); +$version = trim(snmp_get($device, "dupsIdentUPSSoftwareVersion.0", "-OQv", "DeltaUPS-MIB", ""), '" '); # DeltaUPS-MIB::dupsIdentAgentSoftwareVersion.0 = STRING: "2.0h " diff --git a/includes/polling/os/develop.inc.php b/includes/polling/os/develop.inc.php index 86dc994cfd..d4d0b9de53 100644 --- a/includes/polling/os/develop.inc.php +++ b/includes/polling/os/develop.inc.php @@ -9,4 +9,4 @@ * option) any later version. Please see LICENSE.txt at the top level of * the source code distribution for details. */ -$hardware = str_replace("Develop ","",$poll_device['sysDescr']); +$hardware = str_replace("Develop ", "", $poll_device['sysDescr']); diff --git a/includes/polling/os/dnos.inc.php b/includes/polling/os/dnos.inc.php index 59d13dc210..52253a8b06 100644 --- a/includes/polling/os/dnos.inc.php +++ b/includes/polling/os/dnos.inc.php @@ -11,14 +11,13 @@ Build Time: Mon May 4 20:52:56 2015"; $temp_hardware = snmp_get($device, 'productIdentificationDisplayName.0', '-Ovq', 'Dell-Vendor-MIB'); -if (preg_match('/Dell Networking N[1234].*/' , $temp_hardware) == 1) { // If Dell N-Series +if (preg_match('/Dell Networking N[1234].*/', $temp_hardware) == 1) { // If Dell N-Series $hardware = $temp_hardware; $version = snmp_get($device, 'productIdentificationVersion.0', '-Ovq', 'Dell-Vendor-MIB'); $features = snmp_get($device, 'productIdentificationDescription.0', '-Ovq', 'Dell-Vendor-MIB'); -} -else { // Assume S-series - $sysDescr = preg_replace('/[\r]+/',' ', $poll_device['sysDescr']); +} else { // Assume S-series + $sysDescr = preg_replace('/[\r]+/', ' ', $poll_device['sysDescr']); list(,,$version,$hardware,,) = explode(PHP_EOL, $sysDescr); - list(,$version) = explode(': ',$version); - list(,$hardware) = explode(': ',$hardware); + list(,$version) = explode(': ', $version); + list(,$hardware) = explode(': ', $hardware); } diff --git a/includes/polling/os/edgeswitch.inc.php b/includes/polling/os/edgeswitch.inc.php index 5ffb02c30b..71407b2338 100644 --- a/includes/polling/os/edgeswitch.inc.php +++ b/includes/polling/os/edgeswitch.inc.php @@ -1,8 +1,8 @@ null)); } @@ -130,8 +129,7 @@ foreach ($vrfs_lite_cisco as $vrf_lite) { dbUpdate($ospf_instance_update, 'ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ? AND `context_name`=? ', array($device['device_id'], $ospf_instance_id, $device['context_name'])); echo 'U'; unset($ospf_instance_update); - } - else { + } else { echo '.'; } @@ -192,16 +190,14 @@ foreach ($vrfs_lite_cisco as $vrf_lite) { dbUpdate($ospf_area_update, 'ospf_areas', '`device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_id, $device['context_name'])); echo 'U'; unset($ospf_area_update); - } - else { + } else { echo '.'; } unset($ospf_area_poll); unset($ospf_area_db); $ospf_area_count++; - } - else { + } else { dbDelete('ospf_ports', '`device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId'], $device['context_name'])); }//end if }//end foreach @@ -248,8 +244,7 @@ foreach ($vrfs_lite_cisco as $vrf_lite) { if ($ospf_port_poll['ospfAddressLessIf']) { $ospf_port_poll['port_id'] = @dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ospf_port_poll['ospfAddressLessIf'])); - } - else { + } else { $ospf_port_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ? AND A.context_name = ?', array($ospf_port_poll['ospfIfIpAddress'], $device['device_id'], $device['context_name'])); } @@ -266,16 +261,14 @@ foreach ($vrfs_lite_cisco as $vrf_lite) { dbUpdate($ospf_port_update, 'ospf_ports', '`device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_id, $device['context_name'])); echo 'U'; unset($ospf_port_update); - } - else { + } else { echo '.'; } unset($ospf_port_poll); unset($ospf_port_db); $ospf_port_count++; - } - else { + } else { dbDelete('ospf_ports', '`device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_db['ospf_port_id'], $device['context_name'])); // ("DELETE FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."' AND `ospf_port_id` = '".$ospf_port_db['ospf_port_id']."'"); echo '-'; @@ -336,8 +329,7 @@ foreach ($vrfs_lite_cisco as $vrf_lite) { if ($ospf_nbr_db[$device['context_name']]['port_id'] != $ospf_nbr_poll['port_id']) { if (!empty($ospf_nbr_poll['port_id'])) { $ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']); - } - else { + } else { $ospf_nbr_update = array('port_id' => array('NULL')); } } @@ -357,16 +349,14 @@ foreach ($vrfs_lite_cisco as $vrf_lite) { dbUpdate($ospf_nbr_update, 'ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_id, $device['context_name'])); echo 'U'; unset($ospf_nbr_update); - } - else { + } else { echo '.'; } unset($ospf_nbr_poll); unset($ospf_nbr_db); $ospf_nbr_count++; - } - else { + } else { dbDelete('ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_db['ospf_nbr_id'], $device['context_name'])); echo '-'; }//end if diff --git a/includes/polling/port-etherlike.inc.php b/includes/polling/port-etherlike.inc.php index 67a05b77ca..54c727198d 100644 --- a/includes/polling/port-etherlike.inc.php +++ b/includes/polling/port-etherlike.inc.php @@ -18,7 +18,7 @@ if ($this_port['dot3StatsIndex'] and $port['ifType'] == 'ethernetCsmacd') { } $tags = compact('ifName', 'rrd_name', 'rrd_def', 'rrd_oldname'); - data_update($device,'dot3',$tags,$fields); + data_update($device, 'dot3', $tags, $fields); echo 'EtherLike '; } diff --git a/includes/polling/port-poe.inc.php b/includes/polling/port-poe.inc.php index eae9939cc9..e832d2ca9a 100644 --- a/includes/polling/port-poe.inc.php +++ b/includes/polling/port-poe.inc.php @@ -54,7 +54,7 @@ if ($this_port['dot3StatsIndex'] && $port['ifType'] == 'ethernetCsmacd') { ); $tags = compact('ifName', 'rrd_name', 'rrd_def'); - data_update($device,'poe',$tags,$fields); + data_update($device, 'poe', $tags, $fields); echo 'PoE '; }//end if diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index 4855fdc120..660057694a 100644 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -127,8 +127,7 @@ $port_stats = snmpwalk_cache_oid($device, 'ifXEntry', $port_stats, 'IF-MIB'); $hc_test = array_slice($port_stats, 0, 1); if (!isset($hc_test[0]['ifHCInOctets']) && !is_numeric($hc_test[0]['ifHCInOctets'])) { $port_stats = snmpwalk_cache_oid($device, 'ifEntry', $port_stats, 'IF-MIB'); -} -else { +} else { foreach ($ifmib_oids as $oid) { echo "$oid "; $port_stats = snmpwalk_cache_oid($device, $oid, $port_stats, 'IF-MIB'); @@ -138,8 +137,7 @@ else { if ($config['enable_ports_etherlike']) { echo 'dot3Stats '; $port_stats = snmpwalk_cache_oid($device, 'dot3StatsEntry', $port_stats, 'EtherLike-MIB'); -} -else { +} else { echo 'dot3StatsDuplexStatus'; $port_stats = snmpwalk_cache_oid($device, 'dot3StatsDuplexStatus', $port_stats, 'EtherLike-MIB'); } @@ -195,8 +193,7 @@ if ($device['os_group'] == 'cisco') { $port_stats = snmpwalk_cache_oid($device, 'vmVlan', $port_stats, 'CISCO-VLAN-MEMBERSHIP-MIB'); $port_stats = snmpwalk_cache_oid($device, 'vlanTrunkPortEncapsulationOperType', $port_stats, 'CISCO-VTP-MIB'); $port_stats = snmpwalk_cache_oid($device, 'vlanTrunkPortNativeVlan', $port_stats, 'CISCO-VTP-MIB'); -} -else { +} else { $port_stats = snmpwalk_cache_oid($device, 'dot1qPortVlanTable', $port_stats, 'Q-BRIDGE-MIB'); }//end if @@ -212,12 +209,13 @@ d_echo($port_stats); // or maybe other means in the future. The default port association mode still is ifIndex for // compatibility reasons. $port_association_mode = $config['default_port_association_mode']; -if ($device['port_association_mode']) - $port_association_mode = get_port_assoc_mode_name ($device['port_association_mode']); +if ($device['port_association_mode']) { + $port_association_mode = get_port_assoc_mode_name($device['port_association_mode']); +} // Query known ports and mapping table in order of discovery to make sure // the latest discoverd/polled port is in the mapping tables. -$ports_mapped = get_ports_mapped ($device['device_id'], true); +$ports_mapped = get_ports_mapped($device['device_id'], true); $ports = $ports_mapped['ports']; // @@ -240,7 +238,7 @@ foreach ($port_stats as $ifIndex => $port) { $ifName = $port['ifName']; // Get port_id according to port_association_mode used for this device - $port_id = get_port_id ($ports_mapped, $port, $port_association_mode); + $port_id = get_port_id($ports_mapped, $port, $port_association_mode); if (is_port_valid($port, $device)) { echo 'valid'; @@ -268,7 +266,7 @@ foreach ($port_stats as $ifIndex => $port) { * can be legally set to 0, which would yield True when checking if the * value is empty(). */ - if ($config['ignore_unmapable_port'] === True and in_array ($port[$port_association_mode], array ('', Null))) { + if ($config['ignore_unmapable_port'] === true and in_array($port[$port_association_mode], array ('', null))) { continue; } @@ -277,10 +275,8 @@ foreach ($port_stats as $ifIndex => $port) { $ports[$port_id] = dbFetchRow('SELECT * FROM `ports` WHERE `port_id` = ?', array($port_id)); echo 'Adding: '.$ifName.'('.$ifIndex.')('.$port_id.')'; // print_r($ports); - } - - // Port re-discovered after previous deletion? - else if ($ports[$port_id]['deleted'] == 1) { + } // Port re-discovered after previous deletion? + elseif ($ports[$port_id]['deleted'] == 1) { dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($port_id)); $ports[$port_id]['deleted'] = '0'; } @@ -299,11 +295,9 @@ foreach ($port_stats as $ifIndex => $port) { $ports[$port_id]['ifIndex'] = $ifIndex; $port_stats[$ifIndex]['port_id'] = $port_id; - /* Build a list of all ports, identified by their port_id, found within this poller run. */ - $ports_found[] = $port_id; - } - - // Port vanished (mark as deleted) + /* Build a list of all ports, identified by their port_id, found within this poller run. */ + $ports_found[] = $port_id; + } // Port vanished (mark as deleted) else { if ($ports[$port_id]['deleted'] != '1') { dbUpdate(array('deleted' => '1'), 'ports', '`port_id` = ?', array($port_id)); @@ -331,7 +325,7 @@ foreach ($ports as $port) { * If this port did not show up in $port_stats before it has been deleted * since the last poller run. Mark it deleted in the database and go on. */ - if (! in_array ($port_id, $ports_found)) { + if (! in_array($port_id, $ports_found)) { if ($port['deleted'] != '1') { dbUpdate(array('deleted' => '1'), 'ports', '`device_id` = ? AND `port_id` = ?', array($device['device_id'], $port_id)); echo "$port_info_string deleted.\n"; @@ -445,8 +439,8 @@ foreach ($ports as $port) { // FIXME use $q_bridge_mib[$this_port['ifIndex']] to see if it is a trunk (>1 array count) echo 'VLAN == '.$this_port['ifVlan']; - // When devices do not provide ifAlias data, populate with ifDescr data if configured - if ($this_port['ifAlias'] == '' || $this_port['ifAlias'] == NULL) { + // When devices do not provide ifAlias data, populate with ifDescr data if configured + if ($this_port['ifAlias'] == '' || $this_port['ifAlias'] == null) { $this_port['ifAlias'] = $this_port['ifDescr']; d_echo('Using ifDescr as ifAlias'); } @@ -454,7 +448,6 @@ foreach ($ports as $port) { // Update IF-MIB data $tune_port = false; foreach ($data_oids as $oid) { - if ($oid == 'ifAlias') { if ($attribs['ifName:'.$port['ifName']]) { $this_port['ifAlias'] = $port['ifAlias']; @@ -471,12 +464,10 @@ foreach ($ports as $port) { log_event($oid.': '.$port[$oid].' -> NULL', $device, 'interface', $port['port_id']); if ($debug) { d_echo($oid.': '.$port[$oid].' -> NULL '); - } - else { + } else { echo $oid.' '; } - } - else if ($port[$oid] != $this_port[$oid]) { + } elseif ($port[$oid] != $this_port[$oid]) { $port_tune = $attribs['ifName_tune:'.$port['ifName']]; $device_tune = $attribs['override_rrdtool_tune']; if ($port_tune == "true" || @@ -493,8 +484,7 @@ foreach ($ports as $port) { log_event($oid.': '.$port[$oid].' -> '.$this_port[$oid], $device, 'interface', $port['port_id']); if ($debug) { d_echo($oid.': '.$port[$oid].' -> '.$this_port[$oid].' '); - } - else { + } else { echo $oid.' '; } } @@ -518,8 +508,7 @@ foreach ($ports as $port) { if (!isset($port_ifAlias[$attrib])) { $port_ifAlias[$attrib] = array('NULL'); $log_port = 'NULL'; - } - else { + } else { $log_port = $port_ifAlias[$attrib]; } @@ -637,7 +626,7 @@ foreach ($ports as $port) { ); if ($tune_port === true) { - rrdtool_tune('port',$rrdfile,$this_port['ifSpeed']); + rrdtool_tune('port', $rrdfile, $this_port['ifSpeed']); } $port_descr_type = $port['port_descr_type']; diff --git a/includes/polling/processors.inc.php b/includes/polling/processors.inc.php index 6690de34f8..f616f99e51 100644 --- a/includes/polling/processors.inc.php +++ b/includes/polling/processors.inc.php @@ -9,8 +9,7 @@ foreach (dbFetchRows('SELECT * FROM processors WHERE device_id = ?', array($devi $file = $config['install_dir'].'/includes/polling/processors/'. $processor_type .'.inc.php'; if (is_file($file)) { include $file; - } - else { + } else { $proc = snmp_get($device, $processor['processor_oid'], '-O Uqnv', '""'); } @@ -32,7 +31,7 @@ foreach (dbFetchRows('SELECT * FROM processors WHERE device_id = ?', array($devi ); $tags = compact('processor_type', 'processor_index', 'rrd_name', 'rrd_def'); - data_update($device,'processors',$tags,$fields); + data_update($device, 'processors', $tags, $fields); dbUpdate(array('processor_usage' => $proc), 'processors', '`processor_id` = ?', array($processor['processor_id'])); }//end foreach diff --git a/includes/polling/processors/dnos-cpu.inc.php b/includes/polling/processors/dnos-cpu.inc.php index cdc4513491..da44920b21 100644 --- a/includes/polling/processors/dnos-cpu.inc.php +++ b/includes/polling/processors/dnos-cpu.inc.php @@ -2,7 +2,6 @@ echo 'DNOS CPU Usage'; if ($device['os'] == 'dnos') { - preg_match('/(\d*\.\d*)/', snmp_get($device, '.1.3.6.1.4.1.674.10895.5000.2.6132.1.1.1.1.4.9.0', '-OvQ'), $matches); $proc = $matches[0]; } diff --git a/includes/polling/processors/extreme-cpu.inc.php b/includes/polling/processors/extreme-cpu.inc.php index f45d63f24c..c29133c3a0 100644 --- a/includes/polling/processors/extreme-cpu.inc.php +++ b/includes/polling/processors/extreme-cpu.inc.php @@ -12,4 +12,3 @@ if ($device['os'] == 'xos') { //substr(snmp_get($device, '1.3.6.1.4.1.1916.1.32.1.4.1.9.1', '-Ovq', 'EXTREME-BASE-MIB'), 0, 2); } } - diff --git a/includes/polling/processors/nos.inc.php b/includes/polling/processors/nos.inc.php index 158ad3ce9b..081edf2a0a 100644 --- a/includes/polling/processors/nos.inc.php +++ b/includes/polling/processors/nos.inc.php @@ -1,3 +1,3 @@ = 16607) { - $mibdir = $config['mibdir'].'/pbn'.':'.$config['mibdir']; $usage = snmp_get($device, 'nmspmCPUTotal5min.1', '-OUvQ', 'NMS-PROCESS-MIB', $mibdir); diff --git a/includes/polling/processors/powerconnect.inc.php b/includes/polling/processors/powerconnect.inc.php index a614a0a895..340feda8d5 100644 --- a/includes/polling/processors/powerconnect.inc.php +++ b/includes/polling/processors/powerconnect.inc.php @@ -6,7 +6,7 @@ if (strpos($device["sysObjectID"], "enterprises.674.10895.3031") !== false) { } elseif (strpos($device["sysObjectID"], "enterprises.674.10895.3024") !== false) { d_echo("Dell Powerconnect 8024F"); $values = trim(snmp_get($device, $processor['processor_oid'], '-O Uqnv'), '""'); - $values = ltrim($values,' '); + $values = ltrim($values, ' '); preg_match('/(\d*\.\d*)/', $values, $matches); $proc = $matches[0]; } else { diff --git a/includes/polling/processors/viprinux.inc.php b/includes/polling/processors/viprinux.inc.php index 884ead0a3c..6ddf9c1810 100644 --- a/includes/polling/processors/viprinux.inc.php +++ b/includes/polling/processors/viprinux.inc.php @@ -2,7 +2,7 @@ echo 'Viprinet CPU Usage'; if ($device['os'] == 'viprinux') { - $usage = str_replace('"',"", snmp_get($device, 'VIPRINET-MIB::vpnRouterCPULoad.0', '-OvQ')); + $usage = str_replace('"', "", snmp_get($device, 'VIPRINET-MIB::vpnRouterCPULoad.0', '-OvQ')); if (is_numeric($usage)) { $proc = ($usage * 100); } diff --git a/includes/polling/signal/cambium.inc.php b/includes/polling/signal/cambium.inc.php index 12433d084a..a01f5676a8 100644 --- a/includes/polling/signal/cambium.inc.php +++ b/includes/polling/signal/cambium.inc.php @@ -11,23 +11,19 @@ $cambium_type = snmp_get($device, 'sysDescr.0', '-Oqv', ''); $is_epmp = snmp_get($device, 'sysObjectID.0', '-Oqv', ''); if (strstr($cambium_type, 'Cambium PTP 50650')) { - $mib = ':CAMBIUM-PTP650-MIB'; - } -else if (strstr($cambium_type, 'PTP250')) { - $mib = ':CAMBIUM-PTP250-MIB'; -} -else if (strstr($is_epmp, '.17713.21')) { - $epmp_ap = snmp_get($device, 'wirelessInterfaceMode.0', '-Oqv', 'CAMBIUM-PMP80211-MIB'); + $mib = ':CAMBIUM-PTP650-MIB'; +} elseif (strstr($cambium_type, 'PTP250')) { + $mib = ':CAMBIUM-PTP250-MIB'; +} elseif (strstr($is_epmp, '.17713.21')) { + $epmp_ap = snmp_get($device, 'wirelessInterfaceMode.0', '-Oqv', 'CAMBIUM-PMP80211-MIB'); $epmp_number = snmp_get($device, 'cambiumSubModeType.0', '-Oqv', 'CAMBIUM-PMP80211-MIB'); - if ($epmp_ap == 1) { + if ($epmp_ap == 1) { if ($epmp_number != 1) { $mib = ':CAMBIUM-PMP80211-MIB'; } - } - else { + } else { $mib = ':CAMBIUM-PMP80211-MIB'; } +} else { + $mib = ':WHISP-BOX-MIBV2-MIB'; } -else { - $mib = ':WHISP-BOX-MIBV2-MIB'; -} \ No newline at end of file diff --git a/includes/polling/signal/canopy.inc.php b/includes/polling/signal/canopy.inc.php index 6438ad012d..9738a56129 100644 --- a/includes/polling/signal/canopy.inc.php +++ b/includes/polling/signal/canopy.inc.php @@ -10,23 +10,19 @@ */ $cambium_type = snmp_get($device, 'sysDescr.0', '-Oqv', ''); if (strstr($cambium_type, 'BHUL450-DES') || stristr($cambium_type, 'BHUL450-AES')) { - $masterSlaveMode = snmp_get($device, 'bhTimingMode.0', '-Oqv', 'WHISP-BOX-MIBV2-MIB'); - if ($masterSlaveMode == "timingMaster") { - $mib = ':WHISP-APS-MIB'; - } - else { - $mib = ':WHISP-SM-MIB'; - } + $masterSlaveMode = snmp_get($device, 'bhTimingMode.0', '-Oqv', 'WHISP-BOX-MIBV2-MIB'); + if ($masterSlaveMode == "timingMaster") { + $mib = ':WHISP-APS-MIB'; + } else { + $mib = ':WHISP-SM-MIB'; + } +} elseif (strstr($cambium_type, 'BHUL') || stristr($cambium_type, 'BH')) { + $masterSlaveMode = snmp_get($device, 'bhTimingMode.0', '-Oqv', 'WHISP-BOX-MIBV2-MIB'); + if ($masterSlaveMode == "timingMaster") { + $mib = ':WHISP-APS-MIB'; + } else { + $mib = ':WHISP-BOX-MIBV2-MIB'; + } +} else { + $mib = ':WHISP-BOX-MIBV2-MIB'; } -else if (strstr($cambium_type, 'BHUL') || stristr($cambium_type, 'BH')) { - $masterSlaveMode = snmp_get($device, 'bhTimingMode.0', '-Oqv', 'WHISP-BOX-MIBV2-MIB'); - if ($masterSlaveMode == "timingMaster") { - $mib = ':WHISP-APS-MIB'; - } - else { - $mib = ':WHISP-BOX-MIBV2-MIB'; - } -} -else { - $mib = ':WHISP-BOX-MIBV2-MIB'; -} \ No newline at end of file diff --git a/includes/polling/storage.inc.php b/includes/polling/storage.inc.php index a1349eedbe..196416609b 100644 --- a/includes/polling/storage.inc.php +++ b/includes/polling/storage.inc.php @@ -23,8 +23,7 @@ foreach (dbFetchRows('SELECT * FROM storage WHERE device_id = ?', array($device[ if ($storage['size']) { $percent = round(($storage['used'] / $storage['size'] * 100)); - } - else { + } else { $percent = 0; } diff --git a/includes/polling/storage/eql-storage.inc.php b/includes/polling/storage/eql-storage.inc.php index d99dabfe5d..c496470963 100644 --- a/includes/polling/storage/eql-storage.inc.php +++ b/includes/polling/storage/eql-storage.inc.php @@ -29,24 +29,34 @@ $storage_cache20 = array(); d_echo($storage); foreach ($storage_cache1['eql-storage'] as $index => $ventry) { - if (!array_key_exists('eqliscsiVolumeName', $ventry)) continue; - if (is_int($index)) $iind = $index; - else { + if (!array_key_exists('eqliscsiVolumeName', $ventry)) { + continue; + } + if (is_int($index)) { + $iind = $index; + } else { $arrindex = explode(".", $index); $iind = (int)(end($arrindex))+0; } - if (is_int($iind)) $storage_cache10[$iind] = $ventry; + if (is_int($iind)) { + $storage_cache10[$iind] = $ventry; + } } d_echo($storage_cache10); foreach ($storage_cache2['eql-storage'] as $index => $vsentry) { - if (!array_key_exists('eqliscsiVolumeStatusAvailable', $vsentry)) continue; - if (is_int($index)) $iind = $index; - else { + if (!array_key_exists('eqliscsiVolumeStatusAvailable', $vsentry)) { + continue; + } + if (is_int($index)) { + $iind = $index; + } else { $arrindex = explode(".", $index); $iind = (int)(end($arrindex))+0; - } - if (is_int($iind)) $storage_cache20[$iind] = $vsentry; + } + if (is_int($iind)) { + $storage_cache20[$iind] = $vsentry; + } } d_echo($storage_cache20); diff --git a/includes/polling/storage/netapp-storage.inc.php b/includes/polling/storage/netapp-storage.inc.php index dbeffda0ee..08858d914e 100644 --- a/includes/polling/storage/netapp-storage.inc.php +++ b/includes/polling/storage/netapp-storage.inc.php @@ -11,8 +11,7 @@ $storage['units'] = 1024; if (isset($entry['df64TotalKBytes']) && is_numeric($entry['df64TotalKBytes'])) { $storage['used'] = ($entry['df64UsedKBytes'] * $storage['units']); $storage['size'] = ($entry['df64TotalKBytes'] * $storage['units']); -} -else { +} else { $storage['used'] = ($entry['dfKBytesUsed'] * $storage['units']); $storage['size'] = ($entry['dfKBytesTotal'] * $storage['units']); } diff --git a/includes/polling/stp.inc.php b/includes/polling/stp.inc.php index 27af0c75c4..234e00dcfc 100644 --- a/includes/polling/stp.inc.php +++ b/includes/polling/stp.inc.php @@ -23,7 +23,6 @@ $stpprotocol = snmp_get($device, 'dot1dStpProtocolSpecification.0', '-Oqv', 'RST // FIXME I don't know what "unknown" means, perhaps MSTP? (saw it on some cisco devices) // But we can try to retrieve data if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') { - // set time multiplier to convert from centiseconds to seconds // all time values are stored in databese as seconds $tm = '0.01'; @@ -63,20 +62,19 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') { $time_since_change = snmp_get($device, 'dot1dStpTimeSinceTopologyChange.0', '-Ovt', 'RSTP-MIB'); if ($time_since_change > '100') { $time_since_change = substr($time_since_change, 0, -2); // convert to seconds since change - } - else { + } else { $time_since_change = '0'; - } + } $stp['timeSinceTopologyChange'] = $time_since_change; - // designated root is stored in format 2 octet bridge priority + MAC address, so we need to normalize it + // designated root is stored in format 2 octet bridge priority + MAC address, so we need to normalize it $dr = str_replace(array(' ', ':', '-'), '', strtolower($stp_raw[0]['dot1dStpDesignatedRoot'])); $dr = substr($dr, -12); //remove first two octets $stp['designatedRoot'] = $dr; // normalize the MAC $mac_array = explode(':', $mac_raw); - foreach($mac_array as &$octet) { + foreach ($mac_array as &$octet) { if (strlen($octet) < 2) { $octet = "0" . $octet; // add suppressed 0 } @@ -86,8 +84,7 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') { // I'm the boss? if ($stp['bridgeAddress'] == $stp['designatedRoot']) { $stp['rootBridge'] = '1'; - } - else { + } else { $stp['rootBridge'] = '0'; } @@ -109,7 +106,7 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') { // FIXME log_event should log really changing time, not polling time // but upstream function do not care about this at the moment. // - // saw same problem with this line librenms/includes/polling/system.inc.php + // saw same problem with this line librenms/includes/polling/system.inc.php // log_event('Device rebooted after '.formatUptime($device['uptime']), $device, 'reboot', $device['uptime']); // ToDo fix log_event() // @@ -117,12 +114,12 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') { log_event('STP topology changed after: '.formatUptime($stp['timeSinceTopologyChange']), $device, 'stp'); } // Write to db - dbUpdate($stp,'stp','device_id = ?', array($device['device_id'])); + dbUpdate($stp, 'stp', 'device_id = ?', array($device['device_id'])); echo '.'; } // STP port related stuff - foreach ($stp_raw as $port => $value){ + foreach ($stp_raw as $port => $value) { if ($port) { // $stp_raw[0] ist not port related so we skip this one $stp_port = array( 'priority' => $stp_raw[$port]['dot1dStpPortPriority'], @@ -158,8 +155,7 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') { $dp = $stp_raw[$port]['dot1dStpPortDesignatedPort'] - $dp_value; $stp_port['designatedPort'] = $dp; } - } - else { + } else { // Port saved in format priority+port (ieee 802.1d-1998: clause 8.5.5.1) $dp = substr($stp_raw[$port]['dot1dStpPortDesignatedPort'], -2); //discard the first octet (priority part) $stp_port['designatedPort'] = hexdec($dp); @@ -168,7 +164,7 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') { //d_echo($stp_port); // Update db - dbUpdate($stp_port,'ports_stp','`device_id` = ? AND `port_id` = ?', array($device['device_id'], $stp_port['port_id'])); + dbUpdate($stp_port, 'ports_stp', '`device_id` = ? AND `port_id` = ?', array($device['device_id'], $stp_port['port_id'])); echo '.'; } } diff --git a/includes/polling/temperatures/cambium.inc.php b/includes/polling/temperatures/cambium.inc.php index 7aa4c5c2ae..53485533d2 100644 --- a/includes/polling/temperatures/cambium.inc.php +++ b/includes/polling/temperatures/cambium.inc.php @@ -1,3 +1,3 @@ 0) { - dbBulkInsert('processes',$data); + dbBulkInsert('processes', $data); } echo "\n"; } diff --git a/includes/polling/unix-agent/munin-plugins.inc.php b/includes/polling/unix-agent/munin-plugins.inc.php index 6aaef6185c..f8e588f535 100644 --- a/includes/polling/unix-agent/munin-plugins.inc.php +++ b/includes/polling/unix-agent/munin-plugins.inc.php @@ -35,8 +35,7 @@ if (!empty($agent_data['munin'])) { if (preg_match('/^graph_/', $key)) { list(,$key) = explode('_', $key); $plugin['graph'][$key] = $value; - } - else { + } else { list($metric,$key) = explode('.', $key); $plugin['values'][$metric][$key] = $value; } @@ -54,8 +53,7 @@ if (!empty($agent_data['munin'])) { 'mplug_info' => ($plugin['graph']['info'] == null ? array('NULL') : $plugin['graph']['info']), ); $mplug_id = dbInsert($insert, 'munin_plugins'); - } - else { + } else { $mplug_id = $plugins_db[$plugin_type]['id']; } @@ -97,7 +95,7 @@ if (!empty($agent_data['munin'])) { 'rrd_def' => 'DS:val:' . $data['type'] . ':600:U:U', 'rrd_name' => $base_rrd_name . '_' . $name ); - data_update($device,'munin-plugins',$tags,$fields); + data_update($device, 'munin-plugins', $tags, $fields); if (empty($ds_list[$ds_uniq])) { $insert = array( @@ -123,8 +121,7 @@ if (!empty($agent_data['munin'])) { $ds_id = dbInsert($insert, 'munin_plugins_ds'); }//end if }//end foreach - } - else { + } else { echo "No ID!\n"; }//end if }//end foreach diff --git a/includes/polling/unix-agent/packages.inc.php b/includes/polling/unix-agent/packages.inc.php index fdf71a9786..a7e639907d 100644 --- a/includes/polling/unix-agent/packages.inc.php +++ b/includes/polling/unix-agent/packages.inc.php @@ -91,14 +91,12 @@ foreach ($pkgs_id as $pkg) { if (!empty($pkg_update)) { dbUpdate($pkg_update, 'packages', '`pkg_id` = ?', array($id)); echo 'u'; - } - else { + } else { echo '.'; } unset($pkgs_db_id[$id]); - } - else { + } else { if (count($pkgs[$manager][$name][$arch], 1) > '10' || count($pkgs_db[$manager][$name][$arch], 1) == '0') { dbInsert( array( @@ -115,20 +113,17 @@ foreach ($pkgs_id as $pkg) { ); if ($build != '') { $dbuild = '-'.$build; - } - else { + } else { $dbuild = ''; } echo '+'.$name.'-'.$version.$dbuild.'-'.$arch; log_event('Package installed: '.$name.' ('.$arch.') version '.$version.$dbuild, $device, 'package'); - } - else if (count($pkgs_db[$manager][$name][$arch], 1)) { + } elseif (count($pkgs_db[$manager][$name][$arch], 1)) { $pkg_c = dbFetchRow('SELECT * FROM `packages` WHERE `device_id` = ? AND `manager` = ? AND `name` = ? and `arch` = ? ORDER BY version DESC, build DESC', array($device['device_id'], $manager, $name, $arch)); if ($pkg_c['build'] != '') { $pkg_c_dbuild = '-'.$pkg_c['build']; - } - else { + } else { $pkg_c_dbuild = ''; } diff --git a/includes/polling/voltages/hytera.inc.php b/includes/polling/voltages/hytera.inc.php index 319edd0112..ae492f9616 100644 --- a/includes/polling/voltages/hytera.inc.php +++ b/includes/polling/voltages/hytera.inc.php @@ -1,4 +1,4 @@ $gps, - ); - $tags = compact('rrd_def'); - data_update($device, 'cambium-650-gps', $tags, $fields); - $graphs['cambium_650_gps'] = TRUE; -} \ No newline at end of file + 'gps' => $gps, + ); + $tags = compact('rrd_def'); + data_update($device, 'cambium-650-gps', $tags, $fields); + $graphs['cambium_650_gps'] = true; +} diff --git a/includes/polling/wireless/cambium-epmp.inc.php b/includes/polling/wireless/cambium-epmp.inc.php index f331aab52a..d8e0c0ea57 100644 --- a/includes/polling/wireless/cambium-epmp.inc.php +++ b/includes/polling/wireless/cambium-epmp.inc.php @@ -19,7 +19,7 @@ if (is_numeric($cambiumSTADLRSSI) && is_numeric($cambiumSTADLSNR)) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-epmp-RFStatus', $tags, $fields); - $graphs['cambium_epmp_RFStatus'] = TRUE; + $graphs['cambium_epmp_RFStatus'] = true; } $cambiumGPSNumTrackedSat = snmp_get($device, "cambiumGPSNumTrackedSat.0", "-Ovqn", "CAMBIUM-PMP80211-MIB"); @@ -35,7 +35,7 @@ if (is_numeric($cambiumGPSNumTrackedSat) && is_numeric($cambiumGPSNumVisibleSat) ); $tags = compact('rrd_def'); data_update($device, 'cambium-epmp-gps', $tags, $fields); - $graphs['cambium_epmp_gps'] = TRUE; + $graphs['cambium_epmp_gps'] = true; } $cambiumSTAUplinkMCSMode = snmp_get($device, "cambiumSTAUplinkMCSMode.0", "-Ovqn", "CAMBIUM-PMP80211-MIB"); @@ -51,7 +51,7 @@ if (is_numeric($cambiumSTAUplinkMCSMode) && is_numeric($cambiumSTADownlinkMCSMod ); $tags = compact('rrd_def'); data_update($device, 'cambium-epmp-modulation', $tags, $fields); - $graphs['cambium_epmp_modulation'] = TRUE; + $graphs['cambium_epmp_modulation'] = true; } $registeredSM = snmp_get($device, "cambiumAPNumberOfConnectedSTA.0", "-Ovqn", "CAMBIUM-PMP80211-MIB"); @@ -62,7 +62,7 @@ if (is_numeric($registeredSM)) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-epmp-registeredSM', $tags, $fields); - $graphs['cambium_epmp_registeredSM'] = TRUE; + $graphs['cambium_epmp_registeredSM'] = true; } $sysNetworkEntryAttempt = snmp_get($device, "sysNetworkEntryAttempt.0", "-Ovqn", "CAMBIUM-PMP80211-MIB"); @@ -81,7 +81,7 @@ if (is_numeric($sysNetworkEntryAttempt) && is_numeric($sysNetworkEntrySuccess) & ); $tags = compact('rrd_def'); data_update($device, 'cambium-epmp-access', $tags, $fields); - $graphs['cambium_epmp_access'] = TRUE; + $graphs['cambium_epmp_access'] = true; } $gpsSync = snmp_get($device, "cambiumEffectiveSyncSource.0", "-Ovqn", "CAMBIUM-PMP80211-MIB"); @@ -92,7 +92,7 @@ if (is_numeric($gpsSync)) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-epmp-gpsSync', $tags, $fields); - $graphs['cambium_epmp_gpsSync'] = TRUE; + $graphs['cambium_epmp_gpsSync'] = true; } $freq = snmp_get($device, "cambiumSTAConnectedRFFrequency.0", "-Ovqn", "CAMBIUM-PMP80211-MIB"); @@ -103,5 +103,5 @@ if (is_numeric($freq)) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-epmp-freq', $tags, $fields); - $graphs['cambium_epmp_freq'] = TRUE; + $graphs['cambium_epmp_freq'] = true; } diff --git a/includes/polling/wireless/cambium-generic.inc.php b/includes/polling/wireless/cambium-generic.inc.php index 46bb47ce60..63c21f70f4 100644 --- a/includes/polling/wireless/cambium-generic.inc.php +++ b/includes/polling/wireless/cambium-generic.inc.php @@ -22,7 +22,7 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-errorCount', $tags, $fields); - $graphs['cambium_generic_errorCount'] = TRUE; + $graphs['cambium_generic_errorCount'] = true; unset($rrd_filename,$fecInErrorsCount,$fecOutErrorsCount); } @@ -34,11 +34,11 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-crcErrors', $tags, $fields); - $graphs['cambium_generic_crcErrors'] = TRUE; + $graphs['cambium_generic_crcErrors'] = true; } - $vertical = str_replace('"',"",snmp_get($device, ".1.3.6.1.4.1.161.19.3.2.2.117.0", "-Ovqn", "")); - $horizontal = str_replace('"',"",snmp_get($device, ".1.3.6.1.4.1.161.19.3.2.2.118.0", "-Ovqn", "")); + $vertical = str_replace('"', "", snmp_get($device, ".1.3.6.1.4.1.161.19.3.2.2.117.0", "-Ovqn", "")); + $horizontal = str_replace('"', "", snmp_get($device, ".1.3.6.1.4.1.161.19.3.2.2.118.0", "-Ovqn", "")); $combined = snmp_get($device, "1.3.6.1.4.1.161.19.3.2.2.21.0", "-Ovqn", ""); if (is_numeric($vertical) && is_numeric($horizontal) && is_numeric($combined)) { $rrd_def = array( @@ -53,7 +53,7 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-signalHV', $tags, $fields); - $graphs['cambium_generic_signalHV'] = TRUE; + $graphs['cambium_generic_signalHV'] = true; unset($rrd_filename,$vertical,$horizontal,$combined); } @@ -65,7 +65,7 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-rssi', $tags, $fields); - $graphs['cambium_generic_rssi'] = TRUE; + $graphs['cambium_generic_rssi'] = true; unset($rrd_filename,$rssi); } @@ -77,12 +77,12 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-jitter', $tags, $fields); - $graphs['cambium_generic_jitter'] = TRUE; + $graphs['cambium_generic_jitter'] = true; unset($rrd_filename,$jitter); } - $horizontal = str_replace('"',"",snmp_get($device, "radioDbmHorizontal.0", "-Ovqn", "WHISP-SM-MIB")); - $vertical = str_replace('"',"",snmp_get($device, "radioDbmVertical.0", "-Ovqn", "WHISP-SM-MIB")); + $horizontal = str_replace('"', "", snmp_get($device, "radioDbmHorizontal.0", "-Ovqn", "WHISP-SM-MIB")); + $vertical = str_replace('"', "", snmp_get($device, "radioDbmVertical.0", "-Ovqn", "WHISP-SM-MIB")); if (is_numeric($horizontal) && is_numeric($vertical)) { $rrd_def = array( 'DS:horizontal:GAUGE:600:-100:100', @@ -94,11 +94,11 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-450-slaveHV', $tags, $fields); - $graphs['cambium_generic_450_slaveHV'] = TRUE; + $graphs['cambium_generic_450_slaveHV'] = true; unset($rrd_filename,$horizontal,$vertical); } - $ssr = str_replace('"',"",snmp_get($device, "signalStrengthRatio.0", "-Ovqn", "WHISP-SM-MIB")); + $ssr = str_replace('"', "", snmp_get($device, "signalStrengthRatio.0", "-Ovqn", "WHISP-SM-MIB")); if (is_numeric($ssr)) { $rrd_def = 'DS:ssr:GAUGE:600:-150:150'; $fields = array( @@ -106,12 +106,12 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-450-slaveSSR', $tags, $fields); - $graphs['cambium_generic_450_slaveSSR'] = TRUE; + $graphs['cambium_generic_450_slaveSSR'] = true; unset($rrd_filename,$ssr); } - $horizontal = str_replace('"',"",snmp_get($device, "signalToNoiseRatioSMHorizontal.0", "-Ovqn", "WHISP-SM-MIB")); - $vertical = str_replace('"',"",snmp_get($device, "signalToNoiseRatioSMVertical.0", "-Ovqn", "WHISP-SM-MIB")); + $horizontal = str_replace('"', "", snmp_get($device, "signalToNoiseRatioSMHorizontal.0", "-Ovqn", "WHISP-SM-MIB")); + $vertical = str_replace('"', "", snmp_get($device, "signalToNoiseRatioSMVertical.0", "-Ovqn", "WHISP-SM-MIB")); if (is_numeric($horizontal) && is_numeric($vertical)) { $rrd_def = array( 'DS:horizontal:GAUGE:600:0:100', @@ -123,7 +123,7 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-450-slaveSNR', $tags, $fields); - $graphs['cambium_generic_450_slaveSNR'] = TRUE; + $graphs['cambium_generic_450_slaveSNR'] = true; unset($rrd_filename,$horizontal,$vertical); } } @@ -132,11 +132,9 @@ if (strstr($hardware, 'AP') || strstr($hardware, 'Master') || strstr($hardware, $gpsStatus = snmp_get($device, "whispGPSStats.0", "-Ovqn", "WHISP-APS-MIB"); if ($gpsStatus == 'generatingSync') { $gpsStatus = 3; - } - else if ($gpsStatus == 'gpsLostSync') { + } elseif ($gpsStatus == 'gpsLostSync') { $gpsStatus = 2; - } - else if ($gpsStatus == 'gpsSynchronized') { + } elseif ($gpsStatus == 'gpsSynchronized') { $gpsStatus = 1; } if (is_numeric($gpsStatus)) { @@ -146,12 +144,12 @@ if (strstr($hardware, 'AP') || strstr($hardware, 'Master') || strstr($hardware, ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-whispGPSStats', $tags, $fields); - $graphs['cambium_generic_whispGPSStats'] = TRUE; + $graphs['cambium_generic_whispGPSStats'] = true; unset($rrd_filename,$gpsStatus); } - $visible = str_replace('"',"",snmp_get($device, ".1.3.6.1.4.1.161.19.3.4.4.7.0", "-Ovqn", "")); - $tracked = str_replace('"',"",snmp_get($device, ".1.3.6.1.4.1.161.19.3.4.4.8.0", "-Ovqn", "")); + $visible = str_replace('"', "", snmp_get($device, ".1.3.6.1.4.1.161.19.3.4.4.7.0", "-Ovqn", "")); + $tracked = str_replace('"', "", snmp_get($device, ".1.3.6.1.4.1.161.19.3.4.4.8.0", "-Ovqn", "")); if (is_numeric($visible) && is_numeric($tracked)) { $rrd_def = array( 'DS:visible:GAUGE:600:0:1000', @@ -163,26 +161,26 @@ if (strstr($hardware, 'AP') || strstr($hardware, 'Master') || strstr($hardware, ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-gpsStats', $tags, $fields); - $graphs['cambium_generic_gpsStats'] = TRUE; + $graphs['cambium_generic_gpsStats'] = true; unset($rrd_filename,$visible,$tracked); } } //PTP Equipment - $lastLevel = str_replace('"',"",snmp_get($device, "lastPowerLevel.2", "-Ovqn", "WHISP-APS-MIB")); - if (is_numeric($lastLevel)) { - $rrd_def = 'DS:last:GAUGE:600:-100:0'; - $fields = array( - 'last' => $lastLevel, - ); - $tags = compact('rrd_def'); - data_update($device, 'cambium-generic-450-powerlevel', $tags, $fields); - $graphs['cambium_generic_450_powerlevel'] = TRUE; - unset($lastLevel); - } + $lastLevel = str_replace('"', "", snmp_get($device, "lastPowerLevel.2", "-Ovqn", "WHISP-APS-MIB")); +if (is_numeric($lastLevel)) { + $rrd_def = 'DS:last:GAUGE:600:-100:0'; + $fields = array( + 'last' => $lastLevel, + ); + $tags = compact('rrd_def'); + data_update($device, 'cambium-generic-450-powerlevel', $tags, $fields); + $graphs['cambium_generic_450_powerlevel'] = true; + unset($lastLevel); +} if (strstr($version, 'AP') == false) { - $horizontal = str_replace('"',"",snmp_get($device, "linkRadioDbmHorizontal.2", "-Ovqn", "WHISP-APS-MIB")); - $vertical = str_replace('"',"",snmp_get($device, "linkRadioDbmVertical.2", "-Ovqn", "WHISP-APS-MIB")); + $horizontal = str_replace('"', "", snmp_get($device, "linkRadioDbmHorizontal.2", "-Ovqn", "WHISP-APS-MIB")); + $vertical = str_replace('"', "", snmp_get($device, "linkRadioDbmVertical.2", "-Ovqn", "WHISP-APS-MIB")); if (is_numeric($horizontal) && is_numeric($vertical)) { $rrd_def = array( 'DS:horizontal:GAUGE:600:-100:0', @@ -194,12 +192,12 @@ if (strstr($version, 'AP') == false) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-450-linkRadioDbm', $tags, $fields); - $graphs['cambium_generic_450_linkRadioDbm'] = TRUE; + $graphs['cambium_generic_450_linkRadioDbm'] = true; unset($rrd_filename,$horizontal,$horizontal); } - $horizontal = str_replace('"',"",snmp_get($device, "signalToNoiseRatioHorizontal.2", "-Ovqn", "WHISP-APS-MIB")); - $vertical = str_replace('"',"",snmp_get($device, "signalToNoiseRatioVertical.2", "-Ovqn", "WHISP-APS-MIB")); + $horizontal = str_replace('"', "", snmp_get($device, "signalToNoiseRatioHorizontal.2", "-Ovqn", "WHISP-APS-MIB")); + $vertical = str_replace('"', "", snmp_get($device, "signalToNoiseRatioVertical.2", "-Ovqn", "WHISP-APS-MIB")); if (is_numeric($horizontal) && is_numeric($vertical)) { $rrd_def = array( 'DS:horizontal:GAUGE:600:0:100', @@ -211,27 +209,27 @@ if (strstr($version, 'AP') == false) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-450-ptpSNR', $tags, $fields); - $graphs['cambium_generic_450_ptpSNR'] = TRUE; + $graphs['cambium_generic_450_ptpSNR'] = true; unset($rrd_filename,$horizontal,$horizontal); } - $ssr = str_replace('"',"",snmp_get($device, "linkSignalStrengthRatio.2", "-Ovqn", "WHISP-APS-MIB")); + $ssr = str_replace('"', "", snmp_get($device, "linkSignalStrengthRatio.2", "-Ovqn", "WHISP-APS-MIB")); if (is_numeric($ssr)) { - $rrd_def = 'DS:ssr:GAUGE:600:-150:150'; - $fields = array( + $rrd_def = 'DS:ssr:GAUGE:600:-150:150'; + $fields = array( 'ssr' => $ssr, - ); + ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-450-masterSSR', $tags, $fields); - $graphs['cambium_generic_450_masterSSR'] = TRUE; - unset($rrd_filename,$ssr); + $graphs['cambium_generic_450_masterSSR'] = true; + unset($rrd_filename,$ssr); } - if (strstr($hardware, 'PTP 230')) { - $dbmRadio = str_replace('"',"",snmp_get($device, "radioDbmInt.0", "-Ovqn", "WHISP-SM-MIB")); - $minRadio = str_replace('"',"",snmp_get($device, "minRadioDbm.0", "-Ovqn", "WHISP-SM-MIB")); - $maxRadio = str_replace('"',"",snmp_get($device, "maxRadioDbm.0", "-Ovqn", "WHISP-SM-MIB")); - $avgRadio = str_replace('"',"",snmp_get($device, "radioDbmAvg.0", "-Ovqn", "WHISP-SM-MIB")); + if (strstr($hardware, 'PTP 230')) { + $dbmRadio = str_replace('"', "", snmp_get($device, "radioDbmInt.0", "-Ovqn", "WHISP-SM-MIB")); + $minRadio = str_replace('"', "", snmp_get($device, "minRadioDbm.0", "-Ovqn", "WHISP-SM-MIB")); + $maxRadio = str_replace('"', "", snmp_get($device, "maxRadioDbm.0", "-Ovqn", "WHISP-SM-MIB")); + $avgRadio = str_replace('"', "", snmp_get($device, "radioDbmAvg.0", "-Ovqn", "WHISP-SM-MIB")); if (is_numeric($dbmRadio) && is_numeric($minRadio) && is_numeric($maxRadio) && is_numeric($avgRadio)) { $rrd_def = array( @@ -248,7 +246,7 @@ if (strstr($version, 'AP') == false) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-radioDbm', $tags, $fields); - $graphs['cambium_generic_radioDbm'] = TRUE; + $graphs['cambium_generic_radioDbm'] = true; unset($rrd_filename,$dbmRadio,$minRadio,$maxRadio,$avgRadio); } } @@ -256,8 +254,8 @@ if (strstr($version, 'AP') == false) { //AP Equipment if (strstr($version, 'AP')) { - $registered = str_replace('"',"",snmp_get($device, "regCount.0", "-Ovqn", "WHISP-APS-MIB")); - $failed = str_replace('"',"",snmp_get($device, "regFailureCount.0", "-Ovqn", "WHISP-APS-MIB")); + $registered = str_replace('"', "", snmp_get($device, "regCount.0", "-Ovqn", "WHISP-APS-MIB")); + $failed = str_replace('"', "", snmp_get($device, "regFailureCount.0", "-Ovqn", "WHISP-APS-MIB")); if (is_numeric($registered) && is_numeric($failed)) { $rrd_def = array( 'DS:regCount:GAUGE:600:0:15000', @@ -269,17 +267,16 @@ if (strstr($version, 'AP')) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-regCount', $tags, $fields); - $graphs['cambium_generic_regCount'] = TRUE; + $graphs['cambium_generic_regCount'] = true; unset($rrd_filename,$registered,$failed); } - $freq = str_replace('"',"",snmp_get($device, "currentRadioFreqCarrier.0", "-Ovqn", "WHISP-APS-MIB")); + $freq = str_replace('"', "", snmp_get($device, "currentRadioFreqCarrier.0", "-Ovqn", "WHISP-APS-MIB")); if (is_numeric($freq)) { $rrd_def = 'DS:freq:GAUGE:600:0:100000'; if ($freq > 99999) { $freq = $freq / 100000; - } - else { + } else { $freq = $freq / 10000; } $fields = array( @@ -287,7 +284,7 @@ if (strstr($version, 'AP')) { ); $tags = compact('rrd_def'); data_update($device, 'cambium-generic-freq', $tags, $fields); - $graphs['cambium_generic_freq'] = TRUE; + $graphs['cambium_generic_freq'] = true; unset($rrd_filename,$freq); } -} \ No newline at end of file +} diff --git a/includes/polling/wireless/canopy-generic.inc.php b/includes/polling/wireless/canopy-generic.inc.php index f5465c14e0..819983fad3 100644 --- a/includes/polling/wireless/canopy-generic.inc.php +++ b/includes/polling/wireless/canopy-generic.inc.php @@ -23,7 +23,7 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-errorCount', $tags, $fields); - $graphs['canopy_generic_errorCount'] = TRUE; + $graphs['canopy_generic_errorCount'] = true; unset($rrd_filename, $fecInErrorsCount, $fecOutErrorsCount); } @@ -35,7 +35,7 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-crcErrors', $tags, $fields); - $graphs['canopy_generic_crcErrors'] = TRUE; + $graphs['canopy_generic_crcErrors'] = true; } $vertical = str_replace('"', "", snmp_get($device, ".1.3.6.1.4.1.161.19.3.2.2.117.0", "-Ovqn", "")); @@ -54,7 +54,7 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-signalHV', $tags, $fields); - $graphs['canopy_generic_signalHV'] = TRUE; + $graphs['canopy_generic_signalHV'] = true; unset($rrd_filename, $vertical, $horizontal, $combined); } @@ -66,7 +66,7 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-rssi', $tags, $fields); - $graphs['canopy_generic_rssi'] = TRUE; + $graphs['canopy_generic_rssi'] = true; unset($rrd_filename, $rssi); } @@ -78,7 +78,7 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-jitter', $tags, $fields); - $graphs['canopy_generic_jitter'] = TRUE; + $graphs['canopy_generic_jitter'] = true; unset($rrd_filename, $jitter); } @@ -96,7 +96,7 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-450-slaveHV', $tags, $fields); - $graphs['canopy_generic_450_slaveHV'] = TRUE; + $graphs['canopy_generic_450_slaveHV'] = true; unset($rrd_filename, $horizontal, $vertical); } @@ -108,7 +108,7 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-450-slaveSSR', $tags, $fields); - $graphs['canopy_generic_450_slaveSSR'] = TRUE; + $graphs['canopy_generic_450_slaveSSR'] = true; unset($rrd_filename, $ssr); } @@ -125,7 +125,7 @@ if (strstr($hardware, 'CMM') == false) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-450-slaveSNR', $tags, $fields); - $graphs['canopy_generic_450_slaveSNR'] = TRUE; + $graphs['canopy_generic_450_slaveSNR'] = true; unset($rrd_filename, $horizontal, $vertical); } } @@ -134,9 +134,9 @@ if (strstr($hardware, 'AP') || strstr($hardware, 'Master') || strstr($hardware, $gpsStatus = snmp_get($device, "whispGPSStats.0", "-Ovqn", "WHISP-APS-MIB"); if ($gpsStatus == 'generatingSync') { $gpsStatus = 3; - } else if ($gpsStatus == 'gpsLostSync') { + } elseif ($gpsStatus == 'gpsLostSync') { $gpsStatus = 2; - } else if ($gpsStatus == 'gpsSynchronized') { + } elseif ($gpsStatus == 'gpsSynchronized') { $gpsStatus = 1; } if (is_numeric($gpsStatus)) { @@ -146,7 +146,7 @@ if (strstr($hardware, 'AP') || strstr($hardware, 'Master') || strstr($hardware, ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-whispGPSStats', $tags, $fields); - $graphs['canopy_generic_whispGPSStats'] = TRUE; + $graphs['canopy_generic_whispGPSStats'] = true; unset($rrd_filename, $gpsStatus); } @@ -163,7 +163,7 @@ if (strstr($hardware, 'AP') || strstr($hardware, 'Master') || strstr($hardware, ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-gpsStats', $tags, $fields); - $graphs['canopy_generic_gpsStats'] = TRUE; + $graphs['canopy_generic_gpsStats'] = true; unset($rrd_filename, $visible, $tracked); } } @@ -182,7 +182,7 @@ if (strstr($version, 'AP') == false) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-450-linkRadioDbm', $tags, $fields); - $graphs['canopy_generic_450_linkRadioDbm'] = TRUE; + $graphs['canopy_generic_450_linkRadioDbm'] = true; unset($rrd_filename, $horizontal, $horizontal); } @@ -194,7 +194,7 @@ if (strstr($version, 'AP') == false) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-450-powerlevel', $tags, $fields); - $graphs['canopy_generic_450_powerlevel'] = TRUE; + $graphs['canopy_generic_450_powerlevel'] = true; unset($lastLevel); } @@ -211,7 +211,7 @@ if (strstr($version, 'AP') == false) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-450-ptpSNR', $tags, $fields); - $graphs['canopy_generic_450_ptpSNR'] = TRUE; + $graphs['canopy_generic_450_ptpSNR'] = true; unset($rrd_filename, $horizontal, $horizontal); } @@ -223,7 +223,7 @@ if (strstr($version, 'AP') == false) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-450-masterSSR', $tags, $fields); - $graphs['canopy_generic_450_masterSSR'] = TRUE; + $graphs['canopy_generic_450_masterSSR'] = true; unset($rrd_filename, $ssr); } @@ -249,7 +249,7 @@ if (strstr($version, 'AP') == false) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-radioDbm', $tags, $fields); - $graphs['canopy_generic_radioDbm'] = TRUE; + $graphs['canopy_generic_radioDbm'] = true; unset($rrd_filename, $dbmRadio, $minRadio, $maxRadio, $avgRadio); } } @@ -270,7 +270,7 @@ if (strstr($version, 'AP')) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-regCount', $tags, $fields); - $graphs['canopy_generic_regCount'] = TRUE; + $graphs['canopy_generic_regCount'] = true; unset($rrd_filename, $registered, $failed); } @@ -287,7 +287,7 @@ if (strstr($version, 'AP')) { ); $tags = compact('rrd_def'); data_update($device, 'canopy-generic-freq', $tags, $fields); - $graphs['canopy_generic_freq'] = TRUE; + $graphs['canopy_generic_freq'] = true; unset($rrd_filename, $freq); } -} \ No newline at end of file +} diff --git a/includes/polling/wireless/cisco-wwan.inc.php b/includes/polling/wireless/cisco-wwan.inc.php index c11b9bb216..9df483abeb 100644 --- a/includes/polling/wireless/cisco-wwan.inc.php +++ b/includes/polling/wireless/cisco-wwan.inc.php @@ -17,7 +17,7 @@ if (is_numeric($rssi)) { ); $tags = compact('rrd_def'); data_update($device, 'cisco-wwan-rssi', $tags, $fields); - $graphs['cisco_wwan_rssi'] = TRUE; + $graphs['cisco_wwan_rssi'] = true; } $mnc = snmp_get($device, "CISCO-WAN-3G-MIB::c3gGsmMnc.13", "-Ovqn", "CISCO-WAN-3G-MIB"); @@ -28,6 +28,6 @@ if (is_numeric($mnc)) { ); $tags = compact('rrd_def'); data_update($device, 'cisco-wwan-rssi', $tags, $fields); - $graphs['cisco-wwan-mnc'] = TRUE; + $graphs['cisco-wwan-mnc'] = true; } unset($rrd_def, $rssi, $mnc, $fields, $tags); diff --git a/includes/polling/wireless/xirrus.inc.php b/includes/polling/wireless/xirrus.inc.php index 6777fb8e67..bdad45a289 100644 --- a/includes/polling/wireless/xirrus.inc.php +++ b/includes/polling/wireless/xirrus.inc.php @@ -5,7 +5,7 @@ $dataRate = snmpwalk_cache_oid($device, 'XIRRUS-MIB::realtimeMonitorAverageDataR $noiseFloor = snmpwalk_cache_oid($device, 'XIRRUS-MIB::realtimeMonitorNoiseFloor', array(), 'XIRRUS-MIB'); $associations=array(); -foreach($radios as $idx => $radio) { +foreach ($radios as $idx => $radio) { $radioName = $radio['realtimeMonitorIfaceName']; $associations[$radioName]=0; @@ -32,13 +32,14 @@ if ($config['xirrus_disable_stations']!=true) { // station associations // custom RRDs and graph as each AP may have 16 radios $assoc = snmpwalk_cache_oid($device, 'XIRRUS-MIB::stationAssociationIAP', array(), 'XIRRUS-MIB'); - foreach($assoc as $s) { + foreach ($assoc as $s) { $radio = array_pop($s); $associations[$radio]++; } - unset($radio); unset($assoc); + unset($radio); + unset($assoc); // write to rrds - foreach($associations as $radio => $count) { + foreach ($associations as $radio => $count) { $measurement = 'xirrus_users'; $rrd_name = array($measurement, $radio); $rrd_def = 'DS:stations:GAUGE:600:0:3200'; @@ -48,15 +49,15 @@ if ($config['xirrus_disable_stations']!=true) { $tags = compact('radio', 'rrd_name', 'rrd_def'); data_update($device, $measurement, $tags, $fields); } - $graphs['xirrus_stations'] = TRUE; + $graphs['xirrus_stations'] = true; } else { - $graphs['xirrus_stations'] = FALSE; + $graphs['xirrus_stations'] = false; } -$graphs['xirrus_rssi'] = TRUE; -$graphs['xirrus_dataRates'] = TRUE; -$graphs['xirrus_noiseFloor'] = TRUE; -$graphs['xirrus_stations'] = TRUE; +$graphs['xirrus_rssi'] = true; +$graphs['xirrus_dataRates'] = true; +$graphs['xirrus_noiseFloor'] = true; +$graphs['xirrus_stations'] = true; // cleanup -unset($rrd_def, $radios, $rssi, $radioName, $associations, $tags, $fields, $measurement); \ No newline at end of file +unset($rrd_def, $radios, $rssi, $radioName, $associations, $tags, $fields, $measurement); diff --git a/includes/rewrites.php b/includes/rewrites.php index b862a12de3..b58d01f25e 100644 --- a/includes/rewrites.php +++ b/includes/rewrites.php @@ -1,7 +1,8 @@ $replace) { $string = str_replace($search, $replace, $string); } @@ -1093,7 +1110,8 @@ function array_str_replace($array, $string) { } -function array_preg_replace($array, $string) { +function array_preg_replace($array, $string) +{ foreach ($array as $search => $replace) { $string = preg_replace($search, $replace, $string); } @@ -1102,7 +1120,8 @@ function array_preg_replace($array, $string) { } -function rewrite_adslLineType($adslLineType) { +function rewrite_adslLineType($adslLineType) +{ $adslLineTypes = array( 'noChannel' => 'No Channel', 'fastOnly' => 'Fastpath', @@ -1120,216 +1139,217 @@ function rewrite_adslLineType($adslLineType) { return ($adslLineType); } -function rewrite_brocade_fc_switches($descr) { - switch($descr) { - case "1": - $hardware = "Brocade 1000 Switch"; - break; - case "2": - $hardware = "Brocade 2800 Switch"; - break; - case "3": - $hardware = "Brocade 2100/2400 Switch"; - break; - case "4": - $hardware = "Brocade 20x0 Switch"; - break; - case "5": - $hardware = "Brocade 22x0 Switch"; - break; - case "6": - $hardware = "Brocade 2800 Switch"; - break; - case "7": - $hardware = "Brocade 2000 Switch"; - break; - case "9": - $hardware = "Brocade 3800 Switch"; - break; - case "10": - $hardware = "Brocade 12000 Director"; - break; - case "12": - $hardware = "Brocade 3900 Switch"; - break; - case "16": - $hardware = "Brocade 3200 Switch"; - break; - case "18": - $hardware = "Brocade 3000 Switch"; - break; - case "21": - $hardware = "Brocade 24000 Director"; - break; - case "22": - $hardware = "Brocade 3016 Switch"; - break; - case "26": - $hardware = "Brocade 3850 Switch"; - break; - case "27": - $hardware = "Brocade 3250 Switch"; - break; - case "29": - $hardware = "Brocade 4012 Embedded Switch"; - break; - case "32": - $hardware = "Brocade 4100 Switch"; - break; - case "33": - $hardware = "Brocade 3014 Switch"; - break; - case "34": - $hardware = "Brocade 200E Switch"; - break; - case "37": - $hardware = "Brocade 4020 Embedded Switch"; - break; - case "38": - $hardware = "Brocade 7420 SAN Router"; - break; - case "40": - $hardware = "Fibre Channel Routing (FCR) Front Domain"; - break; - case "41": - $hardware = "Fibre Channel Routing (FCR) Xlate Domain"; - break; - case "42": - $hardware = "Brocade 48000 Director"; - break; - case "43": - $hardware = "Brocade 4024 Embedded Switch"; - break; - case "44": - $hardware = "Brocade 4900 Switch"; - break; - case "45": - $hardware = "Brocade 4016 Embedded Switch"; - break; - case "46": - $hardware = "Brocade 7500 Switch"; - break; - case "51": - $hardware = "Brocade 4018 Embedded Switch"; - break; - case "55.2": - $hardware = "Brocade 7600 Switch"; - break; - case "58": - $hardware = "Brocade 5000 Switch"; - break; - case "61": - $hardware = "Brocade 4424 Embedded Switch"; - break; - case "62": - $hardware = "Brocade DCX Backbone"; - break; - case "64": - $hardware = "Brocade 5300 Switch"; - break; - case "66": - $hardware = "Brocade 5100 Switch"; - break; - case "67": - $hardware = "Brocade Encryption Switch"; - break; - case "69": - $hardware = "Brocade 5410 Blade"; - break; - case "70": - $hardware = "Brocade 5410 Embedded Switch"; - break; - case "71": - $hardware = "Brocade 300 Switch"; - break; - case "72": - $hardware = "Brocade 5480 Embedded Switch"; - break; - case "73": - $hardware = "Brocade 5470 Embedded Switch"; - break; - case "75": - $hardware = "Brocade M5424 Embedded Switch"; - break; - case "76": - $hardware = "Brocade 8000 Switch"; - break; - case "77": - $hardware = "Brocade DCX-4S Backbone"; - break; - case "83": - $hardware = "Brocade 7800 Extension Switch"; - break; - case "86": - $hardware = "Brocade 5450 Embedded Switch"; - break; - case "87": - $hardware = "Brocade 5460 Embedded Switch"; - break; - case "90": - $hardware = "Brocade 8470 Embedded Switch"; - break; - case "92": - $hardware = "Brocade VA-40FC Switch"; - break; - case "95": - $hardware = "Brocade VDX 6720-24 Data Center Switch"; - break; - case "96": - $hardware = "Brocade VDX 6730-32 Data Center Switch"; - break; - case "97": - $hardware = "Brocade VDX 6720-60 Data Center Switch"; - break; - case "98": - $hardware = "Brocade VDX 6720-76 Data Center Switch"; - break; - case "108": - $hardware = "Dell M84280k FCoE Embedded Switch"; - break; - case "109": - $hardware = "Brocade 6510 Switch"; - break; - case "116": - $hardware = "Brocade VDX 6710 Data Center Switch"; - break; - case "117": - $hardware = "Brocade 6547 Embedded Switch"; - break; - case "118": - $hardware = "Brocade 6505 Switch"; - break; - case "120": - $hardware = "Brocade DCX 8510-8 Backbone"; - break; - case "121": - $hardware = "Brocade DCX 8510-4 Backbone"; - break; - case "124": - $hardware = "Brocade 5430 Switch"; - break; - case "125": - $hardware = "Brocade 5431 Switch"; - break; - case "129": - $hardware = "Brocade 6548 Switch"; - break; - case "130": - $hardware = "Brocade M6505 Switch"; - break; - case "133": - $hardware = "Brocade 6520 Switch"; - break; - case "134": - $hardware = "Brocade 5432 Switch"; - break; - case "148": - $hardware = "Brocade 7840 Switch"; - break; - default: - $hardware = "Unknown Brocade FC Switch"; - } - return $hardware; +function rewrite_brocade_fc_switches($descr) +{ + switch ($descr) { + case "1": + $hardware = "Brocade 1000 Switch"; + break; + case "2": + $hardware = "Brocade 2800 Switch"; + break; + case "3": + $hardware = "Brocade 2100/2400 Switch"; + break; + case "4": + $hardware = "Brocade 20x0 Switch"; + break; + case "5": + $hardware = "Brocade 22x0 Switch"; + break; + case "6": + $hardware = "Brocade 2800 Switch"; + break; + case "7": + $hardware = "Brocade 2000 Switch"; + break; + case "9": + $hardware = "Brocade 3800 Switch"; + break; + case "10": + $hardware = "Brocade 12000 Director"; + break; + case "12": + $hardware = "Brocade 3900 Switch"; + break; + case "16": + $hardware = "Brocade 3200 Switch"; + break; + case "18": + $hardware = "Brocade 3000 Switch"; + break; + case "21": + $hardware = "Brocade 24000 Director"; + break; + case "22": + $hardware = "Brocade 3016 Switch"; + break; + case "26": + $hardware = "Brocade 3850 Switch"; + break; + case "27": + $hardware = "Brocade 3250 Switch"; + break; + case "29": + $hardware = "Brocade 4012 Embedded Switch"; + break; + case "32": + $hardware = "Brocade 4100 Switch"; + break; + case "33": + $hardware = "Brocade 3014 Switch"; + break; + case "34": + $hardware = "Brocade 200E Switch"; + break; + case "37": + $hardware = "Brocade 4020 Embedded Switch"; + break; + case "38": + $hardware = "Brocade 7420 SAN Router"; + break; + case "40": + $hardware = "Fibre Channel Routing (FCR) Front Domain"; + break; + case "41": + $hardware = "Fibre Channel Routing (FCR) Xlate Domain"; + break; + case "42": + $hardware = "Brocade 48000 Director"; + break; + case "43": + $hardware = "Brocade 4024 Embedded Switch"; + break; + case "44": + $hardware = "Brocade 4900 Switch"; + break; + case "45": + $hardware = "Brocade 4016 Embedded Switch"; + break; + case "46": + $hardware = "Brocade 7500 Switch"; + break; + case "51": + $hardware = "Brocade 4018 Embedded Switch"; + break; + case "55.2": + $hardware = "Brocade 7600 Switch"; + break; + case "58": + $hardware = "Brocade 5000 Switch"; + break; + case "61": + $hardware = "Brocade 4424 Embedded Switch"; + break; + case "62": + $hardware = "Brocade DCX Backbone"; + break; + case "64": + $hardware = "Brocade 5300 Switch"; + break; + case "66": + $hardware = "Brocade 5100 Switch"; + break; + case "67": + $hardware = "Brocade Encryption Switch"; + break; + case "69": + $hardware = "Brocade 5410 Blade"; + break; + case "70": + $hardware = "Brocade 5410 Embedded Switch"; + break; + case "71": + $hardware = "Brocade 300 Switch"; + break; + case "72": + $hardware = "Brocade 5480 Embedded Switch"; + break; + case "73": + $hardware = "Brocade 5470 Embedded Switch"; + break; + case "75": + $hardware = "Brocade M5424 Embedded Switch"; + break; + case "76": + $hardware = "Brocade 8000 Switch"; + break; + case "77": + $hardware = "Brocade DCX-4S Backbone"; + break; + case "83": + $hardware = "Brocade 7800 Extension Switch"; + break; + case "86": + $hardware = "Brocade 5450 Embedded Switch"; + break; + case "87": + $hardware = "Brocade 5460 Embedded Switch"; + break; + case "90": + $hardware = "Brocade 8470 Embedded Switch"; + break; + case "92": + $hardware = "Brocade VA-40FC Switch"; + break; + case "95": + $hardware = "Brocade VDX 6720-24 Data Center Switch"; + break; + case "96": + $hardware = "Brocade VDX 6730-32 Data Center Switch"; + break; + case "97": + $hardware = "Brocade VDX 6720-60 Data Center Switch"; + break; + case "98": + $hardware = "Brocade VDX 6720-76 Data Center Switch"; + break; + case "108": + $hardware = "Dell M84280k FCoE Embedded Switch"; + break; + case "109": + $hardware = "Brocade 6510 Switch"; + break; + case "116": + $hardware = "Brocade VDX 6710 Data Center Switch"; + break; + case "117": + $hardware = "Brocade 6547 Embedded Switch"; + break; + case "118": + $hardware = "Brocade 6505 Switch"; + break; + case "120": + $hardware = "Brocade DCX 8510-8 Backbone"; + break; + case "121": + $hardware = "Brocade DCX 8510-4 Backbone"; + break; + case "124": + $hardware = "Brocade 5430 Switch"; + break; + case "125": + $hardware = "Brocade 5431 Switch"; + break; + case "129": + $hardware = "Brocade 6548 Switch"; + break; + case "130": + $hardware = "Brocade M6505 Switch"; + break; + case "133": + $hardware = "Brocade 6520 Switch"; + break; + case "134": + $hardware = "Brocade 5432 Switch"; + break; + case "148": + $hardware = "Brocade 7840 Switch"; + break; + default: + $hardware = "Unknown Brocade FC Switch"; + } + return $hardware; } $ipmiSensorsNames = array( diff --git a/includes/services.inc.php b/includes/services.inc.php index 5e07dad182..9f165e7e7f 100644 --- a/includes/services.inc.php +++ b/includes/services.inc.php @@ -1,6 +1,7 @@ 0) { - edit_service($update,$service['service_id']); + edit_service($update, $service['service_id']); } return true; } -function check_service($command) { +function check_service($command) +{ // This array is used to test for valid UOM's to be used for graphing. // Valid values from: https://nagios-plugins.org/doc/guidelines.html#AEN200 // Note: This array must be decend from 2 char to 1 char so that the search works correctly. @@ -230,7 +236,7 @@ function check_service($command) { // is the UOM valid - https://nagios-plugins.org/doc/guidelines.html#AEN200 foreach ($valid_uom as $v) { - if ((strlen($value)-strlen($v)) === strpos($value,$v)) { + if ((strlen($value)-strlen($v)) === strpos($value, $v)) { // Yes, store and strip it off the value $uom = $v; $value = substr($value, 0, -strlen($v)); @@ -242,8 +248,7 @@ function check_service($command) { // We have a DS. Add an entry to the array. d_echo("Perf Data - DS: ".$ds.", Value: ".$value.", UOM: ".$uom."\n"); $metrics[$ds] = array ('value'=>$value, 'uom'=>$uom); - } - else { + } else { // No DS. Don't add an entry to the array. d_echo("Perf Data - None.\n"); } diff --git a/includes/services/check_dns.inc.php b/includes/services/check_dns.inc.php index bfdbf4b9ef..9905f3c490 100644 --- a/includes/services/check_dns.inc.php +++ b/includes/services/check_dns.inc.php @@ -1,7 +1,15 @@ 0) { return $device[$setting]; - } - else if (isset($config['snmp'][$setting])) { + } elseif (isset($config['snmp'][$setting])) { return $config['snmp'][$setting]; } - }//end prep_snmp_setting() -function mibdir($mibdir) { +function mibdir($mibdir) +{ global $config; return ' -M '.($mibdir ? $mibdir : $config['mibdir']); - }//end mibdir() -function snmp_get_multi($device, $oids, $options='-OQUs', $mib=null, $mibdir=null) { +function snmp_get_multi($device, $oids, $options = '-OQUs', $mib = null, $mibdir = null) +{ global $debug,$config,$runtime_stats,$mibs_loaded; // populate timeout & retries values from configuration @@ -97,11 +97,11 @@ function snmp_get_multi($device, $oids, $options='-OQUs', $mib=null, $mibdir=nul } return $array; - }//end snmp_get_multi() -function snmp_get($device, $oid, $options=null, $mib=null, $mibdir=null) { +function snmp_get($device, $oid, $options = null, $mib = null, $mibdir = null) +{ global $debug,$config,$runtime_stats,$mibs_loaded; $timeout = prep_snmp_setting($device, 'timeout'); @@ -144,18 +144,16 @@ function snmp_get($device, $oid, $options=null, $mib=null, $mibdir=null) { if (is_string($data) && (preg_match('/(No Such Instance|No Such Object|No more variables left|Authentication failure)/i', $data))) { return false; - } - elseif ($data || $data === '0') { + } elseif ($data || $data === '0') { return $data; - } - else { + } else { return false; } - }//end snmp_get() -function snmp_walk($device, $oid, $options=null, $mib=null, $mibdir=null) { +function snmp_walk($device, $oid, $options = null, $mib = null, $mibdir = null) +{ global $debug,$config,$runtime_stats; $timeout = prep_snmp_setting($device, 'timeout'); @@ -167,8 +165,7 @@ function snmp_walk($device, $oid, $options=null, $mib=null, $mibdir=null) { if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) { $snmpcommand = $config['snmpwalk']; - } - else { + } else { $snmpcommand = $config['snmpbulkwalk']; $max_repeaters = $device['snmp_max_repeaters']; if ($max_repeaters > 0) { @@ -205,8 +202,7 @@ function snmp_walk($device, $oid, $options=null, $mib=null, $mibdir=null) { if (is_string($data) && (preg_match('/No Such (Object|Instance)/i', $data))) { $data = false; - } - else { + } else { if (preg_match('/No more variables left in this MIB View \(It is past the end of the MIB tree\)$/', $data)) { // Bit ugly :-( $d_ex = explode("\n", $data); @@ -218,11 +214,11 @@ function snmp_walk($device, $oid, $options=null, $mib=null, $mibdir=null) { $runtime_stats['snmpwalk']++; return $data; - }//end snmp_walk() -function snmpwalk_cache_cip($device, $oid, $array=array(), $mib=0) { +function snmpwalk_cache_cip($device, $oid, $array = array(), $mib = 0) +{ global $config, $debug; $timeout = prep_snmp_setting($device, 'timeout'); @@ -234,8 +230,7 @@ function snmpwalk_cache_cip($device, $oid, $array=array(), $mib=0) { if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) { $snmpcommand = $config['snmpwalk']; - } - else { + } else { $snmpcommand = $config['snmpbulkwalk']; $max_repeaters = $device['snmp_max_repeaters']; if ($max_repeaters > 0) { @@ -281,8 +276,7 @@ function snmpwalk_cache_cip($device, $oid, $array=array(), $mib=0) { if ($dir == '1') { $dir = 'input'; - } - else if ($dir == '2') { + } elseif ($dir == '2') { $dir = 'output'; } @@ -292,11 +286,11 @@ function snmpwalk_cache_cip($device, $oid, $array=array(), $mib=0) { }//end foreach return $array; - }//end snmpwalk_cache_cip() -function snmp_cache_ifIndex($device) { +function snmp_cache_ifIndex($device) +{ // FIXME: this is not yet using our own snmp_* global $config, $debug; @@ -309,8 +303,7 @@ function snmp_cache_ifIndex($device) { if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) { $snmpcommand = $config['snmpwalk']; - } - else { + } else { $snmpcommand = $config['snmpbulkwalk']; $max_repeaters = $device['snmp_max_repeaters']; if ($max_repeaters > 0) { @@ -347,11 +340,11 @@ function snmp_cache_ifIndex($device) { } return $array; - }//end snmp_cache_ifIndex() -function snmpwalk_cache_oid($device, $oid, $array, $mib=null, $mibdir=null, $snmpflags='-OQUs') { +function snmpwalk_cache_oid($device, $oid, $array, $mib = null, $mibdir = null, $snmpflags = '-OQUs') +{ $data = snmp_walk($device, $oid, $snmpflags, $mib, $mibdir); foreach (explode("\n", $data) as $entry) { list($oid,$value) = explode('=', $entry, 2); @@ -364,10 +357,10 @@ function snmpwalk_cache_oid($device, $oid, $array, $mib=null, $mibdir=null, $snm } return $array; - }//end snmpwalk_cache_oid() -function snmpwalk_cache_long_oid($device, $oid, $noid, $array, $mib=null, $mibdir=null, $snmpflags='-OQnU') { +function snmpwalk_cache_long_oid($device, $oid, $noid, $array, $mib = null, $mibdir = null, $snmpflags = '-OQnU') +{ $data = snmp_walk($device, $oid, $snmpflags, $mib, $mibdir); foreach (explode("\n", $data) as $entry) { list($tmp_oid,$value) = explode('=', $entry, 2); @@ -384,7 +377,6 @@ function snmpwalk_cache_long_oid($device, $oid, $noid, $array, $mib=null, $mibdi } return $array; - }//end snmpwalk_cache_oid() @@ -392,13 +384,14 @@ function snmpwalk_cache_long_oid($device, $oid, $noid, $array, $mib=null, $mibdi // this is useful when the oid is indexed by the mac address and snmpwalk would // return periods (.) for non-printable numbers, thus making many different indexes appear // to be the same. -function snmpwalk_cache_oid_num($device, $oid, $array, $mib=null, $mibdir=null) { +function snmpwalk_cache_oid_num($device, $oid, $array, $mib = null, $mibdir = null) +{ return snmpwalk_cache_oid($device, $oid, $array, $mib, $mibdir, $snmpflags = '-OQUn'); - }//end snmpwalk_cache_oid_num() -function snmpwalk_cache_multi_oid($device, $oid, $array, $mib=null, $mibdir=null, $snmpflags='-OQUs') { +function snmpwalk_cache_multi_oid($device, $oid, $array, $mib = null, $mibdir = null, $snmpflags = '-OQUs') +{ global $cache; if (!(is_array($cache['snmp'][$device['device_id']]) && array_key_exists($oid, $cache['snmp'][$device['device_id']]))) { @@ -423,11 +416,11 @@ function snmpwalk_cache_multi_oid($device, $oid, $array, $mib=null, $mibdir=null }//end if return $cache['snmp'][$device['device_id']][$oid]; - }//end snmpwalk_cache_multi_oid() -function snmpwalk_cache_double_oid($device, $oid, $array, $mib=null, $mibdir=null) { +function snmpwalk_cache_double_oid($device, $oid, $array, $mib = null, $mibdir = null) +{ $data = snmp_walk($device, $oid, '-OQUs', $mib, $mibdir); foreach (explode("\n", $data) as $entry) { @@ -442,11 +435,11 @@ function snmpwalk_cache_double_oid($device, $oid, $array, $mib=null, $mibdir=nul } return $array; - }//end snmpwalk_cache_double_oid() -function snmpwalk_cache_triple_oid($device, $oid, $array, $mib=null, $mibdir=null) { +function snmpwalk_cache_triple_oid($device, $oid, $array, $mib = null, $mibdir = null) +{ $data = snmp_walk($device, $oid, '-OQUs', $mib, $mibdir); foreach (explode("\n", $data) as $entry) { @@ -461,11 +454,11 @@ function snmpwalk_cache_triple_oid($device, $oid, $array, $mib=null, $mibdir=nul } return $array; - }//end snmpwalk_cache_triple_oid() -function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib=0) { +function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib = 0) +{ global $config, $debug; $timeout = prep_snmp_setting($device, 'timeout'); @@ -477,8 +470,7 @@ function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib=0) { if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) { $snmpcommand = $config['snmpwalk']; - } - else { + } else { $snmpcommand = $config['snmpbulkwalk']; $max_repeaters = $device['snmp_max_repeaters']; if ($max_repeaters > 0) { @@ -519,11 +511,11 @@ function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib=0) { } return $array; - }//end snmpwalk_cache_twopart_oid() -function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib=0) { +function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0) +{ global $config, $debug; $timeout = prep_snmp_setting($device, 'timeout'); @@ -535,8 +527,7 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib=0) { if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) { $snmpcommand = $config['snmpwalk']; - } - else { + } else { $snmpcommand = $config['snmpbulkwalk']; $max_repeaters = $device['snmp_max_repeaters']; if ($max_repeaters > 0) { @@ -581,11 +572,11 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib=0) { } return $array; - }//end snmpwalk_cache_threepart_oid() -function snmp_cache_slotport_oid($oid, $device, $array, $mib=0) { +function snmp_cache_slotport_oid($oid, $device, $array, $mib = 0) +{ global $config, $debug; $timeout = prep_snmp_setting($device, 'timeout'); @@ -597,8 +588,7 @@ function snmp_cache_slotport_oid($oid, $device, $array, $mib=0) { if ($device['snmpver'] == 'v1' || $config['os'][$device['os']]['nobulk']) { $snmpcommand = $config['snmpwalk']; - } - else { + } else { $snmpcommand = $config['snmpbulkwalk']; $max_repeaters = $device['snmp_max_repeaters']; if ($max_repeaters > 0) { @@ -639,18 +629,18 @@ function snmp_cache_slotport_oid($oid, $device, $array, $mib=0) { } return $array; - }//end snmp_cache_slotport_oid() -function snmp_cache_oid($oid, $device, $array, $mib=0) { +function snmp_cache_oid($oid, $device, $array, $mib = 0) +{ $array = snmpwalk_cache_oid($device, $oid, $array, $mib); return $array; - }//end snmp_cache_oid() -function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0) { +function snmp_cache_port_oids($oids, $port, $device, $array, $mib = 0) +{ global $config, $debug; $timeout = prep_snmp_setting($device, 'timeout'); @@ -697,11 +687,11 @@ function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0) { } return $array; - }//end snmp_cache_port_oids() -function snmp_cache_portIfIndex($device, $array) { +function snmp_cache_portIfIndex($device, $array) +{ global $config; $timeout = prep_snmp_setting($device, 'timeout'); @@ -733,11 +723,11 @@ function snmp_cache_portIfIndex($device, $array) { } return $array; - }//end snmp_cache_portIfIndex() -function snmp_cache_portName($device, $array) { +function snmp_cache_portName($device, $array) +{ global $config; $timeout = prep_snmp_setting($device, 'timeout'); @@ -772,52 +762,46 @@ function snmp_cache_portName($device, $array) { } return $array; - }//end snmp_cache_portName() -function snmp_gen_auth(&$device) { +function snmp_gen_auth(&$device) +{ global $debug, $vdebug; $cmd = ''; if ($device['snmpver'] === 'v3') { - $cmd = " -v3 -n '' -l '".$device['authlevel']."'"; - - //add context if exist context - if(key_exists('context_name', $device)){ - $cmd = " -v3 -n '".$device['context_name']."' -l '".$device['authlevel']."'"; - } - + + //add context if exist context + if (key_exists('context_name', $device)) { + $cmd = " -v3 -n '".$device['context_name']."' -l '".$device['authlevel']."'"; + } + if ($device['authlevel'] === 'noAuthNoPriv') { // We have to provide a username anyway (see Net-SNMP doc) // FIXME: There are two other places this is set - why are they ignored here? $cmd .= ' -u root'; - } - else if ($device['authlevel'] === 'authNoPriv') { + } elseif ($device['authlevel'] === 'authNoPriv') { $cmd .= " -a '".$device['authalgo']."'"; $cmd .= " -A '".$device['authpass']."'"; $cmd .= " -u '".$device['authname']."'"; - } - else if ($device['authlevel'] === 'authPriv') { + } elseif ($device['authlevel'] === 'authPriv') { $cmd .= " -a '".$device['authalgo']."'"; $cmd .= " -A '".$device['authpass']."'"; $cmd .= " -u '".$device['authname']."'"; $cmd .= " -x '".$device['cryptoalgo']."'"; $cmd .= " -X '".$device['cryptopass']."'"; - } - else { + } else { if ($debug) { print 'DEBUG: '.$device['snmpver']." : Unsupported SNMPv3 AuthLevel (wtf have you done ?)\n"; } } - } - else if ($device['snmpver'] === 'v2c' or $device['snmpver'] === 'v1') { + } elseif ($device['snmpver'] === 'v2c' or $device['snmpver'] === 'v1') { $cmd = " -".$device['snmpver']; $cmd .= " -c '".$device['community']."'"; - } - else { + } else { if ($debug) { print 'DEBUG: '.$device['snmpver']." : Unsupported SNMP Version (shouldn't be possible to get here)\n"; } @@ -828,7 +812,6 @@ function snmp_gen_auth(&$device) { } return $cmd; - }//end snmp_gen_auth() @@ -847,7 +830,8 @@ function snmp_gen_auth(&$device) { * ::= { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) ruckusRootMIB(25053) ruckusObjects(1) ruckusZD(2) ruckusZDSystemModule(1) ruckusZDSystemMIB(1) ruckusZDSystemObjects(1) * ruckusZDSystemStats(15) 30 } */ -function snmp_mib_parse($oid, $mib, $module, $mibdir=null) { +function snmp_mib_parse($oid, $mib, $module, $mibdir = null) +{ $fulloid = explode('.', $oid); $lastpart = end($fulloid); @@ -909,8 +893,7 @@ function snmp_mib_parse($oid, $mib, $module, $mibdir=null) { if (isset($result['syntax']) && isset($result['object_type'])) { $result['mib'] = $mib; return $result; - } - else { + } else { return null; } } // snmp_mib_parse @@ -930,7 +913,7 @@ function snmp_mib_parse($oid, $mib, $module, $mibdir=null) { */ -function snmp_mib_walk($mib, $module, $mibdir=null) +function snmp_mib_walk($mib, $module, $mibdir = null) { $cmd = 'snmptranslate -Ts'; $cmd .= mibdir($mibdir); @@ -948,7 +931,6 @@ function snmp_mib_walk($mib, $module, $mibdir=null) } return $result; - } // snmp_mib_walk @@ -1014,7 +996,6 @@ function snmp_mib_load($mib, $module, $included_by, $mibdir = null) $columns = array('module', 'mib', 'object_type', 'oid', 'syntax', 'description', 'max_access', 'status', 'included_by'); update_db_table('mibdefs', $columns, 3, $mibs); return count($mibs); - } // snmp_mib_load @@ -1053,7 +1034,6 @@ function snmp_translate($oid, $module, $mibdir = null) $matches[1], $matches[2], ); - } // snmp_translate @@ -1068,26 +1048,25 @@ function oid_rrd_type($oid, $mibdef) } switch ($mibdef[$oid]['syntax']) { - case 'OCTET': - case 'IpAddress': - return false; + case 'OCTET': + case 'IpAddress': + return false; - case 'TimeTicks': - // FIXME - return false; + case 'TimeTicks': + // FIXME + return false; - case 'INTEGER': - case 'Integer32': - return 'GAUGE:600:U:U'; + case 'INTEGER': + case 'Integer32': + return 'GAUGE:600:U:U'; - case 'Counter32': - case 'Counter64': - return 'COUNTER:600:0:U'; - - case 'Gauge32': - case 'Unsigned32': - return 'GAUGE:600:0:U'; + case 'Counter32': + case 'Counter64': + return 'COUNTER:600:0:U'; + case 'Gauge32': + case 'Unsigned32': + return 'GAUGE:600:0:U'; } return false; @@ -1108,7 +1087,6 @@ function tag_graphs($mibname, $oids, $mibdef, &$graphs) $graphs[$graphname] = true; } } - } // tag_graphs @@ -1219,8 +1197,7 @@ function load_mibdefs($module, $name) foreach ($result as $mib => $m) { if (strlen($prefix) > 2) { $result[$mib]['shortname'] = preg_replace("/^$prefix/", '', $m['object_type'], 1); - } - else { + } else { $result[$mib]['shortname'] = $m['object_type']; } } @@ -1295,18 +1272,15 @@ function register_mibs($device, $mibs, $included_by) 'included_by' => $included_by, ); update_db_table('device_mibs', $columns, 3, $rows); - } - else { + } else { d_echo("MIB: Could not load definition for $mod::$nam\n"); } - } - else { + } else { d_echo("MIB: Could not find $module::$name\n"); } } echo "\n"; - } // register_mibs /** @@ -1331,11 +1305,12 @@ function register_mibs($device, $mibs, $included_by) * @internal param $string * @return array */ -function snmpwalk_array_num($device,$oid,$indexes=1) { +function snmpwalk_array_num($device, $oid, $indexes = 1) +{ $array = array(); $string = snmp_walk($device, $oid, '-Osqn'); - if ( $string === false) { + if ($string === false) { // False means: No Such Object. return false; } @@ -1348,7 +1323,7 @@ function snmpwalk_array_num($device,$oid,$indexes=1) { foreach (explode("\n", $string) as $line) { if ($line[0] == '.') { // strip the leading . if it exists. - $line = substr($line,1); + $line = substr($line, 1); } list($key, $value) = explode(' ', $line, 2); $prop_id = explode('.', $key); @@ -1359,17 +1334,17 @@ function snmpwalk_array_num($device,$oid,$indexes=1) { $indexes = count($prop_id)-1; } - for ($i=0;$i<$indexes;$i++) { + for ($i=0; $i<$indexes; $i++) { // Pop the index off. $index = array_pop($prop_id); $value = array($index => $value); } // Rebuild our key - $key = implode('.',$prop_id); + $key = implode('.', $prop_id); // Add the entry to the master array - $array = array_replace_recursive($array,array($key => $value)); + $array = array_replace_recursive($array, array($key => $value)); } return $array; } diff --git a/includes/snmptrap/linkUp.inc.php b/includes/snmptrap/linkUp.inc.php index fadee6a27a..d0279e895b 100644 --- a/includes/snmptrap/linkUp.inc.php +++ b/includes/snmptrap/linkUp.inc.php @@ -1,6 +1,6 @@ 'up'), 'ports', 'port_id=?',array($interface['port_id'])); + log_event("Interface Enabled : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id']); + dbUpdate(array('ifAdminStatus' => 'up'), 'ports', 'port_id=?', array($interface['port_id'])); } if ($ifOperStatus != $interface['ifOperStatus']) { - log_event("Interface went Up : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id']); - dbUpdate(array('ifOperStatus' => 'up'), 'ports', 'port_id=?',array($interface['port_id'])); + log_event("Interface went Up : " . $interface['ifDescr'] . " (TRAP)", $device, "interface", $interface['port_id']); + dbUpdate(array('ifOperStatus' => 'up'), 'ports', 'port_id=?', array($interface['port_id'])); } diff --git a/includes/sql-schema/update.php b/includes/sql-schema/update.php index 3f3cab6619..9be89e00ad 100644 --- a/includes/sql-schema/update.php +++ b/includes/sql-schema/update.php @@ -25,8 +25,7 @@ if (!isset($debug)) { $options = getopt('d'); if (isset($options['d'])) { $debug = true; - } - else { + } else { $debug = false; } } @@ -34,8 +33,7 @@ if (!isset($debug)) { $insert = 0; if ($db_rev = @dbFetchCell('SELECT version FROM `dbSchema` ORDER BY version DESC LIMIT 1')) { -} -else { +} else { $db_rev = 0; $insert = 1; } @@ -95,10 +93,9 @@ $limit = 150; //magic marker far enough in the future foreach ($filelist as $file) { list($filename,$extension) = explode('.', $file, 2); if ($filename > $db_rev) { - - if (isset($_SESSION['stage']) ) { + if (isset($_SESSION['stage'])) { $limit++; - if ( time()-$_SESSION['last'] > 45 ) { + if (time()-$_SESSION['last'] > 45) { $_SESSION['offset'] = $limit; $GLOBALS['refresh'] = 'Updating, please wait..'.date('r').''; return; @@ -126,8 +123,7 @@ foreach ($filelist as $file) { if ($line[0] != '#') { if ($config['db']['extension'] == 'mysqli') { $update = mysqli_query($database_link, $line); - } - else { + } else { $update = mysql_query($line); } if (!$update) { @@ -135,8 +131,7 @@ foreach ($filelist as $file) { if ($debug) { if ($config['db']['extension'] == 'mysqli') { echo mysqli_error($database_link)."\n"; - } - else { + } else { echo mysql_error()."\n"; } } @@ -147,12 +142,10 @@ foreach ($filelist as $file) { if ($db_rev < 5) { echo " done.\n"; - } - else { + } else { echo " done ($err errors).\n"; } - } - else { + } else { echo " Could not open file!\n"; }//end if @@ -160,8 +153,7 @@ foreach ($filelist as $file) { $db_rev = $filename; if ($insert) { dbInsert(array('version' => $db_rev), 'dbSchema'); - } - else { + } else { dbUpdate(array('version' => $db_rev), 'dbSchema'); } }//end if @@ -169,8 +161,7 @@ foreach ($filelist as $file) { if ($updating) { echo "-- Done\n"; - if( isset($_SESSION['stage']) ) { + if (isset($_SESSION['stage'])) { $_SESSION['build-ok'] = true; } } - diff --git a/includes/syslog.php b/includes/syslog.php index 26b7ba7901..55414efc1b 100644 --- a/includes/syslog.php +++ b/includes/syslog.php @@ -5,45 +5,45 @@ // $device_id_ip = @dbFetchCell("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = '" . $entry['host']."' AND I.port_id = A.port_id"); -function get_cache($host, $value) { +function get_cache($host, $value) +{ global $dev_cache; if (!isset($dev_cache[$host][$value])) { switch ($value) { - case 'device_id': - // Try by hostname - $ip = inet_pton($host); - if (inet_ntop($ip) === 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)); - } - break; + case 'device_id': + // Try by hostname + $ip = inet_pton($host); + if (inet_ntop($ip) === 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)); + } + break; - case 'os': - $dev_cache[$host]['os'] = dbFetchCell('SELECT `os` FROM devices WHERE `device_id` = ?', array(get_cache($host, 'device_id'))); - break; + case 'os': + $dev_cache[$host]['os'] = dbFetchCell('SELECT `os` FROM devices WHERE `device_id` = ?', array(get_cache($host, 'device_id'))); + break; - case 'version': - $dev_cache[$host]['version'] = dbFetchCell('SELECT `version` FROM devices WHERE `device_id`= ?', array(get_cache($host, 'device_id'))); - break; + case 'version': + $dev_cache[$host]['version'] = dbFetchCell('SELECT `version` FROM devices WHERE `device_id`= ?', array(get_cache($host, 'device_id'))); + break; - default: - return null; + default: + return null; }//end switch }//end if return $dev_cache[$host][$value]; - }//end get_cache() -function process_syslog($entry, $update) { +function process_syslog($entry, $update) +{ global $config, $dev_cache; foreach ($config['syslog_filter'] as $bi) { @@ -59,26 +59,24 @@ function process_syslog($entry, $update) { if (in_array($os, array('ios', 'iosxe', 'catos'))) { // multipart message - if(strpos($entry['msg'], ':') !== false) { + if (strpos($entry['msg'], ':') !== false) { $matches = array(); $timestamp_prefix = '([\*\.]?[A-Z][a-z]{2} \d\d? \d\d:\d\d:\d\d(.\d\d\d)?( [A-Z]{3})?: )?'; $program_match = '(?%?[A-Za-z\d\-_]+(:[A-Z]* %[A-Z\d\-_]+)?)'; $message_match = '(?.*)'; - if(preg_match('/^' . $timestamp_prefix . $program_match . ': ?' . $message_match . '/', $entry['msg'], $matches)) { + if (preg_match('/^' . $timestamp_prefix . $program_match . ': ?' . $message_match . '/', $entry['msg'], $matches)) { $entry['program'] = $matches['program']; $entry['msg'] = $matches['msg']; } unset($matches); - } - else { + } else { // if this looks like a program (no groups of 2 or more lowercase letters), move it to program if (!preg_match('/[(a-z)]{2,}/', $entry['msg'])) { $entry['program'] = $entry['msg']; unset($entry['msg']); - } + } } - } - else if ($os == 'linux' and get_cache($entry['host'], 'version') == 'Point') { + } elseif ($os == 'linux' and get_cache($entry['host'], 'version') == 'Point') { // Cisco WAP200 and similar $matches = array(); if (preg_match('#Log: \[(?P.*)\] - (?P.*)#', $entry['msg'], $matches)) { @@ -87,8 +85,7 @@ function process_syslog($entry, $update) { } unset($matches); - } - else if ($os == 'linux') { + } elseif ($os == 'linux') { $matches = array(); // pam_krb5(sshd:auth): authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231 // pam_krb5[sshd:auth]: authentication failure; logname=root uid=0 euid=0 tty=ssh ruser= rhost=123.213.132.231 @@ -104,20 +101,18 @@ function process_syslog($entry, $update) { // $entry['msg'] = substr($entry['msg'], $pos+1); // } // fallback, better than nothing... - else if (empty($entry['program']) and !empty($entry['facility'])) { + elseif (empty($entry['program']) and !empty($entry['facility'])) { $entry['program'] = $entry['facility']; } unset($matches); - } - else if ($os == 'procurve') { + } elseif ($os == 'procurve') { $matches = array(); if (preg_match('/^(?P[A-Za-z]+): {2}(?P.*)/', $entry['msg'], $matches)) { $entry['msg'] = $matches['msg']. " [". $entry['program']. "]"; $entry['program'] = $matches['program']; } unset($matches); - }//end if if (!isset($entry['program'])) { @@ -148,5 +143,4 @@ function process_syslog($entry, $update) { }//end if return $entry; - }//end process_syslog() diff --git a/scripts/pre-commit.php b/scripts/pre-commit.php index bfdaf4ec14..592f6c5933 100755 --- a/scripts/pre-commit.php +++ b/scripts/pre-commit.php @@ -117,7 +117,7 @@ function check_style($passthru = false) $cs_exclude = '--ignore=html/lib/* --ignore=html/plugins/'; - $cs_cmd = "./vendor/bin/phpcs -n -p --colors --extensions=php --standard=PSR2 $cs_exclude html"; + $cs_cmd = "./vendor/bin/phpcs -n -p --colors --extensions=php --standard=PSR2 $cs_exclude html includes"; $cs_output = ''; if ($passthru) { From a8fce2808ff1f6cdc43d1d34006dbce00ae6b35d Mon Sep 17 00:00:00 2001 From: cromagdk Date: Sun, 28 Aug 2016 19:42:41 +0200 Subject: [PATCH 36/69] Update snmpd setup in Installation-Ubuntu-1604 docs (#4243) docs: Update snmpd setup in Installation-Ubuntu-1604 docs #4243 --- doc/Installation/Installation-Ubuntu-1604-Apache.md | 4 ++-- doc/Installation/Installation-Ubuntu-1604-Nginx.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/Installation/Installation-Ubuntu-1604-Apache.md b/doc/Installation/Installation-Ubuntu-1604-Apache.md index 56bc1df13a..79860acde8 100644 --- a/doc/Installation/Installation-Ubuntu-1604-Apache.md +++ b/doc/Installation/Installation-Ubuntu-1604-Apache.md @@ -105,8 +105,8 @@ Now head to: http://librenms.example.com/install.php and follow the on-screen in #### Configure snmpd ```bash -cp /opt/librenms/snmpd.conf.example /etc/snmpd.conf -vim /etc/snmpd.conf +cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf +vim /etc/snmp/snmpd.conf ``` Edit the text which says `RANDOMSTRINGGOESHERE` and set your own community string. diff --git a/doc/Installation/Installation-Ubuntu-1604-Nginx.md b/doc/Installation/Installation-Ubuntu-1604-Nginx.md index 1aa8975dcf..ea17551fb2 100644 --- a/doc/Installation/Installation-Ubuntu-1604-Nginx.md +++ b/doc/Installation/Installation-Ubuntu-1604-Nginx.md @@ -108,8 +108,8 @@ Now head to: http://librenms.example.com/install.php and follow the on-screen in #### Configure snmpd ```bash -cp /opt/librenms/snmpd.conf.example /etc/snmpd.conf -vim /etc/snmpd.conf +cp /opt/librenms/snmpd.conf.example /etc/snmpd/snmpd.conf +vim /etc/snmpd/snmpd.conf ``` Edit the text which says `RANDOMSTRINGGOESHERE` and set your own community string. From 316bfb52ab6e83ebfb75e7d1c1ea2a7bcda82511 Mon Sep 17 00:00:00 2001 From: ospfbgp Date: Sun, 28 Aug 2016 16:13:49 -0400 Subject: [PATCH 37/69] Update AUTHORS.md (#4236) * Update AUTHORS.md * Update AUTHORS.md I agree to the conditions of the Contributor Agreement contained in doc/General/Contributing.md. * Update AUTHORS.md I agree to the conditions of the Contributor Agreement contained in doc/General/Contributing.md. --- AUTHORS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index b6ff814f31..852f62e722 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -121,7 +121,8 @@ LibreNMS contributors: - Phil Regnauld (reegnauld) - Russell Morris (arrmo) - Bennett Blodinger (benwa) -- Michael Hansen (nerdalertdk) +- Michael Hansen (nerdalertdk) +- Daniel Cox (ospfbgp) [1]: http://observium.org/ "Observium web site" Observium was written by: From b7d0b97c64caccb76bc2ebb39f9ed8161e4e6559 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Sun, 28 Aug 2016 15:44:36 -0500 Subject: [PATCH 38/69] More pre-commit.php improvements (#4224) * more pre-commit.php improvements do not check influx-db on hhvm Use parallel-lint to increase lint check speed and improve output Add option to print out the commands that would be executed, makes it easier to modify them and run by hand Fixed a couple of bugs * Integrate the environment check Flip it so we don't interfere with command line users --- .travis.yml | 14 ++- composer.json | 5 +- scripts/pre-commit.php | 255 ++++++++++++++++++++++++----------------- 3 files changed, 164 insertions(+), 110 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0ab420a850..86c04a8549 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,13 +4,21 @@ matrix: include: - php: 7.0 - php: 5.3 + env: + SKIP_STYLE_CHECK=1 - php: 5.4 + env: + SKIP_STYLE_CHECK=1 - php: 5.5 + env: + SKIP_STYLE_CHECK=1 - php: 5.6 env: - PHP_CS=1 + SKIP_STYLE_CHECK=1 EXECUTE_BUILD_DOCS=true - php: hhvm + env: + SKIP_STYLE_CHECK=1 allow_failures: - php: hhvm @@ -27,6 +35,6 @@ after_success: - test $TRAVIS_PULL_REQUEST == "false" && test $TRAVIS_BRANCH == "master" && test $EXECUTE_BUILD_DOCS == "true" && bash scripts/deploy-docs.sh script: - - php scripts/pre-commit.php -l - - if [[ $PHP_CS == 1 ]]; then php scripts/pre-commit.php -p -s; fi + - php scripts/pre-commit.php -p -l + - php scripts/pre-commit.php -p -s - phpunit diff --git a/composer.json b/composer.json index 6ca49b6e1a..88137f6892 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,8 @@ { "require-dev": { "squizlabs/php_codesniffer": "*", - "phpunit/phpunit": "4.*" + "phpunit/phpunit": "4.*", + "jakub-onderka/php-parallel-lint": "*", + "jakub-onderka/php-console-highlighter": "*" } } - diff --git a/scripts/pre-commit.php b/scripts/pre-commit.php index 592f6c5933..37ce5ab42b 100755 --- a/scripts/pre-commit.php +++ b/scripts/pre-commit.php @@ -2,52 +2,56 @@ false, + 'c' => false, + 'passthru' => false, + 'commands' => false, +); $passthru = check_opt($options, 'p', 'passthru'); -$commands = array_diff($options, $parameters); +$command_only = check_opt($options, 'c', 'commands'); +$commands = array_diff_assoc($options, $parameters); $all = empty($commands); $ret = 0; - // run tests -if ($all || check_opt($commands, 'l', 'lint')) { - $ret += check_lint(); +if (($all || check_opt($commands, 'l', 'lint')) && !getenv('SKIP_LINT_CHECK')) { + $ret += check_lint($passthru, $command_only); } -if ($all || check_opt($commands, 's', 'style')) { - $ret += check_style($passthru); +if (($all || check_opt($commands, 's', 'style')) && !getenv('SKIP_STYLE_CHECK')) { + $ret += check_style($passthru, $command_only); } -if ($all || check_opt($commands, 'u', 'unit')) { - $ret += check_unit($passthru); +if (($all || check_opt($commands, 'u', 'unit')) && !getenv('SKIP_UNIT_CHECK')) { + $ret += check_unit($passthru, $command_only); } @@ -58,6 +62,124 @@ if ($all && $ret === 0) { exit($ret); //return the combined/single return value of tests +/** + * Runs php -l and tests for any syntax errors + * + * @param bool $passthru display the output as comes in + * @param bool $command_only only display the intended command, no checks + * @return int the return value from running php -l (0 = success) + */ +function check_lint($passthru = false, $command_only = false) +{ + // matches a substring of the relative path, leading / is treated as absolute path + $lint_excludes = array('vendor/'); + if (defined('HHVM_VERSION') || version_compare(PHP_VERSION, '5.6', '<')) { + $lint_excludes[] = 'lib/influxdb-php/'; + } + + $lint_exclude = build_excludes('--exclude ', $lint_excludes); + $lint_cmd = "./vendor/bin/parallel-lint $lint_exclude ./"; + + if ($command_only) { + echo $lint_cmd . PHP_EOL; + return 250; + } + + echo 'Running lint check... '; + + if ($passthru) { + echo PHP_EOL; + passthru($lint_cmd, $lint_ret); + } else { + exec($lint_cmd, $lint_output, $lint_ret); + + if ($lint_ret > 0) { + print(implode(PHP_EOL, $lint_output) . PHP_EOL); + } else { + echo "success\n"; + } + } + + return $lint_ret; +} + +/** + * Runs phpcs --standard=PSR2 against the code base + * + * @param bool $passthru display the output as comes in + * @param bool $command_only only display the intended command, no checks + * @return int the return value from phpcs (0 = success) + */ +function check_style($passthru = false, $command_only = false) +{ + // matches a substring of the full path + $cs_excludes = array( + '/vendor/', + '/lib/', + '/html/plugins/', + ); + + $cs_exclude = build_excludes('--ignore=', $cs_excludes); + $cs_cmd = "./vendor/bin/phpcs -n -p --colors --extensions=php --standard=PSR2 $cs_exclude ./html ./includes"; + + if ($command_only) { + echo $cs_cmd . PHP_EOL; + return 250; + } + + echo 'Running style check... '; + + if ($passthru) { + echo PHP_EOL; + passthru($cs_cmd, $cs_ret); + } else { + exec($cs_cmd, $cs_output, $cs_ret); + + if ($cs_ret > 0) { + echo "failed\n"; + print(implode(PHP_EOL, $cs_output) . PHP_EOL); + } else { + echo "success\n"; + } + } + + return $cs_ret; +} + +/** + * Runs phpunit + * + * @param bool $passthru display the output as comes in + * @param bool $command_only only display the intended command, no checks + * @return int the return value from phpunit (0 = success) + */ +function check_unit($passthru = false, $command_only = false) +{ + $phpunit_cmd = './vendor/bin/phpunit --colors=always'; + + if ($command_only) { + echo $phpunit_cmd . PHP_EOL; + return 250; + } + + echo 'Running unit tests... '; + if ($passthru) { + echo PHP_EOL; + passthru($phpunit_cmd, $phpunit_ret); + } else { + exec($phpunit_cmd, $phpunit_output, $phpunit_ret); + + if ($phpunit_ret > 0) { + echo "failed\n"; + print(implode(PHP_EOL, $phpunit_output) . PHP_EOL); + } else { + echo "success\n"; + } + } + + return $phpunit_ret; +} + /** * Check if the given options array contains any of the $opts specified * @@ -74,96 +196,19 @@ function check_opt($options) return !empty($intersect); } - /** - * Runs php -l and tests for any syntax errors + * Build a list of exclude arguments from an array * - * @return int the return value from running php -l (0 = success) + * @param string $exclude_string such as "--exclude" + * @param array $excludes array of directories to exclude + * @return string resulting string */ -function check_lint() +function build_excludes($exclude_string, $excludes) { - echo "Running lint check... \n"; - - if (version_compare(PHP_VERSION, '5.6') >= 0) { - $lint_exclude = 'vendor'; - } else { - $lint_exclude = 'vendor|lib/influxdb-php'; - } - $lint_cmd = 'find . -regextype posix-extended -regex "\./('; - $lint_cmd .= $lint_exclude; - $lint_cmd .= ')" -prune -o -name "*.php" -print0 | xargs -0 -n1 -P8 php -l '; - $lint_cmd .= '| grep -v "^No syntax errors detected"; test $? -eq 1'; - - exec($lint_cmd, $lint_output, $lint_ret); - - if ($lint_ret > 0) { - print(implode(PHP_EOL, $lint_output) . PHP_EOL); - } else { - echo "success\n"; + $result = ''; + foreach ($excludes as $exclude) { + $result .= $exclude_string . $exclude . ' '; } - return $lint_ret; -} - -/** - * Runs phpcs --standard=PSR2 against the code base - * - * @param bool $passthru display the output as comes in - * @return int the return value from phpcs (0 = success) - */ -function check_style($passthru = false) -{ - echo 'Checking PSR-2 style...'.($passthru ? "\n" : ' '); - - - $cs_exclude = '--ignore=html/lib/* --ignore=html/plugins/'; - $cs_cmd = "./vendor/bin/phpcs -n -p --colors --extensions=php --standard=PSR2 $cs_exclude html includes"; - - $cs_output = ''; - if ($passthru) { - passthru($cs_cmd, $cs_ret); - } else { - exec($cs_cmd, $cs_output, $cs_ret); - } - - if (!$passthru) { - if ($cs_ret > 0) { - echo "failed\n"; - print(implode(PHP_EOL, $cs_output) . PHP_EOL); - } else { - echo "success\n"; - } - } - - return $cs_ret; -} - -/** - * Runs phpunit - * - * @param bool $passthru display the output as comes in - * @return int the return value from phpunit (0 = success) - */ -function check_unit($passthru = false) -{ - echo 'Running unit tests...'.($passthru ? "\n" : ' '); - $phpunit_cmd = './vendor/bin/phpunit --colors=always'; - - $phpunit_output = ''; - if ($passthru) { - passthru($phpunit_cmd, $phpunit_ret); - } else { - exec($phpunit_cmd, $phpunit_output, $phpunit_ret); - } - - if (!$passthru) { - if ($phpunit_ret > 0) { - echo "failed\n"; - print(implode(PHP_EOL, $phpunit_output) . PHP_EOL); - } else { - echo "success\n"; - } - } - - return $phpunit_ret; + return $result; } From 49dbe3ea01b269d3e503815d0d8fafb6e92655c3 Mon Sep 17 00:00:00 2001 From: crcro Date: Sun, 28 Aug 2016 23:48:06 +0300 Subject: [PATCH 39/69] availability map updates (#4183) webui: More updates to availability map #4183 --- html/css/styles.css | 1 + html/includes/common/availability-map.inc.php | 116 +++++++++++------- html/pages/settings/webui.inc.php | 4 + sql-schema/131.sql | 1 + 4 files changed, 80 insertions(+), 42 deletions(-) create mode 100644 sql-schema/131.sql diff --git a/html/css/styles.css b/html/css/styles.css index a5fc4f9057..de0ae68592 100644 --- a/html/css/styles.css +++ b/html/css/styles.css @@ -1881,6 +1881,7 @@ label { padding:8px; border-radius:5px; text-align:center; + white-space: nowrap; } .device-availability.up, .service-availability.up { diff --git a/html/includes/common/availability-map.inc.php b/html/includes/common/availability-map.inc.php index 4fd15f5bf9..d2a5e6b50e 100644 --- a/html/includes/common/availability-map.inc.php +++ b/html/includes/common/availability-map.inc.php @@ -12,9 +12,25 @@ * the source code distribution for details. */ +$select_modes = array( + '0' => 'only devices', + '1' => 'only services', + '2' => 'devices and services', +); + if (defined('SHOW_SETTINGS')) { - $current_mode = isset($widget_settings['mode']) ? $widget_settings['mode'] : 0; - $current_width = isset($widget_settings['tile_width']) ? $widget_settings['tile_width'] : 10; + if (isset($widget_settings['mode'])) { + $mode = $widget_settings['mode']; + } else { + $mode = 0; + } + + if (isset($widget_settings['tile_width'])) { + $current_width = $widget_settings['tile_width']; + } else { + $current_width = 10; + } + $common_output[] = '
@@ -31,12 +47,15 @@ if (defined('SHOW_SETTINGS')) { if ($config['show_services'] == 0) { $common_output[] = ''; } else { - $common_output[] = ' - - - '; + foreach ($select_modes as $mode_select => $option) { + if ($mode_select == $mode) { + $selected = 'selected'; + } else { + $selected = ''; + } + $common_output[] = ''; + } } - $common_output[] ='
@@ -50,7 +69,12 @@ if (defined('SHOW_SETTINGS')) { $sql = dbFetchRow('SELECT `settings` FROM `users_widgets` WHERE `user_id` = ? AND `widget_id` = ?', array($_SESSION["user_id"], '1')); $widget_mode = json_decode($sql['settings']); - $mode = isset($_SESSION["mapView"]) ? $_SESSION["mapView"] : $widget_mode->{'mode'}; + + if (isset($_SESSION["mapView"])) { + $mode = $_SESSION["mapView"]; + } else { + $mode = $widget_mode->{'mode'}; + } $host_up_count = 0; $host_warn_count = 0; @@ -59,9 +83,17 @@ if (defined('SHOW_SETTINGS')) { $service_warn_count = 0; $service_down_count = 0; + if ($config['webui']['availability_map_sort_status'] == 1) { + $deviceOrderBy = 'status'; + $serviceOrderBy = '`S`.`service_status` DESC'; + } else { + $deviceOrderBy = 'hostname'; + $serviceOrderBy = '`D`.`hostname`'; + } + if ($mode == 0 || $mode == 2) { // Only show devices if mode is 0 or 2 (Only Devices or both) - $sql = 'SELECT `D`.`hostname`,`D`.`device_id`,`D`.`status`,`D`.`uptime`, `D`.`os`, `D`.`icon` FROM `devices` AS `D`'; + $sql = 'SELECT `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`status`, `D`.`uptime`, `D`.`os`, `D`.`icon` FROM `devices` AS `D`'; if (is_normal_user() === true) { $sql .= ' , `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = ? AND'; $param = array( @@ -70,7 +102,7 @@ if (defined('SHOW_SETTINGS')) { } else { $sql .= ' WHERE'; } - $sql .= " `D`.`ignore` = '0' AND `D`.`disabled` = '0' ORDER BY `hostname`"; + $sql .= " `D`.`ignore` = '0' AND `D`.`disabled` = '0' ORDER BY `".$deviceOrderBy."`"; $temp_output = array(); foreach (dbFetchRows($sql, $param) as $device) { @@ -101,7 +133,7 @@ if (defined('SHOW_SETTINGS')) {
'.$deviceState.' '.$deviceIcon.'
- '.$device["hostname"].' + '.shorthost(ip_to_sysname($device, $device['hostname'])).'
'; } else { @@ -117,7 +149,7 @@ if (defined('SHOW_SETTINGS')) { } if (($mode == 1 || $mode == 2) && ($config['show_services'] != 0)) { - $service_query = 'select `S`.`service_type`, `S`.`service_id`, `S`.`service_desc`, `S`.`service_status`, `D`.`hostname`, `D`.`device_id`, `D`.`os`, `D`.`icon` from services S, devices D where `S`.`device_id` = `D`.`device_id`;'; + $service_query = 'select `S`.`service_type`, `S`.`service_id`, `S`.`service_desc`, `S`.`service_status`, `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`os`, `D`.`icon` from services S, devices D where `S`.`device_id` = `D`.`device_id` ORDER BY '.$serviceOrderBy.';'; $services = dbFetchRows($service_query); if (count($services) > 0) { foreach ($services as $service) { @@ -142,22 +174,22 @@ if (defined('SHOW_SETTINGS')) { if ($directpage == "yes") { $deviceIcon = getImage($service); $temp_output[] = ' - -
- ' . $service["service_type"] . ' - ' . $serviceState . ' - ' . $deviceIcon . '
- ' . $service["hostname"] . ' +
+
+ '.$service["service_type"].' + '.$serviceState.' + '.$deviceIcon.'
+ '.shorthost(ip_to_sysname($service, $service['hostname'])).'
'; } else { $temp_output[] = ' - - ' . $service['service_type'] . ' - ' . $serviceState . ' + + '.$service['service_type'].' - '.$serviceState.' '; } } else { - $temp_output[] = '
'; + $temp_output[] = '
'; } } } else { @@ -165,8 +197,6 @@ if (defined('SHOW_SETTINGS')) { } } - - if ($directpage == "yes") { $temp_header[] = '
@@ -174,12 +204,16 @@ if (defined('SHOW_SETTINGS')) {