示例#1
0
function plugin_thold_install()
{
    global $config;
    if (version_compare($config['cacti_version'], '1.0.0') < 0) {
        return false;
    }
    api_plugin_register_hook('thold', 'page_head', 'thold_page_head', 'setup.php');
    api_plugin_register_hook('thold', 'top_header_tabs', 'thold_show_tab', 'includes/tab.php');
    api_plugin_register_hook('thold', 'top_graph_header_tabs', 'thold_show_tab', 'includes/tab.php');
    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_register_hook('thold', 'config_form', 'thold_config_form', 'includes/settings.php');
    api_plugin_register_hook('thold', 'config_settings', 'thold_config_settings', 'includes/settings.php');
    api_plugin_register_hook('thold', 'draw_navigation_text', 'thold_draw_navigation_text', 'includes/settings.php');
    api_plugin_register_hook('thold', 'data_sources_table', 'thold_data_sources_table', 'setup.php');
    api_plugin_register_hook('thold', 'graphs_new_top_links', 'thold_graphs_new', 'setup.php');
    api_plugin_register_hook('thold', 'api_device_save', 'thold_api_device_save', 'setup.php');
    api_plugin_register_hook('thold', 'update_host_status', 'thold_update_host_status', 'includes/polling.php');
    api_plugin_register_hook('thold', 'poller_output', 'thold_poller_output', 'includes/polling.php');
    api_plugin_register_hook('thold', 'device_action_array', 'thold_device_action_array', 'setup.php');
    api_plugin_register_hook('thold', 'device_action_execute', 'thold_device_action_execute', 'setup.php');
    api_plugin_register_hook('thold', 'device_action_prepare', 'thold_device_action_prepare', 'setup.php');
    api_plugin_register_hook('thold', 'host_edit_bottom', 'thold_host_edit_bottom', 'setup.php');
    api_plugin_register_hook('thold', 'user_admin_setup_sql_save', 'thold_user_admin_setup_sql_save', 'setup.php');
    api_plugin_register_hook('thold', 'poller_bottom', 'thold_poller_bottom', 'includes/polling.php');
    api_plugin_register_hook('thold', 'user_admin_edit', 'thold_user_admin_edit', 'setup.php');
    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', 'snmpagent_cache_install', 'thold_snmpagent_cache_install', 'setup.php');
    /* hooks to add dropdown to allow the assignment of a cluster resource */
    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_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');
    api_plugin_register_realm('thold', 'thold.php', __('Plugin -> Configure Thresholds'), 1);
    api_plugin_register_realm('thold', 'thold_templates.php', __('Plugin -> Configure Threshold Templates'), 1);
    api_plugin_register_realm('thold', 'notify_lists.php', __('Plugin -> Manage Notification Lists'), 1);
    api_plugin_register_realm('thold', 'thold_graph.php,graph_thold.php,thold_view_failures.php,thold_view_normal.php,thold_view_recover.php,thold_view_recent.php,thold_view_host.php', __('Plugin -> View Thresholds'), 1);
    include_once $config['base_path'] . '/plugins/thold/includes/database.php';
    thold_setup_database();
    thold_snmpagent_cache_install();
}
示例#2
0
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"');
}