Skip to content

Commit 2d3b623

Browse files
TheWitnessCopilot
andauthored
Updating workflow to include code validation PHP8.4 and MariaDB 10.6 (#739)
* Adding Worflows for code validation * Apply php-cs-fixer rules * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent d43d679 commit 2d3b623

39 files changed

Lines changed: 7694 additions & 7305 deletions

.github/workflows/plugin-ci-workflow.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ jobs:
3838
strategy:
3939
fail-fast: false
4040
matrix:
41-
php: ['8.1', '8.2', '8.3']
41+
php: ['8.1', '8.2', '8.3', '8.4']
4242
os: [ubuntu-latest]
4343

4444
services:
45-
mysql:
46-
image: mysql:8.0
45+
mariadb:
46+
image: mariadb:10.6
4747
env:
4848
MYSQL_ROOT_PASSWORD: cactiroot
4949
MYSQL_DATABASE: cacti
@@ -81,7 +81,6 @@ jobs:
8181
- name: Check PHP version
8282
run: php -v
8383

84-
8584
- name: Run apt-get update
8685
run: sudo apt-get update
8786

@@ -141,7 +140,6 @@ jobs:
141140
sed -r "s/'cactiuser'/'cactiuser'/g" > ${{ github.workspace }}/cacti/include/config.php
142141
sudo chmod 664 ${{ github.workspace }}/cacti/include/config.php
143142
144-
145143
- name: Configure Apache
146144
run: |
147145
cat << 'EOF' | sed 's#GITHUB_WORKSPACE#${{ github.workspace }}#g' > /tmp/cacti.conf
@@ -189,7 +187,24 @@ jobs:
189187
exit 1
190188
fi
191189
190+
- name: Remove the plugins directory exclusion from the .phpstan.neon
191+
run: sed '/plugins/d' -i .phpstan.neon
192+
working-directory: ${{ github.workspace }}/cacti
193+
194+
- name: Mark composer scripts executable
195+
run: sudo chmod +x ${{ github.workspace }}/cacti/include/vendor/bin/*
196+
197+
- name: Run Linter on base code
198+
run: composer run-script lint ${{ github.workspace }}/cacti/plugins/thold
199+
working-directory: ${{ github.workspace }}/cacti
200+
201+
- name: Checking coding standards on base code
202+
run: composer run-script phpcsfixer ${{ github.workspace }}/cacti/plugins/thold
203+
working-directory: ${{ github.workspace }}/cacti
192204

205+
# - name: Run PHPStan at Level 6 on base code outside of Composer due to technical issues
206+
# run: ./include/vendor/bin/phpstan analyze --level 6 ${{ github.workspace }}/cacti/plugins/thold
207+
# working-directory: ${{ github.workspace }}/cacti
193208

194209
- name: Run Cacti Poller
195210
run: |
@@ -201,14 +216,10 @@ jobs:
201216
exit 1
202217
fi
203218
204-
205-
206219
- name: View Cacti Logs
207220
if: always()
208221
run: |
209222
if [ -f ${{ github.workspace }}/cacti/log/cacti.log ]; then
210223
echo "=== Cacti Log ==="
211224
sudo cat ${{ github.workspace }}/cacti/log/cacti.log
212225
fi
213-
214-

cli_import.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,44 @@
2222
+-------------------------------------------------------------------------+
2323
*/
2424

25-
/* let PHP run just as long as it has to */
25+
// let PHP run just as long as it has to
2626
ini_set('max_execution_time', '0');
2727

2828
error_reporting(E_ALL);
2929

30-
include(dirname(__FILE__) . '/../../include/cli_check.php');
30+
include(__DIR__ . '/../../include/cli_check.php');
3131
include_once($config['base_path'] . '/lib/xml.php');
3232
include_once($config['base_path'] . '/plugins/thold/thold_functions.php');
3333

34-
/* set the defaults */
34+
// set the defaults
3535
$force = false;
3636
$debug = false;
3737
$filename = false;
3838
$errors = 0;
3939

40-
/* process calling arguments */
40+
// process calling arguments
4141
$parms = $_SERVER['argv'];
4242
array_shift($parms);
4343

4444
if (sizeof($parms)) {
45-
foreach($parms as $parameter) {
45+
foreach ($parms as $parameter) {
4646
if (strpos($parameter, '=')) {
47-
list($arg, $value) = explode('=', $parameter);
47+
[$arg, $value] = explode('=', $parameter);
4848
} else {
49-
$arg = $parameter;
49+
$arg = $parameter;
5050
$value = '';
5151
}
5252

5353
switch ($arg) {
5454
case '--debug':
5555
case '-d':
5656
$debug = true;
57+
5758
break;
5859
case '--filename':
5960
case '-f':
6061
$filename = $value;
62+
6163
break;
6264
case '--version':
6365
case '-V':
@@ -77,28 +79,28 @@
7779
}
7880
}
7981

80-
/* validate filename set */
82+
// validate filename set
8183
if ($filename === false) {
8284
print 'ERROR: You must specify a filename using either the --filename of -f options.' . PHP_EOL . PHP_EOL;
8385
display_help();
8486
exit(-1);
8587
}
8688

87-
/* validate exists */
89+
// validate exists
8890
if (!file_exists($filename)) {
8991
print 'ERROR: The filename \'' . $filename . '\' does not exist.' . PHP_EOL . PHP_EOL;
9092
display_help();
9193
exit(-1);
9294
}
9395

94-
/* validate readable */
96+
// validate readable
9597
if (!is_readable($filename)) {
9698
print 'ERROR: The filename \'' . $filename . '\' is not readable.' . PHP_EOL . PHP_EOL;
9799
display_help();
98100
exit(-1);
99101
}
100102

101-
/* validate good xml */
103+
// validate good xml
102104
$data = file_get_contents($filename);
103105

104106
$xml = xml2array($data);
@@ -112,19 +114,19 @@
112114
$return_data = thold_template_import($data);
113115

114116
if (sizeof($return_data) && isset($return_data['success'])) {
115-
foreach($return_data['success'] as $message) {
117+
foreach ($return_data['success'] as $message) {
116118
print 'NOTE: ' . $message . PHP_EOL;
117119
}
118120
}
119121

120122
if (isset($return_data['errors'])) {
121-
foreach($return_data['errors'] as $error) {
123+
foreach ($return_data['errors'] as $error) {
122124
print 'ERROR: ' . $error . PHP_EOL;
123125
}
124126
}
125127

126128
if (isset($return_data['failure'])) {
127-
foreach($return_data['failure'] as $error) {
129+
foreach ($return_data['failure'] as $error) {
128130
print 'ERROR: ' . $error . PHP_EOL;
129131
}
130132

@@ -160,9 +162,8 @@ function display_version() {
160162
print 'Threshold Template Import Utility, Version ' . $info['version'] . ', ' . COPYRIGHT_YEARS . PHP_EOL;
161163
}
162164

163-
164-
/* display_help - displays the usage of the function */
165-
function display_help () {
165+
// display_help - displays the usage of the function
166+
function display_help() {
166167
display_version();
167168

168169
print PHP_EOL;
@@ -172,4 +173,3 @@ function display_help () {
172173
print 'Simple CLI command to import a threshold template.' . PHP_EOL . PHP_EOL;
173174
print '--filename=N - A valid threshold template exported using the thold plugin.' . PHP_EOL . PHP_EOL;
174175
}
175-

cli_thresholds.php

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
+-------------------------------------------------------------------------+
2323
*/
2424

25-
/* let PHP run just as long as it has to */
25+
// let PHP run just as long as it has to
2626
ini_set('max_execution_time', '0');
2727

2828
error_reporting(E_ALL);
29-
$dir = dirname(__FILE__);
29+
$dir = __DIR__;
3030
chdir($dir);
3131

3232
if (strpos($dir, 'plugins') !== false) {
@@ -37,24 +37,24 @@
3737

3838
include_once($config['base_path'] . '/plugins/thold/thold_functions.php');
3939

40-
/* set the defaults */
40+
// set the defaults
4141
$force = false;
4242
$debug = false;
4343
$gtemplate = 0;
4444
$ttemplate = 0;
4545
$hids = '';
4646
$gids = '';
4747

48-
/* process calling arguments */
48+
// process calling arguments
4949
$parms = $_SERVER['argv'];
5050
array_shift($parms);
5151

5252
if (sizeof($parms)) {
53-
foreach($parms as $parameter) {
53+
foreach ($parms as $parameter) {
5454
if (strpos($parameter, '=')) {
55-
list($arg, $value) = explode('=', $parameter);
55+
[$arg, $value] = explode('=', $parameter);
5656
} else {
57-
$arg = $parameter;
57+
$arg = $parameter;
5858
$value = '';
5959
}
6060

@@ -72,25 +72,31 @@
7272
case '--debug':
7373
case '-d':
7474
$debug = true;
75+
7576
break;
7677
case '--force':
7778
case '-f':
7879
$force = true;
80+
7981
break;
8082
case '--graph-template':
8183
case '-gt':
8284
$gtemplate = $value;
85+
8386
break;
8487
case '--thold-template':
8588
case '-tt':
8689
$ttemplate = $value;
90+
8791
break;
8892
case '--graph-ids':
8993
case '-ids':
9094
$gids = $value;
95+
9196
break;
9297
case '--host-ids':
9398
$hids = $value;
99+
94100
break;
95101
case '--version':
96102
case '-V':
@@ -110,10 +116,11 @@
110116
}
111117
}
112118

113-
/* validate device ids */
119+
// validate device ids
114120
if (strlen($hids)) {
115121
$hids = explode(' ', $hids);
116-
foreach($hids as $id) {
122+
123+
foreach ($hids as $id) {
117124
if (!is_numeric($id)) {
118125
print 'ERROR: The Device ID \'' . $id . '\' is NOT numeric. All Device IDs must be numeric.' . PHP_EOL . PHP_EOL;
119126
display_help();
@@ -122,24 +129,25 @@
122129
}
123130
}
124131

125-
/* validate values */
132+
// validate values
126133
if (!is_numeric($ttemplate)) {
127134
print 'ERROR: The Thold Template must be numeric.' . PHP_EOL . PHP_EOL;
128135
display_help();
129136
exit(-1);
130137
}
131138

132-
/* validate values */
139+
// validate values
133140
if (!is_numeric($gtemplate)) {
134141
print 'ERROR: The Graph Template must be numeric.' . PHP_EOL . PHP_EOL;
135142
display_help();
136143
exit(-1);
137144
}
138145

139-
/* validate graph ids */
146+
// validate graph ids
140147
if (strlen($gids)) {
141148
$gids = explode(' ', $gids);
142-
foreach($gids as $id) {
149+
150+
foreach ($gids as $id) {
143151
if (!is_numeric($id)) {
144152
print 'ERROR: The Graph ID \'' . $id . '\' is NOT numeric. All Graph IDs must be numeric.' . PHP_EOL . PHP_EOL;
145153
display_help();
@@ -148,7 +156,7 @@
148156
}
149157
}
150158

151-
/* perform some checks */
159+
// perform some checks
152160
if ($ttemplate == 0 && $gtemplate == 0 && $hids == '' && $gids == '') {
153161
print 'ERROR: You must choose either --auto-create or a combination of Devices, Graphs,' . PHP_EOL;
154162
print 'a Graph Template of Threshold Template.' . PHP_EOL . PHP_EOL;
@@ -174,6 +182,7 @@ function thold_cli_autocreate($hids = '', $gids = '', $gtemplate = 0, $ttemplate
174182

175183
function display_version() {
176184
global $config;
185+
177186
if (!function_exists('plugin_thold_version')) {
178187
include_once($config['base_path'] . '/plugins/thold/setup.php');
179188
}
@@ -182,9 +191,8 @@ function display_version() {
182191
print 'Threshold Command Line Interface, Version ' . $info['version'] . ', ' . COPYRIGHT_YEARS . PHP_EOL;
183192
}
184193

185-
186-
/* display_help - displays the usage of the function */
187-
function display_help () {
194+
// display_help - displays the usage of the function
195+
function display_help() {
188196
display_version();
189197

190198
print PHP_EOL;
@@ -206,4 +214,3 @@ function display_help () {
206214
print '--thold-template=N - The Threshold Template to use for creating Thresholds' . PHP_EOL;
207215
print '--graph-ids=\'N1 N2 ...\' - The Threshold Template to use for creating Thresholds' . PHP_EOL . PHP_EOL;
208216
}
209-

extras/apply_realms.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,28 @@
2222
+-------------------------------------------------------------------------+
2323
*/
2424

25-
include_once(dirname(__FILE__) . "/../../../include/cli_check.php");
25+
include_once(__DIR__ . '/../../../include/cli_check.php');
2626

2727
// Get the current users
28-
$users = db_fetch_assoc("SELECT id FROM user_auth");
28+
$users = db_fetch_assoc('SELECT id FROM user_auth');
2929

3030
// Get the realm for threshold viewing, increase 100 per plugin realm standards
3131
$realm = db_fetch_cell("SELECT id FROM plugin_realms WHERE display = 'View Thresholds'");
3232
$realm = $realm + 100;
3333

3434
print "Threshold Viewing Realm: $realm\n";
35-
print "Found " . count($users) . " users\n";
35+
print 'Found ' . count($users) . " users\n";
3636

3737
// Loop through and update each users permissions
3838
print "Updating Realm Permissions\n";
3939

4040
foreach ($users as $user) {
41-
print ".";
41+
print '.';
4242
$u = $user['id'];
4343
db_execute_prepared('REPLACE INTO user_auth_realm
4444
(realm_id, user_id) VALUES
4545
(?, ?)',
46-
array($realm, $u));
46+
[$realm, $u]);
4747
}
4848

4949
print "\n";
50-

extras/index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@
2323
*/
2424

2525
header('Location:../index.php');
26-

0 commit comments

Comments
 (0)