root/trunk/setup.php @ 112

Revision 112, 81.7 KB (checked in by divagater, 5 years ago)

Various updates

Line 
1<?php
2/*
3 +-------------------------------------------------------------------------+
4 | Nagios Plugin for Cacti                                                 |
5 |                                                                         |
6 | Copyright (C) 2007 Billy Gunn (billy@gunn.org)                          |
7 |                                                                         |
8 | This program is free software; you can redistribute it and/or           |
9 | modify it under the terms of the GNU General Public License             |
10 | as published by the Free Software Foundation; either version 2          |
11 | of the License, or (at your option) any later version.                  |
12 |                                                                         |
13 | This program is distributed in the hope that it will be useful,         |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
16 | GNU General Public License for more details.                            |
17 +-------------------------------------------------------------------------+
18 | Cacti and Nagios are the copyright of their respective owners.          |
19 +-------------------------------------------------------------------------+
20*/
21
22function plugin_init_npc() {
23    global $plugin_hooks;
24    $plugin_hooks['top_header_tabs']['npc'] = 'npc_show_tab';
25    $plugin_hooks['top_graph_header_tabs']['npc'] = 'npc_show_tab';
26    $plugin_hooks['config_arrays']['npc'] = 'npc_config_arrays';
27    $plugin_hooks['draw_navigation_text']['npc'] = 'npc_draw_navigation_text';
28    $plugin_hooks['config_form']['npc'] = 'npc_config_form';
29    $plugin_hooks['api_device_save']['npc'] = 'npc_api_device_save';
30    $plugin_hooks['top_graph_refresh']['npc'] = 'npc_top_graph_refresh';
31    $plugin_hooks['config_settings']['npc'] = 'npc_config_settings';
32}
33
34function npc_version () {
35    return array(   'name'          => 'npc',
36                    'version'       => '0.2.0',
37                    'longname'      => 'Nagios plugin for Cacti',
38                    'author'        => 'Billy Gunn',
39                    'homepage'      => 'http://cactiusers.org',
40                    'email'         => 'billy@gunn.org',
41                    'url'           => 'http://cactiusers.org/cacti/versions.php'
42    );
43}
44
45function npc_top_graph_refresh() {
46    // Don't want to refresh so set very high
47    return('2592000');
48}
49
50function npc_config_arrays () {
51
52    global $user_auth_realms, $user_auth_realm_filenames, $npc_date_format, $npc_time_format;
53    global $npc_default_settings;
54
55    $user_auth_realms[32]='View NPC';
56    $user_auth_realm_filenames['npc.php'] = 32;
57    $user_auth_realm_filenames['test.php'] = 32;
58    $user_auth_realm_filenames['npc_layout.php'] = 32;
59    $user_auth_realm_filenames['npc_service_detail.php'] = 32;
60
61    $npc_date_format = array(
62        "Y-m-d" => "2007-12-27",
63        "m-d-Y" => "12-27-2007",
64        "d-m-Y" => "27-12-2007",
65        "Y/m/d" => "2007/12/27",
66        "m/d/Y" => "12/27/2007",
67        "d/m/Y" => "27/12/2007",
68        "Y.m.d" => "2007.12.27",
69        "d.m.Y" => "27.12.2007",
70        "m.d.Y" => "12.27.2007"
71    );
72
73    $npc_time_format = array(
74        "H:i:s"  => "23:07",
75        "h:i:sa" => "11:07pm",
76        "h:i:sA" => "11:07PM",
77        "H.i.s"  => "23.07",
78        "h.i.sa" => "11.07pm",
79        "h.i.sA" => "11.07PM"
80    );
81
82    $npc_default_settings = array(
83        'date_format' => "s%3AY-m-d",
84        'time_format' => "s%3AH%3Ai%3As",
85
86        "serviceProblems" => 'o%3Acollapsed%3Db%253A0%5Ecolumn%3Ds%253Adashcol1%5Ehidden%3Db%253A0%5Eindex%3Ds%253A0%5Erefresh%3Dn%253A60%5Erows%3Dn%253A10',
87        "serviceSummary" => 'o%3Acollapsed%3Db%253A0%5Ecolumn%3Ds%253Adashcol1%5Ehidden%3Db%253A0%5Eindex%3Ds%253A1%5Erefresh%3Dn%253A60%5Erows%3Dn%253A10',
88        "servicegroupServiceStatus" => 'o%3Acollapsed%3Db%253A0%5Ecolumn%3Ds%253Adashcol1%5Ehidden%3Db%253A0%5Eindex%3Ds%253A2%5Erefresh%3Dn%253A60%5Erows%3Dn%253A10',
89        "servicegroupHostStatus" => 'o%3Acollapsed%3Db%253A0%5Ecolumn%3Ds%253Adashcol1%5Ehidden%3Db%253A0%5Eindex%3Ds%253A3%5Erefresh%3Dn%253A60%5Erows%3Dn%253A10',
90        "monitoringPerf" => 'o%3Acollapsed%3Db%253A0%5Ecolumn%3Ds%253Adashcol1%5Ehidden%3Db%253A1%5Eindex%3Ds%253A4%5Erefresh%3Dn%253A60%5Erows%3Dn%253A10',
91
92        "hostProblems" => 'o%3Acollapsed%3Db%253A0%5Ecolumn%3Ds%253Adashcol2%5Ehidden%3Db%253A0%5Eindex%3Ds%253A0%5Erefresh%3Dn%253A60%5Erows%3Dn%253A10',
93        "hostSummary" => 'o%3Acollapsed%3Db%253A0%5Ecolumn%3Ds%253Adashcol2%5Ehidden%3Db%253A0%5Eindex%3Ds%253A1%5Erefresh%3Dn%253A60%5Erows%3Dn%253A10',
94        "hostgroupServiceStatus" => 'o%3Acollapsed%3Db%253A0%5Ecolumn%3Ds%253Adashcol2%5Ehidden%3Db%253A0%5Eindex%3Ds%253A2%5Erefresh%3Dn%253A60%5Erows%3Dn%253A10',
95        "hostgroupHostStatus" => 'o%3Acollapsed%3Db%253A0%5Ecolumn%3Ds%253Adashcol2%5Ehidden%3Db%253A0%5Eindex%3Ds%253A3%5Erefresh%3Dn%253A60%5Erows%3Dn%253A10',
96        "eventLog" => 'o%3Acollapsed%3Db%253A0%5Ecolumn%3Ds%253Adashcol2%5Ehidden%3Db%253A1%5Eindex%3Ds%253A4%5Erefresh%3Dn%253A60%5Erows%3Dn%253A5'
97    );
98
99}
100
101function npc_config_form () {
102        global $fields_host_edit;
103        $fields_host_edit2 = $fields_host_edit;
104        $fields_host_edit3 = array();
105        foreach ($fields_host_edit2 as $f => $a) {
106                $fields_host_edit3[$f] = $a;
107                if ($f == 'disabled') {
108                        $fields_host_edit3["npc_host_object_id"] = array(
109                                "method" => "drop_sql",
110                                "friendly_name" => "Nagios Host Mapping",
111                                "description" => "Select the Nagios host that maps to this host.",
112                                "value" => "|arg1:npc_host_object_id|",
113                                "none_value" => "None",
114                                "default" => "0",
115                                "sql" => "SELECT npc_hosts.host_object_id as id, concat(npc_instances.instance_name, ': ', obj1.name1) AS name FROM `npc_hosts` LEFT JOIN npc_objects as obj1 ON npc_hosts.host_object_id=obj1.object_id LEFT JOIN npc_instances ON npc_hosts.instance_id=npc_instances.instance_id WHERE npc_hosts.config_type='1'",
116                                "form_id" => false
117                        );
118                }
119        }
120        $fields_host_edit = $fields_host_edit3;
121}
122
123function npc_api_device_save ($save) {
124        if (isset($_POST['npc_host_object_id'])) {
125                $save["npc_host_object_id"] = form_input_validate($_POST['npc_host_object_id'], "npc_host_object_id", "", true, 3);
126        } else {
127                $save['npc_host_object_id'] = form_input_validate('', "npc_host_object_id", "", true, 3);
128    }
129
130        return $save;
131}
132
133function npc_draw_navigation_text ($nav) {
134   $nav["npc.php:"] = array("title" => "NPC", "mapping" => "index.php:", "url" => "npc.php", "level" => "1");
135   $nav["statusDetail.php:"] = array("title" => "Status Detail", "mapping" => "npc.php:", "url" => "statusDetail.php", "level" => "3");
136   $nav["extinfo.php:"] = array("title" => "Service / Host Information", "mapping" => "statusDetail.php:", "url" => "extinfo.php", "level" => "4");
137   $nav["command.php:"] = array("title" => "Command Execution", "mapping" => "extinfo.php:", "url" => "command.php", "level" => "5");
138   return $nav;
139}
140
141function npc_setup_table () {
142    global $config, $database_default, $npc_default_settings;
143
144    include_once($config["library_path"] . "/database.php");
145
146    // Set the new version
147    $new = npc_version();
148    $new = $new['version'];
149    db_execute("REPLACE INTO settings (name, value) VALUES ('plugin_npc_version', '$new')");
150
151    $found = false;
152    $result = mysql_query("SHOW COLUMNS FROM host FROM " . $database_default) or die (mysql_error());
153    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
154        if ($row['Field'] == 'npc_host_object_id') {
155            $found = true;
156        }
157    }
158
159    if (!$found) {
160        $sql = "ALTER TABLE host ADD npc_host_object_id int(11) default NULL COMMENT 'Nagios host object mapping'";
161        $result = mysql_query($sql) or die (mysql_error());
162    }
163
164
165    $result = db_fetch_assoc('show tables');
166
167    $tables = array();
168    $sql = array();
169
170    if (count($result) > 1) {
171            foreach($result as $index => $arr) {
172                    foreach ($arr as $t) {
173                            $tables[] = $t;
174                    }
175            }
176    }
177
178    if (!in_array('npc_acknowledgements', $tables)) {
179        $sql[] = "CREATE TABLE `npc_acknowledgements` (
180                    `acknowledgement_id` int(11) NOT NULL auto_increment,
181                    `instance_id` smallint(6) NOT NULL default '0',
182                    `entry_time` datetime NOT NULL default '0000-00-00 00:00:00',
183                    `entry_time_usec` int(11) NOT NULL default '0',
184                    `acknowledgement_type` smallint(6) NOT NULL default '0',
185                    `object_id` int(11) NOT NULL default '0',
186                    `state` smallint(6) NOT NULL default '0',
187                    `author_name` varchar(64) NOT NULL default '',
188                    `comment_data` varchar(255) NOT NULL default '',
189                    `is_sticky` smallint(6) NOT NULL default '0',
190                    `persistent_comment` smallint(6) NOT NULL default '0',
191                    `notify_contacts` smallint(6) NOT NULL default '0',
192                    PRIMARY KEY  (`acknowledgement_id`)
193                 )  ENGINE=InnoDB COMMENT='Current and historical host and service acknowledgements';";
194
195        // Add some default values
196        $sql[] = "INSERT INTO settings VALUES ('npc_date_format','Y-m-d');";
197        $sql[] = "INSERT INTO settings VALUES ('npc_time_format','H:i');";
198        $sql[] = "INSERT INTO settings VALUES ('npc_eventlog_portlet','on');";
199        $sql[] = "INSERT INTO settings VALUES ('npc_host_summary_portlet','on');";
200        $sql[] = "INSERT INTO settings VALUES ('npc_portlet_refresh',60);";
201        $sql[] = "INSERT INTO settings VALUES ('npc_portlet_rows',10);";
202
203    }
204
205    if (!in_array('npc_commands', $tables)) {
206        $sql[] = "CREATE TABLE `npc_commands` (
207                    `command_id` int(11) NOT NULL auto_increment,
208                    `instance_id` smallint(6) NOT NULL default '0',
209                    `config_type` smallint(6) NOT NULL default '0',
210                    `object_id` int(11) NOT NULL default '0',
211                    `command_line` varchar(255) NOT NULL default '',
212                    PRIMARY KEY  (`command_id`),
213                    UNIQUE KEY `instance_id` (`instance_id`,`object_id`,`config_type`)
214                  ) ENGINE=InnoDB COMMENT='Command definitions';";
215    }
216
217    if (!in_array('npc_commenthistory', $tables)) {
218        $sql[] = "CREATE TABLE `npc_commenthistory` (
219                    `commenthistory_id` int(11) NOT NULL auto_increment,
220                    `instance_id` smallint(6) NOT NULL default '0',
221                    `entry_time` datetime NOT NULL default '0000-00-00 00:00:00',
222                    `entry_time_usec` int(11) NOT NULL default '0',
223                    `comment_type` smallint(6) NOT NULL default '0',
224                    `entry_type` smallint(6) NOT NULL default '0',
225                    `object_id` int(11) NOT NULL default '0',
226                    `comment_time` datetime NOT NULL default '0000-00-00 00:00:00',
227                    `internal_comment_id` int(11) NOT NULL default '0',
228                    `author_name` varchar(64) NOT NULL default '',
229                    `comment_data` varchar(255) NOT NULL default '',
230                    `is_persistent` smallint(6) NOT NULL default '0',
231                    `comment_source` smallint(6) NOT NULL default '0',
232                    `expires` smallint(6) NOT NULL default '0',
233                    `expiration_time` datetime NOT NULL default '0000-00-00 00:00:00',
234                    `deletion_time` datetime NOT NULL default '0000-00-00 00:00:00',
235                    `deletion_time_usec` int(11) NOT NULL default '0',
236                    PRIMARY KEY  (`commenthistory_id`),
237                    UNIQUE KEY `instance_id` (`instance_id`,`comment_time`,`internal_comment_id`)
238                  ) ENGINE=InnoDB COMMENT='Historical host and service comments';";
239    }
240
241    if (!in_array('npc_comments', $tables)) {
242        $sql[] = "CREATE TABLE `npc_comments` (
243                    `comment_id` int(11) NOT NULL auto_increment,
244                    `instance_id` smallint(6) NOT NULL default '0',
245                    `entry_time` datetime NOT NULL default '0000-00-00 00:00:00',
246                    `entry_time_usec` int(11) NOT NULL default '0',
247                    `comment_type` smallint(6) NOT NULL default '0',
248                    `entry_type` smallint(6) NOT NULL default '0',
249                    `object_id` int(11) NOT NULL default '0',
250                    `comment_time` datetime NOT NULL default '0000-00-00 00:00:00',
251                    `internal_comment_id` int(11) NOT NULL default '0',
252                    `author_name` varchar(64) NOT NULL default '',
253                    `comment_data` varchar(255) NOT NULL default '',
254                    `is_persistent` smallint(6) NOT NULL default '0',
255                    `comment_source` smallint(6) NOT NULL default '0',
256                    `expires` smallint(6) NOT NULL default '0',
257                    `expiration_time` datetime NOT NULL default '0000-00-00 00:00:00',
258                    PRIMARY KEY  (`comment_id`),
259                    UNIQUE KEY `instance_id` (`instance_id`,`comment_time`,`internal_comment_id`)
260                  ) ENGINE=InnoDB;";
261    }
262
263    if (!in_array('npc_configfiles', $tables)) {
264        $sql[] = "CREATE TABLE `npc_configfiles` (
265                    `configfile_id` int(11) NOT NULL auto_increment,
266                    `instance_id` smallint(6) NOT NULL default '0',
267                    `configfile_type` smallint(6) NOT NULL default '0',
268                    `configfile_path` varchar(255) NOT NULL default '',
269                    PRIMARY KEY  (`configfile_id`),
270                    UNIQUE KEY `instance_id` (`instance_id`,`configfile_type`,`configfile_path`)
271                  ) ENGINE=InnoDB COMMENT='Configuration files';";
272    }
273
274    if (!in_array('npc_configfilevariables', $tables)) {
275        $sql[] = "CREATE TABLE `npc_configfilevariables` (
276                    `configfilevariable_id` int(11) NOT NULL auto_increment,
277                    `instance_id` smallint(6) NOT NULL default '0',
278                    `configfile_id` int(11) NOT NULL default '0',
279                    `varname` varchar(64) NOT NULL default '',
280                    `varvalue` varchar(255) NOT NULL default '',
281                    PRIMARY KEY  (`configfilevariable_id`),
282                    UNIQUE KEY `instance_id` (`instance_id`,`configfile_id`,`varname`)
283                  ) ENGINE=InnoDB COMMENT='Configuration file variables';";
284    }
285
286    if (!in_array('npc_conninfo', $tables)) {
287        $sql[] = "CREATE TABLE `npc_conninfo` (
288                    `conninfo_id` int(11) NOT NULL auto_increment,
289                    `instance_id` smallint(6) NOT NULL default '0',
290                    `agent_name` varchar(32) NOT NULL default '',
291                    `agent_version` varchar(8) NOT NULL default '',
292                    `disposition` varchar(16) NOT NULL default '',
293                    `connect_source` varchar(16) NOT NULL default '',
294                    `connect_type` varchar(16) NOT NULL default '',
295                    `connect_time` datetime NOT NULL default '0000-00-00 00:00:00',
296                    `disconnect_time` datetime NOT NULL default '0000-00-00 00:00:00',
297                    `last_checkin_time` datetime NOT NULL default '0000-00-00 00:00:00',
298                    `data_start_time` datetime NOT NULL default '0000-00-00 00:00:00',
299                    `data_end_time` datetime NOT NULL default '0000-00-00 00:00:00',
300                    `bytes_processed` int(11) NOT NULL default '0',
301                    `lines_processed` int(11) NOT NULL default '0',
302                    `entries_processed` int(11) NOT NULL default '0',
303                    PRIMARY KEY  (`conninfo_id`)
304                  ) ENGINE=InnoDB COMMENT='NDO2DB daemon connection information';";
305    }
306
307    if (!in_array('npc_contact_addresses', $tables)) {
308        $sql[] = "CREATE TABLE `npc_contact_addresses` (
309                    `contact_address_id` int(11) NOT NULL auto_increment,
310                    `instance_id` smallint(6) NOT NULL default '0',
311                    `contact_id` int(11) NOT NULL default '0',
312                    `address_number` smallint(6) NOT NULL default '0',
313                    `address` varchar(255) NOT NULL default '',
314                    PRIMARY KEY  (`contact_address_id`),
315                    UNIQUE KEY `contact_id` (`contact_id`,`address_number`)
316                  ) ENGINE=InnoDB COMMENT='Contact addresses';";
317    }
318
319    if (!in_array('npc_contact_notificationcommands', $tables)) {
320        $sql[] = "CREATE TABLE `npc_contact_notificationcommands` (
321                    `contact_notificationcommand_id` int(11) NOT NULL auto_increment,
322                    `instance_id` smallint(6) NOT NULL default '0',
323                    `contact_id` int(11) NOT NULL default '0',
324                    `notification_type` smallint(6) NOT NULL default '0',
325                    `command_object_id` int(11) NOT NULL default '0',
326                    `command_args` varchar(255) NOT NULL default '',
327                    PRIMARY KEY  (`contact_notificationcommand_id`),
328                    UNIQUE KEY `contact_id` (`contact_id`,`notification_type`,`command_object_id`,`command_args`)
329                  ) ENGINE=InnoDB COMMENT='Contact host and service notification commands';";
330    }
331
332    if (!in_array('npc_contactgroup_members', $tables)) {
333        $sql[] = "CREATE TABLE `npc_contactgroup_members` (
334                    `contactgroup_member_id` int(11) NOT NULL auto_increment,
335                    `instance_id` smallint(6) NOT NULL default '0',
336                    `contactgroup_id` int(11) NOT NULL default '0',
337                    `contact_object_id` int(11) NOT NULL default '0',
338                    PRIMARY KEY  (`contactgroup_member_id`),
339                    UNIQUE KEY `instance_id` (`contactgroup_id`,`contact_object_id`)
340                  ) ENGINE=InnoDB COMMENT='Contactgroup members';";
341    }
342
343    if (!in_array('npc_contactgroups', $tables)) {
344        $sql[] = "CREATE TABLE `npc_contactgroups` (
345                    `contactgroup_id` int(11) NOT NULL auto_increment,
346                    `instance_id` smallint(6) NOT NULL default '0',
347                    `config_type` smallint(6) NOT NULL default '0',
348                    `contactgroup_object_id` int(11) NOT NULL default '0',
349                    `alias` varchar(255) NOT NULL default '',
350                    PRIMARY KEY  (`contactgroup_id`),
351                    UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`contactgroup_object_id`)
352                  ) ENGINE=InnoDB COMMENT='Contactgroup definitions';";
353    }
354
355    if (!in_array('npc_contactnotificationmethods', $tables)) {
356        $sql[] = "CREATE TABLE `npc_contactnotificationmethods` (
357                    `contactnotificationmethod_id` int(11) NOT NULL auto_increment,
358                    `instance_id` smallint(6) NOT NULL default '0',
359                    `contactnotification_id` int(11) NOT NULL default '0',
360                    `start_time` datetime NOT NULL default '0000-00-00 00:00:00',
361                    `start_time_usec` int(11) NOT NULL default '0',
362                    `end_time` datetime NOT NULL default '0000-00-00 00:00:00',
363                    `end_time_usec` int(11) NOT NULL default '0',
364                    `command_object_id` int(11) NOT NULL default '0',
365                    `command_args` varchar(255) NOT NULL default '',
366                    PRIMARY KEY  (`contactnotificationmethod_id`),
367                    UNIQUE KEY `instance_id` (`instance_id`,`contactnotification_id`,`start_time`,`start_time_usec`)
368                  ) ENGINE=InnoDB COMMENT='Historical record of contact notification methods';";
369    }
370
371    if (!in_array('npc_contactnotifications', $tables)) {
372        $sql[] = "CREATE TABLE `npc_contactnotifications` (
373                    `contactnotification_id` int(11) NOT NULL auto_increment,
374                    `instance_id` smallint(6) NOT NULL default '0',
375                    `notification_id` int(11) NOT NULL default '0',
376                    `contact_object_id` int(11) NOT NULL default '0',
377                    `start_time` datetime NOT NULL default '0000-00-00 00:00:00',
378                    `start_time_usec` int(11) NOT NULL default '0',
379                    `end_time` datetime NOT NULL default '0000-00-00 00:00:00',
380                    `end_time_usec` int(11) NOT NULL default '0',
381                    PRIMARY KEY  (`contactnotification_id`),
382                    UNIQUE KEY `instance_id` (`instance_id`,`contact_object_id`,`start_time`,`start_time_usec`)
383                  ) ENGINE=InnoDB COMMENT='Historical record of contact notifications';";
384    }
385
386    if (!in_array('npc_contacts', $tables)) {
387        $sql[] = "CREATE TABLE `npc_contacts` (
388                    `contact_id` int(11) NOT NULL auto_increment,
389                    `instance_id` smallint(6) NOT NULL default '0',
390                    `config_type` smallint(6) NOT NULL default '0',
391                    `contact_object_id` int(11) NOT NULL default '0',
392                    `alias` varchar(64) NOT NULL default '',
393                    `email_address` varchar(255) NOT NULL default '',
394                    `pager_address` varchar(64) NOT NULL default '',
395                    `host_timeperiod_object_id` int(11) NOT NULL default '0',
396                    `service_timeperiod_object_id` int(11) NOT NULL default '0',
397                    `host_notifications_enabled` smallint(6) NOT NULL default '0',
398                    `service_notifications_enabled` smallint(6) NOT NULL default '0',
399                    `can_submit_commands` smallint(6) NOT NULL default '0',
400                    `notify_service_recovery` smallint(6) NOT NULL default '0',
401                    `notify_service_warning` smallint(6) NOT NULL default '0',
402                    `notify_service_unknown` smallint(6) NOT NULL default '0',
403                    `notify_service_critical` smallint(6) NOT NULL default '0',
404                    `notify_service_flapping` smallint(6) NOT NULL default '0',
405                    `notify_service_downtime` smallint(6) NOT NULL default '0',
406                    `notify_host_recovery` smallint(6) NOT NULL default '0',
407                    `notify_host_down` smallint(6) NOT NULL default '0',
408                    `notify_host_unreachable` smallint(6) NOT NULL default '0',
409                    `notify_host_flapping` smallint(6) NOT NULL default '0',
410                    `notify_host_downtime` smallint(6) NOT NULL default '0',
411                    PRIMARY KEY  (`contact_id`),
412                    UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`contact_object_id`)
413                  ) ENGINE=InnoDB COMMENT='Contact definitions';";
414    }
415
416    if (!in_array('npc_contactstatus', $tables)) {
417        $sql[] = "CREATE TABLE `npc_contactstatus` (
418                    `contactstatus_id` int(11) NOT NULL auto_increment,
419                    `instance_id` smallint(6) NOT NULL default '0',
420                    `contact_object_id` int(11) NOT NULL default '0',
421                    `status_update_time` datetime NOT NULL default '0000-00-00 00:00:00',
422                    `host_notifications_enabled` smallint(6) NOT NULL default '0',
423                    `service_notifications_enabled` smallint(6) NOT NULL default '0',
424                    `last_host_notification` datetime NOT NULL default '0000-00-00 00:00:00',
425                    `last_service_notification` datetime NOT NULL default '0000-00-00 00:00:00',
426                    `modified_attributes` int(11) NOT NULL default '0',
427                    `modified_host_attributes` int(11) NOT NULL default '0',
428                    `modified_service_attributes` int(11) NOT NULL default '0',
429                    PRIMARY KEY  (`contactstatus_id`),
430                    UNIQUE KEY `contact_object_id` (`contact_object_id`)
431                  ) ENGINE=InnoDB COMMENT='Contact status';";
432    }
433
434    if (!in_array('npc_customvariables', $tables)) {
435        $sql[] = "CREATE TABLE `npc_customvariables` (
436                    `customvariable_id` int(11) NOT NULL auto_increment,
437                    `instance_id` smallint(6) NOT NULL default '0',
438                    `object_id` int(11) NOT NULL default '0',
439                    `config_type` smallint(6) NOT NULL default '0',
440                    `has_been_modified` smallint(6) NOT NULL default '0',
441                    `varname` varchar(255) NOT NULL default '',
442                    `varvalue` varchar(255) NOT NULL default '',
443                    PRIMARY KEY  (`customvariable_id`),
444                    UNIQUE KEY `object_id_2` (`object_id`,`config_type`,`varname`),
445                    KEY `varname` (`varname`)
446                  ) ENGINE=InnoDB COMMENT='Custom variables';";
447    }
448
449    if (!in_array('npc_customvariablestatus', $tables)) {
450        $sql[] = "CREATE TABLE `npc_customvariablestatus` (
451                    `customvariablestatus_id` int(11) NOT NULL auto_increment,
452                    `instance_id` smallint(6) NOT NULL default '0',
453                    `object_id` int(11) NOT NULL default '0',
454                    `status_update_time` datetime NOT NULL default '0000-00-00 00:00:00',
455                    `has_been_modified` smallint(6) NOT NULL default '0',
456                    `varname` varchar(255) NOT NULL default '',
457                    `varvalue` varchar(255) NOT NULL default '',
458                    PRIMARY KEY  (`customvariablestatus_id`),
459                    UNIQUE KEY `object_id_2` (`object_id`,`varname`),
460                    KEY `varname` (`varname`)
461                  ) ENGINE=InnoDB COMMENT='Custom variable status information';";
462    }
463
464    if (!in_array('npc_dbversion', $tables)) {
465        $sql[] = "CREATE TABLE `npc_dbversion` (
466                    `name` varchar(10) NOT NULL default '',
467                    `version` varchar(10) NOT NULL default ''
468                  ) ENGINE=InnoDB;";
469    }
470
471    if (!in_array('npc_downtimehistory', $tables)) {
472        $sql[] = "CREATE TABLE `npc_downtimehistory` (
473                    `downtimehistory_id` int(11) NOT NULL auto_increment,
474                    `instance_id` smallint(6) NOT NULL default '0',
475                    `downtime_type` smallint(6) NOT NULL default '0',
476                    `object_id` int(11) NOT NULL default '0',
477                    `entry_time` datetime NOT NULL default '0000-00-00 00:00:00',
478                    `author_name` varchar(64) NOT NULL default '',
479                    `comment_data` varchar(255) NOT NULL default '',
480                    `internal_downtime_id` int(11) NOT NULL default '0',
481                    `triggered_by_id` int(11) NOT NULL default '0',
482                    `is_fixed` smallint(6) NOT NULL default '0',
483                    `duration` smallint(6) NOT NULL default '0',
484                    `scheduled_start_time` datetime NOT NULL default '0000-00-00 00:00:00',
485                    `scheduled_end_time` datetime NOT NULL default '0000-00-00 00:00:00',
486                    `was_started` smallint(6) NOT NULL default '0',
487                    `actual_start_time` datetime NOT NULL default '0000-00-00 00:00:00',
488                    `actual_start_time_usec` int(11) NOT NULL default '0',
489                    `actual_end_time` datetime NOT NULL default '0000-00-00 00:00:00',
490                    `actual_end_time_usec` int(11) NOT NULL default '0',
491                    `was_cancelled` smallint(6) NOT NULL default '0',
492                    PRIMARY KEY  (`downtimehistory_id`),
493                    UNIQUE KEY `instance_id` (`instance_id`,`object_id`,`entry_time`,`internal_downtime_id`)
494                  ) ENGINE=InnoDB COMMENT='Historical scheduled host and service downtime';";
495    }
496
497    if (!in_array('npc_eventhandlers', $tables)) {
498        $sql[] = "CREATE TABLE `npc_eventhandlers` (
499                    `eventhandler_id` int(11) NOT NULL auto_increment,
500                    `instance_id` smallint(6) NOT NULL default '0',
501                    `eventhandler_type` smallint(6) NOT NULL default '0',
502                    `object_id` int(11) NOT NULL default '0',
503                    `state` smallint(6) NOT NULL default '0',
504                    `state_type` smallint(6) NOT NULL default '0',
505                    `start_time` datetime NOT NULL default '0000-00-00 00:00:00',
506                    `start_time_usec` int(11) NOT NULL default '0',
507                    `end_time` datetime NOT NULL default '0000-00-00 00:00:00',
508                    `end_time_usec` int(11) NOT NULL default '0',
509                    `command_object_id` int(11) NOT NULL default '0',
510                    `command_args` varchar(255) NOT NULL default '',
511                    `command_line` varchar(255) NOT NULL default '',
512                    `timeout` smallint(6) NOT NULL default '0',
513                    `early_timeout` smallint(6) NOT NULL default '0',
514                    `execution_time` double NOT NULL default '0',
515                    `return_code` smallint(6) NOT NULL default '0',
516                    `output` varchar(255) NOT NULL default '',
517                    PRIMARY KEY  (`eventhandler_id`),
518                    UNIQUE KEY `instance_id` (`instance_id`,`object_id`,`start_time`,`start_time_usec`)
519                  ) ENGINE=InnoDB COMMENT='Historical host and service event handlers';";
520    }
521
522    if (!in_array('npc_externalcommands', $tables)) {
523        $sql[] = "CREATE TABLE `npc_externalcommands` (
524                    `externalcommand_id` int(11) NOT NULL auto_increment,
525                    `instance_id` smallint(6) NOT NULL default '0',
526                    `entry_time` datetime NOT NULL default '0000-00-00 00:00:00',
527                    `command_type` smallint(6) NOT NULL default '0',
528                    `command_name` varchar(128) NOT NULL default '',
529                    `command_args` varchar(255) NOT NULL default '',
530                    PRIMARY KEY  (`externalcommand_id`)
531                  ) ENGINE=InnoDB COMMENT='Historical record of processed external commands';";
532    }
533
534    if (!in_array('npc_flappinghistory', $tables)) {
535        $sql[] = "CREATE TABLE `npc_flappinghistory` (
536                    `flappinghistory_id` int(11) NOT NULL auto_increment,
537                    `instance_id` smallint(6) NOT NULL default '0',
538                    `event_time` datetime NOT NULL default '0000-00-00 00:00:00',
539                    `event_time_usec` int(11) NOT NULL default '0',
540                    `event_type` smallint(6) NOT NULL default '0',
541                    `reason_type` smallint(6) NOT NULL default '0',
542                    `flapping_type` smallint(6) NOT NULL default '0',
543                    `object_id` int(11) NOT NULL default '0',
544                    `percent_state_change` double NOT NULL default '0',
545                    `low_threshold` double NOT NULL default '0',
546                    `high_threshold` double NOT NULL default '0',
547                    `comment_time` datetime NOT NULL default '0000-00-00 00:00:00',
548                    `internal_comment_id` int(11) NOT NULL default '0',
549                    PRIMARY KEY  (`flappinghistory_id`)
550                  ) ENGINE=InnoDB COMMENT='Current and historical record of host and service flapping';";
551    }
552
553    if (!in_array('npc_host_contactgroups', $tables)) {
554        $sql[] = "CREATE TABLE `npc_host_contactgroups` (
555                    `host_contactgroup_id` int(11) NOT NULL auto_increment,
556                    `instance_id` smallint(6) NOT NULL default '0',
557                    `host_id` int(11) NOT NULL default '0',
558                    `contactgroup_object_id` int(11) NOT NULL default '0',
559                    PRIMARY KEY  (`host_contactgroup_id`),
560                    UNIQUE KEY `instance_id` (`host_id`,`contactgroup_object_id`)
561                  ) ENGINE=InnoDB COMMENT='Host contact groups';";
562    }
563
564    if (!in_array('npc_host_contacts', $tables)) {
565        $sql[] = "CREATE TABLE `npc_host_contacts` (
566                    `host_contact_id` int(11) NOT NULL auto_increment,
567                    `instance_id` smallint(6) NOT NULL default '0',
568                    `host_id` int(11) NOT NULL default '0',
569                    `contact_object_id` int(11) NOT NULL default '0',
570                    PRIMARY KEY  (`host_contact_id`),
571                    UNIQUE KEY `instance_id` (`instance_id`,`host_id`,`contact_object_id`)
572                  ) ENGINE=InnoDB;";
573    }
574
575    if (!in_array('npc_host_parenthosts', $tables)) {
576        $sql[] = "CREATE TABLE `npc_host_parenthosts` (
577                    `host_parenthost_id` int(11) NOT NULL auto_increment,
578                    `instance_id` smallint(6) NOT NULL default '0',
579                    `host_id` int(11) NOT NULL default '0',
580                    `parent_host_object_id` int(11) NOT NULL default '0',
581                    PRIMARY KEY  (`host_parenthost_id`),
582                    UNIQUE KEY `instance_id` (`host_id`,`parent_host_object_id`)
583                  ) ENGINE=InnoDB COMMENT='Parent hosts';";
584    }
585
586    if (!in_array('npc_hostchecks', $tables)) {
587        $sql[] = "CREATE TABLE `npc_hostchecks` (
588                    `hostcheck_id` int(11) NOT NULL auto_increment,
589                    `instance_id` smallint(6) NOT NULL default '0',
590                    `host_object_id` int(11) NOT NULL default '0',
591                    `check_type` smallint(6) NOT NULL default '0',
592                    `is_raw_check` smallint(6) NOT NULL default '0',
593                    `current_check_attempt` smallint(6) NOT NULL default '0',
594                    `max_check_attempts` smallint(6) NOT NULL default '0',
595                    `state` smallint(6) NOT NULL default '0',
596                    `state_type` smallint(6) NOT NULL default '0',
597                    `start_time` datetime NOT NULL default '0000-00-00 00:00:00',
598                    `start_time_usec` int(11) NOT NULL default '0',
599                    `end_time` datetime NOT NULL default '0000-00-00 00:00:00',
600                    `end_time_usec` int(11) NOT NULL default '0',
601                    `command_object_id` int(11) NOT NULL default '0',
602                    `command_args` varchar(255) NOT NULL default '',
603                    `command_line` varchar(255) NOT NULL default '',
604                    `timeout` smallint(6) NOT NULL default '0',
605                    `early_timeout` smallint(6) NOT NULL default '0',
606                    `execution_time` double NOT NULL default '0',
607                    `latency` double NOT NULL default '0',
608                    `return_code` smallint(6) NOT NULL default '0',
609                    `output` varchar(255) NOT NULL default '',
610                    `perfdata` varchar(255) NOT NULL default '',
611                    PRIMARY KEY  (`hostcheck_id`),
612                    UNIQUE KEY `instance_id` (`instance_id`,`host_object_id`,`start_time`,`start_time_usec`)
613                  ) ENGINE=InnoDB COMMENT='Historical host checks';";
614    }
615
616    if (!in_array('npc_hostdependencies', $tables)) {
617        $sql[] = "CREATE TABLE `npc_hostdependencies` (
618                    `hostdependency_id` int(11) NOT NULL auto_increment,
619                    `instance_id` smallint(6) NOT NULL default '0',
620                    `config_type` smallint(6) NOT NULL default '0',
621                    `host_object_id` int(11) NOT NULL default '0',
622                    `dependent_host_object_id` int(11) NOT NULL default '0',
623                    `dependency_type` smallint(6) NOT NULL default '0',
624                    `inherits_parent` smallint(6) NOT NULL default '0',
625                    `timeperiod_object_id` int(11) NOT NULL default '0',
626                    `fail_on_up` smallint(6) NOT NULL default '0',
627                    `fail_on_down` smallint(6) NOT NULL default '0',
628                    `fail_on_unreachable` smallint(6) NOT NULL default '0',
629                    PRIMARY KEY  (`hostdependency_id`),
630                    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`)
631                  ) ENGINE=InnoDB COMMENT='Host dependency definitions';";
632    }
633
634    if (!in_array('npc_hostescalation_contactgroups', $tables)) {
635        $sql[] = "CREATE TABLE `npc_hostescalation_contactgroups` (
636                    `hostescalation_contactgroup_id` int(11) NOT NULL auto_increment,
637                    `instance_id` smallint(6) NOT NULL default '0',
638                    `hostescalation_id` int(11) NOT NULL default '0',
639                    `contactgroup_object_id` int(11) NOT NULL default '0',
640                    PRIMARY KEY  (`hostescalation_contactgroup_id`),
641                    UNIQUE KEY `instance_id` (`hostescalation_id`,`contactgroup_object_id`)
642                  ) ENGINE=InnoDB COMMENT='Host escalation contact groups';";
643    }
644
645    if (!in_array('npc_hostescalation_contacts', $tables)) {
646        $sql[] = "CREATE TABLE `npc_hostescalation_contacts` (
647                    `hostescalation_contact_id` int(11) NOT NULL auto_increment,
648                    `instance_id` smallint(6) NOT NULL default '0',
649                    `hostescalation_id` int(11) NOT NULL default '0',
650                    `contact_object_id` int(11) NOT NULL default '0',
651                    PRIMARY KEY  (`hostescalation_contact_id`),
652                    UNIQUE KEY `instance_id` (`instance_id`,`hostescalation_id`,`contact_object_id`)
653                  ) ENGINE=InnoDB;";
654    }
655
656    if (!in_array('npc_hostescalations', $tables)) {
657        $sql[] = "CREATE TABLE `npc_hostescalations` (
658                    `hostescalation_id` int(11) NOT NULL auto_increment,
659                    `instance_id` smallint(6) NOT NULL default '0',
660                    `config_type` smallint(6) NOT NULL default '0',
661                    `host_object_id` int(11) NOT NULL default '0',
662                    `timeperiod_object_id` int(11) NOT NULL default '0',
663                    `first_notification` smallint(6) NOT NULL default '0',
664                    `last_notification` smallint(6) NOT NULL default '0',
665                    `notification_interval` double NOT NULL default '0',
666                    `escalate_on_recovery` smallint(6) NOT NULL default '0',
667                    `escalate_on_down` smallint(6) NOT NULL default '0',
668                    `escalate_on_unreachable` smallint(6) NOT NULL default '0',
669                    PRIMARY KEY  (`hostescalation_id`),
670                    UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`host_object_id`,`timeperiod_object_id`,`first_notification`,`last_notification`)
671                  ) ENGINE=InnoDB COMMENT='Host escalation definitions';";
672    }
673
674    if (!in_array('npc_hostgroup_members', $tables)) {
675        $sql[] = "CREATE TABLE `npc_hostgroup_members` (
676                    `hostgroup_member_id` int(11) NOT NULL auto_increment,
677                    `instance_id` smallint(6) NOT NULL default '0',
678                    `hostgroup_id` int(11) NOT NULL default '0',
679                    `host_object_id` int(11) NOT NULL default '0',
680                    PRIMARY KEY  (`hostgroup_member_id`),
681                    UNIQUE KEY `instance_id` (`hostgroup_id`,`host_object_id`)
682                  ) ENGINE=InnoDB COMMENT='Hostgroup members';";
683    }
684
685    if (!in_array('npc_hostgroups', $tables)) {
686        $sql[] = "CREATE TABLE `npc_hostgroups` (
687                    `hostgroup_id` int(11) NOT NULL auto_increment,
688                    `instance_id` smallint(6) NOT NULL default '0',
689                    `config_type` smallint(6) NOT NULL default '0',
690                    `hostgroup_object_id` int(11) NOT NULL default '0',
691                    `alias` varchar(255) NOT NULL default '',
692                    PRIMARY KEY  (`hostgroup_id`),
693                    UNIQUE KEY `instance_id` (`instance_id`,`hostgroup_object_id`)
694                  ) ENGINE=InnoDB COMMENT='Hostgroup definitions';";
695    }
696
697    if (!in_array('npc_hosts', $tables)) {
698        $sql[] = "CREATE TABLE `npc_hosts` (
699                    `host_id` int(11) NOT NULL auto_increment,
700                    `instance_id` smallint(6) NOT NULL default '0',
701                    `config_type` smallint(6) NOT NULL default '0',
702                    `host_object_id` int(11) NOT NULL default '0',
703                    `alias` varchar(64) NOT NULL default '',
704                    `display_name` varchar(64) NOT NULL default '',
705                    `address` varchar(128) NOT NULL default '',
706                    `check_command_object_id` int(11) NOT NULL default '0',
707                    `check_command_args` varchar(255) NOT NULL default '',
708                    `eventhandler_command_object_id` int(11) NOT NULL default '0',
709                    `eventhandler_command_args` varchar(255) NOT NULL default '',
710                    `notification_timeperiod_object_id` int(11) NOT NULL default '0',
711                    `check_timeperiod_object_id` int(11) NOT NULL default '0',
712                    `failure_prediction_options` varchar(64) NOT NULL default '',
713                    `check_interval` double NOT NULL default '0',
714                    `retry_interval` double NOT NULL default '0',
715                    `max_check_attempts` smallint(6) NOT NULL default '0',
716                    `first_notification_delay` double NOT NULL default '0',
717                    `notification_interval` double NOT NULL default '0',
718                    `notify_on_down` smallint(6) NOT NULL default '0',
719                    `notify_on_unreachable` smallint(6) NOT NULL default '0',
720                    `notify_on_recovery` smallint(6) NOT NULL default '0',
721                    `notify_on_flapping` smallint(6) NOT NULL default '0',
722                    `notify_on_downtime` smallint(6) NOT NULL default '0',
723                    `stalk_on_up` smallint(6) NOT NULL default '0',
724                    `stalk_on_down` smallint(6) NOT NULL default '0',
725                    `stalk_on_unreachable` smallint(6) NOT NULL default '0',
726                    `flap_detection_enabled` smallint(6) NOT NULL default '0',
727                    `flap_detection_on_up` smallint(6) NOT NULL default '0',
728                    `flap_detection_on_down` smallint(6) NOT NULL default '0',
729                    `flap_detection_on_unreachable` smallint(6) NOT NULL default '0',
730                    `low_flap_threshold` double NOT NULL default '0',
731                    `high_flap_threshold` double NOT NULL default '0',
732                    `process_performance_data` smallint(6) NOT NULL default '0',
733                    `freshness_checks_enabled` smallint(6) NOT NULL default '0',
734                    `freshness_threshold` smallint(6) NOT NULL default '0',
735                    `passive_checks_enabled` smallint(6) NOT NULL default '0',
736                    `event_handler_enabled` smallint(6) NOT NULL default '0',
737                    `active_checks_enabled` smallint(6) NOT NULL default '0',
738                    `retain_status_information` smallint(6) NOT NULL default '0',
739                    `retain_nonstatus_information` smallint(6) NOT NULL default '0',
740                    `notifications_enabled` smallint(6) NOT NULL default '0',
741                    `obsess_over_host` smallint(6) NOT NULL default '0',
742                    `failure_prediction_enabled` smallint(6) NOT NULL default '0',
743                    `notes` varchar(255) NOT NULL default '',
744                    `notes_url` varchar(255) NOT NULL default '',
745                    `action_url` varchar(255) NOT NULL default '',
746                    `icon_image` varchar(255) NOT NULL default '',
747                    `icon_image_alt` varchar(255) NOT NULL default '',
748                    `vrml_image` varchar(255) NOT NULL default '',
749                    `statusmap_image` varchar(255) NOT NULL default '',
750                    `have_2d_coords` smallint(6) NOT NULL default '0',
751                    `x_2d` smallint(6) NOT NULL default '0',
752                    `y_2d` smallint(6) NOT NULL default '0',
753                    `have_3d_coords` smallint(6) NOT NULL default '0',
754                    `x_3d` double NOT NULL default '0',
755                    `y_3d` double NOT NULL default '0',
756                    `z_3d` double NOT NULL default '0',
757                    PRIMARY KEY  (`host_id`),
758                    UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`host_object_id`)
759                  ) ENGINE=InnoDB COMMENT='Host definitions';";
760    }
761
762    if (!in_array('npc_hoststatus', $tables)) {
763        $sql[] = "CREATE TABLE `npc_hoststatus` (
764                    `hoststatus_id` int(11) NOT NULL auto_increment,
765                    `instance_id` smallint(6) NOT NULL default '0',
766                    `host_object_id` int(11) NOT NULL default '0',
767                    `status_update_time` datetime NOT NULL default '0000-00-00 00:00:00',
768                    `output` varchar(255) NOT NULL default '',
769                    `perfdata` varchar(255) NOT NULL default '',
770                    `current_state` smallint(6) NOT NULL default '0',
771                    `has_been_checked` smallint(6) NOT NULL default '0',
772                    `should_be_scheduled` smallint(6) NOT NULL default '0',
773                    `current_check_attempt` smallint(6) NOT NULL default '0',
774                    `max_check_attempts` smallint(6) NOT NULL default '0',
775                    `last_check` datetime NOT NULL default '0000-00-00 00:00:00',
776                    `next_check` datetime NOT NULL default '0000-00-00 00:00:00',
777                    `check_type` smallint(6) NOT NULL default '0',
778                    `last_state_change` datetime NOT NULL default '0000-00-00 00:00:00',
779                    `last_hard_state_change` datetime NOT NULL default '0000-00-00 00:00:00',
780                    `last_hard_state` smallint(6) NOT NULL default '0',
781                    `last_time_up` datetime NOT NULL default '0000-00-00 00:00:00',
782                    `last_time_down` datetime NOT NULL default '0000-00-00 00:00:00',
783                    `last_time_unreachable` datetime NOT NULL default '0000-00-00 00:00:00',
784                    `state_type` smallint(6) NOT NULL default '0',
785                    `last_notification` datetime NOT NULL default '0000-00-00 00:00:00',
786                    `next_notification` datetime NOT NULL default '0000-00-00 00:00:00',
787                    `no_more_notifications` smallint(6) NOT NULL default '0',
788                    `notifications_enabled` smallint(6) NOT NULL default '0',
789                    `problem_has_been_acknowledged` smallint(6) NOT NULL default '0',
790                    `acknowledgement_type` smallint(6) NOT NULL default '0',
791                    `current_notification_number` smallint(6) NOT NULL default '0',
792                    `passive_checks_enabled` smallint(6) NOT NULL default '0',
793                    `active_checks_enabled` smallint(6) NOT NULL default '0',
794                    `event_handler_enabled` smallint(6) NOT NULL default '0',
795                    `flap_detection_enabled` smallint(6) NOT NULL default '0',
796                    `is_flapping` smallint(6) NOT NULL default '0',
797                    `percent_state_change` double NOT NULL default '0',
798                    `latency` double NOT NULL default '0',
799                    `execution_time` double NOT NULL default '0',
800                    `scheduled_downtime_depth` smallint(6) NOT NULL default '0',
801                    `failure_prediction_enabled` smallint(6) NOT NULL default '0',
802                    `process_performance_data` smallint(6) NOT NULL default '0',
803                    `obsess_over_host` smallint(6) NOT NULL default '0',
804                    `modified_host_attributes` int(11) NOT NULL default '0',
805                    `event_handler` varchar(255) NOT NULL default '',
806                    `check_command` varchar(255) NOT NULL default '',
807                    `normal_check_interval` double NOT NULL default '0',
808                    `retry_check_interval` double NOT NULL default '0',
809                    `check_timeperiod_object_id` int(11) NOT NULL default '0',
810                    PRIMARY KEY  (`hoststatus_id`),
811                    UNIQUE KEY `object_id` (`host_object_id`)
812                  ) ENGINE=InnoDB COMMENT='Current host status information';";
813    }
814
815    if (!in_array('npc_instances', $tables)) {
816        $sql[] = "CREATE TABLE `npc_instances` (
817                    `instance_id` smallint(6) NOT NULL auto_increment,
818                    `instance_name` varchar(64) NOT NULL default '',
819                    `instance_description` varchar(128) NOT NULL default '',
820                    PRIMARY KEY  (`instance_id`)
821                  ) ENGINE=InnoDB COMMENT='Location names of various Nagios installations';";
822    }
823
824    if (!in_array('npc_logentries', $tables)) {
825        $sql[] = "CREATE TABLE `npc_logentries` (
826                    `logentry_id` int(11) NOT NULL auto_increment,
827                    `instance_id` int(11) NOT NULL default '0',
828                    `logentry_time` datetime NOT NULL default '0000-00-00 00:00:00',
829                    `entry_time` datetime NOT NULL default '0000-00-00 00:00:00',
830                    `entry_time_usec` int(11) NOT NULL default '0',
831                    `logentry_type` int(11) NOT NULL default '0',
832                    `logentry_data` varchar(255) NOT NULL default '',
833                    `realtime_data` smallint(6) NOT NULL default '0',
834                    `inferred_data_extracted` smallint(6) NOT NULL default '0',
835                    PRIMARY KEY  (`logentry_id`)
836                  ) ENGINE=InnoDB COMMENT='Historical record of log entries';";
837    }
838
839    if (!in_array('npc_notifications', $tables)) {
840        $sql[] = "CREATE TABLE `npc_notifications` (
841                    `notification_id` int(11) NOT NULL auto_increment,
842                    `instance_id` smallint(6) NOT NULL default '0',
843                    `notification_type` smallint(6) NOT NULL default '0',
844                    `notification_reason` smallint(6) NOT NULL default '0',
845                    `object_id` int(11) NOT NULL default '0',
846                    `start_time` datetime NOT NULL default '0000-00-00 00:00:00',
847                    `start_time_usec` int(11) NOT NULL default '0',
848                    `end_time` datetime NOT NULL default '0000-00-00 00:00:00',
849                    `end_time_usec` int(11) NOT NULL default '0',
850                    `state` smallint(6) NOT NULL default '0',
851                    `output` varchar(255) NOT NULL default '',
852                    `escalated` smallint(6) NOT NULL default '0',
853                    `contacts_notified` smallint(6) NOT NULL default '0',
854                    PRIMARY KEY  (`notification_id`),
855                    UNIQUE KEY `instance_id` (`instance_id`,`object_id`,`start_time`,`start_time_usec`)
856                  ) ENGINE=InnoDB COMMENT='Historical record of host and service notifications';";
857    }
858
859    if (!in_array('npc_objects', $tables)) {
860        $sql[] = "CREATE TABLE `npc_objects` (
861                    `object_id` int(11) NOT NULL auto_increment,
862                    `instance_id` smallint(6) NOT NULL default '0',
863                    `objecttype_id` smallint(6) NOT NULL default '0',
864                    `name1` varchar(128) NOT NULL default '',
865                    `name2` varchar(128) default NULL,
866                    `is_active` smallint(6) NOT NULL default '0',
867                    PRIMARY KEY  (`object_id`),
868                    KEY `objecttype_id` (`objecttype_id`,`name1`,`name2`)
869                  ) ENGINE=InnoDB COMMENT='Current and historical objects of all kinds';";
870    }
871
872    if (!in_array('npc_processevents', $tables)) {
873        $sql[] = "CREATE TABLE `npc_processevents` (
874                    `processevent_id` int(11) NOT NULL auto_increment,
875                    `instance_id` smallint(6) NOT NULL default '0',
876                    `event_type` smallint(6) NOT NULL default '0',
877                    `event_time` datetime NOT NULL default '0000-00-00 00:00:00',
878                    `event_time_usec` int(11) NOT NULL default '0',
879                    `process_id` int(11) NOT NULL default '0',
880                    `program_name` varchar(16) NOT NULL default '',
881                    `program_version` varchar(20) NOT NULL default '',
882                    `program_date` varchar(10) NOT NULL default '',
883                    PRIMARY KEY  (`processevent_id`)
884                  ) ENGINE=InnoDB COMMENT='Historical Nagios process events';";
885    }
886
887    if (!in_array('npc_programstatus', $tables)) {
888        $sql[] = "CREATE TABLE `npc_programstatus` (
889                    `programstatus_id` int(11) NOT NULL auto_increment,
890                    `instance_id` smallint(6) NOT NULL default '0',
891                    `status_update_time` datetime NOT NULL default '0000-00-00 00:00:00',
892                    `program_start_time` datetime NOT NULL default '0000-00-00 00:00:00',
893                    `program_end_time` datetime NOT NULL default '0000-00-00 00:00:00',
894                    `is_currently_running` smallint(6) NOT NULL default '0',
895                    `process_id` int(11) NOT NULL default '0',
896                    `daemon_mode` smallint(6) NOT NULL default '0',
897                    `last_command_check` datetime NOT NULL default '0000-00-00 00:00:00',
898                    `last_log_rotation` datetime NOT NULL default '0000-00-00 00:00:00',
899                    `notifications_enabled` smallint(6) NOT NULL default '0',
900                    `active_service_checks_enabled` smallint(6) NOT NULL default '0',
901                    `passive_service_checks_enabled` smallint(6) NOT NULL default '0',
902                    `active_host_checks_enabled` smallint(6) NOT NULL default '0',
903                    `passive_host_checks_enabled` smallint(6) NOT NULL default '0',
904                    `event_handlers_enabled` smallint(6) NOT NULL default '0',
905                    `flap_detection_enabled` smallint(6) NOT NULL default '0',
906                    `failure_prediction_enabled` smallint(6) NOT NULL default '0',
907                    `process_performance_data` smallint(6) NOT NULL default '0',
908                    `obsess_over_hosts` smallint(6) NOT NULL default '0',
909                    `obsess_over_services` smallint(6) NOT NULL default '0',
910                    `modified_host_attributes` int(11) NOT NULL default '0',
911                    `modified_service_attributes` int(11) NOT NULL default '0',
912                    `global_host_event_handler` varchar(255) NOT NULL default '',
913                    `global_service_event_handler` varchar(255) NOT NULL default '',
914                    PRIMARY KEY  (`programstatus_id`),
915                    UNIQUE KEY `instance_id` (`instance_id`)
916                  ) ENGINE=InnoDB COMMENT='Current program status information';";
917    }
918
919    if (!in_array('npc_runtimevariables', $tables)) {
920        $sql[] = "CREATE TABLE `npc_runtimevariables` (
921                    `runtimevariable_id` int(11) NOT NULL auto_increment,
922                    `instance_id` smallint(6) NOT NULL default '0',
923                    `varname` varchar(64) NOT NULL default '',
924                    `varvalue` varchar(255) NOT NULL default '',
925                    PRIMARY KEY  (`runtimevariable_id`),
926                    UNIQUE KEY `instance_id` (`instance_id`,`varname`)
927                  ) ENGINE=InnoDB COMMENT='Runtime variables from the Nagios daemon';";
928    }
929
930    if (!in_array('npc_scheduleddowntime', $tables)) {
931        $sql[] = "CREATE TABLE `npc_scheduleddowntime` (
932                    `scheduleddowntime_id` int(11) NOT NULL auto_increment,
933                    `instance_id` smallint(6) NOT NULL default '0',
934                    `downtime_type` smallint(6) NOT NULL default '0',
935                    `object_id` int(11) NOT NULL default '0',
936                    `entry_time` datetime NOT NULL default '0000-00-00 00:00:00',
937                    `author_name` varchar(64) NOT NULL default '',
938                    `comment_data` varchar(255) NOT NULL default '',
939                    `internal_downtime_id` int(11) NOT NULL default '0',
940                    `triggered_by_id` int(11) NOT NULL default '0',
941                    `is_fixed` smallint(6) NOT NULL default '0',
942                    `duration` smallint(6) NOT NULL default '0',
943                    `scheduled_start_time` datetime NOT NULL default '0000-00-00 00:00:00',
944                    `scheduled_end_time` datetime NOT NULL default '0000-00-00 00:00:00',
945                    `was_started` smallint(6) NOT NULL default '0',
946                    `actual_start_time` datetime NOT NULL default '0000-00-00 00:00:00',
947                    `actual_start_time_usec` int(11) NOT NULL default '0',
948                    PRIMARY KEY  (`scheduleddowntime_id`),
949                    UNIQUE KEY `instance_id` (`instance_id`,`object_id`,`entry_time`,`internal_downtime_id`)
950                  ) ENGINE=InnoDB COMMENT='Current scheduled host and service downtime';";
951    }
952
953    if (!in_array('npc_service_contactgroups', $tables)) {
954        $sql[] = "CREATE TABLE `npc_service_contactgroups` (
955                    `service_contactgroup_id` int(11) NOT NULL auto_increment,
956                    `instance_id` smallint(6) NOT NULL default '0',
957                    `service_id` int(11) NOT NULL default '0',
958                    `contactgroup_object_id` int(11) NOT NULL default '0',
959                    PRIMARY KEY  (`service_contactgroup_id`),
960                    UNIQUE KEY `instance_id` (`service_id`,`contactgroup_object_id`)
961                  ) ENGINE=InnoDB COMMENT='Service contact groups';";
962    }
963
964    if (!in_array('npc_service_contacts', $tables)) {
965        $sql[] = "CREATE TABLE `npc_service_contacts` (
966                    `service_contact_id` int(11) NOT NULL auto_increment,
967                    `instance_id` smallint(6) NOT NULL default '0',
968                    `service_id` int(11) NOT NULL default '0',
969                    `contact_object_id` int(11) NOT NULL default '0',
970                    PRIMARY KEY  (`service_contact_id`),
971                    UNIQUE KEY `instance_id` (`instance_id`,`service_id`,`contact_object_id`)
972                  ) ENGINE=InnoDB;";
973    }
974
975    if (!in_array('npc_servicechecks', $tables)) {
976        $sql[] = "CREATE TABLE `npc_servicechecks` (
977                    `servicecheck_id` int(11) NOT NULL auto_increment,
978                    `instance_id` smallint(6) NOT NULL default '0',
979                    `service_object_id` int(11) NOT NULL default '0',
980                    `check_type` smallint(6) NOT NULL default '0',
981                    `current_check_attempt` smallint(6) NOT NULL default '0',
982                    `max_check_attempts` smallint(6) NOT NULL default '0',
983                    `state` smallint(6) NOT NULL default '0',
984                    `state_type` smallint(6) NOT NULL default '0',
985                    `start_time` datetime NOT NULL default '0000-00-00 00:00:00',
986                    `start_time_usec` int(11) NOT NULL default '0',
987                    `end_time` datetime NOT NULL default '0000-00-00 00:00:00',
988                    `end_time_usec` int(11) NOT NULL default '0',
989                    `command_object_id` int(11) NOT NULL default '0',
990                    `command_args` varchar(255) NOT NULL default '',
991                    `command_line` varchar(255) NOT NULL default '',
992                    `timeout` smallint(6) NOT NULL default '0',
993                    `early_timeout` smallint(6) NOT NULL default '0',
994                    `execution_time` double NOT NULL default '0',
995                    `latency` double NOT NULL default '0',
996                    `return_code` smallint(6) NOT NULL default '0',
997                    `output` varchar(255) NOT NULL default '',
998                    `perfdata` varchar(255) NOT NULL default '',
999                    PRIMARY KEY  (`servicecheck_id`),
1000                    UNIQUE KEY `instance_id` (`instance_id`,`service_object_id`,`start_time`,`start_time_usec`)
1001                  ) ENGINE=InnoDB COMMENT='Historical service checks';";
1002    }
1003
1004    if (!in_array('npc_servicedependencies', $tables)) {
1005        $sql[] = "CREATE TABLE `npc_servicedependencies` (
1006                    `servicedependency_id` int(11) NOT NULL auto_increment,
1007                    `instance_id` smallint(6) NOT NULL default '0',
1008                    `config_type` smallint(6) NOT NULL default '0',
1009                    `service_object_id` int(11) NOT NULL default '0',
1010                    `dependent_service_object_id` int(11) NOT NULL default '0',
1011                    `dependency_type` smallint(6) NOT NULL default '0',
1012                    `inherits_parent` smallint(6) NOT NULL default '0',
1013                    `timeperiod_object_id` int(11) NOT NULL default '0',
1014                    `fail_on_ok` smallint(6) NOT NULL default '0',
1015                    `fail_on_warning` smallint(6) NOT NULL default '0',
1016                    `fail_on_unknown` smallint(6) NOT NULL default '0',
1017                    `fail_on_critical` smallint(6) NOT NULL default '0',
1018                    PRIMARY KEY  (`servicedependency_id`),
1019                    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`)
1020                  ) ENGINE=InnoDB COMMENT='Service dependency definitions';";
1021    }
1022
1023    if (!in_array('npc_serviceescalation_contactgroups', $tables)) {
1024        $sql[] = "CREATE TABLE `npc_serviceescalation_contactgroups` (
1025                    `serviceescalation_contactgroup_id` int(11) NOT NULL auto_increment,
1026                    `instance_id` smallint(6) NOT NULL default '0',
1027                    `serviceescalation_id` int(11) NOT NULL default '0',
1028                    `contactgroup_object_id` int(11) NOT NULL default '0',
1029                    PRIMARY KEY  (`serviceescalation_contactgroup_id`),
1030                    UNIQUE KEY `instance_id` (`serviceescalation_id`,`contactgroup_object_id`)
1031                  ) ENGINE=InnoDB COMMENT='Service escalation contact groups';";
1032    }
1033
1034    if (!in_array('npc_serviceescalation_contacts', $tables)) {
1035        $sql[] = "CREATE TABLE `npc_serviceescalation_contacts` (
1036                    `serviceescalation_contact_id` int(11) NOT NULL auto_increment,
1037                    `instance_id` smallint(6) NOT NULL default '0',
1038                    `serviceescalation_id` int(11) NOT NULL default '0',
1039                    `contact_object_id` int(11) NOT NULL default '0',
1040                    PRIMARY KEY  (`serviceescalation_contact_id`),
1041                    UNIQUE KEY `instance_id` (`instance_id`,`serviceescalation_id`,`contact_object_id`)
1042                  ) ENGINE=InnoDB;";
1043    }
1044
1045    if (!in_array('npc_serviceescalations', $tables)) {
1046        $sql[] = "CREATE TABLE `npc_serviceescalations` (
1047                    `serviceescalation_id` int(11) NOT NULL auto_increment,
1048                    `instance_id` smallint(6) NOT NULL default '0',
1049                    `config_type` smallint(6) NOT NULL default '0',
1050                    `service_object_id` int(11) NOT NULL default '0',
1051                    `timeperiod_object_id` int(11) NOT NULL default '0',
1052                    `first_notification` smallint(6) NOT NULL default '0',
1053                    `last_notification` smallint(6) NOT NULL default '0',
1054                    `notification_interval` double NOT NULL default '0',
1055                    `escalate_on_recovery` smallint(6) NOT NULL default '0',
1056                    `escalate_on_warning` smallint(6) NOT NULL default '0',
1057                    `escalate_on_unknown` smallint(6) NOT NULL default '0',
1058                    `escalate_on_critical` smallint(6) NOT NULL default '0',
1059                    PRIMARY KEY  (`serviceescalation_id`),
1060                    UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`service_object_id`,`timeperiod_object_id`,`first_notification`,`last_notification`)
1061                  ) ENGINE=InnoDB COMMENT='Service escalation definitions';";
1062    }
1063
1064    if (!in_array('npc_servicegroup_members', $tables)) {
1065        $sql[] = "CREATE TABLE `npc_servicegroup_members` (
1066                    `servicegroup_member_id` int(11) NOT NULL auto_increment,
1067                    `instance_id` smallint(6) NOT NULL default '0',
1068                    `servicegroup_id` int(11) NOT NULL default '0',
1069                    `service_object_id` int(11) NOT NULL default '0',
1070                    PRIMARY KEY  (`servicegroup_member_id`),
1071                    UNIQUE KEY `instance_id` (`servicegroup_id`,`service_object_id`)
1072                  ) ENGINE=InnoDB COMMENT='Servicegroup members';";
1073    }
1074
1075    if (!in_array('npc_servicegroups', $tables)) {
1076        $sql[] = "CREATE TABLE `npc_servicegroups` (
1077                    `servicegroup_id` int(11) NOT NULL auto_increment,
1078                    `instance_id` smallint(6) NOT NULL default '0',
1079                    `config_type` smallint(6) NOT NULL default '0',
1080                    `servicegroup_object_id` int(11) NOT NULL default '0',
1081                    `alias` varchar(255) NOT NULL default '',
1082                    PRIMARY KEY  (`servicegroup_id`),
1083                    UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`servicegroup_object_id`)
1084                  ) ENGINE=InnoDB COMMENT='Servicegroup definitions';";
1085    }
1086
1087    if (!in_array('npc_services', $tables)) {
1088        $sql[] = "CREATE TABLE `npc_services` (
1089                    `service_id` int(11) NOT NULL auto_increment,
1090                    `instance_id` smallint(6) NOT NULL default '0',
1091                    `config_type` smallint(6) NOT NULL default '0',
1092                    `host_object_id` int(11) NOT NULL default '0',
1093                    `service_object_id` int(11) NOT NULL default '0',
1094                    `display_name` varchar(64) NOT NULL default '',
1095                    `check_command_object_id` int(11) NOT NULL default '0',
1096                    `check_command_args` varchar(255) NOT NULL default '',
1097                    `eventhandler_command_object_id` int(11) NOT NULL default '0',
1098                    `eventhandler_command_args` varchar(255) NOT NULL default '',
1099                    `notification_timeperiod_object_id` int(11) NOT NULL default '0',
1100                    `check_timeperiod_object_id` int(11) NOT NULL default '0',
1101                    `failure_prediction_options` varchar(64) NOT NULL default '',
1102                    `check_interval` double NOT NULL default '0',
1103                    `retry_interval` double NOT NULL default '0',
1104                    `max_check_attempts` smallint(6) NOT NULL default '0',
1105                    `first_notification_delay` double NOT NULL default '0',
1106                    `notification_interval` double NOT NULL default '0',
1107                    `notify_on_warning` smallint(6) NOT NULL default '0',
1108                    `notify_on_unknown` smallint(6) NOT NULL default '0',
1109                    `notify_on_critical` smallint(6) NOT NULL default '0',
1110                    `notify_on_recovery` smallint(6) NOT NULL default '0',
1111                    `notify_on_flapping` smallint(6) NOT NULL default '0',
1112                    `notify_on_downtime` smallint(6) NOT NULL default '0',
1113                    `stalk_on_ok` smallint(6) NOT NULL default '0',
1114                    `stalk_on_warning` smallint(6) NOT NULL default '0',
1115                    `stalk_on_unknown` smallint(6) NOT NULL default '0',
1116                    `stalk_on_critical` smallint(6) NOT NULL default '0',
1117                    `is_volatile` smallint(6) NOT NULL default '0',
1118                    `flap_detection_enabled` smallint(6) NOT NULL default '0',
1119                    `flap_detection_on_ok` smallint(6) NOT NULL default '0',
1120                    `flap_detection_on_warning` smallint(6) NOT NULL default '0',
1121                    `flap_detection_on_unknown` smallint(6) NOT NULL default '0',
1122                    `flap_detection_on_critical` smallint(6) NOT NULL default '0',
1123                    `low_flap_threshold` double NOT NULL default '0',
1124                    `high_flap_threshold` double NOT NULL default '0',
1125                    `process_performance_data` smallint(6) NOT NULL default '0',
1126                    `freshness_checks_enabled` smallint(6) NOT NULL default '0',
1127                    `freshness_threshold` smallint(6) NOT NULL default '0',
1128                    `passive_checks_enabled` smallint(6) NOT NULL default '0',
1129                    `event_handler_enabled` smallint(6) NOT NULL default '0',
1130                    `active_checks_enabled` smallint(6) NOT NULL default '0',
1131                    `retain_status_information` smallint(6) NOT NULL default '0',
1132                    `retain_nonstatus_information` smallint(6) NOT NULL default '0',
1133                    `notifications_enabled` smallint(6) NOT NULL default '0',
1134                    `obsess_over_service` smallint(6) NOT NULL default '0',
1135                    `failure_prediction_enabled` smallint(6) NOT NULL default '0',
1136                    `notes` varchar(255) NOT NULL default '',
1137                    `notes_url` varchar(255) NOT NULL default '',
1138                    `action_url` varchar(255) NOT NULL default '',
1139                    `icon_image` varchar(255) NOT NULL default '',
1140                    `icon_image_alt` varchar(255) NOT NULL default '',
1141                    PRIMARY KEY  (`service_id`),
1142                    UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`service_object_id`)
1143                  ) ENGINE=InnoDB COMMENT='Service definitions';";
1144    }
1145
1146    if (!in_array('npc_servicestatus', $tables)) {
1147        $sql[] = "CREATE TABLE `npc_servicestatus` (
1148                    `servicestatus_id` int(11) NOT NULL auto_increment,
1149                    `instance_id` smallint(6) NOT NULL default '0',
1150                    `service_object_id` int(11) NOT NULL default '0',
1151                    `status_update_time` datetime NOT NULL default '0000-00-00 00:00:00',
1152                    `output` varchar(255) NOT NULL default '',
1153                    `perfdata` varchar(255) NOT NULL default '',
1154                    `current_state` smallint(6) NOT NULL default '0',
1155                    `has_been_checked` smallint(6) NOT NULL default '0',
1156                    `should_be_scheduled` smallint(6) NOT NULL default '0',
1157                    `current_check_attempt` smallint(6) NOT NULL default '0',
1158                    `max_check_attempts` smallint(6) NOT NULL default '0',
1159                    `last_check` datetime NOT NULL default '0000-00-00 00:00:00',
1160                    `next_check` datetime NOT NULL default '0000-00-00 00:00:00',
1161                    `check_type` smallint(6) NOT NULL default '0',
1162                    `last_state_change` datetime NOT NULL default '0000-00-00 00:00:00',
1163                    `last_hard_state_change` datetime NOT NULL default '0000-00-00 00:00:00',
1164                    `last_hard_state` smallint(6) NOT NULL default '0',
1165                    `last_time_ok` datetime NOT NULL default '0000-00-00 00:00:00',
1166                    `last_time_warning` datetime NOT NULL default '0000-00-00 00:00:00',
1167                    `last_time_unknown` datetime NOT NULL default '0000-00-00 00:00:00',
1168                    `last_time_critical` datetime NOT NULL default '0000-00-00 00:00:00',
1169                    `state_type` smallint(6) NOT NULL default '0',
1170                    `last_notification` datetime NOT NULL default '0000-00-00 00:00:00',
1171                    `next_notification` datetime NOT NULL default '0000-00-00 00:00:00',
1172                    `no_more_notifications` smallint(6) NOT NULL default '0',
1173                    `notifications_enabled` smallint(6) NOT NULL default '0',
1174                    `problem_has_been_acknowledged` smallint(6) NOT NULL default '0',
1175                    `acknowledgement_type` smallint(6) NOT NULL default '0',
1176                    `current_notification_number` smallint(6) NOT NULL default '0',
1177                    `passive_checks_enabled` smallint(6) NOT NULL default '0',
1178                    `active_checks_enabled` smallint(6) NOT NULL default '0',
1179                    `event_handler_enabled` smallint(6) NOT NULL default '0',
1180                    `flap_detection_enabled` smallint(6) NOT NULL default '0',
1181                    `is_flapping` smallint(6) NOT NULL default '0',
1182                    `percent_state_change` double NOT NULL default '0',
1183                    `latency` double NOT NULL default '0',
1184                    `execution_time` double NOT NULL default '0',
1185                    `scheduled_downtime_depth` smallint(6) NOT NULL default '0',
1186                    `failure_prediction_enabled` smallint(6) NOT NULL default '0',
1187                    `process_performance_data` smallint(6) NOT NULL default '0',
1188                    `obsess_over_service` smallint(6) NOT NULL default '0',
1189                    `modified_service_attributes` int(11) NOT NULL default '0',
1190                    `event_handler` varchar(255) NOT NULL default '',
1191                    `check_command` varchar(255) NOT NULL default '',
1192                    `normal_check_interval` double NOT NULL default '0',
1193                    `retry_check_interval` double NOT NULL default '0',
1194                    `check_timeperiod_object_id` int(11) NOT NULL default '0',
1195                    PRIMARY KEY  (`servicestatus_id`),
1196                    UNIQUE KEY `object_id` (`service_object_id`)
1197                  ) ENGINE=InnoDB COMMENT='Current service status information';";
1198    }
1199
1200    if (!in_array('npc_statehistory', $tables)) {
1201        $sql[] = "CREATE TABLE `npc_statehistory` (
1202                    `statehistory_id` int(11) NOT NULL auto_increment,
1203                    `instance_id` smallint(6) NOT NULL default '0',
1204                    `state_time` datetime NOT NULL default '0000-00-00 00:00:00',
1205                    `state_time_usec` int(11) NOT NULL default '0',
1206                    `object_id` int(11) NOT NULL default '0',
1207                    `state_change` smallint(6) NOT NULL default '0',
1208                    `state` smallint(6) NOT NULL default '0',
1209                    `state_type` smallint(6) NOT NULL default '0',
1210                    `current_check_attempt` smallint(6) NOT NULL default '0',
1211                    `max_check_attempts` smallint(6) NOT NULL default '0',
1212                    `last_state` smallint(6) NOT NULL default '-1',
1213                    `last_hard_state` smallint(6) NOT NULL default '-1',
1214                    `output` varchar(255) NOT NULL default '',
1215                    PRIMARY KEY  (`statehistory_id`)
1216                  ) ENGINE=InnoDB COMMENT='Historical host and service state changes';";
1217    }
1218
1219    if (!in_array('npc_systemcommands', $tables)) {
1220        $sql[] = "CREATE TABLE `npc_systemcommands` (
1221                    `systemcommand_id` int(11) NOT NULL auto_increment,
1222                    `instance_id` smallint(6) NOT NULL default '0',
1223                    `start_time` datetime NOT NULL default '0000-00-00 00:00:00',
1224                    `start_time_usec` int(11) NOT NULL default '0',
1225                    `end_time` datetime NOT NULL default '0000-00-00 00:00:00',
1226                    `end_time_usec` int(11) NOT NULL default '0',
1227                    `command_line` varchar(255) NOT NULL default '',
1228                    `timeout` smallint(6) NOT NULL default '0',
1229                    `early_timeout` smallint(6) NOT NULL default '0',
1230                    `execution_time` double NOT NULL default '0',
1231                    `return_code` smallint(6) NOT NULL default '0',
1232                    `output` varchar(255) NOT NULL default '',
1233                    PRIMARY KEY  (`systemcommand_id`),
1234                    UNIQUE KEY `instance_id` (`instance_id`,`start_time`,`start_time_usec`)
1235                  ) ENGINE=InnoDB COMMENT='Historical system commands that are executed';";
1236    }
1237
1238    if (!in_array('npc_timedeventqueue', $tables)) {
1239        $sql[] = "CREATE TABLE `npc_timedeventqueue` (
1240                    `timedeventqueue_id` int(11) NOT NULL auto_increment,
1241                    `instance_id` smallint(6) NOT NULL default '0',
1242                    `event_type` smallint(6) NOT NULL default '0',
1243                    `queued_time` datetime NOT NULL default '0000-00-00 00:00:00',
1244                    `queued_time_usec` int(11) NOT NULL default '0',
1245                    `scheduled_time` datetime NOT NULL default '0000-00-00 00:00:00',
1246                    `recurring_event` smallint(6) NOT NULL default '0',
1247                    `object_id` int(11) NOT NULL default '0',
1248                    PRIMARY KEY  (`timedeventqueue_id`)
1249                  ) ENGINE=InnoDB COMMENT='Current Nagios event queue';";
1250    }
1251
1252    if (!in_array('npc_timedevents', $tables)) {
1253        $sql[] = "CREATE TABLE `npc_timedevents` (
1254                    `timedevent_id` int(11) NOT NULL auto_increment,
1255                    `instance_id` smallint(6) NOT NULL default '0',
1256                    `event_type` smallint(6) NOT NULL default '0',
1257                    `queued_time` datetime NOT NULL default '0000-00-00 00:00:00',
1258                    `queued_time_usec` int(11) NOT NULL default '0',
1259                    `event_time` datetime NOT NULL default '0000-00-00 00:00:00',
1260                    `event_time_usec` int(11) NOT NULL default '0',
1261                    `scheduled_time` datetime NOT NULL default '0000-00-00 00:00:00',
1262                    `recurring_event` smallint(6) NOT NULL default '0',
1263                    `object_id` int(11) NOT NULL default '0',
1264                    `deletion_time` datetime NOT NULL default '0000-00-00 00:00:00',
1265                    `deletion_time_usec` int(11) NOT NULL default '0',
1266                    PRIMARY KEY  (`timedevent_id`),
1267                    UNIQUE KEY `instance_id` (`instance_id`,`event_type`,`scheduled_time`,`object_id`)
1268                  ) ENGINE=InnoDB COMMENT='Historical events from the Nagios event queue';";
1269    }
1270
1271    if (!in_array('npc_timeperiod_timeranges', $tables)) {
1272        $sql[] = "CREATE TABLE `npc_timeperiod_timeranges` (
1273                    `timeperiod_timerange_id` int(11) NOT NULL auto_increment,
1274                    `instance_id` smallint(6) NOT NULL default '0',
1275                    `timeperiod_id` int(11) NOT NULL default '0',
1276                    `day` smallint(6) NOT NULL default '0',
1277                    `start_sec` int(11) NOT NULL default '0',
1278                    `end_sec` int(11) NOT NULL default '0',
1279                    PRIMARY KEY  (`timeperiod_timerange_id`),
1280                    UNIQUE KEY `instance_id` (`timeperiod_id`,`day`,`start_sec`,`end_sec`)
1281                  ) ENGINE=InnoDB COMMENT='Timeperiod definitions';";
1282    }
1283
1284    if (!in_array('npc_timeperiods', $tables)) {
1285        $sql[] = "CREATE TABLE `npc_timeperiods` (
1286                    `timeperiod_id` int(11) NOT NULL auto_increment,
1287                    `instance_id` smallint(6) NOT NULL default '0',
1288                    `config_type` smallint(6) NOT NULL default '0',
1289                    `timeperiod_object_id` int(11) NOT NULL default '0',
1290                    `alias` varchar(255) NOT NULL default '',
1291                    PRIMARY KEY  (`timeperiod_id`),
1292                    UNIQUE KEY `instance_id` (`instance_id`,`config_type`,`timeperiod_object_id`)
1293                  ) ENGINE=InnoDB COMMENT='Timeperiod definitions';";
1294    }
1295
1296    if (!in_array('npc_settings', $tables)) {
1297        $sql[] = "CREATE TABLE `npc_settings` (
1298                    `user_id` mediumint(8) unsigned NOT NULL,
1299                    `settings` text default null,
1300                    PRIMARY KEY  (`user_id`)
1301                  ) ENGINE=InnoDB COMMENT='NPC user settings';";
1302    } else {
1303
1304        $cUser = db_fetch_assoc('SELECT id FROM user_auth');
1305        $nUser = db_fetch_assoc('SELECT user_id FROM npc_settings');
1306
1307        // Add exitsting users to npc_settings
1308        for ($i = 0; $i < count($cUser); $i++) {
1309            if (!db_fetch_cell('SELECT user_id FROM npc_settings WHERE user_id = ' . $cUser[$i]['id'])) {
1310                db_execute("INSERT INTO npc_settings VALUES(". $cUser[$i]['id'].",'".serialize($npc_default_settings)."')");
1311            }
1312        }
1313
1314        // Delete non existent users from npc_settings
1315        for ($i = 0; $i < count($nUser); $i++) {
1316            if (isset($nUser[$i]['id']) && !db_fetch_cell('SELECT id FROM user_auth WHERE id = ' . $nUser[$i]['id'])) {
1317                db_execute('DELETE FROM npc_settings WHERE user_id = ' . $nUser[$i]['id']);
1318            }
1319        }
1320    }
1321
1322    if (!empty($sql)) {
1323        for ($a = 0; $a < count($sql); $a++) {
1324             $result = db_execute($sql[$a]);
1325        }
1326   }
1327}
1328
1329function npc_show_tab() {
1330        global $config;
1331        if (api_user_realm_auth('npc.php')) {
1332            $cp = false;
1333            if (basename($_SERVER["PHP_SELF"]) == "npc.php")
1334                $cp = true;
1335
1336            print '<a href="' . $config['url_path'] . 'plugins/npc/npc.php"><img src="' . $config['url_path'] . 'plugins/npc/images/tab_npc' . ($cp ? "_down": "") . '.gif" alt="npc" align="absmiddle" border="0"></a>';
1337        }
1338        npc_check_upgrade ();
1339}
1340
1341function npc_check_upgrade() {
1342    $current = npc_version ();
1343    $current = $current['version'];
1344    $old = read_config_option('plugin_npc_version');
1345    //if ($current != $old) {
1346        npc_setup_table ();
1347    //}
1348}
1349
1350
1351function npc_config_settings() {
1352
1353        global $tabs, $settings, $npc_date_format, $npc_time_format;
1354
1355        $tabs["npc"] = " NPC ";
1356
1357        $settings['npc'] = array(
1358                "npc_header" => array(
1359                        "friendly_name" => "General Settings",
1360                        "method" => "spacer",
1361                ),
1362                "npc_nagios_commands" => array(
1363                        "friendly_name" => "Remote Commands",
1364                        "description" => "Allow commands to be written to the Nagios command file.",
1365                        "method" => "checkbox",
1366                ),
1367                "npc_nagios_cmd_path" => array(
1368                        "friendly_name" => "Nagios Command File Path",
1369                        "description" => "The path to the Nagios command file (nagios.cmd).",
1370                        "method" => "textbox",
1371                        "max_length" => 255,
1372                ),
1373                "npc_nagios_url" => array(
1374                        "friendly_name" => "Nagios URL",
1375                        "description" => "The full URL to your Nagios installation (http://nagios.company.com/nagios/)",
1376                        "method" => "textbox",
1377                        "max_length" => 255,
1378                ),
1379                "npc_date_format" => array(
1380                    "friendly_name" => "Date Format",
1381                    "description" => "Select the format you want for displaying dates.",
1382                    "method" => "drop_array",
1383                    "default" => "Y-m-d",
1384                    "array" => $npc_date_format,
1385                ),
1386                "npc_time_format" => array(
1387                    "friendly_name" => "Time Format",
1388                    "description" => "Select the format you want for displaying times.",
1389                    "method" => "drop_array",
1390                    "default" => "H:i",
1391                    "array" => $npc_time_format,
1392                )
1393        );
1394}
1395
Note: See TracBrowser for help on using the browser.