function thold_upgrade_database() { global $config, $database_default; include_once $config['library_path'] . '/database.php'; thold_setup_database(); include_once $config['base_path'] . '/plugins/thold/setup.php'; include_once $config['base_path'] . '/plugins/thold/thold_functions.php'; $v = plugin_thold_version(); $oldv = read_config_option('plugin_thold_version'); if ($oldv < 0.1) { db_execute('INSERT INTO settings (name, value) VALUES ("plugin_thold_version", "' . $v['version'] . '")'); $oldv = $v['version']; } // Check for needed Cacti Indexes $indexes = array_rekey(db_fetch_assoc("SHOW INDEX FROM graph_templates_item"), "Key_name", "Key_name"); if (!array_key_exists("task_item_id", $indexes)) { db_execute("ALTER TABLE graph_templates_item ADD INDEX task_item_id(task_item_id)"); } $indexes = array_rekey(db_fetch_assoc("SHOW INDEX FROM data_local"), "Key_name", "Key_name"); if (!array_key_exists("data_template_id", $indexes)) { db_execute("ALTER TABLE data_local ADD INDEX data_template_id(data_template_id)"); } if (!array_key_exists("snmp_query_id", $indexes)) { db_execute("ALTER TABLE data_local ADD INDEX snmp_query_id(snmp_query_id)"); } $indexes = array_rekey(db_fetch_assoc("SHOW INDEX FROM host_snmp_cache"), "Key_name", "Key_name"); if (!array_key_exists("snmp_query_id", $indexes)) { db_execute("ALTER TABLE host_snmp_cache ADD INDEX snmp_query_id(snmp_query_id)"); } $indexes = array_rekey(db_fetch_assoc("SHOW INDEX FROM data_template_rrd"), "Key_name", "Key_name"); if (!array_key_exists("data_source_name", $indexes)) { db_execute("ALTER TABLE data_template_rrd ADD INDEX data_source_name(data_source_name)"); } // Added in thold v0.4 if ($oldv < 0.4) { api_plugin_db_add_column('thold', 'thold_data', array('name' => 'name', 'type' => 'varchar(100)', 'NULL' => false, 'default' => '', 'after' => 'id')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_hi', 'type' => 'varchar(100)', 'NULL' => true, 'after' => 'thold_fail_trigger')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_low', 'type' => 'varchar(100)', 'NULL' => true, 'after' => 'time_hi')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1, 'after' => 'time_low')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1, 'after' => 'time_fail_trigger')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'thold_type', 'type' => 'int (3)', 'NULL' => false, 'default' => 0, 'after' => 'thold_enabled')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'data_type', 'type' => 'int (3)', 'NULL' => false, 'default' => 0, 'after' => 'notify_extra')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'percent_ds', 'type' => 'varchar(64)', 'NULL' => false, 'default' => 0, 'after' => 'cdef')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'tcheck', 'type' => 'int(1)', 'NULL' => false, 'default' => 0)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'exempt', 'type' => 'char(3)', 'NULL' => false, 'default' => '')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'local_graph_id', 'type' => 'int(11)', 'NULL' => false, 'default' => 0, 'after' => 'data_id')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'graph_template_id', 'type' => 'int(11)', 'NULL' => false, 'default' => 0, 'after' => 'graph_id')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'data_template_id', 'type' => 'int(11)', 'NULL' => false, 'default' => 0, 'after' => 'graph_template')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'restored_alert', 'type' => 'char(3)', 'NULL' => false, 'default' => '')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'name', 'type' => 'varchar(100)', 'NULL' => false, 'default' => '', 'after' => 'id')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_hi', 'type' => 'varchar(100)', 'NULL' => true, 'after' => 'thold_fail_trigger')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_low', 'type' => 'varchar(100)', 'NULL' => true, 'after' => 'time_hi')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1, 'after' => 'time_low')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1, 'after' => 'time_fail_trigger')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'thold_type', 'type' => 'int (3)', 'NULL' => false, 'default' => 0, 'after' => 'thold_enabled')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'data_type', 'type' => 'int (3)', 'NULL' => false, 'default' => 0, 'after' => 'syslog_priority')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'percent_ds', 'type' => 'varchar(64)', 'NULL' => false, 'default' => 0, 'after' => 'cdef')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'exempt', 'type' => 'char(3)', 'NULL' => false, 'default' => '')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'restored_alert', 'type' => 'char(3)', 'NULL' => false, 'default' => '')); // Update our hooks db_execute('UPDATE plugin_hooks SET file = "includes/settings.php" WHERE name = "thold" AND hook = "config_arrays"'); db_execute('UPDATE plugin_hooks SET file = "includes/settings.php" WHERE name = "thold" AND hook = "config_settings"'); db_execute('UPDATE plugin_hooks SET file = "includes/settings.php" WHERE name = "thold" AND hook = "draw_navigation_text"'); db_execute('UPDATE plugin_hooks SET function = "thold_poller_bottom", file = "includes/polling.php" WHERE name = "thold" AND hook = "poller_bottom"'); // Register the new hooks api_plugin_register_hook('thold', 'rrd_graph_graph_options', 'thold_rrd_graph_graph_options', 'setup.php'); api_plugin_register_hook('thold', 'graph_buttons', 'thold_graph_button', 'setup.php'); api_plugin_register_hook('thold', 'data_source_action_array', 'thold_data_source_action_array', 'setup.php'); api_plugin_register_hook('thold', 'data_source_action_prepare', 'thold_data_source_action_prepare', 'setup.php'); api_plugin_register_hook('thold', 'data_source_action_execute', 'thold_data_source_action_execute', 'setup.php'); api_plugin_register_hook('thold', 'graphs_action_array', 'thold_graphs_action_array', 'setup.php'); api_plugin_register_hook('thold', 'graphs_action_prepare', 'thold_graphs_action_prepare', 'setup.php'); api_plugin_register_hook('thold', 'graphs_action_execute', 'thold_graphs_action_execute', 'setup.php'); api_plugin_enable_hooks('thold'); // Fix our realms db_execute('UPDATE plugin_realms SET file = "thold.php" WHERE display = "Configure Thresholds"'); api_plugin_register_realm('thold', 'thold_templates.php', 'Configure Threshold Templates', 1); db_execute('ALTER TABLE thold_data ADD INDEX ( tcheck )', FALSE); db_execute('ALTER TABLE thold_data ADD INDEX ( local_graph_id )', FALSE); db_execute('ALTER TABLE thold_data ADD INDEX ( graph_template_id )', FALSE); db_execute('ALTER TABLE thold_data ADD INDEX ( data_template_id )', FALSE); // Rename some columns db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN rra_id local_data_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN data_id data_template_rrd_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN template thold_template_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN data_template data_template_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN graph_id local_graph_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN graph_template graph_template_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE plugin_thold_log CHANGE COLUMN graph_id local_graph_id int(11) UNSIGNED NOT NULL default "0"'); /* Set the default names on threshold and templates */ db_execute("UPDATE thold_data, data_template_data, data_template_rrd SET\n\t\t\t thold_data.name = CONCAT_WS('',data_template_data.name_cache, ' [', data_template_rrd.data_source_name, ']', '')\n\t\t\t WHERE data_template_data.local_data_id = thold_data.local_data_id AND data_template_rrd.id = thold_data.data_template_rrd_id AND thold_data.name = ''"); db_execute("UPDATE thold_template SET name = CONCAT_WS('', data_template_name, ' [', data_source_name, ']', '') WHERE name = ''"); /* Set the graph_ids for all thresholds */ db_execute('UPDATE thold_data, graph_templates_item, data_template_rrd SET thold_data.local_graph_id = graph_templates_item.local_graph_id, thold_data.graph_template_id = graph_templates_item.graph_template_id, thold_data.data_template_id = data_template_rrd.data_template_id WHERE data_template_rrd.local_data_id=thold_data.local_data_id AND data_template_rrd.id=graph_templates_item.task_item_id'); } // End 0.4 Upgrade if (version_compare($oldv, '0.4.3', '<')) { // Fix a few hooks db_execute('DELETE FROM plugin_hooks WHERE name = "thold" AND hook = "config_insert"'); db_execute('DELETE FROM plugin_hooks WHERE name = "thold" AND hook = "config_arrays"'); api_plugin_register_hook('thold', 'config_insert', 'thold_config_insert', 'includes/settings.php'); api_plugin_register_hook('thold', 'config_arrays', 'thold_config_arrays', 'includes/settings.php'); api_plugin_enable_hooks('thold'); $e = strtolower(db_fetch_cell("SELECT `value` FROM settings WHERE `name` = 'thold_from_email'")); if ($e == '*****@*****.**') { db_execute("UPDATE settings SET `value`='cacti@localhost' WHERE `name`='thold_from_email'"); } } if (version_compare($oldv, '0.4.4', '<')) { api_plugin_db_add_column('thold', 'thold_data', array('name' => 'lasttime', 'type' => 'TIMESTAMP', 'NULL' => false, 'after' => 'lastread')); db_execute('ALTER TABLE thold_data ADD COLUMN bl_thold_valid INT UNSIGNED NOT NULL DEFAULT 0', FALSE); db_execute('ALTER TABLE thold_data MODIFY name varchar(150) default NULL'); db_execute('ALTER TABLE thold_template MODIFY COLUMN bl_pct_down varchar(100)'); db_execute('ALTER TABLE thold_template MODIFY COLUMN bl_pct_up varchar(100)'); db_execute('ALTER TABLE thold_data MODIFY COLUMN bl_pct_down varchar(100)'); db_execute('ALTER TABLE thold_data MODIFY COLUMN bl_pct_up varchar(100)'); } if (version_compare($oldv, '0.4.5', '<')) { api_plugin_db_add_column('thold', 'thold_template', array('name' => 'thold_warning_hi', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'thold_warning_low', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'thold_warning_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'thold_warning_fail_count', 'type' => 'int(11)', 'NULL' => false, 'default' => '0')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_warning_hi', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_warning_low', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_warning_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_warning_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'notify_warning_extra', 'type' => 'text', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_warning_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'thold_warning_hi', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'thold_warning_low', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'thold_warning_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'thold_warning_fail_count', 'type' => 'int(11)', 'NULL' => false, 'default' => '0')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_warning_hi', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_warning_low', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_warning_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_warning_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'notify_warning_extra', 'type' => 'text', 'NULL' => true)); db_execute('ALTER TABLE thold_data MODIFY COLUMN notify_extra text'); db_execute('ALTER TABLE thold_template MODIFY COLUMN notify_extra text'); $data = array(); $data['columns'][] = array('name' => 'id', 'type' => 'int(12)', 'NULL' => false, 'auto_increment' => true); $data['columns'][] = array('name' => 'name', 'type' => 'varchar(128)', 'NULL' => false); $data['columns'][] = array('name' => 'description', 'type' => 'varchar(512)', 'NULL' => false); $data['columns'][] = array('name' => 'emails', 'type' => 'varchar(512)', 'NULL' => false); $data['primary'] = 'id'; $data['type'] = 'InnoDB'; $data['comment'] = 'Table of Notification Lists'; api_plugin_db_table_create('thold', 'plugin_notification_lists', $data); api_plugin_db_add_column('thold', 'host', array('name' => 'thold_send_email', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '1', 'after' => 'disabled')); api_plugin_db_add_column('thold', 'host', array('name' => 'thold_host_email', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => true, 'after' => 'thold_send_email')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'notify_warning', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '1', 'after' => 'notify_warning_extra')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'notify_alert', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '1', 'after' => 'notify_warning_extra')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'notify_warning', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '1', 'after' => 'notify_warning_extra')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'notify_alert', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '1', 'after' => 'notify_warning_extra')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'hash', 'type' => 'varchar(32)', 'NULL' => true, 'after' => 'id')); db_execute("ALTER TABLE thold_data REMOVE COLUMN bl_enabled", FALSE); db_execute("ALTER TABLE thold_template REMOVE COLUMN bl_enabled", FALSE); api_plugin_register_hook('thold', 'config_form', 'thold_config_form', 'includes/settings.php'); api_plugin_register_realm('thold', 'notify_lists.php', 'Plugin -> Manage Notification Lists', 1); /* set unique hash values for all thold templates */ $templates = db_fetch_assoc("SELECT id FROM thold_template"); if (sizeof($templates)) { foreach ($templates as $t) { $hash = get_hash_thold_template($t['id']); db_execute("UPDATE thold_template SET hash='{$hash}' WHERE id=" . $t['id']); } } } if (version_compare($oldv, '0.4.7', '<')) { $data = array(); $data['columns'][] = array('name' => 'id', 'type' => 'int(12)', 'NULL' => false, 'unsigned' => true, 'auto_increment' => true); $data['columns'][] = array('name' => 'host_id', 'type' => 'int(12)', 'unsigned' => true, 'NULL' => false); $data['primary'] = 'id'; $data['type'] = 'InnoDB'; $data['comment'] = 'Table of Devices in a Down State'; api_plugin_db_table_create('thold', 'plugin_thold_host_failed', $data); db_execute("DELETE FROM settings WHERE name='thold_failed_hosts'"); /* increase the size of the settings table */ db_execute("ALTER TABLE settings MODIFY column `value` varchar(1024) not null default ''"); } if (version_compare($oldv, '0.6', '<')) { api_plugin_db_add_column('thold', 'thold_data', array('name' => 'snmp_event_category', 'type' => 'varchar(255)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'snmp_event_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '3')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'snmp_event_warning_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '2')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'thold_daemon_pid', 'type' => 'varchar(25)', 'NULL' => false, 'default' => '')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'snmp_event_category', 'type' => 'varchar(255)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'snmp_event_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '3')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'snmp_event_warning_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '2')); $data = array(); $data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false); $data['columns'][] = array('name' => 'pid', 'type' => 'varchar(25)', 'NULL' => false); $data['columns'][] = array('name' => 'rrd_reindexed', 'type' => 'varchar(600)', 'NULL' => false); $data['columns'][] = array('name' => 'rrd_time_reindexed', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false); $data['keys'][] = array('name' => 'id', 'columns' => 'id`, `pid'); $data['type'] = 'InnoDB'; $data['comment'] = 'Table of Poller Outdata needed for queued daemon processes'; api_plugin_db_table_create('thold', 'plugin_thold_daemon_data', $data); $data = array(); $data['columns'][] = array('name' => 'pid', 'type' => 'varchar(25)', 'NULL' => false); $data['columns'][] = array('name' => 'start', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'end', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'processed_items', 'type' => 'mediumint(8)', 'NULL' => false, 'default' => '0'); $data['primary'] = 'pid'; $data['type'] = 'InnoDB'; $data['comment'] = 'Table of Thold Daemon Processes being queued'; api_plugin_db_table_create('thold', 'plugin_thold_daemon_processes', $data); // Rename some columns db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN rra_id local_data_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN data_id data_template_rrd_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN template thold_template_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN data_template data_template_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN graph_id local_graph_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN graph_template graph_template_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE plugin_thold_log CHANGE COLUMN graph_id local_graph_id int(11) UNSIGNED NOT NULL default "0"'); } if (version_compare($oldv, '1.0', '<')) { $data = array(); $data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'unsigned' => true, 'NULL' => false, 'auto_increment' => true); $data['columns'][] = array('name' => 'device_template_id', 'type' => 'int(11)', 'unsigned' => true, 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'thold_template_id', 'type' => 'int(11)', 'unsigned' => true, 'NULL' => false, 'default' => '0'); $data['primary'] = 'id'; $data['type'] = 'InnoDB'; $data['comment'] = 'Table of Device Template Threshold Templates'; api_plugin_db_table_create('thold', 'plugin_thold_device_template', $data); api_plugin_register_hook('thold', 'device_template_edit', 'thold_device_template_edit', 'setup.php'); api_plugin_register_hook('thold', 'device_template_top', 'thold_device_template_top', 'setup.php'); api_plugin_register_hook('thold', 'device_edit_pre_bottom', 'thold_device_edit_pre_bottom', 'setup.php'); api_plugin_register_hook('thold', 'api_device_new', 'thold_api_device_new', 'setup.php'); if (api_plugin_is_enabled('thold')) { api_plugin_enable_hooks('thold'); } } db_execute('UPDATE settings SET value = "' . $v['version'] . '" WHERE name = "plugin_thold_version"'); db_execute('UPDATE plugin_config SET version = "' . $v['version'] . '" WHERE directory = "thold"'); }
function template_save_edit() { /* ================= input validation ================= */ input_validate_input_number(get_request_var_post('id')); input_validate_input_number(get_request_var_post('thold_type')); input_validate_input_number(get_request_var_post('thold_hi')); input_validate_input_number(get_request_var_post('thold_low')); input_validate_input_number(get_request_var_post('thold_fail_trigger')); input_validate_input_number(get_request_var_post('time_hi')); input_validate_input_number(get_request_var_post('time_low')); input_validate_input_number(get_request_var_post('time_fail_trigger')); input_validate_input_number(get_request_var_post('time_fail_length')); input_validate_input_number(get_request_var_post('thold_warning_type')); input_validate_input_number(get_request_var_post('thold_warning_hi')); input_validate_input_number(get_request_var_post('thold_warning_low')); input_validate_input_number(get_request_var_post('thold_warning_fail_trigger')); input_validate_input_number(get_request_var_post('time_warning_hi')); input_validate_input_number(get_request_var_post('time_warning_low')); input_validate_input_number(get_request_var_post('time_warning_fail_trigger')); input_validate_input_number(get_request_var_post('time_warning_fail_length')); input_validate_input_number(get_request_var_post('bl_ref_time_range')); input_validate_input_number(get_request_var_post('bl_pct_down')); input_validate_input_number(get_request_var_post('bl_pct_up')); input_validate_input_number(get_request_var_post('bl_fail_trigger')); input_validate_input_number(get_request_var_post('repeat_alert')); input_validate_input_number(get_request_var_post('data_type')); input_validate_input_number(get_request_var_post('cdef')); input_validate_input_number(get_request_var_post('notify_warning')); input_validate_input_number(get_request_var_post('notify_alert')); /* ==================================================== */ /* clean up date1 string */ if (isset($_POST['name'])) { $_POST['name'] = trim(str_replace(array("\\", "'", '"'), '', get_request_var_post('name'))); } /* save: data_template */ $save['id'] = $_POST['id']; $save['hash'] = get_hash_thold_template($save['id']); $save['name'] = $_POST['name']; $save['thold_type'] = $_POST['thold_type']; // High / Low $save['thold_hi'] = $_POST['thold_hi']; $save['thold_low'] = $_POST['thold_low']; $save['thold_fail_trigger'] = $_POST['thold_fail_trigger']; // Time Based $save['time_hi'] = $_POST['time_hi']; $save['time_low'] = $_POST['time_low']; $save['time_fail_trigger'] = $_POST['time_fail_trigger']; $save['time_fail_length'] = $_POST['time_fail_length']; if (isset($_POST['thold_fail_trigger']) && $_POST['thold_fail_trigger'] != '') { $save['thold_fail_trigger'] = $_POST['thold_fail_trigger']; } else { $alert_trigger = read_config_option('alert_trigger'); if ($alert_trigger != '' && is_numeric($alert_trigger)) { $save['thold_fail_trigger'] = $alert_trigger; } else { $save['thold_fail_trigger'] = 5; } } /*** Warnings ***/ // High / Low Warnings $save['thold_warning_hi'] = $_POST['thold_warning_hi']; $save['thold_warning_low'] = $_POST['thold_warning_low']; $save['thold_warning_fail_trigger'] = $_POST['thold_warning_fail_trigger']; // Time Based Warnings $save['time_warning_hi'] = $_POST['time_warning_hi']; $save['time_warning_low'] = $_POST['time_warning_low']; $save['time_warning_fail_trigger'] = $_POST['time_warning_fail_trigger']; $save['time_warning_fail_length'] = $_POST['time_warning_fail_length']; if (isset($_POST['thold_warning_fail_trigger']) && $_POST['thold_warning_fail_trigger'] != '') { $save['thold_warning_fail_trigger'] = $_POST['thold_warning_fail_trigger']; } else { $alert_trigger = read_config_option('alert_trigger'); if ($alert_trigger != '' && is_numeric($alert_trigger)) { $save['thold_warning_fail_trigger'] = $alert_trigger; } else { $save['thold_warning_fail_trigger'] = 5; } } if (isset($_POST['thold_enabled'])) { $save['thold_enabled'] = 'on'; } else { $save['thold_enabled'] = 'off'; } if (isset($_POST['exempt'])) { $save['exempt'] = 'on'; } else { $save['exempt'] = 'off'; } if (isset($_POST['restored_alert'])) { $save['restored_alert'] = 'on'; } else { $save['restored_alert'] = 'off'; } if (isset($_POST['bl_ref_time_range']) && $_POST['bl_ref_time_range'] != '') { $save['bl_ref_time_range'] = $_POST['bl_ref_time_range']; } else { $alert_bl_timerange_def = read_config_option('alert_bl_timerange_def'); if ($alert_bl_timerange_def != '' && is_numeric($alert_bl_timerange_def)) { $save['bl_ref_time_range'] = $alert_bl_timerange_def; } else { $save['bl_ref_time_range'] = 10800; } } $save['bl_pct_down'] = $_POST['bl_pct_down']; $save['bl_pct_up'] = $_POST['bl_pct_up']; if (isset($_POST['bl_fail_trigger']) && $_POST['bl_fail_trigger'] != '') { $save['bl_fail_trigger'] = $_POST['bl_fail_trigger']; } else { $alert_bl_trigger = read_config_option('alert_bl_trigger'); if ($alert_bl_trigger != '' && is_numeric($alert_bl_trigger)) { $save['bl_fail_trigger'] = $alert_bl_trigger; } else { $save['bl_fail_trigger'] = 3; } } if (isset($_POST['repeat_alert']) && $_POST['repeat_alert'] != '') { $save['repeat_alert'] = $_POST['repeat_alert']; } else { $alert_repeat = read_config_option('alert_repeat'); if ($alert_repeat != '' && is_numeric($alert_repeat)) { $save['repeat_alert'] = $alert_repeat; } else { $save['repeat_alert'] = 12; } } $save['notify_extra'] = $_POST['notify_extra']; $save['notify_warning_extra'] = $_POST['notify_warning_extra']; $save['notify_warning'] = $_POST['notify_warning']; $save['notify_alert'] = $_POST['notify_alert']; $save['cdef'] = $_POST['cdef']; $save['data_type'] = $_POST['data_type']; $save['percent_ds'] = $_POST['percent_ds']; $save['expression'] = $_POST['expression']; if (!is_error_message()) { $id = sql_save($save, 'thold_template'); if ($id) { raise_message(1); if (isset($_POST['notify_accounts']) && is_array($_POST['notify_accounts'])) { thold_save_template_contacts($id, $_POST['notify_accounts']); } elseif (!isset($_POST['notify_accounts'])) { thold_save_template_contacts($id, array()); } thold_template_update_thresholds($id); plugin_thold_log_changes($id, 'modified_template', $save); } else { raise_message(2); } } if (is_error_message() || empty($_POST['id'])) { header('Location: thold_templates.php?action=edit&id=' . (empty($id) ? $_POST['id'] : $id)); } else { header('Location: thold_templates.php'); } }