2019-02-25 14:48:22 +01:00
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2014-04-03 15:36:13 +02:00
2014-05-25 16:23:35 +02:00
# include "db_ido/dbevents.hpp"
# include "db_ido/dbtype.hpp"
# include "db_ido/dbvalue.hpp"
# include "base/convert.hpp"
# include "base/objectlock.hpp"
# include "base/initialize.hpp"
2015-08-15 20:28:05 +02:00
# include "base/configtype.hpp"
2014-05-25 16:23:35 +02:00
# include "base/utility.hpp"
2014-10-19 14:21:12 +02:00
# include "base/logger.hpp"
2014-05-25 16:23:35 +02:00
# include "remote/endpoint.hpp"
# include "icinga/notification.hpp"
# include "icinga/checkcommand.hpp"
# include "icinga/eventcommand.hpp"
# include "icinga/externalcommandprocessor.hpp"
# include "icinga/compatutility.hpp"
2017-12-06 17:03:56 +01:00
# include "icinga/pluginutility.hpp"
2014-05-25 16:23:35 +02:00
# include "icinga/icingaapplication.hpp"
2014-04-03 15:36:13 +02:00
# include <boost/algorithm/string/join.hpp>
2021-01-18 14:29:05 +01:00
# include <utility>
2014-04-03 15:36:13 +02:00
using namespace icinga ;
INITIALIZE_ONCE ( & DbEvents : : StaticInitialize ) ;
2018-01-04 04:25:35 +01:00
void DbEvents : : StaticInitialize ( )
2014-04-03 15:36:13 +02:00
{
/* Status */
2021-01-18 14:29:05 +01:00
Comment : : OnCommentAdded . connect ( [ ] ( const Comment : : Ptr & comment ) { DbEvents : : AddComment ( comment ) ; } ) ;
Comment : : OnCommentRemoved . connect ( [ ] ( const Comment : : Ptr & comment ) { DbEvents : : RemoveComment ( comment ) ; } ) ;
Downtime : : OnDowntimeAdded . connect ( [ ] ( const Downtime : : Ptr & downtime ) { DbEvents : : AddDowntime ( downtime ) ; } ) ;
Downtime : : OnDowntimeRemoved . connect ( [ ] ( const Downtime : : Ptr & downtime ) { DbEvents : : RemoveDowntime ( downtime ) ; } ) ;
Downtime : : OnDowntimeTriggered . connect ( [ ] ( const Downtime : : Ptr & downtime ) { DbEvents : : TriggerDowntime ( downtime ) ; } ) ;
Checkable : : OnAcknowledgementSet . connect ( [ ] ( const Checkable : : Ptr & checkable , const String & , const String & ,
AcknowledgementType type , bool , bool , double , double , const MessageOrigin : : Ptr & ) {
DbEvents : : AddAcknowledgement ( checkable , type ) ;
} ) ;
Checkable : : OnAcknowledgementCleared . connect ( [ ] ( const Checkable : : Ptr & checkable , const String & , double , const MessageOrigin : : Ptr & ) {
DbEvents : : RemoveAcknowledgement ( checkable ) ;
} ) ;
Checkable : : OnNextCheckUpdated . connect ( [ ] ( const Checkable : : Ptr & checkable ) { NextCheckUpdatedHandler ( checkable ) ; } ) ;
Checkable : : OnFlappingChanged . connect ( [ ] ( const Checkable : : Ptr & checkable , const Value & ) { FlappingChangedHandler ( checkable ) ; } ) ;
Checkable : : OnNotificationSentToAllUsers . connect ( [ ] ( const Notification : : Ptr & notification , const Checkable : : Ptr & checkable ,
const std : : set < User : : Ptr > & , const NotificationType & , const CheckResult : : Ptr & , const String & , const String & ,
const MessageOrigin : : Ptr & ) {
DbEvents : : LastNotificationChangedHandler ( notification , checkable ) ;
} ) ;
Checkable : : OnEnableActiveChecksChanged . connect ( [ ] ( const Checkable : : Ptr & checkable , const Value & ) {
DbEvents : : EnableActiveChecksChangedHandler ( checkable ) ;
} ) ;
Checkable : : OnEnablePassiveChecksChanged . connect ( [ ] ( const Checkable : : Ptr & checkable , const Value & ) {
DbEvents : : EnablePassiveChecksChangedHandler ( checkable ) ;
} ) ;
Checkable : : OnEnableNotificationsChanged . connect ( [ ] ( const Checkable : : Ptr & checkable , const Value & ) {
DbEvents : : EnableNotificationsChangedHandler ( checkable ) ;
} ) ;
Checkable : : OnEnablePerfdataChanged . connect ( [ ] ( const Checkable : : Ptr & checkable , const Value & ) {
DbEvents : : EnablePerfdataChangedHandler ( checkable ) ;
} ) ;
Checkable : : OnEnableFlappingChanged . connect ( [ ] ( const Checkable : : Ptr & checkable , const Value & ) {
DbEvents : : EnableFlappingChangedHandler ( checkable ) ;
} ) ;
Checkable : : OnReachabilityChanged . connect ( [ ] ( const Checkable : : Ptr & checkable , const CheckResult : : Ptr & cr ,
std : : set < Checkable : : Ptr > children , const MessageOrigin : : Ptr & ) {
DbEvents : : ReachabilityChangedHandler ( checkable , cr , std : : move ( children ) ) ;
} ) ;
2014-12-12 15:53:10 +01:00
2014-04-03 15:36:13 +02:00
/* History */
2021-01-18 14:29:05 +01:00
Comment : : OnCommentAdded . connect ( [ ] ( const Comment : : Ptr & comment ) { AddCommentHistory ( comment ) ; } ) ;
Downtime : : OnDowntimeAdded . connect ( [ ] ( const Downtime : : Ptr & downtime ) { AddDowntimeHistory ( downtime ) ; } ) ;
Checkable : : OnAcknowledgementSet . connect ( [ ] ( const Checkable : : Ptr & checkable , const String & author , const String & comment ,
AcknowledgementType type , bool notify , bool , double expiry , double , const MessageOrigin : : Ptr & ) {
DbEvents : : AddAcknowledgementHistory ( checkable , author , comment , type , notify , expiry ) ;
} ) ;
Checkable : : OnNotificationSentToAllUsers . connect ( [ ] ( const Notification : : Ptr & notification , const Checkable : : Ptr & checkable ,
const std : : set < User : : Ptr > & users , const NotificationType & type , const CheckResult : : Ptr & cr , const String & author ,
const String & text , const MessageOrigin : : Ptr & ) {
DbEvents : : AddNotificationHistory ( notification , checkable , users , type , cr , author , text ) ;
} ) ;
Checkable : : OnStateChange . connect ( [ ] ( const Checkable : : Ptr & checkable , const CheckResult : : Ptr & cr , StateType type , const MessageOrigin : : Ptr & ) {
DbEvents : : AddStateChangeHistory ( checkable , cr , type ) ;
} ) ;
Checkable : : OnNewCheckResult . connect ( [ ] ( const Checkable : : Ptr & checkable , const CheckResult : : Ptr & cr , const MessageOrigin : : Ptr & ) {
DbEvents : : AddCheckResultLogHistory ( checkable , cr ) ;
} ) ;
Checkable : : OnNotificationSentToUser . connect ( [ ] ( const Notification : : Ptr & notification , const Checkable : : Ptr & checkable ,
const User : : Ptr & users , const NotificationType & type , const CheckResult : : Ptr & cr , const String & author , const String & text ,
const String & , const MessageOrigin : : Ptr & ) {
DbEvents : : AddNotificationSentLogHistory ( notification , checkable , users , type , cr , author , text ) ;
} ) ;
Checkable : : OnFlappingChanged . connect ( [ ] ( const Checkable : : Ptr & checkable , const Value & ) {
DbEvents : : AddFlappingChangedLogHistory ( checkable ) ;
} ) ;
Checkable : : OnEnableFlappingChanged . connect ( [ ] ( const Checkable : : Ptr & checkable , const Value & ) {
DbEvents : : AddEnableFlappingChangedLogHistory ( checkable ) ;
} ) ;
Downtime : : OnDowntimeTriggered . connect ( [ ] ( const Downtime : : Ptr & downtime ) { DbEvents : : AddTriggerDowntimeLogHistory ( downtime ) ; } ) ;
Downtime : : OnDowntimeRemoved . connect ( [ ] ( const Downtime : : Ptr & downtime ) { DbEvents : : AddRemoveDowntimeLogHistory ( downtime ) ; } ) ;
Checkable : : OnFlappingChanged . connect ( [ ] ( const Checkable : : Ptr & checkable , const Value & ) { DbEvents : : AddFlappingChangedHistory ( checkable ) ; } ) ;
Checkable : : OnEnableFlappingChanged . connect ( [ ] ( const Checkable : : Ptr & checkable , const Value & ) { DbEvents : : AddEnableFlappingChangedHistory ( checkable ) ; } ) ;
Checkable : : OnNewCheckResult . connect ( [ ] ( const Checkable : : Ptr & checkable , const CheckResult : : Ptr & cr , const MessageOrigin : : Ptr & ) {
DbEvents : : AddCheckableCheckHistory ( checkable , cr ) ;
} ) ;
Checkable : : OnEventCommandExecuted . connect ( [ ] ( const Checkable : : Ptr & checkable ) { DbEvents : : AddEventHandlerHistory ( checkable ) ; } ) ;
ExternalCommandProcessor : : OnNewExternalCommand . connect ( [ ] ( double time , const String & command , const std : : vector < String > & arguments ) {
DbEvents : : AddExternalCommandHistory ( time , command , arguments ) ;
} ) ;
2014-04-03 15:36:13 +02:00
}
2014-05-02 23:38:37 +02:00
/* check events */
2016-01-22 18:42:15 +01:00
void DbEvents : : NextCheckUpdatedHandler ( const Checkable : : Ptr & checkable )
2014-05-02 23:38:37 +02:00
{
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
DbQuery query1 ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria = new Dictionary ( ) ;
if ( service ) {
2014-05-02 23:38:37 +02:00
query1 . Table = " servicestatus " ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria - > Set ( " service_object_id " , service ) ;
} else {
2014-05-02 23:38:37 +02:00
query1 . Table = " hoststatus " ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria - > Set ( " host_object_id " , host ) ;
}
2014-05-02 23:38:37 +02:00
2015-12-10 15:24:28 +01:00
query1 . Type = DbQueryUpdate ;
2014-11-10 13:21:33 +01:00
query1 . Category = DbCatState ;
2014-11-11 16:35:58 +01:00
query1 . StatusUpdate = true ;
query1 . Object = DbObject : : GetOrCreateByObject ( checkable ) ;
2014-05-02 23:38:37 +02:00
2018-01-11 11:17:38 +01:00
query1 . Fields = new Dictionary ( {
{ " next_check " , DbValue : : FromTimestamp ( checkable - > GetNextCheck ( ) ) }
} ) ;
2014-05-02 23:38:37 +02:00
2014-05-02 23:49:52 +02:00
DbObject : : OnQuery ( query1 ) ;
}
2015-08-04 14:47:44 +02:00
void DbEvents : : FlappingChangedHandler ( const Checkable : : Ptr & checkable )
2014-05-02 23:49:52 +02:00
{
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
DbQuery query1 ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria = new Dictionary ( ) ;
if ( service ) {
2014-05-02 23:49:52 +02:00
query1 . Table = " servicestatus " ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria - > Set ( " service_object_id " , service ) ;
} else {
2014-05-02 23:49:52 +02:00
query1 . Table = " hoststatus " ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria - > Set ( " host_object_id " , host ) ;
}
2014-05-02 23:49:52 +02:00
2015-12-10 15:24:28 +01:00
query1 . Type = DbQueryUpdate ;
2014-11-10 13:21:33 +01:00
query1 . Category = DbCatState ;
2014-11-11 16:35:58 +01:00
query1 . StatusUpdate = true ;
query1 . Object = DbObject : : GetOrCreateByObject ( checkable ) ;
2014-05-02 23:49:52 +02:00
2014-11-08 21:17:16 +01:00
Dictionary : : Ptr fields1 = new Dictionary ( ) ;
2017-12-05 18:53:22 +01:00
fields1 - > Set ( " is_flapping " , checkable - > IsFlapping ( ) ) ;
fields1 - > Set ( " percent_state_change " , checkable - > GetFlappingCurrent ( ) ) ;
2014-05-02 23:49:52 +02:00
2018-01-11 11:17:38 +01:00
query1 . Fields = new Dictionary ( {
{ " is_flapping " , checkable - > IsFlapping ( ) } ,
{ " percent_state_change " , checkable - > GetFlappingCurrent ( ) }
} ) ;
2014-05-02 23:49:52 +02:00
query1 . WhereCriteria - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2014-05-03 00:16:53 +02:00
DbObject : : OnQuery ( query1 ) ;
}
void DbEvents : : LastNotificationChangedHandler ( const Notification : : Ptr & notification , const Checkable : : Ptr & checkable )
{
2017-12-06 16:18:26 +01:00
std : : pair < unsigned long , unsigned long > now_bag = ConvertTimestamp ( Utility : : GetTime ( ) ) ;
2017-12-21 12:00:42 +01:00
std : : pair < unsigned long , unsigned long > timeBag = ConvertTimestamp ( notification - > GetNextNotification ( ) ) ;
2014-05-03 00:16:53 +02:00
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
DbQuery query1 ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria = new Dictionary ( ) ;
if ( service ) {
2014-05-03 00:16:53 +02:00
query1 . Table = " servicestatus " ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria - > Set ( " service_object_id " , service ) ;
} else {
2014-05-03 00:16:53 +02:00
query1 . Table = " hoststatus " ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria - > Set ( " host_object_id " , host ) ;
}
2014-05-03 00:16:53 +02:00
2015-12-10 15:24:28 +01:00
query1 . Type = DbQueryUpdate ;
2014-11-10 13:21:33 +01:00
query1 . Category = DbCatState ;
2014-11-11 16:35:58 +01:00
query1 . StatusUpdate = true ;
query1 . Object = DbObject : : GetOrCreateByObject ( checkable ) ;
2014-05-03 00:16:53 +02:00
2018-01-11 11:17:38 +01:00
query1 . Fields = new Dictionary ( {
{ " last_notification " , DbValue : : FromTimestamp ( now_bag . first ) } ,
{ " next_notification " , DbValue : : FromTimestamp ( timeBag . first ) } ,
{ " current_notification_number " , notification - > GetNotificationNumber ( ) }
} ) ;
2014-05-03 00:16:53 +02:00
query1 . WhereCriteria - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2014-05-02 23:38:37 +02:00
DbObject : : OnQuery ( query1 ) ;
}
2014-12-12 15:53:10 +01:00
void DbEvents : : ReachabilityChangedHandler ( const Checkable : : Ptr & checkable , const CheckResult : : Ptr & cr , std : : set < Checkable : : Ptr > children )
{
int is_reachable = 0 ;
if ( cr - > GetState ( ) = = ServiceOK )
is_reachable = 1 ;
2016-08-25 06:19:44 +02:00
for ( const Checkable : : Ptr & child : children ) {
2014-12-12 15:53:10 +01:00
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( child ) ;
DbQuery query1 ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria = new Dictionary ( ) ;
if ( service ) {
2014-12-12 15:53:10 +01:00
query1 . Table = " servicestatus " ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria - > Set ( " service_object_id " , service ) ;
} else {
2014-12-12 15:53:10 +01:00
query1 . Table = " hoststatus " ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria - > Set ( " host_object_id " , host ) ;
}
2014-12-12 15:53:10 +01:00
2015-12-10 15:24:28 +01:00
query1 . Type = DbQueryUpdate ;
2014-12-12 15:53:10 +01:00
query1 . Category = DbCatState ;
query1 . StatusUpdate = true ;
query1 . Object = DbObject : : GetOrCreateByObject ( child ) ;
2018-01-11 11:17:38 +01:00
query1 . Fields = new Dictionary ( {
{ " is_reachable " , is_reachable }
} ) ;
2014-12-12 15:53:10 +01:00
query1 . WhereCriteria - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
DbObject : : OnQuery ( query1 ) ;
}
}
2014-05-10 16:52:48 +02:00
/* enable changed events */
2015-08-04 14:47:44 +02:00
void DbEvents : : EnableActiveChecksChangedHandler ( const Checkable : : Ptr & checkable )
2014-05-10 16:52:48 +02:00
{
2015-08-04 14:47:44 +02:00
EnableChangedHandlerInternal ( checkable , " active_checks_enabled " , checkable - > GetEnableActiveChecks ( ) ) ;
2014-05-10 16:52:48 +02:00
}
2015-08-04 14:47:44 +02:00
void DbEvents : : EnablePassiveChecksChangedHandler ( const Checkable : : Ptr & checkable )
2014-05-10 16:52:48 +02:00
{
2015-08-04 14:47:44 +02:00
EnableChangedHandlerInternal ( checkable , " passive_checks_enabled " , checkable - > GetEnablePassiveChecks ( ) ) ;
2014-05-10 16:52:48 +02:00
}
2015-08-04 14:47:44 +02:00
void DbEvents : : EnableNotificationsChangedHandler ( const Checkable : : Ptr & checkable )
2014-05-10 16:52:48 +02:00
{
2015-08-04 14:47:44 +02:00
EnableChangedHandlerInternal ( checkable , " notifications_enabled " , checkable - > GetEnableNotifications ( ) ) ;
2014-05-10 16:52:48 +02:00
}
2015-08-04 14:47:44 +02:00
void DbEvents : : EnablePerfdataChangedHandler ( const Checkable : : Ptr & checkable )
2014-05-10 16:52:48 +02:00
{
2015-08-04 14:47:44 +02:00
EnableChangedHandlerInternal ( checkable , " process_performance_data " , checkable - > GetEnablePerfdata ( ) ) ;
2014-05-10 16:52:48 +02:00
}
2015-08-04 14:47:44 +02:00
void DbEvents : : EnableFlappingChangedHandler ( const Checkable : : Ptr & checkable )
2014-05-10 16:52:48 +02:00
{
2015-08-04 14:47:44 +02:00
EnableChangedHandlerInternal ( checkable , " flap_detection_enabled " , checkable - > GetEnableFlapping ( ) ) ;
2014-05-10 16:52:48 +02:00
}
2015-08-04 14:47:44 +02:00
void DbEvents : : EnableChangedHandlerInternal ( const Checkable : : Ptr & checkable , const String & fieldName , bool enabled )
2014-05-10 16:52:48 +02:00
{
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
DbQuery query1 ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria = new Dictionary ( ) ;
if ( service ) {
2014-05-10 16:52:48 +02:00
query1 . Table = " servicestatus " ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria - > Set ( " service_object_id " , service ) ;
} else {
2014-05-10 16:52:48 +02:00
query1 . Table = " hoststatus " ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria - > Set ( " host_object_id " , host ) ;
}
2014-05-10 16:52:48 +02:00
2015-12-10 15:24:28 +01:00
query1 . Type = DbQueryUpdate ;
2014-11-10 13:21:33 +01:00
query1 . Category = DbCatState ;
2014-11-11 16:35:58 +01:00
query1 . StatusUpdate = true ;
query1 . Object = DbObject : : GetOrCreateByObject ( checkable ) ;
2014-05-10 16:52:48 +02:00
2018-01-11 11:17:38 +01:00
query1 . Fields = new Dictionary ( {
{ fieldName , enabled }
} ) ;
2014-05-10 16:52:48 +02:00
query1 . WhereCriteria - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
DbObject : : OnQuery ( query1 ) ;
}
2015-08-04 14:47:44 +02:00
2014-04-03 15:36:13 +02:00
/* comments */
void DbEvents : : AddComments ( const Checkable : : Ptr & checkable )
{
2015-10-29 16:12:53 +01:00
std : : set < Comment : : Ptr > comments = checkable - > GetComments ( ) ;
2015-12-14 11:36:03 +01:00
std : : vector < DbQuery > queries ;
2016-08-25 06:19:44 +02:00
for ( const Comment : : Ptr & comment : comments ) {
2015-12-14 11:36:03 +01:00
AddCommentInternal ( queries , comment , false ) ;
2014-04-03 15:36:13 +02:00
}
2015-12-14 11:36:03 +01:00
DbObject : : OnMultipleQueries ( queries ) ;
2014-04-03 15:36:13 +02:00
}
2015-08-20 17:18:48 +02:00
void DbEvents : : AddComment ( const Comment : : Ptr & comment )
2014-04-03 15:36:13 +02:00
{
2015-12-14 11:36:03 +01:00
std : : vector < DbQuery > queries ;
AddCommentInternal ( queries , comment , false ) ;
DbObject : : OnMultipleQueries ( queries ) ;
2014-04-03 15:36:13 +02:00
}
2015-08-20 17:18:48 +02:00
void DbEvents : : AddCommentHistory ( const Comment : : Ptr & comment )
2014-04-03 15:36:13 +02:00
{
2015-12-14 11:36:03 +01:00
std : : vector < DbQuery > queries ;
AddCommentInternal ( queries , comment , true ) ;
DbObject : : OnMultipleQueries ( queries ) ;
2014-04-03 15:36:13 +02:00
}
2015-12-14 11:36:03 +01:00
void DbEvents : : AddCommentInternal ( std : : vector < DbQuery > & queries , const Comment : : Ptr & comment , bool historical )
2014-04-03 15:36:13 +02:00
{
2015-08-20 17:18:48 +02:00
Checkable : : Ptr checkable = comment - > GetCheckable ( ) ;
2017-12-21 12:00:42 +01:00
std : : pair < unsigned long , unsigned long > timeBag = ConvertTimestamp ( comment - > GetEntryTime ( ) ) ;
2014-04-03 15:36:13 +02:00
2014-11-08 21:17:16 +01:00
Dictionary : : Ptr fields1 = new Dictionary ( ) ;
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " entry_time " , DbValue : : FromTimestamp ( timeBag . first ) ) ;
fields1 - > Set ( " entry_time_usec " , timeBag . second ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " entry_type " , comment - > GetEntryType ( ) ) ;
2015-08-20 17:18:48 +02:00
fields1 - > Set ( " object_id " , checkable ) ;
2014-04-03 15:36:13 +02:00
2017-12-21 12:00:42 +01:00
int commentType = 0 ;
if ( checkable - > GetReflectionType ( ) = = Host : : TypeInstance )
commentType = 2 ;
else if ( checkable - > GetReflectionType ( ) = = Service : : TypeInstance )
commentType = 1 ;
else {
2014-04-03 15:36:13 +02:00
return ;
}
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " comment_type " , commentType ) ;
fields1 - > Set ( " internal_comment_id " , comment - > GetLegacyId ( ) ) ;
2015-11-06 16:45:09 +01:00
fields1 - > Set ( " name " , comment - > GetName ( ) ) ;
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " comment_time " , DbValue : : FromTimestamp ( timeBag . first ) ) ; /* same as entry_time */
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " author_name " , comment - > GetAuthor ( ) ) ;
fields1 - > Set ( " comment_data " , comment - > GetText ( ) ) ;
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " is_persistent " , comment - > GetPersistent ( ) ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " comment_source " , 1 ) ; /* external */
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " expires " , ( comment - > GetExpireTime ( ) > 0 ) ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " expiration_time " , DbValue : : FromTimestamp ( comment - > GetExpireTime ( ) ) ) ;
fields1 - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2017-12-21 12:00:42 +01:00
Endpoint : : Ptr endpoint = Endpoint : : GetByName ( IcingaApplication : : GetInstance ( ) - > GetNodeName ( ) ) ;
2014-04-03 15:36:13 +02:00
if ( endpoint )
fields1 - > Set ( " endpoint_object_id " , endpoint ) ;
DbQuery query1 ;
2017-12-21 12:00:42 +01:00
2014-04-03 15:36:13 +02:00
if ( ! historical ) {
query1 . Table = " comments " ;
2016-08-01 17:54:03 +02:00
query1 . Type = DbQueryInsert | DbQueryUpdate ;
fields1 - > Set ( " session_token " , 0 ) ; /* DbConnection class fills in real ID */
2018-01-11 11:17:38 +01:00
query1 . WhereCriteria = new Dictionary ( {
{ " object_id " , checkable } ,
{ " name " , comment - > GetName ( ) } ,
{ " entry_time " , DbValue : : FromTimestamp ( timeBag . first ) }
} ) ;
2014-04-03 15:36:13 +02:00
} else {
query1 . Table = " commenthistory " ;
2016-08-01 17:54:03 +02:00
query1 . Type = DbQueryInsert ;
2014-04-03 15:36:13 +02:00
}
2017-12-21 12:00:42 +01:00
2014-04-03 15:36:13 +02:00
query1 . Category = DbCatComment ;
query1 . Fields = fields1 ;
2017-11-30 08:19:58 +01:00
queries . emplace_back ( std : : move ( query1 ) ) ;
2014-04-03 15:36:13 +02:00
}
2015-12-14 11:36:03 +01:00
void DbEvents : : RemoveComment ( const Comment : : Ptr & comment )
2014-04-03 15:36:13 +02:00
{
2015-12-14 11:36:03 +01:00
std : : vector < DbQuery > queries ;
RemoveCommentInternal ( queries , comment ) ;
DbObject : : OnMultipleQueries ( queries ) ;
2014-04-03 15:36:13 +02:00
}
2015-12-14 11:36:03 +01:00
void DbEvents : : RemoveCommentInternal ( std : : vector < DbQuery > & queries , const Comment : : Ptr & comment )
2014-04-03 15:36:13 +02:00
{
2015-08-20 17:18:48 +02:00
Checkable : : Ptr checkable = comment - > GetCheckable ( ) ;
2014-04-03 15:36:13 +02:00
2017-12-21 12:00:42 +01:00
std : : pair < unsigned long , unsigned long > timeBag = ConvertTimestamp ( comment - > GetEntryTime ( ) ) ;
2016-06-20 17:38:01 +02:00
2014-04-03 15:36:13 +02:00
/* Status */
DbQuery query1 ;
query1 . Table = " comments " ;
query1 . Type = DbQueryDelete ;
query1 . Category = DbCatComment ;
2017-12-21 12:00:42 +01:00
2018-01-11 11:17:38 +01:00
query1 . WhereCriteria = new Dictionary ( {
{ " object_id " , checkable } ,
{ " entry_time " , DbValue : : FromTimestamp ( timeBag . first ) } ,
{ " name " , comment - > GetName ( ) }
} ) ;
2017-11-30 08:19:58 +01:00
queries . emplace_back ( std : : move ( query1 ) ) ;
2014-04-03 15:36:13 +02:00
/* History - update deletion time for service/host */
2017-12-21 12:00:42 +01:00
std : : pair < unsigned long , unsigned long > timeBagNow = ConvertTimestamp ( Utility : : GetTime ( ) ) ;
2014-04-03 15:36:13 +02:00
DbQuery query2 ;
query2 . Table = " commenthistory " ;
query2 . Type = DbQueryUpdate ;
query2 . Category = DbCatComment ;
2018-01-11 11:17:38 +01:00
query2 . Fields = new Dictionary ( {
{ " deletion_time " , DbValue : : FromTimestamp ( timeBagNow . first ) } ,
{ " deletion_time_usec " , timeBagNow . second }
} ) ;
2014-04-03 15:36:13 +02:00
2018-01-11 11:17:38 +01:00
query2 . WhereCriteria = new Dictionary ( {
{ " object_id " , checkable } ,
{ " entry_time " , DbValue : : FromTimestamp ( timeBag . first ) } ,
{ " name " , comment - > GetName ( ) }
} ) ;
2017-12-21 12:00:42 +01:00
2017-11-30 08:19:58 +01:00
queries . emplace_back ( std : : move ( query2 ) ) ;
2014-04-03 15:36:13 +02:00
}
/* downtimes */
void DbEvents : : AddDowntimes ( const Checkable : : Ptr & checkable )
{
2015-10-29 16:12:53 +01:00
std : : set < Downtime : : Ptr > downtimes = checkable - > GetDowntimes ( ) ;
2015-12-14 11:36:03 +01:00
std : : vector < DbQuery > queries ;
2016-08-25 06:19:44 +02:00
for ( const Downtime : : Ptr & downtime : downtimes ) {
2015-12-14 11:36:03 +01:00
AddDowntimeInternal ( queries , downtime , false ) ;
2014-04-03 15:36:13 +02:00
}
2015-12-14 11:36:03 +01:00
DbObject : : OnMultipleQueries ( queries ) ;
2014-04-03 15:36:13 +02:00
}
2015-12-14 11:36:03 +01:00
void DbEvents : : AddDowntime ( const Downtime : : Ptr & downtime )
2014-04-03 15:36:13 +02:00
{
2015-12-14 11:36:03 +01:00
std : : vector < DbQuery > queries ;
AddDowntimeInternal ( queries , downtime , false ) ;
DbObject : : OnMultipleQueries ( queries ) ;
2014-04-03 15:36:13 +02:00
}
2015-12-14 11:36:03 +01:00
void DbEvents : : AddDowntimeHistory ( const Downtime : : Ptr & downtime )
2014-04-03 15:36:13 +02:00
{
2015-12-14 11:36:03 +01:00
std : : vector < DbQuery > queries ;
2015-12-16 13:57:29 +01:00
AddDowntimeInternal ( queries , downtime , true ) ;
2015-12-14 11:36:03 +01:00
DbObject : : OnMultipleQueries ( queries ) ;
2015-02-07 19:37:12 +01:00
}
2014-04-03 15:36:13 +02:00
2015-12-14 11:36:03 +01:00
void DbEvents : : AddDowntimeInternal ( std : : vector < DbQuery > & queries , const Downtime : : Ptr & downtime , bool historical )
2014-04-03 15:36:13 +02:00
{
2015-08-20 17:18:48 +02:00
Checkable : : Ptr checkable = downtime - > GetCheckable ( ) ;
2014-11-08 21:17:16 +01:00
Dictionary : : Ptr fields1 = new Dictionary ( ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " entry_time " , DbValue : : FromTimestamp ( downtime - > GetEntryTime ( ) ) ) ;
fields1 - > Set ( " object_id " , checkable ) ;
2017-12-21 12:00:42 +01:00
int downtimeType = 0 ;
if ( checkable - > GetReflectionType ( ) = = Host : : TypeInstance )
downtimeType = 2 ;
else if ( checkable - > GetReflectionType ( ) = = Service : : TypeInstance )
downtimeType = 1 ;
else {
2014-04-03 15:36:13 +02:00
return ;
}
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " downtime_type " , downtimeType ) ;
fields1 - > Set ( " internal_downtime_id " , downtime - > GetLegacyId ( ) ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " author_name " , downtime - > GetAuthor ( ) ) ;
fields1 - > Set ( " comment_data " , downtime - > GetComment ( ) ) ;
2015-08-20 17:18:48 +02:00
fields1 - > Set ( " triggered_by_id " , Downtime : : GetByName ( downtime - > GetTriggeredBy ( ) ) ) ;
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " is_fixed " , downtime - > GetFixed ( ) ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " duration " , downtime - > GetDuration ( ) ) ;
fields1 - > Set ( " scheduled_start_time " , DbValue : : FromTimestamp ( downtime - > GetStartTime ( ) ) ) ;
fields1 - > Set ( " scheduled_end_time " , DbValue : : FromTimestamp ( downtime - > GetEndTime ( ) ) ) ;
2017-09-19 13:14:57 +02:00
fields1 - > Set ( " name " , downtime - > GetName ( ) ) ;
2016-08-11 12:10:04 +02:00
/* flexible downtimes are started at trigger time */
if ( downtime - > GetFixed ( ) ) {
2017-12-21 12:00:42 +01:00
std : : pair < unsigned long , unsigned long > timeBag = ConvertTimestamp ( downtime - > GetStartTime ( ) ) ;
fields1 - > Set ( " actual_start_time " , DbValue : : FromTimestamp ( timeBag . first ) ) ;
fields1 - > Set ( " actual_start_time_usec " , timeBag . second ) ;
2016-08-11 12:10:04 +02:00
fields1 - > Set ( " was_started " , ( ( downtime - > GetStartTime ( ) < = Utility : : GetTime ( ) ) ? 1 : 0 ) ) ;
}
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " is_in_effect " , downtime - > IsInEffect ( ) ) ;
2016-03-23 13:42:00 +01:00
fields1 - > Set ( " trigger_time " , DbValue : : FromTimestamp ( downtime - > GetTriggerTime ( ) ) ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2017-12-21 12:00:42 +01:00
Endpoint : : Ptr endpoint = Endpoint : : GetByName ( IcingaApplication : : GetInstance ( ) - > GetNodeName ( ) ) ;
2014-04-03 15:36:13 +02:00
if ( endpoint )
fields1 - > Set ( " endpoint_object_id " , endpoint ) ;
DbQuery query1 ;
2016-08-01 17:54:03 +02:00
if ( ! historical ) {
2014-04-03 15:36:13 +02:00
query1 . Table = " scheduleddowntime " ;
2016-08-01 17:54:03 +02:00
query1 . Type = DbQueryInsert | DbQueryUpdate ;
fields1 - > Set ( " session_token " , 0 ) ; /* DbConnection class fills in real ID */
2018-01-11 11:17:38 +01:00
query1 . WhereCriteria = new Dictionary ( {
{ " object_id " , checkable } ,
{ " name " , downtime - > GetName ( ) } ,
{ " entry_time " , DbValue : : FromTimestamp ( downtime - > GetEntryTime ( ) ) }
} ) ;
2016-08-01 17:54:03 +02:00
} else {
2014-04-03 15:36:13 +02:00
query1 . Table = " downtimehistory " ;
2016-08-01 17:54:03 +02:00
query1 . Type = DbQueryInsert ;
}
2014-04-03 15:36:13 +02:00
query1 . Category = DbCatDowntime ;
query1 . Fields = fields1 ;
2017-11-30 08:19:58 +01:00
queries . emplace_back ( std : : move ( query1 ) ) ;
2016-03-23 13:42:00 +01:00
/* host/service status */
if ( ! historical ) {
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
DbQuery query2 ;
2017-12-21 12:00:42 +01:00
query2 . WhereCriteria = new Dictionary ( ) ;
if ( service ) {
2016-03-23 13:42:00 +01:00
query2 . Table = " servicestatus " ;
2017-12-21 12:00:42 +01:00
query2 . WhereCriteria - > Set ( " service_object_id " , service ) ;
} else {
2016-03-23 13:42:00 +01:00
query2 . Table = " hoststatus " ;
2017-12-21 12:00:42 +01:00
query2 . WhereCriteria - > Set ( " host_object_id " , host ) ;
}
2016-03-23 13:42:00 +01:00
query2 . Type = DbQueryUpdate ;
query2 . Category = DbCatState ;
query2 . StatusUpdate = true ;
query2 . Object = DbObject : : GetOrCreateByObject ( checkable ) ;
Dictionary : : Ptr fields2 = new Dictionary ( ) ;
fields2 - > Set ( " scheduled_downtime_depth " , checkable - > GetDowntimeDepth ( ) ) ;
query2 . Fields = fields2 ;
query2 . WhereCriteria - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2017-12-21 12:00:42 +01:00
2017-11-30 08:19:58 +01:00
queries . emplace_back ( std : : move ( query2 ) ) ;
2016-03-23 13:42:00 +01:00
}
2014-04-03 15:36:13 +02:00
}
2015-12-14 11:36:03 +01:00
void DbEvents : : RemoveDowntime ( const Downtime : : Ptr & downtime )
2014-04-03 15:36:13 +02:00
{
2015-12-14 11:36:03 +01:00
std : : vector < DbQuery > queries ;
RemoveDowntimeInternal ( queries , downtime ) ;
DbObject : : OnMultipleQueries ( queries ) ;
2014-04-03 15:36:13 +02:00
}
2015-12-14 11:36:03 +01:00
void DbEvents : : RemoveDowntimeInternal ( std : : vector < DbQuery > & queries , const Downtime : : Ptr & downtime )
2014-04-03 15:36:13 +02:00
{
2015-08-20 17:18:48 +02:00
Checkable : : Ptr checkable = downtime - > GetCheckable ( ) ;
2014-04-03 15:36:13 +02:00
/* Status */
DbQuery query1 ;
query1 . Table = " scheduleddowntime " ;
query1 . Type = DbQueryDelete ;
query1 . Category = DbCatDowntime ;
2014-11-08 21:17:16 +01:00
query1 . WhereCriteria = new Dictionary ( ) ;
2017-08-09 17:41:43 +02:00
2014-04-03 15:36:13 +02:00
query1 . WhereCriteria - > Set ( " object_id " , checkable ) ;
2016-06-20 17:38:01 +02:00
query1 . WhereCriteria - > Set ( " entry_time " , DbValue : : FromTimestamp ( downtime - > GetEntryTime ( ) ) ) ;
2015-10-28 17:12:23 +01:00
query1 . WhereCriteria - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2017-09-19 13:14:57 +02:00
query1 . WhereCriteria - > Set ( " scheduled_start_time " , DbValue : : FromTimestamp ( downtime - > GetStartTime ( ) ) ) ;
query1 . WhereCriteria - > Set ( " scheduled_end_time " , DbValue : : FromTimestamp ( downtime - > GetEndTime ( ) ) ) ;
query1 . WhereCriteria - > Set ( " name " , downtime - > GetName ( ) ) ;
2017-11-30 08:19:58 +01:00
queries . emplace_back ( std : : move ( query1 ) ) ;
2014-04-03 15:36:13 +02:00
/* History - update actual_end_time, was_cancelled for service (and host in case) */
2017-12-21 12:00:42 +01:00
std : : pair < unsigned long , unsigned long > timeBag = ConvertTimestamp ( Utility : : GetTime ( ) ) ;
2014-04-03 15:36:13 +02:00
DbQuery query3 ;
query3 . Table = " downtimehistory " ;
query3 . Type = DbQueryUpdate ;
query3 . Category = DbCatDowntime ;
2014-11-08 21:17:16 +01:00
Dictionary : : Ptr fields3 = new Dictionary ( ) ;
2014-04-03 15:36:13 +02:00
fields3 - > Set ( " was_cancelled " , downtime - > GetWasCancelled ( ) ? 1 : 0 ) ;
2017-02-24 15:29:39 +01:00
if ( downtime - > GetFixed ( ) | | ( ! downtime - > GetFixed ( ) & & downtime - > GetTriggerTime ( ) > 0 ) ) {
2017-12-21 12:00:42 +01:00
fields3 - > Set ( " actual_end_time " , DbValue : : FromTimestamp ( timeBag . first ) ) ;
fields3 - > Set ( " actual_end_time_usec " , timeBag . second ) ;
2017-02-24 15:29:39 +01:00
}
2016-03-23 13:42:00 +01:00
fields3 - > Set ( " is_in_effect " , 0 ) ;
2014-04-03 15:36:13 +02:00
query3 . Fields = fields3 ;
2018-01-11 11:17:38 +01:00
query3 . WhereCriteria = new Dictionary ( {
{ " object_id " , checkable } ,
{ " entry_time " , DbValue : : FromTimestamp ( downtime - > GetEntryTime ( ) ) } ,
{ " instance_id " , 0 } , /* DbConnection class fills in real ID */
{ " scheduled_start_time " , DbValue : : FromTimestamp ( downtime - > GetStartTime ( ) ) } ,
{ " scheduled_end_time " , DbValue : : FromTimestamp ( downtime - > GetEndTime ( ) ) } ,
{ " name " , downtime - > GetName ( ) }
} ) ;
2017-11-30 08:19:58 +01:00
queries . emplace_back ( std : : move ( query3 ) ) ;
2015-04-11 11:40:14 +02:00
/* host/service status */
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
DbQuery query4 ;
2017-12-21 12:00:42 +01:00
query4 . WhereCriteria = new Dictionary ( ) ;
if ( service ) {
2015-04-11 11:40:14 +02:00
query4 . Table = " servicestatus " ;
2017-12-21 12:00:42 +01:00
query4 . WhereCriteria - > Set ( " service_object_id " , service ) ;
} else {
2015-04-11 11:40:14 +02:00
query4 . Table = " hoststatus " ;
2017-12-21 12:00:42 +01:00
query4 . WhereCriteria - > Set ( " host_object_id " , host ) ;
}
2015-04-11 11:40:14 +02:00
2015-12-14 11:36:03 +01:00
query4 . Type = DbQueryUpdate ;
2015-04-11 11:40:14 +02:00
query4 . Category = DbCatState ;
query4 . StatusUpdate = true ;
query4 . Object = DbObject : : GetOrCreateByObject ( checkable ) ;
Dictionary : : Ptr fields4 = new Dictionary ( ) ;
fields4 - > Set ( " scheduled_downtime_depth " , checkable - > GetDowntimeDepth ( ) ) ;
query4 . Fields = fields4 ;
query4 . WhereCriteria - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2017-12-21 12:00:42 +01:00
2017-11-30 08:19:58 +01:00
queries . emplace_back ( std : : move ( query4 ) ) ;
2014-04-03 15:36:13 +02:00
}
2015-08-20 17:18:48 +02:00
void DbEvents : : TriggerDowntime ( const Downtime : : Ptr & downtime )
2014-04-03 15:36:13 +02:00
{
2015-08-20 17:18:48 +02:00
Checkable : : Ptr checkable = downtime - > GetCheckable ( ) ;
2014-04-03 15:36:13 +02:00
2017-12-21 12:00:42 +01:00
std : : pair < unsigned long , unsigned long > timeBag = ConvertTimestamp ( Utility : : GetTime ( ) ) ;
2014-04-03 15:36:13 +02:00
/* Status */
DbQuery query1 ;
query1 . Table = " scheduleddowntime " ;
query1 . Type = DbQueryUpdate ;
query1 . Category = DbCatDowntime ;
2018-01-11 11:17:38 +01:00
query1 . Fields = new Dictionary ( {
{ " was_started " , 1 } ,
{ " actual_start_time " , DbValue : : FromTimestamp ( timeBag . first ) } ,
{ " actual_start_time_usec " , timeBag . second } ,
{ " is_in_effect " , ( downtime - > IsInEffect ( ) ? 1 : 0 ) } ,
{ " trigger_time " , DbValue : : FromTimestamp ( downtime - > GetTriggerTime ( ) ) } ,
{ " instance_id " , 0 } /* DbConnection class fills in real ID */
} ) ;
query1 . WhereCriteria = new Dictionary ( {
{ " object_id " , checkable } ,
{ " entry_time " , DbValue : : FromTimestamp ( downtime - > GetEntryTime ( ) ) } ,
{ " instance_id " , 0 } , /* DbConnection class fills in real ID */
{ " scheduled_start_time " , DbValue : : FromTimestamp ( downtime - > GetStartTime ( ) ) } ,
{ " scheduled_end_time " , DbValue : : FromTimestamp ( downtime - > GetEndTime ( ) ) } ,
{ " name " , downtime - > GetName ( ) }
} ) ;
2014-04-03 15:36:13 +02:00
DbObject : : OnQuery ( query1 ) ;
/* History - downtime was started for service (and host in case) */
DbQuery query3 ;
query3 . Table = " downtimehistory " ;
query3 . Type = DbQueryUpdate ;
query3 . Category = DbCatDowntime ;
2018-01-11 11:17:38 +01:00
query3 . Fields = new Dictionary ( {
{ " was_started " , 1 } ,
{ " is_in_effect " , 1 } ,
{ " actual_start_time " , DbValue : : FromTimestamp ( timeBag . first ) } ,
{ " actual_start_time_usec " , timeBag . second } ,
{ " trigger_time " , DbValue : : FromTimestamp ( downtime - > GetTriggerTime ( ) ) }
} ) ;
2014-04-03 15:36:13 +02:00
2017-09-19 13:14:57 +02:00
query3 . WhereCriteria = query1 . WhereCriteria ;
2014-04-03 15:36:13 +02:00
DbObject : : OnQuery ( query3 ) ;
2014-05-03 00:37:47 +02:00
/* host/service status */
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
DbQuery query4 ;
2017-12-21 12:00:42 +01:00
query4 . WhereCriteria = new Dictionary ( ) ;
if ( service ) {
2014-05-03 00:37:47 +02:00
query4 . Table = " servicestatus " ;
2017-12-21 12:00:42 +01:00
query4 . WhereCriteria - > Set ( " service_object_id " , service ) ;
} else {
2014-05-03 00:37:47 +02:00
query4 . Table = " hoststatus " ;
2017-12-21 12:00:42 +01:00
query4 . WhereCriteria - > Set ( " host_object_id " , host ) ;
}
2014-05-03 00:37:47 +02:00
2015-12-14 11:36:03 +01:00
query4 . Type = DbQueryUpdate ;
2014-11-11 16:35:58 +01:00
query4 . Category = DbCatState ;
query4 . StatusUpdate = true ;
query4 . Object = DbObject : : GetOrCreateByObject ( checkable ) ;
2014-05-03 00:37:47 +02:00
2018-01-11 11:17:38 +01:00
query4 . Fields = new Dictionary ( {
{ " scheduled_downtime_depth " , checkable - > GetDowntimeDepth ( ) }
} ) ;
2014-05-03 00:37:47 +02:00
query4 . WhereCriteria - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
DbObject : : OnQuery ( query4 ) ;
2014-04-03 15:36:13 +02:00
}
/* acknowledgements */
void DbEvents : : AddAcknowledgementHistory ( const Checkable : : Ptr & checkable , const String & author , const String & comment ,
2017-12-19 15:50:05 +01:00
AcknowledgementType type , bool notify , double expiry )
2014-04-03 15:36:13 +02:00
{
2017-12-21 12:00:42 +01:00
std : : pair < unsigned long , unsigned long > timeBag = ConvertTimestamp ( Utility : : GetTime ( ) ) ;
2014-04-03 15:36:13 +02:00
DbQuery query1 ;
query1 . Table = " acknowledgements " ;
query1 . Type = DbQueryInsert ;
query1 . Category = DbCatAcknowledgement ;
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
2014-11-08 21:17:16 +01:00
Dictionary : : Ptr fields1 = new Dictionary ( ) ;
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " entry_time " , DbValue : : FromTimestamp ( timeBag . first ) ) ;
fields1 - > Set ( " entry_time_usec " , timeBag . second ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " acknowledgement_type " , type ) ;
fields1 - > Set ( " object_id " , checkable ) ;
fields1 - > Set ( " author_name " , author ) ;
fields1 - > Set ( " comment_data " , comment ) ;
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " persistent_comment " , 1 ) ;
fields1 - > Set ( " notify_contacts " , notify ) ;
fields1 - > Set ( " is_sticky " , type = = AcknowledgementSticky ) ;
fields1 - > Set ( " end_time " , DbValue : : FromTimestamp ( expiry ) ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2017-12-21 12:00:42 +01:00
if ( service )
2017-08-07 10:58:52 +02:00
fields1 - > Set ( " state " , service - > GetState ( ) ) ;
2017-12-21 12:00:42 +01:00
else
2017-12-21 09:12:12 +01:00
fields1 - > Set ( " state " , GetHostState ( host ) ) ;
2017-08-07 10:58:52 +02:00
2017-12-21 12:00:42 +01:00
Endpoint : : Ptr endpoint = Endpoint : : GetByName ( IcingaApplication : : GetInstance ( ) - > GetNodeName ( ) ) ;
2014-04-03 15:36:13 +02:00
if ( endpoint )
fields1 - > Set ( " endpoint_object_id " , endpoint ) ;
query1 . Fields = fields1 ;
DbObject : : OnQuery ( query1 ) ;
}
2014-05-02 23:17:36 +02:00
void DbEvents : : AddAcknowledgement ( const Checkable : : Ptr & checkable , AcknowledgementType type )
{
AddAcknowledgementInternal ( checkable , type , true ) ;
}
void DbEvents : : RemoveAcknowledgement ( const Checkable : : Ptr & checkable )
{
AddAcknowledgementInternal ( checkable , AcknowledgementNone , false ) ;
}
void DbEvents : : AddAcknowledgementInternal ( const Checkable : : Ptr & checkable , AcknowledgementType type , bool add )
{
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
DbQuery query1 ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria = new Dictionary ( ) ;
if ( service ) {
2014-05-02 23:17:36 +02:00
query1 . Table = " servicestatus " ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria - > Set ( " service_object_id " , service ) ;
} else {
2014-05-02 23:17:36 +02:00
query1 . Table = " hoststatus " ;
2017-12-21 12:00:42 +01:00
query1 . WhereCriteria - > Set ( " host_object_id " , host ) ;
}
2014-05-02 23:17:36 +02:00
2015-12-14 11:36:03 +01:00
query1 . Type = DbQueryUpdate ;
2014-11-11 16:35:58 +01:00
query1 . Category = DbCatState ;
query1 . StatusUpdate = true ;
query1 . Object = DbObject : : GetOrCreateByObject ( checkable ) ;
2014-05-02 23:17:36 +02:00
2018-01-11 11:17:38 +01:00
query1 . Fields = new Dictionary ( {
{ " acknowledgement_type " , type } ,
{ " problem_has_been_acknowledged " , add ? 1 : 0 }
} ) ;
2014-05-02 23:17:36 +02:00
query1 . WhereCriteria - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
DbObject : : OnQuery ( query1 ) ;
}
2014-04-03 15:36:13 +02:00
/* notifications */
void DbEvents : : AddNotificationHistory ( const Notification : : Ptr & notification , const Checkable : : Ptr & checkable , const std : : set < User : : Ptr > & users , NotificationType type ,
2017-12-19 15:50:05 +01:00
const CheckResult : : Ptr & cr , const String & author , const String & text )
2014-04-03 15:36:13 +02:00
{
2022-02-10 16:08:30 +01:00
/* NotificationInsertID has to be tracked per IDO instance, therefore the OnQuery and OnMultipleQueries signals
* cannot be called directly as all IDO instances would insert rows with the same ID which is ( most likely ) only
* correct in one database . Instead , pass a lambda which generates the queries with new DbValue for
* NotificationInsertID each IDO instance .
*/
DbObject : : OnMakeQueries ( [ & checkable , & users , & type , & cr ] ( const DbObject : : QueryCallbacks & callbacks ) {
/* start and end happen at the same time */
std : : pair < unsigned long , unsigned long > timeBag = ConvertTimestamp ( Utility : : GetTime ( ) ) ;
2014-04-03 15:36:13 +02:00
2022-02-10 16:08:30 +01:00
DbQuery query1 ;
query1 . Table = " notifications " ;
query1 . Type = DbQueryInsert ;
query1 . Category = DbCatNotification ;
query1 . NotificationInsertID = new DbValue ( DbValueObjectInsertID , - 1 ) ;
2014-04-03 15:36:13 +02:00
2022-02-10 16:08:30 +01:00
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
2017-08-07 10:58:52 +02:00
2022-02-10 16:08:30 +01:00
Dictionary : : Ptr fields1 = new Dictionary ( ) ;
fields1 - > Set ( " notification_type " , 1 ) ; /* service */
fields1 - > Set ( " notification_reason " , MapNotificationReasonType ( type ) ) ;
fields1 - > Set ( " object_id " , checkable ) ;
fields1 - > Set ( " start_time " , DbValue : : FromTimestamp ( timeBag . first ) ) ;
fields1 - > Set ( " start_time_usec " , timeBag . second ) ;
fields1 - > Set ( " end_time " , DbValue : : FromTimestamp ( timeBag . first ) ) ;
fields1 - > Set ( " end_time_usec " , timeBag . second ) ;
if ( service )
fields1 - > Set ( " state " , service - > GetState ( ) ) ;
else
fields1 - > Set ( " state " , GetHostState ( host ) ) ;
if ( cr ) {
fields1 - > Set ( " output " , CompatUtility : : GetCheckResultOutput ( cr ) ) ;
fields1 - > Set ( " long_output " , CompatUtility : : GetCheckResultLongOutput ( cr ) ) ;
}
2014-04-03 15:36:13 +02:00
2022-02-10 16:08:30 +01:00
fields1 - > Set ( " escalated " , 0 ) ;
fields1 - > Set ( " contacts_notified " , static_cast < long > ( users . size ( ) ) ) ;
fields1 - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2014-04-03 15:36:13 +02:00
2022-02-10 16:08:30 +01:00
Endpoint : : Ptr endpoint = Endpoint : : GetByName ( IcingaApplication : : GetInstance ( ) - > GetNodeName ( ) ) ;
2014-04-03 15:36:13 +02:00
2022-02-10 16:08:30 +01:00
if ( endpoint )
fields1 - > Set ( " endpoint_object_id " , endpoint ) ;
2014-04-03 15:36:13 +02:00
2022-02-10 16:08:30 +01:00
query1 . Fields = fields1 ;
callbacks . Query ( query1 ) ;
2014-04-03 15:36:13 +02:00
2022-02-10 16:08:30 +01:00
std : : vector < DbQuery > queries ;
2014-04-03 15:36:13 +02:00
2022-02-10 16:08:30 +01:00
for ( const User : : Ptr & user : users ) {
DbQuery query2 ;
query2 . Table = " contactnotifications " ;
query2 . Type = DbQueryInsert ;
query2 . Category = DbCatNotification ;
2014-04-03 15:36:13 +02:00
2022-02-10 16:08:30 +01:00
query2 . Fields = new Dictionary ( {
{ " contact_object_id " , user } ,
{ " start_time " , DbValue : : FromTimestamp ( timeBag . first ) } ,
{ " start_time_usec " , timeBag . second } ,
{ " end_time " , DbValue : : FromTimestamp ( timeBag . first ) } ,
{ " end_time_usec " , timeBag . second } ,
{ " notification_id " , query1 . NotificationInsertID } ,
{ " instance_id " , 0 } /* DbConnection class fills in real ID */
} ) ;
2014-04-03 15:36:13 +02:00
2022-02-10 16:08:30 +01:00
queries . emplace_back ( std : : move ( query2 ) ) ;
}
2016-03-21 13:37:32 +01:00
2022-02-10 16:08:30 +01:00
callbacks . MultipleQueries ( queries ) ;
} ) ;
2014-04-03 15:36:13 +02:00
}
/* statehistory */
void DbEvents : : AddStateChangeHistory ( const Checkable : : Ptr & checkable , const CheckResult : : Ptr & cr , StateType type )
{
2015-04-24 17:41:07 +02:00
double ts = cr - > GetExecutionEnd ( ) ;
2017-12-21 12:00:42 +01:00
std : : pair < unsigned long , unsigned long > timeBag = ConvertTimestamp ( ts ) ;
2014-04-03 15:36:13 +02:00
DbQuery query1 ;
query1 . Table = " statehistory " ;
query1 . Type = DbQueryInsert ;
query1 . Category = DbCatStateHistory ;
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
2014-11-08 21:17:16 +01:00
Dictionary : : Ptr fields1 = new Dictionary ( ) ;
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " state_time " , DbValue : : FromTimestamp ( timeBag . first ) ) ;
fields1 - > Set ( " state_time_usec " , timeBag . second ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " object_id " , checkable ) ;
fields1 - > Set ( " state_change " , 1 ) ; /* service */
fields1 - > Set ( " state_type " , checkable - > GetStateType ( ) ) ;
fields1 - > Set ( " current_check_attempt " , checkable - > GetCheckAttempt ( ) ) ;
fields1 - > Set ( " max_check_attempts " , checkable - > GetMaxCheckAttempts ( ) ) ;
if ( service ) {
2017-08-07 10:58:52 +02:00
fields1 - > Set ( " state " , service - > GetState ( ) ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " last_state " , service - > GetLastState ( ) ) ;
fields1 - > Set ( " last_hard_state " , service - > GetLastHardState ( ) ) ;
} else {
2017-12-21 09:12:12 +01:00
fields1 - > Set ( " state " , GetHostState ( host ) ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " last_state " , host - > GetLastState ( ) ) ;
fields1 - > Set ( " last_hard_state " , host - > GetLastHardState ( ) ) ;
}
if ( cr ) {
fields1 - > Set ( " output " , CompatUtility : : GetCheckResultOutput ( cr ) ) ;
fields1 - > Set ( " long_output " , CompatUtility : : GetCheckResultLongOutput ( cr ) ) ;
fields1 - > Set ( " check_source " , cr - > GetCheckSource ( ) ) ;
}
fields1 - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2017-12-21 12:00:42 +01:00
Endpoint : : Ptr endpoint = Endpoint : : GetByName ( IcingaApplication : : GetInstance ( ) - > GetNodeName ( ) ) ;
2014-04-03 15:36:13 +02:00
if ( endpoint )
fields1 - > Set ( " endpoint_object_id " , endpoint ) ;
query1 . Fields = fields1 ;
DbObject : : OnQuery ( query1 ) ;
}
/* logentries */
void DbEvents : : AddCheckResultLogHistory ( const Checkable : : Ptr & checkable , const CheckResult : : Ptr & cr )
{
2017-12-21 12:00:42 +01:00
if ( ! cr )
return ;
2014-04-03 15:36:13 +02:00
2017-12-21 12:00:42 +01:00
Dictionary : : Ptr varsBefore = cr - > GetVarsBefore ( ) ;
Dictionary : : Ptr varsAfter = cr - > GetVarsAfter ( ) ;
2014-04-03 15:36:13 +02:00
2017-12-21 12:00:42 +01:00
if ( varsBefore & & varsAfter ) {
if ( varsBefore - > Get ( " state " ) = = varsAfter - > Get ( " state " ) & &
varsBefore - > Get ( " state_type " ) = = varsAfter - > Get ( " state_type " ) & &
varsBefore - > Get ( " attempt " ) = = varsAfter - > Get ( " attempt " ) & &
varsBefore - > Get ( " reachable " ) = = varsAfter - > Get ( " reachable " ) )
2014-04-03 15:36:13 +02:00
return ; /* Nothing changed, ignore this checkresult. */
}
LogEntryType type ;
2017-12-21 12:00:42 +01:00
String output = CompatUtility : : GetCheckResultOutput ( cr ) ;
2014-04-03 15:36:13 +02:00
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
std : : ostringstream msgbuf ;
if ( service ) {
msgbuf < < " SERVICE ALERT: "
2017-12-19 15:50:05 +01:00
< < host - > GetName ( ) < < " ; "
< < service - > GetShortName ( ) < < " ; "
< < Service : : StateToString ( service - > GetState ( ) ) < < " ; "
< < Service : : StateTypeToString ( service - > GetStateType ( ) ) < < " ; "
2017-12-21 12:00:42 +01:00
< < service - > GetCheckAttempt ( ) < < " ; "
2017-12-19 15:50:05 +01:00
< < output < < " "
< < " " ;
2014-04-03 15:36:13 +02:00
switch ( service - > GetState ( ) ) {
2014-04-08 09:11:54 +02:00
case ServiceOK :
2014-04-03 15:36:13 +02:00
type = LogEntryTypeServiceOk ;
break ;
2014-04-08 09:11:54 +02:00
case ServiceUnknown :
2014-04-03 15:36:13 +02:00
type = LogEntryTypeServiceUnknown ;
break ;
2014-04-08 09:11:54 +02:00
case ServiceWarning :
2014-04-03 15:36:13 +02:00
type = LogEntryTypeServiceWarning ;
break ;
2014-04-08 09:11:54 +02:00
case ServiceCritical :
2014-04-03 15:36:13 +02:00
type = LogEntryTypeServiceCritical ;
break ;
default :
2014-10-19 17:52:17 +02:00
Log ( LogCritical , " DbEvents " )
2017-12-21 12:00:42 +01:00
< < " Unknown service state: " < < service - > GetState ( ) ;
2014-04-03 15:36:13 +02:00
return ;
}
} else {
msgbuf < < " HOST ALERT: "
2017-12-19 15:50:05 +01:00
< < host - > GetName ( ) < < " ; "
2017-12-21 09:24:04 +01:00
< < GetHostStateString ( host ) < < " ; "
2017-12-19 15:50:05 +01:00
< < Host : : StateTypeToString ( host - > GetStateType ( ) ) < < " ; "
2017-12-21 12:00:42 +01:00
< < host - > GetCheckAttempt ( ) < < " ; "
2017-12-19 15:50:05 +01:00
< < output < < " "
< < " " ;
2014-04-03 15:36:13 +02:00
switch ( host - > GetState ( ) ) {
case HostUp :
type = LogEntryTypeHostUp ;
break ;
case HostDown :
type = LogEntryTypeHostDown ;
break ;
default :
2014-10-19 17:52:17 +02:00
Log ( LogCritical , " DbEvents " )
2017-12-21 12:00:42 +01:00
< < " Unknown host state: " < < host - > GetState ( ) ;
2014-04-03 15:36:13 +02:00
return ;
}
2017-12-21 12:00:42 +01:00
if ( ! host - > IsReachable ( ) )
2014-04-08 08:54:49 +02:00
type = LogEntryTypeHostUnreachable ;
2014-04-03 15:36:13 +02:00
}
AddLogHistory ( checkable , msgbuf . str ( ) , type ) ;
}
2015-08-20 17:18:48 +02:00
void DbEvents : : AddTriggerDowntimeLogHistory ( const Downtime : : Ptr & downtime )
2014-04-03 15:36:13 +02:00
{
2015-08-20 17:18:48 +02:00
Checkable : : Ptr checkable = downtime - > GetCheckable ( ) ;
2014-04-03 15:36:13 +02:00
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
std : : ostringstream msgbuf ;
if ( service ) {
msgbuf < < " SERVICE DOWNTIME ALERT: "
< < host - > GetName ( ) < < " ; "
< < service - > GetShortName ( ) < < " ; "
< < " STARTED " < < " ; "
< < " Service has entered a period of scheduled downtime. "
< < " " ;
} else {
msgbuf < < " HOST DOWNTIME ALERT: "
< < host - > GetName ( ) < < " ; "
< < " STARTED " < < " ; "
< < " Service has entered a period of scheduled downtime. "
< < " " ;
}
AddLogHistory ( checkable , msgbuf . str ( ) , LogEntryTypeInfoMessage ) ;
}
2015-08-20 17:18:48 +02:00
void DbEvents : : AddRemoveDowntimeLogHistory ( const Downtime : : Ptr & downtime )
2014-04-03 15:36:13 +02:00
{
2015-08-20 17:18:48 +02:00
Checkable : : Ptr checkable = downtime - > GetCheckable ( ) ;
2014-04-03 15:36:13 +02:00
2017-12-21 12:00:42 +01:00
String downtimeOutput ;
String downtimeStateStr ;
2014-04-03 15:36:13 +02:00
if ( downtime - > GetWasCancelled ( ) ) {
2017-12-21 12:00:42 +01:00
downtimeOutput = " Scheduled downtime for service has been cancelled. " ;
downtimeStateStr = " CANCELLED " ;
2014-04-03 15:36:13 +02:00
} else {
2017-12-21 12:00:42 +01:00
downtimeOutput = " Service has exited from a period of scheduled downtime. " ;
downtimeStateStr = " STOPPED " ;
2014-04-03 15:36:13 +02:00
}
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
std : : ostringstream msgbuf ;
if ( service ) {
msgbuf < < " SERVICE DOWNTIME ALERT: "
< < host - > GetName ( ) < < " ; "
< < service - > GetShortName ( ) < < " ; "
2017-12-21 12:00:42 +01:00
< < downtimeStateStr < < " ; "
< < downtimeOutput
2014-04-03 15:36:13 +02:00
< < " " ;
} else {
msgbuf < < " HOST DOWNTIME ALERT: "
< < host - > GetName ( ) < < " ; "
2017-12-21 12:00:42 +01:00
< < downtimeStateStr < < " ; "
< < downtimeOutput
2014-04-03 15:36:13 +02:00
< < " " ;
}
2014-04-06 18:17:52 +02:00
AddLogHistory ( checkable , msgbuf . str ( ) , LogEntryTypeInfoMessage ) ;
2014-04-03 15:36:13 +02:00
}
void DbEvents : : AddNotificationSentLogHistory ( const Notification : : Ptr & notification , const Checkable : : Ptr & checkable , const User : : Ptr & user ,
2020-01-07 14:20:59 +01:00
NotificationType notification_type , const CheckResult : : Ptr & cr ,
2017-12-19 15:50:05 +01:00
const String & author , const String & comment_text )
2014-04-03 15:36:13 +02:00
{
CheckCommand : : Ptr commandObj = checkable - > GetCheckCommand ( ) ;
2017-12-21 12:00:42 +01:00
String checkCommandName ;
2014-04-03 15:36:13 +02:00
if ( commandObj )
2017-12-21 12:00:42 +01:00
checkCommandName = commandObj - > GetName ( ) ;
2014-04-03 15:36:13 +02:00
2019-07-02 16:33:11 +02:00
String notificationTypeStr = Notification : : NotificationTypeToStringCompat ( notification_type ) ; //TODO: Change that to our own types.
2014-04-03 15:36:13 +02:00
String author_comment = " " ;
if ( notification_type = = NotificationCustom | | notification_type = = NotificationAcknowledgement ) {
author_comment = " ; " + author + " ; " + comment_text ;
}
if ( ! cr )
return ;
2017-12-21 12:00:42 +01:00
String output = CompatUtility : : GetCheckResultOutput ( cr ) ;
2014-04-03 15:36:13 +02:00
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
std : : ostringstream msgbuf ;
if ( service ) {
msgbuf < < " SERVICE NOTIFICATION: "
2017-12-19 15:50:05 +01:00
< < user - > GetName ( ) < < " ; "
< < host - > GetName ( ) < < " ; "
< < service - > GetShortName ( ) < < " ; "
2017-12-21 12:00:42 +01:00
< < notificationTypeStr < < " "
2017-12-19 15:50:05 +01:00
< < " ( " < < Service : : StateToString ( service - > GetState ( ) ) < < " ); "
2017-12-21 12:00:42 +01:00
< < checkCommandName < < " ; "
2017-12-19 15:50:05 +01:00
< < output < < author_comment
< < " " ;
2014-04-03 15:36:13 +02:00
} else {
msgbuf < < " HOST NOTIFICATION: "
2017-12-19 15:50:05 +01:00
< < user - > GetName ( ) < < " ; "
< < host - > GetName ( ) < < " ; "
2017-12-21 12:00:42 +01:00
< < notificationTypeStr < < " "
2017-12-19 15:50:05 +01:00
< < " ( " < < Host : : StateToString ( host - > GetState ( ) ) < < " ); "
2017-12-21 12:00:42 +01:00
< < checkCommandName < < " ; "
2017-12-19 15:50:05 +01:00
< < output < < author_comment
< < " " ;
2014-04-03 15:36:13 +02:00
}
2014-04-06 18:17:52 +02:00
AddLogHistory ( checkable , msgbuf . str ( ) , LogEntryTypeHostNotification ) ;
2014-04-03 15:36:13 +02:00
}
2015-08-04 14:47:44 +02:00
void DbEvents : : AddFlappingChangedLogHistory ( const Checkable : : Ptr & checkable )
2014-04-03 15:36:13 +02:00
{
2017-12-21 12:00:42 +01:00
String flappingStateStr ;
String flappingOutput ;
2017-12-13 12:54:14 +01:00
2015-08-04 14:47:44 +02:00
if ( checkable - > IsFlapping ( ) ) {
2017-12-21 12:00:42 +01:00
flappingOutput = " Service appears to have started flapping ( " + Convert : : ToString ( checkable - > GetFlappingCurrent ( ) ) + " % change >= " + Convert : : ToString ( checkable - > GetFlappingThresholdHigh ( ) ) + " % threshold) " ;
flappingStateStr = " STARTED " ;
2015-08-04 14:47:44 +02:00
} else {
2017-12-21 12:00:42 +01:00
flappingOutput = " Service appears to have stopped flapping ( " + Convert : : ToString ( checkable - > GetFlappingCurrent ( ) ) + " % change < " + Convert : : ToString ( checkable - > GetFlappingThresholdLow ( ) ) + " % threshold) " ;
flappingStateStr = " STOPPED " ;
2015-08-04 14:47:44 +02:00
}
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
std : : ostringstream msgbuf ;
2014-04-03 15:36:13 +02:00
2015-08-04 14:47:44 +02:00
if ( service ) {
msgbuf < < " SERVICE FLAPPING ALERT: "
2017-12-19 15:50:05 +01:00
< < host - > GetName ( ) < < " ; "
< < service - > GetShortName ( ) < < " ; "
2017-12-21 12:00:42 +01:00
< < flappingStateStr < < " ; "
< < flappingOutput
2017-12-19 15:50:05 +01:00
< < " " ;
2015-08-04 14:47:44 +02:00
} else {
msgbuf < < " HOST FLAPPING ALERT: "
2017-12-19 15:50:05 +01:00
< < host - > GetName ( ) < < " ; "
2017-12-21 12:00:42 +01:00
< < flappingStateStr < < " ; "
< < flappingOutput
2017-12-19 15:50:05 +01:00
< < " " ;
2014-04-03 15:36:13 +02:00
}
2015-08-04 14:47:44 +02:00
AddLogHistory ( checkable , msgbuf . str ( ) , LogEntryTypeInfoMessage ) ;
}
void DbEvents : : AddEnableFlappingChangedLogHistory ( const Checkable : : Ptr & checkable )
{
if ( ! checkable - > GetEnableFlapping ( ) )
return ;
2017-12-13 12:54:14 +01:00
2017-12-21 12:00:42 +01:00
String flappingOutput = " Flap detection has been disabled " ;
String flappingStateStr = " DISABLED " ;
2015-08-04 14:47:44 +02:00
2014-04-03 15:36:13 +02:00
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
std : : ostringstream msgbuf ;
if ( service ) {
2014-08-17 17:57:20 +02:00
msgbuf < < " SERVICE FLAPPING ALERT: "
2017-12-19 15:50:05 +01:00
< < host - > GetName ( ) < < " ; "
< < service - > GetShortName ( ) < < " ; "
2017-12-21 12:00:42 +01:00
< < flappingStateStr < < " ; "
< < flappingOutput
2017-12-19 15:50:05 +01:00
< < " " ;
2014-04-03 15:36:13 +02:00
} else {
2014-08-17 17:57:20 +02:00
msgbuf < < " HOST FLAPPING ALERT: "
2017-12-19 15:50:05 +01:00
< < host - > GetName ( ) < < " ; "
2017-12-21 12:00:42 +01:00
< < flappingStateStr < < " ; "
< < flappingOutput
2017-12-19 15:50:05 +01:00
< < " " ;
2014-04-03 15:36:13 +02:00
}
2014-04-06 18:17:52 +02:00
AddLogHistory ( checkable , msgbuf . str ( ) , LogEntryTypeInfoMessage ) ;
2014-04-03 15:36:13 +02:00
}
2018-01-04 08:54:18 +01:00
void DbEvents : : AddLogHistory ( const Checkable : : Ptr & checkable , const String & buffer , LogEntryType type )
2014-04-03 15:36:13 +02:00
{
2017-12-21 12:00:42 +01:00
std : : pair < unsigned long , unsigned long > timeBag = ConvertTimestamp ( Utility : : GetTime ( ) ) ;
2014-04-03 15:36:13 +02:00
DbQuery query1 ;
query1 . Table = " logentries " ;
query1 . Type = DbQueryInsert ;
query1 . Category = DbCatLog ;
2014-11-08 21:17:16 +01:00
Dictionary : : Ptr fields1 = new Dictionary ( ) ;
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " logentry_time " , DbValue : : FromTimestamp ( timeBag . first ) ) ;
fields1 - > Set ( " entry_time " , DbValue : : FromTimestamp ( timeBag . first ) ) ;
fields1 - > Set ( " entry_time_usec " , timeBag . second ) ;
fields1 - > Set ( " object_id " , checkable ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " logentry_type " , type ) ;
fields1 - > Set ( " logentry_data " , buffer ) ;
fields1 - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2017-12-21 12:00:42 +01:00
Endpoint : : Ptr endpoint = Endpoint : : GetByName ( IcingaApplication : : GetInstance ( ) - > GetNodeName ( ) ) ;
2014-04-03 15:36:13 +02:00
if ( endpoint )
fields1 - > Set ( " endpoint_object_id " , endpoint ) ;
query1 . Fields = fields1 ;
DbObject : : OnQuery ( query1 ) ;
}
/* flappinghistory */
2015-08-04 14:47:44 +02:00
void DbEvents : : AddFlappingChangedHistory ( const Checkable : : Ptr & checkable )
2014-04-03 15:36:13 +02:00
{
2017-12-21 12:00:42 +01:00
std : : pair < unsigned long , unsigned long > timeBag = ConvertTimestamp ( Utility : : GetTime ( ) ) ;
2014-04-03 15:36:13 +02:00
DbQuery query1 ;
query1 . Table = " flappinghistory " ;
query1 . Type = DbQueryInsert ;
query1 . Category = DbCatFlapping ;
2014-11-08 21:17:16 +01:00
Dictionary : : Ptr fields1 = new Dictionary ( ) ;
2014-04-03 15:36:13 +02:00
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " event_time " , DbValue : : FromTimestamp ( timeBag . first ) ) ;
fields1 - > Set ( " event_time_usec " , timeBag . second ) ;
2014-04-03 15:36:13 +02:00
2015-08-04 14:47:44 +02:00
if ( checkable - > IsFlapping ( ) )
fields1 - > Set ( " event_type " , 1000 ) ;
else {
fields1 - > Set ( " event_type " , 1001 ) ;
fields1 - > Set ( " reason_type " , 1 ) ;
2014-04-03 15:36:13 +02:00
}
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
fields1 - > Set ( " flapping_type " , service ? 1 : 0 ) ;
fields1 - > Set ( " object_id " , checkable ) ;
fields1 - > Set ( " percent_state_change " , checkable - > GetFlappingCurrent ( ) ) ;
2017-10-19 17:32:52 +02:00
fields1 - > Set ( " low_threshold " , checkable - > GetFlappingThresholdLow ( ) ) ;
fields1 - > Set ( " high_threshold " , checkable - > GetFlappingThresholdHigh ( ) ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2017-12-21 12:00:42 +01:00
Endpoint : : Ptr endpoint = Endpoint : : GetByName ( IcingaApplication : : GetInstance ( ) - > GetNodeName ( ) ) ;
2015-08-04 14:47:44 +02:00
if ( endpoint )
fields1 - > Set ( " endpoint_object_id " , endpoint ) ;
query1 . Fields = fields1 ;
DbObject : : OnQuery ( query1 ) ;
}
void DbEvents : : AddEnableFlappingChangedHistory ( const Checkable : : Ptr & checkable )
{
2017-12-21 12:00:42 +01:00
if ( ! checkable - > GetEnableFlapping ( ) )
return ;
std : : pair < unsigned long , unsigned long > timeBag = ConvertTimestamp ( Utility : : GetTime ( ) ) ;
2015-08-04 14:47:44 +02:00
DbQuery query1 ;
query1 . Table = " flappinghistory " ;
query1 . Type = DbQueryInsert ;
query1 . Category = DbCatFlapping ;
Dictionary : : Ptr fields1 = new Dictionary ( ) ;
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " event_time " , DbValue : : FromTimestamp ( timeBag . first ) ) ;
fields1 - > Set ( " event_time_usec " , timeBag . second ) ;
2017-12-13 12:54:14 +01:00
2015-08-04 14:47:44 +02:00
fields1 - > Set ( " event_type " , 1001 ) ;
fields1 - > Set ( " reason_type " , 2 ) ;
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
fields1 - > Set ( " flapping_type " , service ? 1 : 0 ) ;
fields1 - > Set ( " object_id " , checkable ) ;
fields1 - > Set ( " percent_state_change " , checkable - > GetFlappingCurrent ( ) ) ;
2017-10-19 17:32:52 +02:00
fields1 - > Set ( " low_threshold " , checkable - > GetFlappingThresholdLow ( ) ) ;
fields1 - > Set ( " high_threshold " , checkable - > GetFlappingThresholdHigh ( ) ) ;
2015-08-04 14:47:44 +02:00
fields1 - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2017-12-21 12:00:42 +01:00
Endpoint : : Ptr endpoint = Endpoint : : GetByName ( IcingaApplication : : GetInstance ( ) - > GetNodeName ( ) ) ;
2014-04-03 15:36:13 +02:00
if ( endpoint )
fields1 - > Set ( " endpoint_object_id " , endpoint ) ;
query1 . Fields = fields1 ;
DbObject : : OnQuery ( query1 ) ;
}
/* servicechecks */
2015-04-27 15:06:14 +02:00
void DbEvents : : AddCheckableCheckHistory ( const Checkable : : Ptr & checkable , const CheckResult : : Ptr & cr )
2014-04-03 15:36:13 +02:00
{
if ( ! cr )
return ;
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
DbQuery query1 ;
query1 . Table = service ? " servicechecks " : " hostchecks " ;
query1 . Type = DbQueryInsert ;
query1 . Category = DbCatCheck ;
2014-11-08 21:17:16 +01:00
Dictionary : : Ptr fields1 = new Dictionary ( ) ;
2017-12-05 11:34:38 +01:00
fields1 - > Set ( " check_type " , ! checkable - > GetEnableActiveChecks ( ) ) ; /* 0 .. active, 1 .. passive */
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " current_check_attempt " , checkable - > GetCheckAttempt ( ) ) ;
fields1 - > Set ( " max_check_attempts " , checkable - > GetMaxCheckAttempts ( ) ) ;
fields1 - > Set ( " state_type " , checkable - > GetStateType ( ) ) ;
2015-04-24 17:41:07 +02:00
double start = cr - > GetExecutionStart ( ) ;
double end = cr - > GetExecutionEnd ( ) ;
2017-12-21 12:00:42 +01:00
double executionTime = cr - > CalculateExecutionTime ( ) ;
2014-04-03 15:36:13 +02:00
2017-12-21 12:00:42 +01:00
std : : pair < unsigned long , unsigned long > timeBagStart = ConvertTimestamp ( start ) ;
std : : pair < unsigned long , unsigned long > timeBagEnd = ConvertTimestamp ( end ) ;
2015-04-24 17:41:07 +02:00
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " start_time " , DbValue : : FromTimestamp ( timeBagStart . first ) ) ;
fields1 - > Set ( " start_time_usec " , timeBagStart . second ) ;
fields1 - > Set ( " end_time " , DbValue : : FromTimestamp ( timeBagEnd . first ) ) ;
fields1 - > Set ( " end_time_usec " , timeBagEnd . second ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " command_object_id " , checkable - > GetCheckCommand ( ) ) ;
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " execution_time " , executionTime ) ;
fields1 - > Set ( " latency " , cr - > CalculateLatency ( ) ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " return_code " , cr - > GetExitStatus ( ) ) ;
2017-12-06 17:03:56 +01:00
fields1 - > Set ( " perfdata " , PluginUtility : : FormatPerfdata ( cr - > GetPerformanceData ( ) ) ) ;
2014-04-03 15:36:13 +02:00
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " output " , CompatUtility : : GetCheckResultOutput ( cr ) ) ;
fields1 - > Set ( " long_output " , CompatUtility : : GetCheckResultLongOutput ( cr ) ) ;
fields1 - > Set ( " command_line " , CompatUtility : : GetCommandLine ( checkable - > GetCheckCommand ( ) ) ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
if ( service ) {
fields1 - > Set ( " service_object_id " , service ) ;
fields1 - > Set ( " state " , service - > GetState ( ) ) ;
} else {
fields1 - > Set ( " host_object_id " , host ) ;
2017-12-21 09:12:12 +01:00
fields1 - > Set ( " state " , GetHostState ( host ) ) ;
2014-04-03 15:36:13 +02:00
}
2017-12-21 12:00:42 +01:00
Endpoint : : Ptr endpoint = Endpoint : : GetByName ( IcingaApplication : : GetInstance ( ) - > GetNodeName ( ) ) ;
2014-04-03 15:36:13 +02:00
if ( endpoint )
fields1 - > Set ( " endpoint_object_id " , endpoint ) ;
query1 . Fields = fields1 ;
DbObject : : OnQuery ( query1 ) ;
}
/* eventhandlers */
void DbEvents : : AddEventHandlerHistory ( const Checkable : : Ptr & checkable )
{
DbQuery query1 ;
query1 . Table = " eventhandlers " ;
query1 . Type = DbQueryInsert ;
query1 . Category = DbCatEventHandler ;
2014-11-08 21:17:16 +01:00
Dictionary : : Ptr fields1 = new Dictionary ( ) ;
2014-04-03 15:36:13 +02:00
Host : : Ptr host ;
Service : : Ptr service ;
tie ( host , service ) = GetHostService ( checkable ) ;
fields1 - > Set ( " object_id " , checkable ) ;
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " state_type " , checkable - > GetStateType ( ) ) ;
fields1 - > Set ( " command_object_id " , checkable - > GetEventCommand ( ) ) ;
fields1 - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2017-08-07 10:58:52 +02:00
if ( service ) {
fields1 - > Set ( " state " , service - > GetState ( ) ) ;
fields1 - > Set ( " eventhandler_type " , 1 ) ;
} else {
2017-12-21 09:12:12 +01:00
fields1 - > Set ( " state " , GetHostState ( host ) ) ;
2017-08-07 10:58:52 +02:00
fields1 - > Set ( " eventhandler_type " , 0 ) ;
}
2017-12-21 12:00:42 +01:00
std : : pair < unsigned long , unsigned long > timeBag = ConvertTimestamp ( Utility : : GetTime ( ) ) ;
2014-04-03 15:36:13 +02:00
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " start_time " , DbValue : : FromTimestamp ( timeBag . first ) ) ;
fields1 - > Set ( " start_time_usec " , timeBag . second ) ;
fields1 - > Set ( " end_time " , DbValue : : FromTimestamp ( timeBag . first ) ) ;
fields1 - > Set ( " end_time_usec " , timeBag . second ) ;
2014-04-03 15:36:13 +02:00
2017-12-21 12:00:42 +01:00
Endpoint : : Ptr endpoint = Endpoint : : GetByName ( IcingaApplication : : GetInstance ( ) - > GetNodeName ( ) ) ;
2014-04-03 15:36:13 +02:00
if ( endpoint )
fields1 - > Set ( " endpoint_object_id " , endpoint ) ;
query1 . Fields = fields1 ;
DbObject : : OnQuery ( query1 ) ;
}
/* externalcommands */
void DbEvents : : AddExternalCommandHistory ( double time , const String & command , const std : : vector < String > & arguments )
{
DbQuery query1 ;
query1 . Table = " externalcommands " ;
query1 . Type = DbQueryInsert ;
query1 . Category = DbCatExternalCommand ;
2014-11-08 21:17:16 +01:00
Dictionary : : Ptr fields1 = new Dictionary ( ) ;
2014-04-03 15:36:13 +02:00
2017-12-21 12:00:42 +01:00
fields1 - > Set ( " entry_time " , DbValue : : FromTimestamp ( time ) ) ;
2017-12-06 16:39:22 +01:00
fields1 - > Set ( " command_type " , MapExternalCommandType ( command ) ) ;
2014-04-03 15:36:13 +02:00
fields1 - > Set ( " command_name " , command ) ;
fields1 - > Set ( " command_args " , boost : : algorithm : : join ( arguments , " ; " ) ) ;
fields1 - > Set ( " instance_id " , 0 ) ; /* DbConnection class fills in real ID */
2017-12-21 12:00:42 +01:00
Endpoint : : Ptr endpoint = Endpoint : : GetByName ( IcingaApplication : : GetInstance ( ) - > GetNodeName ( ) ) ;
2014-04-03 15:36:13 +02:00
if ( endpoint )
fields1 - > Set ( " endpoint_object_id " , endpoint ) ;
query1 . Fields = fields1 ;
DbObject : : OnQuery ( query1 ) ;
}
2017-12-06 16:18:26 +01:00
2017-12-21 09:12:12 +01:00
int DbEvents : : GetHostState ( const Host : : Ptr & host )
{
int currentState = host - > GetState ( ) ;
if ( currentState ! = HostUp & & ! host - > IsReachable ( ) )
currentState = 2 ; /* hardcoded compat state */
return currentState ;
}
2017-12-21 09:24:04 +01:00
String DbEvents : : GetHostStateString ( const Host : : Ptr & host )
{
if ( host - > GetState ( ) ! = HostUp & & ! host - > IsReachable ( ) )
return " UNREACHABLE " ; /* hardcoded compat state */
return Host : : StateToString ( host - > GetState ( ) ) ;
}
2017-12-06 16:18:26 +01:00
std : : pair < unsigned long , unsigned long > DbEvents : : ConvertTimestamp ( double time )
{
unsigned long time_sec = static_cast < long > ( time ) ;
unsigned long time_usec = ( time - time_sec ) * 1000 * 1000 ;
return std : : make_pair ( time_sec , time_usec ) ;
}
2017-12-06 16:39:22 +01:00
int DbEvents : : MapNotificationReasonType ( NotificationType type )
{
switch ( type ) {
case NotificationDowntimeStart :
return 5 ;
case NotificationDowntimeEnd :
return 6 ;
case NotificationDowntimeRemoved :
return 7 ;
case NotificationCustom :
return 8 ;
case NotificationAcknowledgement :
return 1 ;
case NotificationProblem :
return 0 ;
case NotificationRecovery :
return 0 ;
case NotificationFlappingStart :
return 2 ;
case NotificationFlappingEnd :
return 3 ;
default :
return 0 ;
}
}
int DbEvents : : MapExternalCommandType ( const String & name )
{
if ( name = = " NONE " )
return 0 ;
if ( name = = " ADD_HOST_COMMENT " )
return 1 ;
if ( name = = " DEL_HOST_COMMENT " )
return 2 ;
if ( name = = " ADD_SVC_COMMENT " )
return 3 ;
if ( name = = " DEL_SVC_COMMENT " )
return 4 ;
if ( name = = " ENABLE_SVC_CHECK " )
return 5 ;
if ( name = = " DISABLE_SVC_CHECK " )
return 6 ;
if ( name = = " SCHEDULE_SVC_CHECK " )
return 7 ;
if ( name = = " DELAY_SVC_NOTIFICATION " )
return 9 ;
if ( name = = " DELAY_HOST_NOTIFICATION " )
return 10 ;
if ( name = = " DISABLE_NOTIFICATIONS " )
return 11 ;
if ( name = = " ENABLE_NOTIFICATIONS " )
return 12 ;
if ( name = = " RESTART_PROCESS " )
return 13 ;
if ( name = = " SHUTDOWN_PROCESS " )
return 14 ;
if ( name = = " ENABLE_HOST_SVC_CHECKS " )
return 15 ;
if ( name = = " DISABLE_HOST_SVC_CHECKS " )
return 16 ;
if ( name = = " SCHEDULE_HOST_SVC_CHECKS " )
return 17 ;
if ( name = = " DELAY_HOST_SVC_NOTIFICATIONS " )
return 19 ;
if ( name = = " DEL_ALL_HOST_COMMENTS " )
return 20 ;
if ( name = = " DEL_ALL_SVC_COMMENTS " )
return 21 ;
if ( name = = " ENABLE_SVC_NOTIFICATIONS " )
return 22 ;
if ( name = = " DISABLE_SVC_NOTIFICATIONS " )
return 23 ;
if ( name = = " ENABLE_HOST_NOTIFICATIONS " )
return 24 ;
if ( name = = " DISABLE_HOST_NOTIFICATIONS " )
return 25 ;
if ( name = = " ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST " )
return 26 ;
if ( name = = " DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST " )
return 27 ;
if ( name = = " ENABLE_HOST_SVC_NOTIFICATIONS " )
return 28 ;
if ( name = = " DISABLE_HOST_SVC_NOTIFICATIONS " )
return 29 ;
if ( name = = " PROCESS_SERVICE_CHECK_RESULT " )
return 30 ;
if ( name = = " SAVE_STATE_INFORMATION " )
return 31 ;
if ( name = = " READ_STATE_INFORMATION " )
return 32 ;
if ( name = = " ACKNOWLEDGE_HOST_PROBLEM " )
return 33 ;
if ( name = = " ACKNOWLEDGE_SVC_PROBLEM " )
return 34 ;
if ( name = = " START_EXECUTING_SVC_CHECKS " )
return 35 ;
if ( name = = " STOP_EXECUTING_SVC_CHECKS " )
return 36 ;
if ( name = = " START_ACCEPTING_PASSIVE_SVC_CHECKS " )
return 37 ;
if ( name = = " STOP_ACCEPTING_PASSIVE_SVC_CHECKS " )
return 38 ;
if ( name = = " ENABLE_PASSIVE_SVC_CHECKS " )
return 39 ;
if ( name = = " DISABLE_PASSIVE_SVC_CHECKS " )
return 40 ;
if ( name = = " ENABLE_EVENT_HANDLERS " )
return 41 ;
if ( name = = " DISABLE_EVENT_HANDLERS " )
return 42 ;
if ( name = = " ENABLE_HOST_EVENT_HANDLER " )
return 43 ;
if ( name = = " DISABLE_HOST_EVENT_HANDLER " )
return 44 ;
if ( name = = " ENABLE_SVC_EVENT_HANDLER " )
return 45 ;
if ( name = = " DISABLE_SVC_EVENT_HANDLER " )
return 46 ;
if ( name = = " ENABLE_HOST_CHECK " )
return 47 ;
if ( name = = " DISABLE_HOST_CHECK " )
return 48 ;
if ( name = = " START_OBSESSING_OVER_SVC_CHECKS " )
return 49 ;
if ( name = = " STOP_OBSESSING_OVER_SVC_CHECKS " )
return 50 ;
if ( name = = " REMOVE_HOST_ACKNOWLEDGEMENT " )
return 51 ;
if ( name = = " REMOVE_SVC_ACKNOWLEDGEMENT " )
return 52 ;
if ( name = = " SCHEDULE_FORCED_HOST_SVC_CHECKS " )
return 53 ;
if ( name = = " SCHEDULE_FORCED_SVC_CHECK " )
return 54 ;
if ( name = = " SCHEDULE_HOST_DOWNTIME " )
return 55 ;
if ( name = = " SCHEDULE_SVC_DOWNTIME " )
return 56 ;
if ( name = = " ENABLE_HOST_FLAP_DETECTION " )
return 57 ;
if ( name = = " DISABLE_HOST_FLAP_DETECTION " )
return 58 ;
if ( name = = " ENABLE_SVC_FLAP_DETECTION " )
return 59 ;
if ( name = = " DISABLE_SVC_FLAP_DETECTION " )
return 60 ;
if ( name = = " ENABLE_FLAP_DETECTION " )
return 61 ;
if ( name = = " DISABLE_FLAP_DETECTION " )
return 62 ;
if ( name = = " ENABLE_HOSTGROUP_SVC_NOTIFICATIONS " )
return 63 ;
if ( name = = " DISABLE_HOSTGROUP_SVC_NOTIFICATIONS " )
return 64 ;
if ( name = = " ENABLE_HOSTGROUP_HOST_NOTIFICATIONS " )
return 65 ;
if ( name = = " DISABLE_HOSTGROUP_HOST_NOTIFICATIONS " )
return 66 ;
if ( name = = " ENABLE_HOSTGROUP_SVC_CHECKS " )
return 67 ;
if ( name = = " DISABLE_HOSTGROUP_SVC_CHECKS " )
return 68 ;
if ( name = = " CANCEL_HOST_DOWNTIME " )
return 69 ;
if ( name = = " CANCEL_SVC_DOWNTIME " )
return 70 ;
if ( name = = " CANCEL_ACTIVE_HOST_DOWNTIME " )
return 71 ;
if ( name = = " CANCEL_PENDING_HOST_DOWNTIME " )
return 72 ;
if ( name = = " CANCEL_ACTIVE_SVC_DOWNTIME " )
return 73 ;
if ( name = = " CANCEL_PENDING_SVC_DOWNTIME " )
return 74 ;
if ( name = = " CANCEL_ACTIVE_HOST_SVC_DOWNTIME " )
return 75 ;
if ( name = = " CANCEL_PENDING_HOST_SVC_DOWNTIME " )
return 76 ;
if ( name = = " FLUSH_PENDING_COMMANDS " )
return 77 ;
if ( name = = " DEL_HOST_DOWNTIME " )
return 78 ;
if ( name = = " DEL_SVC_DOWNTIME " )
return 79 ;
if ( name = = " ENABLE_FAILURE_PREDICTION " )
return 80 ;
if ( name = = " DISABLE_FAILURE_PREDICTION " )
return 81 ;
if ( name = = " ENABLE_PERFORMANCE_DATA " )
return 82 ;
if ( name = = " DISABLE_PERFORMANCE_DATA " )
return 83 ;
if ( name = = " SCHEDULE_HOSTGROUP_HOST_DOWNTIME " )
return 84 ;
if ( name = = " SCHEDULE_HOSTGROUP_SVC_DOWNTIME " )
return 85 ;
if ( name = = " SCHEDULE_HOST_SVC_DOWNTIME " )
return 86 ;
if ( name = = " PROCESS_HOST_CHECK_RESULT " )
return 87 ;
if ( name = = " START_EXECUTING_HOST_CHECKS " )
return 88 ;
if ( name = = " STOP_EXECUTING_HOST_CHECKS " )
return 89 ;
if ( name = = " START_ACCEPTING_PASSIVE_HOST_CHECKS " )
return 90 ;
if ( name = = " STOP_ACCEPTING_PASSIVE_HOST_CHECKS " )
return 91 ;
if ( name = = " ENABLE_PASSIVE_HOST_CHECKS " )
return 92 ;
if ( name = = " DISABLE_PASSIVE_HOST_CHECKS " )
return 93 ;
if ( name = = " START_OBSESSING_OVER_HOST_CHECKS " )
return 94 ;
if ( name = = " STOP_OBSESSING_OVER_HOST_CHECKS " )
return 95 ;
if ( name = = " SCHEDULE_HOST_CHECK " )
return 96 ;
if ( name = = " SCHEDULE_FORCED_HOST_CHECK " )
return 98 ;
if ( name = = " START_OBSESSING_OVER_SVC " )
return 99 ;
if ( name = = " STOP_OBSESSING_OVER_SVC " )
return 100 ;
if ( name = = " START_OBSESSING_OVER_HOST " )
return 101 ;
if ( name = = " STOP_OBSESSING_OVER_HOST " )
return 102 ;
if ( name = = " ENABLE_HOSTGROUP_HOST_CHECKS " )
return 103 ;
if ( name = = " DISABLE_HOSTGROUP_HOST_CHECKS " )
return 104 ;
if ( name = = " ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS " )
return 105 ;
if ( name = = " DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS " )
return 106 ;
if ( name = = " ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS " )
return 107 ;
if ( name = = " DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS " )
return 108 ;
if ( name = = " ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS " )
return 109 ;
if ( name = = " DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS " )
return 110 ;
if ( name = = " ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS " )
return 111 ;
if ( name = = " DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS " )
return 112 ;
if ( name = = " ENABLE_SERVICEGROUP_SVC_CHECKS " )
return 113 ;
if ( name = = " DISABLE_SERVICEGROUP_SVC_CHECKS " )
return 114 ;
if ( name = = " ENABLE_SERVICEGROUP_HOST_CHECKS " )
return 115 ;
if ( name = = " DISABLE_SERVICEGROUP_HOST_CHECKS " )
return 116 ;
if ( name = = " ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS " )
return 117 ;
if ( name = = " DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS " )
return 118 ;
if ( name = = " ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS " )
return 119 ;
if ( name = = " DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS " )
return 120 ;
if ( name = = " SCHEDULE_SERVICEGROUP_HOST_DOWNTIME " )
return 121 ;
if ( name = = " SCHEDULE_SERVICEGROUP_SVC_DOWNTIME " )
return 122 ;
if ( name = = " CHANGE_GLOBAL_HOST_EVENT_HANDLER " )
return 123 ;
if ( name = = " CHANGE_GLOBAL_SVC_EVENT_HANDLER " )
return 124 ;
if ( name = = " CHANGE_HOST_EVENT_HANDLER " )
return 125 ;
if ( name = = " CHANGE_SVC_EVENT_HANDLER " )
return 126 ;
if ( name = = " CHANGE_HOST_CHECK_COMMAND " )
return 127 ;
if ( name = = " CHANGE_SVC_CHECK_COMMAND " )
return 128 ;
if ( name = = " CHANGE_NORMAL_HOST_CHECK_INTERVAL " )
return 129 ;
if ( name = = " CHANGE_NORMAL_SVC_CHECK_INTERVAL " )
return 130 ;
if ( name = = " CHANGE_RETRY_SVC_CHECK_INTERVAL " )
return 131 ;
if ( name = = " CHANGE_MAX_HOST_CHECK_ATTEMPTS " )
return 132 ;
if ( name = = " CHANGE_MAX_SVC_CHECK_ATTEMPTS " )
return 133 ;
if ( name = = " SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME " )
return 134 ;
if ( name = = " ENABLE_HOST_AND_CHILD_NOTIFICATIONS " )
return 135 ;
if ( name = = " DISABLE_HOST_AND_CHILD_NOTIFICATIONS " )
return 136 ;
if ( name = = " SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME " )
return 137 ;
if ( name = = " ENABLE_SERVICE_FRESHNESS_CHECKS " )
return 138 ;
if ( name = = " DISABLE_SERVICE_FRESHNESS_CHECKS " )
return 139 ;
if ( name = = " ENABLE_HOST_FRESHNESS_CHECKS " )
return 140 ;
if ( name = = " DISABLE_HOST_FRESHNESS_CHECKS " )
return 141 ;
if ( name = = " SET_HOST_NOTIFICATION_NUMBER " )
return 142 ;
if ( name = = " SET_SVC_NOTIFICATION_NUMBER " )
return 143 ;
if ( name = = " CHANGE_HOST_CHECK_TIMEPERIOD " )
return 144 ;
if ( name = = " CHANGE_SVC_CHECK_TIMEPERIOD " )
return 145 ;
if ( name = = " PROCESS_FILE " )
return 146 ;
if ( name = = " CHANGE_CUSTOM_HOST_VAR " )
return 147 ;
if ( name = = " CHANGE_CUSTOM_SVC_VAR " )
return 148 ;
if ( name = = " CHANGE_CUSTOM_CONTACT_VAR " )
return 149 ;
if ( name = = " ENABLE_CONTACT_HOST_NOTIFICATIONS " )
return 150 ;
if ( name = = " DISABLE_CONTACT_HOST_NOTIFICATIONS " )
return 151 ;
if ( name = = " ENABLE_CONTACT_SVC_NOTIFICATIONS " )
return 152 ;
if ( name = = " DISABLE_CONTACT_SVC_NOTIFICATIONS " )
return 153 ;
if ( name = = " ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS " )
return 154 ;
if ( name = = " DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS " )
return 155 ;
if ( name = = " ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS " )
return 156 ;
if ( name = = " DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS " )
return 157 ;
if ( name = = " CHANGE_RETRY_HOST_CHECK_INTERVAL " )
return 158 ;
if ( name = = " SEND_CUSTOM_HOST_NOTIFICATION " )
return 159 ;
if ( name = = " SEND_CUSTOM_SVC_NOTIFICATION " )
return 160 ;
if ( name = = " CHANGE_HOST_NOTIFICATION_TIMEPERIOD " )
return 161 ;
if ( name = = " CHANGE_SVC_NOTIFICATION_TIMEPERIOD " )
return 162 ;
if ( name = = " CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD " )
return 163 ;
if ( name = = " CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD " )
return 164 ;
if ( name = = " CHANGE_HOST_MODATTR " )
return 165 ;
if ( name = = " CHANGE_SVC_MODATTR " )
return 166 ;
if ( name = = " CHANGE_CONTACT_MODATTR " )
return 167 ;
if ( name = = " CHANGE_CONTACT_MODHATTR " )
return 168 ;
if ( name = = " CHANGE_CONTACT_MODSATTR " )
return 169 ;
if ( name = = " SYNC_STATE_INFORMATION " )
return 170 ;
if ( name = = " DEL_DOWNTIME_BY_HOST_NAME " )
return 171 ;
if ( name = = " DEL_DOWNTIME_BY_HOSTGROUP_NAME " )
return 172 ;
if ( name = = " DEL_DOWNTIME_BY_START_TIME_COMMENT " )
return 173 ;
if ( name = = " ACKNOWLEDGE_HOST_PROBLEM_EXPIRE " )
return 174 ;
if ( name = = " ACKNOWLEDGE_SVC_PROBLEM_EXPIRE " )
return 175 ;
if ( name = = " DISABLE_NOTIFICATIONS_EXPIRE_TIME " )
return 176 ;
if ( name = = " CUSTOM_COMMAND " )
return 999 ;
return 0 ;
}