Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
261 changes: 261 additions & 0 deletions .github/workflows/plugin-ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
# +-------------------------------------------------------------------------+
# | 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. |
# +-------------------------------------------------------------------------+

name: Plugin Integration Tests

on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

env:
CACTI: 1.2.x

jobs:
integration-test:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
php: ['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
ref: ${{ env.CACTI }}
path: cacti

- name: Checkout flowview Plugin
uses: actions/checkout@v4
with:
path: cacti/plugins/flowview

- 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, snmp
ini-values: "post_max_size=256M, max_execution_time=60, date.timezone=America/New_York"
Comment on lines +70 to +71

- 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 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
composer config --no-plugins allow-plugins.pestphp/pest-plugin true
composer require --dev --no-progress --no-interaction "pestphp/pest: ^3" "pestphp/pest-plugin-drift: ^3.0"
rm -f composer.lock
composer install --dev --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
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot GITHUB_WORKSPACE/cacti

<Directory GITHUB_WORKSPACE/cacti>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
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 flowview Plugin
run: |
cd ${{ github.workspace }}/cacti
sudo php cli/plugin_manage.php --plugin=flowview --install --enable
Comment on lines +163 to +166

- name: Check PHP Syntax for Plugin
run: |
cd ${{ github.workspace }}/cacti/plugins/flowview
if find . -name '*.php' -exec php -l {} 2>&1 \; | grep -iv 'no syntax errors detected'; then
echo "Syntax errors found!"
exit 1
fi

- name: Set expected Cacti version for unit tests
run: echo -n "${{ env.CACTI }}" | sudo tee ${{ github.workspace }}/cacti/plugins/flowview/tests/.cacti-version > /dev/null

- name: Run Pest Unit Tests
env:
COMPOSER_ROOT_VERSION: 1.3.0-dev
run: |
cd ${{ github.workspace }}/cacti
include/vendor/bin/pest --configuration=plugins/flowview/phpunit.xml \
--coverage-clover=plugins/flowview/coverage/clover.xml \
plugins/flowview/tests/Security plugins/flowview/tests/Unit

- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-php${{ matrix.php }}
path: ${{ github.workspace }}/cacti/plugins/flowview/coverage/
if-no-files-found: warn

- name: Remove the plugins directory exclusion from the .phpstan.neon
if: ${{ env.CACTI != '1.2.x' }}
run: sed '/plugins/d' -i .phpstan.neon
working-directory: ${{ github.workspace }}/cacti

- name: Mark composer scripts executable
if: ${{ env.CACTI != '1.2.x' }}
run: sudo chmod +x ${{ github.workspace }}/cacti/include/vendor/bin/*
working-directory: ${{ github.workspace }}/cacti

- name: Run Linter on base code
if: ${{ env.CACTI != '1.2.x' }}
run: composer run-script lint ${{ github.workspace }}/cacti/plugins/flowview
working-directory: ${{ github.workspace }}/cacti

- name: Checking coding standards on base code
if: ${{ env.CACTI != '1.2.x' }}
run: composer run-script phpcsfixer ${{ github.workspace }}/cacti/plugins/flowview
working-directory: ${{ github.workspace }}/cacti

- name: Run PHPStan at Level 6 on base code outside of Composer due to technical issues
if: ${{ env.CACTI != '1.2.x' }}
run: ./include/vendor/bin/phpstan analyze --level 6 ${{ github.workspace }}/cacti/plugins/flowview
working-directory: ${{ github.workspace }}/cacti

- name: Re-apply web user ownership before polling
run: |
p="${{ github.workspace }}"
while [ "$p" != "/" ]; do
sudo chmod o+x "$p" || true
p=$(dirname "$p")
done
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: Run Cacti Poller
run: |
cd ${{ github.workspace }}/cacti
sudo -u www-data 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

- name: Check Cacti Logs for Errors
if: always()
run: |
if [ -f ${{ github.workspace }}/cacti/log/cacti.log ]; then
if grep -E "FATAL:|ERROR:|WARNING:" ${{ github.workspace }}/cacti/log/cacti.log; then
echo "Found FATAL/ERROR/WARNING entries in Cacti log"
exit 1
fi
fi
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
# +-------------------------------------------------------------------------+

.git*
!.github/
!.github/workflows/
!.github/workflows/*.yml
.phpunit.result.cache
.phpunit.cache/
coverage/
config.php
locales/po/*.mo
.omc/
7 changes: 4 additions & 3 deletions database.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,10 @@ function flowview_sql_save($array_items, $table_name, $key_cols = 'id', $autoinc
function flowview_db_table_exists($table, $log = true, $cnn_id = false) {
$flowview_cnn = flowview_get_connection($cnn_id);

preg_match("/([`]{0,1}(?<database>[\w_]+)[`]{0,1}\.){0,1}[`]{0,1}(?<table>[\w_]+)[`]{0,1}/", $table, $matches);
if ($matches !== false && array_key_exists('table', $matches)) {
$sql = 'SHOW TABLES LIKE \'' . $matches['table'] . '\'';
$matched = preg_match('/^(?:`?(?<database>[A-Za-z0-9_]+)`?\.)?`?(?<table>[A-Za-z0-9_]+)`?$/D', $table, $matches);
if ($matched === 1) {
$table_pattern = addcslashes($matches['table'], '\\%_');
Comment on lines +244 to +246
$sql = 'SHOW TABLES LIKE \'' . $table_pattern . '\'';

return (db_fetch_cell($sql, '', $log, $flowview_cnn) ? true : false);
}
Expand Down
Loading
Loading