mirror of https://github.com/Icinga/icinga2.git
parent
53c93f459c
commit
afd6af39d5
|
@ -0,0 +1,52 @@
|
|||
###API ACTIONS
|
||||
|
||||
|
||||
Action name | Parameters | Target types | Notes
|
||||
---------------------------------------|-----------------------------------|--------------------------|-----------------------
|
||||
process-check-result | exit_status; plugin_output; check_source; performance_data[]; check_command[]; execution_end; execution_start; schedule_end; schedule_start | Service; Host | -
|
||||
reschedule-check | {next_check}; {(force_check)} | Service; Host | -
|
||||
acknowledge-problem | author; comment; {timestamp}; {(sticky)}; {(notify)} | Service; Host | -
|
||||
remove-acknowledgement | - | Service; Host | -
|
||||
add-comment | author; comment | Service; Host | -
|
||||
remove-comment | comment_id | - | -
|
||||
remove-all-comments | - | Service; Host | -
|
||||
delay-notifications | timestamp | Service;Host | -
|
||||
add-downtime | start_time; end_time; duration; author; comment; {trigger_id}; {(fixed)} | Service; Host; ServiceGroup; HostGroup | Downtime for all services on host x?
|
||||
remove-downtime | downtime_id | - | remove by name?
|
||||
send-custom-notification | options[]; author; comment | Service; Host | -
|
||||
|
||||
enable-passive-checks | - | Service; Host; ServiceGroup; HostGroup | "System" as target?
|
||||
disable-passive-checks | - | Service; Host; ServiceGroup; HostGroup | diable all passive checks for services of hosts y in hostgroup x?
|
||||
enable-active-checks | - | Host; HostGroup | -
|
||||
disable-active-checks | - | Host; HostGroup | -
|
||||
enable-notifications | - | Service; Host; ServiceGroup; HostGroup | Enable all notifications for services of host x?
|
||||
disable-notifications | - | Service; Host; ServiceGroup; HostGroup | -
|
||||
enable-flap-detection | - | Service; Host; ServiceGroup; HostGroup | -
|
||||
disable-flap-detection | - | Service; Host; ServiceGroup; HostGroup | -
|
||||
enable-event-handler | - | Service; Host | -
|
||||
disable-event-handler | - | Service; Host | -
|
||||
|
||||
change-custom-vor | var_name; var_value | Service; Host; User; Checkcommand; Eventcommand; Notificationcommand
|
||||
change-mod-attribute | mod_value | Service; Host; User; Checkcommand; Eventcommand; Notificationcommand
|
||||
change-event-handler | {event_command_name} | Service; Host | -
|
||||
change-check-command | check_command_name | Service; Host | -
|
||||
change-max-check-attempts | max_check_attempts | Service; Host | -
|
||||
change-check-interval | check_interval | Service; Host | -
|
||||
change-retry-interval | retry_interval | Service; Host | -
|
||||
change-check-period | time_period_name | Service; Host | -
|
||||
|
||||
enable-all-notifications | - | - | -
|
||||
disable-all-notifications | - | - | -
|
||||
enable-all-flap-detection | - | - | -
|
||||
disable-all-flap-detection | - | - | -
|
||||
enable-all-event-handlers | - | - | -
|
||||
disable-all-event-handlers | - | - | -
|
||||
enable-all-performance-data | - | - | -
|
||||
disable-all-performance-data | - | - | -
|
||||
start-all-executing-svc-checks | - | - | -
|
||||
stop-all-executing-svc-checks | - | - | -
|
||||
start-all-executing-host-checks | - | - | -
|
||||
stop-all-executing-host-checks | - | - | -
|
||||
shutdown-process | - | - | -
|
||||
restart-process | - | - | -
|
||||
process-file | - | - | -
|
|
@ -19,7 +19,12 @@
|
|||
|
||||
#include "icinga/apiactions.hpp"
|
||||
#include "icinga/service.hpp"
|
||||
#include "icinga/servicegroup.hpp"
|
||||
#include "icinga/hostgroup.hpp"
|
||||
#include "icinga/pluginutility.hpp"
|
||||
#include "icinga/checkcommand.hpp"
|
||||
#include "icinga/eventcommand.hpp"
|
||||
#include "icinga/notificationcommand.hpp"
|
||||
#include "remote/apiaction.hpp"
|
||||
#include "remote/httputility.hpp"
|
||||
#include "base/utility.hpp"
|
||||
|
@ -27,16 +32,64 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
Dictionary::Ptr ApiActions::CreateResult(const int code, const String& status) {
|
||||
REGISTER_APIACTION(process_check_result, "Service;Host", &ApiActions::ProcessCheckResult);
|
||||
REGISTER_APIACTION(reschedule_check, "Service;Host", &ApiActions::RescheduleCheck);
|
||||
REGISTER_APIACTION(delay_notifications, "Service;Host", &ApiActions::DelayNotifications); //TODO groups
|
||||
|
||||
REGISTER_APIACTION(acknowledge_problem, "Service;Host", &ApiActions::AcknowledgeProblem);
|
||||
REGISTER_APIACTION(remove_acknowledgement, "Service;Host", &ApiActions::RemoveAcknowledgement);
|
||||
REGISTER_APIACTION(add_comment, "Service;Host", &ApiActions::AddComment);
|
||||
//REGISTER_APIACTION(remove_comment, "", &ApiActions::RemoveComment); TODO Actions without objects
|
||||
REGISTER_APIACTION(remove_all_comments, "Service;Host", &ApiActions::RemoveAllComments);
|
||||
REGISTER_APIACTION(schedule_downtime, "Service;Host", &ApiActions::ScheduleDowntime); //TODO groups
|
||||
//REGISTER_APIACTION(remove_downtime, "Service;Host", &ApiActions::RemoveDowntime); //TODO groups
|
||||
|
||||
REGISTER_APIACTION(enable_passive_checks, "Service;Host", &ApiActions::EnablePassiveChecks); //TODO groups
|
||||
REGISTER_APIACTION(disable_passive_checks, "Service;Host", &ApiActions::DisablePassiveChecks); //TODO groups
|
||||
REGISTER_APIACTION(enable_active_checks, "Host", &ApiActions::EnableActiveChecks); //TODO groups
|
||||
REGISTER_APIACTION(disable_active_checks, "Host", &ApiActions::DisableActiveChecks); //TODO groups
|
||||
REGISTER_APIACTION(enable_notifications, "Service;Host", &ApiActions::EnableNotifications);
|
||||
REGISTER_APIACTION(disable_notifications, "Service;Host", &ApiActions::DisableNotifications);
|
||||
REGISTER_APIACTION(enable_flap_detection, "Service;Host", &ApiActions::EnableFlapDetection);
|
||||
REGISTER_APIACTION(disable_flap_detection, "Service;Host", &ApiActions::DisableFlapDetection);
|
||||
|
||||
/*
|
||||
REGISTER_APIACTION(change_event_handler, "Service;Host", &ApiActions::ChangeEventHandler);
|
||||
REGISTER_APIACTION(change_check_command, "Service;Host", &ApiActions::ChangeCheckCommand);
|
||||
REGISTER_APIACTION(change_max_check_attempts, "Service;Host", &ApiActions::ChangeMaxCheckAttempts);
|
||||
REGISTER_APIACTION(change_check_period, "Service;Host", &ApiActions::ChangeCheckPeriod);
|
||||
REGISTER_APIACTION(change_check_interval, "Service;Host", &ApiActions::ChangeCheckInterval);
|
||||
REGISTER_APIACTION(change_retry_interval, "Service;Host", &ApiActions::ChangeRetryInterval);
|
||||
*/
|
||||
/*
|
||||
REGISTER_APIACTION(enable_notifications, "", &ApiActions::EnableNotifications);
|
||||
REGISTER_APIACTION(disable_notifications, "", &ApiActions::DisableNotifications);
|
||||
REGISTER_APIACTION(enable_flap_detection, "", &ApiActions::EnableFlapDetection);
|
||||
REGISTER_APIACTION(disable_flap_detection, "", &ApiActions::DisableFlapDetection);
|
||||
REGISTER_APIACTION(enable_event_handlers, "", &ApiActions::EnableEventHandlers);
|
||||
REGISTER_APIACTION(disable_event_handlers, "", &ApiActions::DisableEventHandlers);
|
||||
REGISTER_APIACTION(enable_performance_data, "", &ApiActions::EnablePerformanceData);
|
||||
REGISTER_APIACTION(disable_performance_data, "", &ApiActions::DisablePerformanceData);
|
||||
REGISTER_APIACTION(start_executing_svc_checks, "", &ApiActions::StartExecutingSvcChecks);
|
||||
REGISTER_APIACTION(stop_executing_svc_checks, "", &ApiActions::StopExecutingSvcChecks);
|
||||
REGISTER_APIACTION(start_executing_host_checks, "", &ApiActions::StartExecutingHostChecks);
|
||||
REGISTER_APIACTION(stop_executing_host_checks, "", &ApiActions::StopExecutingHostChecks);
|
||||
*/
|
||||
|
||||
/*
|
||||
REGISTER_APIACTION(shutdown_process, "", &ApiActions::ShutdownProcess);
|
||||
REGISTER_APIACTION(restart_process, "", &ApiActions::RestartProcess);
|
||||
REGISTER_APIACTION(process_file, "", &ApiActions::ProcessFile);
|
||||
*/
|
||||
|
||||
Dictionary::Ptr ApiActions::CreateResult(int code, const String& status)
|
||||
{
|
||||
Dictionary::Ptr result = new Dictionary();
|
||||
result->Set("code", code);
|
||||
result->Set("status", status);
|
||||
return result;
|
||||
}
|
||||
|
||||
REGISTER_APIACTION(reschedule_check, "Service;Host", &ApiActions::RescheduleCheck);
|
||||
REGISTER_APIACTION(process_check_result, "Service;Host", &ApiActions::ProcessCheckResult);
|
||||
|
||||
Dictionary::Ptr ApiActions::RescheduleCheck(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
@ -68,8 +121,6 @@ Dictionary::Ptr ApiActions::ProcessCheckResult(const ConfigObject::Ptr& object,
|
|||
if (!checkable->GetEnablePassiveChecks())
|
||||
return ApiActions::CreateResult(403, "Passive checks are disabled for " + checkable->GetName());
|
||||
|
||||
String name;
|
||||
|
||||
Host::Ptr host;
|
||||
Service::Ptr service;
|
||||
tie(host, service) = GetHostService(checkable);
|
||||
|
@ -82,28 +133,26 @@ Dictionary::Ptr ApiActions::ProcessCheckResult(const ConfigObject::Ptr& object,
|
|||
ServiceState state;
|
||||
|
||||
if (!service) {
|
||||
name = host->GetName();
|
||||
if (exitStatus == 0)
|
||||
state = ServiceOK;
|
||||
else if (exitStatus == 1)
|
||||
state = ServiceCritical;
|
||||
else
|
||||
return ApiActions::CreateResult(403, "Invalid 'exit_status' for Host " + name);
|
||||
return ApiActions::CreateResult(403, "Invalid 'exit_status' for Host " + checkable->GetName());
|
||||
} else {
|
||||
state = PluginUtility::ExitStatusToState(exitStatus);
|
||||
name = service->GetName() + "!" + service->GetHostName();
|
||||
}
|
||||
|
||||
if (!params->Contains("output"))
|
||||
return ApiActions::CreateResult(400, "Parameter 'output' is required");
|
||||
if (!params->Contains("plugin_output"))
|
||||
return ApiActions::CreateResult(403, "Parameter 'plugin_output' is required");
|
||||
|
||||
CheckResult::Ptr cr = new CheckResult();
|
||||
cr->SetOutput(HttpUtility::GetLastParameter(params, "output"));
|
||||
cr->SetOutput(HttpUtility::GetLastParameter(params, "plugin_output"));
|
||||
cr->SetState(state);
|
||||
|
||||
cr->SetCheckSource(HttpUtility::GetLastParameter(params, "check_source"));
|
||||
cr->SetPerformanceData(HttpUtility::GetLastParameter(params, "performance_data"));
|
||||
cr->SetCommand(HttpUtility::GetLastParameter(params, "command"));
|
||||
cr->SetPerformanceData(params->Get("performance_data"));
|
||||
cr->SetCommand(params->Get("check_command"));
|
||||
cr->SetExecutionEnd(HttpUtility::GetLastParameter(params, "execution_end"));
|
||||
cr->SetExecutionStart(HttpUtility::GetLastParameter(params, "execution_start"));
|
||||
cr->SetScheduleEnd(HttpUtility::GetLastParameter(params, "schedule_end"));
|
||||
|
@ -111,14 +160,513 @@ Dictionary::Ptr ApiActions::ProcessCheckResult(const ConfigObject::Ptr& object,
|
|||
|
||||
checkable->ProcessCheckResult(cr);
|
||||
|
||||
if (!service) {
|
||||
ObjectLock olock(checkable);
|
||||
/* 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. */
|
||||
checkable->SetNextCheck(Utility::GetTime() + checkable->GetCheckInterval());
|
||||
|
||||
/* 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. */
|
||||
checkable->SetNextCheck(Utility::GetTime() + checkable->GetCheckInterval());
|
||||
return ApiActions::CreateResult(200, "Successfully processed check result for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::EnablePassiveChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
//TODO check if group undso
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot enable passive checks for non-existent object");
|
||||
|
||||
checkable->SetEnablePassiveChecks(true);
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully enabled passive checks for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::DisablePassiveChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
//TODO check if group undso
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot disable passive checks non-existent object");
|
||||
|
||||
checkable->SetEnablePassiveChecks(false);
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully disabled passive checks for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::EnableActiveChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Host::Ptr host = static_pointer_cast<Host>(object);
|
||||
|
||||
if (!host)
|
||||
return ApiActions::CreateResult(404, "Cannot enable checks for non-existent object");
|
||||
|
||||
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
||||
service->SetEnableActiveChecks(true);
|
||||
}
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully processed check result for " + name);
|
||||
return ApiActions::CreateResult(200, "Successfully enabled active checks for " + host->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::DisableActiveChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Host::Ptr host = static_pointer_cast<Host>(object);
|
||||
|
||||
if (!host)
|
||||
return ApiActions::CreateResult(404, "Cannot enable checks for non-existent object");
|
||||
|
||||
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
||||
service->SetEnableActiveChecks(false);
|
||||
}
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully disabled active checks for " + host->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::AcknowledgeProblem(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot acknowledge problem for non-existent object");
|
||||
|
||||
if (!params->Contains("author") || !params->Contains("comment"))
|
||||
return ApiActions::CreateResult(403, "Acknowledgements require an author and a comment");
|
||||
|
||||
AcknowledgementType sticky = AcknowledgementNormal;
|
||||
bool notify = false;
|
||||
double timestamp = 0;
|
||||
if (params->Contains("sticky"))
|
||||
sticky = AcknowledgementSticky;
|
||||
if (params->Contains("notify"))
|
||||
notify = true;
|
||||
if (params->Contains("timestamp"))
|
||||
timestamp = HttpUtility::GetLastParameter(params, "timestamp");
|
||||
|
||||
Host::Ptr host;
|
||||
Service::Ptr service;
|
||||
tie(host, service) = GetHostService(checkable);
|
||||
|
||||
if (!service) {
|
||||
if (host->GetState() == HostUp)
|
||||
return ApiActions::CreateResult(409, "Host " + checkable->GetName() + " is up");
|
||||
} else {
|
||||
if (service->GetState() == ServiceOK)
|
||||
return ApiActions::CreateResult(409, "Service " + checkable->GetName() + " is ok");
|
||||
}
|
||||
|
||||
checkable->AddComment(CommentAcknowledgement, HttpUtility::GetLastParameter(params, "author"),
|
||||
HttpUtility::GetLastParameter(params, "comment"), timestamp);
|
||||
checkable->AcknowledgeProblem(HttpUtility::GetLastParameter(params, "author"),
|
||||
HttpUtility::GetLastParameter(params, "comment"), sticky, notify, timestamp);
|
||||
return ApiActions::CreateResult(200, "Successfully acknowledged problem for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::RemoveAcknowledgement(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot remove acknowlegement for non-existent object");
|
||||
|
||||
checkable->ClearAcknowledgement();
|
||||
checkable->RemoveCommentsByType(CommentAcknowledgement);
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully removed acknowledgement for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::AddComment(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot add comment for non-existent object");
|
||||
|
||||
if (!params->Contains("author") || !params->Contains("comment"))
|
||||
return ApiActions::CreateResult(403, "Comments require an author and a comment");
|
||||
|
||||
//TODO Fragnen warum es (void) checkable->AddComment(..) war
|
||||
checkable->AddComment(CommentUser, HttpUtility::GetLastParameter(params, "author"),
|
||||
HttpUtility::GetLastParameter(params, "comment"), 0);
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully added comment for " + checkable->GetName());
|
||||
}
|
||||
|
||||
/*
|
||||
Dictionary::Ptr ApiActions::RemoveComment(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
if (!params->Contains("comment_id"))
|
||||
return ApiActions::CreateResult(403, "Comment removal requires an comment_id";
|
||||
|
||||
int comment_id = HttpUtility::GetLastParameter(params, "comment_id");
|
||||
|
||||
String rid = Service::GetCommentIDFromLegacyID(comment_id);
|
||||
Service::RemoveComment(rid);
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully removed comment " + comment_id);
|
||||
}
|
||||
*/
|
||||
|
||||
Dictionary::Ptr ApiActions::RemoveAllComments(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot remove comments from non-existent object");
|
||||
|
||||
checkable->RemoveAllComments();
|
||||
return ApiActions::CreateResult(200, "Successfully removed all comments for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::EnableNotifications(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot enable notifications for non-existent object");
|
||||
|
||||
checkable->SetEnableNotifications(true);
|
||||
return ApiActions::CreateResult(200, "Successfully enabled notifications for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::DisableNotifications(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot disable notifications for non-existent object");
|
||||
|
||||
checkable->SetEnableNotifications(true);
|
||||
return ApiActions::CreateResult(200, "Successfully disabled notifications for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::DelayNotifications(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot delay notifications for non-existent object");
|
||||
|
||||
if (!params->Contains("timestamp"))
|
||||
return ApiActions::CreateResult(403, "A timestamp is required to delay notifications");
|
||||
|
||||
BOOST_FOREACH(const Notification::Ptr& notification, checkable->GetNotifications()) {
|
||||
notification->SetNextNotification(HttpUtility::GetLastParameter(params, "timestamp"));
|
||||
}
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully delayed notifications for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Can't schedule downtime for non-existent object");
|
||||
|
||||
if (!params->Contains("start_time") || !params->Contains("end_time") || !params->Contains("duration") ||
|
||||
!params->Contains("author") || !params->Contains("comment"))
|
||||
return ApiActions::CreateResult(404, "Options 'start_time', 'end_time', 'duration', 'author' and 'comment' are required");
|
||||
//Duration from end_time - start_time ?
|
||||
|
||||
bool fixd = false;
|
||||
if (params->Contains("fixed"))
|
||||
fixd = HttpUtility::GetLastParameter(params, "fixed");
|
||||
|
||||
int triggeredByLegacy = params->Contains("trigger_id") ? (int) HttpUtility::GetLastParameter(params, "trigger_id") : 0;
|
||||
String triggeredBy;
|
||||
if (triggeredByLegacy)
|
||||
triggeredBy = Service::GetDowntimeIDFromLegacyID(triggeredByLegacy);
|
||||
|
||||
checkable->AddDowntime(HttpUtility::GetLastParameter(params, "author"), HttpUtility::GetLastParameter(params, "comment"),
|
||||
HttpUtility::GetLastParameter(params, "start_time"), HttpUtility::GetLastParameter(params, "end_time"),
|
||||
fixd, triggeredBy, HttpUtility::GetLastParameter(params, "duration"));
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully scheduled downtime for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::EnableFlapDetection(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Can't enable flap detection for non-existent object");
|
||||
|
||||
checkable->SetEnableFlapping(true);
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully enabled flap detection for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::DisableFlapDetection(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Can't disable flap detection for non-existent object");
|
||||
|
||||
checkable->SetEnableFlapping(false);
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully disabled flap detection for " + checkable->GetName());
|
||||
}
|
||||
|
||||
/*
|
||||
Dictionary::Ptr ApiActions::RemoveDowntime(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
if (!params->Contains("downtime_id"))
|
||||
return ApiActions::CreateResult(403, "Downtime removal requires a downtime_id";
|
||||
|
||||
int downtime_id = HttpUtility::GetLastParameter(params, "downtime_id");
|
||||
|
||||
String rid = Service::GetDowntimeIDFromLegacyID(downtime_id);
|
||||
Service::RemoveDowntime(rid);
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully removed downtime " + downtime_id);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
Dictionary::Ptr ApiActions::EnableNotifications(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
IcingaApplication::GetInstance()->SetEnableNotifications(true);
|
||||
|
||||
ApiActions::CreateResult(200, "Globally enabled notifications.");
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::DisableNotifications(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
IcingaApplication::GetInstance()->SetEnableNotifications(false);
|
||||
|
||||
ApiActions::CreateResult(200, "Globally disabled notifications.");
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::EnableFlapDetection(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
IcingaApplication::GetInstance()->SetEnableFlapping(true);
|
||||
|
||||
ApiActions::CreateResult(200, "Globally enabled flap detection.");
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::DisableFlapDetection(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
IcingaApplication::GetInstance()->SetEnableFlapping(false);
|
||||
|
||||
ApiActions::CreateResult(200, "Globally disabled flap detection.");
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::EnableEventHandlers(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
IcingaApplication::GetInstance()->SetEnableEventHandlers(true);
|
||||
|
||||
ApiActions::CreateResult(200, "Globally enabled event handlers.");
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::DisableEventHandlers(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
IcingaApplication::GetInstance()->SetEnableEventHandlers(false);
|
||||
|
||||
ApiActions::CreateResult(200, "Globally disabled event handlers.");
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::EnablePerformanceData(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
IcingaApplication::GetInstance()->SetEnablePerfdata(true);
|
||||
|
||||
ApiActions::CreateResult(200, "Globally enabled performance data processing.");
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::DisablePerformanceData(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
IcingaApplication::GetInstance()->SetEnablePerfdata(false);
|
||||
|
||||
ApiActions::CreateResult(200, "Globally disabled performance data processing.");
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::StartExecutingSvcChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
IcingaApplication::GetInstance()->SetEnableServiceChecks(true);
|
||||
|
||||
ApiActions::CreateResult(200, "Globally enabled service checks.");
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::StopExecutingSvcChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
IcingaApplication::GetInstance()->SetEnableServiceChecks(false);
|
||||
|
||||
ApiActions::CreateResult(200, "Globally disabled service checks.");
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::StartExecutingHostChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
IcingaApplication::GetInstance()->SetEnableHostChecks(true);
|
||||
|
||||
ApiActions::CreateResult(200, "Globally enabled host checks.");
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::StopExecutingHostChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
IcingaApplication::GetInstance()->SetEnableHostChecks(false);
|
||||
|
||||
ApiActions::CreateResult(200, "Globally disabled host checks.");
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
Dictionary::Ptr ApiActions::ChangeEventHandler(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot change event handler of a non-existent object");
|
||||
|
||||
// empty command string implicitely disables event handler
|
||||
if (!params->Contains("event_command_name")) {
|
||||
checkable->SetEnableEventHandler(false);
|
||||
return ApiActions::CreateResult(200, "Successfully disabled event handler for " + checkable->GetName());
|
||||
} else {
|
||||
String event_name = HttpUtility::GetLastParameter(params, "event_command_name");
|
||||
|
||||
EventCommand::Ptr command = EventCommand::GetByName(event_name);
|
||||
|
||||
if (!command)
|
||||
return ApiActions::CreateResult(404, "Event command '" + event_name + "' does not exist");
|
||||
|
||||
checkable->SetEventCommand(command);
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully changed event command for " + checkable->GetName());
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::ChangeCheckCommand(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot change check command of a non-existent object");
|
||||
if (!params->Contains("check_command_name"))
|
||||
return ApiActions::CreateResult(403, "Parameter 'check_command_name' is required");
|
||||
|
||||
String check_name = HttpUtility::GetLastParameter(params, "check_command_name");
|
||||
|
||||
CheckCommand::Ptr command = CheckCommand::GetByName(check_name);
|
||||
|
||||
if (!command)
|
||||
return ApiActions::CreateResult(404, "Check command '" + check_name + "' does not exist");
|
||||
|
||||
checkable->SetCheckCommand(command);
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully changed check command for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::ChangeMaxCheckAttempts(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot change check command of a non-existent object");
|
||||
if (!params->Contains("max_check_attempts"))
|
||||
return ApiActions::CreateResult(403, "Parameter 'max_check_attempts' is required");
|
||||
|
||||
checkable->SetMaxCheckAttempts(HttpUtility::GetLastParameter(params, "max_check_attempts"));
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully changed the maximum check attempts for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::ChangeCheckPeriod(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot change check command of a non-existent object");
|
||||
if (!params->Contains("time_period_name"))
|
||||
return ApiActions::CreateResult(403, "Parameter 'time_period_name' is required");
|
||||
|
||||
String time_period_name = HttpUtility::GetLastParameter(params, "time_period_name");
|
||||
|
||||
TimePeriod::Ptr time_period = TimePeriod::GetByName(time_period_name);
|
||||
|
||||
if (!time_period)
|
||||
return ApiActions::CreateResult(404, "Time period '" + time_period_name + "' does not exist");
|
||||
|
||||
checkable->SetCheckPeriod(time_period);
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully changed the time period for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::ChangeCheckInterval(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot change check command of a non-existent object");
|
||||
if (!params->Contains("check_interval"))
|
||||
return ApiActions::CreateResult(403, "Parameter 'check_interval' is required");
|
||||
|
||||
checkable->SetCheckInterval(HttpUtility::GetLastParameter(params, "check_interval"));
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully changed the check interval for " + checkable->GetName());
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::ChangeRetryInterval(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
||||
|
||||
if (!checkable)
|
||||
return ApiActions::CreateResult(404, "Cannot change check command of a non-existent object");
|
||||
if (!params->Contains("retry_interval"))
|
||||
return ApiActions::CreateResult(403, "Parameter 'retry_interval' is required");
|
||||
|
||||
checkable->SetRetryInterval(HttpUtility::GetLastParameter(params, "retry_interval"));
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully changed the retry interval for " + checkable->GetName());
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
Dictionary::Ptr ApiActions::RestartProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Application::RequestShutdown();
|
||||
|
||||
return ApiActions::CreateResult(200, "I don't exist!");
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::RestartProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
Application::RequestRestart();
|
||||
|
||||
return ApiActions::CreateResult(200, "That's not how this works");
|
||||
}
|
||||
|
||||
Dictionary::Ptr ApiActions::ProcessFile(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
|
||||
{
|
||||
if (!params->Contains("file_name")
|
||||
return ApiActions::CreateResult(403, "Parameter 'file_name' is required");
|
||||
|
||||
String file = HttpUtility::GetLastParameter(params, "file_name")
|
||||
|
||||
bool del = true;
|
||||
if (!params->Contains("delete") || !HttpUtility::GetLastParameter(params, "delete"))
|
||||
del = false;
|
||||
|
||||
std::ifstream ifp;
|
||||
ifp.exceptions(std::ifstream::badbit);
|
||||
|
||||
ifp.open(file.CStr(), std::ifstream::in);
|
||||
|
||||
while (ifp.good()) {
|
||||
std::string line;
|
||||
std::getline(ifp, line);
|
||||
|
||||
try {
|
||||
Execute(line);
|
||||
} catch (const std::exception& ex) {
|
||||
ifp.close();
|
||||
return ApiActions::CreateResult(500, "Command execution failed");
|
||||
}
|
||||
}
|
||||
|
||||
ifp.close();
|
||||
|
||||
if (del)
|
||||
(void) unlink(file.CStr());
|
||||
|
||||
return ApiActions::CreateResult(200, "Successfully processed " + (del?"and deleted ":"") + "file " + file);
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -33,13 +33,58 @@ namespace icinga
|
|||
class I2_ICINGA_API ApiActions
|
||||
{
|
||||
public:
|
||||
static Dictionary::Ptr RescheduleCheck(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ProcessCheckResult(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr RescheduleCheck(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr DelayNotifications(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
|
||||
static Dictionary::Ptr AcknowledgeProblem(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr RemoveAcknowledgement(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr AddComment(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
/* static Dictionary::Ptr RemoveComment(const ConfigObject::Ptr& object, const Dictionary::Ptr& params); */
|
||||
static Dictionary::Ptr RemoveAllComments(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ScheduleDowntime(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
/* static Dictionary::Ptr RemoveDowntime(const ConfigObject::Ptr& object, const Dictionary::Ptr& params); */
|
||||
|
||||
static Dictionary::Ptr EnablePassiveChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr DisablePassiveChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr EnableActiveChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr DisableActiveChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr EnableNotifications(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr DisableNotifications(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr EnableFlapDetection(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr DisableFlapDetection(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
|
||||
/* static Dictionary::Ptr ChangeEventHandler(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ChangeCheckCommand(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ChangeMaxCheckAttempts(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ChangeCheckInterval(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ChangeRetryInterval(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ChangeCheckPeriod(const ConfigObject::Ptr& object, const Dictionary::Ptr& params); */
|
||||
|
||||
/* static Dictionary::Ptr ApiActions::EnableNotifications(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ApiActions::DisableNotifications(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ApiActions::EnableFlapDetection(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ApiActions::DisableFlapDetection(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ApiActions::EnableEventHandlers(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ApiActions::DisableEventHandlers(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ApiActions::EnablePerformanceData(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ApiActions::DisablePerformanceData(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ApiActions::StartExecutingSvcChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ApiActions::StopExecutingSvcChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ApiActions::StartExecutingHostChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ApiActions::StopExecutingHostChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params); */
|
||||
|
||||
/*
|
||||
static Dictionary::Ptr ApiActions::ShutdownProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ApiActions::RestartProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
static Dictionary::Ptr ApiActions::ProcessFile(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||
*/
|
||||
|
||||
private:
|
||||
static Dictionary::Ptr CreateResult(const int code, const String& status);
|
||||
static Dictionary::Ptr CreateResult(int code, const String& status);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* APIACTIONS_H */
|
||||
|
||||
|
|
Loading…
Reference in New Issue