Skip to content

Commit

Permalink
Fixing Issue #5414 - Plugin control of change device settings
Browse files Browse the repository at this point in the history
Plugins are unable to modify fields in the setting 'Change Device Settings'
  • Loading branch information
TheWitness committed Jul 23, 2023
1 parent 63887c3 commit 32d56dd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Cacti CHANGELOG
-issue#5402: Cacti translations including less compatible language replacement characters in a few locations
-issue#5403: Cacti Log regular expression filters can not calculate 'does not match' properly
-issue#5413: Rows Per Page - Not all options are available
-issue#5414: Plugins are unable to modify fields in the setting 'Change Device Settings'
-feature#5375: Add template for Fortinet firewall and Aruba Instant cluster
-feature#5393: Add template for SNMP printer
-feature: Update Cisco Device Template to include HSRP graph template
Expand Down
12 changes: 2 additions & 10 deletions host.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ function form_save() {
------------------------ */

function form_actions() {
global $device_actions, $fields_host_edit;
global $device_actions, $device_change_fields, $fields_host_edit;

/* ================= input validation ================= */
get_filter_request_var('drp_action', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z0-9_]+)$/')));
Expand Down Expand Up @@ -420,15 +420,7 @@ function form_actions() {
$form_array = array();

foreach ($fields_host_edit as $field_name => $field_array) {
if ((preg_match('/^snmp_/', $field_name)) ||
(preg_match('/^ping_/', $field_name)) ||
($field_name == 'poller_id') ||
($field_name == 'site_id') ||
($field_name == 'host_template_id') ||
($field_name == 'availability_method') ||
($field_name == 'device_threads') ||
($field_name == 'location') ||
($field_name == 'max_oids')) {
if (api_device_change_field_match($field_name)) {
$form_array += array($field_name => $fields_host_edit[$field_name]);

$form_array[$field_name]['value'] = '';
Expand Down
16 changes: 16 additions & 0 deletions include/global_arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,22 @@
10 => __('%d Threads', 10)
);

$device_change_fields = array(
'preg_field' => array(
'/^snmp_/',
'/^ping_/'
),
'match_field' => array(
'poller_id',
'site_id',
'host_template_id',
'availability_method',
'device_threads',
'location',
'max_oids'
)
);

$cron_intervals = array(
60 => __('Every Minute'),
300 => __('Every %d Minutes', 5)
Expand Down
35 changes: 35 additions & 0 deletions lib/api_device.php
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,41 @@ function api_device_update_host_template($device_id, $device_template_id) {
api_plugin_hook_function('device_template_change', $data);
}

/**
* api_device_change_field_match - Checks the global $device_change_fileds array
* against the field name and returns true or false if it matches the rule
*
* This function can be used by plugins to allow the modification of additional
* device fields from the change device rule.
*
* @param string The field name to check
*
* @return bool True or false if it matches one of the rules
*/
function api_device_change_field_match($field_name) {
global $device_change_fields;

$matches = false;

foreach($device_change_fields as $rule_type => $rules) {
foreach($rules as $field_rule) {
if ($rule_type == 'preg_field') {
if (preg_match($field_rule, $field_name)) {
$matches = true;
break 2;
}
} elseif ($rule_type == 'match_field') {
if ($field_rule == $field_name) {
$matches = true;
break 2;
}
}
}
}

return $matches;
}

/**
* api_device_template_sync_template - updates the device template mapping for all devices mapped to a template
*
Expand Down

0 comments on commit 32d56dd

Please sign in to comment.