Skip to content

Commit

Permalink
QA: #1987 - Provide install/uninstall/enable/disable logging
Browse files Browse the repository at this point in the history
* Provide logging for common plugin actions
* Provide backward compatibility for plugins like syslog
  • Loading branch information
TheWitness committed Nov 5, 2024
1 parent 3b296bf commit 5fb662c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,12 +769,16 @@ function api_plugin_install($plugin) {
SET status = 4
WHERE directory = ?',
array($plugin));

cacti_log(sprintf('NOTE: Cacti Plugin %s has been installed by %s', $plugin, get_username()), false, 'PLUGIN');
} else {
// Set the plugin as "needs configuration"
db_execute_prepared('UPDATE plugin_config
SET status = 2
WHERE directory = ?',
array($plugin));

cacti_log(sprintf('WARNING: Cacti Plugin %s was not installed by %s due to Configuration Issues', $plugin, get_username()), false, 'PLUGIN');
}
} else {
raise_message('install_error', __('The Plugin in the directory \'%s\' does not include an install function \'%s()\'. This function must exist for the plugin to be installed.', $plugin, $function), MESSAGE_LEVEL_ERROR);
Expand Down Expand Up @@ -871,6 +875,8 @@ function api_plugin_uninstall($plugin, $tables = true) {
}

api_plugin_replicate_config();

cacti_log(sprintf('NOTE: Cacti Plugin %s has been uninstalled by %s', $plugin, get_username()), false, 'PLUGIN');
}

function api_plugin_check_config($plugin) {
Expand Down Expand Up @@ -903,6 +909,8 @@ function api_plugin_enable($plugin) {
SET status = 1
WHERE directory = ?',
array($plugin));

cacti_log(sprintf('WARNING: Cacti Plugin %s has been enabled by %s', $plugin, get_username()), false, 'PLUGIN');
}
}

Expand Down Expand Up @@ -938,6 +946,8 @@ function api_plugin_disable($plugin) {
array($plugin));

api_plugin_replicate_config();

cacti_log(sprintf('WARNING: Cacti Plugin %s has been disabled by %s', $plugin, get_username()), false, 'PLUGIN');
}

function api_plugin_remove_data($plugin) {
Expand Down
13 changes: 13 additions & 0 deletions plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@

set_default_action('list');

/**
* this is for legacy support for plugins like syslog
* that are dependent on the mode request variable
* to be set.
*/
if (isset_request_var('mode')) {
set_request_var('action', get_nfilter_request_var('mode'));

if (isset_request_var('id')) {
set_request_var('plugin', get_nfilter_request_var('id'));
}
}

$action = get_nfilter_request_var('action');

/* pre-check for actions that will fail by default */
Expand Down

0 comments on commit 5fb662c

Please sign in to comment.