Skip to content

Commit cf91d42

Browse files
authored
Create CI flow for Syslog (#245)
* agents * Update copilot-instructions.md * correct filename spelling * Move agents folder to proper place * add gha * Update codeql.yml * rename file * Create php-lint.yml * Update phpstan.yml * Update php-lint.yml * . * . * Update install-syslog-cacti.yml * Update populate_syslog_incoming.sh * . * Update install-syslog-cacti.yml * rename file prepare for PR * Update populate_syslog_incoming.sh * add removal and alert rules * add output for tracing * Update plugin-ci-workflow.yml * Update plugin-ci-workflow.yml * Update plugin-ci-workflow.yml
1 parent a45260c commit cf91d42

File tree

2 files changed

+316
-0
lines changed

2 files changed

+316
-0
lines changed
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
# +-------------------------------------------------------------------------+
2+
# | Copyright (C) 2004-2025 The Cacti Group |
3+
# | |
4+
# | This program is free software; you can redistribute it and/or |
5+
# | modify it under the terms of the GNU General Public License |
6+
# | as published by the Free Software Foundation; either version 2 |
7+
# | of the License, or (at your option) any later version. |
8+
# | |
9+
# | This program is distributed in the hope that it will be useful, |
10+
# | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11+
# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12+
# | GNU General Public License for more details. |
13+
# +-------------------------------------------------------------------------+
14+
# | Cacti: The Complete RRDtool-based Graphing Solution |
15+
# +-------------------------------------------------------------------------+
16+
# | This code is designed, written, and maintained by the Cacti Group. See |
17+
# | about.php and/or the AUTHORS file for specific developer information. |
18+
# +-------------------------------------------------------------------------+
19+
# | http://www.cacti.net/ |
20+
# +-------------------------------------------------------------------------+
21+
22+
name: Plugin Integration Tests
23+
24+
on:
25+
push:
26+
branches:
27+
- main
28+
- develop
29+
pull_request:
30+
branches:
31+
- main
32+
- develop
33+
34+
jobs:
35+
integration-test:
36+
runs-on: ${{ matrix.os }}
37+
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
php: ['8.1', '8.2', '8.3']
42+
os: [ubuntu-latest]
43+
44+
services:
45+
mysql:
46+
image: mysql:8.0
47+
env:
48+
MYSQL_ROOT_PASSWORD: cactiroot
49+
MYSQL_DATABASE: cacti
50+
MYSQL_USER: cactiuser
51+
MYSQL_PASSWORD: cactiuser
52+
ports:
53+
- 3306:3306
54+
options: >-
55+
--health-cmd="mysqladmin ping"
56+
--health-interval=10s
57+
--health-timeout=5s
58+
--health-retries=3
59+
60+
name: PHP ${{ matrix.php }} Integration Test on ${{ matrix.os }}
61+
62+
steps:
63+
- name: Checkout Cacti
64+
uses: actions/checkout@v4
65+
with:
66+
repository: Cacti/cacti
67+
path: cacti
68+
69+
- name: Checkout Syslog Plugin
70+
uses: actions/checkout@v4
71+
with:
72+
path: cacti/plugins/syslog
73+
74+
- name: Install PHP ${{ matrix.php }}
75+
uses: shivammathur/setup-php@v2
76+
with:
77+
php-version: ${{ matrix.php }}
78+
extensions: intl, mysql, gd, ldap, gmp, xml, curl, json, mbstring
79+
ini-values: "post_max_size=256M, max_execution_time=60, date.timezone=America/New_York"
80+
81+
- name: Check PHP version
82+
run: php -v
83+
84+
85+
- name: Run apt-get update
86+
run: sudo apt-get update
87+
88+
- name: Install System Dependencies
89+
run: sudo apt-get install -y apache2 snmp snmpd rrdtool fping libapache2-mod-php${{ matrix.php }}
90+
91+
- name: Start SNMPD Agent and Test
92+
run: |
93+
sudo systemctl start snmpd
94+
sudo snmpwalk -c public -v2c -On localhost .1.3.6.1.2.1.1
95+
96+
- name: Setup Permissions
97+
run: |
98+
sudo chown -R www-data:runner ${{ github.workspace }}/cacti
99+
sudo find ${{ github.workspace }}/cacti -type d -exec chmod 775 {} \;
100+
sudo find ${{ github.workspace }}/cacti -type f -exec chmod 664 {} \;
101+
sudo chmod +x ${{ github.workspace }}/cacti/cmd.php
102+
sudo chmod +x ${{ github.workspace }}/cacti/poller.php
103+
104+
- name: Create MySQL Config
105+
run: |
106+
echo -e "[client]\nuser = root\npassword = cactiroot\nhost = 127.0.0.1\n" > ~/.my.cnf
107+
cat ~/.my.cnf
108+
109+
- name: Initialize Cacti Database
110+
env:
111+
MYSQL_AUTH_USR: '--defaults-file=~/.my.cnf'
112+
run: |
113+
mysql $MYSQL_AUTH_USR -e 'CREATE DATABASE IF NOT EXISTS cacti;'
114+
mysql $MYSQL_AUTH_USR -e "CREATE USER IF NOT EXISTS 'cactiuser'@'localhost' IDENTIFIED BY 'cactiuser';"
115+
mysql $MYSQL_AUTH_USR -e "GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost';"
116+
mysql $MYSQL_AUTH_USR -e "GRANT SELECT ON mysql.time_zone_name TO 'cactiuser'@'localhost';"
117+
mysql $MYSQL_AUTH_USR -e "FLUSH PRIVILEGES;"
118+
mysql $MYSQL_AUTH_USR cacti < ${{ github.workspace }}/cacti/cacti.sql
119+
mysql $MYSQL_AUTH_USR -e "INSERT INTO settings (name, value) VALUES ('path_php_binary', '/usr/bin/php')" cacti
120+
121+
- name: Validate composer files
122+
run: |
123+
cd ${{ github.workspace }}/cacti
124+
if [ -f composer.json ]; then
125+
composer validate --strict || true
126+
fi
127+
128+
- name: Install Composer Dependencies
129+
run: |
130+
cd ${{ github.workspace }}/cacti
131+
if [ -f composer.json ]; then
132+
sudo composer install --prefer-dist --no-progress
133+
fi
134+
135+
- name: Create Cacti config.php
136+
run: |
137+
cat ${{ github.workspace }}/cacti/include/config.php.dist | \
138+
sed -r "s/localhost/127.0.0.1/g" | \
139+
sed -r "s/'cacti'/'cacti'/g" | \
140+
sed -r "s/'cactiuser'/'cactiuser'/g" | \
141+
sed -r "s/'cactiuser'/'cactiuser'/g" > ${{ github.workspace }}/cacti/include/config.php
142+
sudo chmod 664 ${{ github.workspace }}/cacti/include/config.php
143+
144+
- name: Create Syslog Plugin config.php
145+
run: |
146+
cp ${{ github.workspace }}/cacti/plugins/syslog/config.php.dist ${{ github.workspace }}/cacti/plugins/syslog/config.php
147+
sed -i "s/localhost/127.0.0.1/g" ${{ github.workspace }}/cacti/plugins/syslog/config.php
148+
sed -i "s/'cacti'/'cacti'/g" ${{ github.workspace }}/cacti/plugins/syslog/config.php
149+
sed -i "s/'cactiuser'/'cactiuser'/g" ${{ github.workspace }}/cacti/plugins/syslog/config.php
150+
sed -i 's/\/\/\$/\$/g' ${{ github.workspace }}/cacti/plugins/syslog/config.php
151+
sudo chmod 664 ${{ github.workspace }}/cacti/plugins/syslog/config.php
152+
153+
- name: Configure Apache
154+
run: |
155+
cat << 'EOF' | sed 's#GITHUB_WORKSPACE#${{ github.workspace }}#g' > /tmp/cacti.conf
156+
<VirtualHost *:80>
157+
ServerAdmin webmaster@localhost
158+
DocumentRoot GITHUB_WORKSPACE/cacti
159+
160+
<Directory GITHUB_WORKSPACE/cacti>
161+
Options Indexes FollowSymLinks
162+
AllowOverride All
163+
Require all granted
164+
</Directory>
165+
166+
ErrorLog ${APACHE_LOG_DIR}/error.log
167+
CustomLog ${APACHE_LOG_DIR}/access.log combined
168+
</VirtualHost>
169+
EOF
170+
sudo cp /tmp/cacti.conf /etc/apache2/sites-available/000-default.conf
171+
sudo systemctl restart apache2
172+
173+
- name: Install Cacti via CLI
174+
run: |
175+
cd ${{ github.workspace }}/cacti
176+
sudo php cli/install_cacti.php --accept-eula --install --force
177+
178+
- name: Install Syslog Plugin
179+
run: |
180+
cd ${{ github.workspace }}/cacti
181+
sudo php cli/plugin_manage.php --plugin=syslog --install --enable
182+
183+
- name: Check PHP Syntax for Plugin
184+
run: |
185+
cd ${{ github.workspace }}/cacti/plugins/syslog
186+
if find . -name '*.php' -exec php -l {} 2>&1 \; | grep -iv 'no syntax errors detected'; then
187+
echo "Syntax errors found!"
188+
exit 1
189+
fi
190+
191+
192+
- name: Run Cacti Poller
193+
run: |
194+
cd ${{ github.workspace }}/cacti
195+
sudo php poller.php --poller=1 --force --debug
196+
if ! grep -q "SYSTEM STATS" log/cacti.log; then
197+
echo "Cacti poller did not finish successfully"
198+
cat log/cacti.log
199+
exit 1
200+
fi
201+
202+
- name: Populate Syslog Test Data
203+
run: |
204+
sudo chmod +x ${{ github.workspace }}/cacti/plugins/syslog/.github/workflows/populate_syslog_incoming.sh
205+
cd ${{ github.workspace }}/cacti/plugins/syslog/.github/workflows
206+
sudo ./populate_syslog_incoming.sh
207+
208+
209+
- name: force Syslog Plugin Poller
210+
run: |
211+
cd ${{ github.workspace }}/cacti
212+
sudo php plugins/syslog/syslog_process.php --debug
213+
if ! grep -q "SYSTEM SYSLOG STATS" log/cacti.log; then
214+
echo "Syslog plugin poller did not finish successfully"
215+
cat log/cacti.log
216+
exit 1
217+
fi
218+
219+
220+
- name: View Cacti Logs
221+
if: always()
222+
run: |
223+
if [ -f ${{ github.workspace }}/cacti/log/cacti.log ]; then
224+
echo "=== Cacti Log ==="
225+
sudo cat ${{ github.workspace }}/cacti/log/cacti.log
226+
fi
227+
228+
229+
- name: Create PHPStan config
230+
run: |
231+
cd ${{ github.workspace }}/cacti/plugins/syslog
232+
cat > phpstan.neon << 'EOF'
233+
parameters:
234+
level: 5
235+
paths:
236+
- .
237+
excludePaths:
238+
- vendor/
239+
- locales/
240+
ignoreErrors:
241+
- '#has invalid return type the\.#'
242+
bootstrapFiles:
243+
- ../../include/global.php
244+
EOF
245+
246+
- name: Install PHPStan
247+
run: |
248+
cd ${{ github.workspace }}/cacti/plugins/syslog
249+
composer require --dev phpstan/phpstan --with-all-dependencies || composer global require phpstan/phpstan
250+
251+
- name: Run PHPStan Analysis
252+
run: |
253+
cd ${{ github.workspace }}/cacti/plugins/syslog
254+
if [ -f vendor/bin/phpstan ]; then
255+
vendor/bin/phpstan analyse --no-progress --error-format=github || true
256+
else
257+
phpstan analyse --no-progress --error-format=github || true
258+
fi
259+
continue-on-error: true
260+
261+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
# filepath: insert_syslog_test_data.sh
3+
4+
# Number of iterations
5+
ITERATIONS=100
6+
7+
8+
SQL_ALERT_RULE_INSERT="INSERT INTO syslog_alert (id,hash,name,severity,method,level,num,type,enabled,repeat_alert,open_ticket,message,body,user,date,email,notify,command,notes)
9+
VALUES (1,'8f440030d3425e37cb66e5df54902bb0','interface down alert',1,0,1,1,'messageb','on',0,'','interface down','admin',1767376990,NULL,0,NULL,NULL);"
10+
11+
SQL_REMOVAL_RULE_INSERT="INSERT INTO syslog_remove (id,hash,name,type,enabled,method,message,user,date,notes)
12+
VALUES (1,'0faf589f7b6b7da1bcec40b92340487d','exploded','messageb','on','del',
13+
'the box exploded','admin',1767376604,NULL);"
14+
15+
16+
SYSLOG_EVENTS_INSERT="INSERT INTO syslog_incoming (facility_id, priority_id, program, logtime, host, message, status) VALUES
17+
(1, 1, 'app1', NOW(), 'bob', 'interface down', 0),
18+
(2, 3, 'app2', NOW(), 'alice', 'cpu high', 1),
19+
(1, 2, 'app1', NOW(), 'router_1', 'the box exploded', 0);"
20+
21+
22+
echo "Starting insert of $ITERATIONS batches (30,000 total records)..."
23+
echo "Start time: $(date)"
24+
25+
# MySQL connection parameters
26+
export MYSQL_PWD="cactiuser"
27+
MYSQL_CMD="mysql -h 127.0.0.1 -u cactiuser cacti"
28+
29+
# Create Rules
30+
31+
echo "Creating alert and removal rules..."
32+
$MYSQL_CMD -e "$SQL_ALERT_RULE_INSERT"
33+
34+
echo "Creating removal rule..."
35+
$MYSQL_CMD -e "$SQL_REMOVAL_RULE_INSERT"
36+
37+
38+
# Create test syslog events
39+
for i in $(seq 1 $ITERATIONS); do
40+
$MYSQL_CMD -e "$SYSLOG_EVENTS_INSERT"
41+
42+
# Show progress every 100 iterations
43+
if [ $((i % 100)) -eq 0 ]; then
44+
echo "Progress: $i / $ITERATIONS batches inserted"
45+
fi
46+
done
47+
48+
49+
echo "Completed!"
50+
echo "End time: $(date)"
51+
echo "Total records inserted: $((ITERATIONS * 3))"
52+
53+
# Verify insertion
54+
echo "Verifying record count:"
55+
$MYSQL_CMD -e "SELECT COUNT(*) as total_records FROM syslog_incoming;"

0 commit comments

Comments
 (0)