diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
new file mode 100644
index 0000000..04f1d45
--- /dev/null
+++ b/.github/copilot-instructions.md
@@ -0,0 +1,23 @@
+# Cacti hmib Plugin AI Instructions
+
+## Project Overview
+This is a Cacti plugin. It integrates with the Cacti monitoring platform via the plugin hook architecture.
+
+## Technology Stack
+- PHP 7.4+ (targeting Cacti 1.2.x compatibility)
+- MySQL/MariaDB via Cacti's DB abstraction layer
+- PSR-12 coding standards
+
+## Key Rules
+- Use prepared statements (db_execute_prepared, db_fetch_row_prepared, etc.) for ALL queries with variables
+- Use get_request_var() / get_filter_request_var() for ALL user input, never raw $_REQUEST/$_GET/$_POST
+- Use html_escape() / htmlspecialchars() for ALL output of DB/user values in HTML context
+- Use cacti_escapeshellarg() for ALL shell command arguments
+- No PHP 8.0+ features (str_contains, match, union types, named args) - target PHP 7.4
+- Use ?? and ??= operators (PHP 7.4) instead of isset() ternary patterns
+- All unserialize() calls must use allowed_classes => false
+
+## Testing
+- Tests in tests/ directory
+- Use Pest PHP or PHPUnit
+- php -l lint check required before commit
diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml
new file mode 100644
index 0000000..8fafc05
--- /dev/null
+++ b/.github/workflows/plugin-ci-workflow.yml
@@ -0,0 +1,225 @@
+# +-------------------------------------------------------------------------+
+# | Copyright (C) 2004-2026 The Cacti Group |
+# | |
+# | 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 2 |
+# | of the License, or (at your option) any later version. |
+# | |
+# | This program is distributed in the hope that it will be useful, |
+# | but WITHOUT ANY WARRANTY; without even the implied warranty of |
+# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+# | GNU General Public License for more details. |
+# +-------------------------------------------------------------------------+
+# | Cacti: The Complete RRDtool-based Graphing Solution |
+# +-------------------------------------------------------------------------+
+# | This code is designed, written, and maintained by the Cacti Group. See |
+# | about.php and/or the AUTHORS file for specific developer information. |
+# +-------------------------------------------------------------------------+
+# | http://www.cacti.net/ |
+# +-------------------------------------------------------------------------+
+
+name: Plugin Integration Tests
+
+on:
+ push:
+ branches:
+ - main
+ - develop
+ pull_request:
+ branches:
+ - main
+ - develop
+
+jobs:
+ integration-test:
+ runs-on: ${{ matrix.os }}
+
+ strategy:
+ fail-fast: false
+ matrix:
+ php: ['8.1', '8.2', '8.3', '8.4']
+ os: [ubuntu-latest]
+
+ services:
+ mariadb:
+ image: mariadb:10.6
+ env:
+ MYSQL_ROOT_PASSWORD: cactiroot
+ MYSQL_DATABASE: cacti
+ MYSQL_USER: cactiuser
+ MYSQL_PASSWORD: cactiuser
+ ports:
+ - 3306:3306
+ options: >-
+ --health-cmd="mysqladmin ping"
+ --health-interval=10s
+ --health-timeout=5s
+ --health-retries=3
+
+ name: PHP ${{ matrix.php }} Integration Test on ${{ matrix.os }}
+
+ steps:
+ - name: Checkout Cacti
+ uses: actions/checkout@v4
+ with:
+ repository: Cacti/cacti
+ path: cacti
+
+ - name: Checkout hmib Plugin
+ uses: actions/checkout@v4
+ with:
+ path: cacti/plugins/hmib
+
+ - name: Install PHP ${{ matrix.php }}
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ extensions: intl, mysql, gd, ldap, gmp, xml, curl, json, mbstring
+ ini-values: "post_max_size=256M, max_execution_time=60, date.timezone=America/New_York"
+
+ - name: Check PHP version
+ run: php -v
+
+ - name: Run apt-get update
+ run: sudo apt-get update
+
+ - name: Install System Dependencies
+ run: sudo apt-get install -y apache2 snmp snmpd rrdtool fping
+
+ - name: Start SNMPD Agent and Test
+ run: |
+ sudo systemctl start snmpd
+ sudo snmpwalk -c public -v2c -On localhost .1.3.6.1.2.1.1
+
+ - name: Setup Permissions
+ run: |
+ sudo chown -R www-data:runner ${{ github.workspace }}/cacti
+ sudo find ${{ github.workspace }}/cacti -type d -exec chmod 775 {} \;
+ sudo find ${{ github.workspace }}/cacti -type f -exec chmod 664 {} \;
+ sudo chmod +x ${{ github.workspace }}/cacti/cmd.php
+ sudo chmod +x ${{ github.workspace }}/cacti/poller.php
+
+ - name: Create MySQL Config
+ run: |
+ echo -e "[client]\nuser = root\npassword = cactiroot\nhost = 127.0.0.1\n" > ~/.my.cnf
+ cat ~/.my.cnf
+
+ - name: Initialize Cacti Database
+ env:
+ MYSQL_AUTH_USR: '--defaults-file=~/.my.cnf'
+ run: |
+ mysql $MYSQL_AUTH_USR -e 'CREATE DATABASE IF NOT EXISTS cacti;'
+ mysql $MYSQL_AUTH_USR -e "CREATE USER IF NOT EXISTS 'cactiuser'@'localhost' IDENTIFIED BY 'cactiuser';"
+ mysql $MYSQL_AUTH_USR -e "GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost';"
+ mysql $MYSQL_AUTH_USR -e "GRANT SELECT ON mysql.time_zone_name TO 'cactiuser'@'localhost';"
+ mysql $MYSQL_AUTH_USR -e "FLUSH PRIVILEGES;"
+ mysql $MYSQL_AUTH_USR cacti < ${{ github.workspace }}/cacti/cacti.sql
+ mysql $MYSQL_AUTH_USR -e "INSERT INTO settings (name, value) VALUES ('path_php_binary', '/usr/bin/php')" cacti
+
+ - name: Validate composer files
+ run: |
+ cd ${{ github.workspace }}/cacti
+ if [ -f composer.json ]; then
+ composer validate --strict || true
+ fi
+
+ - name: Install Composer Dependencies
+ run: |
+ cd ${{ github.workspace }}/cacti
+ if [ -f composer.json ]; then
+ sudo composer install --prefer-dist --no-progress
+ fi
+
+ - name: Create Cacti config.php
+ run: |
+ cat ${{ github.workspace }}/cacti/include/config.php.dist | \
+ sed -r "s/localhost/127.0.0.1/g" | \
+ sed -r "s/'cacti'/'cacti'/g" | \
+ sed -r "s/'cactiuser'/'cactiuser'/g" | \
+ sed -r "s/'cactiuser'/'cactiuser'/g" > ${{ github.workspace }}/cacti/include/config.php
+ sudo chmod 664 ${{ github.workspace }}/cacti/include/config.php
+
+ - name: Configure Apache
+ run: |
+ cat << 'EOF' | sed 's#GITHUB_WORKSPACE#${{ github.workspace }}#g' > /tmp/cacti.conf
+
+ ServerAdmin webmaster@localhost
+ DocumentRoot GITHUB_WORKSPACE/cacti
+
+
+ Options Indexes FollowSymLinks
+ AllowOverride All
+ Require all granted
+
+
+ ErrorLog ${APACHE_LOG_DIR}/error.log
+ CustomLog ${APACHE_LOG_DIR}/access.log combined
+
+ EOF
+ sudo cp /tmp/cacti.conf /etc/apache2/sites-available/000-default.conf
+ sudo systemctl restart apache2
+
+ - name: Install Cacti via CLI
+ run: |
+ cd ${{ github.workspace }}/cacti
+ sudo php cli/install_cacti.php --accept-eula --install --force
+
+ - name: Install hmib Plugin
+ run: |
+ cd ${{ github.workspace }}/cacti
+ sudo php cli/plugin_manage.php --plugin=hmib --install --enable
+
+# - name: import hmib Plugin Sample Data
+# run: |
+# cd ${{ github.workspace }}/cacti/plugins/hmib
+# sudo php cli_import.php --filename=.github/workflows/hmib_sample_data.xml
+# if [ $? -ne 0 ]; then
+# echo "Failed to import Thold sample data"
+# exit 1
+# fi
+
+ - name: Check PHP Syntax for Plugin
+ run: |
+ cd ${{ github.workspace }}/cacti/plugins/hmib
+ if find . -name '*.php' -exec php -l {} 2>&1 \; | grep -iv 'no syntax errors detected'; then
+ echo "Syntax errors found!"
+ exit 1
+ fi
+
+ - name: Remove the plugins directory exclusion from the .phpstan.neon
+ run: sed '/plugins/d' -i .phpstan.neon
+ working-directory: ${{ github.workspace }}/cacti
+
+ - name: Mark composer scripts executable
+ run: sudo chmod +x ${{ github.workspace }}/cacti/include/vendor/bin/*
+
+ - name: Run Linter on base code
+ run: composer run-script lint ${{ github.workspace }}/cacti/plugins/hmib
+ working-directory: ${{ github.workspace }}/cacti
+
+ - name: Checking coding standards on base code
+ run: composer run-script phpcsfixer ${{ github.workspace }}/cacti/plugins/hmib
+ working-directory: ${{ github.workspace }}/cacti
+
+# - name: Run PHPStan at Level 6 on base code outside of Composer due to technical issues
+# run: ./include/vendor/bin/phpstan analyze --level 6 ${{ github.workspace }}/cacti/plugins/hmib
+# working-directory: ${{ github.workspace }}/cacti
+
+ - name: Run Cacti Poller
+ run: |
+ cd ${{ github.workspace }}/cacti
+ sudo php poller.php --poller=1 --force --debug
+ if ! grep -q "SYSTEM STATS" log/cacti.log; then
+ echo "Cacti poller did not finish successfully"
+ cat log/cacti.log
+ exit 1
+ fi
+
+ - name: View Cacti Logs
+ if: always()
+ run: |
+ if [ -f ${{ github.workspace }}/cacti/log/cacti.log ]; then
+ echo "=== Cacti Log ==="
+ sudo cat ${{ github.workspace }}/cacti/log/cacti.log
+ fi
diff --git a/associate_os_type.php b/associate_os_type.php
index 82892ad..98b7cb6 100644
--- a/associate_os_type.php
+++ b/associate_os_type.php
@@ -23,11 +23,11 @@
+-------------------------------------------------------------------------+
*/
-chdir(dirname(__FILE__));
+chdir(__DIR__);
chdir('../..');
include('./include/cli_check.php');
-/* process calling arguments */
+// process calling arguments
$parms = $_SERVER['argv'];
array_shift($parms);
@@ -36,11 +36,11 @@
$debug = false;
if (cacti_sizeof($parms)) {
- foreach($parms as $parameter) {
+ foreach ($parms as $parameter) {
if (strpos($parameter, '=')) {
- list($arg, $value) = explode('=', $parameter);
+ [$arg, $value] = explode('=', $parameter);
} else {
- $arg = $parameter;
+ $arg = $parameter;
$value = '';
}
@@ -48,6 +48,7 @@
case '-d':
case '--debug':
$debug = true;
+
break;
case '--version':
case '-V':
@@ -87,8 +88,8 @@ function process_hosts() {
$types = db_fetch_assoc('SELECT * FROM plugin_hmib_hrSystemTypes');
if (cacti_sizeof($types)) {
- foreach($types as $t) {
- db_execute('UPDATE plugin_hmib_hrSystem AS hrs SET host_type='. $t['id'] . "
+ foreach ($types as $t) {
+ db_execute('UPDATE plugin_hmib_hrSystem AS hrs SET host_type=' . $t['id'] . "
WHERE hrs.sysDescr LIKE '%" . $t['sysDescrMatch'] . "%'
AND hrs.sysObjectID LIKE '" . $t['sysObjectID'] . "%'");
}
@@ -105,7 +106,7 @@ function display_version() {
}
$version = plugin_hmib_version();
- print "Host MIB Associate OS Type, Version " . $version['version'] . ", " . COPYRIGHT_YEARS . "\n";
+ print 'Host MIB Associate OS Type, Version ' . $version['version'] . ', ' . COPYRIGHT_YEARS . "\n";
}
function display_help() {
@@ -113,4 +114,3 @@ function display_help() {
print "\nusage: call without any parameter\n";
}
-
diff --git a/hmib.php b/hmib.php
index b5670eb..349473c 100644
--- a/hmib.php
+++ b/hmib.php
@@ -32,29 +32,29 @@
exit;
}
-$hmib_hrSWTypes = array(
+$hmib_hrSWTypes = [
0 => __('Error', 'hmib'),
1 => __('Unknown', 'hmib'),
2 => __('Operating System', 'hmib'),
3 => __('Device Driver', 'hmib'),
4 => __('Application', 'hmib')
-);
+];
-$hmib_hrSWRunStatus = array(
+$hmib_hrSWRunStatus = [
1 => __('Running', 'hmib'),
2 => __('Runnable', 'hmib'),
3 => __('Not Runnable', 'hmib'),
4 => __('Invalid', 'hmib')
-);
+];
-$hmib_hrDeviceStatus = array(
+$hmib_hrDeviceStatus = [
0 => __('Present', 'hmib'),
1 => __('Unknown', 'hmib'),
2 => __('Running', 'hmib'),
3 => __('Warning', 'hmib'),
4 => __('Testing', 'hmib'),
5 => __('Down', 'hmib')
-);
+];
$hmib_types = array_rekey(db_fetch_assoc('SELECT *
FROM plugin_hmib_types
@@ -65,30 +65,38 @@
hmib_tabs();
switch(get_nfilter_request_var('action')) {
-case 'summary':
- hmib_summary();
- break;
-case 'running':
- hmib_running();
- break;
-case 'hardware':
- hmib_hardware();
- break;
-case 'storage':
- hmib_storage();
- break;
-case 'devices':
- hmib_devices();
- break;
-case 'history':
- hmib_history();
- break;
-case 'software':
- hmib_software();
- break;
-case 'graphs':
- hmib_view_graphs();
- break;
+ case 'summary':
+ hmib_summary();
+
+ break;
+ case 'running':
+ hmib_running();
+
+ break;
+ case 'hardware':
+ hmib_hardware();
+
+ break;
+ case 'storage':
+ hmib_storage();
+
+ break;
+ case 'devices':
+ hmib_devices();
+
+ break;
+ case 'history':
+ hmib_history();
+
+ break;
+ case 'software':
+ hmib_software();
+
+ break;
+ case 'graphs':
+ hmib_view_graphs();
+
+ break;
}
bottom_footer();
@@ -96,57 +104,57 @@
function hmib_history() {
global $config, $item_rows, $hmib_hrSWTypes, $hmib_hrSWRunStatus;
- /* ================= input validation and session storage ================= */
- $filters = array(
- 'rows' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ // ================= input validation and session storage =================
+ $filters = [
+ 'rows' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
- ),
- 'page' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'page' => [
+ 'filter' => FILTER_VALIDATE_INT,
'default' => '1'
- ),
- 'template' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'template' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'device' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'device' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'ostype' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'ostype' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'process' => array(
- 'filter' => FILTER_CALLBACK,
+ ],
+ 'process' => [
+ 'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '-1',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'filter' => array(
- 'filter' => FILTER_DEFAULT,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'filter' => [
+ 'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
- ),
- 'sort_column' => array(
- 'filter' => FILTER_CALLBACK,
+ ],
+ 'sort_column' => [
+ 'filter' => FILTER_CALLBACK,
'default' => 'name',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'sort_direction' => array(
- 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'sort_direction' => [
+ 'filter' => FILTER_CALLBACK,
'default' => 'ASC',
- 'options' => array('options' => 'sanitize_search_string')
- )
- );
+ 'options' => ['options' => 'sanitize_search_string']
+ ]
+ ];
validate_store_request_vars($filters, 'sess_hmib_hist');
- /* ================= input validation ================= */
+ // ================= input validation =================
html_start_box(__('Running Process History', 'hmib'), '100%', '', '3', 'center', '');
@@ -157,12 +165,12 @@ function hmib_history() {
|
-
+
|
|
-
+
|
|
-
+
|
|
-
-
+
+
|
@@ -234,44 +242,44 @@ function hmib_history() {
|
-
+
|
- '>
+ '>
|
-
+
|
|
-
+
|
|
@@ -315,34 +323,34 @@ function clearFilter() {
}
$sql_where = "WHERE hrswls.name!='' AND hrswls.name!='System Idle Process'";
- $sql_params = array();
- $sql_limit = ' LIMIT ' . ($num_rows*(get_request_var('page')-1)) . ',' . $num_rows;
+ $sql_params = [];
+ $sql_limit = ' LIMIT ' . ($num_rows * (get_request_var('page') - 1)) . ',' . $num_rows;
$sql_order = get_order_string();
if (get_request_var('template') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' host.host_template_id = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' host.host_template_id = ?';
$sql_params[] = get_request_var('template');
}
if (get_request_var('device') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' host.id = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' host.id = ?';
$sql_params[] = get_request_var('device');
}
if (get_request_var('ostype') > 0) {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrs.host_type = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrs.host_type = ?';
$sql_params[] = get_request_var('ostype');
} elseif (get_request_var('ostype') == 0) {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrst.id IS NULL';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrst.id IS NULL';
}
if (get_request_var('process') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrswls.name = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrswls.name = ?';
$sql_params[] = get_request_var('process');
}
if (get_request_var('filter') != '') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') .
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') .
'(host.description LIKE ? OR hrswls.name LIKE ? OR host.hostname LIKE ?)';
$sql_params[] = '%' . get_request_var('filter') . '%';
@@ -362,7 +370,7 @@ function clearFilter() {
$sql_order
$sql_limit";
- //print $sql;
+ // print $sql;
$rows = db_fetch_assoc_prepared($sql, $sql_params);
@@ -376,28 +384,28 @@ function clearFilter() {
ON hrst.id=hrs.host_type
$sql_where", $sql_params);
- $display_text = array(
- 'description' => array(
+ $display_text = [
+ 'description' => [
'display' => __('Hostname', 'hmib'),
'sort' => 'ASC',
'align' => 'left'
- ),
- 'hrswls.name' => array(
+ ],
+ 'hrswls.name' => [
'display' => __('Process', 'hmib'),
'sort' => 'DESC',
'align' => 'left'
- ),
- 'last_seen' => array(
+ ],
+ 'last_seen' => [
'display' => __('Last Seen', 'hmib'),
'sort' => 'ASC',
'align' => 'right'
- ),
- 'total_time' => array(
+ ],
+ 'total_time' => [
'display' => __('Use Time (d:h:m)', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- )
- );
+ ]
+ ];
$nav = html_nav_bar('hmib.php?action=history', MAX_DISPLAY_PAGES, get_request_var('page'), $num_rows, $total_rows, sizeof($display_text), __('History', 'hmib'), 'page', 'main');
@@ -441,22 +449,21 @@ function clearFilter() {
}
function hmib_get_runtime($time) {
-
if ($time > 86400) {
- $days = floor($time/86400);
+ $days = floor($time / 86400);
$time %= 86400;
} else {
$days = 0;
}
if ($time > 3600) {
- $hours = floor($time/3600);
- $time %= 3600;
+ $hours = floor($time / 3600);
+ $time %= 3600;
} else {
$hours = 0;
}
- $minutes = floor($time/60);
+ $minutes = floor($time / 60);
return $days . ':' . $hours . ':' . $minutes;
}
@@ -464,58 +471,58 @@ function hmib_get_runtime($time) {
function hmib_running() {
global $config, $item_rows, $hmib_hrSWTypes, $hmib_hrSWRunStatus;
- /* ================= input validation and session storage ================= */
- $filters = array(
- 'rows' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ // ================= input validation and session storage =================
+ $filters = [
+ 'rows' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
- ),
- 'page' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'page' => [
+ 'filter' => FILTER_VALIDATE_INT,
'default' => '1'
- ),
- 'template' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'template' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'device' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'device' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'ostype' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'ostype' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'filter' => array(
- 'filter' => FILTER_CALLBACK,
+ ],
+ 'filter' => [
+ 'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'process' => array(
- 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'process' => [
+ 'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '-1',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'sort_column' => array(
- 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'sort_column' => [
+ 'filter' => FILTER_CALLBACK,
'default' => 'name',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'sort_direction' => array(
- 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'sort_direction' => [
+ 'filter' => FILTER_CALLBACK,
'default' => 'ASC',
- 'options' => array('options' => 'sanitize_search_string')
- )
- );
+ 'options' => ['options' => 'sanitize_search_string']
+ ]
+ ];
validate_store_request_vars($filters, 'sess_hmib_run');
- /* ================= input validation ================= */
+ // ================= input validation =================
html_start_box(__('Running Processes', 'hmib'), '100%', '', '3', 'center', '');
@@ -526,12 +533,12 @@ function hmib_running() {
|
-
+
|
|
-
+
|
|
-
+
|
|
-
-
+
+
|
@@ -603,44 +610,44 @@ function hmib_running() {
|
-
+
|
- '>
+ '>
|
-
+
|
|
-
+
|
|
@@ -683,35 +690,35 @@ function clearFilter() {
$num_rows = get_request_var('rows');
}
- $sql_limit = ' LIMIT ' . ($num_rows*(get_request_var('page')-1)) . ',' . $num_rows;
+ $sql_limit = ' LIMIT ' . ($num_rows * (get_request_var('page') - 1)) . ',' . $num_rows;
$sql_where = "WHERE hrswr.name != '' AND hrswr.name != 'System Idle Process'";
- $sql_params = array();
+ $sql_params = [];
$sql_order = get_order_string();
if (get_request_var('template') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' host.host_template_id = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' host.host_template_id = ?';
$sql_params[] = get_request_var('template');
}
if (get_request_var('device') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' host.id = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' host.id = ?';
$sql_params[] = get_request_var('device');
}
if (get_request_var('ostype') > 0) {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrs.host_type = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrs.host_type = ?';
$sql_params[] = get_request_var('ostype');
} elseif (get_request_var('ostype') == 0) {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrst.id IS NULL';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrst.id IS NULL';
}
if (get_request_var('process') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrswr.name = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrswr.name = ?';
$sql_params[] = get_request_var('process');
}
if (get_request_var('filter') != '') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') .
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') .
' (host.description LIKE ? OR hrswr.name LIKE ? OR hrswr.parameters LIKE ? OR host.hostname LIKE ?)';
$sql_params[] = '%' . get_request_var('filter') . '%';
@@ -732,7 +739,7 @@ function clearFilter() {
$sql_order
$sql_limit";
- //print $sql;
+ // print $sql;
$rows = db_fetch_assoc_prepared($sql, $sql_params);
@@ -757,48 +764,48 @@ function clearFilter() {
ON hrst.id=hrs.host_type
$sql_where", $sql_params);
- $display_text = array(
- 'description' => array(
+ $display_text = [
+ 'description' => [
'display' => __('Hostname', 'hmib'),
'sort' => 'ASC',
'align' => 'left'
- ),
- 'hrswr.name' => array(
+ ],
+ 'hrswr.name' => [
'display' => __('Process', 'hmib'),
'sort' => 'DESC',
'align' => 'left'
- ),
- 'path' => array(
+ ],
+ 'path' => [
'display' => __('Path', 'hmib'),
'sort' => 'ASC',
'align' => 'left'
- ),
- 'parameters' => array(
+ ],
+ 'parameters' => [
'display' => __('Parameters', 'hmib'),
'sort' => 'ASC',
'align' => 'left'
- ),
- 'perfCpu' => array(
+ ],
+ 'perfCpu' => [
'display' => __('CPU (Hrs)', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'perfMemory' => array(
+ ],
+ 'perfMemory' => [
'display' => __('Memory (MB)', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'type' => array(
+ ],
+ 'type' => [
'display' => __('Type', 'hmib'),
'sort' => 'ASC',
'align' => 'right'
- ),
- 'status' => array(
+ ],
+ 'status' => [
'display' => __('Status', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- )
- );
+ ]
+ ];
$nav = html_nav_bar('hmib.php?action=running', MAX_DISPLAY_PAGES, get_request_var('page'), $num_rows, $total_rows, sizeof($display_text), __('Processes', 'hmib'), 'page', 'main');
@@ -811,7 +818,7 @@ function clearFilter() {
if (cacti_sizeof($rows)) {
$id = 0;
- foreach($rows as $row) {
+ foreach ($rows as $row) {
form_alternate_row();
if (api_plugin_user_realm_auth('host.php')) {
@@ -825,9 +832,9 @@ function clearFilter() {
form_selectable_cell(filter_value($row['name'], get_request_var('filter')), $id);
form_selectable_cell(filter_value($row['path'], get_request_var('filter')) , $id);
form_selectable_cell(filter_value($row['parameters'], get_request_var('filter')), $id);
- form_selectable_cell(number_format_i18n($row['perfCPU']/3600,0), $id, '', 'right');
- form_selectable_cell(number_format_i18n($row['perfMemory']/1024,2), $id, '', 'right');
- form_selectable_cell((isset($hmib_hrSWTypes[$row['type']]) ? $hmib_hrSWTypes[$row['type']]:__('Unknown', 'hmib')), $id, '', 'right');
+ form_selectable_cell(number_format_i18n($row['perfCPU'] / 3600,0), $id, '', 'right');
+ form_selectable_cell(number_format_i18n($row['perfMemory'] / 1024,2), $id, '', 'right');
+ form_selectable_cell((isset($hmib_hrSWTypes[$row['type']]) ? $hmib_hrSWTypes[$row['type']] : __('Unknown', 'hmib')), $id, '', 'right');
form_selectable_cell($hmib_hrSWRunStatus[$row['status']], $id, '', 'right');
$id++;
@@ -850,13 +857,13 @@ function clearFilter() {
function running_legend($totals, $total_rows) {
html_start_box('', '100%', '', '3', 'center', '');
print '';
- print '| ' . __('Total CPU [h]:', 'hmib') . ' ' . number_format_i18n($totals['cpu']/3600,0) . ' | ';
- print '' . __('Total Size [MB]:', 'hmib') . ' ' . number_format_i18n($totals['memory']/1024,2) . ' | ';
+ print '' . __('Total CPU [h]:', 'hmib') . ' ' . number_format_i18n($totals['cpu'] / 3600,0) . ' | ';
+ print '' . __('Total Size [MB]:', 'hmib') . ' ' . number_format_i18n($totals['memory'] / 1024,2) . ' | ';
print '
';
print '';
- print '| ' . __('Avg. CPU [h]:', 'hmib') . ' ' . ($total_rows ? number_format_i18n($totals['cpu']/(3600*$total_rows),0) : 0) . ' | ';
- print '' . __('Avg. Size [MB]:', 'hmib') . ' ' . ($total_rows ? number_format_i18n($totals['memory']/(1024*$total_rows),2) : 0) . ' | ';
+ print '' . __('Avg. CPU [h]:', 'hmib') . ' ' . ($total_rows ? number_format_i18n($totals['cpu'] / (3600 * $total_rows),0) : 0) . ' | ';
+ print '' . __('Avg. Size [MB]:', 'hmib') . ' ' . ($total_rows ? number_format_i18n($totals['memory'] / (1024 * $total_rows),2) : 0) . ' | ';
print '
';
html_end_box(false);
}
@@ -864,63 +871,63 @@ function running_legend($totals, $total_rows) {
function hmib_hardware() {
global $config, $item_rows, $hmib_hrSWTypes, $hmib_hrDeviceStatus, $hmib_types;
- /* ================= input validation and session storage ================= */
- $filters = array(
- 'rows' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ // ================= input validation and session storage =================
+ $filters = [
+ 'rows' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
- ),
- 'page' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'page' => [
+ 'filter' => FILTER_VALIDATE_INT,
'default' => '1'
- ),
- 'template' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'template' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'device' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'device' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'type' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'type' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'ostype' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'ostype' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'process' => array(
- 'filter' => FILTER_CALLBACK,
+ ],
+ 'process' => [
+ 'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '-1',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'filter' => array(
- 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'filter' => [
+ 'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'sort_column' => array(
- 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'sort_column' => [
+ 'filter' => FILTER_CALLBACK,
'default' => 'hrd.description',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'sort_direction' => array(
- 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'sort_direction' => [
+ 'filter' => FILTER_CALLBACK,
'default' => 'ASC',
- 'options' => array('options' => 'sanitize_search_string')
- )
- );
+ 'options' => ['options' => 'sanitize_search_string']
+ ]
+ ];
validate_store_request_vars($filters, 'sess_hmib_hw');
- /* ================= input validation ================= */
+ // ================= input validation =================
html_start_box(__('Hardware Inventory', 'hmib'), '100%', '', '3', 'center', '');
@@ -931,12 +938,12 @@ function hmib_hardware() {
|
-
+
|
|
-
+
|
|
-
+
|
|
-
-
+
+
|
@@ -1008,43 +1015,44 @@ function hmib_hardware() {
|
-
+
|
- '>
+ '>
|
-
+
|
|
-
+
|
|
@@ -1088,34 +1096,34 @@ function clearFilter() {
}
$sql_where = "WHERE (hrd.description IS NOT NULL AND hrd.description!='')";
- $sql_params = array();
- $sql_limit = ' LIMIT ' . ($num_rows*(get_request_var('page')-1)) . ',' . $num_rows;
+ $sql_params = [];
+ $sql_limit = ' LIMIT ' . ($num_rows * (get_request_var('page') - 1)) . ',' . $num_rows;
$sql_order = get_order_string();
if (get_request_var('template') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' host.host_template_id = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' host.host_template_id = ?';
$sql_params[] = get_request_var('template');
}
if (get_request_var('device') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' host.id = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' host.id = ?';
$sql_params[] = get_request_var('devices');
}
if (get_request_var('ostype') > 0) {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrs.host_type = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrs.host_type = ?';
$sql_params[] = get_request_var('ostype');
} elseif (get_request_var('ostype') == 0) {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrst.id IS NULL';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrst.id IS NULL';
}
if (get_request_var('type') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrd.type = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrd.type = ?';
$sql_params[] = get_request_var('type');
}
if (get_request_var('filter') != '') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') .
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') .
' (host.description LIKE ? OR hrd.description LIKE ? OR host.hostname LIKE ?)';
$sql_params[] = '%' . get_request_var('filter') . '%';
@@ -1143,33 +1151,33 @@ function clearFilter() {
ON hrs.host_type=hrst.id
$sql_where", $sql_params);
- $display_text = array(
- 'host.description' => array(
+ $display_text = [
+ 'host.description' => [
'display' => __('Hostname', 'hmib'),
'sort' => 'ASC',
'align' => 'left'
- ),
- 'hrd.description' => array(
+ ],
+ 'hrd.description' => [
'display' => __('Hardware Description', 'hmib'),
'sort' => 'DESC',
'align' => 'left'
- ),
- 'type' => array(
+ ],
+ 'type' => [
'display' => __('Hardware Type', 'hmib'),
'sort' => 'ASC',
'align' => 'left'
- ),
- 'status' => array(
+ ],
+ 'status' => [
'display' => __('Status', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'errors' => array(
+ ],
+ 'errors' => [
'display' => __('Errors', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- )
- );
+ ]
+ ];
$nav = html_nav_bar('hmib.php?action=hardware', MAX_DISPLAY_PAGES, get_request_var('page'), $num_rows, $total_rows, sizeof($display_text), __('Devices', 'hmib'), 'page', 'main');
@@ -1194,7 +1202,7 @@ function clearFilter() {
}
form_selectable_cell(filter_value($row['description'], get_request_var('filter')), $id);
- form_selectable_cell((isset($hmib_types[$row['type']]) ? $hmib_types[$row['type']]:__('Unknown', 'hmib')), $id);
+ form_selectable_cell((isset($hmib_types[$row['type']]) ? $hmib_types[$row['type']] : __('Unknown', 'hmib')), $id);
form_selectable_cell($hmib_hrDeviceStatus[$row['status']], $id, '', 'right');
form_selectable_cell($row['errors'], $id, '', 'right');
@@ -1202,7 +1210,6 @@ function clearFilter() {
form_end_row();
}
-
} else {
print '| ' . __('No Hardware Found', 'hmib') . ' |
';
}
@@ -1217,63 +1224,63 @@ function clearFilter() {
function hmib_storage() {
global $config, $item_rows, $hmib_hrSWTypes, $hmib_types;
- /* ================= input validation and session storage ================= */
- $filters = array(
- 'rows' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ // ================= input validation and session storage =================
+ $filters = [
+ 'rows' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
- ),
- 'page' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'page' => [
+ 'filter' => FILTER_VALIDATE_INT,
'default' => '1'
- ),
- 'template' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'template' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'device' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'device' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'type' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'type' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'ostype' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'ostype' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'process' => array(
- 'filter' => FILTER_CALLBACK,
+ ],
+ 'process' => [
+ 'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '-1',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'filter' => array(
- 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'filter' => [
+ 'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'sort_column' => array(
- 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'sort_column' => [
+ 'filter' => FILTER_CALLBACK,
'default' => 'hrsto.description',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'sort_direction' => array(
- 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'sort_direction' => [
+ 'filter' => FILTER_CALLBACK,
'default' => 'ASC',
- 'options' => array('options' => 'sanitize_search_string')
- )
- );
+ 'options' => ['options' => 'sanitize_search_string']
+ ]
+ ];
validate_store_request_vars($filters, 'sess_hmib_st');
- /* ================= input validation ================= */
+ // ================= input validation =================
?>
|
-
+
|
|
-
+
|
|
-
+
|
|
-
-
+
+
|
@@ -1364,43 +1371,44 @@ function hmib_storage() {
|
-
+
|
- '>
+ '>
|
-
+
|
|
-
+
|
|
@@ -1444,34 +1452,34 @@ function clearFilter() {
}
$sql_where = "WHERE (hrsto.description IS NOT NULL AND hrsto.description!='')";
- $sql_params = array();
- $sql_limit = ' LIMIT ' . ($num_rows*(get_request_var('page')-1)) . ',' . $num_rows;
+ $sql_params = [];
+ $sql_limit = ' LIMIT ' . ($num_rows * (get_request_var('page') - 1)) . ',' . $num_rows;
$sql_order = get_order_string();
if (get_request_var('template') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' host.host_template_id = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' host.host_template_id = ?';
$sql_params[] = get_request_var('template');
}
if (get_request_var('device') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' host.id = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' host.id = ?';
$sql_params[] = get_request_var('device');
}
if (get_request_var('ostype') > 0) {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrs.host_type = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrs.host_type = ?';
$sql_params[] = get_request_var('ostype');
} elseif (get_request_var('ostype') == 0) {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrst.id IS NULL';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrst.id IS NULL';
}
if (get_request_var('type') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrsto.type = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrsto.type = ?';
$sql_params[] = get_request_var('type');
}
if (get_request_var('filter') != '') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') .
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') .
' (host.description LIKE ? OR hrsto.description LIKE ? OR host.hostname LIKE ?)';
$sql_params[] = '%' . get_request_var('filter') . '%';
@@ -1499,48 +1507,48 @@ function clearFilter() {
ON hrs.host_type=hrst.id
$sql_where", $sql_params);
- $display_text = array(
- 'host.description' => array(
+ $display_text = [
+ 'host.description' => [
'display' => __('Hostname', 'hmib'),
'sort' => 'ASC',
'align' => 'left'
- ),
- 'hrsto.description' => array(
+ ],
+ 'hrsto.description' => [
'display' => __('Storage Description', 'hmib'),
'sort' => 'DESC',
'align' => 'left'
- ),
- 'type' => array(
+ ],
+ 'type' => [
'display' => __('Storage Type', 'hmib'),
'sort' => 'ASC',
'align' => 'left'
- ),
- 'failures' => array(
+ ],
+ 'failures' => [
'display' => __('Errors', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'percent' => array(
+ ],
+ 'percent' => [
'display' => __('Percent Used', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'used' => array(
+ ],
+ 'used' => [
'display' => __('Used (MB)', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'size' => array(
+ ],
+ 'size' => [
'display' => __('Total (MB)', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'allocationUnits' => array(
+ ],
+ 'allocationUnits' => [
'display' => __('Alloc (KB)', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- )
- );
+ ]
+ ];
$nav = html_nav_bar('hmib.php?action=storage', MAX_DISPLAY_PAGES, get_request_var('page'), $num_rows, $total_rows, sizeof($display_text), __('Volumes', 'hmib'), 'page', 'main');
@@ -1565,12 +1573,12 @@ function clearFilter() {
}
form_selectable_cell(filter_value($row['description'], get_request_var('filter')), $id);
- form_selectable_cell((isset($hmib_types[$row['type']]) ? $hmib_types[$row['type']]:__('Unknown', 'hmib')), $id);
+ form_selectable_cell((isset($hmib_types[$row['type']]) ? $hmib_types[$row['type']] : __('Unknown', 'hmib')), $id);
form_selectable_cell($row['failures'], $id, '', 'right');
- form_selectable_cell(round($row['percent']*100, 2) . '%', $id, '', 'right');
- form_selectable_cell(number_format_i18n($row['used']/1024, 0), $id, '', 'right');
- form_selectable_cell(number_format_i18n($row['size']/1024, 0), $id, '', 'right');
+ form_selectable_cell(round($row['percent'] * 100, 2) . '%', $id, '', 'right');
+ form_selectable_cell(number_format_i18n($row['used'] / 1024, 0), $id, '', 'right');
+ form_selectable_cell(number_format_i18n($row['size'] / 1024, 0), $id, '', 'right');
form_selectable_cell(number_format_i18n($row['allocationUnits']), $id, '', 'right');
$id++;
@@ -1591,58 +1599,58 @@ function clearFilter() {
function hmib_devices() {
global $config, $item_rows;
- /* ================= input validation and session storage ================= */
- $filters = array(
- 'rows' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ // ================= input validation and session storage =================
+ $filters = [
+ 'rows' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
- ),
- 'page' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'page' => [
+ 'filter' => FILTER_VALIDATE_INT,
'default' => '1'
- ),
- 'template' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'template' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'process' => array(
- 'filter' => FILTER_CALLBACK,
- 'options' => array('options' => 'sanitize_search_string'),
+ ],
+ 'process' => [
+ 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string'],
'pageset' => true,
'default' => '-1',
- ),
- 'status' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'status' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'ostype' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'ostype' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'filter' => array(
- 'filter' => FILTER_CALLBACK,
+ ],
+ 'filter' => [
+ 'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'sort_column' => array(
- 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'sort_column' => [
+ 'filter' => FILTER_CALLBACK,
'default' => 'description',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'sort_direction' => array(
- 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'sort_direction' => [
+ 'filter' => FILTER_CALLBACK,
'default' => 'ASC',
- 'options' => array('options' => 'sanitize_search_string')
- )
- );
+ 'options' => ['options' => 'sanitize_search_string']
+ ]
+ ];
validate_store_request_vars($filters, 'sess_hmib_devices');
- /* ================= input validation ================= */
+ // ================= input validation =================
html_start_box(__('Device Filter', 'hmib'), '100%', '', '3', 'center', '');
@@ -1653,12 +1661,12 @@ function hmib_devices() {
|
-
+
|
|
-
+
|
|
-
+
|
|
-
-
+
+
|
@@ -1728,63 +1736,68 @@ function hmib_devices() {
|
-
+
|
- '>
+ '>
|
-
+
|
|
-
+
|
|
@@ -1827,38 +1840,38 @@ function clearFilter() {
$num_rows = get_request_var('rows');
}
- $sql_limit = ' LIMIT ' . ($num_rows*(get_request_var('page')-1)) . ',' . $num_rows;
+ $sql_limit = ' LIMIT ' . ($num_rows * (get_request_var('page') - 1)) . ',' . $num_rows;
$sql_where = '';
- $sql_params = array();
+ $sql_params = [];
$sql_order = get_order_string();
if (get_request_var('template') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' host.host_template_id = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' host.host_template_id = ?';
$sql_params[] = get_request_var('template');
}
if (get_request_var('status') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrs.host_status = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrs.host_status = ?';
$sql_params[] = get_request_var('status');
}
if (get_request_var('ostype') > 0) {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrs.host_type = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrs.host_type = ?';
$sql_params[] = get_request_var('ostype');
} elseif (get_request_var('ostype') == 0) {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrst.id IS NULL';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrst.id IS NULL';
}
if (get_request_var('process') != '' && get_request_var('process') != '-1') {
$sql_join = 'INNER JOIN plugin_hmib_hrSWRun AS hrswr ON host.id=hrswr.host_id';
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrswr.name = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrswr.name = ?';
$sql_params[] = get_request_var('process');
} else {
$sql_join = '';
}
if (get_request_var('filter') != '') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') .
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') .
'(host.description LIKE ? OR host.hostname LIKE ?)';
$sql_params[] = '%' . get_request_var('filter') . '%';
@@ -1885,68 +1898,68 @@ function clearFilter() {
$sql_join
$sql_where", $sql_params);
- $display_text = array(
- 'nosort' => array(
+ $display_text = [
+ 'nosort' => [
'display' => __('Actions', 'hmib'),
'sort' => 'ASC',
'align' => 'left'
- ),
- 'description' => array(
+ ],
+ 'description' => [
'display' => __('Hostname', 'hmib'),
'sort' => 'ASC',
'align' => 'left'
- ),
- 'host_status' => array(
+ ],
+ 'host_status' => [
'display' => __('Status', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'uptime' => array(
+ ],
+ 'uptime' => [
'display' => __('Uptime(d:h:m)', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'users' => array(
+ ],
+ 'users' => [
'display' => __('Users', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'cpuPercent' => array(
+ ],
+ 'cpuPercent' => [
'display' => __('CPU %%%', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'numCpus' => array(
+ ],
+ 'numCpus' => [
'display' => __('CPUs', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'processes' => array(
+ ],
+ 'processes' => [
'display' => __('Processes', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'memSize' => array(
+ ],
+ 'memSize' => [
'display' => __('Total Mem', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'memUsed' => array(
+ ],
+ 'memUsed' => [
'display' => __('Used Mem', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'swapSize' => array(
+ ],
+ 'swapSize' => [
'display' => __('Total Swap', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- ),
- 'swapUsed' => array(
+ ],
+ 'swapUsed' => [
'display' => __('Used Swap', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- )
- );
+ ]
+ ];
$nav = html_nav_bar('hmib.php?action=devices', MAX_DISPLAY_PAGES, get_request_var('page'), $num_rows, $total_rows, sizeof($display_text), __('Devices', 'hmib'), 'page', 'main');
@@ -1956,7 +1969,7 @@ function clearFilter() {
html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'hmib.php?action=devices');
- /* set some defaults */
+ // set some defaults
$url = $config['url_path'] . 'plugins/hmib/hmib.php';
$proc = $config['url_path'] . 'plugins/hmib/images/cog.png';
$host = $config['url_path'] . 'plugins/hmib/images/server.png';
@@ -1987,17 +2000,17 @@ function clearFilter() {
$id = 0;
foreach ($rows as $row) {
- $days = intval($row['uptime'] / (60*60*24*100));
- $remainder = $row['uptime'] % (60*60*24*100);
- $hours = intval($remainder / (60*60*100));
- $remainder = $remainder % (60*60*100);
- $minutes = intval($remainder / (60*100));
+ $days = intval($row['uptime'] / (60 * 60 * 24 * 100));
+ $remainder = $row['uptime'] % (60 * 60 * 24 * 100);
+ $hours = intval($remainder / (60 * 60 * 100));
+ $remainder = $remainder % (60 * 60 * 100);
+ $minutes = intval($remainder / (60 * 100));
$found = db_fetch_cell('SELECT COUNT(*) FROM graph_local WHERE host_id=' . $row['host_id']);
form_alternate_row();
- //print "";
+ // print "";
$aurl = "
@@ -2021,7 +2034,7 @@ function clearFilter() {
if ($found) {
$aurl .= "
+ href='" . html_escape("$url?action=graphs&action=graphs&reset=1&host_id=" . $row['host_id'] . '&style=selective&graph_add=&graph_list=&graph_template_id=0&filter=') . "'>
";
} else {
@@ -2031,9 +2044,9 @@ function clearFilter() {
form_selectable_cell($aurl, $id, '1%');
$graph_cpu = hmib_get_graph_url($hcpudq, 0, $row['host_id'], '', $row['numCpus'], false);
- $graph_cpup = hmib_get_graph_url($hcpudq, 0, $row['host_id'], '', round($row['cpuPercent'],2). ' %', false);
- $graph_users = hmib_get_graph_template_url($hugt, 0, $row['host_id'], ($row['host_status'] < 2 ? __('N/A', 'hmib'):$row['users']), false);
- $graph_aproc = hmib_get_graph_template_url($hpgt, 0, $row['host_id'], ($row['host_status'] < 2 ? __('N/A', 'hmib'):$row['processes']), false);
+ $graph_cpup = hmib_get_graph_url($hcpudq, 0, $row['host_id'], '', round($row['cpuPercent'],2) . ' %', false);
+ $graph_users = hmib_get_graph_template_url($hugt, 0, $row['host_id'], ($row['host_status'] < 2 ? __('N/A', 'hmib') : $row['users']), false);
+ $graph_aproc = hmib_get_graph_template_url($hpgt, 0, $row['host_id'], ($row['host_status'] < 2 ? __('N/A', 'hmib') : $row['processes']), false);
if (api_plugin_user_realm_auth('host.php')) {
$host_url = html_escape($config['url_path'] . 'host.php?action=edit&id=' . $row['host_id']);
@@ -2043,17 +2056,16 @@ function clearFilter() {
form_selectable_cell(html_escape($row['description']), $id);
}
-
form_selectable_cell(get_colored_device_status(($row['disabled'] == 'on' ? true : false), $row['host_status']), $id, '', 'right');
form_selectable_cell(hmib_format_uptime($days, $hours, $minutes), $id, '', 'right');
form_selectable_cell($graph_users, $id, '', 'right');
- form_selectable_cell(($row['host_status'] < 2 ? 'N/A':$graph_cpup), $id, '', 'right');
- form_selectable_cell(($row['host_status'] < 2 ? 'N/A':$graph_cpu), $id, '', 'right');
+ form_selectable_cell(($row['host_status'] < 2 ? 'N/A' : $graph_cpup), $id, '', 'right');
+ form_selectable_cell(($row['host_status'] < 2 ? 'N/A' : $graph_cpu), $id, '', 'right');
form_selectable_cell($graph_aproc, $id, '', 'right');
form_selectable_cell(hmib_memory($row['memSize']), $id, '', 'right');
- form_selectable_cell(($row['host_status'] < 2 ? 'N/A':round($row['memUsed'],0)) . '%', $id, '', 'right');
+ form_selectable_cell(($row['host_status'] < 2 ? 'N/A' : round($row['memUsed'],0)) . '%', $id, '', 'right');
form_selectable_cell(hmib_memory($row['swapSize']), $id, '', 'right');
- form_selectable_cell(($row['host_status'] < 2 ? 'N/A':round($row['swapUsed'],0)) . ' %', $id, '', 'right');
+ form_selectable_cell(($row['host_status'] < 2 ? 'N/A' : round($row['swapUsed'],0)) . ' %', $id, '', 'right');
$id++;
@@ -2110,57 +2122,57 @@ function hmib_memory($mem) {
function hmib_software() {
global $config, $item_rows, $hmib_hrSWTypes;
- /* ================= input validation and session storage ================= */
- $filters = array(
- 'rows' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ // ================= input validation and session storage =================
+ $filters = [
+ 'rows' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
- ),
- 'page' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'page' => [
+ 'filter' => FILTER_VALIDATE_INT,
'default' => '1'
- ),
- 'template' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'template' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'device' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'device' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'type' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'type' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'ostype' => array(
- 'filter' => FILTER_VALIDATE_INT,
+ ],
+ 'ostype' => [
+ 'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1',
- ),
- 'filter' => array(
- 'filter' => FILTER_CALLBACK,
+ ],
+ 'filter' => [
+ 'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'sort_column' => array(
- 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'sort_column' => [
+ 'filter' => FILTER_CALLBACK,
'default' => 'name',
- 'options' => array('options' => 'sanitize_search_string')
- ),
- 'sort_direction' => array(
- 'filter' => FILTER_CALLBACK,
+ 'options' => ['options' => 'sanitize_search_string']
+ ],
+ 'sort_direction' => [
+ 'filter' => FILTER_CALLBACK,
'default' => 'ASC',
- 'options' => array('options' => 'sanitize_search_string')
- )
- );
+ 'options' => ['options' => 'sanitize_search_string']
+ ]
+ ];
validate_store_request_vars($filters, 'sess_hmib_sw');
- /* ================= input validation ================= */
+ // ================= input validation =================
?>
|
-
+
|
|
-
+
|
|
-
+
|
|
-
-
+
+
|
@@ -2251,43 +2263,43 @@ function hmib_software() {
|
-
+
|
- '>
+ '>
|
-
+
|
|
-
+
|
|
@@ -2330,35 +2342,35 @@ function clearFilter() {
$num_rows = get_request_var('rows');
}
- $sql_limit = ' LIMIT ' . ($num_rows*(get_request_var('page')-1)) . ',' . $num_rows;
+ $sql_limit = ' LIMIT ' . ($num_rows * (get_request_var('page') - 1)) . ',' . $num_rows;
$sql_where = '';
- $sql_params = array();
+ $sql_params = [];
$sql_order = get_order_string();
if (get_request_var('template') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' host.host_template_id = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' host.host_template_id = ?';
$sql_params[] = get_request_var('template');
}
if (get_request_var('device') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' host.id = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' host.id = ?';
$sql_params[] = get_request_var('device');
}
if (get_request_var('ostype') > 0) {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrs.host_type = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrs.host_type = ?';
$sql_params[] = get_request_var('ostype');
} elseif (get_request_var('ostype') == 0) {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrst.id IS NULL';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrst.id IS NULL';
}
if (get_request_var('type') != '-1') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') . ' hrswi.type = ?';
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' hrswi.type = ?';
$sql_params[] = get_request_var('type');
}
if (get_request_var('filter') != '') {
- $sql_where .= ($sql_where != '' ? ' AND':'WHERE') .
+ $sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') .
' (host.description LIKE ? OR hrswi.name LIKE ? OR hrswi.date LIKE ? OR host.hostname LIKE ?)';
$sql_params[] = '%' . get_request_var('filter') . '%';
@@ -2387,28 +2399,28 @@ function clearFilter() {
ON hrst.id=hrs.host_type
$sql_where", $sql_params);
- $display_text = array(
- 'description' => array(
+ $display_text = [
+ 'description' => [
'display' => __('Hostname', 'hmib'),
'sort' => 'ASC',
'align' => 'left'
- ),
- 'name' => array(
+ ],
+ 'name' => [
'display' => __('Package', 'hmib'),
'sort' => 'DESC',
'align' => 'left'
- ),
- 'type' => array(
+ ],
+ 'type' => [
'display' => __('Type', 'hmib'),
'sort' => 'ASC',
'align' => 'left'
- ),
- 'date' => array(
+ ],
+ 'date' => [
'display' => __('Installed', 'hmib'),
'sort' => 'DESC',
'align' => 'right'
- )
- );
+ ]
+ ];
$nav = html_nav_bar('hmib.php?action=software', MAX_DISPLAY_PAGES, get_request_var('page'), $num_rows, $total_rows, sizeof($display_text), __('Applications', 'hmib'), 'page', 'main');
@@ -2433,7 +2445,7 @@ function clearFilter() {
}
form_selectable_cell(filter_value($row['name'], get_request_var('filter')), $id);
- form_selectable_cell((isset($hmib_hrSWTypes[$row['type']]) ? $hmib_hrSWTypes[$row['type']]:__('Unknown', 'hmib')), $id);
+ form_selectable_cell((isset($hmib_hrSWTypes[$row['type']]) ? $hmib_hrSWTypes[$row['type']] : __('Unknown', 'hmib')), $id);
form_selectable_cell(filter_value($row['date'], get_request_var('filter')), $id, '', 'right');
$id++;
@@ -2454,8 +2466,8 @@ function clearFilter() {
function hmib_tabs() {
global $config;
- /* present a tabbed interface */
- $tabs = array(
+ // present a tabbed interface
+ $tabs = [
'summary' => __esc('Summary', 'hmib'),
'devices' => __esc('Devices', 'hmib'),
'storage' => __esc('Storage', 'hmib'),
@@ -2464,12 +2476,12 @@ function hmib_tabs() {
'history' => __esc('Use History', 'hmib'),
'software' => __esc('Inventory', 'hmib'),
'graphs' => __esc('Graphs', 'hmib')
- );
+ ];
- /* set the default tab */
+ // set the default tab
$current_tab = get_request_var('action');
- /* draw the tabs */
+ // draw the tabs
print "
@@ -990,41 +1011,44 @@ function exportTypes() {
|
-
+
|
- '>
+ '>
|
-
+
|
|
-
-
-
-
-
+
+
+
+
+
|
- '>
+ '>
0 */
+ // only numeric > 0
$regex = '^[1-9][0-9]*';
$field = 'hrStorageSizeInput';
add_host_dq_graphs($h['host_id'], $host_disk_dq, $field, $regex);
@@ -216,31 +220,32 @@ function add_host_based_graphs() {
function add_host_dq_graphs($host_id, $dq, $field = '', $regex = '', $include = true) {
global $config;
- /* add entry if it does not exist */
- $exists = db_fetch_cell_prepared("SELECT COUNT(*)
+ // add entry if it does not exist
+ $exists = db_fetch_cell_prepared('SELECT COUNT(*)
FROM host_snmp_query
WHERE host_id = ?
- AND snmp_query_id = ?",
- array($host_id, $dq));
+ AND snmp_query_id = ?',
+ [$host_id, $dq]);
if (!$exists) {
- db_execute_prepared("REPLACE INTO host_snmp_query
- (host_id, snmp_query_id, reindex_method) VALUES (?, ?, ?)",
- array($host_id, $dq, 1));
+ db_execute_prepared('REPLACE INTO host_snmp_query
+ (host_id, snmp_query_id, reindex_method) VALUES (?, ?, ?)',
+ [$host_id, $dq, 1]);
}
- /* recache snmp data */
+ // recache snmp data
debug('Reindexing Host');
run_data_query($host_id, $dq);
$graph_templates = db_fetch_assoc_prepared('SELECT *
FROM snmp_query_graph
WHERE snmp_query_id = ?',
- array($dq));
+ [$dq]);
debug('Adding Graphs');
+
if (cacti_sizeof($graph_templates)) {
- foreach($graph_templates as $gt) {
+ foreach ($graph_templates as $gt) {
hmib_dq_graphs($host_id, $dq, $gt['graph_template_id'], $gt['id'], $field, $regex, $include);
}
}
@@ -252,28 +257,28 @@ function hmib_gt_graph($host_id, $graph_template_id) {
$php_bin = read_config_option('path_php_binary');
$base = $config['base_path'];
- $name = db_fetch_cell_prepared("SELECT name
+ $name = db_fetch_cell_prepared('SELECT name
FROM graph_templates
- WHERE id = ?",
- array($graph_template_id));
+ WHERE id = ?',
+ [$graph_template_id]);
- $assoc = db_fetch_cell_prepared("SELECT count(*)
+ $assoc = db_fetch_cell_prepared('SELECT count(*)
FROM host_graph
WHERE graph_template_id = ?
- AND host_id = ?",
- array($graph_template_id, $host_id));
+ AND host_id = ?',
+ [$graph_template_id, $host_id]);
if (!$assoc) {
- db_execute_prepared("INSERT INTO host_graph
- (host_id, graph_template_id) VALUES (?, ?)",
- array($host_id, $graph_template_id));
+ db_execute_prepared('INSERT INTO host_graph
+ (host_id, graph_template_id) VALUES (?, ?)',
+ [$host_id, $graph_template_id]);
}
- $exists = db_fetch_cell_prepared("SELECT count(*)
+ $exists = db_fetch_cell_prepared('SELECT count(*)
FROM graph_local
WHERE host_id = ?
- AND graph_template_id = ?",
- array($host_id, $graph_template_id));
+ AND graph_template_id = ?',
+ [$host_id, $graph_template_id]);
if (!$exists) {
print "NOTE: Adding Graph: '$name' for Host: " . $host_id;
@@ -284,7 +289,7 @@ function hmib_gt_graph($host_id, $graph_template_id) {
' --host-id=' . $host_id;
$return_code = 0;
- $output = array();
+ $output = [];
$timeout = 20;
exec_with_timeout($command, $output, $return_code, $timeout);
@@ -294,7 +299,7 @@ function hmib_gt_graph($host_id, $graph_template_id) {
print "WARNING: add_graphs.php CLI returned a non-zero return code of $return_code" . PHP_EOL;
}
- foreach($output as $l) {
+ foreach ($output as $l) {
print trim($l) . PHP_EOL;
}
} else {
@@ -306,12 +311,13 @@ function hmib_gt_graph($host_id, $graph_template_id) {
function add_summary_graphs($host_id, $host_template) {
global $config;
- $php_bin = read_config_option('path_php_binary');
- $base = $config['base_path'];
+ $php_bin = cacti_escapeshellcmd(read_config_option('path_php_binary'));
+ $base = cacti_escapeshellarg($config['base_path']);
$return_code = 0;
+
if (empty($host_id)) {
- /* add the host */
+ // add the host
debug('Adding Host');
$result = exec("$php_bin -q $base/cli/add_device.php --description='Summary Device' --ip=summary --template=$host_template --version=0 --avail=none", $return_code);
} else {
@@ -319,22 +325,22 @@ function add_summary_graphs($host_id, $host_template) {
$result = exec("$php_bin -q $base/cli/poller_reindex_hosts.php -id=$host_id -qid=All", $return_code);
}
- /* data query graphs first */
+ // data query graphs first
debug('Processing Data Queries');
- $data_queries = db_fetch_assoc_prepared("SELECT *
+ $data_queries = db_fetch_assoc_prepared('SELECT *
FROM host_snmp_query
- WHERE host_id = ?",
- array($host_id));
+ WHERE host_id = ?',
+ [$host_id]);
if (cacti_sizeof($data_queries)) {
- foreach($data_queries as $dq) {
+ foreach ($data_queries as $dq) {
$graph_templates = db_fetch_assoc_prepared('SELECT *
FROM snmp_query_graph
WHERE snmp_query_id = ?',
- array($dq['snmp_query_id']));
+ [$dq['snmp_query_id']]);
if (cacti_sizeof($graph_templates)) {
- foreach($graph_templates as $gt) {
+ foreach ($graph_templates as $gt) {
hmib_dq_graphs($host_id, $dq['snmp_query_id'], $gt['graph_template_id'], $gt['id']);
}
}
@@ -342,19 +348,19 @@ function add_summary_graphs($host_id, $host_template) {
}
debug('Processing Graph Templates');
- $graph_templates = db_fetch_assoc_prepared("SELECT *
+ $graph_templates = db_fetch_assoc_prepared('SELECT *
FROM host_graph
- WHERE host_id = ?",
- array($host_id));
+ WHERE host_id = ?',
+ [$host_id]);
if (cacti_sizeof($graph_templates)) {
- foreach($graph_templates as $gt) {
- /* see if the graph exists already */
- $exists = db_fetch_cell_prepared("SELECT COUNT(*)
+ foreach ($graph_templates as $gt) {
+ // see if the graph exists already
+ $exists = db_fetch_cell_prepared('SELECT COUNT(*)
FROM graph_local
WHERE host_id = ?
- AND graph_template_id = ?",
- array($host_id, $gt['graph_template_id']));
+ AND graph_template_id = ?',
+ [$host_id, $gt['graph_template_id']]);
if (!$exists) {
print "NOTE: Adding item: '" . $gt['graph_template_id'] . "' for Host: " . $host_id;
@@ -364,7 +370,7 @@ function add_summary_graphs($host_id, $host_template) {
' --graph-type=cg' .
' --host-id=' . $host_id;
- $output = array();
+ $output = [];
$return_code = 0;
$timeout = 20;
@@ -390,55 +396,55 @@ function add_summary_graphs($host_id, $host_template) {
function hmib_dq_graphs($host_id, $query_id, $graph_template_id, $query_type_id,
$field = '', $regex = '', $include = true) {
-
global $config, $php_bin, $path_grid;
$php_bin = read_config_option('path_php_binary');
$base = $config['base_path'];
if ($field == '') {
- $field = db_fetch_cell_prepared("SELECT sort_field
+ $field = db_fetch_cell_prepared('SELECT sort_field
FROM host_snmp_query
WHERE host_id = ?
- AND snmp_query_id= ?",
- array($host_id, $query_id));
+ AND snmp_query_id= ?',
+ [$host_id, $query_id]);
}
- $items = db_fetch_assoc_prepared("SELECT *
+ $items = db_fetch_assoc_prepared('SELECT *
FROM host_snmp_cache
WHERE field_name = ?
AND host_id = ?
- AND snmp_query_id = ?",
- array($field, $host_id, $query_id));
+ AND snmp_query_id = ?',
+ [$field, $host_id, $query_id]);
if (cacti_sizeof($items)) {
- foreach($items as $item) {
+ foreach ($items as $item) {
$field_value = $item['field_value'];
$index = $item['snmp_index'];
if ($regex == '') {
- /* add graph below */
+ // add graph below
} elseif ((($include == true) && (preg_match('/' . $regex . '/', $field_value))) ||
(($include != true) && (!preg_match('/' . $regex . '/', $field_value)))) {
- /* add graph below */
+ // add graph below
} else {
print "NOTE: Bypassig item due to Regex rule: '" . $field_value . "' for Host: " . $host_id . "\n";
+
continue;
}
- /* check to see if the graph exists or not */
- $exists = db_fetch_cell_prepared("SELECT id
+ // check to see if the graph exists or not
+ $exists = db_fetch_cell_prepared('SELECT id
FROM graph_local
WHERE host_id = ?
AND snmp_query_id = ?
AND graph_template_id = ?
- AND snmp_index = ?",
- array($host_id, $query_id, $graph_template_id, $index));
+ AND snmp_index = ?',
+ [$host_id, $query_id, $graph_template_id, $index]);
if (!$exists) {
$command = "$php_bin -q $base/cli/add_graphs.php" .
' --graph-template-id=' . $graph_template_id .
- ' --graph-type=ds' .
+ ' --graph-type=ds' .
' --snmp-query-type-id=' . $query_type_id .
' --host-id=' . $host_id .
' --snmp-query-id=' . $query_id .
@@ -473,7 +479,7 @@ function display_version() {
}
$info = plugin_hmib_version();
- print "Host MIB Graph Automator, Version " . $info['version'] . ", " . COPYRIGHT_YEARS . "\n";
+ print 'Host MIB Graph Automator, Version ' . $info['version'] . ', ' . COPYRIGHT_YEARS . "\n";
}
function display_help() {
@@ -482,4 +488,3 @@ function display_help() {
print "\nThe Host MIB process that creates graphs for Cacti.\n\n";
print "usage: poller_graphs.php [--force] [--debug]\n";
}
-
diff --git a/poller_hmib.php b/poller_hmib.php
index 830e976..1436126 100644
--- a/poller_hmib.php
+++ b/poller_hmib.php
@@ -23,14 +23,14 @@
+-------------------------------------------------------------------------+
*/
-chdir(dirname(__FILE__));
+chdir(__DIR__);
chdir('../..');
include('./include/cli_check.php');
include_once('./lib/poller.php');
if (!function_exists('cacti_escapeshellcmd')) {
- include_once('./plugins/hmib/snmp_functions.php');
+ include_once('./plugins/hmib/snmp_functions.php');
}
if (!defined('SNMP_VALUE_LIBRARY')) {
@@ -42,7 +42,7 @@
include_once('./plugins/hmib/snmp.php');
include_once('./lib/ping.php');
-/* process calling arguments */
+// process calling arguments
$parms = $_SERVER['argv'];
array_shift($parms);
@@ -58,11 +58,11 @@
$key = '';
if (cacti_sizeof($parms)) {
- foreach($parms as $parameter) {
+ foreach ($parms as $parameter) {
if (strpos($parameter, '=')) {
- list($arg, $value) = explode('=', $parameter);
+ [$arg, $value] = explode('=', $parameter);
} else {
- $arg = $parameter;
+ $arg = $parameter;
$value = '';
}
@@ -70,30 +70,38 @@
case '-d':
case '--debug':
$debug = true;
+
break;
case '--host-id':
$host_id = $value;
+
break;
case '--seed':
$seed = $value;
+
break;
case '--key':
$key = $value;
+
break;
case '-f':
case '--force':
$forcerun = true;
+
break;
case '-fd':
case '--force-discovery':
$forcediscovery = true;
+
break;
case '-M':
$mainrun = true;
+
break;
case '-s':
case '--start':
$start = $value;
+
break;
case '--version':
case '-V':
@@ -113,13 +121,13 @@
}
}
-/* Check for mandatory parameters */
+// Check for mandatory parameters
if (!$mainrun && $host_id == '') {
print "FATAL: You must specify a Cacti host-id run\n";
exit;
}
-/* Do not process if not enabled */
+// Do not process if not enabled
if (read_config_option('hmib_enabled') == '' || !api_plugin_is_enabled('hmib')) {
print 'WARNING: The Host Mib Collection is Down! Exiting' . PHP_EOL;
exit(0);
@@ -170,13 +178,13 @@ function autoDiscoverHosts() {
debug("Starting AutoDiscovery for '" . sizeof($hosts) . "' Hosts");
- /* set a process lock */
+ // set a process lock
db_execute('REPLACE INTO plugin_hmib_processes (pid, taskid) VALUES (' . getmypid() . ', 0)');
$snmp_errors = 0;
if (cacti_sizeof($hosts)) {
- foreach($hosts as $host) {
+ foreach ($hosts as $host) {
debug("AutoDiscovery Check for Host '" . $host['description'] . '[' . $host['hostname'] . "]'");
$hostMib = cacti_snmp_walk($host['hostname'], $host['snmp_community'], '.1.3.6.1.2.1.25.1', $host['snmp_version'],
$host['snmp_username'], $host['snmp_password'],
@@ -207,7 +215,7 @@ function autoDiscoverHosts() {
cacti_log("WARNING: There were $snmp_errors SNMP errors while performing autoDiscover data", false, 'HMIB', POLLER_VERBOSITY_MEDIUM);
}
- /* remove the process lock */
+ // remove the process lock
db_execute('DELETE FROM plugin_hmib_processes WHERE pid=' . getmypid());
db_execute("REPLACE INTO settings (name,value) VALUES ('hmib_autodiscovery_lastrun', '" . time() . "')");
@@ -224,10 +232,10 @@ function process_hosts() {
*/
$auto_discovery_lastrun = read_config_option('hmib_autodiscovery_lastrun');
- /* Get Collection Frequencies (in seconds) */
+ // Get Collection Frequencies (in seconds)
$auto_discovery_freq = read_config_option('hmib_autodiscovery_freq');
- /* Set the booleans based upon current times */
+ // Set the booleans based upon current times
if (read_config_option('hmib_autodiscovery') == 'on') {
print "NOTE: Auto Discovery Starting\n";
@@ -238,10 +246,10 @@ function process_hosts() {
print "NOTE: Auto Discovery Complete\n";
}
- /* Purge collectors that run longer than 10 minutes */
+ // Purge collectors that run longer than 10 minutes
db_execute('DELETE FROM plugin_hmib_processes WHERE (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(started)) > 600');
- /* Do not process collectors are still running */
+ // Do not process collectors are still running
if (db_fetch_cell('SELECT count(*) FROM plugin_hmib_processes') > 0) {
print "WARNING: Another Host Mib Collector is still running! Exiting\n";
exit(0);
@@ -258,7 +266,7 @@ function process_hosts() {
WHERE host.disabled!='on'
AND host.status!=1");
- /* Remove entries from down and disabled hosts */
+ // Remove entries from down and disabled hosts
db_execute("DELETE FROM plugin_hmib_hrSWRun
WHERE host_id IN(
SELECT id
@@ -296,13 +304,14 @@ function process_hosts() {
print "NOTE: Launching Collectors Starting\n";
$i = 0;
+
if (cacti_sizeof($hosts)) {
foreach ($hosts as $host) {
while (true) {
$processes = db_fetch_cell('SELECT COUNT(*) FROM plugin_hmib_processes');
if ($processes < $concurrent_processes) {
- /* put a placeholder in place to prevent overloads on slow systems */
+ // put a placeholder in place to prevent overloads on slow systems
$key = rand();
db_execute("INSERT INTO plugin_hmib_processes (pid, taskid, started) VALUES ($key, $seed, NOW())");
@@ -319,18 +328,19 @@ function process_hosts() {
}
}
- /* taking a break cause for slow systems slow */
+ // taking a break cause for slow systems slow
sleep(5);
print "NOTE: All Hosts Launched, proceeding to wait for completion\n";
- /* wait for all processes to end or max run time */
+ // wait for all processes to end or max run time
while (true) {
$processes_left = db_fetch_cell("SELECT count(*) FROM plugin_hmib_processes WHERE taskid=$seed");
- $pl = db_fetch_cell('SELECT count(*) FROM plugin_hmib_processes');
+ $pl = db_fetch_cell('SELECT count(*) FROM plugin_hmib_processes');
if ($processes_left == 0) {
print "NOTE: All Processes Complete, Exiting\n";
+
break;
} else {
print "NOTE: Waiting on '$processes_left' Processes\n";
@@ -358,22 +368,27 @@ function process_hosts() {
$hrStorage_freq = read_config_option('hmib_hrStorage_freq');
$hrProcessor_freq = read_config_option('hmib_hrProcessor_freq');
- /* set the collector statistics */
+ // set the collector statistics
if (runCollector($start, $hrDevices_lastrun, $hrDevices_freq)) {
db_execute("REPLACE INTO settings (name,value) VALUES ('hmib_hrDevices_lastrun', '$start')");
}
+
if (runCollector($start, $hrSWRun_lastrun, $hrSWRun_freq)) {
db_execute("REPLACE INTO settings (name,value) VALUES ('hmib_hrSWRun_lastrun', '$start')");
}
+
if (runCollector($start, $hrSWRunPerf_lastrun, $hrSWRunPerf_freq)) {
db_execute("REPLACE INTO settings (name,value) VALUES ('hmib_hrSWRunPerf_lastrun', '$start')");
}
+
if (runCollector($start, $hrSWInstalled_lastrun, $hrSWInstalled_freq)) {
db_execute("REPLACE INTO settings (name,value) VALUES ('hmib_hrSWInstalled_lastrun', '$start')");
}
+
if (runCollector($start, $hrStorage_lastrun, $hrStorage_freq)) {
db_execute("REPLACE INTO settings (name,value) VALUES ('hmib_hrStorage_lastrun', '$start')");
}
+
if (runCollector($start, $hrProcessor_lastrun, $hrProcessor_freq)) {
db_execute("REPLACE INTO settings (name,value) VALUES ('hmib_hrProcessor_lastrun', '$start')");
}
@@ -387,14 +402,14 @@ function process_hosts() {
WHERE host.id IS NULL');
if (cacti_sizeof($dead_hosts)) {
- foreach($dead_hosts as $host) {
- db_execute('DELETE FROM plugin_hmib_hrSystem WHERE host_id='. $host['host_id']);
- db_execute('DELETE FROM plugin_hmib_hrSWRun WHERE host_id='. $host['host_id']);
- db_execute('DELETE FROM plugin_hmib_hrSWRun_last_seen WHERE host_id='. $host['host_id']);
- db_execute('DELETE FROM plugin_hmib_hrDevices WHERE host_id='. $host['host_id']);
- db_execute('DELETE FROM plugin_hmib_hrStorage WHERE host_id='. $host['host_id']);
- db_execute('DELETE FROM plugin_hmib_hrProcessor WHERE host_id='. $host['host_id']);
- db_execute('DELETE FROM plugin_hmib_hrSWInstalled WHERE host_id='. $host['host_id']);
+ foreach ($dead_hosts as $host) {
+ db_execute('DELETE FROM plugin_hmib_hrSystem WHERE host_id=' . $host['host_id']);
+ db_execute('DELETE FROM plugin_hmib_hrSWRun WHERE host_id=' . $host['host_id']);
+ db_execute('DELETE FROM plugin_hmib_hrSWRun_last_seen WHERE host_id=' . $host['host_id']);
+ db_execute('DELETE FROM plugin_hmib_hrDevices WHERE host_id=' . $host['host_id']);
+ db_execute('DELETE FROM plugin_hmib_hrStorage WHERE host_id=' . $host['host_id']);
+ db_execute('DELETE FROM plugin_hmib_hrProcessor WHERE host_id=' . $host['host_id']);
+ db_execute('DELETE FROM plugin_hmib_hrSWInstalled WHERE host_id=' . $host['host_id']);
print "Purging Host with ID '" . $host['host_id'] . "'\n";
}
}
@@ -402,7 +417,7 @@ function process_hosts() {
print "NOTE: Updating Summary Statistics for Each Host\n";
- /* update some statistics in hrSystem */
+ // update some statistics in hrSystem
$stats = db_fetch_assoc('SELECT
host.id AS host_id,
host.status AS host_status,
@@ -427,12 +442,13 @@ function process_hosts() {
numCpus=VALUES(numCpus)';
$j = 0;
- foreach($stats as $s) {
- $sql_insert .= (strlen($sql_insert) ? ', ':'') . '(' .
- $s['host_id'] . ', ' .
+
+ foreach ($stats as $s) {
+ $sql_insert .= (strlen($sql_insert) ? ', ' : '') . '(' .
+ $s['host_id'] . ', ' .
$s['host_status'] . ', ' .
- (!empty($s['cpuPercent']) ? $s['cpuPercent']:'0') . ', ' .
- (!empty($s['numCpus']) ? $s['numCpus']:'0') . ')';
+ (!empty($s['cpuPercent']) ? $s['cpuPercent'] : '0') . ', ' .
+ (!empty($s['numCpus']) ? $s['numCpus'] : '0') . ')';
$j++;
@@ -447,7 +463,7 @@ function process_hosts() {
}
}
- /* update the memory information */
+ // update the memory information
db_execute('INSERT INTO plugin_hmib_hrSystem
(host_id, memSize, memUsed, swapSize, swapUsed)
SELECT host_id,
@@ -469,38 +485,37 @@ function process_hosts() {
$types = db_fetch_assoc('SELECT * FROM plugin_hmib_hrSystemTypes');
if (cacti_sizeof($types)) {
- foreach($types as $t) {
- db_execute('UPDATE plugin_hmib_hrSystem AS hrs SET host_type='. $t['id'] . "
+ foreach ($types as $t) {
+ db_execute('UPDATE plugin_hmib_hrSystem AS hrs SET host_type=' . $t['id'] . "
WHERE hrs.sysDescr LIKE '%" . $t['sysDescrMatch'] . "%'
AND hrs.sysObjectID LIKE '" . $t['sysObjectID'] . "%'");
}
}
- /* for hosts that are down, clear information */
+ // for hosts that are down, clear information
db_execute('UPDATE plugin_hmib_hrSystem
SET users=0, cpuPercent=0, processes=0, memUsed=0, swapUsed=0, uptime=0, sysUptime=0
WHERE host_status IN (0,1)');
-
- /* take time and log performance data */
+ // take time and log performance data
$end = microtime(true);
$cacti_stats = sprintf(
'Time:%0.2f ' .
'Processes:%s ' .
'Hosts:%s',
- round($end-$start,2),
+ round($end - $start,2),
$concurrent_processes,
sizeof($hosts));
- /* log to the database */
+ // log to the database
db_execute("REPLACE INTO settings (name,value) VALUES ('stats_hmib', '" . $cacti_stats . "')");
- /* log to the logfile */
+ // log to the logfile
cacti_log('HMIB STATS: ' . $cacti_stats , true, 'SYSTEM');
print "NOTE: Host Mib Polling Completed, $cacti_stats\n";
- /* launch the graph creation process */
+ // launch the graph creation process
process_graphs();
}
@@ -513,8 +528,8 @@ function process_host($host_id, $seed, $key) {
' --start=' . $start .
' --seed=' . $seed .
' --key=' . $key .
- ($forcerun ? ' --force':'') .
- ($debug ? ' --debug':''));
+ ($forcerun ? ' --force' : '') .
+ ($debug ? ' --debug' : ''));
}
function process_graphs() {
@@ -522,8 +537,8 @@ function process_graphs() {
exec_background(read_config_option('path_php_binary'),' -q ' .
$config['base_path'] . '/plugins/hmib/poller_graphs.php' .
- ($forcerun ? ' --force':'') .
- ($debug ? ' --debug':''));
+ ($forcerun ? ' --force' : '') .
+ ($debug ? ' --debug' : ''));
}
function checkHost($host_id) {
@@ -548,17 +563,17 @@ function checkHost($host_id) {
$hrStorage_freq = read_config_option('hmib_hrStorage_freq');
$hrProcessor_freq = read_config_option('hmib_hrProcessor_freq');
- /* remove the key process and insert the set a process lock */
+ // remove the key process and insert the set a process lock
if ($key != '') {
db_execute("DELETE FROM plugin_hmib_processes WHERE pid=$key");
}
db_execute('REPLACE INTO plugin_hmib_processes (pid, taskid) VALUES (' . getmypid() . ", $seed)");
- /* obtain host information */
+ // obtain host information
$host = db_fetch_row_prepared('SELECT *
FROM host WHERE id = ?',
- array($host_id));
+ [$host_id]);
if (cacti_sizeof($host)) {
// Run the collectors
@@ -596,10 +611,10 @@ function checkHost($host_id) {
collect_hrProcessor($host);
}
- /* compensate for batch systems */
+ // compensate for batch systems
$time = substr(time(), 0, 3);
- /* update the most recent table */
+ // update the most recent table
db_execute_prepared('INSERT INTO plugin_hmib_hrSWRun_last_seen (host_id, name, total_time)
SELECT DISTINCT host_id, name, ' . read_config_option('hmib_hrSWRunPerf_freq') . " AS `total_time`
FROM plugin_hmib_hrSWRun
@@ -608,14 +623,14 @@ function checkHost($host_id) {
ON DUPLICATE KEY UPDATE
last_seen=NOW(),
total_time=total_time+VALUES(total_time)",
- array($host['id']));
+ [$host['id']]);
- /* remove the process lock */
+ // remove the process lock
db_execute_prepared('DELETE FROM plugin_hmib_processes
WHERE pid = ?',
- array(getmypid()));
+ [getmypid()]);
- /* remove odd entries */
+ // remove odd entries
db_execute("DELETE FROM plugin_hmib_hrSWRun_last_seen WHERE name='' OR name LIKE '$time%'");
if ($snmp_errors > 0) {
@@ -647,24 +662,29 @@ function collect_hrSystem(&$host) {
// Locate the values names
if (cacti_sizeof($hostMib)) {
- foreach($hostMib as $mib) {
- /* do some cleanup */
- if (substr($mib['oid'], 0, 1) != '.') $mib['oid'] = '.' . trim($mib['oid']);
- if (substr($mib['value'], 0, 4) == 'OID:') $mib['value'] = str_replace('OID:', '', $mib['value']);
+ foreach ($hostMib as $mib) {
+ // do some cleanup
+ if (substr($mib['oid'], 0, 1) != '.') {
+ $mib['oid'] = '.' . trim($mib['oid']);
+ }
+
+ if (substr($mib['value'], 0, 4) == 'OID:') {
+ $mib['value'] = str_replace('OID:', '', $mib['value']);
+ }
- $key = array_search($mib['oid'], $hrSystem);
+ $key = array_search($mib['oid'], $hrSystem, true);
if ($key == 'date') {
$mib['value'] = hmib_dateParse($mib['value']);
}
if (!empty($key)) {
- $set_string .= (strlen($set_string) ? ', ':'') . $key . '=' . db_qstr(trim($mib['value']));
+ $set_string .= (strlen($set_string) ? ', ' : '') . $key . '=' . db_qstr(trim($mib['value']));
}
}
}
- /* Update the values */
+ // Update the values
if (strlen($set_string)) {
db_execute("UPDATE plugin_hmib_hrSystem SET $set_string WHERE host_id=" . $host['id']);
}
@@ -678,7 +698,8 @@ function hmib_dateParse($value) {
$value[1] = substr($value[1], 0, strpos($value[1], '.'));
}
- $date1 = trim($value[0] . ' ' . (isset($value[1]) ? $value[1]:''));
+ $date1 = trim($value[0] . ' ' . ($value[1] ?? ''));
+
if (strtotime($date1) === false) {
$value = date('Y-m-d H:i:s');
} else {
@@ -689,13 +710,15 @@ function hmib_dateParse($value) {
}
function hmib_splitBaseIndex($oid) {
- $splitIndex = array();
+ $splitIndex = [];
$oid = strrev($oid);
$pos = strpos($oid, '.');
+
if ($pos !== false) {
$index = strrev(substr($oid, 0, $pos));
- $base = strrev(substr($oid, $pos+1));
- return array($base, $index);
+ $base = strrev(substr($oid, $pos + 1));
+
+ return [$base, $index];
} else {
return $splitIndex;
}
@@ -708,18 +731,19 @@ function collectHostIndexedOid(&$host, $tree, $table, $name) {
debug("Beginning Processing for '" . $host['description'] . '[' . $host['hostname'] . "]', Table '$name'");
if (!cacti_sizeof($types)) {
- $types = array_rekey(db_fetch_assoc('SELECT id, oid, description FROM plugin_hmib_types'), 'oid', array('id', 'description'));
+ $types = array_rekey(db_fetch_assoc('SELECT id, oid, description FROM plugin_hmib_types'), 'oid', ['id', 'description']);
}
$cols = db_get_table_column_types($table);
if (cacti_sizeof($host)) {
- /* mark for deletion */
+ // mark for deletion
db_execute("UPDATE $table SET present=0 WHERE host_id=" . $host['id']);
debug("Polling $name from '" . $host['description'] . '[' . $host['hostname'] . "]'");
- $hostMib = array();
- foreach($tree AS $mname => $oid) {
+ $hostMib = [];
+
+ foreach ($tree as $mname => $oid) {
if ($name == 'hrProcessor') {
$retrieval = SNMP_VALUE_PLAIN;
} elseif ($mname == 'date') {
@@ -745,10 +769,10 @@ function collectHostIndexedOid(&$host, $tree, $table, $name) {
$sql_prefix = "INSERT INTO $table";
if (cacti_sizeof($tree)) {
- foreach($tree as $bname => $oid) {
+ foreach ($tree as $bname => $oid) {
if ($bname != 'baseOID' && $bname != 'index') {
- $values .= (strlen($values) ? '`, `':'`') . $bname;
- $sql_suffix .= (!strlen($sql_suffix) ? ' ON DUPLICATE KEY UPDATE `index`=VALUES(`index`), `':', `') . $bname . '`=VALUES(`' . $bname . '`)';
+ $values .= (strlen($values) ? '`, `' : '`') . $bname;
+ $sql_suffix .= (!strlen($sql_suffix) ? ' ON DUPLICATE KEY UPDATE `index`=VALUES(`index`), `' : ', `') . $bname . '`=VALUES(`' . $bname . '`)';
}
}
}
@@ -758,15 +782,17 @@ function collectHostIndexedOid(&$host, $tree, $table, $name) {
// Locate the values names
$prevIndex = '';
- $new_array = array();
+ $new_array = [];
$wonky = false;
$hrProcValid = false;
$effective = 0;
if (cacti_sizeof($hostMib)) {
- foreach($hostMib as $mib) {
- /* do some cleanup */
- if (substr($mib['oid'], 0, 1) != '.') $mib['oid'] = '.' . $mib['oid'];
+ foreach ($hostMib as $mib) {
+ // do some cleanup
+ if (substr($mib['oid'], 0, 1) != '.') {
+ $mib['oid'] = '.' . $mib['oid'];
+ }
if (substr($mib['value'], 0, 4) == 'OID:') {
$mib['value'] = trim(str_replace('OID:', '', $mib['value']));
@@ -777,18 +803,19 @@ function collectHostIndexedOid(&$host, $tree, $table, $name) {
if (cacti_sizeof($splitIndex)) {
$index = $splitIndex[1];
$oid = $splitIndex[0];
- $key = array_search($oid, $tree);
+ $key = array_search($oid, $tree, true);
- /* issue workaround for snmp issues */
+ // issue workaround for snmp issues
if ($name == 'hrProcessor' && $mib['value'] == '.0.0') {
if ($wonky) {
$key = 'load';
$mib['value'] = $effective;
} elseif (!$hrProcValid) {
if (db_fetch_cell("SELECT count(*) FROM plugin_hmib_hrSystem WHERE sysDescr LIKE '%Linux%' AND host_id=" . $host['id'])) {
- /* look for the hrProcessorLoad value */
+ // look for the hrProcessorLoad value
$temp_mib = $hostMib;
- foreach($temp_mib AS $kk => $vv) {
+
+ foreach ($temp_mib as $kk => $vv) {
if (substr_count($kk, '.1.3.6.1.2.1.25.3.3.1.2')) {
$hrProcValid = true;
}
@@ -826,16 +853,18 @@ function collectHostIndexedOid(&$host, $tree, $table, $name) {
if (!empty($key)) {
if ($key == 'type') {
$value = explode('(', $mib['value']);
+
if (cacti_sizeof($value) > 1) {
$value = trim($value[1], " \n\r)");
+
if ($table != 'plugin_hmib_hrSWInstalled' && $table != 'plugin_hmib_hrSWRun') {
- $new_array[$index][$key] = (isset($types[$value]) ? $types[$value]['id']:0);
+ $new_array[$index][$key] = (isset($types[$value]) ? $types[$value]['id'] : 0);
} else {
$new_array[$index][$key] = $value;
}
} else {
if ($table != 'plugin_hmib_hrSWInstalled' && $table != 'plugin_hmib_hrSWRun') {
- $new_array[$index][$key] = (isset($types[$value[0]]) ? $types[$value[0]]['id']:0);
+ $new_array[$index][$key] = (isset($types[$value[0]]) ? $types[$value[0]]['id'] : 0);
} else {
$new_array[$index][$key] = $value[0];
}
@@ -844,7 +873,7 @@ function collectHostIndexedOid(&$host, $tree, $table, $name) {
$new_array[$index][$key] = hmib_dateParse($mib['value']);
} elseif ($key == 'name' && $table == 'plugin_hmib_hrSWRun') {
if (!empty($mib['value']) && $mib['value'] != 'NULL') {
- $parts = explode('/', $mib['value']);
+ $parts = explode('/', $mib['value']);
$new_array[$index][$key] = $parts[0];
} else {
$new_array[$index][$key] = '';
@@ -890,20 +919,21 @@ function collectHostIndexedOid(&$host, $tree, $table, $name) {
}
}
- /* dump the output to the database */
+ // dump the output to the database
$sql_insert = '';
- $sql_params = array();
+ $sql_params = [];
$count = 0;
+
if (cacti_sizeof($new_array)) {
- foreach($new_array as $index => $item) {
- $sql_insert .= ($sql_insert != '' ? '), (':'(') . '?, ?, ';
+ foreach ($new_array as $index => $item) {
+ $sql_insert .= ($sql_insert != '' ? '), (' : '(') . '?, ?, ';
$sql_params[] = $host['id'];
$sql_params[] = $index;
$i = 0;
- foreach($tree as $key => $oid) {
+ foreach ($tree as $key => $oid) {
if ($key != 'baseOID' && $key != 'index') {
if (isset($item[$key]) && $item[$key] != '') {
if (isset($cols[$key]['type'])) {
@@ -911,16 +941,15 @@ function collectHostIndexedOid(&$host, $tree, $table, $name) {
strstr($cols[$key]['type'], 'float') !== false ||
strstr($cols[$key]['type'], 'double') !== false ||
strstr($cols[$key]['type'], 'decimal') !== false) {
-
if (is_numeric($item[$key])) {
- $sql_insert .= ($i > 0 ? ', ':'') . '?';
+ $sql_insert .= ($i > 0 ? ', ' : '') . '?';
$sql_params[] = $item[$key];
} else {
- $sql_insert .= ($i > 0 ? ', ':'') . '?';
+ $sql_insert .= ($i > 0 ? ', ' : '') . '?';
$sql_params[] = 0;
}
} else {
- $sql_insert .= ($i > 0 ? ', ':'') . '?';
+ $sql_insert .= ($i > 0 ? ', ' : '') . '?';
$sql_params[] = $item[$key];
}
@@ -932,20 +961,19 @@ function collectHostIndexedOid(&$host, $tree, $table, $name) {
strstr($cols[$key]['type'], 'float') !== false ||
strstr($cols[$key]['type'], 'double') !== false ||
strstr($cols[$key]['type'], 'decimal') !== false) {
-
if (isset($item[$key]) && is_numeric($item[$key])) {
- $sql_insert .= ($i > 0 ? ', ':'') . '?';
+ $sql_insert .= ($i > 0 ? ', ' : '') . '?';
$sql_params[] = $item[$key];
} else {
- $sql_insert .= ($i > 0 ? ', ':'') . '?';
+ $sql_insert .= ($i > 0 ? ', ' : '') . '?';
$sql_params[] = 0;
}
} else {
if (isset($item[$key])) {
- $sql_insert .= ($i > 0 ? ', ':'') . '?';
+ $sql_insert .= ($i > 0 ? ', ' : '') . '?';
$sql_params[] = $item[$key];
} else {
- $sql_insert .= ($i > 0 ? ', ':'') . '?';
+ $sql_insert .= ($i > 0 ? ', ' : '') . '?';
$sql_params[] = 0;
}
}
@@ -959,10 +987,11 @@ function collectHostIndexedOid(&$host, $tree, $table, $name) {
$sql_insert .= ')';
$count++;
+
if (($count % 100) == 0) {
db_execute_prepared($sql_prefix . $sql_insert . $sql_suffix, $sql_params);
$sql_insert = '';
- $sql_params = array();
+ $sql_params = [];
}
}
@@ -970,7 +999,7 @@ function collectHostIndexedOid(&$host, $tree, $table, $name) {
db_execute_prepared($sql_prefix . $sql_insert . $sql_suffix, $sql_params);
}
- /* remove old records */
+ // remove old records
db_execute("DELETE FROM $table WHERE present=0 AND host_id=" . $host['id']);
}
}
@@ -1013,7 +1042,7 @@ function display_version() {
}
$info = plugin_hmib_version();
- print "Host MIB Poller Process, Version " . $info['version'] . ", " . COPYRIGHT_YEARS . "\n";
+ print 'Host MIB Poller Process, Version ' . $info['version'] . ', ' . COPYRIGHT_YEARS . "\n";
}
function display_help() {
@@ -1024,4 +1053,3 @@ function display_help() {
print "master process: poller_hmib.php [-M] [-f] [-fd] [-d]\n";
print "child process: poller_hmib.php --host-id=N [--seed=N] [-f] [-d]\n\n";
}
-
diff --git a/setup.php b/setup.php
index f132d3c..13c0e76 100644
--- a/setup.php
+++ b/setup.php
@@ -23,7 +23,7 @@
*/
function plugin_hmib_install() {
- # graph setup all arrays needed for automation
+ // graph setup all arrays needed for automation
api_plugin_register_hook('hmib', 'config_arrays', 'hmib_config_arrays', 'setup.php');
api_plugin_register_hook('hmib', 'config_settings', 'hmib_config_settings', 'setup.php');
api_plugin_register_hook('hmib', 'draw_navigation_text', 'hmib_draw_navigation_text', 'setup.php');
@@ -58,20 +58,23 @@ function plugin_hmib_uninstall() {
function plugin_hmib_check_config() {
// Here we will check to ensure everything is configured
hmib_check_upgrade();
+
return true;
}
function plugin_hmib_upgrade() {
// Here we will upgrade to the newest version
hmib_check_upgrade();
+
return true;
}
function plugin_hmib_version() {
global $config;
$info = parse_ini_file($config['base_path'] . '/plugins/hmib/INFO', true);
+
return $info['info'];
- }
+}
function hmib_check_upgrade() {
global $config, $database_default;
@@ -79,8 +82,9 @@ function hmib_check_upgrade() {
include_once($config['library_path'] . '/functions.php');
// Let's only run this check if we are on a page that actually needs the data
- $files = array('plugins.php', 'hmib.php');
- if (!in_array(get_current_page(), $files)) {
+ $files = ['plugins.php', 'hmib.php'];
+
+ if (!in_array(get_current_page(), $files, true)) {
return;
}
@@ -90,15 +94,15 @@ function hmib_check_upgrade() {
if ($current != $old) {
if (api_plugin_is_enabled('hmib')) {
- # may sound ridiculous, but enables new hooks
+ // may sound ridiculous, but enables new hooks
api_plugin_enable_hooks('hmib');
}
db_execute("UPDATE plugin_config SET version='$current' WHERE directory='hmib'");
db_execute("UPDATE plugin_config SET
- version='" . $info['version'] . "',
- name='" . $info['longname'] . "',
- author='" . $info['author'] . "',
+ version='" . $info['version'] . "',
+ name='" . $info['longname'] . "',
+ author='" . $info['author'] . "',
webpage='" . $info['homepage'] . "'
WHERE directory='" . $info['name'] . "' ");
@@ -348,7 +352,7 @@ function hmib_setup_table() {
(50,'.1.3.6.1.2.1.25.3.9.5','FAT'),
(51,'.1.3.6.1.2.1.25.3.9.9','NTFS')");
- /* optimizations */
+ // optimizations
if (!db_index_exists('data_input_data', 'data_template_data_id')) {
db_execute('ALTER TABLE data_input_data ADD INDEX data_template_data_id(data_template_data_id)');
}
@@ -373,68 +377,68 @@ function hmib_poller_bottom() {
exec_background(read_config_option('path_php_binary'), ' -q ' . $config['base_path'] . '/plugins/hmib/poller_hmib.php -M');
}
-function hmib_config_settings () {
+function hmib_config_settings() {
global $tabs, $settings, $hmib_frequencies, $item_rows;
- $tabs['hmib'] = __('Host MIB', 'hmib');
- $settings['hmib'] = array(
- 'hmib_header' => array(
+ $tabs['hmib'] = __('Host MIB', 'hmib');
+ $settings['hmib'] = [
+ 'hmib_header' => [
'friendly_name' => __('Host MIB General Settings', 'hmib'),
- 'method' => 'spacer',
- ),
- 'hmib_enabled' => array(
+ 'method' => 'spacer',
+ ],
+ 'hmib_enabled' => [
'friendly_name' => __('Host MIB Poller Enabled', 'hmib'),
- 'description' => __('Check this box, if you want Host MIB polling to be enabled. Otherwise, the poller will not function.', 'hmib'),
- 'method' => 'checkbox',
- 'default' => ''
- ),
- 'hmib_autodiscovery' => array(
+ 'description' => __('Check this box, if you want Host MIB polling to be enabled. Otherwise, the poller will not function.', 'hmib'),
+ 'method' => 'checkbox',
+ 'default' => ''
+ ],
+ 'hmib_autodiscovery' => [
'friendly_name' => __('Automatically Discover Cacti Devices', 'hmib'),
- 'description' => __('Do you wish to automatically scan for and add devices which support the Host Resource MIB from the Cacti host table?', 'hmib'),
- 'method' => 'checkbox',
- 'default' => 'on'
- ),
- 'hmib_autopurge' => array(
+ 'description' => __('Do you wish to automatically scan for and add devices which support the Host Resource MIB from the Cacti host table?', 'hmib'),
+ 'method' => 'checkbox',
+ 'default' => 'on'
+ ],
+ 'hmib_autopurge' => [
'friendly_name' => __('Automatically Purge Devices', 'hmib'),
- 'description' => __('Do you wish to automatically purge devices that are removed from the Cacti system?', 'hmib'),
- 'method' => 'checkbox',
- 'default' => 'on'
- ),
- 'hmib_os_type_rows' => array(
+ 'description' => __('Do you wish to automatically purge devices that are removed from the Cacti system?', 'hmib'),
+ 'method' => 'checkbox',
+ 'default' => 'on'
+ ],
+ 'hmib_os_type_rows' => [
'friendly_name' => __('Default Row Count', 'hmib'),
- 'description' => __('How many rows do you wish to see on the HMIB OS Type by default?', 'hmib'),
- 'method' => 'drop_array',
- 'default' => '10',
- 'array' => $item_rows
- ),
- 'hmib_top_types' => array(
+ 'description' => __('How many rows do you wish to see on the HMIB OS Type by default?', 'hmib'),
+ 'method' => 'drop_array',
+ 'default' => '10',
+ 'array' => $item_rows
+ ],
+ 'hmib_top_types' => [
'friendly_name' => __('Default Top Host Types', 'hmib'),
- 'description' => __('How many processes do you wish to see on the HMIB Dashboard by default?', 'hmib'),
- 'method' => 'drop_array',
- 'default' => '10',
- 'array' => array(
+ 'description' => __('How many processes do you wish to see on the HMIB Dashboard by default?', 'hmib'),
+ 'method' => 'drop_array',
+ 'default' => '10',
+ 'array' => [
5 => __('%d Types', 5, 'hmib'),
8 => __('%d Types', 8, 'hmib'),
10 => __('%d Types', 10, 'hmib'),
- 15 => __('%d Types', 15, 'hmib'))
- ),
- 'hmib_top_processes' => array(
+ 15 => __('%d Types', 15, 'hmib')]
+ ],
+ 'hmib_top_processes' => [
'friendly_name' => __('Default Top Processes', 'hmib'),
- 'description' => __('How many processes do you wish to see on the HMIB Dashboard by default?', 'hmib'),
- 'method' => 'drop_array',
- 'default' => '10',
- 'array' => array(
+ 'description' => __('How many processes do you wish to see on the HMIB Dashboard by default?', 'hmib'),
+ 'method' => 'drop_array',
+ 'default' => '10',
+ 'array' => [
5 => __('%d Processes', 5, 'hmib'),
10 => __('%d Processes', 10, 'hmib'),
20 => __('%d Processes', 20, 'hmib'),
- 30 => __('%d Processes', 30, 'hmib'))
- ),
- 'hmib_concurrent_processes' => array(
+ 30 => __('%d Processes', 30, 'hmib')]
+ ],
+ 'hmib_concurrent_processes' => [
'friendly_name' => __('Maximum Concurrent Collectors', 'hmib'),
- 'description' => __('What is the maximum number of concurrent collector process that you want to run at one time?', 'hmib'),
- 'method' => 'drop_array',
- 'default' => '10',
- 'array' => array(
+ 'description' => __('What is the maximum number of concurrent collector process that you want to run at one time?', 'hmib'),
+ 'method' => 'drop_array',
+ 'default' => '10',
+ 'array' => [
1 => __('%d Process', 1, 'hmib'),
2 => __('%d Processes', 2, 'hmib'),
3 => __('%d Processes', 3, 'hmib'),
@@ -444,89 +448,89 @@ function hmib_config_settings () {
20 => __('%d Processes', 20, 'hmib'),
30 => __('%d Processes', 30, 'hmib'),
40 => __('%d Processes', 40, 'hmib'),
- 50 => __('%d Processes', 50, 'hmib'))
- ),
- 'hmib_autodiscovery_header' => array(
+ 50 => __('%d Processes', 50, 'hmib')]
+ ],
+ 'hmib_autodiscovery_header' => [
'friendly_name' => __('Host Auto Discovery Frequency', 'hmib'),
- 'method' => 'spacer',
- ),
- 'hmib_autodiscovery_freq' => array(
+ 'method' => 'spacer',
+ ],
+ 'hmib_autodiscovery_freq' => [
'friendly_name' => __('Auto Discovery Frequency', 'hmib'),
- 'description' => __('How often do you want to look for new Cacti Devices?', 'hmib'),
- 'method' => 'drop_array',
- 'default' => '300',
- 'array' => $hmib_frequencies
- ),
- 'hmib_automation_header' => array(
+ 'description' => __('How often do you want to look for new Cacti Devices?', 'hmib'),
+ 'method' => 'drop_array',
+ 'default' => '300',
+ 'array' => $hmib_frequencies
+ ],
+ 'hmib_automation_header' => [
'friendly_name' => __('Host Graph Automation', 'hmib'),
- 'method' => 'spacer',
- ),
- 'hmib_automation_frequency' => array(
+ 'method' => 'spacer',
+ ],
+ 'hmib_automation_frequency' => [
'friendly_name' => __('Automatically Add New Graphs', 'hmib'),
- 'description' => __('How often do you want to check for new objects to graph?', 'hmib'),
- 'method' => 'drop_array',
- 'default' => '0',
- 'array' => array(
+ 'description' => __('How often do you want to check for new objects to graph?', 'hmib'),
+ 'method' => 'drop_array',
+ 'default' => '0',
+ 'array' => [
0 => __('Never', 'hmib'),
1 => __('%d Hour', 1, 'hmib'),
12 => __('%d Hours', 12, 'hmib'),
24 => __('%d Day', 1, 'hmib'),
- 48 => __('%d Days', 2, 'hmib'))
- ),
- 'hmib_frequencies' => array(
+ 48 => __('%d Days', 2, 'hmib')]
+ ],
+ 'hmib_frequencies' => [
'friendly_name' => __('Host MIB Table Collection Frequencies', 'hmib'),
- 'method' => 'spacer',
- ),
- 'hmib_hrSWRun_freq' => array(
+ 'method' => 'spacer',
+ ],
+ 'hmib_hrSWRun_freq' => [
'friendly_name' => __('Running Programs Frequency', 'hmib'),
- 'description' => __('How often do you want to scan running software?', 'hmib'),
- 'method' => 'drop_array',
- 'default' => '300',
- 'array' => $hmib_frequencies
- ),
- 'hmib_hrSWRunPerf_freq' => array(
+ 'description' => __('How often do you want to scan running software?', 'hmib'),
+ 'method' => 'drop_array',
+ 'default' => '300',
+ 'array' => $hmib_frequencies
+ ],
+ 'hmib_hrSWRunPerf_freq' => [
'friendly_name' => __('Running Programs CPU/Memory Frequency', 'hmib'),
- 'description' => __('How often do you want to scan running software for performance data?', 'hmib'),
- 'method' => 'drop_array',
- 'default' => '300',
- 'array' => $hmib_frequencies
- ),
- 'hmib_hrSWInstalled_freq' => array(
+ 'description' => __('How often do you want to scan running software for performance data?', 'hmib'),
+ 'method' => 'drop_array',
+ 'default' => '300',
+ 'array' => $hmib_frequencies
+ ],
+ 'hmib_hrSWInstalled_freq' => [
'friendly_name' => __('Installed Software Frequency', 'hmib'),
- 'description' => __('How often do you want to scan for installed software?', 'hmib'),
- 'method' => 'drop_array',
- 'default' => '86400',
- 'array' => $hmib_frequencies
- ),
- 'hmib_hrStorage_freq' => array(
+ 'description' => __('How often do you want to scan for installed software?', 'hmib'),
+ 'method' => 'drop_array',
+ 'default' => '86400',
+ 'array' => $hmib_frequencies
+ ],
+ 'hmib_hrStorage_freq' => [
'friendly_name' => __('Storage Frequency', 'hmib'),
- 'description' => __('How often do you want to scan for Storage performance data?', 'hmib'),
- 'method' => 'drop_array',
- 'default' => '3600',
- 'array' => $hmib_frequencies
- ),
- 'hmib_hrDevices_freq' => array(
+ 'description' => __('How often do you want to scan for Storage performance data?', 'hmib'),
+ 'method' => 'drop_array',
+ 'default' => '3600',
+ 'array' => $hmib_frequencies
+ ],
+ 'hmib_hrDevices_freq' => [
'friendly_name' => __('Device Frequency', 'hmib'),
- 'description' => __('How often do you want to scan for Device performance data?', 'hmib'),
- 'method' => 'drop_array',
- 'default' => '3600',
- 'array' => $hmib_frequencies
- ),
- 'hmib_hrProcessor_freq' => array(
+ 'description' => __('How often do you want to scan for Device performance data?', 'hmib'),
+ 'method' => 'drop_array',
+ 'default' => '3600',
+ 'array' => $hmib_frequencies
+ ],
+ 'hmib_hrProcessor_freq' => [
'friendly_name' => __('Processor Frequency', 'hmib'),
- 'description' => __('How often do you want to scan for Processor performance data?', 'hmib'),
- 'method' => 'drop_array',
- 'default' => '300',
- 'array' => $hmib_frequencies
- )
- );
+ 'description' => __('How often do you want to scan for Processor performance data?', 'hmib'),
+ 'method' => 'drop_array',
+ 'default' => '300',
+ 'array' => $hmib_frequencies
+ ]
+ ];
}
function hmib_config_arrays() {
global $menu, $messages, $hmib_frequencies;
global $hrSystem, $hrSWRun, $hrSWRunPerf, $hrSWInstalled, $hrStorage, $hrDevices, $hrProcessor;
- $hmib_frequencies = array(
+ $hmib_frequencies = [
-1 => __('Disabled', 'hmib'),
60 => __('%d Minute', 1, 'hmib'),
300 => __('%d Minutes', 5, 'hmib'),
@@ -537,9 +541,9 @@ function hmib_config_arrays() {
14400 => __('%d Hours', 4, 'hmib'),
43200 => __('%d Hours', 12, 'hmib'),
86400 => __('%d Day', 1, 'hmib')
- );
+ ];
- $hrSystem = array(
+ $hrSystem = [
'baseOID' => '.1.3.6.1.2.1.25.1.',
'uptime' => '.1.3.6.1.2.1.25.1.1.0',
'date' => '.1.3.6.1.2.1.25.1.2.0',
@@ -555,9 +559,9 @@ function hmib_config_arrays() {
'sysContact' => '.1.3.6.1.2.1.1.4.0',
'sysName' => '.1.3.6.1.2.1.1.5.0',
'sysLocation' => '.1.3.6.1.2.1.1.6.0'
- );
+ ];
- $hrSWRun = array(
+ $hrSWRun = [
'baseOID' => '.1.3.6.1.2.1.25.4.2.1',
'index' => '.1.3.6.1.2.1.25.4.2.1.1',
'name' => '.1.3.6.1.2.1.25.4.2.1.2',
@@ -565,23 +569,23 @@ function hmib_config_arrays() {
'parameters' => '.1.3.6.1.2.1.25.4.2.1.5',
'type' => '.1.3.6.1.2.1.25.4.2.1.6',
'status' => '.1.3.6.1.2.1.25.4.2.1.7'
- );
+ ];
- $hrSWRunPerf = array(
+ $hrSWRunPerf = [
'baseOID' => '.1.3.6.1.2.1.25.5.1.1',
'perfCPU' => '.1.3.6.1.2.1.25.5.1.1.1',
'perfMemory' => '.1.3.6.1.2.1.25.5.1.1.2'
- );
+ ];
- $hrSWInstalled = array(
+ $hrSWInstalled = [
'baseOID' => '.1.3.6.1.2.1.25.6.3.1',
'index' => '.1.3.6.1.2.1.25.6.3.1.1',
'name' => '.1.3.6.1.2.1.25.6.3.1.2',
'type' => '.1.3.6.1.2.1.25.6.3.1.4',
'date' => '.1.3.6.1.2.1.25.6.3.1.5'
- );
+ ];
- $hrStorage = array(
+ $hrStorage = [
'baseOID' => '.1.3.6.1.2.1.25.2.3',
'index' => '.1.3.6.1.2.1.25.2.3.1.1',
'type' => '.1.3.6.1.2.1.25.2.3.1.2',
@@ -590,50 +594,50 @@ function hmib_config_arrays() {
'size' => '.1.3.6.1.2.1.25.2.3.1.5',
'used' => '.1.3.6.1.2.1.25.2.3.1.6',
'failures' => '.1.3.6.1.2.1.25.2.3.1.7'
- );
+ ];
- $hrDevices = array(
+ $hrDevices = [
'baseOID' => '.1.3.6.1.2.1.25.3.2.1',
'index' => '.1.3.6.1.2.1.25.3.2.1.1',
'type' => '.1.3.6.1.2.1.25.3.2.1.2',
'description' => '.1.3.6.1.2.1.25.3.2.1.3',
'status' => '.1.3.6.1.2.1.25.3.2.1.5',
'errors' => '.1.3.6.1.2.1.25.3.2.1.6',
- );
+ ];
- $hrProcessor = array(
+ $hrProcessor = [
'baseOID' => '.1.3.6.1.2.1.25.3.3.1',
'load' => '.1.3.6.1.2.1.25.3.3.1.2'
- );
+ ];
if (isset($_SESSION['hmib_message']) && $_SESSION['hmib_message'] != '') {
- $messages['hmib_message'] = array('message' => $_SESSION['hmib_message'], 'type' => 'info');
+ $messages['hmib_message'] = ['message' => $_SESSION['hmib_message'], 'type' => 'info'];
}
$menu[__('Management')]['plugins/hmib/hmib_types.php'] = __('OS Types', 'hmib');
if (function_exists('auth_augment_roles')) {
- auth_augment_roles(__('Normal User'), array('hmib.php'));
- auth_augment_roles(__('General Administration'), array('hmib_types.php'));
+ auth_augment_roles(__('Normal User'), ['hmib.php']);
+ auth_augment_roles(__('General Administration'), ['hmib_types.php']);
}
hmib_check_upgrade();
}
-function hmib_draw_navigation_text ($nav) {
- $nav['hmib.php:summary'] = array('title' => __('Host MIB Inventory Summary', 'hmib'), 'mapping' => '', 'url' => 'hmib.php', 'level' => '0');
- $nav['hmib.php:devices'] = array('title' => __('Host MIB Details', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0');
- $nav['hmib.php:storage'] = array('title' => __('Host MIB Storage', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0');
- $nav['hmib.php:hardware'] = array('title' => __('Host MIB Hardware', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0');
- $nav['hmib.php:running'] = array('title' => __('Host MIB Running Processes', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0');
- $nav['hmib.php:history'] = array('title' => __('Host MIB Process Use History', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0');
- $nav['hmib.php:software'] = array('title' => __('Host MIB Software Inventory', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0');
- $nav['hmib.php:graphs'] = array('title' => __('Host MIB Graphs', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0');
-
- $nav['hmib_types.php:'] = array('title' => __('Host MIB OS Types', 'hmib'), 'mapping' => 'index.php:', 'url' => 'hmib_types.php', 'level' => '1');
- $nav['hmib_types.php:actions']= array('title' => __('Actions', 'hmib'), 'mapping' => 'index.php:,hmib_types.php:', 'url' => 'hmib_types.php', 'level' => '2');
- $nav['hmib_types.php:edit'] = array('title' => __('(Edit)', 'hmib'), 'mapping' => 'index.php:,hmib_types.php:', 'url' => 'hmib_types.php', 'level' => '2');
- $nav['hmib_types.php:import'] = array('title' => __('Import', 'hmib'), 'mapping' => 'index.php:,hmib_types.php:', 'url' => 'hmib_types.php', 'level' => '2');
+function hmib_draw_navigation_text($nav) {
+ $nav['hmib.php:summary'] = ['title' => __('Host MIB Inventory Summary', 'hmib'), 'mapping' => '', 'url' => 'hmib.php', 'level' => '0'];
+ $nav['hmib.php:devices'] = ['title' => __('Host MIB Details', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0'];
+ $nav['hmib.php:storage'] = ['title' => __('Host MIB Storage', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0'];
+ $nav['hmib.php:hardware'] = ['title' => __('Host MIB Hardware', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0'];
+ $nav['hmib.php:running'] = ['title' => __('Host MIB Running Processes', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0'];
+ $nav['hmib.php:history'] = ['title' => __('Host MIB Process Use History', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0'];
+ $nav['hmib.php:software'] = ['title' => __('Host MIB Software Inventory', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0'];
+ $nav['hmib.php:graphs'] = ['title' => __('Host MIB Graphs', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0'];
+
+ $nav['hmib_types.php:'] = ['title' => __('Host MIB OS Types', 'hmib'), 'mapping' => 'index.php:', 'url' => 'hmib_types.php', 'level' => '1'];
+ $nav['hmib_types.php:actions'] = ['title' => __('Actions', 'hmib'), 'mapping' => 'index.php:,hmib_types.php:', 'url' => 'hmib_types.php', 'level' => '2'];
+ $nav['hmib_types.php:edit'] = ['title' => __('(Edit)', 'hmib'), 'mapping' => 'index.php:,hmib_types.php:', 'url' => 'hmib_types.php', 'level' => '2'];
+ $nav['hmib_types.php:import'] = ['title' => __('Import', 'hmib'), 'mapping' => 'index.php:,hmib_types.php:', 'url' => 'hmib_types.php', 'level' => '2'];
return $nav;
}
@@ -692,7 +696,7 @@ function hmib_get_cpu_indexes($host_index) {
}
$host_id = $host_index['host_id'];
- $rarray = array();
+ $rarray = [];
$indexes = db_fetch_assoc("SELECT `index`
FROM plugin_hmib_hrProcessor
@@ -701,7 +705,8 @@ function hmib_get_cpu_indexes($host_index) {
if (cacti_sizeof($indexes)) {
$i = 0;
- foreach($indexes as $i) {
+
+ foreach ($indexes as $i) {
$rarray[] = $i;
}
}
@@ -744,4 +749,3 @@ function hmib_get_disk($host_index) {
}
}
}
-
diff --git a/snmp.php b/snmp.php
index be13e1d..c958554 100644
--- a/snmp.php
+++ b/snmp.php
@@ -27,12 +27,10 @@
define('SNMP_METHOD_PHP', 1);
define('SNMP_METHOD_BINARY', 2);
-if (!isset($banned_snmp_strings)) {
- $banned_snmp_strings = array(
+$banned_snmp_strings ??= [
'End of MIB',
'No Such'
- );
-}
+ ];
/* we must use an apostrophe to escape community names under Unix in case the user uses
characters that the shell might interpret. */
@@ -44,22 +42,24 @@
function cacti_snmp_get($hostname, $community, $oid, $version, $username, $password, $auth_proto, $priv_pass,
$priv_proto, $context, $port = 161, $timeout = 500, $retries = 0, $max_oids = 10, $method = SNMP_VALUE_LIBRARY, $environ = SNMP_POLLER) {
-
global $config, $snmp_errors;
- /* determine default retries */
+ // determine default retries
if (($retries == 0) || (!is_numeric($retries))) {
$retries = read_config_option('snmp_retries');
- if ($retries == '') $retries = 3;
+
+ if ($retries == '') {
+ $retries = 3;
+ }
}
- /* do not attempt to poll invalid combinations */
+ // do not attempt to poll invalid combinations
if (($version == 0) || (!is_numeric($version)) ||
(!is_numeric($port)) ||
(!is_numeric($retries)) ||
(!is_numeric($timeout)) ||
(($community == '') && ($version != 3))
- ) {
+ ) {
return 'U';
}
@@ -69,7 +69,7 @@ function cacti_snmp_get($hostname, $community, $oid, $version, $username, $passw
we are getting back */
snmp_set_quick_print(0);
- /* set the output format to numeric */
+ // set the output format to numeric
snmp_set_valueretrieval($method);
if ($version == '1') {
@@ -78,7 +78,7 @@ function cacti_snmp_get($hostname, $community, $oid, $version, $username, $passw
$snmp_value = @snmp2_get("$hostname:$port", $community, $oid, ($timeout * 1000), $retries);
} else {
if ($priv_proto == '[None]') {
- $proto = 'authNoPriv';
+ $proto = 'authNoPriv';
$priv_proto = '';
} else {
$proto = 'authPriv';
@@ -92,17 +92,17 @@ function cacti_snmp_get($hostname, $community, $oid, $version, $username, $passw
$snmp_errors++;
}
} else {
- /* ucd/net snmp want the timeout in seconds */
+ // ucd/net snmp want the timeout in seconds
$timeout = ceil($timeout / 1000);
if ($version == '1') {
- $snmp_auth = '-c ' . snmp_escape_string($community); /* v1/v2 - community string */
+ $snmp_auth = '-c ' . snmp_escape_string($community); // v1/v2 - community string
} elseif ($version == '2') {
- $snmp_auth = '-c ' . snmp_escape_string($community); /* v1/v2 - community string */
- $version = '2c'; /* ucd/net snmp prefers this over '2' */
+ $snmp_auth = '-c ' . snmp_escape_string($community); // v1/v2 - community string
+ $version = '2c'; // ucd/net snmp prefers this over '2'
} elseif ($version == '3') {
if ($priv_proto == '[None]') {
- $proto = 'authNoPriv';
+ $proto = 'authNoPriv';
$priv_proto = '';
} else {
$proto = 'authPriv';
@@ -124,22 +124,29 @@ function cacti_snmp_get($hostname, $community, $oid, $version, $username, $passw
' -l ' . snmp_escape_string($proto) .
' -a ' . snmp_escape_string($auth_proto) .
' -A ' . snmp_escape_string($password) .
- ' ' . $priv_pass .
- ' ' . $context); /* v3 - username/password */
+ ' ' . $priv_pass .
+ ' ' . $context); // v3 - username/password
}
- /* no valid snmp version has been set, get out */
- if (empty($snmp_auth)) { return; }
+ // no valid snmp version has been set, get out
+ if (empty($snmp_auth)) {
+ return;
+ }
+
+ // cast numeric args to int — prevents shell injection if the host record is tampered
+ $version = (int) $version;
+ $timeout = (int) $timeout;
+ $retries = (int) $retries;
exec(cacti_escapeshellcmd(read_config_option('path_snmpget')) . ' -O fntevU ' . $snmp_auth . " -v $version -t $timeout -r $retries " . cacti_escapeshellarg($hostname) . ":$port " . cacti_escapeshellarg($oid), $snmp_value);
- /* fix for multi-line snmp output */
+ // fix for multi-line snmp output
if (is_array($snmp_value)) {
$snmp_value = implode(' ', $snmp_value);
}
}
- /* fix for multi-line snmp output */
+ // fix for multi-line snmp output
if (isset($snmp_value)) {
if (is_array($snmp_value)) {
$snmp_value = implode(' ', $snmp_value);
@@ -151,7 +158,7 @@ function cacti_snmp_get($hostname, $community, $oid, $version, $username, $passw
$snmp_errors++;
}
- /* strip out non-snmp data */
+ // strip out non-snmp data
$snmp_value = format_snmp_string($snmp_value, false);
return $snmp_value;
@@ -160,19 +167,22 @@ function cacti_snmp_get($hostname, $community, $oid, $version, $username, $passw
function cacti_snmp_getnext($hostname, $community, $oid, $version, $username, $password, $auth_proto, $priv_pass, $priv_proto, $context, $port = 161, $timeout = 500, $retries = 0, $method = SNMP_VALUE_LIBRARY, $environ = SNMP_POLLER) {
global $config, $snmp_errors;
- /* determine default retries */
+ // determine default retries
if (($retries == 0) || (!is_numeric($retries))) {
$retries = read_config_option('snmp_retries');
- if ($retries == '') $retries = 3;
+
+ if ($retries == '') {
+ $retries = 3;
+ }
}
- /* do not attempt to poll invalid combinations */
+ // do not attempt to poll invalid combinations
if (($version == 0) || (!is_numeric($version)) ||
(!is_numeric($port)) ||
(!is_numeric($retries)) ||
(!is_numeric($timeout)) ||
(($community == '') && ($version != 3))
- ) {
+ ) {
return 'U';
}
@@ -182,7 +192,7 @@ function cacti_snmp_getnext($hostname, $community, $oid, $version, $username, $p
we are getting back */
snmp_set_quick_print(0);
- /* set the output format to numeric */
+ // set the output format to numeric
snmp_set_valueretrieval($method);
if ($version == '1') {
@@ -191,7 +201,7 @@ function cacti_snmp_getnext($hostname, $community, $oid, $version, $username, $p
$snmp_value = @snmp2_getnext("$hostname:$port", $community, $oid, ($timeout * 1000), $retries);
} else {
if ($priv_proto == '[None]') {
- $proto = 'authNoPriv';
+ $proto = 'authNoPriv';
$priv_proto = '';
} else {
$proto = 'authPriv';
@@ -205,17 +215,17 @@ function cacti_snmp_getnext($hostname, $community, $oid, $version, $username, $p
$snmp_errors++;
}
} else {
- /* ucd/net snmp want the timeout in seconds */
+ // ucd/net snmp want the timeout in seconds
$timeout = ceil($timeout / 1000);
if ($version == '1') {
- $snmp_auth = '-c ' . snmp_escape_string($community); /* v1/v2 - community string */
+ $snmp_auth = '-c ' . snmp_escape_string($community); // v1/v2 - community string
} elseif ($version == '2') {
- $snmp_auth = '-c ' . snmp_escape_string($community); /* v1/v2 - community string */
- $version = '2c'; /* ucd/net snmp prefers this over '2' */
+ $snmp_auth = '-c ' . snmp_escape_string($community); // v1/v2 - community string
+ $version = '2c'; // ucd/net snmp prefers this over '2'
} elseif ($version == '3') {
if ($priv_proto == '[None]') {
- $proto = 'authNoPriv';
+ $proto = 'authNoPriv';
$priv_proto = '';
} else {
$proto = 'authPriv';
@@ -237,18 +247,20 @@ function cacti_snmp_getnext($hostname, $community, $oid, $version, $username, $p
' -l ' . snmp_escape_string($proto) .
' -a ' . snmp_escape_string($auth_proto) .
' -A ' . snmp_escape_string($password) .
- ' ' . $priv_pass .
- ' ' . $context); /* v3 - username/password */
+ ' ' . $priv_pass .
+ ' ' . $context); // v3 - username/password
}
- /* no valid snmp version has been set, get out */
- if (empty($snmp_auth)) { return; }
+ // no valid snmp version has been set, get out
+ if (empty($snmp_auth)) {
+ return;
+ }
exec(cacti_escapeshellcmd(read_config_option('path_snmpgetnext')) . " -O fntevU $snmp_auth -v $version -t $timeout -r $retries " . cacti_escapeshellarg($hostname) . ":$port " . cacti_escapeshellarg($oid), $snmp_value);
}
if (isset($snmp_value)) {
- /* fix for multi-line snmp output */
+ // fix for multi-line snmp output
if (is_array($snmp_value)) {
$snmp_value = implode(' ', $snmp_value);
}
@@ -259,7 +271,7 @@ function cacti_snmp_getnext($hostname, $community, $oid, $version, $username, $p
$snmp_errors++;
}
- /* strip out non-snmp data */
+ // strip out non-snmp data
$snmp_value = format_snmp_string($snmp_value, false);
return $snmp_value;
@@ -269,25 +281,28 @@ function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $pass
global $config, $banned_snmp_strings, $snmp_errors;
$snmp_oid_included = true;
- $snmp_auth = '';
- $snmp_array = array();
- $temp_array = array();
+ $snmp_auth = '';
+ $snmp_array = [];
+ $temp_array = [];
- /* determine default retries */
+ // determine default retries
if (($retries == 0) || (!is_numeric($retries))) {
$retries = read_config_option('snmp_retries');
- if ($retries == '') $retries = 3;
+
+ if ($retries == '') {
+ $retries = 3;
+ }
}
- /* do not attempt to poll invalid combinations */
+ // do not attempt to poll invalid combinations
if (($version == 0) || (!is_numeric($version)) ||
(!is_numeric($max_oids)) ||
(!is_numeric($port)) ||
(!is_numeric($retries)) ||
(!is_numeric($timeout)) ||
(($community == '') && ($version != 3))
- ) {
- return array();
+ ) {
+ return [];
}
$path_snmpbulkwalk = read_config_option('path_snmpbulkwalk');
@@ -300,12 +315,12 @@ function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $pass
/* make sure snmp* is verbose so we can see what types of data
we are getting back */
- /* force php to return numeric oid's */
+ // force php to return numeric oid's
cacti_oid_numeric_format();
snmp_set_quick_print(0);
- /* set the output format to numeric */
+ // set the output format to numeric
snmp_set_valueretrieval($method);
if ($version == '1') {
@@ -314,7 +329,7 @@ function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $pass
$temp_array = @snmp2_real_walk("$hostname:$port", $community, $oid, ($timeout * 1000), $retries);
} else {
if ($priv_proto == '[None]') {
- $proto = 'authNoPriv';
+ $proto = 'authNoPriv';
$priv_proto = '';
} else {
$proto = 'authPriv';
@@ -328,38 +343,40 @@ function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $pass
$snmp_errors++;
}
- /* check for bad entries */
+ // check for bad entries
if (is_array($temp_array) && sizeof($temp_array)) {
- foreach($temp_array as $key => $value) {
- foreach($banned_snmp_strings as $item) {
+ foreach ($temp_array as $key => $value) {
+ foreach ($banned_snmp_strings as $item) {
if (strstr($value, $item) != '') {
unset($temp_array[$key]);
+
continue 2;
}
}
}
$o = 0;
+
for (reset($temp_array); $i = key($temp_array); next($temp_array)) {
if ($temp_array[$i] != 'NULL') {
- $snmp_array[$o]['oid'] = preg_replace('/^\./', '', $i);
+ $snmp_array[$o]['oid'] = preg_replace('/^\./', '', $i);
$snmp_array[$o]['value'] = format_snmp_string($temp_array[$i], $snmp_oid_included);
}
$o++;
}
}
} else {
- /* ucd/net snmp want the timeout in seconds */
+ // ucd/net snmp want the timeout in seconds
$timeout = ceil($timeout / 1000);
if ($version == '1') {
- $snmp_auth = '-c ' . snmp_escape_string($community); /* v1/v2 - community string */
+ $snmp_auth = '-c ' . snmp_escape_string($community); // v1/v2 - community string
} elseif ($version == '2') {
- $snmp_auth = '-c ' . snmp_escape_string($community); /* v1/v2 - community string */
- $version = '2c'; /* ucd/net snmp prefers this over '2' */
+ $snmp_auth = '-c ' . snmp_escape_string($community); // v1/v2 - community string
+ $version = '2c'; // ucd/net snmp prefers this over '2'
} elseif ($version == '3') {
if ($priv_proto == '[None]') {
- $proto = 'authNoPriv';
+ $proto = 'authNoPriv';
$priv_proto = '';
} else {
$proto = 'authPriv';
@@ -381,8 +398,8 @@ function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $pass
' -l ' . snmp_escape_string($proto) .
' -a ' . snmp_escape_string($auth_proto) .
' -A ' . snmp_escape_string($password) .
- ' ' . $priv_pass .
- ' ' . $context); /* v3 - username/password */
+ ' ' . $priv_pass .
+ ' ' . $context); // v3 - username/password
}
if (file_exists($path_snmpbulkwalk) && ($version > 1) && ($max_oids > 1)) {
@@ -396,20 +413,21 @@ function cacti_snmp_walk($hostname, $community, $oid, $version, $username, $pass
$snmp_errors++;
}
- /* check for bad entries */
+ // check for bad entries
if (is_array($temp_array) && sizeof($temp_array)) {
- foreach($temp_array as $key => $value) {
- foreach($banned_snmp_strings as $item) {
+ foreach ($temp_array as $key => $value) {
+ foreach ($banned_snmp_strings as $item) {
if (strstr($value, $item) != '') {
unset($temp_array[$key]);
+
continue 2;
}
}
}
- for ($i=0; $i < count($temp_array); $i++) {
+ for ($i = 0; $i < count($temp_array); $i++) {
if ($temp_array[$i] != 'NULL') {
- $snmp_array[$i]['oid'] = trim(preg_replace('/(.*) =.*/', "\\1", $temp_array[$i]));
+ $snmp_array[$i]['oid'] = trim(preg_replace('/(.*) =.*/', '\\1', $temp_array[$i]));
$snmp_array[$i]['value'] = format_snmp_string($temp_array[$i], true);
}
}
@@ -429,13 +447,14 @@ function format_snmp_string($string, $snmp_oid_included) {
}
if ($snmp_oid_included) {
- /* strip off all leading junk (the oid and stuff) */
+ // strip off all leading junk (the oid and stuff)
$string_array = explode('=', $string);
+
if (cacti_sizeof($string_array) == 1) {
- /* trim excess first */
+ // trim excess first
$string = trim($string);
} elseif ((substr($string, 0, 1) == '.') || (strpos($string, '::') !== false)) {
- /* drop the OID from the array */
+ // drop the OID from the array
array_shift($string_array);
$string = trim(implode('=', $string_array));
} else {
@@ -443,17 +462,19 @@ function format_snmp_string($string, $snmp_oid_included) {
}
}
- /* trim quoting and other oddities */
+ // trim quoting and other oddities
$string = trim($string, " \r\n\0\x0B\t\"'");
- /* search for a hex string */
+ // search for a hex string
if (substr_count($string, ':')) {
$newstr = '';
$fail = false;
$pieces = explode(':', $string);
- foreach($pieces AS $p) {
+
+ foreach ($pieces as $p) {
if (!preg_match('/^[0-9a-fA-F]{1,2}$/',$p)) {
$fail = true;
+
break;
}
$newstr .= chr(hexdec($p));
@@ -464,19 +485,20 @@ function format_snmp_string($string, $snmp_oid_included) {
}
}
- /* return the easiest value */
+ // return the easiest value
if ($string == '') {
return $string;
}
- /* now check for the second most obvious */
+ // now check for the second most obvious
if (is_numeric($string)) {
return trim($string);
}
- /* account for invalid MIB files */
+ // account for invalid MIB files
if (substr_count($string, 'Wrong Type')) {
$string = strrev($string);
+
if ($position = strpos($string, ':')) {
$string = trim(strrev(substr($string, 0, $position)));
} else {
@@ -484,9 +506,10 @@ function format_snmp_string($string, $snmp_oid_included) {
}
}
- /* Remove invalid chars */
+ // Remove invalid chars
$k = strlen($string);
- for ($i=0; $i < $k; $i++) {
+
+ for ($i = 0; $i < $k; $i++) {
if ((ord($string[$i]) <= 31) || (ord($string[$i]) >= 127)) {
$string[$i] = ' ';
}
@@ -496,30 +519,31 @@ function format_snmp_string($string, $snmp_oid_included) {
if ((substr_count($string, 'Hex-STRING:')) ||
(substr_count($string, 'Hex-')) ||
(substr_count($string, 'Hex:'))) {
- /* strip of the 'Hex-STRING:' */
+ // strip of the 'Hex-STRING:'
$string = preg_replace('/Hex-STRING: ?/i', '', $string);
$string = preg_replace('/Hex: ?/i', '', $string);
$string = preg_replace('/Hex- ?/i', '', $string);
$string_array = explode(' ', $string);
- /* loop through each string character and make ascii */
+ // loop through each string character and make ascii
$string = '';
$hexval = '';
$ishex = false;
- for ($i=0;($i= 127)) {
- if ((($i+1) == sizeof($string_array)) && ($string_array[$i] == 0)) {
- /* do nothing */
+ if ((($i + 1) == sizeof($string_array)) && ($string_array[$i] == 0)) {
+ // do nothing
} else {
$ishex = true;
}
@@ -527,34 +551,37 @@ function format_snmp_string($string, $snmp_oid_included) {
}
}
- if ($ishex) $string = $hexval;
+ if ($ishex) {
+ $string = $hexval;
+ }
} elseif (preg_match("/(hex:\?)?([a-fA-F0-9]{1,2}(:|\s)) {5}/", $string)) {
$octet = '';
- /* strip of the 'hex:' */
+ // strip of the 'hex:'
$string = preg_replace('/hex: ?/i', '', $string);
- /* split the hex on the delimiter */
+ // split the hex on the delimiter
$octets = preg_split('/\s|:/', $string);
- /* loop through each octet and format it accordingly */
- for ($i=0;($i^()[]{}$\\";
+ $replacements = '#&;`|*?<>^()[]{}$\\';
- for ($i=0; $i < strlen($replacements); $i++) {
+ for ($i = 0; $i < strlen($replacements); $i++) {
$string = str_replace($replacements[$i], ' ', $string);
}
@@ -38,36 +38,36 @@ function cacti_escapeshellcmd($string) {
}
}
-
/**
* mimics escapeshellarg, even for windows
- * @param $string - the string to be escaped
- * @param $quote - true: do NOT remove quotes from result; false: do remove quotes
- * @return - the escaped [quoted|unquoted] string
+ * @param $string - the string to be escaped
+ * @param $quote - true: do NOT remove quotes from result; false: do remove quotes
+ * @return - the escaped [quoted|unquoted] string
*/
-function cacti_escapeshellarg($string, $quote=true) {
+function cacti_escapeshellarg($string, $quote = true) {
global $config;
+
/* we must use an apostrophe to escape community names under Unix in case the user uses
characters that the shell might interpret. the ucd-snmp binaries on Windows flip out when
you do this, but are perfectly happy with a quotation mark. */
if ($config['cacti_server_os'] == 'unix') {
$string = escapeshellarg($string);
+
if ($quote) {
return $string;
} else {
- # remove first and last char
- return substr($string, 1, (strlen($string)-2));
+ // remove first and last char
+ return substr($string, 1, (strlen($string) - 2));
}
} else {
if (substr_count($string, CACTI_ESCAPE_CHARACTER)) {
- $string = str_replace(CACTI_ESCAPE_CHARACTER, "\\" . CACTI_ESCAPE_CHARACTER, $string);
+ $string = str_replace(CACTI_ESCAPE_CHARACTER, '\\' . CACTI_ESCAPE_CHARACTER, $string);
}
- if ( $quote ) {
+ if ($quote) {
return CACTI_ESCAPE_CHARACTER . $string . CACTI_ESCAPE_CHARACTER;
} else {
return $string;
}
}
}
-
diff --git a/templates/index.php b/templates/index.php
index b974c41..828ecbe 100644
--- a/templates/index.php
+++ b/templates/index.php
@@ -22,5 +22,4 @@
+-------------------------------------------------------------------------+
*/
-header("Location:../index.php");
-
+header('Location:../index.php');
diff --git a/tests/Integration/test_hmib_filter_output_wiring.php b/tests/Integration/test_hmib_filter_output_wiring.php
new file mode 100644
index 0000000..9c761aa
--- /dev/null
+++ b/tests/Integration/test_hmib_filter_output_wiring.php
@@ -0,0 +1,30 @@
+' . \$h['description'] . ''",
+ ". '>' . \$t['description'] . ''",
+];
+
+foreach ($forbidden as $pattern) {
+ if (strpos($contents, $pattern) !== false) {
+ fwrite(STDERR, "Raw option label output remains: {$pattern}\n");
+ exit(1);
+ }
+}
+
+print "OK\n";