Chinaunix首页 | 论坛 | 博客
  • 博客访问: 129012
  • 博文数量: 10
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 172
  • 用 户 组: 普通用户
  • 注册时间: 2013-07-22 16:29
个人简介

坚持专注,追求卓越。

文章分类

全部博文(10)

文章存档

2015年(3)

2014年(3)

2013年(4)

我的朋友

分类: 系统运维

2015-03-11 09:14:04

ndo2db产生数据库乱码时请用下面两个文件:

适用版本:ndoutils-2.0.0

数据库初始化mysql.sql:


点击(此处)折叠或打开

  1. -- phpMyAdmin SQL Dump
  2. -- version 2.11.8.1
  3. -- http://www.phpmyadmin.net
  4. -- Host: localhost
  5. -- Generation Time: Jan 03, 2009 at 09:24 AM
  6. -- Server version: 5.0.45
  7. -- PHP Version: 5.2.6

  8. SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


  9. --
  10. -- Database: `nagios`
  11. --

  12. -- --------------------------------------------------------

  13. --
  14. -- Table structure for table `monitor_acknowledgements`
  15. --

  16. CREATE TABLE IF NOT EXISTS `monitor_acknowledgements` (
  17.   `acknowledgement_id` int(11) NOT NULL auto_increment,
  18.   `instance_id` smallint(6) NOT NULL default '0',
  19.   `entry_time` datetime NOT NULL default '0000-00-00 00:00:00',
  20.   `entry_time_usec` int(11) NOT NULL default '0',
  21.   `acknowledgement_type` smallint(6) NOT NULL default '0',
  22.   `object_id` int(11) NOT NULL default '0',
  23.   `state` smallint(6) NOT NULL default '0',
  24.   `author_name` varchar(64) NOT NULL default '',
  25.   `comment_data` varchar(255) NOT NULL default '',
  26.   `is_sticky` smallint(6) NOT NULL default '0',
  27.   `persistent_comment` smallint(6) NOT NULL default '0',
  28.   `notify_contacts` smallint(6) NOT NULL default '0',
  29.   PRIMARY KEY (`acknowledgement_id`),
  30.   UNIQUE KEY `instance_id` (`instance_id`, `entry_time`, `entry_time_usec`)
  31. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Current and historical host and service acknowledgements';

  32. -- --------------------------------------------------------

  33. --
  34. -- Table structure for table `monitor_commands`
  35. --

  36. CREATE TABLE IF NOT EXISTS `monitor_commands` (
  37.   `command_id` int(11) NOT NULL auto_increment,
  38.   `instance_id` smallint(6) NOT NULL default '0',
  39.   `config_type` smallint(6) NOT NULL default '0',
  40.   `object_id` int(11) NOT NULL default '0',
  41.   `command_line` varchar(255) NOT NULL default '',
  42.   PRIMARY KEY (`command_id`),
  43.   UNIQUE KEY `instance_id` (`instance_id`,`object_id`,`config_type`)
  44. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Command definitions';

  45. -- --------------------------------------------------------

  46. --
  47. -- Table structure for table `monitor_commenthistory`
  48. --

  49. CREATE TABLE IF NOT EXISTS `monitor_commenthistory` (
  50.   `commenthistory_id` int(11) NOT NULL auto_increment,
  51.   `instance_id` smallint(6) NOT NULL default '0',
  52.   `entry_time` datetime NOT NULL default '0000-00-00 00:00:00',
  53.   `entry_time_usec` int(11) NOT NULL default '0',
  54.   `comment_type` smallint(6) NOT NULL default '0',
  55.   `entry_type` smallint(6) NOT NULL default '0',
  56.   `object_id` int(11) NOT NULL default '0',
  57.   `comment_time` datetime NOT NULL default '0000-00-00 00:00:00',
  58.   `internal_comment_id` int(11) NOT NULL default '0',
  59.   `author_name` varchar(64) NOT NULL default '',
  60.   `comment_data` varchar(255) NOT NULL default '',
  61.   `is_persistent` smallint(6) NOT NULL default '0',
  62.   `comment_source` smallint(6) NOT NULL default '0',
  63.   `expires` smallint(6) NOT NULL default '0',
  64.   `expiration_time` datetime NOT NULL default '0000-00-00 00:00:00',
  65.   `deletion_time` datetime NOT NULL default '0000-00-00 00:00:00',
  66.   `deletion_time_usec` int(11) NOT NULL default '0',
  67.   PRIMARY KEY (`commenthistory_id`),
  68.   UNIQUE KEY `instance_id` (`instance_id`,`comment_time`,`internal_comment_id`)
  69. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historical host and service comments';

  70. -- --------------------------------------------------------

  71. --
  72. -- Table structure for table `monitor_comments`
  73. --

  74. CREATE TABLE IF NOT EXISTS `monitor_comments` (
  75.   `comment_id` int(11) NOT NULL auto_increment,
  76.   `instance_id` smallint(6) NOT NULL default '0',
  77.   `entry_time` datetime NOT NULL default '0000-00-00 00:00:00',
  78.   `entry_time_usec` int(11) NOT NULL default '0',
  79.   `comment_type` smallint(6) NOT NULL default '0',
  80.   `entry_type` smallint(6) NOT NULL default '0',
  81.   `object_id` int(11) NOT NULL default '0',
  82.   `comment_time` datetime NOT NULL default '0000-00-00 00:00:00',
  83.   `internal_comment_id` int(11) NOT NULL default '0',
  84.   `author_name` varchar(64) NOT NULL default '',
  85.   `comment_data` varchar(255) NOT NULL default '',
  86.   `is_persistent` smallint(6) NOT NULL default '0',
  87.   `comment_source` smallint(6) NOT NULL default '0',
  88.   `expires` smallint(6) NOT NULL default '0',
  89.   `expiration_time` datetime NOT NULL default '0000-00-00 00:00:00',
  90.   PRIMARY KEY (`comment_id`),
  91.   UNIQUE KEY `instance_id` (`instance_id`,`comment_time`,`internal_comment_id`)
  92. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

  93. -- --------------------------------------------------------

  94. --
  95. -- Table structure for table `monitor_configfiles`
  96. --

  97. CREATE TABLE IF NOT EXISTS `monitor_configfiles` (
  98.   `configfile_id` int(11) NOT NULL auto_increment,
  99.   `instance_id` smallint(6) NOT NULL default '0',
  100.   `configfile_type` smallint(6) NOT NULL default '0',
  101.   `configfile_path` varchar(255) NOT NULL default '',
  102.   PRIMARY KEY (`configfile_id`),
  103.   UNIQUE KEY `instance_id` (`instance_id`,`configfile_type`,`configfile_path`)
  104. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Configuration files';

  105. -- --------------------------------------------------------

  106. --
  107. -- Table structure for table `monitor_configfilevariables`
  108. --

  109. CREATE TABLE IF NOT EXISTS `monitor_configfilevariables` (
  110.   `configfilevariable_id` int(11) NOT NULL auto_increment,
  111.   `instance_id` smallint(6) NOT NULL default '0',
  112.   `configfile_id` int(11) NOT NULL default '0',
  113.   `varname` varchar(64) NOT NULL default '',
  114.   `varvalue` varchar(255) NOT NULL default '',
  115.   PRIMARY KEY (`configfilevariable_id`)
  116. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Configuration file variables';

  117. -- --------------------------------------------------------

  118. --
  119. -- Table structure for table `monitor_conninfo`
  120. --

  121. CREATE TABLE IF NOT EXISTS `monitor_conninfo` (
  122.   `conninfo_id` int(11) NOT NULL auto_increment,
  123.   `instance_id` smallint(6) NOT NULL default '0',
  124.   `agent_name` varchar(32) NOT NULL default '',
  125.   `agent_version` varchar(8) NOT NULL default '',
  126.   `disposition` varchar(16) NOT NULL default '',
  127.   `connect_source` varchar(16) NOT NULL default '',
  128.   `connect_type` varchar(16) NOT NULL default '',
  129.   `connect_time` datetime NOT NULL default '0000-00-00 00:00:00',
  130.   `disconnect_time` datetime NOT NULL default '0000-00-00 00:00:00',
  131.   `last_checkin_time` datetime NOT NULL default '0000-00-00 00:00:00',
  132.   `data_start_time` datetime NOT NULL default '0000-00-00 00:00:00',
  133.   `data_end_time` datetime NOT NULL default '0000-00-00 00:00:00',
  134.   `bytes_processed` int(11) NOT NULL default '0',
  135.   `lines_processed` int(11) NOT NULL default '0',
  136.   `entries_processed` int(11) NOT NULL default '0',
  137.   PRIMARY KEY (`conninfo_id`)
  138. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='NDO2DB daemon connection information';

  139. -- --------------------------------------------------------

  140. --
  141. -- Table structure for table `monitor_contactgroups`
  142. --

  143. CREATE TABLE IF NOT EXISTS `monitor_contactgroups` (
  144.   `contactgroup_id` int(11) NOT NULL auto_increment,
  145.   `instance_id` smallint(6) NOT NULL default '0',
  146.   `config_type` smallint(6) NOT NULL default '0',
  147.   `contactgroup_object_id` int(11) NOT NULL default '0',
  148.   `alias` varchar(255) NOT NULL default '',
  149.   PRIMARY KEY (`contactgroup_id`),
  150.   UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`contactgroup_object_id`)
  151. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Contactgroup definitions';

  152. -- --------------------------------------------------------

  153. --
  154. -- Table structure for table `monitor_contactgroup_members`
  155. --

  156. CREATE TABLE IF NOT EXISTS `monitor_contactgroup_members` (
  157.   `contactgroup_member_id` int(11) NOT NULL auto_increment,
  158.   `instance_id` smallint(6) NOT NULL default '0',
  159.   `contactgroup_id` int(11) NOT NULL default '0',
  160.   `contact_object_id` int(11) NOT NULL default '0',
  161.   PRIMARY KEY (`contactgroup_member_id`),
  162.   UNIQUE KEY `instance_id` (`contactgroup_id`,`contact_object_id`)
  163. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Contactgroup members';

  164. -- --------------------------------------------------------

  165. --
  166. -- Table structure for table `monitor_contactnotificationmethods`
  167. --

  168. CREATE TABLE IF NOT EXISTS `monitor_contactnotificationmethods` (
  169.   `contactnotificationmethod_id` int(11) NOT NULL auto_increment,
  170.   `instance_id` smallint(6) NOT NULL default '0',
  171.   `contactnotification_id` int(11) NOT NULL default '0',
  172.   `start_time` datetime NOT NULL default '0000-00-00 00:00:00',
  173.   `start_time_usec` int(11) NOT NULL default '0',
  174.   `end_time` datetime NOT NULL default '0000-00-00 00:00:00',
  175.   `end_time_usec` int(11) NOT NULL default '0',
  176.   `command_object_id` int(11) NOT NULL default '0',
  177.   `command_args` varchar(255) NOT NULL default '',
  178.   PRIMARY KEY (`contactnotificationmethod_id`),
  179.   UNIQUE KEY `instance_id` (`instance_id`,`contactnotification_id`,`start_time`,`start_time_usec`)
  180. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historical record of contact notification methods';

  181. -- --------------------------------------------------------

  182. --
  183. -- Table structure for table `monitor_contactnotifications`
  184. --

  185. CREATE TABLE IF NOT EXISTS `monitor_contactnotifications` (
  186.   `contactnotification_id` int(11) NOT NULL auto_increment,
  187.   `instance_id` smallint(6) NOT NULL default '0',
  188.   `notification_id` int(11) NOT NULL default '0',
  189.   `contact_object_id` int(11) NOT NULL default '0',
  190.   `start_time` datetime NOT NULL default '0000-00-00 00:00:00',
  191.   `start_time_usec` int(11) NOT NULL default '0',
  192.   `end_time` datetime NOT NULL default '0000-00-00 00:00:00',
  193.   `end_time_usec` int(11) NOT NULL default '0',
  194.   PRIMARY KEY (`contactnotification_id`),
  195.   UNIQUE KEY `instance_id` (`instance_id`,`contact_object_id`,`start_time`,`start_time_usec`)
  196. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historical record of contact notifications';

  197. -- --------------------------------------------------------

  198. --
  199. -- Table structure for table `monitor_contacts`
  200. --

  201. CREATE TABLE IF NOT EXISTS `monitor_contacts` (
  202.   `contact_id` int(11) NOT NULL auto_increment,
  203.   `instance_id` smallint(6) NOT NULL default '0',
  204.   `config_type` smallint(6) NOT NULL default '0',
  205.   `contact_object_id` int(11) NOT NULL default '0',
  206.   `alias` varchar(64) NOT NULL default '',
  207.   `email_address` varchar(255) NOT NULL default '',
  208.   `pager_address` varchar(64) NOT NULL default '',
  209.   `minimum_importance` int(11) NOT NULL default '0',
  210.   `host_timeperiod_object_id` int(11) NOT NULL default '0',
  211.   `service_timeperiod_object_id` int(11) NOT NULL default '0',
  212.   `host_notifications_enabled` smallint(6) NOT NULL default '0',
  213.   `service_notifications_enabled` smallint(6) NOT NULL default '0',
  214.   `can_submit_commands` smallint(6) NOT NULL default '0',
  215.   `notify_service_recovery` smallint(6) NOT NULL default '0',
  216.   `notify_service_warning` smallint(6) NOT NULL default '0',
  217.   `notify_service_unknown` smallint(6) NOT NULL default '0',
  218.   `notify_service_critical` smallint(6) NOT NULL default '0',
  219.   `notify_service_flapping` smallint(6) NOT NULL default '0',
  220.   `notify_service_downtime` smallint(6) NOT NULL default '0',
  221.   `notify_host_recovery` smallint(6) NOT NULL default '0',
  222.   `notify_host_down` smallint(6) NOT NULL default '0',
  223.   `notify_host_unreachable` smallint(6) NOT NULL default '0',
  224.   `notify_host_flapping` smallint(6) NOT NULL default '0',
  225.   `notify_host_downtime` smallint(6) NOT NULL default '0',
  226.   PRIMARY KEY (`contact_id`),
  227.   UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`contact_object_id`)
  228. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Contact definitions';

  229. -- --------------------------------------------------------

  230. --
  231. -- Table structure for table `monitor_contactstatus`
  232. --

  233. CREATE TABLE IF NOT EXISTS `monitor_contactstatus` (
  234.   `contactstatus_id` int(11) NOT NULL auto_increment,
  235.   `instance_id` smallint(6) NOT NULL default '0',
  236.   `contact_object_id` int(11) NOT NULL default '0',
  237.   `status_update_time` datetime NOT NULL default '0000-00-00 00:00:00',
  238.   `host_notifications_enabled` smallint(6) NOT NULL default '0',
  239.   `service_notifications_enabled` smallint(6) NOT NULL default '0',
  240.   `last_host_notification` datetime NOT NULL default '0000-00-00 00:00:00',
  241.   `last_service_notification` datetime NOT NULL default '0000-00-00 00:00:00',
  242.   `modified_attributes` int(11) NOT NULL default '0',
  243.   `modified_host_attributes` int(11) NOT NULL default '0',
  244.   `modified_service_attributes` int(11) NOT NULL default '0',
  245.   PRIMARY KEY (`contactstatus_id`),
  246.   UNIQUE KEY `contact_object_id` (`contact_object_id`)
  247. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Contact status';

  248. -- --------------------------------------------------------

  249. --
  250. -- Table structure for table `monitor_contact_addresses`
  251. --

  252. CREATE TABLE IF NOT EXISTS `monitor_contact_addresses` (
  253.   `contact_address_id` int(11) NOT NULL auto_increment,
  254.   `instance_id` smallint(6) NOT NULL default '0',
  255.   `contact_id` int(11) NOT NULL default '0',
  256.   `address_number` smallint(6) NOT NULL default '0',
  257.   `address` varchar(255) NOT NULL default '',
  258.   PRIMARY KEY (`contact_address_id`),
  259.   UNIQUE KEY `contact_id` (`contact_id`,`address_number`)
  260. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Contact addresses';

  261. -- --------------------------------------------------------

  262. --
  263. -- Table structure for table `monitor_contact_notificationcommands`
  264. --

  265. CREATE TABLE IF NOT EXISTS `monitor_contact_notificationcommands` (
  266.   `contact_notificationcommand_id` int(11) NOT NULL auto_increment,
  267.   `instance_id` smallint(6) NOT NULL default '0',
  268.   `contact_id` int(11) NOT NULL default '0',
  269.   `notification_type` smallint(6) NOT NULL default '0',
  270.   `command_object_id` int(11) NOT NULL default '0',
  271.   `command_args` varchar(255) NOT NULL default '',
  272.   PRIMARY KEY (`contact_notificationcommand_id`),
  273.   UNIQUE KEY `contact_id` (`contact_id`,`notification_type`,`command_object_id`,`command_args`)
  274. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Contact host and service notification commands';

  275. -- --------------------------------------------------------

  276. --
  277. -- Table structure for table `monitor_customvariables`
  278. --

  279. CREATE TABLE IF NOT EXISTS `monitor_customvariables` (
  280.   `customvariable_id` int(11) NOT NULL auto_increment,
  281.   `instance_id` smallint(6) NOT NULL default '0',
  282.   `object_id` int(11) NOT NULL default '0',
  283.   `config_type` smallint(6) NOT NULL default '0',
  284.   `has_been_modified` smallint(6) NOT NULL default '0',
  285.   `varname` varchar(255) NOT NULL default '',
  286.   `varvalue` varchar(255) NOT NULL default '',
  287.   PRIMARY KEY (`customvariable_id`),
  288.   UNIQUE KEY `object_id_2` (`object_id`,`config_type`,`varname`),
  289.   KEY `varname` (`varname`)
  290. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Custom variables';

  291. -- --------------------------------------------------------

  292. --
  293. -- Table structure for table `monitor_customvariablestatus`
  294. --

  295. CREATE TABLE IF NOT EXISTS `monitor_customvariablestatus` (
  296.   `customvariablestatus_id` int(11) NOT NULL auto_increment,
  297.   `instance_id` smallint(6) NOT NULL default '0',
  298.   `object_id` int(11) NOT NULL default '0',
  299.   `status_update_time` datetime NOT NULL default '0000-00-00 00:00:00',
  300.   `has_been_modified` smallint(6) NOT NULL default '0',
  301.   `varname` varchar(255) NOT NULL default '',
  302.   `varvalue` varchar(255) NOT NULL default '',
  303.   PRIMARY KEY (`customvariablestatus_id`),
  304.   UNIQUE KEY `object_id_2` (`object_id`,`varname`),
  305.   KEY `varname` (`varname`)
  306. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Custom variable status information';

  307. -- --------------------------------------------------------

  308. --
  309. -- Table structure for table `monitor_dbversion`
  310. --

  311. CREATE TABLE IF NOT EXISTS `monitor_dbversion` (
  312.   `name` varchar(10) NOT NULL default '',
  313.   `version` varchar(10) NOT NULL default ''
  314. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

  315. -- --------------------------------------------------------

  316. --
  317. -- Table structure for table `monitor_downtimehistory`
  318. --

  319. CREATE TABLE IF NOT EXISTS `monitor_downtimehistory` (
  320.   `downtimehistory_id` int(11) NOT NULL auto_increment,
  321.   `instance_id` smallint(6) NOT NULL default '0',
  322.   `downtime_type` smallint(6) NOT NULL default '0',
  323.   `object_id` int(11) NOT NULL default '0',
  324.   `entry_time` datetime NOT NULL default '0000-00-00 00:00:00',
  325.   `author_name` varchar(64) NOT NULL default '',
  326.   `comment_data` varchar(255) NOT NULL default '',
  327.   `internal_downtime_id` int(11) NOT NULL default '0',
  328.   `triggered_by_id` int(11) NOT NULL default '0',
  329.   `is_fixed` smallint(6) NOT NULL default '0',
  330.   `duration` smallint(6) NOT NULL default '0',
  331.   `scheduled_start_time` datetime NOT NULL default '0000-00-00 00:00:00',
  332.   `scheduled_end_time` datetime NOT NULL default '0000-00-00 00:00:00',
  333.   `was_started` smallint(6) NOT NULL default '0',
  334.   `actual_start_time` datetime NOT NULL default '0000-00-00 00:00:00',
  335.   `actual_start_time_usec` int(11) NOT NULL default '0',
  336.   `actual_end_time` datetime NOT NULL default '0000-00-00 00:00:00',
  337.   `actual_end_time_usec` int(11) NOT NULL default '0',
  338.   `was_cancelled` smallint(6) NOT NULL default '0',
  339.   PRIMARY KEY (`downtimehistory_id`),
  340.   UNIQUE KEY `instance_id` (`instance_id`,`object_id`,`entry_time`,`internal_downtime_id`)
  341. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historical scheduled host and service downtime';

  342. -- --------------------------------------------------------

  343. --
  344. -- Table structure for table `monitor_eventhandlers`
  345. --

  346. CREATE TABLE IF NOT EXISTS `monitor_eventhandlers` (
  347.   `eventhandler_id` int(11) NOT NULL auto_increment,
  348.   `instance_id` smallint(6) NOT NULL default '0',
  349.   `eventhandler_type` smallint(6) NOT NULL default '0',
  350.   `object_id` int(11) NOT NULL default '0',
  351.   `state` smallint(6) NOT NULL default '0',
  352.   `state_type` smallint(6) NOT NULL default '0',
  353.   `start_time` datetime NOT NULL default '0000-00-00 00:00:00',
  354.   `start_time_usec` int(11) NOT NULL default '0',
  355.   `end_time` datetime NOT NULL default '0000-00-00 00:00:00',
  356.   `end_time_usec` int(11) NOT NULL default '0',
  357.   `command_object_id` int(11) NOT NULL default '0',
  358.   `command_args` varchar(255) NOT NULL default '',
  359.   `command_line` varchar(255) NOT NULL default '',
  360.   `timeout` smallint(6) NOT NULL default '0',
  361.   `early_timeout` smallint(6) NOT NULL default '0',
  362.   `execution_time` double NOT NULL default '0',
  363.   `return_code` smallint(6) NOT NULL default '0',
  364.   `output` varchar(255) NOT NULL default '',
  365.   `long_output` TEXT NOT NULL default '',
  366.   PRIMARY KEY (`eventhandler_id`),
  367.   UNIQUE KEY `instance_id` (`instance_id`,`object_id`,`start_time`,`start_time_usec`)
  368. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historical host and service event handlers';

  369. -- --------------------------------------------------------

  370. --
  371. -- Table structure for table `monitor_externalcommands`
  372. --

  373. CREATE TABLE IF NOT EXISTS `monitor_externalcommands` (
  374.   `externalcommand_id` int(11) NOT NULL auto_increment,
  375.   `instance_id` smallint(6) NOT NULL default '0',
  376.   `entry_time` datetime NOT NULL default '0000-00-00 00:00:00',
  377.   `command_type` smallint(6) NOT NULL default '0',
  378.   `command_name` varchar(128) NOT NULL default '',
  379.   `command_args` varchar(255) NOT NULL default '',
  380.   PRIMARY KEY (`externalcommand_id`)
  381. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historical record of processed external commands';

  382. -- --------------------------------------------------------

  383. --
  384. -- Table structure for table `monitor_flappinghistory`
  385. --

  386. CREATE TABLE IF NOT EXISTS `monitor_flappinghistory` (
  387.   `flappinghistory_id` int(11) NOT NULL auto_increment,
  388.   `instance_id` smallint(6) NOT NULL default '0',
  389.   `event_time` datetime NOT NULL default '0000-00-00 00:00:00',
  390.   `event_time_usec` int(11) NOT NULL default '0',
  391.   `event_type` smallint(6) NOT NULL default '0',
  392.   `reason_type` smallint(6) NOT NULL default '0',
  393.   `flapping_type` smallint(6) NOT NULL default '0',
  394.   `object_id` int(11) NOT NULL default '0',
  395.   `percent_state_change` double NOT NULL default '0',
  396.   `low_threshold` double NOT NULL default '0',
  397.   `high_threshold` double NOT NULL default '0',
  398.   `comment_time` datetime NOT NULL default '0000-00-00 00:00:00',
  399.   `internal_comment_id` int(11) NOT NULL default '0',
  400.   PRIMARY KEY (`flappinghistory_id`)
  401. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Current and historical record of host and service flapping';

  402. -- --------------------------------------------------------

  403. --
  404. -- Table structure for table `monitor_hostchecks`
  405. --

  406. CREATE TABLE IF NOT EXISTS `monitor_hostchecks` (
  407.   `hostcheck_id` int(11) NOT NULL auto_increment,
  408.   `instance_id` smallint(6) NOT NULL default '0',
  409.   `host_object_id` int(11) NOT NULL default '0',
  410.   `check_type` smallint(6) NOT NULL default '0',
  411.   `is_raw_check` smallint(6) NOT NULL default '0',
  412.   `current_check_attempt` smallint(6) NOT NULL default '0',
  413.   `max_check_attempts` smallint(6) NOT NULL default '0',
  414.   `state` smallint(6) NOT NULL default '0',
  415.   `state_type` smallint(6) NOT NULL default '0',
  416.   `start_time` datetime NOT NULL default '0000-00-00 00:00:00',
  417.   `start_time_usec` int(11) NOT NULL default '0',
  418.   `end_time` datetime NOT NULL default '0000-00-00 00:00:00',
  419.   `end_time_usec` int(11) NOT NULL default '0',
  420.   `command_object_id` int(11) NOT NULL default '0',
  421.   `command_args` varchar(255) NOT NULL default '',
  422.   `command_line` varchar(255) NOT NULL default '',
  423.   `timeout` smallint(6) NOT NULL default '0',
  424.   `early_timeout` smallint(6) NOT NULL default '0',
  425.   `execution_time` double NOT NULL default '0',
  426.   `latency` double NOT NULL default '0',
  427.   `return_code` smallint(6) NOT NULL default '0',
  428.   `output` varchar(255) NOT NULL default '',
  429.   `long_output` TEXT NOT NULL default '',
  430.   `perfdata` TEXT NOT NULL default '',
  431.   PRIMARY KEY (`hostcheck_id`),
  432.   UNIQUE KEY `instance_id` (`instance_id`,`host_object_id`,`start_time`,`start_time_usec`)
  433. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historical host checks';

  434. -- --------------------------------------------------------

  435. --
  436. -- Table structure for table `monitor_hostdependencies`
  437. --

  438. CREATE TABLE IF NOT EXISTS `monitor_hostdependencies` (
  439.   `hostdependency_id` int(11) NOT NULL auto_increment,
  440.   `instance_id` smallint(6) NOT NULL default '0',
  441.   `config_type` smallint(6) NOT NULL default '0',
  442.   `host_object_id` int(11) NOT NULL default '0',
  443.   `dependent_host_object_id` int(11) NOT NULL default '0',
  444.   `dependency_type` smallint(6) NOT NULL default '0',
  445.   `inherits_parent` smallint(6) NOT NULL default '0',
  446.   `timeperiod_object_id` int(11) NOT NULL default '0',
  447.   `fail_on_up` smallint(6) NOT NULL default '0',
  448.   `fail_on_down` smallint(6) NOT NULL default '0',
  449.   `fail_on_unreachable` smallint(6) NOT NULL default '0',
  450.   PRIMARY KEY (`hostdependency_id`),
  451.   UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`host_object_id`,`dependent_host_object_id`,`dependency_type`,`inherits_parent`,`fail_on_up`,`fail_on_down`,`fail_on_unreachable`)
  452. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Host dependency definitions';

  453. -- --------------------------------------------------------

  454. --
  455. -- Table structure for table `monitor_hostescalations`
  456. --

  457. CREATE TABLE IF NOT EXISTS `monitor_hostescalations` (
  458.   `hostescalation_id` int(11) NOT NULL auto_increment,
  459.   `instance_id` smallint(6) NOT NULL default '0',
  460.   `config_type` smallint(6) NOT NULL default '0',
  461.   `host_object_id` int(11) NOT NULL default '0',
  462.   `timeperiod_object_id` int(11) NOT NULL default '0',
  463.   `first_notification` smallint(6) NOT NULL default '0',
  464.   `last_notification` smallint(6) NOT NULL default '0',
  465.   `notification_interval` double NOT NULL default '0',
  466.   `escalate_on_recovery` smallint(6) NOT NULL default '0',
  467.   `escalate_on_down` smallint(6) NOT NULL default '0',
  468.   `escalate_on_unreachable` smallint(6) NOT NULL default '0',
  469.   PRIMARY KEY (`hostescalation_id`),
  470.   UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`host_object_id`,`timeperiod_object_id`,`first_notification`,`last_notification`)
  471. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Host escalation definitions';

  472. -- --------------------------------------------------------

  473. --
  474. -- Table structure for table `monitor_hostescalation_contactgroups`
  475. --

  476. CREATE TABLE IF NOT EXISTS `monitor_hostescalation_contactgroups` (
  477.   `hostescalation_contactgroup_id` int(11) NOT NULL auto_increment,
  478.   `instance_id` smallint(6) NOT NULL default '0',
  479.   `hostescalation_id` int(11) NOT NULL default '0',
  480.   `contactgroup_object_id` int(11) NOT NULL default '0',
  481.   PRIMARY KEY (`hostescalation_contactgroup_id`),
  482.   UNIQUE KEY `instance_id` (`hostescalation_id`,`contactgroup_object_id`)
  483. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Host escalation contact groups';

  484. -- --------------------------------------------------------

  485. --
  486. -- Table structure for table `monitor_hostescalation_contacts`
  487. --

  488. CREATE TABLE IF NOT EXISTS `monitor_hostescalation_contacts` (
  489.   `hostescalation_contact_id` int(11) NOT NULL auto_increment,
  490.   `instance_id` smallint(6) NOT NULL default '0',
  491.   `hostescalation_id` int(11) NOT NULL default '0',
  492.   `contact_object_id` int(11) NOT NULL default '0',
  493.   PRIMARY KEY (`hostescalation_contact_id`),
  494.   UNIQUE KEY `instance_id` (`instance_id`,`hostescalation_id`,`contact_object_id`)
  495. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

  496. -- --------------------------------------------------------

  497. --
  498. -- Table structure for table `monitor_hostgroups`
  499. --

  500. CREATE TABLE IF NOT EXISTS `monitor_hostgroups` (
  501.   `hostgroup_id` int(11) NOT NULL auto_increment,
  502.   `instance_id` smallint(6) NOT NULL default '0',
  503.   `config_type` smallint(6) NOT NULL default '0',
  504.   `hostgroup_object_id` int(11) NOT NULL default '0',
  505.   `alias` varchar(255) NOT NULL default '',
  506.   PRIMARY KEY (`hostgroup_id`),
  507.   UNIQUE KEY `instance_id` (`instance_id`,`hostgroup_object_id`)
  508. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Hostgroup definitions';

  509. -- --------------------------------------------------------

  510. --
  511. -- Table structure for table `monitor_hostgroup_members`
  512. --

  513. CREATE TABLE IF NOT EXISTS `monitor_hostgroup_members` (
  514.   `hostgroup_member_id` int(11) NOT NULL auto_increment,
  515.   `instance_id` smallint(6) NOT NULL default '0',
  516.   `hostgroup_id` int(11) NOT NULL default '0',
  517.   `host_object_id` int(11) NOT NULL default '0',
  518.   PRIMARY KEY (`hostgroup_member_id`),
  519.   UNIQUE KEY `instance_id` (`hostgroup_id`,`host_object_id`)
  520. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Hostgroup members';

  521. -- --------------------------------------------------------

  522. --
  523. -- Table structure for table `monitor_hosts`
  524. --

  525. CREATE TABLE IF NOT EXISTS `monitor_hosts` (
  526.   `host_id` int(11) NOT NULL auto_increment,
  527.   `instance_id` smallint(6) NOT NULL default '0',
  528.   `config_type` smallint(6) NOT NULL default '0',
  529.   `host_object_id` int(11) NOT NULL default '0',
  530.   `alias` varchar(64) NOT NULL default '',
  531.   `display_name` varchar(64) NOT NULL default '',
  532.   `address` varchar(128) NOT NULL default '',
  533.   `importance` int(11) NOT NULL default '0',
  534.   `check_command_object_id` int(11) NOT NULL default '0',
  535.   `check_command_args` varchar(255) NOT NULL default '',
  536.   `eventhandler_command_object_id` int(11) NOT NULL default '0',
  537.   `eventhandler_command_args` varchar(255) NOT NULL default '',
  538.   `notification_timeperiod_object_id` int(11) NOT NULL default '0',
  539.   `check_timeperiod_object_id` int(11) NOT NULL default '0',
  540.   `failure_prediction_options` varchar(64) NOT NULL default '',
  541.   `check_interval` double NOT NULL default '0',
  542.   `retry_interval` double NOT NULL default '0',
  543.   `max_check_attempts` smallint(6) NOT NULL default '0',
  544.   `first_notification_delay` double NOT NULL default '0',
  545.   `notification_interval` double NOT NULL default '0',
  546.   `notify_on_down` smallint(6) NOT NULL default '0',
  547.   `notify_on_unreachable` smallint(6) NOT NULL default '0',
  548.   `notify_on_recovery` smallint(6) NOT NULL default '0',
  549.   `notify_on_flapping` smallint(6) NOT NULL default '0',
  550.   `notify_on_downtime` smallint(6) NOT NULL default '0',
  551.   `stalk_on_up` smallint(6) NOT NULL default '0',
  552.   `stalk_on_down` smallint(6) NOT NULL default '0',
  553.   `stalk_on_unreachable` smallint(6) NOT NULL default '0',
  554.   `flap_detection_enabled` smallint(6) NOT NULL default '0',
  555.   `flap_detection_on_up` smallint(6) NOT NULL default '0',
  556.   `flap_detection_on_down` smallint(6) NOT NULL default '0',
  557.   `flap_detection_on_unreachable` smallint(6) NOT NULL default '0',
  558.   `low_flap_threshold` double NOT NULL default '0',
  559.   `high_flap_threshold` double NOT NULL default '0',
  560.   `process_performance_data` smallint(6) NOT NULL default '0',
  561.   `freshness_checks_enabled` smallint(6) NOT NULL default '0',
  562.   `freshness_threshold` smallint(6) NOT NULL default '0',
  563.   `passive_checks_enabled` smallint(6) NOT NULL default '0',
  564.   `event_handler_enabled` smallint(6) NOT NULL default '0',
  565.   `active_checks_enabled` smallint(6) NOT NULL default '0',
  566.   `retain_status_information` smallint(6) NOT NULL default '0',
  567.   `retain_nonstatus_information` smallint(6) NOT NULL default '0',
  568.   `notifications_enabled` smallint(6) NOT NULL default '0',
  569.   `obsess_over_host` smallint(6) NOT NULL default '0',
  570.   `failure_prediction_enabled` smallint(6) NOT NULL default '0',
  571.   `notes` varchar(255) NOT NULL default '',
  572.   `notes_url` varchar(255) NOT NULL default '',
  573.   `action_url` varchar(255) NOT NULL default '',
  574.   `icon_image` varchar(255) NOT NULL default '',
  575.   `icon_image_alt` varchar(255) NOT NULL default '',
  576.   `vrml_image` varchar(255) NOT NULL default '',
  577.   `statusmap_image` varchar(255) NOT NULL default '',
  578.   `have_2d_coords` smallint(6) NOT NULL default '0',
  579.   `x_2d` smallint(6) NOT NULL default '0',
  580.   `y_2d` smallint(6) NOT NULL default '0',
  581.   `have_3d_coords` smallint(6) NOT NULL default '0',
  582.   `x_3d` double NOT NULL default '0',
  583.   `y_3d` double NOT NULL default '0',
  584.   `z_3d` double NOT NULL default '0',
  585.   PRIMARY KEY (`host_id`),
  586.   UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`host_object_id`),
  587.   KEY `host_object_id` (`host_object_id`)
  588. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Host definitions';

  589. -- --------------------------------------------------------

  590. --
  591. -- Table structure for table `monitor_hoststatus`
  592. --

  593. CREATE TABLE IF NOT EXISTS `monitor_hoststatus` (
  594.   `hoststatus_id` int(11) NOT NULL auto_increment,
  595.   `instance_id` smallint(6) NOT NULL default '0',
  596.   `host_object_id` int(11) NOT NULL default '0',
  597.   `status_update_time` datetime NOT NULL default '0000-00-00 00:00:00',
  598.   `output` varchar(255) NOT NULL default '',
  599.   `long_output` TEXT NOT NULL default '',
  600.   `perfdata` TEXT NOT NULL default '',
  601.   `current_state` smallint(6) NOT NULL default '0',
  602.   `has_been_checked` smallint(6) NOT NULL default '0',
  603.   `should_be_scheduled` smallint(6) NOT NULL default '0',
  604.   `current_check_attempt` smallint(6) NOT NULL default '0',
  605.   `max_check_attempts` smallint(6) NOT NULL default '0',
  606.   `last_check` datetime NOT NULL default '0000-00-00 00:00:00',
  607.   `next_check` datetime NOT NULL default '0000-00-00 00:00:00',
  608.   `check_type` smallint(6) NOT NULL default '0',
  609.   `last_state_change` datetime NOT NULL default '0000-00-00 00:00:00',
  610.   `last_hard_state_change` datetime NOT NULL default '0000-00-00 00:00:00',
  611.   `last_hard_state` smallint(6) NOT NULL default '0',
  612.   `last_time_up` datetime NOT NULL default '0000-00-00 00:00:00',
  613.   `last_time_down` datetime NOT NULL default '0000-00-00 00:00:00',
  614.   `last_time_unreachable` datetime NOT NULL default '0000-00-00 00:00:00',
  615.   `state_type` smallint(6) NOT NULL default '0',
  616.   `last_notification` datetime NOT NULL default '0000-00-00 00:00:00',
  617.   `next_notification` datetime NOT NULL default '0000-00-00 00:00:00',
  618.   `no_more_notifications` smallint(6) NOT NULL default '0',
  619.   `notifications_enabled` smallint(6) NOT NULL default '0',
  620.   `problem_has_been_acknowledged` smallint(6) NOT NULL default '0',
  621.   `acknowledgement_type` smallint(6) NOT NULL default '0',
  622.   `current_notification_number` smallint(6) NOT NULL default '0',
  623.   `passive_checks_enabled` smallint(6) NOT NULL default '0',
  624.   `active_checks_enabled` smallint(6) NOT NULL default '0',
  625.   `event_handler_enabled` smallint(6) NOT NULL default '0',
  626.   `flap_detection_enabled` smallint(6) NOT NULL default '0',
  627.   `is_flapping` smallint(6) NOT NULL default '0',
  628.   `percent_state_change` double NOT NULL default '0',
  629.   `latency` double NOT NULL default '0',
  630.   `execution_time` double NOT NULL default '0',
  631.   `scheduled_downtime_depth` smallint(6) NOT NULL default '0',
  632.   `failure_prediction_enabled` smallint(6) NOT NULL default '0',
  633.   `process_performance_data` smallint(6) NOT NULL default '0',
  634.   `obsess_over_host` smallint(6) NOT NULL default '0',
  635.   `modified_host_attributes` int(11) NOT NULL default '0',
  636.   `event_handler` varchar(255) NOT NULL default '',
  637.   `check_command` varchar(255) NOT NULL default '',
  638.   `normal_check_interval` double NOT NULL default '0',
  639.   `retry_check_interval` double NOT NULL default '0',
  640.   `check_timeperiod_object_id` int(11) NOT NULL default '0',
  641.   PRIMARY KEY (`hoststatus_id`),
  642.   UNIQUE KEY `object_id` (`host_object_id`),
  643.   KEY `instance_id` (`instance_id`),
  644.   KEY `status_update_time` (`status_update_time`),
  645.   KEY `current_state` (`current_state`),
  646.   KEY `check_type` (`check_type`),
  647.   KEY `state_type` (`state_type`),
  648.   KEY `last_state_change` (`last_state_change`),
  649.   KEY `notifications_enabled` (`notifications_enabled`),
  650.   KEY `problem_has_been_acknowledged` (`problem_has_been_acknowledged`),
  651.   KEY `active_checks_enabled` (`active_checks_enabled`),
  652.   KEY `passive_checks_enabled` (`passive_checks_enabled`),
  653.   KEY `event_handler_enabled` (`event_handler_enabled`),
  654.   KEY `flap_detection_enabled` (`flap_detection_enabled`),
  655.   KEY `is_flapping` (`is_flapping`),
  656.   KEY `percent_state_change` (`percent_state_change`),
  657.   KEY `latency` (`latency`),
  658.   KEY `execution_time` (`execution_time`),
  659.   KEY `scheduled_downtime_depth` (`scheduled_downtime_depth`)
  660. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Current host status information';

  661. -- --------------------------------------------------------

  662. --
  663. -- Table structure for table `monitor_host_contactgroups`
  664. --

  665. CREATE TABLE IF NOT EXISTS `monitor_host_contactgroups` (
  666.   `host_contactgroup_id` int(11) NOT NULL auto_increment,
  667.   `instance_id` smallint(6) NOT NULL default '0',
  668.   `host_id` int(11) NOT NULL default '0',
  669.   `contactgroup_object_id` int(11) NOT NULL default '0',
  670.   PRIMARY KEY (`host_contactgroup_id`),
  671.   UNIQUE KEY `instance_id` (`host_id`,`contactgroup_object_id`)
  672. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Host contact groups';

  673. -- --------------------------------------------------------

  674. --
  675. -- Table structure for table `monitor_host_contacts`
  676. --

  677. CREATE TABLE IF NOT EXISTS `monitor_host_contacts` (
  678.   `host_contact_id` int(11) NOT NULL auto_increment,
  679.   `instance_id` smallint(6) NOT NULL default '0',
  680.   `host_id` int(11) NOT NULL default '0',
  681.   `contact_object_id` int(11) NOT NULL default '0',
  682.   PRIMARY KEY (`host_contact_id`),
  683.   UNIQUE KEY `instance_id` (`instance_id`,`host_id`,`contact_object_id`)
  684. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

  685. -- --------------------------------------------------------

  686. --
  687. -- Table structure for table `monitor_host_parenthosts`
  688. --

  689. CREATE TABLE IF NOT EXISTS `monitor_host_parenthosts` (
  690.   `host_parenthost_id` int(11) NOT NULL auto_increment,
  691.   `instance_id` smallint(6) NOT NULL default '0',
  692.   `host_id` int(11) NOT NULL default '0',
  693.   `parent_host_object_id` int(11) NOT NULL default '0',
  694.   PRIMARY KEY (`host_parenthost_id`),
  695.   UNIQUE KEY `instance_id` (`host_id`,`parent_host_object_id`)
  696. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Parent hosts';

  697. -- --------------------------------------------------------

  698. --
  699. -- Table structure for table `monitor_instances`
  700. --

  701. CREATE TABLE IF NOT EXISTS `monitor_instances` (
  702.   `instance_id` smallint(6) NOT NULL auto_increment,
  703.   `instance_name` varchar(64) NOT NULL default '',
  704.   `instance_description` varchar(128) NOT NULL default '',
  705.   PRIMARY KEY (`instance_id`)
  706. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Location names of various Nagios installations';

  707. -- --------------------------------------------------------

  708. --
  709. -- Table structure for table `monitor_logentries`
  710. --

  711. CREATE TABLE IF NOT EXISTS `monitor_logentries` (
  712.   `logentry_id` int(11) NOT NULL auto_increment,
  713.   `instance_id` int(11) NOT NULL default '0',
  714.   `logentry_time` datetime NOT NULL default '0000-00-00 00:00:00',
  715.   `entry_time` datetime NOT NULL default '0000-00-00 00:00:00',
  716.   `entry_time_usec` int(11) NOT NULL default '0',
  717.   `logentry_type` int(11) NOT NULL default '0',
  718.   `logentry_data` varchar(255) NOT NULL default '',
  719.   `realtime_data` smallint(6) NOT NULL default '0',
  720.   `inferred_data_extracted` smallint(6) NOT NULL default '0',
  721.   PRIMARY KEY (`logentry_id`),
  722.   UNIQUE KEY `instance_id` (`instance_id`, `logentry_time`,`entry_time`,`entry_time_usec`)
  723. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historical record of log entries';

  724. -- --------------------------------------------------------

  725. --
  726. -- Table structure for table `monitor_notifications`
  727. --

  728. CREATE TABLE IF NOT EXISTS `monitor_notifications` (
  729.   `notification_id` int(11) NOT NULL auto_increment,
  730.   `instance_id` smallint(6) NOT NULL default '0',
  731.   `notification_type` smallint(6) NOT NULL default '0',
  732.   `notification_reason` smallint(6) NOT NULL default '0',
  733.   `object_id` int(11) NOT NULL default '0',
  734.   `start_time` datetime NOT NULL default '0000-00-00 00:00:00',
  735.   `start_time_usec` int(11) NOT NULL default '0',
  736.   `end_time` datetime NOT NULL default '0000-00-00 00:00:00',
  737.   `end_time_usec` int(11) NOT NULL default '0',
  738.   `state` smallint(6) NOT NULL default '0',
  739.   `output` varchar(255) NOT NULL default '',
  740.   `long_output` TEXT NOT NULL default '',
  741.   `escalated` smallint(6) NOT NULL default '0',
  742.   `contacts_notified` smallint(6) NOT NULL default '0',
  743.   PRIMARY KEY (`notification_id`),
  744.   UNIQUE KEY `instance_id` (`instance_id`,`object_id`,`start_time`,`start_time_usec`)
  745. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historical record of host and service notifications';

  746. -- --------------------------------------------------------

  747. --
  748. -- Table structure for table `monitor_objects`
  749. --

  750. CREATE TABLE IF NOT EXISTS `monitor_objects` (
  751.   `object_id` int(11) NOT NULL auto_increment,
  752.   `instance_id` smallint(6) NOT NULL default '0',
  753.   `objecttype_id` smallint(6) NOT NULL default '0',
  754.   `name1` varchar(128) NOT NULL default '',
  755.   `name2` varchar(128) default NULL,
  756.   `is_active` smallint(6) NOT NULL default '0',
  757.   PRIMARY KEY (`object_id`),
  758.   KEY `objecttype_id` (`objecttype_id`,`name1`,`name2`)
  759. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Current and historical objects of all kinds';

  760. -- --------------------------------------------------------

  761. --
  762. -- Table structure for table `monitor_processevents`
  763. --

  764. CREATE TABLE IF NOT EXISTS `monitor_processevents` (
  765.   `processevent_id` int(11) NOT NULL auto_increment,
  766.   `instance_id` smallint(6) NOT NULL default '0',
  767.   `event_type` smallint(6) NOT NULL default '0',
  768.   `event_time` datetime NOT NULL default '0000-00-00 00:00:00',
  769.   `event_time_usec` int(11) NOT NULL default '0',
  770.   `process_id` int(11) NOT NULL default '0',
  771.   `program_name` varchar(16) NOT NULL default '',
  772.   `program_version` varchar(20) NOT NULL default '',
  773.   `program_date` varchar(10) NOT NULL default '',
  774.   PRIMARY KEY (`processevent_id`)
  775. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historical Nagios process events';

  776. -- --------------------------------------------------------

  777. --
  778. -- Table structure for table `monitor_programstatus`
  779. --

  780. CREATE TABLE IF NOT EXISTS `monitor_programstatus` (
  781.   `programstatus_id` int(11) NOT NULL auto_increment,
  782.   `instance_id` smallint(6) NOT NULL default '0',
  783.   `status_update_time` datetime NOT NULL default '0000-00-00 00:00:00',
  784.   `program_start_time` datetime NOT NULL default '0000-00-00 00:00:00',
  785.   `program_end_time` datetime NOT NULL default '0000-00-00 00:00:00',
  786.   `is_currently_running` smallint(6) NOT NULL default '0',
  787.   `process_id` int(11) NOT NULL default '0',
  788.   `daemon_mode` smallint(6) NOT NULL default '0',
  789.   `last_command_check` datetime NOT NULL default '0000-00-00 00:00:00',
  790.   `last_log_rotation` datetime NOT NULL default '0000-00-00 00:00:00',
  791.   `notifications_enabled` smallint(6) NOT NULL default '0',
  792.   `active_service_checks_enabled` smallint(6) NOT NULL default '0',
  793.   `passive_service_checks_enabled` smallint(6) NOT NULL default '0',
  794.   `active_host_checks_enabled` smallint(6) NOT NULL default '0',
  795.   `passive_host_checks_enabled` smallint(6) NOT NULL default '0',
  796.   `event_handlers_enabled` smallint(6) NOT NULL default '0',
  797.   `flap_detection_enabled` smallint(6) NOT NULL default '0',
  798.   `failure_prediction_enabled` smallint(6) NOT NULL default '0',
  799.   `process_performance_data` smallint(6) NOT NULL default '0',
  800.   `obsess_over_hosts` smallint(6) NOT NULL default '0',
  801.   `obsess_over_services` smallint(6) NOT NULL default '0',
  802.   `modified_host_attributes` int(11) NOT NULL default '0',
  803.   `modified_service_attributes` int(11) NOT NULL default '0',
  804.   `global_host_event_handler` varchar(255) NOT NULL default '',
  805.   `global_service_event_handler` varchar(255) NOT NULL default '',
  806.   PRIMARY KEY (`programstatus_id`),
  807.   UNIQUE KEY `instance_id` (`instance_id`)
  808. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Current program status information';

  809. -- --------------------------------------------------------

  810. --
  811. -- Table structure for table `monitor_runtimevariables`
  812. --

  813. CREATE TABLE IF NOT EXISTS `monitor_runtimevariables` (
  814.   `runtimevariable_id` int(11) NOT NULL auto_increment,
  815.   `instance_id` smallint(6) NOT NULL default '0',
  816.   `varname` varchar(64) NOT NULL default '',
  817.   `varvalue` varchar(255) NOT NULL default '',
  818.   PRIMARY KEY (`runtimevariable_id`),
  819.   UNIQUE KEY `instance_id` (`instance_id`,`varname`)
  820. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Runtime variables from the Nagios daemon';

  821. -- --------------------------------------------------------

  822. --
  823. -- Table structure for table `monitor_scheduleddowntime`
  824. --

  825. CREATE TABLE IF NOT EXISTS `monitor_scheduleddowntime` (
  826.   `scheduleddowntime_id` int(11) NOT NULL auto_increment,
  827.   `instance_id` smallint(6) NOT NULL default '0',
  828.   `downtime_type` smallint(6) NOT NULL default '0',
  829.   `object_id` int(11) NOT NULL default '0',
  830.   `entry_time` datetime NOT NULL default '0000-00-00 00:00:00',
  831.   `author_name` varchar(64) NOT NULL default '',
  832.   `comment_data` varchar(255) NOT NULL default '',
  833.   `internal_downtime_id` int(11) NOT NULL default '0',
  834.   `triggered_by_id` int(11) NOT NULL default '0',
  835.   `is_fixed` smallint(6) NOT NULL default '0',
  836.   `duration` smallint(6) NOT NULL default '0',
  837.   `scheduled_start_time` datetime NOT NULL default '0000-00-00 00:00:00',
  838.   `scheduled_end_time` datetime NOT NULL default '0000-00-00 00:00:00',
  839.   `was_started` smallint(6) NOT NULL default '0',
  840.   `actual_start_time` datetime NOT NULL default '0000-00-00 00:00:00',
  841.   `actual_start_time_usec` int(11) NOT NULL default '0',
  842.   PRIMARY KEY (`scheduleddowntime_id`),
  843.   UNIQUE KEY `instance_id` (`instance_id`,`object_id`,`entry_time`,`internal_downtime_id`)
  844. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Current scheduled host and service downtime';

  845. -- --------------------------------------------------------

  846. --
  847. -- Table structure for table `monitor_servicechecks`
  848. --

  849. CREATE TABLE IF NOT EXISTS `monitor_servicechecks` (
  850.   `servicecheck_id` int(11) NOT NULL auto_increment,
  851.   `instance_id` smallint(6) NOT NULL default '0',
  852.   `service_object_id` int(11) NOT NULL default '0',
  853.   `check_type` smallint(6) NOT NULL default '0',
  854.   `current_check_attempt` smallint(6) NOT NULL default '0',
  855.   `max_check_attempts` smallint(6) NOT NULL default '0',
  856.   `state` smallint(6) NOT NULL default '0',
  857.   `state_type` smallint(6) NOT NULL default '0',
  858.   `start_time` datetime NOT NULL default '0000-00-00 00:00:00',
  859.   `start_time_usec` int(11) NOT NULL default '0',
  860.   `end_time` datetime NOT NULL default '0000-00-00 00:00:00',
  861.   `end_time_usec` int(11) NOT NULL default '0',
  862.   `command_object_id` int(11) NOT NULL default '0',
  863.   `command_args` varchar(255) NOT NULL default '',
  864.   `command_line` varchar(255) NOT NULL default '',
  865.   `timeout` smallint(6) NOT NULL default '0',
  866.   `early_timeout` smallint(6) NOT NULL default '0',
  867.   `execution_time` double NOT NULL default '0',
  868.   `latency` double NOT NULL default '0',
  869.   `return_code` smallint(6) NOT NULL default '0',
  870.   `output` varchar(255) NOT NULL default '',
  871.   `long_output` TEXT NOT NULL default '',
  872.   `perfdata` TEXT NOT NULL default '',
  873.   PRIMARY KEY (`servicecheck_id`),
  874.   KEY `instance_id` (`instance_id`),
  875.   KEY `service_object_id` (`service_object_id`),
  876.   KEY `start_time` (`start_time`)
  877. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historical service checks';

  878. -- --------------------------------------------------------

  879. --
  880. -- Table structure for table `monitor_servicedependencies`
  881. --

  882. CREATE TABLE IF NOT EXISTS `monitor_servicedependencies` (
  883.   `servicedependency_id` int(11) NOT NULL auto_increment,
  884.   `instance_id` smallint(6) NOT NULL default '0',
  885.   `config_type` smallint(6) NOT NULL default '0',
  886.   `service_object_id` int(11) NOT NULL default '0',
  887.   `dependent_service_object_id` int(11) NOT NULL default '0',
  888.   `dependency_type` smallint(6) NOT NULL default '0',
  889.   `inherits_parent` smallint(6) NOT NULL default '0',
  890.   `timeperiod_object_id` int(11) NOT NULL default '0',
  891.   `fail_on_ok` smallint(6) NOT NULL default '0',
  892.   `fail_on_warning` smallint(6) NOT NULL default '0',
  893.   `fail_on_unknown` smallint(6) NOT NULL default '0',
  894.   `fail_on_critical` smallint(6) NOT NULL default '0',
  895.   PRIMARY KEY (`servicedependency_id`),
  896.   UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`service_object_id`,`dependent_service_object_id`,`dependency_type`,`inherits_parent`,`fail_on_ok`,`fail_on_warning`,`fail_on_unknown`,`fail_on_critical`)
  897. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Service dependency definitions';

  898. -- --------------------------------------------------------

  899. --
  900. -- Table structure for table `monitor_serviceescalations`
  901. --

  902. CREATE TABLE IF NOT EXISTS `monitor_serviceescalations` (
  903.   `serviceescalation_id` int(11) NOT NULL auto_increment,
  904.   `instance_id` smallint(6) NOT NULL default '0',
  905.   `config_type` smallint(6) NOT NULL default '0',
  906.   `service_object_id` int(11) NOT NULL default '0',
  907.   `timeperiod_object_id` int(11) NOT NULL default '0',
  908.   `first_notification` smallint(6) NOT NULL default '0',
  909.   `last_notification` smallint(6) NOT NULL default '0',
  910.   `notification_interval` double NOT NULL default '0',
  911.   `escalate_on_recovery` smallint(6) NOT NULL default '0',
  912.   `escalate_on_warning` smallint(6) NOT NULL default '0',
  913.   `escalate_on_unknown` smallint(6) NOT NULL default '0',
  914.   `escalate_on_critical` smallint(6) NOT NULL default '0',
  915.   PRIMARY KEY (`serviceescalation_id`),
  916.   UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`service_object_id`,`timeperiod_object_id`,`first_notification`,`last_notification`)
  917. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Service escalation definitions';

  918. -- --------------------------------------------------------

  919. --
  920. -- Table structure for table `monitor_serviceescalation_contactgroups`
  921. --

  922. CREATE TABLE IF NOT EXISTS `monitor_serviceescalation_contactgroups` (
  923.   `serviceescalation_contactgroup_id` int(11) NOT NULL auto_increment,
  924.   `instance_id` smallint(6) NOT NULL default '0',
  925.   `serviceescalation_id` int(11) NOT NULL default '0',
  926.   `contactgroup_object_id` int(11) NOT NULL default '0',
  927.   PRIMARY KEY (`serviceescalation_contactgroup_id`),
  928.   UNIQUE KEY `instance_id` (`serviceescalation_id`,`contactgroup_object_id`)
  929. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Service escalation contact groups';

  930. -- --------------------------------------------------------

  931. --
  932. -- Table structure for table `monitor_serviceescalation_contacts`
  933. --

  934. CREATE TABLE IF NOT EXISTS `monitor_serviceescalation_contacts` (
  935.   `serviceescalation_contact_id` int(11) NOT NULL auto_increment,
  936.   `instance_id` smallint(6) NOT NULL default '0',
  937.   `serviceescalation_id` int(11) NOT NULL default '0',
  938.   `contact_object_id` int(11) NOT NULL default '0',
  939.   PRIMARY KEY (`serviceescalation_contact_id`),
  940.   UNIQUE KEY `instance_id` (`instance_id`,`serviceescalation_id`,`contact_object_id`)
  941. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

  942. -- --------------------------------------------------------

  943. --
  944. -- Table structure for table `monitor_servicegroups`
  945. --

  946. CREATE TABLE IF NOT EXISTS `monitor_servicegroups` (
  947.   `servicegroup_id` int(11) NOT NULL auto_increment,
  948.   `instance_id` smallint(6) NOT NULL default '0',
  949.   `config_type` smallint(6) NOT NULL default '0',
  950.   `servicegroup_object_id` int(11) NOT NULL default '0',
  951.   `alias` varchar(255) NOT NULL default '',
  952.   PRIMARY KEY (`servicegroup_id`),
  953.   UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`servicegroup_object_id`)
  954. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Servicegroup definitions';

  955. -- --------------------------------------------------------

  956. --
  957. -- Table structure for table `monitor_servicegroup_members`
  958. --

  959. CREATE TABLE IF NOT EXISTS `monitor_servicegroup_members` (
  960.   `servicegroup_member_id` int(11) NOT NULL auto_increment,
  961.   `instance_id` smallint(6) NOT NULL default '0',
  962.   `servicegroup_id` int(11) NOT NULL default '0',
  963.   `service_object_id` int(11) NOT NULL default '0',
  964.   PRIMARY KEY (`servicegroup_member_id`),
  965.   UNIQUE KEY `instance_id` (`servicegroup_id`,`service_object_id`)
  966. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Servicegroup members';

  967. -- --------------------------------------------------------

  968. --
  969. -- Table structure for table `monitor_services`
  970. --

  971. CREATE TABLE IF NOT EXISTS `monitor_services` (
  972.   `service_id` int(11) NOT NULL auto_increment,
  973.   `instance_id` smallint(6) NOT NULL default '0',
  974.   `config_type` smallint(6) NOT NULL default '0',
  975.   `host_object_id` int(11) NOT NULL default '0',
  976.   `service_object_id` int(11) NOT NULL default '0',
  977.   `display_name` varchar(64) NOT NULL default '',
  978.   `importance` int(11) NOT NULL default '0',
  979.   `check_command_object_id` int(11) NOT NULL default '0',
  980.   `check_command_args` varchar(255) NOT NULL default '',
  981.   `eventhandler_command_object_id` int(11) NOT NULL default '0',
  982.   `eventhandler_command_args` varchar(255) NOT NULL default '',
  983.   `notification_timeperiod_object_id` int(11) NOT NULL default '0',
  984.   `check_timeperiod_object_id` int(11) NOT NULL default '0',
  985.   `failure_prediction_options` varchar(64) NOT NULL default '',
  986.   `check_interval` double NOT NULL default '0',
  987.   `retry_interval` double NOT NULL default '0',
  988.   `max_check_attempts` smallint(6) NOT NULL default '0',
  989.   `first_notification_delay` double NOT NULL default '0',
  990.   `notification_interval` double NOT NULL default '0',
  991.   `notify_on_warning` smallint(6) NOT NULL default '0',
  992.   `notify_on_unknown` smallint(6) NOT NULL default '0',
  993.   `notify_on_critical` smallint(6) NOT NULL default '0',
  994.   `notify_on_recovery` smallint(6) NOT NULL default '0',
  995.   `notify_on_flapping` smallint(6) NOT NULL default '0',
  996.   `notify_on_downtime` smallint(6) NOT NULL default '0',
  997.   `stalk_on_ok` smallint(6) NOT NULL default '0',
  998.   `stalk_on_warning` smallint(6) NOT NULL default '0',
  999.   `stalk_on_unknown` smallint(6) NOT NULL default '0',
  1000.   `stalk_on_critical` smallint(6) NOT NULL default '0',
  1001.   `is_volatile` smallint(6) NOT NULL default '0',
  1002.   `flap_detection_enabled` smallint(6) NOT NULL default '0',
  1003.   `flap_detection_on_ok` smallint(6) NOT NULL default '0',
  1004.   `flap_detection_on_warning` smallint(6) NOT NULL default '0',
  1005.   `flap_detection_on_unknown` smallint(6) NOT NULL default '0',
  1006.   `flap_detection_on_critical` smallint(6) NOT NULL default '0',
  1007.   `low_flap_threshold` double NOT NULL default '0',
  1008.   `high_flap_threshold` double NOT NULL default '0',
  1009.   `process_performance_data` smallint(6) NOT NULL default '0',
  1010.   `freshness_checks_enabled` smallint(6) NOT NULL default '0',
  1011.   `freshness_threshold` smallint(6) NOT NULL default '0',
  1012.   `passive_checks_enabled` smallint(6) NOT NULL default '0',
  1013.   `event_handler_enabled` smallint(6) NOT NULL default '0',
  1014.   `active_checks_enabled` smallint(6) NOT NULL default '0',
  1015.   `retain_status_information` smallint(6) NOT NULL default '0',
  1016.   `retain_nonstatus_information` smallint(6) NOT NULL default '0',
  1017.   `notifications_enabled` smallint(6) NOT NULL default '0',
  1018.   `obsess_over_service` smallint(6) NOT NULL default '0',
  1019.   `failure_prediction_enabled` smallint(6) NOT NULL default '0',
  1020.   `notes` varchar(255) NOT NULL default '',
  1021.   `notes_url` varchar(255) NOT NULL default '',
  1022.   `action_url` varchar(255) NOT NULL default '',
  1023.   `icon_image` varchar(255) NOT NULL default '',
  1024.   `icon_image_alt` varchar(255) NOT NULL default '',
  1025.   PRIMARY KEY (`service_id`),
  1026.   UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`service_object_id`),
  1027.   KEY `service_object_id` (`service_object_id`)
  1028. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Service definitions';

  1029. -- --------------------------------------------------------

  1030. --
  1031. -- Table structure for table `monitor_servicestatus`
  1032. --

  1033. CREATE TABLE IF NOT EXISTS `monitor_servicestatus` (
  1034.   `servicestatus_id` int(11) NOT NULL auto_increment,
  1035.   `instance_id` smallint(6) NOT NULL default '0',
  1036.   `service_object_id` int(11) NOT NULL default '0',
  1037.   `status_update_time` datetime NOT NULL default '0000-00-00 00:00:00',
  1038.   `output` varchar(255) NOT NULL default '',
  1039.   `long_output` TEXT NOT NULL default '',
  1040.   `perfdata` TEXT NOT NULL default '',
  1041.   `current_state` smallint(6) NOT NULL default '0',
  1042.   `has_been_checked` smallint(6) NOT NULL default '0',
  1043.   `should_be_scheduled` smallint(6) NOT NULL default '0',
  1044.   `current_check_attempt` smallint(6) NOT NULL default '0',
  1045.   `max_check_attempts` smallint(6) NOT NULL default '0',
  1046.   `last_check` datetime NOT NULL default '0000-00-00 00:00:00',
  1047.   `next_check` datetime NOT NULL default '0000-00-00 00:00:00',
  1048.   `check_type` smallint(6) NOT NULL default '0',
  1049.   `last_state_change` datetime NOT NULL default '0000-00-00 00:00:00',
  1050.   `last_hard_state_change` datetime NOT NULL default '0000-00-00 00:00:00',
  1051.   `last_hard_state` smallint(6) NOT NULL default '0',
  1052.   `last_time_ok` datetime NOT NULL default '0000-00-00 00:00:00',
  1053.   `last_time_warning` datetime NOT NULL default '0000-00-00 00:00:00',
  1054.   `last_time_unknown` datetime NOT NULL default '0000-00-00 00:00:00',
  1055.   `last_time_critical` datetime NOT NULL default '0000-00-00 00:00:00',
  1056.   `state_type` smallint(6) NOT NULL default '0',
  1057.   `last_notification` datetime NOT NULL default '0000-00-00 00:00:00',
  1058.   `next_notification` datetime NOT NULL default '0000-00-00 00:00:00',
  1059.   `no_more_notifications` smallint(6) NOT NULL default '0',
  1060.   `notifications_enabled` smallint(6) NOT NULL default '0',
  1061.   `problem_has_been_acknowledged` smallint(6) NOT NULL default '0',
  1062.   `acknowledgement_type` smallint(6) NOT NULL default '0',
  1063.   `current_notification_number` smallint(6) NOT NULL default '0',
  1064.   `passive_checks_enabled` smallint(6) NOT NULL default '0',
  1065.   `active_checks_enabled` smallint(6) NOT NULL default '0',
  1066.   `event_handler_enabled` smallint(6) NOT NULL default '0',
  1067.   `flap_detection_enabled` smallint(6) NOT NULL default '0',
  1068.   `is_flapping` smallint(6) NOT NULL default '0',
  1069.   `percent_state_change` double NOT NULL default '0',
  1070.   `latency` double NOT NULL default '0',
  1071.   `execution_time` double NOT NULL default '0',
  1072.   `scheduled_downtime_depth` smallint(6) NOT NULL default '0',
  1073.   `failure_prediction_enabled` smallint(6) NOT NULL default '0',
  1074.   `process_performance_data` smallint(6) NOT NULL default '0',
  1075.   `obsess_over_service` smallint(6) NOT NULL default '0',
  1076.   `modified_service_attributes` int(11) NOT NULL default '0',
  1077.   `event_handler` varchar(255) NOT NULL default '',
  1078.   `check_command` varchar(255) NOT NULL default '',
  1079.   `normal_check_interval` double NOT NULL default '0',
  1080.   `retry_check_interval` double NOT NULL default '0',
  1081.   `check_timeperiod_object_id` int(11) NOT NULL default '0',
  1082.   PRIMARY KEY (`servicestatus_id`),
  1083.   UNIQUE KEY `object_id` (`service_object_id`),
  1084.   KEY `instance_id` (`instance_id`),
  1085.   KEY `status_update_time` (`status_update_time`),
  1086.   KEY `current_state` (`current_state`),
  1087.   KEY `check_type` (`check_type`),
  1088.   KEY `state_type` (`state_type`),
  1089.   KEY `last_state_change` (`last_state_change`),
  1090.   KEY `notifications_enabled` (`notifications_enabled`),
  1091.   KEY `problem_has_been_acknowledged` (`problem_has_been_acknowledged`),
  1092.   KEY `active_checks_enabled` (`active_checks_enabled`),
  1093.   KEY `passive_checks_enabled` (`passive_checks_enabled`),
  1094.   KEY `event_handler_enabled` (`event_handler_enabled`),
  1095.   KEY `flap_detection_enabled` (`flap_detection_enabled`),
  1096.   KEY `is_flapping` (`is_flapping`),
  1097.   KEY `percent_state_change` (`percent_state_change`),
  1098.   KEY `latency` (`latency`),
  1099.   KEY `execution_time` (`execution_time`),
  1100.   KEY `scheduled_downtime_depth` (`scheduled_downtime_depth`)
  1101. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Current service status information';

  1102. -- --------------------------------------------------------

  1103. --
  1104. -- Table structure for table `monitor_service_contactgroups`
  1105. --

  1106. CREATE TABLE IF NOT EXISTS `monitor_service_contactgroups` (
  1107.   `service_contactgroup_id` int(11) NOT NULL auto_increment,
  1108.   `instance_id` smallint(6) NOT NULL default '0',
  1109.   `service_id` int(11) NOT NULL default '0',
  1110.   `contactgroup_object_id` int(11) NOT NULL default '0',
  1111.   PRIMARY KEY (`service_contactgroup_id`),
  1112.   UNIQUE KEY `instance_id` (`service_id`,`contactgroup_object_id`)
  1113. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Service contact groups';

  1114. -- --------------------------------------------------------

  1115. --
  1116. -- Table structure for table `monitor_service_contacts`
  1117. --

  1118. CREATE TABLE IF NOT EXISTS `monitor_service_contacts` (
  1119.   `service_contact_id` int(11) NOT NULL auto_increment,
  1120.   `instance_id` smallint(6) NOT NULL default '0',
  1121.   `service_id` int(11) NOT NULL default '0',
  1122.   `contact_object_id` int(11) NOT NULL default '0',
  1123.   PRIMARY KEY (`service_contact_id`),
  1124.   UNIQUE KEY `instance_id` (`instance_id`,`service_id`,`contact_object_id`)
  1125. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

  1126. -- --------------------------------------------------------

  1127. --
  1128. -- Table structure for table `monitor_service_parentservices`
  1129. --

  1130. CREATE TABLE IF NOT EXISTS `monitor_service_parentservices` (
  1131.   `service_parentservice_id` int(11) NOT NULL auto_increment,
  1132.   `instance_id` smallint(6) NOT NULL default '0',
  1133.   `service_id` int(11) NOT NULL default '0',
  1134.   `parent_service_object_id` int(11) NOT NULL default '0',
  1135.   PRIMARY KEY (`service_parentservice_id`),
  1136.   UNIQUE KEY `instance_id` (`service_id`,`parent_service_object_id`)
  1137. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Parent services';

  1138. -- --------------------------------------------------------

  1139. --
  1140. -- Table structure for table `monitor_statehistory`
  1141. --

  1142. CREATE TABLE IF NOT EXISTS `monitor_statehistory` (
  1143.   `statehistory_id` int(11) NOT NULL auto_increment,
  1144.   `instance_id` smallint(6) NOT NULL default '0',
  1145.   `state_time` datetime NOT NULL default '0000-00-00 00:00:00',
  1146.   `state_time_usec` int(11) NOT NULL default '0',
  1147.   `object_id` int(11) NOT NULL default '0',
  1148.   `state_change` smallint(6) NOT NULL default '0',
  1149.   `state` smallint(6) NOT NULL default '0',
  1150.   `state_type` smallint(6) NOT NULL default '0',
  1151.   `current_check_attempt` smallint(6) NOT NULL default '0',
  1152.   `max_check_attempts` smallint(6) NOT NULL default '0',
  1153.   `last_state` smallint(6) NOT NULL default '-1',
  1154.   `last_hard_state` smallint(6) NOT NULL default '-1',
  1155.   `output` varchar(255) NOT NULL default '',
  1156.   `long_output` TEXT NOT NULL default '',
  1157.   PRIMARY KEY (`statehistory_id`)
  1158. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historical host and service state changes';

  1159. -- --------------------------------------------------------

  1160. --
  1161. -- Table structure for table `monitor_systemcommands`
  1162. --

  1163. CREATE TABLE IF NOT EXISTS `monitor_systemcommands` (
  1164.   `systemcommand_id` int(11) NOT NULL auto_increment,
  1165.   `instance_id` smallint(6) NOT NULL default '0',
  1166.   `start_time` datetime NOT NULL default '0000-00-00 00:00:00',
  1167.   `start_time_usec` int(11) NOT NULL default '0',
  1168.   `end_time` datetime NOT NULL default '0000-00-00 00:00:00',
  1169.   `end_time_usec` int(11) NOT NULL default '0',
  1170.   `command_line` varchar(255) NOT NULL default '',
  1171.   `timeout` smallint(6) NOT NULL default '0',
  1172.   `early_timeout` smallint(6) NOT NULL default '0',
  1173.   `execution_time` double NOT NULL default '0',
  1174.   `return_code` smallint(6) NOT NULL default '0',
  1175.   `output` varchar(255) NOT NULL default '',
  1176.   `long_output` TEXT NOT NULL default '',
  1177.   PRIMARY KEY (`systemcommand_id`),
  1178.   KEY `instance_id` (`instance_id`),
  1179.   KEY `start_time` (`start_time`)
  1180. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historical system commands that are executed';

  1181. -- --------------------------------------------------------

  1182. --
  1183. -- Table structure for table `monitor_timedeventqueue`
  1184. --

  1185. CREATE TABLE IF NOT EXISTS `monitor_timedeventqueue` (
  1186.   `timedeventqueue_id` int(11) NOT NULL auto_increment,
  1187.   `instance_id` smallint(6) NOT NULL default '0',
  1188.   `event_type` smallint(6) NOT NULL default '0',
  1189.   `queued_time` datetime NOT NULL default '0000-00-00 00:00:00',
  1190.   `queued_time_usec` int(11) NOT NULL default '0',
  1191.   `scheduled_time` datetime NOT NULL default '0000-00-00 00:00:00',
  1192.   `recurring_event` smallint(6) NOT NULL default '0',
  1193.   `object_id` int(11) NOT NULL default '0',
  1194.   PRIMARY KEY (`timedeventqueue_id`),
  1195.   KEY `instance_id` (`instance_id`),
  1196.   KEY `event_type` (`event_type`),
  1197.   KEY `scheduled_time` (`scheduled_time`),
  1198.   KEY `object_id` (`object_id`)
  1199. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Current Nagios event queue';

  1200. -- --------------------------------------------------------

  1201. --
  1202. -- Table structure for table `monitor_timedevents`
  1203. --

  1204. CREATE TABLE IF NOT EXISTS `monitor_timedevents` (
  1205.   `timedevent_id` int(11) NOT NULL auto_increment,
  1206.   `instance_id` smallint(6) NOT NULL default '0',
  1207.   `event_type` smallint(6) NOT NULL default '0',
  1208.   `queued_time` datetime NOT NULL default '0000-00-00 00:00:00',
  1209.   `queued_time_usec` int(11) NOT NULL default '0',
  1210.   `event_time` datetime NOT NULL default '0000-00-00 00:00:00',
  1211.   `event_time_usec` int(11) NOT NULL default '0',
  1212.   `scheduled_time` datetime NOT NULL default '0000-00-00 00:00:00',
  1213.   `recurring_event` smallint(6) NOT NULL default '0',
  1214.   `object_id` int(11) NOT NULL default '0',
  1215.   `deletion_time` datetime NOT NULL default '0000-00-00 00:00:00',
  1216.   `deletion_time_usec` int(11) NOT NULL default '0',
  1217.   PRIMARY KEY (`timedevent_id`),
  1218.   KEY `instance_id` (`instance_id`),
  1219.   KEY `event_type` (`event_type`),
  1220.   KEY `scheduled_time` (`scheduled_time`),
  1221.   KEY `object_id` (`object_id`)
  1222. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historical events from the Nagios event queue';

  1223. -- --------------------------------------------------------

  1224. --
  1225. -- Table structure for table `monitor_timeperiods`
  1226. --

  1227. CREATE TABLE IF NOT EXISTS `monitor_timeperiods` (
  1228.   `timeperiod_id` int(11) NOT NULL auto_increment,
  1229.   `instance_id` smallint(6) NOT NULL default '0',
  1230.   `config_type` smallint(6) NOT NULL default '0',
  1231.   `timeperiod_object_id` int(11) NOT NULL default '0',
  1232.   `alias` varchar(255) NOT NULL default '',
  1233.   PRIMARY KEY (`timeperiod_id`),
  1234.   UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`timeperiod_object_id`)
  1235. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Timeperiod definitions';

  1236. -- --------------------------------------------------------

  1237. --
  1238. -- Table structure for table `monitor_timeperiod_timeranges`
  1239. --

  1240. CREATE TABLE IF NOT EXISTS `monitor_timeperiod_timeranges` (
  1241.   `timeperiod_timerange_id` int(11) NOT NULL auto_increment,
  1242.   `instance_id` smallint(6) NOT NULL default '0',
  1243.   `timeperiod_id` int(11) NOT NULL default '0',
  1244.   `day` smallint(6) NOT NULL default '0',
  1245.   `start_sec` int(11) NOT NULL default '0',
  1246.   `end_sec` int(11) NOT NULL default '0',
  1247.   PRIMARY KEY (`timeperiod_timerange_id`),
  1248.   UNIQUE KEY `instance_id` (`timeperiod_id`,`day`,`start_sec`,`end_sec`)
  1249. ) ENGINE=MyISAM AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Timeperiod definitions';
ndoutils-2.0.0/src目录中的db.c


点击(此处)折叠或打开

  1. /***************************************************************
  2.  * DB.C - Datatabase routines for NDO2DB daemon
  3.  *
  4.  * Copyright (c) 2009 Nagios Core Development Team and Community Contributors
  5.  * Copyright (c) 2005-2009 Ethan Galstad
  6.  *
  7.  * Last Modified: 07-11-2009
  8.  *
  9.  **************************************************************/

  10. /* include our project's header files */
  11. #include "../include/config.h"
  12. #include "../include/common.h"
  13. #include "../include/io.h"
  14. #include "../include/utils.h"
  15. #include "../include/protoapi.h"
  16. #include "../include/ndo2db.h"
  17. #include "../include/dbhandlers.h"
  18. #include "../include/db.h"

  19. extern int errno;

  20. extern ndo2db_dbconfig ndo2db_db_settings;
  21. extern time_t ndo2db_db_last_checkin_time;

  22. char *ndo2db_db_rawtablenames[NDO2DB_MAX_DBTABLES]={
  23.     "instances",
  24.     "conninfo",
  25.     "objects",
  26.     "objecttypes",
  27.     "logentries",
  28.     "systemcommands",
  29.     "eventhandlers",
  30.     "servicechecks",
  31.     "hostchecks",
  32.     "programstatus",
  33.     "externalcommands",
  34.     "servicestatus",
  35.     "hoststatus",
  36.     "processevents",
  37.     "timedevents",
  38.     "timedeventqueue",
  39.     "flappinghistory",
  40.     "commenthistory",
  41.     "comments",
  42.     "notifications",
  43.     "contactnotifications",
  44.     "contactnotificationmethods",
  45.     "acknowledgements",
  46.     "statehistory",
  47.     "downtimehistory",
  48.     "scheduleddowntime",
  49.     "configfiles",
  50.     "configfilevariables",
  51.     "runtimevariables",
  52.     "contactstatus",
  53.     "customvariablestatus",
  54.     "",
  55.     "",
  56.     "",
  57.     "",
  58.     "",
  59.     "",
  60.     "",
  61.     "",
  62.     "",
  63.     "commands",
  64.     "timeperiods",
  65.     "timeperiod_timeranges",
  66.     "contactgroups",
  67.     "contactgroup_members",
  68.     "hostgroups",
  69.     "hostgroup_members",
  70.     "servicegroups",
  71.     "servicegroup_members",
  72.     "hostescalations",
  73.     "hostescalation_contacts",
  74.     "serviceescalations",
  75.     "serviceescalation_contacts",
  76.     "hostdependencies",
  77.     "servicedependencies",
  78.     "contacts",
  79.     "contact_addresses",
  80.     "contact_notificationcommands",
  81.     "hosts",
  82.     "host_parenthosts",
  83.     "host_contacts",
  84.     "services",
  85.     "service_contacts",
  86.     "customvariables",
  87.     "host_contactgroups",
  88.     "service_contactgroups",
  89.     "hostescalation_contactgroups",
  90.     "serviceescalation_contactgroups",
  91.     "service_parentservices",
  92.         };


  93. char *ndo2db_db_tablenames[NDO2DB_MAX_DBTABLES];

  94. /*
  95. #define DEBUG_NDO2DB_QUERIES 1
  96. */

  97. /****************************************************************************/
  98. /* CONNECTION FUNCTIONS */
  99. /****************************************************************************/

  100. /* initialize database structures */
  101. int ndo2db_db_init(ndo2db_idi *idi){
  102.     register int x;

  103.     if(idi==NULL)
  104.         return NDO_ERROR;

  105.     /* initialize db server type */
  106.     idi->dbinfo.server_type=ndo2db_db_settings.server_type;

  107.     /* initialize table names */
  108.     for(x=0;x<NDO2DB_MAX_DBTABLES;x++){
  109.         if((ndo2db_db_tablenames[x]=(char *)malloc(strlen(ndo2db_db_rawtablenames[x])+((ndo2db_db_settings.dbprefix==NULL)?0:strlen(ndo2db_db_settings.dbprefix))+1))==NULL)
  110.             return NDO_ERROR;
  111.         sprintf(ndo2db_db_tablenames[x],"%s%s",(ndo2db_db_settings.dbprefix==NULL)?"":ndo2db_db_settings.dbprefix,ndo2db_db_rawtablenames[x]);
  112.      }

  113.     /* initialize other variables */
  114.     idi->dbinfo.connected=NDO_FALSE;
  115.     idi->dbinfo.error=NDO_FALSE;
  116.     idi->dbinfo.instance_id=0L;
  117.     idi->dbinfo.conninfo_id=0L;
  118.     idi->dbinfo.latest_program_status_time=(time_t)0L;
  119.     idi->dbinfo.latest_host_status_time=(time_t)0L;
  120.     idi->dbinfo.latest_service_status_time=(time_t)0L;
  121.     idi->dbinfo.latest_queued_event_time=(time_t)0L;
  122.     idi->dbinfo.latest_realtime_data_time=(time_t)0L;
  123.     idi->dbinfo.latest_comment_time=(time_t)0L;
  124.     idi->dbinfo.clean_event_queue=NDO_FALSE;
  125.     idi->dbinfo.last_notification_id=0L;
  126.     idi->dbinfo.last_contact_notification_id=0L;
  127.     idi->dbinfo.max_timedevents_age=ndo2db_db_settings.max_timedevents_age;
  128.     idi->dbinfo.max_systemcommands_age=ndo2db_db_settings.max_systemcommands_age;
  129.     idi->dbinfo.max_servicechecks_age=ndo2db_db_settings.max_servicechecks_age;
  130.     idi->dbinfo.max_hostchecks_age=ndo2db_db_settings.max_hostchecks_age;
  131.     idi->dbinfo.max_eventhandlers_age=ndo2db_db_settings.max_eventhandlers_age;
  132.     idi->dbinfo.max_externalcommands_age=ndo2db_db_settings.max_externalcommands_age;
  133.     idi->dbinfo.max_notifications_age=ndo2db_db_settings.max_notifications_age;
  134.     idi->dbinfo.max_contactnotifications_age=ndo2db_db_settings.max_contactnotifications_age;
  135.     idi->dbinfo.max_contactnotificationmethods_age=ndo2db_db_settings.max_contactnotificationmethods_age;
  136.     idi->dbinfo.max_logentries_age=ndo2db_db_settings.max_logentries_age;
  137.     idi->dbinfo.max_acknowledgements_age=ndo2db_db_settings.max_acknowledgements_age;    
  138.     idi->dbinfo.last_table_trim_time=(time_t)0L;
  139.     idi->dbinfo.last_logentry_time=(time_t)0L;
  140.     idi->dbinfo.last_logentry_data=NULL;
  141.     idi->dbinfo.object_hashlist=NULL;

  142.     /* initialize db structures, etc. */
  143.     switch(idi->dbinfo.server_type){
  144.     case NDO2DB_DBSERVER_MYSQL:
  145. #ifdef USE_MYSQL
  146.         if(!mysql_init(&idi->dbinfo.mysql_conn)){
  147.             syslog(LOG_USER|LOG_INFO,"Error: mysql_init() failed\n");
  148.             return NDO_ERROR;
  149.      }
  150. #endif
  151.         break;
  152.     case NDO2DB_DBSERVER_PGSQL:
  153. #ifdef USE_PGSQL
  154.         idi->dbinfo.pgsql_conn=NULL;
  155.         idi->dbinfo.pgsql_result=NULL;
  156. #endif
  157.         break;
  158.     default:
  159.         break;
  160.      }

  161.     return NDO_OK;
  162.         }


  163. /* clean up database structures */
  164. int ndo2db_db_deinit(ndo2db_idi *idi){
  165.     register int x;

  166.     if(idi==NULL)
  167.         return NDO_ERROR;

  168.     /* free table names */
  169.     for(x=0;x<NDO2DB_MAX_DBTABLES;x++){
  170.         if(ndo2db_db_tablenames[x])
  171.             free(ndo2db_db_tablenames[x]);
  172.         ndo2db_db_tablenames[x]=NULL;
  173.      }

  174.     /* free cached object ids */
  175.     ndo2db_free_cached_object_ids(idi);

  176.     return NDO_OK;
  177.         }


  178. /* connects to the database server */
  179. int ndo2db_db_connect(ndo2db_idi *idi){
  180.     int result=NDO_OK;

  181.     if(idi==NULL)
  182.         return NDO_ERROR;

  183.     /* we're already connected... */
  184.     if(idi->dbinfo.connected==NDO_TRUE)
  185.         return NDO_OK;

  186.     switch(idi->dbinfo.server_type){
  187.     case NDO2DB_DBSERVER_MYSQL:
  188. #ifdef USE_MYSQL
  189.         if(!mysql_real_connect(&idi->dbinfo.mysql_conn,ndo2db_db_settings.host,ndo2db_db_settings.username,ndo2db_db_settings.password,ndo2db_db_settings.dbname,ndo2db_db_settings.port,NULL,0)){

  190.             mysql_close(&idi->dbinfo.mysql_conn);
  191.             syslog(LOG_USER|LOG_INFO,"Error: Could not connect to MySQL database: %s",mysql_error(&idi->dbinfo.mysql_conn));
  192.             result=NDO_ERROR;
  193.             idi->disconnect_client=NDO_TRUE;
  194.          }
  195.         else{
  196.             /*rubydrew@qq.com*/
  197.             mysql_set_character_set(&idi->dbinfo.mysql_conn, "utf8");
  198.             idi->dbinfo.connected=NDO_TRUE;
  199.             syslog(LOG_USER|LOG_DEBUG,"Successfully connected to MySQL database");
  200.          }
  201. #endif
  202.         break;
  203.     case NDO2DB_DBSERVER_PGSQL:
  204. #ifdef USE_PGSQL
  205.         snprintf(connect_string,sizeof(connect_string)-1,"host='%s' port=%d dbname='%s' user='%s' password='%s'",ndo2db_db_settings.host,ndo2db_db_settings.port,ndo2db_db_settings.dbname,ndo2db_db_settings.username,ndo2db_db_settings.password);
  206.         connect_string[sizeof(connect_string)-1]='\x0';
  207.         idi->dbinfo.pgsql_conn=PQconnectdb(connect_string);

  208.         if(PQstatus(idi->dbinfo.pgsql_conn)==CONNECTION_BAD){
  209.             PQfinish(idi->dbinfo.pgsql_conn);
  210.             syslog(LOG_USER|LOG_INFO,"Error: Could not connect to PostgreSQL database: %s",PQerrorMessage(idi->dbinfo.pgsql_conn));
  211.             result=NDO_ERROR;
  212.             idi->disconnect_client=NDO_TRUE;
  213.          }
  214.         else{
  215.             idi->dbinfo.connected=NDO_TRUE;
  216.             syslog(LOG_USER|LOG_DEBUG,"Successfully connected to PostgreSQL database");
  217.          }
  218. #endif
  219.         break;
  220.     default:
  221.         break;
  222.      }

  223.     return result;
  224.         }


  225. /* disconnects from the database server */
  226. int ndo2db_db_disconnect(ndo2db_idi *idi){

  227.     if(idi==NULL)
  228.         return NDO_ERROR;

  229.     /* we're not connected... */
  230.     if(idi->dbinfo.connected==NDO_FALSE)
  231.         return NDO_OK;

  232.     switch(idi->dbinfo.server_type){
  233.     case NDO2DB_DBSERVER_MYSQL:
  234. #ifdef USE_MYSQL
  235.         /* close the connection to the database server */        
  236.         mysql_close(&idi->dbinfo.mysql_conn);
  237.         idi->dbinfo.connected=NDO_FALSE;
  238.         syslog(LOG_USER|LOG_DEBUG,"Successfully disconnected from MySQL database");
  239. #endif
  240.         break;
  241.     case NDO2DB_DBSERVER_PGSQL:
  242. #ifdef USE_PGSQL
  243.         /* close database connection and cleanup */
  244.         if(PQstatus(idi->dbinfo.pgsql_conn)!=CONNECTION_BAD)
  245.             PQfinish(idi->dbinfo.pgsql_conn);
  246.         idi->dbinfo.connected=NDO_FALSE;
  247.         syslog(LOG_USER|LOG_DEBUG,"Successfully disconnected from PostgreSQL database");
  248. #endif
  249.         break;
  250.     default:
  251.         break;
  252.      }

  253.     return NDO_OK;
  254.         }


  255. /* post-connect routines */
  256. int ndo2db_db_hello(ndo2db_idi *idi){
  257.     char *buf=NULL;
  258.     char *ts=NULL;
  259.     int result=NDO_OK;
  260.     int have_instance=NDO_FALSE;
  261.     time_t current_time;

  262.     /* make sure we have an instance name */
  263.     if(idi->instance_name==NULL)
  264.         idi->instance_name=strdup("default");

  265.     /* get existing instance */
  266.     if(asprintf(&buf,"SELECT instance_id FROM %s WHERE instance_name='%s'",ndo2db_db_tablenames[NDO2DB_DBTABLE_INSTANCES],idi->instance_name)==-1)
  267.         buf=NULL;
  268.     if((result=ndo2db_db_query(idi,buf))==NDO_OK){
  269.         switch(idi->dbinfo.server_type){
  270.         case NDO2DB_DBSERVER_MYSQL:
  271. #ifdef USE_MYSQL
  272.             idi->dbinfo.mysql_result=mysql_store_result(&idi->dbinfo.mysql_conn);
  273.             if((idi->dbinfo.mysql_row=mysql_fetch_row(idi->dbinfo.mysql_result))!=NULL){
  274.                 ndo2db_convert_string_to_unsignedlong(idi->dbinfo.mysql_row[0],&idi->dbinfo.instance_id);
  275.                 have_instance=NDO_TRUE;
  276.          }
  277.             mysql_free_result(idi->dbinfo.mysql_result);
  278.             idi->dbinfo.mysql_result=NULL;
  279. #endif
  280.             break;
  281.         default:
  282.             break;
  283.          }
  284.      }
  285.     free(buf);

  286.     /* insert new instance if necessary */
  287.     if(have_instance==NDO_FALSE){
  288.         if(asprintf(&buf,"INSERT INTO %s SET instance_name='%s'",ndo2db_db_tablenames[NDO2DB_DBTABLE_INSTANCES],idi->instance_name)==-1)
  289.             buf=NULL;
  290.         if((result=ndo2db_db_query(idi,buf))==NDO_OK){
  291.             switch(idi->dbinfo.server_type){
  292.             case NDO2DB_DBSERVER_MYSQL:
  293. #ifdef USE_MYSQL
  294.                 idi->dbinfo.instance_id=mysql_insert_id(&idi->dbinfo.mysql_conn);
  295. #endif
  296.                 break;
  297.             default:
  298.                 break;
  299.              }
  300.      }
  301.         free(buf);
  302.      }
  303.     
  304.     ts=ndo2db_db_timet_to_sql(idi,idi->data_start_time);

  305.     /* record initial connection information */
  306.     if(asprintf(&buf,"INSERT INTO %s SET instance_id='%lu', connect_time=NOW(), last_checkin_time=NOW(), bytes_processed='0', lines_processed='0', entries_processed='0', agent_name='%s', agent_version='%s', disposition='%s', connect_source='%s', connect_type='%s', data_start_time=%s"
  307.          ,ndo2db_db_tablenames[NDO2DB_DBTABLE_CONNINFO]
  308.          ,idi->dbinfo.instance_id
  309.          ,idi->agent_name
  310.          ,idi->agent_version
  311.          ,idi->disposition
  312.          ,idi->connect_source
  313.          ,idi->connect_type
  314.          ,ts
  315.          )==-1)
  316.         buf=NULL;
  317.     if((result=ndo2db_db_query(idi,buf))==NDO_OK){
  318.         switch(idi->dbinfo.server_type){
  319.         case NDO2DB_DBSERVER_MYSQL:
  320. #ifdef USE_MYSQL
  321.             idi->dbinfo.conninfo_id=mysql_insert_id(&idi->dbinfo.mysql_conn);
  322. #endif
  323.             break;
  324.         default:
  325.             break;
  326.          }
  327.      }
  328.     free(buf);
  329.     free(ts);

  330.     /* get cached object ids... */
  331.     ndo2db_get_cached_object_ids(idi);

  332.     /* get latest times from various tables... */
  333.     ndo2db_db_get_latest_data_time(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_PROGRAMSTATUS],"status_update_time",(unsigned long *)&idi->dbinfo.latest_program_status_time);
  334.     ndo2db_db_get_latest_data_time(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_HOSTSTATUS],"status_update_time",(unsigned long *)&idi->dbinfo.latest_host_status_time);
  335.     ndo2db_db_get_latest_data_time(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_SERVICESTATUS],"status_update_time",(unsigned long *)&idi->dbinfo.latest_service_status_time);
  336.     ndo2db_db_get_latest_data_time(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_CONTACTSTATUS],"status_update_time",(unsigned long *)&idi->dbinfo.latest_contact_status_time);
  337.     ndo2db_db_get_latest_data_time(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_TIMEDEVENTQUEUE],"queued_time",(unsigned long *)&idi->dbinfo.latest_queued_event_time);
  338.     ndo2db_db_get_latest_data_time(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_COMMENTS],"entry_time",(unsigned long *)&idi->dbinfo.latest_comment_time);

  339.     /* calculate time of latest realtime data */
  340.     idi->dbinfo.latest_realtime_data_time=(time_t)0L;
  341.     if(idi->dbinfo.latest_program_status_time>idi->dbinfo.latest_realtime_data_time)
  342.         idi->dbinfo.latest_realtime_data_time=idi->dbinfo.latest_program_status_time;
  343.     if(idi->dbinfo.latest_host_status_time>idi->dbinfo.latest_realtime_data_time)
  344.         idi->dbinfo.latest_realtime_data_time=idi->dbinfo.latest_host_status_time;
  345.     if(idi->dbinfo.latest_service_status_time>idi->dbinfo.latest_realtime_data_time)
  346.         idi->dbinfo.latest_realtime_data_time=idi->dbinfo.latest_service_status_time;
  347.     if(idi->dbinfo.latest_contact_status_time>idi->dbinfo.latest_realtime_data_time)
  348.         idi->dbinfo.latest_realtime_data_time=idi->dbinfo.latest_contact_status_time;
  349.     if(idi->dbinfo.latest_queued_event_time>idi->dbinfo.latest_realtime_data_time)
  350.         idi->dbinfo.latest_realtime_data_time=idi->dbinfo.latest_queued_event_time;

  351.     /* get current time */
  352.     /* make sure latest time stamp isn't in the future - this will cause problems if a backwards system time change occurs */
  353.     time(¤t_time);
  354.     if(idi->dbinfo.latest_realtime_data_time>current_time)
  355.         idi->dbinfo.latest_realtime_data_time=current_time;

  356.     /* set flags to clean event queue, etc. */
  357.     idi->dbinfo.clean_event_queue=NDO_TRUE;

  358.     /* set misc data */
  359.     idi->dbinfo.last_notification_id=0L;
  360.     idi->dbinfo.last_contact_notification_id=0L;

  361.     return result;
  362.         }


  363. /* pre-disconnect routines */
  364. int ndo2db_db_goodbye(ndo2db_idi *idi){
  365.     int result=NDO_OK;
  366.     char *buf=NULL;
  367.     char *ts=NULL;

  368.     ts=ndo2db_db_timet_to_sql(idi,idi->data_end_time);

  369.     /* record last connection information */
  370.     if(asprintf(&buf,"UPDATE %s SET disconnect_time=NOW(), last_checkin_time=NOW(), data_end_time=%s, bytes_processed='%lu', lines_processed='%lu', entries_processed='%lu' WHERE conninfo_id='%lu'"
  371.          ,ndo2db_db_tablenames[NDO2DB_DBTABLE_CONNINFO]
  372.          ,ts
  373.          ,idi->bytes_processed
  374.          ,idi->lines_processed
  375.          ,idi->entries_processed
  376.          ,idi->dbinfo.conninfo_id
  377.          )==-1)
  378.         buf=NULL;
  379.     result=ndo2db_db_query(idi,buf);
  380.     free(buf);

  381.     free(ts);

  382.     return result;
  383.         }


  384. /* checking routines */
  385. int ndo2db_db_checkin(ndo2db_idi *idi){
  386.     int result=NDO_OK;
  387.     char *buf=NULL;

  388.     /* record last connection information */
  389.     if(asprintf(&buf,"UPDATE %s SET last_checkin_time=NOW(), bytes_processed='%lu', lines_processed='%lu', entries_processed='%lu' WHERE conninfo_id='%lu'"
  390.          ,ndo2db_db_tablenames[NDO2DB_DBTABLE_CONNINFO]
  391.          ,idi->bytes_processed
  392.          ,idi->lines_processed
  393.          ,idi->entries_processed
  394.          ,idi->dbinfo.conninfo_id
  395.          )==-1)
  396.         buf=NULL;
  397.     result=ndo2db_db_query(idi,buf);
  398.     free(buf);

  399.     time(&ndo2db_db_last_checkin_time);

  400.     return result;
  401.         }



  402. /****************************************************************************/
  403. /* MISC FUNCTIONS */
  404. /****************************************************************************/

  405. /* escape a string for a SQL statement */
  406. char *ndo2db_db_escape_string(ndo2db_idi *idi, char *buf){
  407.     register int x,y,z;
  408.     char *newbuf=NULL;

  409.     if(idi==NULL || buf==NULL)
  410.         return NULL;

  411.     z=strlen(buf);

  412.     /* allocate space for the new string */
  413.     if((newbuf=(char *)malloc((z*2)+1))==NULL)
  414.         return NULL;

  415.     /* escape characters */
  416.     for(x=0,y=0;x<z;x++){

  417.         if(idi->dbinfo.server_type==NDO2DB_DBSERVER_MYSQL){
  418.             if(buf[x]=='\'' || buf[x]=='\"' || buf[x]=='*' || buf[x]=='\\' || buf[x]=='$' || buf[x]=='?' || buf[x]=='.' || buf[x]=='^' || buf[x]=='+' || buf[x]=='[' || buf[x]==']' || buf[x]=='(' || buf[x]==')')
  419.                 newbuf[y++]='\\';
  420.          }
  421.         else if(idi->dbinfo.server_type==NDO2DB_DBSERVER_PGSQL){
  422.             if(! (isspace(buf[x]) || isalnum(buf[x]) || (buf[x]=='_')) )
  423.                 newbuf[y++]='\\';
  424.          }

  425.         newbuf[y++]=buf[x];
  426.      }

  427.     /* terminate escape string */
  428.     newbuf [y]='\0';

  429.     return newbuf;
  430.         }


  431. /* SQL query conversion of time_t format to date/time format */
  432. char *ndo2db_db_timet_to_sql(ndo2db_idi *idi, time_t t){
  433.     char *buf=NULL;

  434.     switch(idi->dbinfo.server_type){
  435.     case NDO2DB_DBSERVER_MYSQL:
  436. #ifdef USE_MYSQL
  437.         asprintf(&buf,"FROM_UNIXTIME(%lu)",(unsigned long)t);
  438. #endif
  439.         break;
  440.     case NDO2DB_DBSERVER_PGSQL:
  441. #ifdef USE_PGSQL
  442.         asprintf(&buf,"FROM_UNIXTIME(%lu)",(unsigned long)t);
  443. #endif
  444.         break;
  445.     default:
  446.         break;
  447.      }
  448.     
  449.     return buf;
  450.         }


  451. /* SQL query conversion of date/time format to time_t format */
  452. char *ndo2db_db_sql_to_timet(ndo2db_idi *idi, char *field){
  453.     char *buf=NULL;

  454.     switch(idi->dbinfo.server_type){
  455.     case NDO2DB_DBSERVER_MYSQL:
  456. #ifdef USE_MYSQL
  457.         asprintf(&buf,"UNIX_TIMESTAMP(%s)",(field==NULL)?"":field);
  458. #endif
  459.         break;
  460.     case NDO2DB_DBSERVER_PGSQL:
  461. #ifdef USE_PGSQL
  462.         asprintf(&buf,"UNIX_TIMESTAMP(%s",(field==NULL)?"":field);
  463. #endif
  464.         break;
  465.     default:
  466.         break;
  467.      }
  468.     
  469.     return buf;
  470.         }


  471. /* executes a SQL statement */
  472. int ndo2db_db_query(ndo2db_idi *idi, char *buf){
  473.     int result=NDO_OK;
  474.     int query_result=0;

  475.     if(idi==NULL || buf==NULL)
  476.         return NDO_ERROR;

  477.     /* if we're not connected, try and reconnect... */
  478.     if(idi->dbinfo.connected==NDO_FALSE){
  479.         if(ndo2db_db_connect(idi)==NDO_ERROR)
  480.             return NDO_ERROR;
  481.         ndo2db_db_hello(idi);
  482.      }

  483. #ifdef DEBUG_NDO2DB_QUERIES
  484.     printf("%s\n\n",buf);
  485. #endif

  486.     ndo2db_log_debug_info(NDO2DB_DEBUGL_SQL,0,"%s\n",buf);

  487.     switch(idi->dbinfo.server_type){
  488.     case NDO2DB_DBSERVER_MYSQL:
  489. #ifdef USE_MYSQL
  490.         if((query_result=mysql_query(&idi->dbinfo.mysql_conn,buf))){
  491.             syslog(LOG_USER|LOG_INFO,"Error: mysql_query() failed for '%s'\n",buf);
  492.             syslog(LOG_USER|LOG_INFO,"mysql_error: '%s'\n", mysql_error(&idi->dbinfo.mysql_conn));
  493.             result=NDO_ERROR;
  494.          }
  495. #endif
  496.         break;
  497.     case NDO2DB_DBSERVER_PGSQL:
  498. #ifdef USE_PGSQL
  499.         idi->dbinfo.pgsql_result==PQexec(idi->dbinfo.pgsql_conn,buf);
  500.         if((query_result=PQresultStatus(idi->dbinfo.pgsql_result))!=PGRES_COMMAND_OK){
  501.             syslog(LOG_USER|LOG_INFO,"Error: PQexec() failed for '%s'\n",buf);
  502.             PQclear(idi->dbinfo.pgsql_result);
  503.             result=NDO_ERROR;
  504.      }
  505. #endif
  506.         break;
  507.     default:
  508.         break;
  509.      }

  510.     /* handle errors */
  511.     if(result==NDO_ERROR)
  512.         ndo2db_handle_db_error(idi,query_result);

  513.     return result;
  514.         }


  515. /* frees memory associated with a query */
  516. int ndo2db_db_free_query(ndo2db_idi *idi){

  517.     if(idi==NULL)
  518.         return NDO_ERROR;

  519.     switch(idi->dbinfo.server_type){
  520.     case NDO2DB_DBSERVER_MYSQL:
  521. #ifdef USE_MYSQL
  522. #endif
  523.         break;
  524.     case NDO2DB_DBSERVER_PGSQL:
  525. #ifdef USE_PGSQL
  526.         PQclear(idi->dbinfo.pgsql_result);
  527. #endif
  528.         break;
  529.     default:
  530.         break;
  531.      }

  532.     return NDO_OK;
  533.         }


  534. /* handles SQL query errors */
  535. int ndo2db_handle_db_error(ndo2db_idi *idi, int query_result){
  536.     int result=0;

  537.     if(idi==NULL)
  538.         return NDO_ERROR;

  539.     /* we're not currently connected... */
  540.     if(idi->dbinfo.connected==NDO_FALSE)
  541.         return NDO_OK;

  542.     switch(idi->dbinfo.server_type){
  543.     case NDO2DB_DBSERVER_MYSQL:
  544. #ifdef USE_MYSQL
  545.         result=mysql_errno(&idi->dbinfo.mysql_conn);
  546.         if(result==CR_SERVER_LOST || result==CR_SERVER_GONE_ERROR){
  547.             syslog(LOG_USER|LOG_INFO,"Error: Connection to MySQL database has been lost!\n");
  548.             ndo2db_db_disconnect(idi);
  549.             idi->disconnect_client=NDO_TRUE;
  550.          }
  551. #endif
  552.         break;
  553.     case NDO2DB_DBSERVER_PGSQL:
  554. #ifdef USE_PGSQL
  555.         result=PQstatus(idi->dbinfo.pgsql_conn);
  556.         if(result!=CONNECTION_OK){
  557.             syslog(LOG_USER|LOG_INFO,"Error: Connection to PostgreSQL database has been lost!\n");
  558.             ndo2db_db_disconnect(idi);
  559.             idi->disconnect_client=NDO_TRUE;
  560.      }
  561. #endif
  562.         break;
  563.     default:
  564.         break;
  565.      }

  566.     return NDO_OK;
  567.         }


  568. /* clears data from a given table (current instance only) */
  569. int ndo2db_db_clear_table(ndo2db_idi *idi, char *table_name){
  570.     char *buf=NULL;
  571.     int result=NDO_OK;

  572.     if(idi==NULL || table_name==NULL)
  573.         return NDO_ERROR;

  574.     if(asprintf(&buf,"DELETE FROM %s WHERE instance_id='%lu'"
  575.          ,table_name
  576.          ,idi->dbinfo.instance_id
  577.          )==-1)
  578.         buf=NULL;

  579.     result=ndo2db_db_query(idi,buf);
  580.     free(buf);

  581.     return result;
  582.         }
  583.         

  584. /* gets latest data time value from a given table */
  585. int ndo2db_db_get_latest_data_time(ndo2db_idi *idi, char *table_name, char *field_name, unsigned long *t){
  586.     char *buf=NULL;
  587.     char *ts[1];
  588.     int result=NDO_OK;

  589.     if(idi==NULL || table_name==NULL || field_name==NULL || t==NULL)
  590.         return NDO_ERROR;

  591.     *t=(time_t)0L;
  592.     ts[0]=ndo2db_db_sql_to_timet(idi,field_name);

  593.     if(asprintf(&buf,"SELECT %s AS latest_time FROM %s WHERE instance_id='%lu' ORDER BY %s DESC LIMIT 0,1"
  594.          ,ts[0]
  595.          ,table_name
  596.          ,idi->dbinfo.instance_id
  597.          ,field_name
  598.          )==-1)
  599.         buf=NULL;

  600.     if((result=ndo2db_db_query(idi,buf))==NDO_OK){
  601.         switch(idi->dbinfo.server_type){
  602.         case NDO2DB_DBSERVER_MYSQL:
  603. #ifdef USE_MYSQL
  604.             idi->dbinfo.mysql_result=mysql_store_result(&idi->dbinfo.mysql_conn);
  605.             if((idi->dbinfo.mysql_row=mysql_fetch_row(idi->dbinfo.mysql_result))!=NULL){
  606.                 ndo2db_convert_string_to_unsignedlong(idi->dbinfo.mysql_row[0],t);
  607.          }
  608.             mysql_free_result(idi->dbinfo.mysql_result);
  609.             idi->dbinfo.mysql_result=NULL;
  610. #endif
  611.             break;
  612.         default:
  613.             break;
  614.          }
  615.      }
  616.     free(buf);
  617.     free(ts[0]);

  618.     return result;
  619.         }
  620.         

  621. /* trim/delete old data from a given table */
  622. int ndo2db_db_trim_data_table(ndo2db_idi *idi, char *table_name, char *field_name, unsigned long t){
  623.     char *buf=NULL;
  624.     char *ts[1];
  625.     int result=NDO_OK;

  626.     if(idi==NULL || table_name==NULL || field_name==NULL)
  627.         return NDO_ERROR;

  628.     ts[0]=ndo2db_db_timet_to_sql(idi,(time_t)t);

  629.     if(asprintf(&buf,"DELETE FROM %s WHERE instance_id='%lu' AND %s<%s"
  630.          ,table_name
  631.          ,idi->dbinfo.instance_id
  632.          ,field_name
  633.          ,ts[0]
  634.          )==-1)
  635.         buf=NULL;

  636.     result=ndo2db_db_query(idi,buf);
  637.     free(buf);
  638.     free(ts[0]);

  639.     return result;
  640.         }
  641.         

  642. /* performs some periodic table maintenance... */
  643. int ndo2db_db_perform_maintenance(ndo2db_idi *idi){
  644.     time_t current_time;

  645.     /* get the current time */
  646.     time(¤t_time);

  647.     /* trim tables */
  648.     if(((unsigned long)current_time-60)>(unsigned long)idi->dbinfo.last_table_trim_time){
  649.         if(idi->dbinfo.max_timedevents_age>0L)
  650.             ndo2db_db_trim_data_table(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_TIMEDEVENTS],"scheduled_time",(time_t)((unsigned long)current_time-idi->dbinfo.max_timedevents_age));
  651.         if(idi->dbinfo.max_systemcommands_age>0L)
  652.             ndo2db_db_trim_data_table(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_SYSTEMCOMMANDS],"start_time",(time_t)((unsigned long)current_time-idi->dbinfo.max_systemcommands_age));
  653.         if(idi->dbinfo.max_servicechecks_age>0L)
  654.             ndo2db_db_trim_data_table(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_SERVICECHECKS],"start_time",(time_t)((unsigned long)current_time-idi->dbinfo.max_servicechecks_age));
  655.         if(idi->dbinfo.max_hostchecks_age>0L)
  656.             ndo2db_db_trim_data_table(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_HOSTCHECKS],"start_time",(time_t)((unsigned long)current_time-idi->dbinfo.max_hostchecks_age));
  657.         if(idi->dbinfo.max_eventhandlers_age>0L)
  658.             ndo2db_db_trim_data_table(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_EVENTHANDLERS],"start_time",(time_t)((unsigned long)current_time-idi->dbinfo.max_eventhandlers_age));
  659.         if(idi->dbinfo.max_externalcommands_age>0L)
  660.             ndo2db_db_trim_data_table(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_EXTERNALCOMMANDS],"entry_time",(time_t)((unsigned long)current_time-idi->dbinfo.max_externalcommands_age));
  661.         if(idi->dbinfo.max_notifications_age>0L)
  662.             ndo2db_db_trim_data_table(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_NOTIFICATIONS],"entry_time",(time_t)((unsigned long)current_time-idi->dbinfo.max_notifications_age));

  663.         if(idi->dbinfo.max_contactnotifications_age>0L)
  664.             ndo2db_db_trim_data_table(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_CONTACTNOTIFICATIONS],"entry_time",(time_t)((unsigned long)current_time-idi->dbinfo.max_contactnotifications_age));
  665.         if(idi->dbinfo.max_contactnotificationmethods_age>0L)
  666.             ndo2db_db_trim_data_table(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_CONTACTNOTIFICATIONMETHODS],"entry_time",(time_t)((unsigned long)current_time-idi->dbinfo.max_contactnotificationmethods_age));
  667.         if(idi->dbinfo.max_logentries_age>0L)
  668.             ndo2db_db_trim_data_table(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_LOGENTRIES],"entry_time",(time_t)((unsigned long)current_time-idi->dbinfo.max_logentries_age));
  669.         if(idi->dbinfo.max_acknowledgements_age>0L)
  670.             ndo2db_db_trim_data_table(idi,ndo2db_db_tablenames[NDO2DB_DBTABLE_ACKNOWLEDGEMENTS],"entry_time

ndoutils-2.0.1-utf8(完美解决中文乱码问题) 

软件下载地址:http://download.csdn.net/detail/drew27/8475389



参考资料:http://blog.sina.com.cn/s/blog_620f4cf70100pvlv.html

阅读(2363) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~