Skip to content

Commit ec9dfdb

Browse files
bmfmanciniCopilotCopilot
authored
Fix for 723 (#735)
* Agents for Github * Ci workflow * fix syntax * Update plugin-ci-workflow.yml * Update agent tools * Initial plan * Fix PHP 8+ type coercion error in pagination calculations Co-authored-by: bmfmancini <13388748+bmfmancini@users.noreply.github.com> * Update .github/workflows/plugin-ci-workflow.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bmfmancini <13388748+bmfmancini@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e8a604e commit ec9dfdb

File tree

10 files changed

+306
-13
lines changed

10 files changed

+306
-13
lines changed

.github/agents/code-quality.agent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "This Custom agent acts as a quality assurance specialist, focusing on code quality, best practices, and maintainability."
33
name: "Code Quality Specialist"
4-
tools: ["search/codebase", "edit/editFiles", "web/githubRepo", "vscode/extensions", "execute/getTerminalOutput", "web"]
4+
tools: ['vscode/extensions', 'execute/testFailure', 'execute/getTerminalOutput', 'execute/getTaskOutput', 'execute/runInTerminal', 'execute/runTests', 'read', 'edit/createFile', 'edit/editFiles', 'search', 'web']
55
model: "Claude Sonnet 4.5"
66
---
77

.github/agents/mysql-mariadb.agent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "This custom agent assits with enhancements, troubleshooting, and management of MySQL and MariaDB databases."
33
name: "MySQL/ MariaDB Database Administrator"
4-
tools: ["search/codebase", "edit/editFiles", "web/githubRepo", "vscode/extensions", "execute/getTerminalOutput", "web"]
4+
tools: ['vscode/extensions', 'execute/testFailure', 'execute/getTerminalOutput', 'execute/getTaskOutput', 'execute/runInTerminal', 'execute/runTests', 'read', 'edit/createFile', 'edit/editFiles', 'search', 'web']
55
model: "Claude Sonnet 4.5"
66
---
77

.github/agents/php-devloper.agent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "This custom agent acts as a PHP developer, assisting with PHP code development, debugging, and optimization."
33
name: "PHP Developer"
4-
tools: ["search/codebase", "edit/editFiles", "web/githubRepo", "vscode/extensions", "execute/getTerminalOutput", "web"]
4+
tools: ['vscode/extensions', 'execute/testFailure', 'execute/getTerminalOutput', 'execute/getTaskOutput', 'execute/runInTerminal', 'execute/runTests', 'read', 'edit/createFile', 'edit/editFiles', 'search', 'web']
55
model: "Claude Sonnet 4.5"
66
---
77

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
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 Thold Plugin
70+
uses: actions/checkout@v4
71+
with:
72+
path: cacti/plugins/thold
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+
145+
- name: Configure Apache
146+
run: |
147+
cat << 'EOF' | sed 's#GITHUB_WORKSPACE#${{ github.workspace }}#g' > /tmp/cacti.conf
148+
<VirtualHost *:80>
149+
ServerAdmin webmaster@localhost
150+
DocumentRoot GITHUB_WORKSPACE/cacti
151+
152+
<Directory GITHUB_WORKSPACE/cacti>
153+
Options Indexes FollowSymLinks
154+
AllowOverride All
155+
Require all granted
156+
</Directory>
157+
158+
ErrorLog ${APACHE_LOG_DIR}/error.log
159+
CustomLog ${APACHE_LOG_DIR}/access.log combined
160+
</VirtualHost>
161+
EOF
162+
sudo cp /tmp/cacti.conf /etc/apache2/sites-available/000-default.conf
163+
sudo systemctl restart apache2
164+
165+
- name: Install Cacti via CLI
166+
run: |
167+
cd ${{ github.workspace }}/cacti
168+
sudo php cli/install_cacti.php --accept-eula --install --force
169+
170+
- name: Install Thold Plugin
171+
run: |
172+
cd ${{ github.workspace }}/cacti
173+
sudo php cli/plugin_manage.php --plugin=thold --install --enable
174+
175+
- name: import Thold Plugin Sample Data
176+
run: |
177+
cd ${{ github.workspace }}/cacti/plugins/thold
178+
sudo php cli_import.php --filename=.github/workflows/thold_sample_data.xml
179+
if [ $? -ne 0 ]; then
180+
echo "Failed to import Thold sample data"
181+
exit 1
182+
fi
183+
184+
- name: Check PHP Syntax for Plugin
185+
run: |
186+
cd ${{ github.workspace }}/cacti/plugins/thold
187+
if find . -name '*.php' -exec php -l {} 2>&1 \; | grep -iv 'no syntax errors detected'; then
188+
echo "Syntax errors found!"
189+
exit 1
190+
fi
191+
192+
193+
194+
- name: Run Cacti Poller
195+
run: |
196+
cd ${{ github.workspace }}/cacti
197+
sudo php poller.php --poller=1 --force --debug
198+
if ! grep -q "SYSTEM STATS" log/cacti.log; then
199+
echo "Cacti poller did not finish successfully"
200+
cat log/cacti.log
201+
exit 1
202+
fi
203+
204+
205+
206+
- name: View Cacti Logs
207+
if: always()
208+
run: |
209+
if [ -f ${{ github.workspace }}/cacti/log/cacti.log ]; then
210+
echo "=== Cacti Log ==="
211+
sudo cat ${{ github.workspace }}/cacti/log/cacti.log
212+
fi
213+
214+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<templates>
2+
<template1>
3+
<hash>0757348c8bf2c998d95034f03b0c9a1c</hash>
4+
<name>Linux - Memory - Free [mem_buffers]</name>
5+
<suggested_name>|data_source_description| [|data_source_name|]</suggested_name>
6+
<data_template_id>dc33aa9a8e71fb7c61ec0e7a6da074aa</data_template_id>
7+
<data_template_hash>dc33aa9a8e71fb7c61ec0e7a6da074aa</data_template_hash>
8+
<data_template_name>Linux - Memory - Free</data_template_name>
9+
<data_source_id>a4df3de5238d3beabee1a2fe140d3d80</data_source_id>
10+
<data_source_name>mem_buffers</data_source_name>
11+
<data_source_friendly>Result (in Kilobytes)</data_source_friendly>
12+
<thold_hi>10</thold_hi>
13+
<thold_low>5</thold_low>
14+
<thold_fail_trigger>1</thold_fail_trigger>
15+
<time_hi></time_hi>
16+
<time_low></time_low>
17+
<time_fail_trigger>1</time_fail_trigger>
18+
<time_fail_length>1</time_fail_length>
19+
<thold_warning_hi></thold_warning_hi>
20+
<thold_warning_low></thold_warning_low>
21+
<thold_warning_fail_trigger>1</thold_warning_fail_trigger>
22+
<thold_warning_fail_count>0</thold_warning_fail_count>
23+
<time_warning_hi></time_warning_hi>
24+
<time_warning_low></time_warning_low>
25+
<time_warning_fail_trigger>1</time_warning_fail_trigger>
26+
<time_warning_fail_length>1</time_warning_fail_length>
27+
<thold_enabled>on</thold_enabled>
28+
<thold_type>0</thold_type>
29+
<bl_ref_time_range>86400</bl_ref_time_range>
30+
<bl_type>0</bl_type>
31+
<bl_pct_down></bl_pct_down>
32+
<bl_pct_up></bl_pct_up>
33+
<bl_fail_trigger>2</bl_fail_trigger>
34+
<bl_fail_count></bl_fail_count>
35+
<bl_alert>0</bl_alert>
36+
<bl_cf>AVG</bl_cf>
37+
<repeat_alert>0</repeat_alert>
38+
<notify_extra></notify_extra>
39+
<notify_warning_extra></notify_warning_extra>
40+
<notify_templated>on</notify_templated>
41+
<notify_warning>0</notify_warning>
42+
<notify_alert>0</notify_alert>
43+
<snmp_event_category></snmp_event_category>
44+
<snmp_event_description></snmp_event_description>
45+
<snmp_event_severity>3</snmp_event_severity>
46+
<snmp_event_warning_severity>2</snmp_event_warning_severity>
47+
<data_type>0</data_type>
48+
<show_units>off</show_units>
49+
<units_suffix></units_suffix>
50+
<decimals>-1</decimals>
51+
<cdef>0</cdef>
52+
<percent_ds>mem_buffers</percent_ds>
53+
<expression></expression>
54+
<upper_ds>mem_buffers</upper_ds>
55+
<exempt></exempt>
56+
<thold_hrule_alert>0</thold_hrule_alert>
57+
<thold_hrule_warning>0</thold_hrule_warning>
58+
<skipscale></skipscale>
59+
<restored_alert></restored_alert>
60+
<reset_ack></reset_ack>
61+
<persist_ack></persist_ack>
62+
<email_subject></email_subject>
63+
<email_subject_warn></email_subject_warn>
64+
<email_subject_restoral></email_subject_restoral>
65+
<email_body>An Alert has been issued that requires your attention. &lt;br&gt;&lt;br&gt;&lt;strong&gt;Device&lt;/strong&gt;: &lt;DESCRIPTION&gt; (&lt;HOSTNAME&gt;)&lt;br&gt;&lt;strong&gt;URL&lt;/strong&gt;: &lt;URL&gt;&lt;br&gt;&lt;strong&gt;Message&lt;/strong&gt;: &lt;SUBJECT&gt;&lt;br&gt;&lt;br&gt;&lt;GRAPH&gt;</email_body>
66+
<email_body_warn>A Warning has been issued that requires your attention. &lt;br&gt;&lt;br&gt;&lt;strong&gt;Device&lt;/strong&gt;: &lt;DESCRIPTION&gt; (&lt;HOSTNAME&gt;)&lt;br&gt;&lt;strong&gt;URL&lt;/strong&gt;: &lt;URL&gt;&lt;br&gt;&lt;strong&gt;Message&lt;/strong&gt;: &lt;SUBJECT&gt;&lt;br&gt;&lt;br&gt;&lt;GRAPH&gt;</email_body_warn>
67+
<email_body_restoral>A Threshold has returned to normal status. &lt;br&gt;&lt;br&gt;&lt;strong&gt;Device&lt;/strong&gt;: &lt;DESCRIPTION&gt; (&lt;HOSTNAME&gt;)&lt;br&gt;&lt;strong&gt;URL&lt;/strong&gt;: &lt;URL&gt;&lt;br&gt;&lt;strong&gt;Message&lt;/strong&gt;: &lt;SUBJECT&gt;&lt;br&gt;&lt;br&gt;&lt;GRAPH&gt;</email_body_restoral>
68+
<trigger_cmd_high></trigger_cmd_high>
69+
<trigger_cmd_low></trigger_cmd_low>
70+
<trigger_cmd_norm></trigger_cmd_norm>
71+
<syslog_priority>4</syslog_priority>
72+
<syslog_facility>24</syslog_facility>
73+
<syslog_enabled></syslog_enabled>
74+
<notes></notes>
75+
<external_id></external_id>
76+
<format_file>default.format</format_file>
77+
<graph_timespan>7</graph_timespan>
78+
</template1>
79+
</templates>

notify_lists.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ function clearFilter() {
11691169
$sql_params[] = get_request_var('id');
11701170
}
11711171

1172-
$sql_limit = 'LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows;
1172+
$sql_limit = 'LIMIT ' . ($rows*(intval(get_request_var('page'))-1)) . ',' . $rows;
11731173
$sql_order = get_order_string();
11741174

11751175
$total_rows = db_fetch_cell_prepared("SELECT
@@ -1345,7 +1345,7 @@ function tholds($header_label) {
13451345
$sql_where = '';
13461346

13471347
$sort = get_request_var('sort_column') . ' ' . get_request_var('sort_direction');
1348-
$limit = ($rows*(get_request_var('page')-1)) . ", $rows";
1348+
$limit = ($rows*(intval(get_request_var('page'))-1)) . ", $rows";
13491349

13501350
if (!isempty_request_var('template') && get_request_var('template') != '-1') {
13511351
$sql_where .= ($sql_where == '' ? '' : ' AND ') . 'td.data_template_id = ' . get_request_var('template');
@@ -1690,7 +1690,7 @@ function templates($header_label) {
16901690

16911691
$sql_where = '';
16921692
$sql_order = get_order_string();
1693-
$sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows;
1693+
$sql_limit = ' LIMIT ' . ($rows*(intval(get_request_var('page'))-1)) . ',' . $rows;
16941694

16951695
if (get_request_var('associated') == 'true') {
16961696
$sql_where .= (!strlen($sql_where) ? 'WHERE ' : ' AND ') . '(notify_warning=' . get_request_var('id') . ' OR notify_alert=' . get_request_var('id') . ')';
@@ -2113,7 +2113,7 @@ function clearFilter() {
21132113
$sql_where");
21142114

21152115
$sql_order = get_order_string();
2116-
$sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows;
2116+
$sql_limit = ' LIMIT ' . ($rows*(intval(get_request_var('page'))-1)) . ',' . $rows;
21172117

21182118
$lists = db_fetch_assoc("SELECT id, name, enabled, description, emails,
21192119
(SELECT COUNT(id) FROM thold_data WHERE notify_alert = nl.id) as thold_alerts,

notify_queue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ function clearFilter() {
381381
$sql_where");
382382

383383
$sql_order = get_order_string();
384-
$sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows;
384+
$sql_limit = ' LIMIT ' . ($rows*(intval(get_request_var('page'))-1)) . ',' . $rows;
385385

386386
$notifications = db_fetch_assoc("SELECT nq.*, h.hostname
387387
FROM notification_queue AS nq

thold.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ function list_tholds() {
616616
}
617617

618618
$sql_order = get_order_string();
619-
$sql_limit = ($rows*(get_request_var('page')-1)) . ',' . $rows;
619+
$sql_limit = ($rows*(intval(get_request_var('page'))-1)) . ',' . $rows;
620620
$sql_order = str_replace('ORDER BY ', '', $sql_order);
621621

622622
$tholds = get_allowed_thresholds($sql_where, $sql_order, $sql_limit, $total_rows);

0 commit comments

Comments
 (0)