Example #1
0
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"');
}
Example #2
0
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);
	}
}
Example #3
0
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 ''");
}
Example #4
0
function flowview_setup_table()
{
    global $config;
    $data = array();
    $data['columns'][] = array('name' => 'ip', 'type' => 'varchar(32)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'host', 'type' => 'varchar(255)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'time', 'type' => 'int(20)', 'NULL' => false, 'default' => '0');
    $data['keys'][] = array('name' => 'ip', 'columns' => 'ip');
    $data['type'] = 'MEMORY';
    $data['comment'] = 'Plugin Flowview - DNS Cache to help speed things up';
    api_plugin_db_table_create('flowview', 'plugin_flowview_dnscache', $data);
    $data = array();
    $data['columns'][] = array('name' => 'id', 'type' => 'int(12)', 'NULL' => false, 'auto_increment' => true);
    $data['columns'][] = array('name' => 'name', 'type' => 'varchar(64)', 'NULL' => false);
    $data['columns'][] = array('name' => 'folder', 'type' => 'varchar(64)', 'NULL' => false);
    $data['columns'][] = array('name' => 'allowfrom', 'type' => 'varchar(32)', 'NULL' => false, 'default' => '0');
    $data['columns'][] = array('name' => 'port', 'type' => 'int(12)', 'NULL' => false);
    $data['columns'][] = array('name' => 'nesting', 'type' => 'varchar(4)', 'NULL' => false, 'default' => '-1');
    $data['columns'][] = array('name' => 'version', 'type' => 'varchar(12)', 'NULL' => false, 'default' => '5');
    $data['columns'][] = array('name' => 'rotation', 'type' => 'int(12)', 'NULL' => false, 'default' => '1439');
    $data['columns'][] = array('name' => 'expire', 'type' => 'int(3)', 'NULL' => false, 'default' => '7');
    $data['columns'][] = array('name' => 'compression', 'type' => 'int(1)', 'NULL' => false, 'default' => '0');
    $data['primary'] = 'id';
    $data['keys'][] = array('name' => 'folder', 'columns' => 'folder');
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Plugin Flowview - List of Devices to collect flows from';
    api_plugin_db_table_create('flowview', 'plugin_flowview_devices', $data);
    $data = array();
    $data['columns'][] = array('name' => 'id', 'type' => 'int(12)', 'NULL' => false, 'auto_increment' => true);
    $data['columns'][] = array('name' => 'name', 'type' => 'varchar(255)', 'NULL' => false);
    $data['columns'][] = array('name' => 'device', 'type' => 'varchar(32)', 'NULL' => false);
    $data['columns'][] = array('name' => 'timespan', 'type' => 'int(11)', 'NULL' => false, 'default' => 0);
    $data['columns'][] = array('name' => 'startdate', 'type' => 'varchar(32)', 'NULL' => false);
    $data['columns'][] = array('name' => 'enddate', 'type' => 'varchar(32)', 'NULL' => false);
    $data['columns'][] = array('name' => 'tosfields', 'type' => 'varchar(32)', 'NULL' => false);
    $data['columns'][] = array('name' => 'tcpflags', 'type' => 'varchar(32)', 'NULL' => false);
    $data['columns'][] = array('name' => 'protocols', 'type' => 'varchar(8)', 'NULL' => false);
    $data['columns'][] = array('name' => 'sourceip', 'type' => 'varchar(255)', 'NULL' => false);
    $data['columns'][] = array('name' => 'sourceport', 'type' => 'varchar(255)', 'NULL' => false);
    $data['columns'][] = array('name' => 'sourceinterface', 'type' => 'varchar(64)', 'NULL' => false);
    $data['columns'][] = array('name' => 'sourceas', 'type' => 'varchar(64)', 'NULL' => false);
    $data['columns'][] = array('name' => 'destip', 'type' => 'varchar(255)', 'NULL' => false);
    $data['columns'][] = array('name' => 'destport', 'type' => 'varchar(255)', 'NULL' => false);
    $data['columns'][] = array('name' => 'destinterface', 'type' => 'varchar(64)', 'NULL' => false);
    $data['columns'][] = array('name' => 'destas', 'type' => 'varchar(64)', 'NULL' => false);
    $data['columns'][] = array('name' => 'statistics', 'type' => 'int(3)', 'NULL' => false);
    $data['columns'][] = array('name' => 'printed', 'type' => 'int(3)', 'NULL' => false);
    $data['columns'][] = array('name' => 'includeif', 'type' => 'int(2)', 'NULL' => false);
    $data['columns'][] = array('name' => 'sortfield', 'type' => 'int(2)', 'NULL' => false);
    $data['columns'][] = array('name' => 'cutofflines', 'type' => 'varchar(8)', 'NULL' => false);
    $data['columns'][] = array('name' => 'cutoffoctets', 'type' => 'varchar(8)', 'NULL' => false);
    $data['columns'][] = array('name' => 'resolve', 'type' => 'varchar(2)', 'NULL' => false);
    $data['primary'] = 'id';
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Plugin Flowview - List of Saved Flow Queries';
    api_plugin_db_table_create('flowview', 'plugin_flowview_queries', $data);
    $data = array();
    $data['columns'][] = array('name' => 'id', 'type' => 'int(12)', 'NULL' => false, 'auto_increment' => true);
    $data['columns'][] = array('name' => 'title', 'type' => 'varchar(128)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'enabled', 'type' => 'varchar(3)', 'NULL' => false, 'default' => 'on');
    $data['columns'][] = array('name' => 'sendinterval', 'type' => 'int(20)', 'NULL' => false);
    $data['columns'][] = array('name' => 'lastsent', 'type' => 'int(20)', 'NULL' => false);
    $data['columns'][] = array('name' => 'start', 'type' => 'datetime', 'NULL' => false);
    $data['columns'][] = array('name' => 'email', 'type' => 'text', 'NULL' => false);
    $data['columns'][] = array('name' => 'savedquery', 'type' => 'int(12)', 'NULL' => false);
    $data['primary'] = 'id';
    $data['keys'][] = array('name' => 'savedquery', 'columns' => 'savedquery');
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Plugin Flowview - Scheduling for running and emails of saved queries';
    api_plugin_db_table_create('flowview', 'plugin_flowview_schedules', $data);
    $data = array();
    $data['columns'][] = array('name' => 'id', 'type' => 'int(12)', 'NULL' => false, 'auto_increment' => true);
    $data['columns'][] = array('name' => 'service', 'type' => 'varchar(20)', 'NULL' => false, 'default' => '');
    $data['columns'][] = array('name' => 'port', 'type' => 'int(12)', 'NULL' => false);
    $data['columns'][] = array('name' => 'proto', 'type' => 'char(4)', 'NULL' => false);
    $data['columns'][] = array('name' => 'description', 'type' => 'varchar(255)', 'NULL' => false, 'default' => '');
    $data['primary'] = 'id';
    $data['type'] = 'InnoDB';
    $data['comment'] = 'Plugin Flowview - Database of well known Ports';
    api_plugin_db_table_create('flowview', 'plugin_flowview_ports', $data);
    $inserts = file($config['base_path'] . '/plugins/flowview/plugin_flowview_ports.sql');
    if (sizeof($inserts)) {
        db_execute('TRUNCATE plugin_flowview_ports');
        foreach ($inserts as $i) {
            db_execute($i);
        }
    }
}
Example #5
0
function maint_setup_database()
{
    $data = array();
    $data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false, 'auto_increment' => true);
    $data['columns'][] = array('name' => 'enabled', 'type' => 'varchar(3)', 'NULL' => false, 'default' => 'on');
    $data['columns'][] = array('name' => 'name', 'type' => 'varchar(128)', 'NULL' => true);
    $data['columns'][] = array('name' => 'mtype', 'type' => 'int(11)', 'NULL' => false);
    $data['columns'][] = array('name' => 'stime', 'type' => 'int(22)', 'NULL' => false);
    $data['columns'][] = array('name' => 'etime', 'type' => 'int(22)', 'NULL' => false);
    $data['columns'][] = array('name' => 'minterval', 'type' => 'int(11)', 'NULL' => false);
    $data['primary'] = 'id';
    $data['keys'][] = array('name' => 'mtype', 'columns' => 'mtype');
    $data['keys'][] = array('name' => 'enabled', 'columns' => 'enabled');
    $data['type'] = 'MyISAM';
    $data['comment'] = 'Maintenance Schedules';
    api_plugin_db_table_create('maint', 'plugin_maint_schedules', $data);
    $data = array();
    $data['columns'][] = array('name' => 'type', 'type' => 'int(6)', 'NULL' => false);
    $data['columns'][] = array('name' => 'host', 'type' => 'int(12)', 'NULL' => false);
    $data['columns'][] = array('name' => 'schedule', 'type' => 'int(12)', 'NULL' => false);
    $data['primary'] = 'type`,`schedule`,`host';
    $data['keys'][] = array('name' => 'type', 'columns' => 'type');
    $data['keys'][] = array('name' => 'schedule', 'columns' => 'schedule');
    $data['type'] = 'MyISAM';
    $data['comment'] = 'Maintenance Schedules Hosts';
    api_plugin_db_table_create('maint', 'plugin_maint_hosts', $data);
}
Example #6
0
function iper_setup_table()
{
    global $config, $database_default;
    include_once $config["library_path"] . "/database.php";
    db_execute('DROP TABLE IF EXISTS `plugin_iper_snmptt`');
    $schema = array();
    $schema['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'unsigned' => true, 'NULL' => false, 'auto_increment' => true);
    $schema['columns'][] = array('name' => 'eventname', 'type' => 'varchar(50)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'eventid', 'type' => 'varchar(50)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'trapoid', 'type' => 'varchar(100)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'enterprise', 'type' => 'varchar(100)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'community', 'type' => 'varchar(20)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'hostname', 'type' => 'varchar(250)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'agentip', 'type' => 'varchar(16)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'category', 'type' => 'varchar(20)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'severity', 'type' => 'varchar(20)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'uptime', 'type' => 'varchar(20)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'traptime', 'type' => 'datetime', 'NULL' => true);
    $schema['columns'][] = array('name' => 'formatline', 'type' => 'text', 'NULL' => true);
    $schema['columns'][] = array('name' => 'created', 'type' => 'timestamp', 'NULL' => true, 'default' => 'CURRENT_TIMESTAMP');
    $schema['primary'] = 'id';
    $schema['keys'][] = array('name' => 'hostname', 'columns' => 'hostname');
    $schema['type'] = 'MyISAM';
    $schema['comment'] = 'snpm trap data';
    api_plugin_db_table_create('iper', 'plugin_iper_snmptt', $schema);
    $schema = array();
    db_execute('DROP TABLE IF EXISTS plugin_iper_snmptt_unk');
    $schema['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'unsigned' => true, 'NULL' => false, 'auto_increment' => true);
    $schema['columns'][] = array('name' => 'trapoid', 'type' => 'varchar(100)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'enterprise', 'type' => 'varchar(100)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'community', 'type' => 'varchar(20)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'hostname', 'type' => 'varchar(250)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'agentip', 'type' => 'varchar(16)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'uptime', 'type' => 'varchar(20)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'traptime', 'type' => 'datetime', 'NULL' => true);
    $schema['columns'][] = array('name' => 'formatline', 'type' => 'text', 'NULL' => true);
    $schema['columns'][] = array('name' => 'created', 'type' => 'timestamp', 'NULL' => true, 'default' => 'CURRENT_TIMESTAMP');
    $schema['primary'] = 'id';
    $schema['keys'][] = array('name' => 'id', 'columns' => 'id');
    $schema['type'] = 'MyISAM';
    $schema['comment'] = 'Unkonwn trap data';
    api_plugin_db_table_create('iper', 'plugin_iper_snmptt_unk', $schema, 1);
    db_execute('DROP TABLE IF EXISTS plugin_iper_syslog');
    $schema = array();
    $schema['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'unsigned' => true, 'NULL' => false, 'auto_increment' => true);
    $schema['columns'][] = array('name' => 'host', 'type' => 'varchar(128)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'sourceip', 'type' => 'varchar(45)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'facility', 'type' => 'varchar(10)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'priority', 'type' => 'varchar(10)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'sys_date', 'type' => 'datetime', 'NULL' => true);
    $schema['columns'][] = array('name' => 'message', 'type' => 'text', 'NULL' => true);
    $schema['columns'][] = array('name' => 'status', 'type' => 'tinyint(4)', 'NULL' => true);
    $schema['columns'][] = array('name' => 'alert', 'type' => 'tinyint(3)', 'NULL' => true);
    $schema['primary'] = 'id';
    $schema['keys'][] = array('name' => 'facility', 'columns' => 'facility');
    $schema['keys'][] = array('name' => 'priority', 'columns' => 'priority');
    $schema['keys'][] = array('name' => 'sourceip', 'columns' => 'sourceip');
    $schema['keys'][] = array('name' => 'status', 'columns' => 'status');
    $schema['keys'][] = array('name' => 'sys_date', 'columns' => 'sys_date');
    $schema['keys'][] = array('name' => 'alert', 'columns' => 'alert');
    $schema['type'] = 'MyISAM';
    $schema['comment'] = 'syslog data';
    api_plugin_db_table_create('iper', 'plugin_iper_syslog', $schema);
    $schema['columns'][6] = array('name' => 'message', 'type' => 'varchar(255)', 'NULL' => true);
    $schema['type'] = 'MEMORY';
    $schema['comment'] = 'syslog imcoming data';
    api_plugin_db_table_create('iper', 'plugin_iper_syslog_incoming', $schema);
}