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 | -
+remove-comment | - | Service;Host | -
+remove-comment-by-id | comment_id | - | -
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?
+remove-downtime | - | Service; Host | -
+remove-downtime-by-id | downtime_id | - | -
send-custom-notification | options[]; author; comment | Service; Host | -
enable-passive-checks | - | Service; Host; ServiceGroup; HostGroup | "System" as target?
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 | - | - | -
+enable-global-notifications | - | - | -
+disable-global-notifications | - | - | -
+enable-global-flap-detection | - | - | -
+disable-global-flap-detection | - | - | -
+enable-global-event-handlers | - | - | -
+disable-global-event-handlers | - | - | -
+enable-global-performance-data | - | - | -
+disable-global-performance-data | - | - | -
+start-global-executing-svc-checks | - | - | -
+stop-global-executing-svc-checks | - | - | -
+start-global-executing-host-checks | - | - | -
+stop-global-executing-host-checks | - | - | -
shutdown-process | - | - | -
restart-process | - | - | -
-process-file | - | - | -
#include "remote/httputility.hpp"
#include "base/utility.hpp"
#include "base/convert.hpp"
+#include <fstream>
using namespace icinga;
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);
-REGISTER_APIACTION(remove_all_comments, "Service;Host", &ApiActions::RemoveAllComments);
+REGISTER_APIACTION(remove_comment, "Service;Host", &ApiActions::RemoveComment);
+REGISTER_APIACTION(remove_comment_by_id, "", &ApiActions::RemoveCommentByID);
REGISTER_APIACTION(schedule_downtime, "Service;Host", &ApiActions::ScheduleDowntime);
-REGISTER_APIACTION(remove_downtime, "", &ApiActions::RemoveDowntime);
+REGISTER_APIACTION(remove_downtime, "Service;Host", &ApiActions::RemoveDowntime);
+REGISTER_APIACTION(remove_downtime_by_id, "", &ApiActions::RemoveDowntimeByID);
REGISTER_APIACTION(enable_passive_checks, "Service;Host", &ApiActions::EnablePassiveChecks);
REGISTER_APIACTION(disable_passive_checks, "Service;Host", &ApiActions::DisablePassiveChecks);
REGISTER_APIACTION(start_global_executing_host_checks, "", &ApiActions::StartGlobalExecutingHostChecks);
REGISTER_APIACTION(stop_global_executing_host_checks, "", &ApiActions::StopGlobalExecutingHostChecks);
-//TODO: add process related actions
-/*
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, const Dictionary::Ptr& additional)
{
Dictionary::Ptr ApiActions::RemoveComment(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
{
- if (!params->Contains("comment_id"))
- return ApiActions::CreateResult(403, "'comment_id' required.");
+ Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
- int comment_id = HttpUtility::GetLastParameter(params, "comment_id");
+ if (!checkable)
+ return ApiActions::CreateResult(404, "Cannot remove comment form non-existent object");
- String rid = Service::GetCommentIDFromLegacyID(comment_id);
- Service::RemoveComment(rid);
+ checkable->RemoveAllComments();
- return ApiActions::CreateResult(200, "Successfully removed comment " + Convert::ToString(comment_id) + ".");
+ return ApiActions::CreateResult(200, "Successfully removed comments for " + checkable->GetName());
}
-Dictionary::Ptr ApiActions::RemoveAllComments(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
+Dictionary::Ptr ApiActions::RemoveCommentByID(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
{
- Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
+ if (!params->Contains("comment_id"))
+ return ApiActions::CreateResult(403, "Parameter 'comment_id' is required.");
- if (!checkable)
- return ApiActions::CreateResult(404, "Cannot remove comments from non-existent object");
+ int comment_id = HttpUtility::GetLastParameter(params, "comment_id");
- checkable->RemoveAllComments();
+ String rid = Service::GetCommentIDFromLegacyID(comment_id);
+
+ if (rid.IsEmpty())
+ return ApiActions::CreateResult(404, "Comment '" + Convert::ToString(comment_id) + "' does not exist.");
- return ApiActions::CreateResult(200, "Successfully removed all comments for " + checkable->GetName());
+ Service::RemoveComment(rid);
+
+ return ApiActions::CreateResult(200, "Successfully removed comment " + Convert::ToString(comment_id) + ".");
}
Dictionary::Ptr ApiActions::EnableNotifications(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
}
Dictionary::Ptr ApiActions::RemoveDowntime(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
+{
+ Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
+
+ if (!checkable)
+ return ApiActions::CreateResult(404, "Cannot remove downtime for non-existent object");
+
+ checkable->RemoveAllDowntimes();
+
+ return ApiActions::CreateResult(200, "Successfully removed downtimes for " + checkable->GetName());
+}
+
+Dictionary::Ptr ApiActions::RemoveDowntimeByID(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
{
if (!params->Contains("downtime_id"))
- return ApiActions::CreateResult(403, "Downtime removal requires a downtime_id");
+ return ApiActions::CreateResult(403, "Parameter 'downtime_id' is required.");
int downtime_id = HttpUtility::GetLastParameter(params, "downtime_id");
String rid = Service::GetDowntimeIDFromLegacyID(downtime_id);
+ if (rid.IsEmpty())
+ return ApiActions::CreateResult(404, "Downtime '" + Convert::ToString(downtime_id) + "' does not exist.");
+
Service::RemoveDowntime(rid, true);
- return ApiActions::CreateResult(200, "Successfully removed downtime with id " + Convert::ToString(downtime_id) + ".");
+ return ApiActions::CreateResult(200, "Successfully removed downtime " + Convert::ToString(downtime_id) + ".");
}
Dictionary::Ptr ApiActions::EnableGlobalNotifications(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
}
*/
-//TODO: process actions
-/*
-Dictionary::Ptr ApiActions::RestartProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
+Dictionary::Ptr ApiActions::ShutdownProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
{
Application::RequestShutdown();
- return ApiActions::CreateResult(200, "I don't exist!");
+ return ApiActions::CreateResult(200, "Shutting down Icinga2");
}
Dictionary::Ptr ApiActions::RestartProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params)
{
Application::RequestRestart();
- return ApiActions::CreateResult(200, "That's not how this works");
+ return ApiActions::CreateResult(200, "Restarting Icinga");
}
-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);
-}
-*/
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 RemoveCommentByID(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 RemoveDowntimeByID(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 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 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 ChangeCheckPeriod(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
+*/
static Dictionary::Ptr EnableGlobalNotifications(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
static Dictionary::Ptr DisableGlobalNotifications(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
static Dictionary::Ptr StartGlobalExecutingHostChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
static Dictionary::Ptr StopGlobalExecutingHostChecks(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
-/* static Dictionary::Ptr ShutdownProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
+ static Dictionary::Ptr ShutdownProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
static Dictionary::Ptr RestartProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
- static Dictionary::Ptr ProcessFile(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
- */
private:
static Dictionary::Ptr CreateResult(int code, const String& status, const Dictionary::Ptr& additional = Dictionary::Ptr());