Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
idoutils: add is_in_effect and trigger_time to scheduleddowntime and …
Browse files Browse the repository at this point in the history
…downtimehistory tables #2539 - MF

requires change on doing neb callback after
having fetched all necessary data when
starting/triggering a downtime.

all 3 rdbms get scheduleddowntime and
downtimehistory populated.

db sqls and upgrade scripts require tests!

refs #2537
refs #2539
  • Loading branch information
Michael Friedrich committed Apr 23, 2012
1 parent 5b7211d commit b7a29ac
Show file tree
Hide file tree
Showing 13 changed files with 297 additions and 135 deletions.
3 changes: 3 additions & 0 deletions Changelog
Expand Up @@ -36,6 +36,7 @@ ENHANCEMENTS
* classic ui: add is_in_effect and trigger_time to downtime view for html, csv, json #2538 - MF

* idoutils: add new index for state in table statehistory #2274 - TD
* idoutils: add is_in_effect and trigger_time to scheduleddowntime and downtimehistory tables #2539 - MF

* install: add configure option --with-temp-file=<filepath> to set temp_file for icinga.cfg #2121 - MF
* install: add --with-plugin-dir to configure for setting the plugins path accordingly #2344 - MF
Expand Down Expand Up @@ -150,6 +151,8 @@ CHANGES
* core: add trigger_time to downtimes #2537
** downtimes in status.dat/retention.dat now holding trigger_time
** nebstruct and event broker api now passing trigger_time and is_in_effect
* core: nebcallback for downtime start now happens *after* setting "in effect" attributes #2539
** needed to pass is_in_effect and trigger_time to neb modules

* classic ui: Added option for max log entries displayed in showlog.cgi #2145
** added new config option "default_num_displayed_log_entries"
Expand Down
8 changes: 4 additions & 4 deletions common/downtime.c
Expand Up @@ -494,10 +494,6 @@ int handle_scheduled_downtime(scheduled_downtime *temp_downtime) {
else
log_debug_info(DEBUGL_DOWNTIME, 0, "Service '%s' on host '%s' starting %s scheduled downtime (id=%lu) with depth=%lu, starttime=%lu, entrytime=%lu, endtime=%lu, duration=%lu.\n", svc->description, svc->host_name, (temp_downtime->fixed == TRUE) ? "fixed" : "flexible", temp_downtime->downtime_id, svc->scheduled_downtime_depth, temp_downtime->start_time, temp_downtime->entry_time, temp_downtime->end_time, temp_downtime->duration);

#ifdef USE_EVENT_BROKER
/* send data to event broker */
broker_downtime_data(NEBTYPE_DOWNTIME_START, NEBFLAG_NONE, NEBATTR_NONE, temp_downtime->type, temp_downtime->host_name, temp_downtime->service_description, temp_downtime->entry_time, temp_downtime->author, temp_downtime->comment, temp_downtime->start_time, temp_downtime->end_time, temp_downtime->fixed, temp_downtime->triggered_by, temp_downtime->duration, temp_downtime->downtime_id, NULL, temp_downtime->is_in_effect, temp_downtime->trigger_time);
#endif
/* this happens after restart of icinga */
if (temp_downtime->is_in_effect != TRUE) {
if (temp_downtime->type == HOST_DOWNTIME && hst->scheduled_downtime_depth == 0) {
Expand Down Expand Up @@ -538,6 +534,10 @@ int handle_scheduled_downtime(scheduled_downtime *temp_downtime) {
/* set the in effect flag */
temp_downtime->is_in_effect = TRUE;

#ifdef USE_EVENT_BROKER
/* send data to broker AFTER we know trigger_time, is_in_effect, and downtime_depth */
broker_downtime_data(NEBTYPE_DOWNTIME_START, NEBFLAG_NONE, NEBATTR_NONE, temp_downtime->type, temp_downtime->host_name, temp_downtime->service_description, temp_downtime->entry_time, temp_downtime->author, temp_downtime->comment, temp_downtime->start_time, temp_downtime->end_time, temp_downtime->fixed, temp_downtime->triggered_by, temp_downtime->duration, temp_downtime->downtime_id, NULL, temp_downtime->is_in_effect, temp_downtime->trigger_time);
#endif
/* update the status data */
if (temp_downtime->type == HOST_DOWNTIME)
update_host_status(hst, FALSE);
Expand Down
4 changes: 4 additions & 0 deletions module/idoutils/db/mysql/mysql.sql
Expand Up @@ -403,6 +403,8 @@ CREATE TABLE IF NOT EXISTS icinga_downtimehistory (
actual_end_time timestamp default '0000-00-00 00:00:00',
actual_end_time_usec int default 0,
was_cancelled smallint default 0,
is_in_effect smallint default 0,
trigger_time timestamp default '0000-00-00 00:00:00',
PRIMARY KEY (downtimehistory_id),
UNIQUE KEY instance_id (instance_id,object_id,entry_time,internal_downtime_id)
) ENGINE=InnoDB COMMENT='Historical scheduled host and service downtime';
Expand Down Expand Up @@ -951,6 +953,8 @@ CREATE TABLE IF NOT EXISTS icinga_scheduleddowntime (
was_started smallint default 0,
actual_start_time timestamp default '0000-00-00 00:00:00',
actual_start_time_usec int default 0,
is_in_effect smallint default 0,
trigger_time timestamp default '0000-00-00 00:00:00',
PRIMARY KEY (scheduleddowntime_id),
UNIQUE KEY instance_id (instance_id,object_id,entry_time,internal_downtime_id)
) ENGINE=InnoDB COMMENT='Current scheduled host and service downtime';
Expand Down
15 changes: 12 additions & 3 deletions module/idoutils/db/mysql/upgrade/mysql-upgrade-1.7.0.sql
Expand Up @@ -2,21 +2,30 @@
-- upgrade path for Icinga IDOUtils 1.7.0
--
-- -----------------------------------------
-- Copyright (c) 2011 Icinga Development Team (http://www.icinga.org)
-- Copyright (c) 2012 Icinga Development Team (http://www.icinga.org)
--
-- Please check http://docs.icinga.org for upgrading information!
-- -----------------------------------------

-- -----------------------------------------
--#2274
-- #2274
-- -----------------------------------------
create index statehist_state_idx on icinga_statehistory(object_id,state);

-- -----------------------------------------
--#2479
-- #2479
-- -----------------------------------------
alter table icinga_hosts modify FAILURE_PREDICTION_OPTIONS varchar(128) ;

-- -----------------------------------------
-- #2537
-- -----------------------------------------

alter table icinga_downtimehistory add is_in_effect smallint default 0;
alter table icinga_downtimehistory add trigger_time timestamp default '0000-00-00 00:00:00';
alter table icinga_scheduleddowntime add is_in_effect smallint default 0;
alter table icinga_scheduleddowntime add trigger_time timestamp default '0000-00-00 00:00:00';

-- -----------------------------------------
-- update dbversion
-- -----------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions module/idoutils/db/oracle/create_icinga_objects_oracle.sql
Expand Up @@ -671,7 +671,9 @@ CREATE TABLE downtimehistory (
actual_start_time_usec integer default 0 ,
actual_end_time TIMESTAMP(0) WITH LOCAL TIME ZONE default TO_TIMESTAMP_TZ('01.01.1970 UTC','DD.MM.YYYY TZR') ,
actual_end_time_usec integer default 0 ,
was_cancelled integer default 0
was_cancelled integer default 0,
is_in_effect integer default 0,
trigger_time TIMESTAMP(0) WITH LOCAL TIME ZONE default TO_TIMESTAMP_TZ('01.01.1970 UTC','DD.MM.YYYY TZR')
)tablespace &&DATATBS;

alter table downtimehistory add constraint downtimehistory_pk PRIMARY KEY (id)
Expand Down Expand Up @@ -1313,7 +1315,9 @@ CREATE TABLE scheduleddowntime (
scheduled_end_time TIMESTAMP(0) WITH LOCAL TIME ZONE default TO_TIMESTAMP_TZ('01.01.1970 UTC','DD.MM.YYYY TZR') ,
was_started integer default 0 ,
actual_start_time TIMESTAMP(0) WITH LOCAL TIME ZONE default TO_TIMESTAMP_TZ('01.01.1970 UTC','DD.MM.YYYY TZR') ,
actual_start_time_usec integer default 0
actual_start_time_usec integer default 0,
is_in_effect integer default 0,
trigger_time TIMESTAMP(0) WITH LOCAL TIME ZONE default TO_TIMESTAMP_TZ('01.01.1970 UTC','DD.MM.YYYY TZR')
)tablespace &&DATATBS;

alter table scheduleddowntime add constraint scheduleddowntime_pk PRIMARY KEY (id)
Expand Down
10 changes: 10 additions & 0 deletions module/idoutils/db/oracle/upgrade/oracle-upgrade-1.7.0.sql
Expand Up @@ -107,6 +107,16 @@ alter sequence SEQ_TIMEDEVENTQUEUE cache 10;
alter sequence SEQ_TIMEDEVENTS cache 10;
alter sequence SEQ_TIMEPERIODS nocache;
alter sequence SEQ_TIMEP_TIMER cache 5;

-- -----------------------------------------
-- #2537
-- -----------------------------------------

alter table downtimehistory add is_in_effect integer default 0;
alter table downtimehistory add trigger_time TIMESTAMP(0) WITH LOCAL TIME ZONE default TO_TIMESTAMP_TZ('01.01.1970 UTC','DD.MM.YYYY TZR');
alter table scheduleddowntime add is_in_effect integer default 0;
alter table scheduleddowntime add trigger_time TIMESTAMP(0) WITH LOCAL TIME ZONE default TO_TIMESTAMP_TZ('01.01.1970 UTC','DD.MM.YYYY TZR');

-- -----------------------------------------
-- finally update dbversion
-- -----------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions module/idoutils/db/pgsql/pgsql.sql
Expand Up @@ -432,6 +432,8 @@ CREATE TABLE icinga_downtimehistory (
actual_end_time timestamp with time zone default '1970-01-01 00:00:00',
actual_end_time_usec INTEGER default 0,
was_cancelled INTEGER default 0,
is_in_effect INTEGER default 0,
trigger_time timestamp with time zone default '1970-01-01 00:00:00',
CONSTRAINT PK_downtimehistory_id PRIMARY KEY (downtimehistory_id) ,
CONSTRAINT UQ_downtimehistory UNIQUE (instance_id,object_id,entry_time,internal_downtime_id)
) ;
Expand Down Expand Up @@ -980,6 +982,8 @@ CREATE TABLE icinga_scheduleddowntime (
was_started INTEGER default 0,
actual_start_time timestamp with time zone default '1970-01-01 00:00:00',
actual_start_time_usec INTEGER default 0,
is_in_effect INTEGER default 0,
trigger_time timestamp with time zone default '1970-01-01 00:00:00',
CONSTRAINT PK_scheduleddowntime_id PRIMARY KEY (scheduleddowntime_id) ,
CONSTRAINT UQ_scheduleddowntime UNIQUE (instance_id,object_id,entry_time,internal_downtime_id)
) ;
Expand Down
9 changes: 9 additions & 0 deletions module/idoutils/db/pgsql/upgrade/pgsql-upgrade-1.7.0.sql
Expand Up @@ -25,6 +25,15 @@ CREATE OR REPLACE FUNCTION unix_timestamp(timestamp with time zone) RETURNS bigi
SELECT EXTRACT(EPOCH FROM $1)::bigint AS result;
' LANGUAGE 'SQL';

-- -----------------------------------------
-- #2537
-- -----------------------------------------

alter table icinga_downtimehistory add is_in_effect INTEGER default 0;
alter table icinga_downtimehistory add trigger_time timestamp with time zone default '1970-01-01 00:00:00';
alter table icinga_scheduleddowntime add is_in_effect INTEGER default 0;
alter table icinga_scheduleddowntime add trigger_time timestamp with time zone default '1970-01-01 00:00:00';

-- -----------------------------------------
-- update dbversion
-- -----------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion module/idoutils/include/protoapi.h
Expand Up @@ -107,7 +107,7 @@

/************** COMMON DATA ATTRIBUTES **************/

#define IDO_MAX_DATA_TYPES 268
#define IDO_MAX_DATA_TYPES 270

#define IDO_DATA_NONE 0

Expand Down Expand Up @@ -388,4 +388,6 @@

#define IDO_DATA_HOSTADDRESS6 266
#define IDO_DATA_END_TIME 267 /* ACKNOWLEDGEMENT DATA */
#define IDO_DATA_DOWNTIMEISINEFFECT 268
#define IDO_DATA_DOWNTIMETRIGGERTIME 269
#endif
27 changes: 18 additions & 9 deletions module/idoutils/src/db.c
Expand Up @@ -5067,15 +5067,18 @@ int ido2db_oci_prepared_statement_downtimedata_scheduled_downtime(ido2db_idi *id
"comment_data=:X6, triggered_by_id=:X8, "
"is_fixed=:X9, duration=:X10, "
"scheduled_start_time=unixts2localts(:X11) , "
"scheduled_end_time=unixts2localts(:X12) "
"scheduled_end_time=unixts2localts(:X12), "
"is_in_effect=:X13, trigger_time=unixts2localts(:X14) "
"WHEN NOT MATCHED THEN "
"INSERT (id, instance_id, downtime_type, object_id, "
"entry_time, author_name, comment_data, "
"internal_downtime_id, triggered_by_id, "
"is_fixed, duration, scheduled_start_time, scheduled_end_time) "
"is_fixed, duration, scheduled_start_time, scheduled_end_time "
"is_in_effect, trigger_time) "
"VALUES (seq_scheduleddowntime.nextval, :X1, :X2, :X3, "
"unixts2localts(:X4), :X5, :X6, "
":X7, :X8, :X9, :X10, unixts2localts(:X11),unixts2localts(:X12))",
":X7, :X8, :X9, :X10, unixts2localts(:X11),unixts2localts(:X12), "
":X13, unixts2localts(:X14))",
ido2db_db_tablenames[IDO2DB_DBTABLE_SCHEDULEDDOWNTIME]) == -1) {
buf = NULL;
}
Expand Down Expand Up @@ -5119,15 +5122,18 @@ int ido2db_oci_prepared_statement_downtimedata_downtime_history(ido2db_idi *idi)
"UPDATE SET downtime_type=:X2, author_name=:X5, "
"comment_data=:X6, triggered_by_id=:X8, is_fixed=:X9, "
"duration=:X10, scheduled_start_time=unixts2localts(:X11), "
"scheduled_end_time=unixts2localts(:X12) "
"scheduled_end_time=unixts2localts(:X12), "
"is_in_effect=:X13, trigger_time=unixts2localts(:X14) "
"WHEN NOT MATCHED THEN "
"INSERT (id, instance_id, downtime_type, object_id, "
"entry_time, author_name, comment_data, internal_downtime_id, "
"triggered_by_id, is_fixed, duration, "
"scheduled_start_time, scheduled_end_time) "
"scheduled_start_time, scheduled_end_time, "
"is_in_effect, trigger_time)"
"VALUES (seq_downtimehistory.nextval, :X1, :X2, :X3, "
"unixts2localts(:X4), :X5, :X6, :X7, :X8, :X9, :X10, "
"unixts2localts(:X11), unixts2localts(:X12))",
"unixts2localts(:X11), unixts2localts(:X12), "
":X13, unixts2localts(:X14))",
ido2db_db_tablenames[IDO2DB_DBTABLE_DOWNTIMEHISTORY]) == -1) {
buf = NULL;
}
Expand Down Expand Up @@ -5163,7 +5169,8 @@ int ido2db_oci_prepared_statement_downtimehistory_update_start(ido2db_idi *idi)

if (asprintf(&buf,
"UPDATE %s SET actual_start_time=unixts2localts(:X1) , "
"actual_start_time_usec=:X2, was_started=:X3 "
"actual_start_time_usec=:X2, was_started=:X3, "
"is_in_effect=:X10, trigger_time=unixts2localts(:X11) "
"WHERE instance_id=:X4 "
"AND downtime_type=:X5 "
"AND object_id=:X6 "
Expand Down Expand Up @@ -5207,7 +5214,8 @@ int ido2db_oci_prepared_statement_scheduleddowntime_update_start(ido2db_idi *idi

if (asprintf(&buf,
"UPDATE %s SET actual_start_time=unixts2localts(:X1), "
"actual_start_time_usec=:X2, was_started=:X3 "
"actual_start_time_usec=:X2, was_started=:X3, "
"is_in_effect=:X10, trigger_time=unixts2localts(:X11) "
"WHERE instance_id=:X4 "
"AND downtime_type=:X5 "
"AND object_id=:X6 "
Expand Down Expand Up @@ -5253,7 +5261,8 @@ int ido2db_oci_prepared_statement_downtimehistory_update_stop(ido2db_idi *idi) {
if (asprintf(&buf,
"UPDATE %s SET "
"actual_end_time=unixts2localts(:X1) , "
"actual_end_time_usec=:X2, was_cancelled=:X3 "
"actual_end_time_usec=:X2, was_cancelled=:X3, "
"is_in_effect=:X10, trigger_time=unixts2localts(:X11) "
"WHERE instance_id=:X4 "
"AND downtime_type=:X5 "
"AND object_id=:X6 "
Expand Down

0 comments on commit b7a29ac

Please sign in to comment.