2013-01-22 08:34:29 +01:00
/******************************************************************************
* Icinga 2 *
2013-09-25 07:43:57 +02:00
* Copyright ( C ) 2012 - 2013 Icinga Development Team ( http : //www.icinga.org/) *
2013-01-22 08:34:29 +01:00
* *
* This program is free software ; you can redistribute it and / or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation ; either version 2 *
* of the License , or ( at your option ) any later version . *
* *
* This program is distributed in the hope that it will be useful , *
* but WITHOUT ANY WARRANTY ; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the *
* GNU General Public License for more details . *
* *
* You should have received a copy of the GNU General Public License *
* along with this program ; if not , write to the Free Software Foundation *
* Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 , USA . *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2013-03-17 20:19:29 +01:00
# include "icinga/externalcommandprocessor.h"
# include "icinga/host.h"
# include "icinga/service.h"
# include "icinga/user.h"
# include "icinga/hostgroup.h"
# include "icinga/servicegroup.h"
2013-11-04 14:41:24 +01:00
# include "icinga/pluginutility.h"
2013-10-08 11:57:35 +02:00
# include "icinga/icingaapplication.h"
2013-03-16 21:18:53 +01:00
# include "base/convert.h"
# include "base/logger_fwd.h"
# include "base/objectlock.h"
2013-03-17 20:19:29 +01:00
# include "base/application.h"
2013-03-25 18:36:15 +01:00
# include "base/utility.h"
2013-03-17 20:19:29 +01:00
# include <fstream>
2013-03-15 18:21:29 +01:00
# include <boost/algorithm/string/classification.hpp>
2013-03-16 21:18:53 +01:00
# include <boost/foreach.hpp>
# include <boost/exception/diagnostic_information.hpp>
2013-03-18 11:02:18 +01:00
# include <boost/algorithm/string/split.hpp>
2013-01-22 08:34:29 +01:00
using namespace icinga ;
2013-02-22 08:12:43 +01:00
boost : : once_flag ExternalCommandProcessor : : m_InitializeOnce = BOOST_ONCE_INIT ;
2013-02-17 19:14:34 +01:00
boost : : mutex ExternalCommandProcessor : : m_Mutex ;
2013-03-16 21:18:53 +01:00
std : : map < String , ExternalCommandProcessor : : Callback > ExternalCommandProcessor : : m_Commands ;
2013-01-22 08:34:29 +01:00
2013-09-30 19:32:32 +02:00
boost : : signals2 : : signal < void ( double , const String & , const std : : vector < String > & ) > ExternalCommandProcessor : : OnNewExternalCommand ;
2013-01-29 15:00:39 +01:00
void ExternalCommandProcessor : : Execute ( const String & line )
2013-01-24 23:42:02 +01:00
{
if ( line . IsEmpty ( ) )
return ;
if ( line [ 0 ] ! = ' [ ' )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Missing timestamp in command: " + line ) ) ;
2013-01-24 23:42:02 +01:00
size_t pos = line . FindFirstOf ( " ] " ) ;
if ( pos = = String : : NPos )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Missing timestamp in command: " + line ) ) ;
2013-01-24 23:42:02 +01:00
String timestamp = line . SubStr ( 1 , pos - 1 ) ;
String args = line . SubStr ( pos + 2 , String : : NPos ) ;
2013-01-29 12:05:46 +01:00
double ts = Convert : : ToDouble ( timestamp ) ;
2013-01-24 23:42:02 +01:00
if ( ts = = 0 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Invalid timestamp in command: " + line ) ) ;
2013-01-24 23:42:02 +01:00
2013-03-18 11:02:18 +01:00
std : : vector < String > argv ;
boost : : algorithm : : split ( argv , args , boost : : is_any_of ( " ; " ) ) ;
2013-01-24 23:42:02 +01:00
2013-03-06 15:41:13 +01:00
if ( argv . empty ( ) )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Missing arguments in command: " + line ) ) ;
2013-01-24 23:42:02 +01:00
2013-03-16 21:18:53 +01:00
std : : vector < String > argvExtra ( argv . begin ( ) + 1 , argv . end ( ) ) ;
2013-01-24 23:42:02 +01:00
Execute ( ts , argv [ 0 ] , argvExtra ) ;
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : Execute ( double time , const String & command , const std : : vector < String > & arguments )
2013-01-22 08:34:29 +01:00
{
2013-02-17 19:14:34 +01:00
boost : : call_once ( m_InitializeOnce , & ExternalCommandProcessor : : Initialize ) ;
Callback callback ;
{
boost : : mutex : : scoped_lock lock ( m_Mutex ) ;
2013-03-16 21:18:53 +01:00
std : : map < String , ExternalCommandProcessor : : Callback > : : iterator it ;
2013-02-17 19:14:34 +01:00
it = m_Commands . find ( command ) ;
if ( it = = m_Commands . end ( ) )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " The external command ' " + command + " ' does not exist. " ) ) ;
2013-02-17 19:14:34 +01:00
callback = it - > second ;
2013-01-22 08:34:29 +01:00
}
2013-09-30 19:32:32 +02:00
OnNewExternalCommand ( time , command , arguments ) ;
2013-02-18 14:40:24 +01:00
callback ( time , arguments ) ;
2013-02-17 19:14:34 +01:00
}
2013-01-22 08:34:29 +01:00
2013-02-17 19:14:34 +01:00
void ExternalCommandProcessor : : Initialize ( void )
{
2013-03-06 11:03:50 +01:00
RegisterCommand ( " PROCESS_HOST_CHECK_RESULT " , & ExternalCommandProcessor : : ProcessHostCheckResult ) ;
2013-02-17 19:14:34 +01:00
RegisterCommand ( " PROCESS_SERVICE_CHECK_RESULT " , & ExternalCommandProcessor : : ProcessServiceCheckResult ) ;
2013-02-26 11:18:03 +01:00
RegisterCommand ( " SCHEDULE_HOST_CHECK " , & ExternalCommandProcessor : : ScheduleHostCheck ) ;
RegisterCommand ( " SCHEDULE_FORCED_HOST_CHECK " , & ExternalCommandProcessor : : ScheduleForcedHostCheck ) ;
2013-02-17 19:14:34 +01:00
RegisterCommand ( " SCHEDULE_SVC_CHECK " , & ExternalCommandProcessor : : ScheduleSvcCheck ) ;
RegisterCommand ( " SCHEDULE_FORCED_SVC_CHECK " , & ExternalCommandProcessor : : ScheduleForcedSvcCheck ) ;
2013-02-26 11:18:03 +01:00
RegisterCommand ( " ENABLE_HOST_CHECK " , & ExternalCommandProcessor : : EnableHostCheck ) ;
RegisterCommand ( " DISABLE_HOST_CHECK " , & ExternalCommandProcessor : : DisableHostCheck ) ;
2013-02-17 19:14:34 +01:00
RegisterCommand ( " ENABLE_SVC_CHECK " , & ExternalCommandProcessor : : EnableSvcCheck ) ;
RegisterCommand ( " DISABLE_SVC_CHECK " , & ExternalCommandProcessor : : DisableSvcCheck ) ;
RegisterCommand ( " SHUTDOWN_PROCESS " , & ExternalCommandProcessor : : ShutdownProcess ) ;
2013-08-30 14:27:24 +02:00
RegisterCommand ( " RESTART_PROCESS " , & ExternalCommandProcessor : : RestartProcess ) ;
2013-02-17 19:14:34 +01:00
RegisterCommand ( " SCHEDULE_FORCED_HOST_SVC_CHECKS " , & ExternalCommandProcessor : : ScheduleForcedHostSvcChecks ) ;
RegisterCommand ( " SCHEDULE_HOST_SVC_CHECKS " , & ExternalCommandProcessor : : ScheduleHostSvcChecks ) ;
RegisterCommand ( " ENABLE_HOST_SVC_CHECKS " , & ExternalCommandProcessor : : EnableHostSvcChecks ) ;
RegisterCommand ( " DISABLE_HOST_SVC_CHECKS " , & ExternalCommandProcessor : : DisableHostSvcChecks ) ;
RegisterCommand ( " ACKNOWLEDGE_SVC_PROBLEM " , & ExternalCommandProcessor : : AcknowledgeSvcProblem ) ;
RegisterCommand ( " ACKNOWLEDGE_SVC_PROBLEM_EXPIRE " , & ExternalCommandProcessor : : AcknowledgeSvcProblemExpire ) ;
2013-03-12 22:00:35 +01:00
RegisterCommand ( " REMOVE_SVC_ACKNOWLEDGEMENT " , & ExternalCommandProcessor : : RemoveSvcAcknowledgement ) ;
2013-02-17 19:14:34 +01:00
RegisterCommand ( " ACKNOWLEDGE_HOST_PROBLEM " , & ExternalCommandProcessor : : AcknowledgeHostProblem ) ;
RegisterCommand ( " ACKNOWLEDGE_HOST_PROBLEM_EXPIRE " , & ExternalCommandProcessor : : AcknowledgeHostProblemExpire ) ;
RegisterCommand ( " REMOVE_HOST_ACKNOWLEDGEMENT " , & ExternalCommandProcessor : : RemoveHostAcknowledgement ) ;
2013-07-01 17:25:30 +02:00
RegisterCommand ( " DISABLE_HOST_FLAP_DETECTION " , & ExternalCommandProcessor : : DisableHostFlapping ) ;
RegisterCommand ( " ENABLE_HOST_FLAP_DETECTION " , & ExternalCommandProcessor : : EnableHostFlapping ) ;
RegisterCommand ( " DISABLE_SVC_FLAP_DETECTION " , & ExternalCommandProcessor : : DisableSvcFlapping ) ;
RegisterCommand ( " ENABLE_SVC_FLAP_DETECTION " , & ExternalCommandProcessor : : EnableSvcFlapping ) ;
2013-02-17 19:14:34 +01:00
RegisterCommand ( " ENABLE_HOSTGROUP_SVC_CHECKS " , & ExternalCommandProcessor : : EnableHostgroupSvcChecks ) ;
RegisterCommand ( " DISABLE_HOSTGROUP_SVC_CHECKS " , & ExternalCommandProcessor : : DisableHostgroupSvcChecks ) ;
RegisterCommand ( " ENABLE_SERVICEGROUP_SVC_CHECKS " , & ExternalCommandProcessor : : EnableServicegroupSvcChecks ) ;
RegisterCommand ( " DISABLE_SERVICEGROUP_SVC_CHECKS " , & ExternalCommandProcessor : : DisableServicegroupSvcChecks ) ;
2013-02-26 11:18:03 +01:00
RegisterCommand ( " ENABLE_PASSIVE_HOST_CHECKS " , & ExternalCommandProcessor : : EnablePassiveHostChecks ) ;
RegisterCommand ( " DISABLE_PASSIVE_HOST_CHECKS " , & ExternalCommandProcessor : : DisablePassiveHostChecks ) ;
2013-02-17 19:14:34 +01:00
RegisterCommand ( " ENABLE_PASSIVE_SVC_CHECKS " , & ExternalCommandProcessor : : EnablePassiveSvcChecks ) ;
RegisterCommand ( " DISABLE_PASSIVE_SVC_CHECKS " , & ExternalCommandProcessor : : DisablePassiveSvcChecks ) ;
RegisterCommand ( " ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS " , & ExternalCommandProcessor : : EnableServicegroupPassiveSvcChecks ) ;
RegisterCommand ( " DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS " , & ExternalCommandProcessor : : DisableServicegroupPassiveSvcChecks ) ;
RegisterCommand ( " ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS " , & ExternalCommandProcessor : : EnableHostgroupPassiveSvcChecks ) ;
RegisterCommand ( " DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS " , & ExternalCommandProcessor : : DisableHostgroupPassiveSvcChecks ) ;
RegisterCommand ( " PROCESS_FILE " , & ExternalCommandProcessor : : ProcessFile ) ;
RegisterCommand ( " SCHEDULE_SVC_DOWNTIME " , & ExternalCommandProcessor : : ScheduleSvcDowntime ) ;
RegisterCommand ( " DEL_SVC_DOWNTIME " , & ExternalCommandProcessor : : DelSvcDowntime ) ;
RegisterCommand ( " SCHEDULE_HOST_DOWNTIME " , & ExternalCommandProcessor : : ScheduleHostDowntime ) ;
RegisterCommand ( " DEL_HOST_DOWNTIME " , & ExternalCommandProcessor : : DelHostDowntime ) ;
RegisterCommand ( " SCHEDULE_HOST_SVC_DOWNTIME " , & ExternalCommandProcessor : : ScheduleHostSvcDowntime ) ;
RegisterCommand ( " SCHEDULE_HOSTGROUP_HOST_DOWNTIME " , & ExternalCommandProcessor : : ScheduleHostgroupHostDowntime ) ;
RegisterCommand ( " SCHEDULE_HOSTGROUP_SVC_DOWNTIME " , & ExternalCommandProcessor : : ScheduleHostgroupSvcDowntime ) ;
RegisterCommand ( " SCHEDULE_SERVICEGROUP_HOST_DOWNTIME " , & ExternalCommandProcessor : : ScheduleServicegroupHostDowntime ) ;
RegisterCommand ( " SCHEDULE_SERVICEGROUP_SVC_DOWNTIME " , & ExternalCommandProcessor : : ScheduleServicegroupSvcDowntime ) ;
RegisterCommand ( " ADD_HOST_COMMENT " , & ExternalCommandProcessor : : AddHostComment ) ;
RegisterCommand ( " DEL_HOST_COMMENT " , & ExternalCommandProcessor : : DelHostComment ) ;
RegisterCommand ( " ADD_SVC_COMMENT " , & ExternalCommandProcessor : : AddSvcComment ) ;
RegisterCommand ( " DEL_SVC_COMMENT " , & ExternalCommandProcessor : : DelSvcComment ) ;
RegisterCommand ( " DEL_ALL_HOST_COMMENTS " , & ExternalCommandProcessor : : DelAllHostComments ) ;
RegisterCommand ( " DEL_ALL_SVC_COMMENTS " , & ExternalCommandProcessor : : DelAllSvcComments ) ;
RegisterCommand ( " SEND_CUSTOM_HOST_NOTIFICATION " , & ExternalCommandProcessor : : SendCustomHostNotification ) ;
RegisterCommand ( " SEND_CUSTOM_SVC_NOTIFICATION " , & ExternalCommandProcessor : : SendCustomSvcNotification ) ;
2013-02-26 12:37:25 +01:00
RegisterCommand ( " DELAY_HOST_NOTIFICATION " , & ExternalCommandProcessor : : DelayHostNotification ) ;
RegisterCommand ( " DELAY_SVC_NOTIFICATION " , & ExternalCommandProcessor : : DelaySvcNotification ) ;
RegisterCommand ( " ENABLE_HOST_NOTIFICATIONS " , & ExternalCommandProcessor : : EnableHostNotifications ) ;
RegisterCommand ( " DISABLE_HOST_NOTIFICATIONS " , & ExternalCommandProcessor : : DisableHostNotifications ) ;
RegisterCommand ( " ENABLE_SVC_NOTIFICATIONS " , & ExternalCommandProcessor : : EnableSvcNotifications ) ;
RegisterCommand ( " DISABLE_SVC_NOTIFICATIONS " , & ExternalCommandProcessor : : DisableSvcNotifications ) ;
2013-04-15 10:23:06 +02:00
RegisterCommand ( " DISABLE_HOSTGROUP_HOST_CHECKS " , & ExternalCommandProcessor : : DisableHostgroupHostChecks ) ;
RegisterCommand ( " DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS " , & ExternalCommandProcessor : : DisableHostgroupPassiveHostChecks ) ;
RegisterCommand ( " DISABLE_SERVICEGROUP_HOST_CHECKS " , & ExternalCommandProcessor : : DisableServicegroupHostChecks ) ;
RegisterCommand ( " DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS " , & ExternalCommandProcessor : : DisableServicegroupPassiveHostChecks ) ;
RegisterCommand ( " ENABLE_HOSTGROUP_HOST_CHECKS " , & ExternalCommandProcessor : : EnableHostgroupHostChecks ) ;
RegisterCommand ( " ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS " , & ExternalCommandProcessor : : EnableHostgroupPassiveHostChecks ) ;
RegisterCommand ( " ENABLE_SERVICEGROUP_HOST_CHECKS " , & ExternalCommandProcessor : : EnableServicegroupHostChecks ) ;
RegisterCommand ( " ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS " , & ExternalCommandProcessor : : EnableServicegroupPassiveHostChecks ) ;
2013-10-08 11:57:35 +02:00
RegisterCommand ( " ENABLE_NOTIFICATIONS " , & ExternalCommandProcessor : : EnableNotifications ) ;
RegisterCommand ( " DISABLE_NOTIFICATIONS " , & ExternalCommandProcessor : : DisableNotifications ) ;
RegisterCommand ( " ENABLE_FLAP_DETECTION " , & ExternalCommandProcessor : : EnableFlapDetection ) ;
RegisterCommand ( " DISABLE_FLAP_DETECTION " , & ExternalCommandProcessor : : DisableFlapDetection ) ;
RegisterCommand ( " ENABLE_EVENT_HANDLERS " , & ExternalCommandProcessor : : EnableEventHandlers ) ;
RegisterCommand ( " DISABLE_EVENT_HANDLERS " , & ExternalCommandProcessor : : DisableEventHandlers ) ;
RegisterCommand ( " ENABLE_PERFORMANCE_DATA " , & ExternalCommandProcessor : : EnablePerformanceData ) ;
RegisterCommand ( " DISABLE_PERFORMANCE_DATA " , & ExternalCommandProcessor : : DisablePerformanceData ) ;
RegisterCommand ( " START_EXECUTING_SVC_CHECKS " , & ExternalCommandProcessor : : StartExecutingSvcChecks ) ;
RegisterCommand ( " STOP_EXECUTING_SVC_CHECKS " , & ExternalCommandProcessor : : StopExecutingSvcChecks ) ;
2013-10-16 12:09:45 +02:00
RegisterCommand ( " CHANGE_SVC_MODATTR " , & ExternalCommandProcessor : : ChangeSvcModattr ) ;
RegisterCommand ( " CHANGE_HOST_MODATTR " , & ExternalCommandProcessor : : ChangeHostModattr ) ;
2013-10-16 13:02:21 +02:00
RegisterCommand ( " CHANGE_NORMAL_SVC_CHECK_INTERVAL " , & ExternalCommandProcessor : : ChangeNormalSvcCheckInterval ) ;
RegisterCommand ( " CHANGE_NORMAL_HOST_CHECK_INTERVAL " , & ExternalCommandProcessor : : ChangeNormalHostCheckInterval ) ;
RegisterCommand ( " CHANGE_RETRY_SVC_CHECK_INTERVAL " , & ExternalCommandProcessor : : ChangeRetrySvcCheckInterval ) ;
RegisterCommand ( " CHANGE_RETRY_HOST_CHECK_INTERVAL " , & ExternalCommandProcessor : : ChangeRetryHostCheckInterval ) ;
2013-10-16 15:20:14 +02:00
RegisterCommand ( " ENABLE_HOST_EVENT_HANDLER " , & ExternalCommandProcessor : : EnableHostEventHandler ) ;
RegisterCommand ( " DISABLE_HOST_EVENT_HANDLER " , & ExternalCommandProcessor : : DisableHostEventHandler ) ;
RegisterCommand ( " ENABLE_SVC_EVENT_HANDLER " , & ExternalCommandProcessor : : EnableSvcEventHandler ) ;
RegisterCommand ( " DISABLE_SVC_EVENT_HANDLER " , & ExternalCommandProcessor : : DisableSvcEventHandler ) ;
2013-01-22 08:34:29 +01:00
}
2013-01-29 15:00:39 +01:00
void ExternalCommandProcessor : : RegisterCommand ( const String & command , const ExternalCommandProcessor : : Callback & callback )
2013-01-22 08:34:29 +01:00
{
2013-02-17 19:14:34 +01:00
boost : : mutex : : scoped_lock lock ( m_Mutex ) ;
2013-01-22 08:34:29 +01:00
m_Commands [ command ] = callback ;
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ProcessHostCheckResult ( double time , const std : : vector < String > & arguments )
2013-02-26 11:18:03 +01:00
{
if ( arguments . size ( ) < 3 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 3 arguments. " ) ) ;
2013-02-26 11:18:03 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
2013-09-27 23:13:25 +02:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot process passive host check result for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-09-27 12:24:30 +02:00
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-02-26 11:18:03 +01:00
if ( ! hc - > GetEnablePassiveChecks ( ) )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Got passive check result for host ' " + arguments [ 0 ] + " ' which has passive checks disabled. " ) ) ;
2013-02-26 11:18:03 +01:00
2013-03-06 11:03:50 +01:00
int exitStatus = Convert : : ToDouble ( arguments [ 1 ] ) ;
2013-11-09 14:22:38 +01:00
CheckResult : : Ptr result = PluginUtility : : ParseCheckOutput ( arguments [ 2 ] ) ;
result - > SetState ( PluginUtility : : ExitStatusToState ( exitStatus ) ) ;
2013-02-26 11:18:03 +01:00
2013-11-09 14:22:38 +01:00
result - > SetScheduleStart ( time ) ;
result - > SetScheduleEnd ( time ) ;
result - > SetExecutionStart ( time ) ;
result - > SetExecutionEnd ( time ) ;
result - > SetActive ( false ) ;
2013-02-26 11:18:03 +01:00
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Processing passive check result for host ' " + arguments [ 0 ] + " ' " ) ;
2013-02-26 11:18:03 +01:00
hc - > ProcessCheckResult ( result ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( hc ) ;
/* Reschedule the next check. The side effect of this is that for as long
* as we receive passive results for a service we won ' t execute any
* active checks . */
hc - > SetNextCheck ( Utility : : GetTime ( ) + hc - > GetCheckInterval ( ) ) ;
}
2013-02-26 11:18:03 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ProcessServiceCheckResult ( double time , const std : : vector < String > & arguments )
2013-01-22 12:05:36 +01:00
{
if ( arguments . size ( ) < 4 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 4 arguments. " ) ) ;
2013-01-22 12:05:36 +01:00
2013-02-08 15:38:22 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-01-22 12:05:36 +01:00
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot process passive service check result for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-01-24 23:10:07 +01:00
if ( ! service - > GetEnablePassiveChecks ( ) )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Got passive check result for service ' " + arguments [ 1 ] + " ' which has passive checks disabled. " ) ) ;
2013-01-24 23:10:07 +01:00
2013-01-29 12:05:46 +01:00
int exitStatus = Convert : : ToDouble ( arguments [ 2 ] ) ;
2013-11-09 14:22:38 +01:00
CheckResult : : Ptr result = PluginUtility : : ParseCheckOutput ( arguments [ 3 ] ) ;
result - > SetState ( PluginUtility : : ExitStatusToState ( exitStatus ) ) ;
result - > SetScheduleStart ( time ) ;
result - > SetScheduleEnd ( time ) ;
result - > SetExecutionStart ( time ) ;
result - > SetExecutionEnd ( time ) ;
result - > SetActive ( false ) ;
2013-01-22 12:05:36 +01:00
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Processing passive check result for service ' " + arguments [ 1 ] + " ' " ) ;
2013-01-22 12:05:36 +01:00
service - > ProcessCheckResult ( result ) ;
2013-01-27 12:13:45 +01:00
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
/* Reschedule the next check. The side effect of this is that for as long
* as we receive passive results for a service we won ' t execute any
* active checks . */
service - > SetNextCheck ( Utility : : GetTime ( ) + service - > GetCheckInterval ( ) ) ;
}
2013-01-22 12:05:36 +01:00
}
2013-01-22 12:56:29 +01:00
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ScheduleHostCheck ( double , const std : : vector < String > & arguments )
2013-02-26 11:18:03 +01:00
{
if ( arguments . size ( ) < 2 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-02-26 11:18:03 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot reschedule host check for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-02-26 11:18:03 +01:00
2013-07-25 09:00:23 +02:00
if ( ! hc ) {
Log ( LogInformation , " icinga " , " Ignoring request request for host ' " +
arguments [ 0 ] + " ' (does not have a host check) " ) ;
return ;
}
2013-02-26 11:18:03 +01:00
double planned_check = Convert : : ToDouble ( arguments [ 1 ] ) ;
if ( planned_check > hc - > GetNextCheck ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Ignoring reschedule request for host ' " +
2013-02-26 11:18:03 +01:00
arguments [ 0 ] + " ' (next check is already sooner than requested check time) " ) ;
return ;
}
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Rescheduling next check for host ' " + arguments [ 0 ] + " ' " ) ;
2013-03-06 11:03:50 +01:00
2013-09-12 15:47:45 +02:00
if ( planned_check < Utility : : GetTime ( ) )
planned_check = Utility : : GetTime ( ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( hc ) ;
hc - > SetNextCheck ( planned_check ) ;
}
2013-02-26 11:18:03 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ScheduleForcedHostCheck ( double , const std : : vector < String > & arguments )
2013-02-26 11:18:03 +01:00
{
if ( arguments . size ( ) < 2 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-02-26 11:18:03 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot reschedule forced host check for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-02-26 11:18:03 +01:00
2013-07-25 09:00:23 +02:00
if ( ! hc ) {
Log ( LogInformation , " icinga " , " Ignoring request request for host ' " +
arguments [ 0 ] + " ' (does not have a host check) " ) ;
return ;
}
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Rescheduling next check for host ' " + arguments [ 0 ] + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( hc ) ;
hc - > SetForceNextCheck ( true ) ;
hc - > SetNextCheck ( Convert : : ToDouble ( arguments [ 1 ] ) ) ;
}
2013-02-26 11:18:03 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ScheduleSvcCheck ( double , const std : : vector < String > & arguments )
2013-01-22 12:56:29 +01:00
{
if ( arguments . size ( ) < 3 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 3 arguments. " ) ) ;
2013-01-22 12:56:29 +01:00
2013-02-08 15:38:22 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-01-22 12:56:29 +01:00
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot reschedule service check for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-01-29 12:05:46 +01:00
double planned_check = Convert : : ToDouble ( arguments [ 2 ] ) ;
2013-01-22 12:56:29 +01:00
2013-01-22 15:13:51 +01:00
if ( planned_check > service - > GetNextCheck ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Ignoring reschedule request for service ' " +
2013-01-22 15:13:51 +01:00
arguments [ 1 ] + " ' (next check is already sooner than requested check time) " ) ;
return ;
}
2013-01-22 12:56:29 +01:00
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Rescheduling next check for service ' " + arguments [ 1 ] + " ' " ) ;
2013-03-06 11:03:50 +01:00
2013-09-12 15:47:45 +02:00
if ( planned_check < Utility : : GetTime ( ) )
planned_check = Utility : : GetTime ( ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetNextCheck ( planned_check ) ;
}
2013-01-22 12:56:29 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ScheduleForcedSvcCheck ( double , const std : : vector < String > & arguments )
2013-01-22 12:56:29 +01:00
{
if ( arguments . size ( ) < 3 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 3 arguments. " ) ) ;
2013-01-22 12:56:29 +01:00
2013-02-08 15:38:22 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-01-22 12:56:29 +01:00
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot reschedule forced service check for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Rescheduling next check for service ' " + arguments [ 1 ] + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetForceNextCheck ( true ) ;
service - > SetNextCheck ( Convert : : ToDouble ( arguments [ 2 ] ) ) ;
}
2013-01-22 12:56:29 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : EnableHostCheck ( double , const std : : vector < String > & arguments )
2013-02-26 11:18:03 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-02-26 11:18:03 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable host check non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Enabling active checks for host ' " + arguments [ 0 ] + " ' " ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-02-26 11:18:03 +01:00
2013-03-06 11:03:50 +01:00
if ( ! hc )
return ;
{
ObjectLock olock ( hc ) ;
2013-02-26 11:18:03 +01:00
hc - > SetEnableActiveChecks ( true ) ;
2013-03-06 11:03:50 +01:00
}
2013-02-26 11:18:03 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DisableHostCheck ( double , const std : : vector < String > & arguments )
2013-02-26 11:18:03 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-02-26 11:18:03 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable host check non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Disabling active checks for host ' " + arguments [ 0 ] + " ' " ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-02-26 11:18:03 +01:00
2013-03-06 11:03:50 +01:00
if ( ! hc )
return ;
{
ObjectLock olock ( hc ) ;
2013-02-26 11:18:03 +01:00
hc - > SetEnableActiveChecks ( false ) ;
2013-03-06 11:03:50 +01:00
}
2013-02-26 11:18:03 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : EnableSvcCheck ( double , const std : : vector < String > & arguments )
2013-01-22 16:01:08 +01:00
{
if ( arguments . size ( ) < 2 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-01-22 16:01:08 +01:00
2013-02-08 15:38:22 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-01-22 16:01:08 +01:00
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable service check for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Enabling active checks for service ' " + arguments [ 1 ] + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnableActiveChecks ( true ) ;
}
2013-01-22 16:01:08 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DisableSvcCheck ( double , const std : : vector < String > & arguments )
2013-01-22 16:01:08 +01:00
{
if ( arguments . size ( ) < 2 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-01-22 16:01:08 +01:00
2013-02-08 15:38:22 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-01-22 16:01:08 +01:00
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable service check for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Disabling active checks for service ' " + arguments [ 1 ] + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnableActiveChecks ( false ) ;
}
2013-01-22 16:01:08 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ShutdownProcess ( double , const std : : vector < String > & )
2013-01-22 16:23:25 +01:00
{
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Shutting down Icinga via external command. " ) ;
2013-01-22 16:23:25 +01:00
Application : : RequestShutdown ( ) ;
}
2013-08-30 14:27:24 +02:00
void ExternalCommandProcessor : : RestartProcess ( double , const std : : vector < String > & )
{
Log ( LogInformation , " icinga " , " Restarting Icinga via external command. " ) ;
Application : : RequestRestart ( ) ;
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ScheduleForcedHostSvcChecks ( double , const std : : vector < String > & arguments )
2013-01-23 10:42:16 +01:00
{
if ( arguments . size ( ) < 2 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-01-23 10:42:16 +01:00
2013-01-29 12:05:46 +01:00
double planned_check = Convert : : ToDouble ( arguments [ 1 ] ) ;
2013-01-23 10:42:16 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot reschedule forced host service checks for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-01-29 14:19:54 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , host - > GetServices ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Rescheduling next check for service ' " + service - > GetName ( ) + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetNextCheck ( planned_check ) ;
service - > SetForceNextCheck ( true ) ;
}
2013-01-23 10:42:16 +01:00
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ScheduleHostSvcChecks ( double , const std : : vector < String > & arguments )
2013-01-23 10:42:16 +01:00
{
if ( arguments . size ( ) < 2 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-01-23 10:42:16 +01:00
2013-01-29 12:05:46 +01:00
double planned_check = Convert : : ToDouble ( arguments [ 1 ] ) ;
2013-01-23 10:42:16 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot reschedule host service checks for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-09-12 15:47:45 +02:00
if ( planned_check < Utility : : GetTime ( ) )
planned_check = Utility : : GetTime ( ) ;
2013-01-29 14:19:54 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , host - > GetServices ( ) ) {
2013-01-23 10:42:16 +01:00
if ( planned_check > service - > GetNextCheck ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Ignoring reschedule request for service ' " +
2013-01-23 16:07:55 +01:00
service - > GetName ( ) + " ' (next check is already sooner than requested check time) " ) ;
continue ;
2013-01-23 10:42:16 +01:00
}
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Rescheduling next check for service ' " + service - > GetName ( ) + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetNextCheck ( planned_check ) ;
}
2013-01-23 10:42:16 +01:00
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : EnableHostSvcChecks ( double , const std : : vector < String > & arguments )
2013-01-23 10:51:54 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-23 10:51:54 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable host service checks for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-01-29 14:19:54 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , host - > GetServices ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Enabling active checks for service ' " + service - > GetName ( ) + " ' " ) ;
2013-01-24 23:10:07 +01:00
service - > SetEnableActiveChecks ( true ) ;
2013-01-23 10:51:54 +01:00
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DisableHostSvcChecks ( double , const std : : vector < String > & arguments )
2013-01-23 10:51:54 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 arguments. " ) ) ;
2013-01-23 10:51:54 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable host service checks for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-01-29 14:19:54 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , host - > GetServices ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Disabling active checks for service ' " + service - > GetName ( ) + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnableActiveChecks ( false ) ;
}
2013-01-23 10:51:54 +01:00
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : AcknowledgeSvcProblem ( double , const std : : vector < String > & arguments )
2013-01-23 13:21:07 +01:00
{
if ( arguments . size ( ) < 7 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 7 arguments. " ) ) ;
2013-01-23 13:21:07 +01:00
2013-01-29 12:05:46 +01:00
bool sticky = Convert : : ToBool ( arguments [ 2 ] ) ;
2013-01-23 13:21:07 +01:00
2013-02-08 15:38:22 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-01-23 13:21:07 +01:00
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot acknowledge service problem for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-01-23 16:18:58 +01:00
if ( service - > GetState ( ) = = StateOK )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " The service ' " + arguments [ 1 ] + " ' is OK. " ) ) ;
2013-01-23 16:18:58 +01:00
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Setting acknowledgement for service ' " + service - > GetName ( ) + " ' " ) ;
2013-03-06 11:03:50 +01:00
2013-08-29 14:01:40 +02:00
service - > AddComment ( CommentAcknowledgement , arguments [ 5 ] , arguments [ 6 ] , 0 ) ;
2013-06-19 10:57:07 +02:00
service - > AcknowledgeProblem ( arguments [ 5 ] , arguments [ 6 ] , sticky ? AcknowledgementSticky : AcknowledgementNormal ) ;
2013-01-23 13:21:07 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : AcknowledgeSvcProblemExpire ( double , const std : : vector < String > & arguments )
2013-01-23 13:21:07 +01:00
{
if ( arguments . size ( ) < 8 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 8 arguments. " ) ) ;
2013-01-23 13:21:07 +01:00
2013-01-29 12:05:46 +01:00
bool sticky = Convert : : ToBool ( arguments [ 2 ] ) ;
double timestamp = Convert : : ToDouble ( arguments [ 5 ] ) ;
2013-01-23 13:21:07 +01:00
2013-02-08 15:38:22 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-01-23 13:21:07 +01:00
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot acknowledge service problem with expire time for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-01-23 16:18:58 +01:00
if ( service - > GetState ( ) = = StateOK )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " The service ' " + arguments [ 1 ] + " ' is OK. " ) ) ;
2013-01-23 16:18:58 +01:00
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Setting timed acknowledgement for service ' " + service - > GetName ( ) + " ' " ) ;
2013-03-06 11:03:50 +01:00
2013-08-29 14:01:40 +02:00
service - > AddComment ( CommentAcknowledgement , arguments [ 6 ] , arguments [ 7 ] , 0 ) ;
2013-06-19 10:57:07 +02:00
service - > AcknowledgeProblem ( arguments [ 6 ] , arguments [ 7 ] , sticky ? AcknowledgementSticky : AcknowledgementNormal , timestamp ) ;
2013-01-23 13:21:07 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : RemoveSvcAcknowledgement ( double , const std : : vector < String > & arguments )
2013-01-23 13:21:07 +01:00
{
if ( arguments . size ( ) < 2 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-01-23 13:21:07 +01:00
2013-02-09 02:16:02 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-01-23 13:21:07 +01:00
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot remove service acknowledgement for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Removing acknowledgement for service ' " + service - > GetName ( ) + " ' " ) ;
2013-03-06 11:03:50 +01:00
2013-10-19 00:17:28 +02:00
ObjectLock olock ( service ) ;
2013-03-08 16:32:29 +01:00
service - > ClearAcknowledgement ( ) ;
2013-01-23 13:21:07 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : AcknowledgeHostProblem ( double , const std : : vector < String > & arguments )
2013-01-27 11:35:47 +01:00
{
2013-01-27 12:02:22 +01:00
if ( arguments . size ( ) < 6 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 6 arguments. " ) ) ;
2013-01-27 11:35:47 +01:00
2013-02-09 02:01:48 +01:00
bool sticky = Convert : : ToBool ( arguments [ 1 ] ) ;
2013-01-27 11:35:47 +01:00
2013-01-27 12:02:22 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-01-27 11:35:47 +01:00
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot acknowledge host problem for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Setting acknowledgement for host ' " + host - > GetName ( ) + " ' " ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr service = host - > GetCheckService ( ) ;
2013-02-09 01:16:43 +01:00
if ( service ) {
2013-02-19 23:02:08 +01:00
if ( service - > GetState ( ) = = StateOK )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " The host ' " + arguments [ 0 ] + " ' is OK. " ) ) ;
2013-02-19 23:02:08 +01:00
2013-08-29 14:01:40 +02:00
service - > AddComment ( CommentAcknowledgement , arguments [ 4 ] , arguments [ 5 ] , 0 ) ;
2013-06-19 10:57:07 +02:00
service - > AcknowledgeProblem ( arguments [ 4 ] , arguments [ 5 ] , sticky ? AcknowledgementSticky : AcknowledgementNormal ) ;
2013-02-09 01:16:43 +01:00
}
2013-01-27 11:35:47 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : AcknowledgeHostProblemExpire ( double , const std : : vector < String > & arguments )
2013-01-27 11:35:47 +01:00
{
2013-01-27 12:02:22 +01:00
if ( arguments . size ( ) < 7 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 7 arguments. " ) ) ;
2013-01-27 11:35:47 +01:00
2013-01-29 12:05:46 +01:00
bool sticky = Convert : : ToBool ( arguments [ 1 ] ) ;
double timestamp = Convert : : ToDouble ( arguments [ 4 ] ) ;
2013-01-27 11:35:47 +01:00
2013-01-27 12:02:22 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-01-27 11:35:47 +01:00
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot acknowledge host problem with expire time for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Setting timed acknowledgement for host ' " + host - > GetName ( ) + " ' " ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr service = host - > GetCheckService ( ) ;
2013-02-09 01:16:43 +01:00
if ( service ) {
2013-02-19 23:02:08 +01:00
if ( service - > GetState ( ) = = StateOK )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " The host ' " + arguments [ 0 ] + " ' is OK. " ) ) ;
2013-02-19 23:02:08 +01:00
2013-08-29 14:01:40 +02:00
service - > AddComment ( CommentAcknowledgement , arguments [ 5 ] , arguments [ 6 ] , 0 ) ;
2013-06-19 10:57:07 +02:00
service - > AcknowledgeProblem ( arguments [ 5 ] , arguments [ 6 ] , sticky ? AcknowledgementSticky : AcknowledgementNormal , timestamp ) ;
2013-02-09 01:16:43 +01:00
}
2013-01-27 11:35:47 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : RemoveHostAcknowledgement ( double , const std : : vector < String > & arguments )
2013-01-27 11:35:47 +01:00
{
2013-01-27 12:02:22 +01:00
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-27 11:35:47 +01:00
2013-01-27 12:02:22 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-01-27 11:35:47 +01:00
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot remove acknowledgement for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Removing acknowledgement for host ' " + host - > GetName ( ) + " ' " ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr service = host - > GetCheckService ( ) ;
2013-03-08 16:32:29 +01:00
if ( service )
2013-02-24 12:47:24 +01:00
service - > ClearAcknowledgement ( ) ;
2013-01-27 11:35:47 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : EnableHostgroupSvcChecks ( double , const std : : vector < String > & arguments )
2013-01-24 13:39:42 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-24 13:39:42 +01:00
HostGroup : : Ptr hg = HostGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! hg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable hostgroup service checks for non-existent hostgroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-02 09:07:47 +01:00
BOOST_FOREACH ( const Host : : Ptr & host , hg - > GetMembers ( ) ) {
2013-01-24 15:12:32 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , host - > GetServices ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Enabling active checks for service ' " + service - > GetName ( ) + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnableActiveChecks ( true ) ;
}
2013-01-24 15:12:32 +01:00
}
2013-01-24 13:39:42 +01:00
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DisableHostgroupSvcChecks ( double , const std : : vector < String > & arguments )
2013-01-24 13:39:42 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-24 13:39:42 +01:00
HostGroup : : Ptr hg = HostGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! hg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable hostgroup service checks for non-existent hostgroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-02 09:07:47 +01:00
BOOST_FOREACH ( const Host : : Ptr & host , hg - > GetMembers ( ) ) {
2013-01-24 15:12:32 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , host - > GetServices ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Disabling active checks for service ' " + service - > GetName ( ) + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnableActiveChecks ( false ) ;
}
2013-01-24 15:12:32 +01:00
}
2013-01-24 13:39:42 +01:00
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : EnableServicegroupSvcChecks ( double , const std : : vector < String > & arguments )
2013-01-24 13:39:42 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-24 13:39:42 +01:00
ServiceGroup : : Ptr sg = ServiceGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! sg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable servicegroup service checks for non-existent servicegroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-02 09:07:47 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , sg - > GetMembers ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Enabling active checks for service ' " + service - > GetName ( ) + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnableActiveChecks ( true ) ;
}
2013-01-24 13:39:42 +01:00
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DisableServicegroupSvcChecks ( double , const std : : vector < String > & arguments )
2013-01-24 13:39:42 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-24 13:39:42 +01:00
ServiceGroup : : Ptr sg = ServiceGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! sg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable servicegroup service checks for non-existent servicegroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-02 09:07:47 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , sg - > GetMembers ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Disabling active checks for service ' " + service - > GetName ( ) + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnableActiveChecks ( false ) ;
}
2013-01-24 23:10:07 +01:00
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : EnablePassiveHostChecks ( double , const std : : vector < String > & arguments )
2013-02-26 11:18:03 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-02-26 11:18:03 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable passive host checks for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Enabling passive checks for host ' " + arguments [ 0 ] + " ' " ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-02-26 11:18:03 +01:00
2013-03-06 11:03:50 +01:00
if ( ! hc )
return ;
{
ObjectLock olock ( hc ) ;
2013-02-26 11:18:03 +01:00
hc - > SetEnablePassiveChecks ( true ) ;
2013-03-06 11:03:50 +01:00
}
2013-02-26 11:18:03 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DisablePassiveHostChecks ( double , const std : : vector < String > & arguments )
2013-02-26 11:18:03 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 arguments. " ) ) ;
2013-02-26 11:18:03 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable passive host checks for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Disabling passive checks for host ' " + arguments [ 0 ] + " ' " ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-02-26 11:18:03 +01:00
2013-03-06 11:03:50 +01:00
if ( ! hc )
return ;
{
ObjectLock olock ( hc ) ;
2013-02-26 11:18:03 +01:00
hc - > SetEnablePassiveChecks ( false ) ;
2013-03-06 11:03:50 +01:00
}
2013-02-26 11:18:03 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : EnablePassiveSvcChecks ( double , const std : : vector < String > & arguments )
2013-01-24 23:10:07 +01:00
{
if ( arguments . size ( ) < 2 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-01-24 23:10:07 +01:00
2013-02-08 15:38:22 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-01-24 23:10:07 +01:00
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable service checks for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Enabling passive checks for service ' " + arguments [ 1 ] + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnablePassiveChecks ( true ) ;
}
2013-01-24 23:10:07 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DisablePassiveSvcChecks ( double , const std : : vector < String > & arguments )
2013-01-24 23:10:07 +01:00
{
if ( arguments . size ( ) < 2 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-01-24 23:10:07 +01:00
2013-02-08 15:38:22 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-01-24 23:10:07 +01:00
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable service checks for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Disabling passive checks for service ' " + arguments [ 1 ] + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnablePassiveChecks ( false ) ;
}
2013-01-24 23:10:07 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : EnableServicegroupPassiveSvcChecks ( double , const std : : vector < String > & arguments )
2013-01-24 23:10:07 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-24 23:10:07 +01:00
ServiceGroup : : Ptr sg = ServiceGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! sg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable servicegroup passive service checks for non-existent servicegroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-02 09:07:47 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , sg - > GetMembers ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Enabling passive checks for service ' " + service - > GetName ( ) + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnablePassiveChecks ( true ) ;
}
2013-01-24 23:10:07 +01:00
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DisableServicegroupPassiveSvcChecks ( double , const std : : vector < String > & arguments )
2013-01-24 23:10:07 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-24 23:10:07 +01:00
ServiceGroup : : Ptr sg = ServiceGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! sg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable servicegroup passive service checks for non-existent servicegroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-02 09:07:47 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , sg - > GetMembers ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Disabling passive checks for service ' " + service - > GetName ( ) + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnablePassiveChecks ( true ) ;
}
2013-01-24 13:39:42 +01:00
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : EnableHostgroupPassiveSvcChecks ( double , const std : : vector < String > & arguments )
2013-01-24 23:10:07 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-24 23:10:07 +01:00
HostGroup : : Ptr hg = HostGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! hg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable hostgroup passive service checks for non-existent hostgroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-02 09:07:47 +01:00
BOOST_FOREACH ( const Host : : Ptr & host , hg - > GetMembers ( ) ) {
2013-01-24 23:10:07 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , host - > GetServices ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Enabling passive checks for service ' " + service - > GetName ( ) + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnablePassiveChecks ( true ) ;
}
2013-01-24 23:10:07 +01:00
}
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DisableHostgroupPassiveSvcChecks ( double , const std : : vector < String > & arguments )
2013-01-24 23:10:07 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-24 23:10:07 +01:00
HostGroup : : Ptr hg = HostGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! hg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable hostgroup passive service checks for non-existent hostgroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-02 09:07:47 +01:00
BOOST_FOREACH ( const Host : : Ptr & host , hg - > GetMembers ( ) ) {
2013-01-24 23:10:07 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , host - > GetServices ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Disabling passive checks for service ' " + service - > GetName ( ) + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnablePassiveChecks ( false ) ;
}
2013-01-24 23:10:07 +01:00
}
}
}
2013-01-24 23:42:02 +01:00
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ProcessFile ( double , const std : : vector < String > & arguments )
2013-01-24 23:42:02 +01:00
{
if ( arguments . size ( ) < 2 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-01-24 23:42:02 +01:00
String file = arguments [ 0 ] ;
2013-01-29 12:05:46 +01:00
bool del = Convert : : ToBool ( arguments [ 1 ] ) ;
2013-01-24 23:42:02 +01:00
2013-03-16 21:18:53 +01:00
std : : ifstream ifp ;
ifp . exceptions ( std : : ifstream : : badbit ) ;
2013-01-24 23:42:02 +01:00
2013-03-16 21:18:53 +01:00
ifp . open ( file . CStr ( ) , std : : ifstream : : in ) ;
2013-01-24 23:42:02 +01:00
while ( ifp . good ( ) ) {
std : : string line ;
std : : getline ( ifp , line ) ;
try {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " compat " , " Executing external command: " + line ) ;
2013-01-24 23:42:02 +01:00
Execute ( line ) ;
2013-03-16 21:18:53 +01:00
} catch ( const std : : exception & ex ) {
std : : ostringstream msgbuf ;
msgbuf < < " External command failed: " < < boost : : diagnostic_information ( ex ) ;
Log ( LogWarning , " icinga " , msgbuf . str ( ) ) ;
2013-01-24 23:42:02 +01:00
}
}
ifp . close ( ) ;
if ( del )
( void ) unlink ( file . CStr ( ) ) ;
}
2013-01-29 14:19:54 +01:00
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ScheduleSvcDowntime ( double , const std : : vector < String > & arguments )
2013-01-29 14:19:54 +01:00
{
if ( arguments . size ( ) < 9 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 9 arguments. " ) ) ;
2013-01-29 14:19:54 +01:00
2013-02-08 15:38:22 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-01-29 14:19:54 +01:00
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot schedule service downtime for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-01-30 09:59:22 +01:00
String triggeredBy ;
int triggeredByLegacy = Convert : : ToLong ( arguments [ 5 ] ) ;
if ( triggeredByLegacy ! = 0 )
2013-02-09 01:16:43 +01:00
triggeredBy = Service : : GetDowntimeIDFromLegacyID ( triggeredByLegacy ) ;
2013-01-29 14:19:54 +01:00
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Creating downtime for service " + service - > GetName ( ) ) ;
2013-11-09 22:08:26 +01:00
( void ) service - > AddDowntime ( arguments [ 7 ] , arguments [ 8 ] ,
2013-01-29 14:19:54 +01:00
Convert : : ToDouble ( arguments [ 2 ] ) , Convert : : ToDouble ( arguments [ 3 ] ) ,
2013-01-30 09:59:22 +01:00
Convert : : ToBool ( arguments [ 4 ] ) , triggeredBy , Convert : : ToDouble ( arguments [ 6 ] ) ) ;
2013-01-29 14:19:54 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DelSvcDowntime ( double , const std : : vector < String > & arguments )
2013-01-29 14:19:54 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-29 14:19:54 +01:00
2013-01-30 09:59:22 +01:00
int id = Convert : : ToLong ( arguments [ 0 ] ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Removing downtime ID " + arguments [ 0 ] ) ;
2013-02-09 01:16:43 +01:00
String rid = Service : : GetDowntimeIDFromLegacyID ( id ) ;
2013-09-17 19:37:10 +02:00
Service : : RemoveDowntime ( rid , true ) ;
2013-01-29 14:19:54 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ScheduleHostDowntime ( double , const std : : vector < String > & arguments )
2013-01-29 14:19:54 +01:00
{
if ( arguments . size ( ) < 8 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 8 arguments. " ) ) ;
2013-01-29 14:19:54 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot schedule host downtime for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-01-30 09:59:22 +01:00
String triggeredBy ;
int triggeredByLegacy = Convert : : ToLong ( arguments [ 4 ] ) ;
if ( triggeredByLegacy ! = 0 )
2013-02-09 01:16:43 +01:00
triggeredBy = Service : : GetDowntimeIDFromLegacyID ( triggeredByLegacy ) ;
2013-01-29 14:19:54 +01:00
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Creating downtime for host " + host - > GetName ( ) ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr service = host - > GetCheckService ( ) ;
2013-02-09 01:16:43 +01:00
if ( service ) {
2013-11-09 22:08:26 +01:00
( void ) service - > AddDowntime ( arguments [ 6 ] , arguments [ 7 ] ,
2013-02-09 01:16:43 +01:00
Convert : : ToDouble ( arguments [ 1 ] ) , Convert : : ToDouble ( arguments [ 2 ] ) ,
Convert : : ToBool ( arguments [ 3 ] ) , triggeredBy , Convert : : ToDouble ( arguments [ 5 ] ) ) ;
}
2013-01-29 14:19:54 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DelHostDowntime ( double , const std : : vector < String > & arguments )
2013-01-29 14:19:54 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-29 14:19:54 +01:00
2013-01-30 09:59:22 +01:00
int id = Convert : : ToLong ( arguments [ 0 ] ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Removing downtime ID " + arguments [ 0 ] ) ;
2013-02-09 01:16:43 +01:00
String rid = Service : : GetDowntimeIDFromLegacyID ( id ) ;
2013-09-17 19:37:10 +02:00
Service : : RemoveDowntime ( rid , true ) ;
2013-01-29 14:19:54 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ScheduleHostSvcDowntime ( double , const std : : vector < String > & arguments )
2013-01-29 14:19:54 +01:00
{
if ( arguments . size ( ) < 8 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 8 argument. " ) ) ;
2013-01-29 14:19:54 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot schedule host services downtime for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-01-30 09:59:22 +01:00
String triggeredBy ;
int triggeredByLegacy = Convert : : ToLong ( arguments [ 4 ] ) ;
if ( triggeredByLegacy ! = 0 )
2013-02-09 01:16:43 +01:00
triggeredBy = Service : : GetDowntimeIDFromLegacyID ( triggeredByLegacy ) ;
2013-01-29 14:19:54 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , host - > GetServices ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Creating downtime for service " + service - > GetName ( ) ) ;
2013-11-09 22:08:26 +01:00
( void ) service - > AddDowntime ( arguments [ 6 ] , arguments [ 7 ] ,
2013-01-29 14:19:54 +01:00
Convert : : ToDouble ( arguments [ 1 ] ) , Convert : : ToDouble ( arguments [ 2 ] ) ,
2013-01-30 09:59:22 +01:00
Convert : : ToBool ( arguments [ 3 ] ) , triggeredBy , Convert : : ToDouble ( arguments [ 5 ] ) ) ;
2013-01-29 14:19:54 +01:00
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ScheduleHostgroupHostDowntime ( double , const std : : vector < String > & arguments )
2013-01-29 14:19:54 +01:00
{
if ( arguments . size ( ) < 8 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 8 arguments. " ) ) ;
2013-01-29 14:19:54 +01:00
HostGroup : : Ptr hg = HostGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! hg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot schedule hostgroup host downtime for non-existent hostgroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-01-30 09:59:22 +01:00
String triggeredBy ;
int triggeredByLegacy = Convert : : ToLong ( arguments [ 4 ] ) ;
if ( triggeredByLegacy ! = 0 )
2013-02-09 01:16:43 +01:00
triggeredBy = Service : : GetDowntimeIDFromLegacyID ( triggeredByLegacy ) ;
2013-01-30 09:59:22 +01:00
2013-03-02 09:07:47 +01:00
BOOST_FOREACH ( const Host : : Ptr & host , hg - > GetMembers ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Creating downtime for host " + host - > GetName ( ) ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr service = host - > GetCheckService ( ) ;
2013-02-09 01:16:43 +01:00
if ( service ) {
2013-11-09 22:08:26 +01:00
( void ) service - > AddDowntime ( arguments [ 6 ] , arguments [ 7 ] ,
2013-02-09 01:16:43 +01:00
Convert : : ToDouble ( arguments [ 1 ] ) , Convert : : ToDouble ( arguments [ 2 ] ) ,
Convert : : ToBool ( arguments [ 3 ] ) , triggeredBy , Convert : : ToDouble ( arguments [ 5 ] ) ) ;
}
2013-01-29 14:19:54 +01:00
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ScheduleHostgroupSvcDowntime ( double , const std : : vector < String > & arguments )
2013-01-29 14:19:54 +01:00
{
2013-01-30 13:23:00 +01:00
if ( arguments . size ( ) < 8 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 8 arguments. " ) ) ;
2013-01-30 13:23:00 +01:00
HostGroup : : Ptr hg = HostGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! hg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot schedule hostgroup service downtime for non-existent hostgroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-01-30 13:23:00 +01:00
String triggeredBy ;
int triggeredByLegacy = Convert : : ToLong ( arguments [ 4 ] ) ;
if ( triggeredByLegacy ! = 0 )
2013-02-09 01:16:43 +01:00
triggeredBy = Service : : GetDowntimeIDFromLegacyID ( triggeredByLegacy ) ;
2013-01-30 13:23:00 +01:00
/* Note: we can't just directly create downtimes for all the services by iterating
* over all hosts in the host group - otherwise we might end up creating multiple
* downtimes for some services . */
2013-03-16 21:18:53 +01:00
std : : set < Service : : Ptr > services ;
2013-01-30 13:23:00 +01:00
2013-03-02 09:07:47 +01:00
BOOST_FOREACH ( const Host : : Ptr & host , hg - > GetMembers ( ) ) {
2013-01-30 13:23:00 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , host - > GetServices ( ) ) {
services . insert ( service ) ;
}
}
BOOST_FOREACH ( const Service : : Ptr & service , services ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Creating downtime for service " + service - > GetName ( ) ) ;
2013-11-09 22:08:26 +01:00
( void ) service - > AddDowntime ( arguments [ 6 ] , arguments [ 7 ] ,
2013-01-30 13:23:00 +01:00
Convert : : ToDouble ( arguments [ 1 ] ) , Convert : : ToDouble ( arguments [ 2 ] ) ,
Convert : : ToBool ( arguments [ 3 ] ) , triggeredBy , Convert : : ToDouble ( arguments [ 5 ] ) ) ;
}
2013-01-29 14:19:54 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ScheduleServicegroupHostDowntime ( double , const std : : vector < String > & arguments )
2013-01-29 14:19:54 +01:00
{
2013-01-30 13:23:00 +01:00
if ( arguments . size ( ) < 8 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 8 arguments. " ) ) ;
2013-01-30 13:23:00 +01:00
ServiceGroup : : Ptr sg = ServiceGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! sg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot schedule servicegroup host downtime for non-existent servicegroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-01-30 13:23:00 +01:00
String triggeredBy ;
int triggeredByLegacy = Convert : : ToLong ( arguments [ 4 ] ) ;
if ( triggeredByLegacy ! = 0 )
2013-02-09 01:16:43 +01:00
triggeredBy = Service : : GetDowntimeIDFromLegacyID ( triggeredByLegacy ) ;
2013-01-30 13:23:00 +01:00
/* Note: we can't just directly create downtimes for all the hosts by iterating
* over all services in the service group - otherwise we might end up creating multiple
* downtimes for some hosts . */
2013-03-16 21:18:53 +01:00
std : : set < Service : : Ptr > services ;
2013-01-30 13:23:00 +01:00
2013-03-02 09:07:47 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , sg - > GetMembers ( ) ) {
2013-02-18 14:40:24 +01:00
Host : : Ptr host = service - > GetHost ( ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hcService = host - > GetCheckService ( ) ;
2013-02-09 01:16:43 +01:00
if ( hcService )
services . insert ( hcService ) ;
2013-01-30 13:23:00 +01:00
}
2013-02-09 01:16:43 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , services ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Creating downtime for service " + service - > GetName ( ) ) ;
2013-11-09 22:08:26 +01:00
( void ) service - > AddDowntime ( arguments [ 6 ] , arguments [ 7 ] ,
2013-01-30 13:23:00 +01:00
Convert : : ToDouble ( arguments [ 1 ] ) , Convert : : ToDouble ( arguments [ 2 ] ) ,
Convert : : ToBool ( arguments [ 3 ] ) , triggeredBy , Convert : : ToDouble ( arguments [ 5 ] ) ) ;
}
2013-01-29 14:19:54 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : ScheduleServicegroupSvcDowntime ( double , const std : : vector < String > & arguments )
2013-01-29 14:19:54 +01:00
{
if ( arguments . size ( ) < 8 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 8 arguments. " ) ) ;
2013-01-29 14:19:54 +01:00
ServiceGroup : : Ptr sg = ServiceGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! sg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot schedule servicegroup service downtime for non-existent servicegroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-01-30 09:59:22 +01:00
String triggeredBy ;
int triggeredByLegacy = Convert : : ToLong ( arguments [ 4 ] ) ;
if ( triggeredByLegacy ! = 0 )
2013-02-09 01:16:43 +01:00
triggeredBy = Service : : GetDowntimeIDFromLegacyID ( triggeredByLegacy ) ;
2013-01-30 09:59:22 +01:00
2013-03-02 09:07:47 +01:00
BOOST_FOREACH ( const Service : : Ptr & service , sg - > GetMembers ( ) ) {
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Creating downtime for service " + service - > GetName ( ) ) ;
2013-11-09 22:08:26 +01:00
( void ) service - > AddDowntime ( arguments [ 6 ] , arguments [ 7 ] ,
2013-01-29 14:19:54 +01:00
Convert : : ToDouble ( arguments [ 1 ] ) , Convert : : ToDouble ( arguments [ 2 ] ) ,
2013-01-30 09:59:22 +01:00
Convert : : ToBool ( arguments [ 3 ] ) , triggeredBy , Convert : : ToDouble ( arguments [ 5 ] ) ) ;
2013-01-29 14:19:54 +01:00
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : AddHostComment ( double , const std : : vector < String > & arguments )
2013-01-29 16:29:09 +01:00
{
if ( arguments . size ( ) < 4 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 4 arguments. " ) ) ;
2013-01-29 16:29:09 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot add host comment for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Creating comment for host " + host - > GetName ( ) ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr service = host - > GetCheckService ( ) ;
2013-02-18 14:40:24 +01:00
if ( service )
2013-02-09 01:16:43 +01:00
( void ) service - > AddComment ( CommentUser , arguments [ 2 ] , arguments [ 3 ] , 0 ) ;
2013-01-29 16:29:09 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DelHostComment ( double , const std : : vector < String > & arguments )
2013-01-29 16:29:09 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-29 16:29:09 +01:00
2013-01-30 09:59:22 +01:00
int id = Convert : : ToLong ( arguments [ 0 ] ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Removing comment ID " + arguments [ 0 ] ) ;
2013-02-09 01:16:43 +01:00
String rid = Service : : GetCommentIDFromLegacyID ( id ) ;
Service : : RemoveComment ( rid ) ;
2013-01-29 16:29:09 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : AddSvcComment ( double , const std : : vector < String > & arguments )
2013-01-29 16:29:09 +01:00
{
if ( arguments . size ( ) < 5 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 5 arguments. " ) ) ;
2013-01-29 16:29:09 +01:00
2013-02-08 15:38:22 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-01-29 16:29:09 +01:00
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot add service comment for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Creating comment for service " + service - > GetName ( ) ) ;
2013-02-09 01:16:43 +01:00
( void ) service - > AddComment ( CommentUser , arguments [ 3 ] , arguments [ 4 ] , 0 ) ;
2013-01-29 16:29:09 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DelSvcComment ( double , const std : : vector < String > & arguments )
2013-01-29 16:29:09 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-29 16:29:09 +01:00
2013-01-30 09:59:22 +01:00
int id = Convert : : ToLong ( arguments [ 0 ] ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Removing comment ID " + arguments [ 0 ] ) ;
2013-01-30 09:59:22 +01:00
2013-02-09 01:16:43 +01:00
String rid = Service : : GetCommentIDFromLegacyID ( id ) ;
Service : : RemoveComment ( rid ) ;
2013-01-29 16:29:09 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DelAllHostComments ( double , const std : : vector < String > & arguments )
2013-01-29 16:29:09 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-01-29 16:29:09 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot delete all host comments for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Removing all comments for host " + host - > GetName ( ) ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr service = host - > GetCheckService ( ) ;
2013-02-18 14:40:24 +01:00
if ( service )
2013-02-09 01:16:43 +01:00
service - > RemoveAllComments ( ) ;
2013-01-29 16:29:09 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DelAllSvcComments ( double , const std : : vector < String > & arguments )
2013-01-29 16:29:09 +01:00
{
if ( arguments . size ( ) < 2 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-01-29 16:29:09 +01:00
2013-02-08 15:38:22 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-01-29 16:29:09 +01:00
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot delete all service comments for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Removing all comments for service " + service - > GetName ( ) ) ;
2013-02-09 01:16:43 +01:00
service - > RemoveAllComments ( ) ;
2013-01-29 16:29:09 +01:00
}
2013-02-09 15:20:10 +01:00
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : SendCustomHostNotification ( double , const std : : vector < String > & arguments )
2013-02-09 15:20:10 +01:00
{
if ( arguments . size ( ) < 4 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 4 arguments. " ) ) ;
2013-02-09 15:20:10 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot send custom host notification for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-21 13:22:26 +01:00
int options = Convert : : ToLong ( arguments [ 1 ] ) ;
2013-02-09 15:20:10 +01:00
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Sending custom notification for host " + host - > GetName ( ) ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr service = host - > GetCheckService ( ) ;
2013-03-21 13:22:26 +01:00
if ( service ) {
if ( options & 2 ) {
ObjectLock olock ( service ) ;
service - > SetForceNextNotification ( true ) ;
}
2013-08-20 11:06:04 +02:00
Service : : OnNotificationsRequested ( service , NotificationCustom , service - > GetLastCheckResult ( ) , arguments [ 2 ] , arguments [ 3 ] ) ;
2013-03-21 13:22:26 +01:00
}
2013-02-09 15:20:10 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : SendCustomSvcNotification ( double , const std : : vector < String > & arguments )
2013-02-09 15:20:10 +01:00
{
if ( arguments . size ( ) < 5 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 5 arguments. " ) ) ;
2013-02-09 15:20:10 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot send custom service notification for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-21 13:22:26 +01:00
int options = Convert : : ToLong ( arguments [ 2 ] ) ;
2013-02-09 15:20:10 +01:00
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Sending custom notification for service " + service - > GetName ( ) ) ;
2013-03-21 13:22:26 +01:00
if ( options & 2 ) {
ObjectLock olock ( service ) ;
service - > SetForceNextNotification ( true ) ;
}
2013-08-20 11:06:04 +02:00
Service : : OnNotificationsRequested ( service , NotificationCustom , service - > GetLastCheckResult ( ) , arguments [ 3 ] , arguments [ 4 ] ) ;
2013-02-09 15:20:10 +01:00
}
2013-02-26 12:37:25 +01:00
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DelayHostNotification ( double , const std : : vector < String > & arguments )
2013-02-26 12:37:25 +01:00
{
if ( arguments . size ( ) < 2 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-02-26 12:37:25 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot delay host notification for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Delaying notifications for host " + host - > GetName ( ) ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-03-06 11:03:50 +01:00
if ( ! hc )
return ;
2013-03-20 10:08:27 +01:00
BOOST_FOREACH ( const Notification : : Ptr & notification , hc - > GetNotifications ( ) ) {
ObjectLock olock ( notification ) ;
2013-03-06 11:03:50 +01:00
2013-03-20 10:08:27 +01:00
notification - > SetNextNotification ( Convert : : ToDouble ( arguments [ 1 ] ) ) ;
2013-02-26 12:37:25 +01:00
}
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DelaySvcNotification ( double , const std : : vector < String > & arguments )
2013-02-26 12:37:25 +01:00
{
if ( arguments . size ( ) < 3 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 3 arguments. " ) ) ;
2013-02-26 12:37:25 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot delay service notification for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Delaying notifications for service " + service - > GetName ( ) ) ;
2013-03-06 11:03:50 +01:00
2013-03-20 10:08:27 +01:00
BOOST_FOREACH ( const Notification : : Ptr & notification , service - > GetNotifications ( ) ) {
ObjectLock olock ( notification ) ;
2013-03-06 11:03:50 +01:00
2013-03-20 10:08:27 +01:00
notification - > SetNextNotification ( Convert : : ToDouble ( arguments [ 2 ] ) ) ;
2013-03-06 11:03:50 +01:00
}
2013-02-26 12:37:25 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : EnableHostNotifications ( double , const std : : vector < String > & arguments )
2013-02-26 12:37:25 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-02-26 12:37:25 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable host notifications for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Enabling notifications for host ' " + arguments [ 0 ] + " ' " ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-02-26 12:37:25 +01:00
2013-03-06 11:03:50 +01:00
if ( ! hc )
return ;
{
ObjectLock olock ( hc ) ;
2013-02-26 12:37:25 +01:00
hc - > SetEnableNotifications ( true ) ;
2013-03-06 11:03:50 +01:00
}
2013-02-26 12:37:25 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DisableHostNotifications ( double , const std : : vector < String > & arguments )
2013-02-26 12:37:25 +01:00
{
if ( arguments . size ( ) < 1 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
2013-02-26 12:37:25 +01:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable host notifications for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Disabling notifications for host ' " + arguments [ 0 ] + " ' " ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-02-26 12:37:25 +01:00
2013-03-06 11:03:50 +01:00
if ( ! hc )
return ;
{
ObjectLock olock ( hc ) ;
2013-02-26 12:37:25 +01:00
hc - > SetEnableNotifications ( false ) ;
2013-03-06 11:03:50 +01:00
}
2013-02-26 12:37:25 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : EnableSvcNotifications ( double , const std : : vector < String > & arguments )
2013-02-26 12:37:25 +01:00
{
if ( arguments . size ( ) < 2 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-02-26 12:37:25 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable service notifications for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Enabling notifications for service ' " + arguments [ 1 ] + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnableNotifications ( true ) ;
}
2013-02-26 12:37:25 +01:00
}
2013-03-16 21:18:53 +01:00
void ExternalCommandProcessor : : DisableSvcNotifications ( double , const std : : vector < String > & arguments )
2013-02-26 12:37:25 +01:00
{
if ( arguments . size ( ) < 2 )
2013-03-16 21:18:53 +01:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-02-26 12:37:25 +01:00
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable service notifications for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-03-16 21:18:53 +01:00
Log ( LogInformation , " icinga " , " Disabling notifications for service ' " + arguments [ 1 ] + " ' " ) ;
2013-03-06 11:03:50 +01:00
{
ObjectLock olock ( service ) ;
service - > SetEnableNotifications ( false ) ;
}
2013-02-26 12:37:25 +01:00
}
2013-04-15 10:23:06 +02:00
void ExternalCommandProcessor : : DisableHostgroupHostChecks ( double , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 1 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 arguments. " ) ) ;
HostGroup : : Ptr hg = HostGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! hg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable hostgroup host checks for non-existent hostgroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-04-15 10:23:06 +02:00
BOOST_FOREACH ( const Host : : Ptr & host , hg - > GetMembers ( ) ) {
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-04-15 10:23:06 +02:00
if ( ! hc )
continue ;
Log ( LogInformation , " icinga " , " Disabling active checks for host ' " + host - > GetName ( ) + " ' " ) ;
{
ObjectLock olock ( hc ) ;
hc - > SetEnableActiveChecks ( false ) ;
}
}
}
void ExternalCommandProcessor : : DisableHostgroupPassiveHostChecks ( double , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 1 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 arguments. " ) ) ;
HostGroup : : Ptr hg = HostGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! hg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable hostgroup passive host checks for non-existent hostgroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-04-15 10:23:06 +02:00
BOOST_FOREACH ( const Host : : Ptr & host , hg - > GetMembers ( ) ) {
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-04-15 10:23:06 +02:00
if ( ! hc )
continue ;
Log ( LogInformation , " icinga " , " Disabling active checks for host ' " + host - > GetName ( ) + " ' " ) ;
{
ObjectLock olock ( hc ) ;
hc - > SetEnablePassiveChecks ( false ) ;
}
}
}
void ExternalCommandProcessor : : DisableServicegroupHostChecks ( double , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 1 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 arguments. " ) ) ;
ServiceGroup : : Ptr sg = ServiceGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! sg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable servicegroup host checks for non-existent servicegroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-04-15 10:23:06 +02:00
BOOST_FOREACH ( const Service : : Ptr & service , sg - > GetMembers ( ) ) {
Host : : Ptr host = service - > GetHost ( ) ;
if ( ! host )
continue ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-04-15 10:23:06 +02:00
if ( ! hc )
continue ;
Log ( LogInformation , " icinga " , " Disabling active checks for host ' " + host - > GetName ( ) + " ' " ) ;
{
ObjectLock olock ( hc ) ;
hc - > SetEnableActiveChecks ( false ) ;
}
}
}
void ExternalCommandProcessor : : DisableServicegroupPassiveHostChecks ( double , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 1 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 arguments. " ) ) ;
ServiceGroup : : Ptr sg = ServiceGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! sg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable servicegroup passive host checks for non-existent servicegroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-04-15 10:23:06 +02:00
BOOST_FOREACH ( const Service : : Ptr & service , sg - > GetMembers ( ) ) {
Host : : Ptr host = service - > GetHost ( ) ;
if ( ! host )
continue ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-04-15 10:23:06 +02:00
if ( ! hc )
continue ;
Log ( LogInformation , " icinga " , " Disabling active checks for host ' " + host - > GetName ( ) + " ' " ) ;
{
ObjectLock olock ( hc ) ;
hc - > SetEnablePassiveChecks ( false ) ;
}
}
}
void ExternalCommandProcessor : : EnableHostgroupHostChecks ( double , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 1 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 arguments. " ) ) ;
HostGroup : : Ptr hg = HostGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! hg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable hostgroup host checks for non-existent hostgroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-04-15 10:23:06 +02:00
BOOST_FOREACH ( const Host : : Ptr & host , hg - > GetMembers ( ) ) {
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-04-15 10:23:06 +02:00
if ( ! hc )
continue ;
Log ( LogInformation , " icinga " , " Enabling active checks for host ' " + host - > GetName ( ) + " ' " ) ;
{
ObjectLock olock ( hc ) ;
hc - > SetEnableActiveChecks ( true ) ;
}
}
}
void ExternalCommandProcessor : : EnableHostgroupPassiveHostChecks ( double , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 1 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 arguments. " ) ) ;
}
void ExternalCommandProcessor : : EnableServicegroupHostChecks ( double , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 1 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 arguments. " ) ) ;
ServiceGroup : : Ptr sg = ServiceGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! sg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable servicegroup host checks for non-existent servicegroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-04-15 10:23:06 +02:00
BOOST_FOREACH ( const Service : : Ptr & service , sg - > GetMembers ( ) ) {
Host : : Ptr host = service - > GetHost ( ) ;
if ( ! host )
continue ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-04-15 10:23:06 +02:00
if ( ! hc )
continue ;
Log ( LogInformation , " icinga " , " Enabling active checks for host ' " + host - > GetName ( ) + " ' " ) ;
{
ObjectLock olock ( hc ) ;
hc - > SetEnableActiveChecks ( true ) ;
}
}
}
void ExternalCommandProcessor : : EnableServicegroupPassiveHostChecks ( double , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 1 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 arguments. " ) ) ;
ServiceGroup : : Ptr sg = ServiceGroup : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! sg )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable servicegroup passive host checks for non-existent servicegroup ' " + arguments [ 0 ] + " ' " ) ) ;
2013-04-15 10:23:06 +02:00
BOOST_FOREACH ( const Service : : Ptr & service , sg - > GetMembers ( ) ) {
Host : : Ptr host = service - > GetHost ( ) ;
if ( ! host )
continue ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-04-15 10:23:06 +02:00
if ( ! hc )
continue ;
Log ( LogInformation , " icinga " , " Enabling active checks for host ' " + host - > GetName ( ) + " ' " ) ;
{
ObjectLock olock ( hc ) ;
hc - > SetEnablePassiveChecks ( false ) ;
}
}
}
2013-06-21 10:28:21 +02:00
void ExternalCommandProcessor : : EnableHostFlapping ( double , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 1 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable host flapping for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-06-21 10:28:21 +02:00
Log ( LogInformation , " icinga " , " Enabling flapping detection for host ' " + arguments [ 0 ] + " ' " ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-06-21 10:28:21 +02:00
if ( ! hc )
return ;
{
ObjectLock olock ( hc ) ;
hc - > SetEnableFlapping ( true ) ;
}
}
void ExternalCommandProcessor : : DisableHostFlapping ( double , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 1 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable host flapping for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-06-21 10:28:21 +02:00
Log ( LogInformation , " icinga " , " Disabling flapping detection for host ' " + arguments [ 0 ] + " ' " ) ;
2013-09-25 09:12:15 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-06-21 10:28:21 +02:00
if ( ! hc )
return ;
{
ObjectLock olock ( hc ) ;
hc - > SetEnableFlapping ( false ) ;
}
}
void ExternalCommandProcessor : : EnableSvcFlapping ( double , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 2 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable service flapping for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-06-21 10:28:21 +02:00
Log ( LogInformation , " icinga " , " Enabling flapping detection for service ' " + arguments [ 1 ] + " ' " ) ;
{
ObjectLock olock ( service ) ;
service - > SetEnableFlapping ( true ) ;
}
}
void ExternalCommandProcessor : : DisableSvcFlapping ( double , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 2 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
2013-09-27 12:24:30 +02:00
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable service flapping for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-06-21 10:28:21 +02:00
Log ( LogInformation , " icinga " , " Disabling flapping detection for service ' " + arguments [ 1 ] + " ' " ) ;
{
ObjectLock olock ( service ) ;
service - > SetEnableFlapping ( false ) ;
}
2013-07-01 11:17:58 +02:00
}
2013-10-08 11:57:35 +02:00
void ExternalCommandProcessor : : EnableNotifications ( double time , const std : : vector < String > & arguments )
{
Log ( LogInformation , " icinga " , " Globally enabling notifications. " ) ;
IcingaApplication : : GetInstance ( ) - > SetEnableNotifications ( true ) ;
}
void ExternalCommandProcessor : : DisableNotifications ( double time , const std : : vector < String > & arguments )
{
Log ( LogInformation , " icinga " , " Globally disabling notifications. " ) ;
IcingaApplication : : GetInstance ( ) - > SetEnableNotifications ( false ) ;
}
void ExternalCommandProcessor : : EnableFlapDetection ( double time , const std : : vector < String > & arguments )
{
Log ( LogInformation , " icinga " , " Globally enabling flap detection. " ) ;
IcingaApplication : : GetInstance ( ) - > SetEnableFlapping ( true ) ;
}
void ExternalCommandProcessor : : DisableFlapDetection ( double time , const std : : vector < String > & arguments )
{
Log ( LogInformation , " icinga " , " Globally disabling flap detection. " ) ;
IcingaApplication : : GetInstance ( ) - > SetEnableFlapping ( false ) ;
}
void ExternalCommandProcessor : : EnableEventHandlers ( double time , const std : : vector < String > & arguments )
{
Log ( LogInformation , " icinga " , " Globally enabling event handlers. " ) ;
IcingaApplication : : GetInstance ( ) - > SetEnableEventHandlers ( true ) ;
}
void ExternalCommandProcessor : : DisableEventHandlers ( double time , const std : : vector < String > & arguments )
{
Log ( LogInformation , " icinga " , " Globally disabling event handlers. " ) ;
IcingaApplication : : GetInstance ( ) - > SetEnableEventHandlers ( false ) ;
}
void ExternalCommandProcessor : : EnablePerformanceData ( double time , const std : : vector < String > & arguments )
{
Log ( LogInformation , " icinga " , " Globally enabling performance data processing. " ) ;
IcingaApplication : : GetInstance ( ) - > SetEnablePerfdata ( true ) ;
}
void ExternalCommandProcessor : : DisablePerformanceData ( double time , const std : : vector < String > & arguments )
{
Log ( LogInformation , " icinga " , " Globally disabling performance data processing. " ) ;
IcingaApplication : : GetInstance ( ) - > SetEnablePerfdata ( false ) ;
}
void ExternalCommandProcessor : : StartExecutingSvcChecks ( double time , const std : : vector < String > & arguments )
{
Log ( LogInformation , " icinga " , " Globally enabling checks. " ) ;
IcingaApplication : : GetInstance ( ) - > SetEnableChecks ( true ) ;
}
void ExternalCommandProcessor : : StopExecutingSvcChecks ( double time , const std : : vector < String > & arguments )
{
Log ( LogInformation , " icinga " , " Globally disabling checks. " ) ;
IcingaApplication : : GetInstance ( ) - > SetEnableChecks ( false ) ;
}
2013-10-16 11:46:54 +02:00
2013-10-16 12:09:45 +02:00
void ExternalCommandProcessor : : ChangeSvcModattr ( double time , const std : : vector < String > & arguments )
2013-10-16 11:46:54 +02:00
{
if ( arguments . size ( ) < 3 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 3 arguments. " ) ) ;
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot update modified attributes for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
int modifiedAttributes = Convert : : ToLong ( arguments [ 2 ] ) ;
Log ( LogInformation , " icinga " , " Updating modified attributes for service ' " + arguments [ 1 ] + " ' " ) ;
{
ObjectLock olock ( service ) ;
service - > SetModifiedAttributes ( modifiedAttributes ) ;
}
2013-10-16 12:08:36 +02:00
}
2013-10-16 12:09:45 +02:00
void ExternalCommandProcessor : : ChangeHostModattr ( double time , const std : : vector < String > & arguments )
2013-10-16 12:08:36 +02:00
{
2013-10-16 13:12:38 +02:00
if ( arguments . size ( ) < 2 )
2013-10-16 12:08:36 +02:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 3 arguments. " ) ) ;
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot update modified attributes for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
Log ( LogInformation , " icinga " , " Updating modified attributes for for host ' " + arguments [ 0 ] + " ' " ) ;
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-10-16 13:02:21 +02:00
int modifiedAttributes = Convert : : ToLong ( arguments [ 1 ] ) ;
2013-10-16 12:08:36 +02:00
{
2013-10-16 12:10:31 +02:00
ObjectLock olock ( hc ) ;
2013-10-16 12:08:36 +02:00
hc - > SetModifiedAttributes ( modifiedAttributes ) ;
}
2013-10-16 13:02:21 +02:00
}
void ExternalCommandProcessor : : ChangeNormalSvcCheckInterval ( double time , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 3 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 3 arguments. " ) ) ;
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot update check interval for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-10-16 13:07:59 +02:00
double interval = Convert : : ToDouble ( arguments [ 2 ] ) ;
2013-10-16 13:02:21 +02:00
Log ( LogInformation , " icinga " , " Updating check interval for service ' " + arguments [ 1 ] + " ' " ) ;
{
ObjectLock olock ( service ) ;
service - > SetCheckInterval ( interval * 60 ) ;
}
}
void ExternalCommandProcessor : : ChangeNormalHostCheckInterval ( double time , const std : : vector < String > & arguments )
{
2013-10-16 13:12:38 +02:00
if ( arguments . size ( ) < 2 )
2013-10-16 13:02:21 +02:00
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 3 arguments. " ) ) ;
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot update check interval for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
Log ( LogInformation , " icinga " , " Updating check interval for for host ' " + arguments [ 0 ] + " ' " ) ;
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-10-16 13:07:59 +02:00
double interval = Convert : : ToDouble ( arguments [ 1 ] ) ;
2013-10-16 13:02:21 +02:00
{
ObjectLock olock ( hc ) ;
2013-10-16 16:08:00 +02:00
hc - > SetCheckInterval ( interval * 60 ) ;
2013-10-16 13:02:21 +02:00
}
}
void ExternalCommandProcessor : : ChangeRetrySvcCheckInterval ( double time , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 3 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 3 arguments. " ) ) ;
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot update retry interval for non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-10-16 13:07:59 +02:00
double interval = Convert : : ToDouble ( arguments [ 2 ] ) ;
2013-10-16 13:02:21 +02:00
Log ( LogInformation , " icinga " , " Updating retry interval for service ' " + arguments [ 1 ] + " ' " ) ;
{
ObjectLock olock ( service ) ;
service - > SetRetryInterval ( interval * 60 ) ;
}
}
void ExternalCommandProcessor : : ChangeRetryHostCheckInterval ( double time , const std : : vector < String > & arguments )
{
2013-10-16 13:12:38 +02:00
if ( arguments . size ( ) < 2 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
2013-10-16 13:02:21 +02:00
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot update retry interval for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
2013-10-16 13:12:38 +02:00
Log ( LogInformation , " icinga " , " Updating retry interval for for host ' " + arguments [ 0 ] + " ' " ) ;
2013-10-16 13:02:21 +02:00
Service : : Ptr hc = host - > GetCheckService ( ) ;
2013-10-16 13:07:59 +02:00
double interval = Convert : : ToDouble ( arguments [ 1 ] ) ;
2013-10-16 13:02:21 +02:00
{
ObjectLock olock ( hc ) ;
hc - > SetRetryInterval ( interval * 60 ) ;
}
2013-10-16 15:20:14 +02:00
}
void ExternalCommandProcessor : : EnableHostEventHandler ( double time , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 1 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable event handler for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
Service : : Ptr hc = host - > GetCheckService ( ) ;
Log ( LogInformation , " icinga " , " Enabling event handler for host ' " + arguments [ 0 ] + " ' " ) ;
{
ObjectLock olock ( hc ) ;
hc - > SetEnableEventHandler ( true ) ;
}
}
void ExternalCommandProcessor : : DisableHostEventHandler ( double time , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 1 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 1 argument. " ) ) ;
Host : : Ptr host = Host : : GetByName ( arguments [ 0 ] ) ;
if ( ! host )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable event handler for non-existent host ' " + arguments [ 0 ] + " ' " ) ) ;
Service : : Ptr hc = host - > GetCheckService ( ) ;
Log ( LogInformation , " icinga " , " Disabling event handler for host ' " + arguments [ 0 ] + " ' " ) ;
{
ObjectLock olock ( hc ) ;
hc - > SetEnableEventHandler ( false ) ;
}
}
void ExternalCommandProcessor : : EnableSvcEventHandler ( double time , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 2 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot enable event handlerfor non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
Log ( LogInformation , " icinga " , " Enabling event handler for service ' " + arguments [ 1 ] + " ' " ) ;
{
ObjectLock olock ( service ) ;
service - > SetEnableEventHandler ( true ) ;
}
}
void ExternalCommandProcessor : : DisableSvcEventHandler ( double time , const std : : vector < String > & arguments )
{
if ( arguments . size ( ) < 2 )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Expected 2 arguments. " ) ) ;
Service : : Ptr service = Service : : GetByNamePair ( arguments [ 0 ] , arguments [ 1 ] ) ;
if ( ! service )
BOOST_THROW_EXCEPTION ( std : : invalid_argument ( " Cannot disable event handlerfor non-existent service ' " + arguments [ 1 ] + " ' on host ' " + arguments [ 0 ] + " ' " ) ) ;
Log ( LogInformation , " icinga " , " Disabling event handler for service ' " + arguments [ 1 ] + " ' " ) ;
{
ObjectLock olock ( service ) ;
service - > SetEnableEventHandler ( false ) ;
}
}