root/trunk/setup.php @ 139

Revision 139, 88.5 KB (checked in by divagater, 5 years ago)

Updated setup.php to support PA 2.x. Added svn:keywords

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