function gpsmap_setup_database() { api_plugin_db_add_column('gpsmap', 'host', array('name' => 'latitude', 'type' => 'decimal(13,10)', 'NULL' => false, 'default' => '0', 'after' => 'availability')); api_plugin_db_add_column('gpsmap', 'host', array('name' => 'longitude', 'type' => 'decimal(13,10)', 'NULL' => false, 'default' => '0', 'after' => 'availability')); api_plugin_db_add_column('gpsmap', 'host', array('name' => 'GPScoverage', 'type' => 'varchar(3)', 'NULL' => false, 'default' => 'on', 'after' => 'availability')); api_plugin_db_add_column('gpsmap', 'host', array('name' => 'start', 'type' => 'int(3)', 'NULL' => false, 'default' => '0', 'after' => 'availability')); api_plugin_db_add_column('gpsmap', 'host', array('name' => 'stop', 'type' => 'int(3)', 'NULL' => false, 'default' => '360', 'after' => 'availability')); api_plugin_db_add_column('gpsmap', 'host', array('name' => 'groupnum', 'type' => 'int(3)', 'NULL' => false, 'default' => '0', 'after' => 'availability')); api_plugin_db_add_column('gpsmap', 'host', array('name' => 'rdistance', 'type' => 'decimal(10,6)', 'NULL' => false, 'default' => '0', 'after' => 'availability')); $data = array(); $data['columns'][] = array('name' => 'templateID', 'type' => 'int(11)', 'NULL' => true); $data['columns'][] = array('name' => 'templateName', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'upimage', 'type' => 'varchar(255)', 'NULL' => true); $data['columns'][] = array('name' => 'recoverimage', 'type' => 'varchar(255)', 'NULL' => true); $data['columns'][] = array('name' => 'downimage', 'type' => 'varchar(255)', 'NULL' => true); $data['columns'][] = array('name' => 'AP', 'type' => 'int(1)', 'NULL' => true); $data['type'] = 'MyISAM'; $data['comment'] = 'GPSMap icon template'; api_plugin_db_table_create('gpsmap', 'gpsmap_templates', $data); mysql_query('UPDATE plugin_config SET version = "' . $v['version'] . '" WHERE directory = "gpsmap"'); }
function api_plugin_upgrade_table ($plugin, $table, $data) { global $config, $database_default; include_once($config['library_path'] . '/database.php'); $result = db_fetch_assoc('SHOW tables FROM `' . $database_default . '`') or die (mysql_error()); $tables = array(); foreach($result as $index => $arr) { foreach ($arr as $t) { $tables[] = $t; } } if (in_array($table, $tables)) { $cols = array(); $result = db_fetch_assoc("SHOW columns FROM $table") or die ('ERROR: Can not display columns!'); foreach($result as $index => $t) { $cols[$t['Field']] = $t; } foreach ($data['columns'] as $column) { if (isset($column['name'])) { if (isset($cols[$column['name']])) { $c = $cols[$column['name']]; $ok = true; if (strstr($c['Type'], 'unsigned')) { $c['unsigned'] = true; $c['Type'] = trim(str_replace('unsigned', '', $c['Type'])); } $c['Type'] = str_replace(' ', '', $c['Type']); $column['type'] = str_replace(' ', '', $column['type']); if (strtolower($column['type']) != strtolower($c['Type'])) { $ok = FALSE; } if (($column['NULL'] == FALSE && $c['Null'] != 'NO') || ($column['NULL'] == TRUE && $c['Null'] != 'YES')) { $ok = FALSE; } if (isset($column['auto_increment']) && ($column['auto_increment'] == 1 && isset($c['Extra']) && $c['Extra'] != 'auto_increment')) { $ok = FALSE; } else if (isset($c['Extra']) && $c['Extra'] == 'auto_increment' && !isset($column['auto_increment'])) { $ok = FALSE; } if (isset($column['unsigned']) && $column['unsigned'] != $c['unsigned']) { $ok = FALSE; } if (isset($column['default']) && $column['default'] != $c['Default']) { $ok = FALSE; } if (!$ok) { $sql = 'ALTER TABLE `' . $table . '` CHANGE `' . $column['name'] . '` `' . $column['name'] . '`'; if (isset($column['type'])) $sql .= ' ' . $column['type']; if (isset($column['unsigned'])) $sql .= ' unsigned'; if (isset($column['NULL']) && $column['NULL'] == FALSE) $sql .= ' NOT NULL'; if (isset($column['NULL']) && $column['NULL'] == true && !isset($column['default'])) $sql .= ' default NULL'; if (isset($column['default'])) $sql .= ' default ' . (is_numeric($column['default']) ? $column['default'] : "'" . $column['default'] . "'"); if (isset($column['auto_increment'])) $sql .= ' auto_increment'; if (isset($column['after'])) $sql .= ' AFTER ' . $column['after']; db_execute($sql); } } else { // Column does not exist api_plugin_db_add_column ($plugin, $table, $column); } } } // Find extra columns in the Database foreach ($cols as $c) { $found = FALSE; foreach ($data['columns'] as $d) { if ($c['Field'] == $d['name']) { $found = true; } } if ($found == FALSE) { // Extra Column in the Table //db_execute('ALTER TABLE `' . $table . '` DROP `' . $c['Field'] . '`'); } } // Check for Primary $result = db_fetch_assoc('SHOW INDEX FROM `' . $table . '`') or die (mysql_error()); if (isset($data['primary'])) { foreach ($data['keys'] as $d) { $found = FALSE; foreach($result as $index) { if ($index['Column_name'] == $d['name'] && $index['Key_name'] == 'PRIMARY') { $found = true; } } if (!$found) { db_execute('ALTER TABLE `' . $table . '` ADD PRIMARY KEY ( `' . $d['name'] . '` )'); } } } // Check Indexes foreach ($data['keys'] as $d) { $found = FALSE; foreach($result as $index) { if ($index['Column_name'] == $d['name'] && $d['name'] == $index['Key_name']) { // INDEX exists, and its not PRIMARY $found = true; } } if (!$found) { if (isset($d['unique']) && $d['unique']) { db_execute('ALTER TABLE `' . $table . '` ADD UNIQUE ( `' . $d['name'] . '` )'); } else { db_execute('ALTER TABLE `' . $table . '` ADD INDEX ( `' . $d['name'] . '` )'); } } } // Check Type $result = db_fetch_row('SHOW TABLE STATUS FROM `' . $database_default . '` WHERE Name LIKE \'' . $table . '\'') or die (mysql_error()); if (isset($result['Engine']) && strtolower($data['type']) != strtolower($result['Engine'])) { // Wrong Type db_execute('ALTER TABLE `' . $table . '` ENGINE = ' . $data['type']); } } else { // Table does not exist, so create it api_plugin_db_table_create ($plugin, $table, $data); } }
function thold_setup_database() { $data = array(); $data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true); $data['columns'][] = array('name' => 'name', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'local_data_id', 'type' => 'int(11)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'data_template_rrd_id', 'type' => 'int(11)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'local_graph_id', 'type' => 'int(11)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'graph_template_id', 'type' => 'int(11)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'data_template_id', 'type' => 'int(11)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'thold_hi', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'thold_low', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'thold_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'thold_fail_count', 'type' => 'int(11)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'time_hi', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'time_low', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'time_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1); $data['columns'][] = array('name' => 'time_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1); $data['columns'][] = array('name' => 'thold_warning_hi', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'thold_warning_low', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'thold_warning_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'thold_warning_fail_count', 'type' => 'int(11)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'time_warning_hi', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'time_warning_low', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'time_warning_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1); $data['columns'][] = array('name' => 'time_warning_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1); $data['columns'][] = array('name' => 'thold_alert', 'type' => 'int(1)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'thold_enabled', 'type' => "enum('on','off')", 'NULL' => false, 'default' => 'on'); $data['columns'][] = array('name' => 'thold_type', 'type' => 'int (3)', 'NULL' => false, 'default' => 0); $data['columns'][] = array('name' => 'bl_ref_time_range', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'bl_pct_down', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'bl_pct_up', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'bl_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'bl_fail_count', 'type' => 'int(11)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'bl_alert', 'type' => 'int(2)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'lastread', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'lasttime', 'type' => 'timestamp', 'NULL' => false, 'default' => '0000-00-00 00:00:00'); $data['columns'][] = array('name' => 'oldvalue', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'repeat_alert', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'notify_default', 'type' => "enum('on','off')", 'NULL' => true); $data['columns'][] = array('name' => 'notify_extra', 'type' => 'varchar(512)', 'NULL' => true); $data['columns'][] = array('name' => 'notify_warning_extra', 'type' => 'varchar(512)', 'NULL' => true); $data['columns'][] = array('name' => 'notify_warning', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'notify_alert', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'host_id', 'type' => 'int(10)', 'NULL' => true); $data['columns'][] = array('name' => 'syslog_priority', 'type' => 'int(2)', 'NULL' => false, 'default' => '3'); $data['columns'][] = array('name' => 'data_type', 'type' => 'int(12)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'cdef', 'type' => 'int(11)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'percent_ds', 'type' => 'varchar(64)', 'NULL' => false, 'default' => ''); $data['columns'][] = array('name' => 'expression', 'type' => 'varchar(70)', 'NULL' => false, 'default' => ''); $data['columns'][] = array('name' => 'thold_template_id', 'type' => 'int(11)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'template_enabled', 'type' => 'char(3)', 'NULL' => false, 'default' => ''); $data['columns'][] = array('name' => 'tcheck', 'type' => 'int(1)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'exempt', 'type' => 'char(3)', 'NULL' => false, 'default' => ''); $data['columns'][] = array('name' => 'restored_alert', 'type' => 'char(3)', 'NULL' => false, 'default' => ''); $data['columns'][] = array('name' => 'bl_thold_valid', 'type' => 'int(10)', 'NULL' => false, 'default' => '0', 'unsigned' => true); $data['columns'][] = array('name' => 'snmp_event_category', 'type' => 'varchar(255)', 'NULL' => true); $data['columns'][] = array('name' => 'snmp_event_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '3'); $data['columns'][] = array('name' => 'snmp_event_warning_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '2'); $data['columns'][] = array('name' => 'thold_daemon_pid', 'type' => 'varchar(25)', 'NULL' => false, 'default' => ''); $data['primary'] = 'id'; $data['keys'][] = array('name' => 'host_id', 'columns' => 'host_id'); $data['keys'][] = array('name' => 'local_data_id', 'columns' => 'local_data_id'); $data['keys'][] = array('name' => 'data_template_rrd_id', 'columns' => 'data_template_rrd_id'); $data['keys'][] = array('name' => 'local_graph_id', 'columns' => 'local_graph_id'); $data['keys'][] = array('name' => 'thold_template_id', 'columns' => 'thold_template_id'); $data['keys'][] = array('name' => 'thold_enabled', 'columns' => 'thold_enabled'); $data['keys'][] = array('name' => 'template_enabled', 'columns' => 'template_enabled'); $data['keys'][] = array('name' => 'tcheck', 'columns' => 'tcheck'); $data['type'] = 'InnoDB'; $data['comment'] = 'Threshold data'; api_plugin_db_table_create('thold', 'thold_data', $data); $data = array(); $data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true); $data['columns'][] = array('name' => 'hash', 'type' => 'varchar(32)', 'NULL' => false); $data['columns'][] = array('name' => 'name', 'type' => 'varchar(100)', 'NULL' => false, 'default' => ''); $data['columns'][] = array('name' => 'data_template_id', 'type' => 'int(10)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'data_template_name', 'type' => 'varchar(100)', 'NULL' => false, 'default' => ''); $data['columns'][] = array('name' => 'data_source_id', 'type' => 'int(10)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'data_source_name', 'type' => 'varchar(100)', 'NULL' => false, 'default' => ''); $data['columns'][] = array('name' => 'data_source_friendly', 'type' => 'varchar(100)', 'NULL' => false, 'default' => ''); $data['columns'][] = array('name' => 'thold_hi', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'thold_low', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'thold_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'time_hi', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'time_low', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'time_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1); $data['columns'][] = array('name' => 'time_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1); $data['columns'][] = array('name' => 'thold_warning_hi', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'thold_warning_low', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'thold_warning_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'thold_warning_fail_count', 'type' => 'int(11)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'time_warning_hi', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'time_warning_low', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'time_warning_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1); $data['columns'][] = array('name' => 'time_warning_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1); $data['columns'][] = array('name' => 'thold_enabled', 'type' => "enum('on','off')", 'NULL' => false, 'default' => 'on'); $data['columns'][] = array('name' => 'thold_type', 'type' => 'int (3)', 'NULL' => false, 'default' => 0); $data['columns'][] = array('name' => 'bl_ref_time_range', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'bl_pct_down', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'bl_pct_up', 'type' => 'varchar(100)', 'NULL' => true); $data['columns'][] = array('name' => 'bl_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'bl_fail_count', 'type' => 'int(11)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'bl_alert', 'type' => 'int(2)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'repeat_alert', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'notify_default', 'type' => "enum('on','off')", 'NULL' => true); $data['columns'][] = array('name' => 'notify_extra', 'type' => 'varchar(512)', 'NULL' => true); $data['columns'][] = array('name' => 'notify_warning_extra', 'type' => 'varchar(512)', 'NULL' => true); $data['columns'][] = array('name' => 'notify_warning', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'notify_alert', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true); $data['columns'][] = array('name' => 'data_type', 'type' => 'int(12)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'cdef', 'type' => 'int(11)', 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'percent_ds', 'type' => 'varchar(64)', 'NULL' => false, 'default' => ''); $data['columns'][] = array('name' => 'expression', 'type' => 'varchar(70)', 'NULL' => false, 'default' => ''); $data['columns'][] = array('name' => 'exempt', 'type' => 'char(3)', 'NULL' => false, 'default' => ''); $data['columns'][] = array('name' => 'restored_alert', 'type' => 'char(3)', 'NULL' => false, 'default' => ''); $data['columns'][] = array('name' => 'snmp_event_category', 'type' => 'varchar(255)', 'NULL' => true); $data['columns'][] = array('name' => 'snmp_event_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '3'); $data['columns'][] = array('name' => 'snmp_event_warning_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '2'); $data['primary'] = 'id'; $data['keys'][] = array('name' => 'id', 'columns' => 'id'); $data['keys'][] = array('name' => 'data_source_id', 'columns' => 'data_source_id'); $data['keys'][] = array('name' => 'data_template_id', 'columns' => 'data_template_id'); $data['type'] = 'InnoDB'; $data['comment'] = 'Table of thresholds defaults for graphs'; api_plugin_db_table_create('thold', 'thold_template', $data); $data = array(); $data['columns'][] = array('name' => 'id', 'type' => 'int(12)', 'NULL' => false, 'auto_increment' => true); $data['columns'][] = array('name' => 'user_id', 'type' => 'int(12)', 'NULL' => false); $data['columns'][] = array('name' => 'type', 'type' => 'varchar(32)', 'NULL' => false); $data['columns'][] = array('name' => 'data', 'type' => 'text', 'NULL' => false); $data['primary'] = 'id'; $data['keys'][] = array('name' => 'type', 'columns' => 'type'); $data['keys'][] = array('name' => 'user_id', 'columns' => 'user_id'); $data['unique_keys'][] = array('name' => 'user_id_type', 'columns' => 'user_id`, `type'); $data['type'] = 'InnoDB'; $data['comment'] = 'Table of threshold contacts'; api_plugin_db_table_create('thold', 'plugin_thold_contacts', $data); $data = array(); $data['columns'][] = array('name' => 'template_id', 'type' => 'int(12)', 'NULL' => false); $data['columns'][] = array('name' => 'contact_id', 'type' => 'int(12)', 'NULL' => false); $data['keys'][] = array('name' => 'template_id', 'columns' => 'template_id'); $data['keys'][] = array('name' => 'contact_id', 'columns' => 'contact_id'); $data['type'] = 'InnoDB'; $data['comment'] = 'Table of Tholds Template Contacts'; api_plugin_db_table_create('thold', 'plugin_thold_template_contact', $data); $data = array(); $data['columns'][] = array('name' => 'thold_id', 'type' => 'int(12)', 'NULL' => false); $data['columns'][] = array('name' => 'contact_id', 'type' => 'int(12)', 'NULL' => false); $data['keys'][] = array('name' => 'thold_id', 'columns' => 'thold_id'); $data['keys'][] = array('name' => 'contact_id', 'columns' => 'contact_id'); $data['type'] = 'InnoDB'; $data['comment'] = 'Table of Tholds Threshold Contacts'; api_plugin_db_table_create('thold', 'plugin_thold_threshold_contact', $data); $data = array(); $data['columns'][] = array('name' => 'id', 'type' => 'int(12)', 'NULL' => false, 'auto_increment' => true); $data['columns'][] = array('name' => 'time', 'type' => 'int(24)', 'NULL' => false); $data['columns'][] = array('name' => 'host_id', 'type' => 'int(10)', 'NULL' => false); $data['columns'][] = array('name' => 'local_graph_id', 'type' => 'int(10)', 'NULL' => false); $data['columns'][] = array('name' => 'threshold_id', 'type' => 'int(10)', 'NULL' => false); $data['columns'][] = array('name' => 'threshold_value', 'type' => 'varchar(64)', 'NULL' => false); $data['columns'][] = array('name' => 'current', 'type' => 'varchar(64)', 'NULL' => false); $data['columns'][] = array('name' => 'status', 'type' => 'int(5)', 'NULL' => false); $data['columns'][] = array('name' => 'type', 'type' => 'int(5)', 'NULL' => false); $data['columns'][] = array('name' => 'description', 'type' => 'varchar(255)', 'NULL' => false); $data['primary'] = 'id'; $data['keys'][] = array('name' => 'time', 'columns' => 'time'); $data['keys'][] = array('name' => 'host_id', 'columns' => 'host_id'); $data['keys'][] = array('name' => 'local_graph_id', 'columns' => 'local_graph_id'); $data['keys'][] = array('name' => 'threshold_id', 'columns' => 'threshold_id'); $data['keys'][] = array('name' => 'status', 'columns' => 'status'); $data['keys'][] = array('name' => 'type', 'columns' => 'type'); $data['type'] = 'InnoDB'; $data['comment'] = 'Table of All Threshold Breaches'; api_plugin_db_table_create('thold', 'plugin_thold_log', $data); $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_register_hook('thold', 'host_edit_bottom', 'thold_host_edit_bottom', 'setup.php'); api_plugin_db_add_column('thold', 'host', array('name' => 'thold_send_email', 'type' => 'int(10)', 'NULL' => false, 'default' => '1', 'after' => 'disabled')); api_plugin_db_add_column('thold', 'host', array('name' => 'thold_host_email', 'type' => 'int(10)', 'NULL' => false, 'after' => 'thold_send_email')); $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); $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); $data = array(); $data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'unsigned' => true, 'NULL' => false, 'auto_increment' => true); $data['columns'][] = array('name' => 'host_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_host_template', $data); $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)'); } /* increase the size of the settings table */ db_execute("ALTER TABLE settings MODIFY column `value` varchar(4096) not null default ''"); }
function monitor_setup_table() { api_plugin_db_add_column('monitor', 'host', array('name' => 'monitor', 'type' => 'char(3)', 'NULL' => false, 'default' => 'on', 'after' => 'disabled')); api_plugin_db_add_column('monitor', 'host', array('name' => 'monitor_text', 'type' => 'text', 'NULL' => false, 'after' => 'monitor')); }
function nmidSmokeping_setup_table_new() { global $config, $database_default; include_once( $config[ "library_path" ] . "/database.php" ); $data = array(); $data[ 'name' ] = 'nwmgmt_smokeping_path'; $data[ 'type' ] = 'varchar(1024)'; $data[ 'NULL' ] = FALSE; $data[ 'default' ] = ''; api_plugin_db_add_column( 'nmidSmokeping', 'host', $data ); $data = array(); $data[ 'name' ] = 'nwmgmt_smokeping_server'; $data[ 'type' ] = 'varchar(1024)'; $data[ 'NULL' ] = FALSE; $data[ 'default' ] = ''; api_plugin_db_add_column( 'nmidSmokeping', 'host', $data ); $data = array(); $data[ 'name' ] = 'nwmgmt_smokeping_probe'; $data[ 'type' ] = 'varchar(255)'; $data[ 'NULL' ] = FALSE; $data[ 'default' ] = ''; api_plugin_db_add_column( 'nmidSmokeping', 'host', $data ); if ( nmidSmokeping_readPluginStatus( 'nmid' ) ) { // fine, no need to add that column again. } else { // nmid is not isntalled, so we need that column added $data = array(); $data[ 'name' ] = 'nwmgmt_settings'; $data[ 'type' ] = 'varchar(12)'; $data[ 'NULL' ] = FALSE; $data[ 'default' ] = 's0000000000'; api_plugin_db_add_column( 'nmid', 'host', $data ); } }