Skip to content

Commit

Permalink
Fixing #4957 - Device Classes
Browse files Browse the repository at this point in the history
Add Device Template Classes to match the Classes in Upcoming release of the Package Plugin
  • Loading branch information
TheWitness committed Oct 16, 2022
1 parent d0d159b commit fe4b7d9
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Cacti CHANGELOG
-feature#4948: When using proxies to load balance Cacti, if the proxy cookie times out, Cacti should properly redirect
-feature#4955: Provide Common Sense Memory Tuning based upon MySQL Tuner Recommendations
-feature#4956: The function db_check_reconnect() should be able to work with any connection
-feature#4957: Add Device Template Classes to match the Classes in Upcoming release of the Package Plugin

1.2.22
-security#4834: When creating new graphs, cross site injection is possible
Expand Down
1 change: 1 addition & 0 deletions cacti.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,7 @@ CREATE TABLE host_template (
id mediumint(8) unsigned NOT NULL auto_increment,
hash varchar(32) NOT NULL default '',
name varchar(100) NOT NULL default '',
class varchar(40) NOT NULL default '',
PRIMARY KEY (id),
KEY `name` (`name`)
) ENGINE=InnoDB ROW_FORMAT=Dynamic;
Expand Down
1 change: 1 addition & 0 deletions docs/audit_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ INSERT INTO `table_columns` VALUES ('host_snmp_query',5,'reindex_method','tinyin
INSERT INTO `table_columns` VALUES ('host_template',1,'id','mediumint(8) unsigned','NO','PRI',NULL,'auto_increment');
INSERT INTO `table_columns` VALUES ('host_template',2,'hash','varchar(32)','NO','','','');
INSERT INTO `table_columns` VALUES ('host_template',3,'name','varchar(100)','NO','MUL','','');
INSERT INTO `table_columns` VALUES ('host_template',4,'class','varchar(40)','NO','MUL','','');
INSERT INTO `table_columns` VALUES ('host_template_graph',1,'host_template_id','mediumint(8) unsigned','NO','PRI','0','');
INSERT INTO `table_columns` VALUES ('host_template_graph',2,'graph_template_id','mediumint(8) unsigned','NO','PRI','0','');
INSERT INTO `table_columns` VALUES ('host_template_snmp_query',1,'host_template_id','mediumint(8) unsigned','NO','PRI','0','');
Expand Down
53 changes: 48 additions & 5 deletions host_templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ function form_save() {
/* ==================================================== */

if (isset_request_var('save_component_template')) {
$save['id'] = get_nfilter_request_var('id');
$save['hash'] = get_hash_host_template(get_nfilter_request_var('id'));
$save['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', '', false, 3);
$save['id'] = get_nfilter_request_var('id');
$save['hash'] = get_hash_host_template(get_nfilter_request_var('id'));
$save['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', '', false, 3);
$save['class'] = form_input_validate(get_nfilter_request_var('class'), 'class', '', false, 3);

if (!is_error_message()) {
$host_template_id = sql_save($save, 'host_template');
Expand Down Expand Up @@ -662,7 +663,7 @@ function template_edit() {
}

function template() {
global $host_actions, $item_rows;
global $host_actions, $item_rows, $device_classes;

/* ================= input validation and session storage ================= */
$filters = array(
Expand All @@ -680,6 +681,13 @@ function template() {
'pageset' => true,
'default' => ''
),
'class' => array(
'filter' => FILTER_CALLBACK,
'default' => '-1',
'pageset' => true,
'sort' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'name',
Expand Down Expand Up @@ -721,6 +729,21 @@ function template() {
<td>
<input type='text' class='ui-state-default ui-corner-all' id='filter' size='25' value='<?php print html_escape_request_var('filter');?>'>
</td>
<td>
<?php print __('Device Class');?>
</td>
<td>
<select id='class' onChange='applyFilter()'>
<option value='-1'<?php print (get_request_var('class') == '-1' ? ' selected>':'>') . __('All');?></option>
<?php
if (cacti_sizeof($device_classes)) {
foreach ($device_classes as $key => $value) {
print "<option value='" . $key . "'"; if (get_request_var('class') == $key) { print ' selected'; } print '>' . html_escape($value) . "</option>\n";
}
}
?>
</select>
</td>
<td>
<?php print __('Device Templates');?>
</td>
Expand Down Expand Up @@ -756,6 +779,7 @@ function template() {
function applyFilter() {
strURL = 'host_templates.php?header=false';
strURL += '&filter='+$('#filter').val();
strURL += '&class='+$('#class').val();
strURL += '&rows='+$('#rows').val();
strURL += '&has_hosts='+$('#has_hosts').is(':checked');
loadPageNoHeader(strURL);
Expand Down Expand Up @@ -793,6 +817,12 @@ function clearFilter() {
$sql_where = '';
}

if (get_request_var('class') != '-1') {
$sql_where = 'WHERE (host_template.class = ' . db_qstr(get_request_var('class')) . ')';
} else {
$sql_where = '';
}

if (get_request_var('has_hosts') == 'true') {
$sql_having = 'HAVING hosts>0';
} else {
Expand All @@ -814,7 +844,7 @@ function clearFilter() {
$sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows;

$template_list = db_fetch_assoc("SELECT
host_template.id,host_template.name, COUNT(DISTINCT host.id) AS hosts
host_template.id, host_template.name, host_template.class, COUNT(DISTINCT host.id) AS hosts
FROM host_template
LEFT JOIN host ON host.host_template_id=host_template.id
$sql_where
Expand All @@ -830,6 +860,12 @@ function clearFilter() {
'sort' => 'ASC',
'tip' => __('The name of this Device Template.')
),
'host_template.class' => array(
'display' => __('Device Class'),
'align' => 'left',
'sort' => 'ASC',
'tip' => __('The Class of this Device Template. The Class Name should be representative of it\'s function.')
),
'host_template.id' => array(
'display' => __('ID'),
'align' => 'right',
Expand Down Expand Up @@ -871,6 +907,13 @@ function clearFilter() {

form_alternate_row('line' . $template['id'], true, $disabled);
form_selectable_cell(filter_value($template['name'], get_request_var('filter'), 'host_templates.php?action=edit&id=' . $template['id']), $template['id']);

if ($template['class'] != '') {
form_selectable_cell($device_classes[$template['class']], $template['id']);
} else {
form_selectable_cell(__('Unassigned'), $template['id']);
}

form_selectable_cell($template['id'], $template['id'], '', 'right');
form_selectable_cell($disabled ? __('No'):__('Yes'), $template['id'], '', 'right');
form_selectable_cell('<a class="linkEditMain" href="' . html_escape('host.php?reset=true&host_template_id=' . $template['id']) . '">' . number_format_i18n($template['hosts'], '-1') . '</a>', $template['id'], '', 'right');
Expand Down
22 changes: 22 additions & 0 deletions include/global_arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,28 @@
__('Troubleshooting') => 'fa fa-bug'
);

$device_classes = array(
'application' => __('Application Related'),
'cacti' => __('Cacti Related'),
'database' => __('Database Related'),
'facilities' => __('Facilities Related'),
'general' => __('Generic Device'),
'hpc' => __('HPC/Grid Computing'),
'hypervisor' => __('Hypervisor Related'),
'license' => __('Licensing Related'),
'linux' => __('Linux Related'),
'loadbalancer' => __('Load Balancer'),
'switch' => __('Network Switch'),
'router' => __('Network Router'),
'firewall' => __('Network Firewall'),
'storage' => __('Storage Related'),
'telephony' => __('Telco Related'),
'webserver' => __('Web Server Related'),
'windows' => __('Windows Related'),
'ups' => __('UPS Related'),
'' => __('Unassigned')
);

if ((isset($_SESSION['sess_user_id']))) {
if (db_table_exists('external_links')) {
$consoles = db_fetch_assoc('SELECT id, title, extendedstyle
Expand Down
8 changes: 8 additions & 0 deletions include/global_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,14 @@
'max_length' => '255',
'size' => '80'
),
'class' => array(
'method' => 'drop_array',
'friendly_name' => __('Class'),
'description' => __('A suitable Class for the Device Template.'),
'value' => '|arg1:class|',
'array' => $device_classes,
'default' => ''
),
'id' => array(
'method' => 'hidden_zero',
'value' => '|arg1:id|'
Expand Down
6 changes: 5 additions & 1 deletion install/upgrades/1_2_23.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ function upgrade_to_1_2_23() {
`local_data_id` mediumint(8) unsigned NOT NULL,
`test_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`message` varchar(250) default '')
ENGINE=InnoDB ROW_FORMAT=Dynamic
ENGINE=InnoDB ROW_FORMAT=Dynamic
COMMENT='Store result of RRDcheck'");

if (!db_column_exists('host_template', 'class')) {
db_install_execute('ALTER TABLE host_template ADD COLUMN class varchar(40) NOT NULL default "" AFTER name');
}
}

0 comments on commit fe4b7d9

Please sign in to comment.