API Actions: Remove -by-id from actions and require names for comments and downtimes

The documentation is updated as well. Furthermore actions provide
detailed error information in case of an exception.
Includes DB IDO schema updates.

fixes #10512
This commit is contained in:
Michael Friedrich 2015-11-06 16:45:09 +01:00
parent a51d01c14d
commit 64c936d387
10 changed files with 94 additions and 86 deletions

View File

@ -252,6 +252,12 @@ The array-append-notation is also supported:
?hosts[]=host1&hosts[]=host2&hosts[]=host3 ?hosts[]=host1&hosts[]=host2&hosts[]=host3
In case you want to add an object with a reference to other objects (e.g. the service
`ping4` belonging to the host `icinga2-node1.localdomain`) you'll need to use the
full name from the returned result set, e.g. `icinga2-node1.localdomain`. An object's
full name can also be retrieved from the `__name` object attribute in object queries.
A similar output is shown in [object list](8-cli-commands.md#cli-command-object) cli output.
#### <a id="icinga2-api-filters"></a> Filters #### <a id="icinga2-api-filters"></a> Filters
Uses the same syntax as [apply rule expressions](3-monitoring-basics.md#using-apply-expressions) Uses the same syntax as [apply rule expressions](3-monitoring-basics.md#using-apply-expressions)
@ -539,18 +545,23 @@ Send a `POST` request to the URL endpoint `/v1/actions/add-comment`.
Example: Example:
$ curl -k -s -u root:icinga -H 'Accept: application/json' -X POST 'https://localhost:5665/v1/actions/add-comment?type=Service&filter=service.name==%22ping4%22' -d '{ "author": "icingaadmin", "comment": "Troubleticket #123456789 opened." }' | python -m json.tool $ curl -k -s -u root:icinga -H 'Accept: application/json' -X POST 'https://localhost:5665/v1/actions/add-comment?type=Service&filter=service.name==%22ping4%22' -d '{ "author": "icingaadmin", "comment": "Troubleticket #123456789 opened." }' | python -m json.tool
{ {
"results": [ "results": [
{ {
"code": 200.0, "code": 200.0,
"comment_id": "i-42866686!ping4!mbmif.local-1446390475-55", "legacy_id": 26.0,
"legacy_id": 2.0, "name": "i-43866687!ping4!mbmif.int.netways.de-1446824161-0",
"status": "Successfully added comment with id 'i-42866686!ping4!mbmif.local-1446390475-55' for object 'i-42866686!ping4'." "status": "Successfully added comment 'i-43866687!ping4!mbmif.int.netways.de-1446824161-0' for object 'i-43866687!ping4'."
},
{
"code": 200.0,
"legacy_id": 27.0,
"name": "i-42866686!ping4!mbmif.int.netways.de-1446824161-1",
"status": "Successfully added comment 'i-42866686!ping4!mbmif.int.netways.de-1446824161-1' for object 'i-42866686!ping4'."
} }
]
} }
### <a id="icinga2-api-actions-remove-all-comments"></a> remove-all-comments ### <a id="icinga2-api-actions-remove-all-comments"></a> remove-all-comments
Removes all comments for services or hosts. Removes all comments for services or hosts.
@ -578,29 +589,29 @@ Example:
} }
} }
### <a id="icinga2-api-actions-remove-comment-by-id"></a> remove-comment-by-id ### <a id="icinga2-api-actions-remove-comment"></a> remove-comment
Tries to remove the comment with the ID `comment_id`, returns `OK` if the Remove the comment using its `name` attribute , returns `OK` if the
comment did not exist. comment did not exist.
**Note**: This is **not** the legacy ID but the comment ID returned by Icinga 2 itself. **Note**: This is **not** the legacy ID but the comment name returned by
Icinga 2 when [add a comment](9-icinga2-api.md#icinga2-api-actions-add-comment).
Send a `POST` request to the URL endpoint `/v1/actions/remove-comment-by-id`. Send a `POST` request to the URL endpoint `/v1/actions/remove-comment`.
parameter | type | description parameter | type | description
------------|---------|-------------- ------------|---------|--------------
comment\_id | integer | **Required.** ID of the comment to remove. name | string | **Required.** Name of the comment to remove.
Does not support a target type or filters. Does not support a target type or filters.
Example: Example:
$ curl -k -s -u root:icinga -H 'Accept: application/json' -X POST 'https://localhost:5665/v1/actions/remove-comment-by-id?comment_id=i-43866687!ping4!mbmif.local-1446390475-56' | python -m json.tool $ curl -k -s -u root:icinga -H 'Accept: application/json' -X POST 'https://localhost:5665/v1/actions/remove-comment?name=i-43866687!ping4!mbmif.int.netways.de-1446824161-0' | python -m json.tool
{ {
"results": [ "results": [
{ {
"code": 200.0, "code": 200.0,
"status": "Successfully removed comment 'i-43866687!ping4!mbmif.local-1446390475-56'." "status": "Successfully removed comment 'i-43866687!ping4!mbmif.int.netways.de-1446824161-0'."
} }
] ]
} }
@ -619,26 +630,24 @@ Send a `POST` request to the URL endpoint `/v1/actions/schedule-downtime`.
end\_time | timestamp | **Required.** Timestamp marking the end of the downtime. end\_time | timestamp | **Required.** Timestamp marking the end of the downtime.
duration | integer | **Required.** Duration of the downtime in seconds if `fixed` is set to false. duration | integer | **Required.** Duration of the downtime in seconds if `fixed` is set to false.
fixed | boolean | **Optional.** Defaults to `false`. If true the downtime is `fixed` otherwise `flexible`. See [downtimes](5-advanced-topics.md#downtimes) for more information. fixed | boolean | **Optional.** Defaults to `false`. If true the downtime is `fixed` otherwise `flexible`. See [downtimes](5-advanced-topics.md#downtimes) for more information.
trigger\_id | integer | **Optional.** Sets the trigger for a triggered downtime. See [downtimes](5-advanced-topics.md#downtimes) for more information on triggered downtimes. trigger\_name | string | **Optional.** Sets the trigger for a triggered downtime. See [downtimes](5-advanced-topics.md#downtimes) for more information on triggered downtimes.
Example: Example:
$ curl -k -s -u root:icinga -H 'Accept: application/json' -X POST 'https://localhost:5665/v1/actions/schedule-downtime?type=Service&filter=service.name==%22ping4%22' \ $ curl -k -s -u root:icinga -H 'Accept: application/json' -X POST 'https://localhost:5665/v1/actions/schedule-downtime?type=Service&filter=service.name==%22ping4%22' -d '{ "start_time": 1446388806, "end_time": 1446389806, "duration": 1000, "author": "icingaadmin", "comment": "IPv4 network maintenance" }' | python -m json.tool
-d '{ "start_time": 1446388806, "end_time": 1446389806, "duration": 1000, "author": "icingaadmin", "comment": "IPv4 network maintenance" }' | python -m json.tool
{ {
"results": [ "results": [
{ {
"code": 200.0, "code": 200.0,
"downtime_id": "i-42866686!ping4!mbmif.local-1446388986-545", "legacy_id": 2.0,
"legacy_id": 8.0, "name": "i-42866686!ping4!mbmif.int.netways.de-1446822004-0",
"status": "Successfully scheduled downtime with id 'i-42866686!ping4!mbmif.local-1446388986-545' for object 'i-42866686!ping4'." "status": "Successfully scheduled downtime 'i-42866686!ping4!mbmif.int.netways.de-1446822004-0' for object 'i-42866686!ping4'."
}, },
{ {
"code": 200.0, "code": 200.0,
"downtime_id": "i-43866687!ping4!mbmif.local-1446388986-546", "legacy_id": 3.0,
"legacy_id": 9.0, "name": "i-43866687!ping4!mbmif.int.netways.de-1446822004-1",
"status": "Successfully scheduled downtime with id 'i-43866687!ping4!mbmif.local-1446388986-546' for object 'i-43866687!ping4'." "status": "Successfully scheduled downtime 'i-43866687!ping4!mbmif.int.netways.de-1446822004-1' for object 'i-43866687!ping4'."
} }
] ]
} }
@ -672,34 +681,33 @@ Example:
] ]
} }
### <a id="icinga2-api-actions-remove-downtime-by-id"></a> remove-downtime-by-id ### <a id="icinga2-api-actions-remove-downtime"></a> remove-downtime
Tries to remove the downtime with the ID `downtime_id`, returns `OK` if the Remove the downtime using its `name` attribute , returns `OK` if the
downtime did not exist. downtime did not exist.
**Note**: This is **not** the legacy ID but the downtime ID returned by Icinga 2 itself. **Note**: This is **not** the legacy ID but the downtime name returned by
Icinga 2 when [scheduling a downtime](9-icinga2-api.md#icinga2-api-actions-schedule-downtime).
Send a `POST` request to the URL endpoint `/v1/actions/remove-downtime-by-id`. Send a `POST` request to the URL endpoint `/v1/actions/remove-downtime`.
parameter | type | description parameter | type | description
-------------|---------|-------------- -------------|---------|--------------
downtime\_id | integer | **Required.** ID of the downtime to remove. name | string | **Required.** Name of the downtime to remove.
Does not support a target type or filter. Does not support a target type or filter.
Example: Example:
$ curl -k -s -u root:icinga -H 'Accept: application/json' -X POST 'https://localhost:5665/v1/actions/remove-downtime-by-id?downtime_id=mbmif.local-1446339731-582' | python -m json.tool $ curl -k -s -u root:icinga -H 'Accept: application/json' -X POST 'https://localhost:5665/v1/actions/remove-downtime?name=i-43866687!ping4!mbmif.int.netways.de-1446822004-1' | python -m json.tool
{ {
"results": [ "results": [
{ {
"code": 200.0, "code": 200.0,
"status": "Successfully removed downtime 'mbmif.local-1446339731-582'." "status": "Successfully removed downtime 'i-43866687!ping4!mbmif.int.netways.de-1446822004-1'."
} }
] ]
} }
### <a id="icinga2-api-actions-shutdown-process"></a> shutdown-process ### <a id="icinga2-api-actions-shutdown-process"></a> shutdown-process
Shuts down Icinga2. May or may not return. Shuts down Icinga2. May or may not return.

View File

@ -353,7 +353,7 @@ void DbEvents::AddCommentByType(const Comment::Ptr& comment, bool historical)
return; return;
} }
fields1->Set("unique_id", comment->GetName()); fields1->Set("name", comment->GetName());
fields1->Set("comment_time", DbValue::FromTimestamp(entry_time)); /* same as entry_time */ fields1->Set("comment_time", DbValue::FromTimestamp(entry_time)); /* same as entry_time */
fields1->Set("author_name", comment->GetAuthor()); fields1->Set("author_name", comment->GetAuthor());
fields1->Set("comment_data", comment->GetText()); fields1->Set("comment_data", comment->GetText());
@ -488,7 +488,7 @@ void DbEvents::AddDowntimeByType(const Downtime::Ptr& downtime, bool historical)
return; return;
} }
fields1->Set("unique_id", downtime->GetName()); fields1->Set("name", downtime->GetName());
fields1->Set("author_name", downtime->GetAuthor()); fields1->Set("author_name", downtime->GetAuthor());
fields1->Set("comment_data", downtime->GetComment()); fields1->Set("comment_data", downtime->GetComment());
fields1->Set("triggered_by_id", Downtime::GetByName(downtime->GetTriggeredBy())); fields1->Set("triggered_by_id", Downtime::GetByName(downtime->GetTriggeredBy()));

View File

@ -82,7 +82,7 @@ CREATE TABLE IF NOT EXISTS icinga_commenthistory (
expiration_time timestamp default '0000-00-00 00:00:00', expiration_time timestamp default '0000-00-00 00:00:00',
deletion_time timestamp default '0000-00-00 00:00:00', deletion_time timestamp default '0000-00-00 00:00:00',
deletion_time_usec int default 0, deletion_time_usec int default 0,
unique_id TEXT character set latin1 default NULL, name TEXT character set latin1 default NULL,
PRIMARY KEY (commenthistory_id), PRIMARY KEY (commenthistory_id),
UNIQUE KEY instance_id (instance_id,object_id,comment_time,internal_comment_id) UNIQUE KEY instance_id (instance_id,object_id,comment_time,internal_comment_id)
) ENGINE=InnoDB COMMENT='Historical host and service comments'; ) ENGINE=InnoDB COMMENT='Historical host and service comments';
@ -109,7 +109,7 @@ CREATE TABLE IF NOT EXISTS icinga_comments (
comment_source smallint default 0, comment_source smallint default 0,
expires smallint default 0, expires smallint default 0,
expiration_time timestamp default '0000-00-00 00:00:00', expiration_time timestamp default '0000-00-00 00:00:00',
unique_id TEXT character set latin1 default NULL, name TEXT character set latin1 default NULL,
PRIMARY KEY (comment_id), PRIMARY KEY (comment_id),
UNIQUE KEY instance_id (instance_id,object_id,comment_time,internal_comment_id) UNIQUE KEY instance_id (instance_id,object_id,comment_time,internal_comment_id)
) ENGINE=InnoDB COMMENT='Usercomments on Icinga objects'; ) ENGINE=InnoDB COMMENT='Usercomments on Icinga objects';
@ -413,7 +413,7 @@ CREATE TABLE IF NOT EXISTS icinga_downtimehistory (
was_cancelled smallint default 0, was_cancelled smallint default 0,
is_in_effect smallint default 0, is_in_effect smallint default 0,
trigger_time timestamp default '0000-00-00 00:00:00', trigger_time timestamp default '0000-00-00 00:00:00',
unique_id TEXT character set latin1 default NULL, name TEXT character set latin1 default NULL,
PRIMARY KEY (downtimehistory_id), PRIMARY KEY (downtimehistory_id),
UNIQUE KEY instance_id (instance_id,object_id,entry_time,internal_downtime_id) UNIQUE KEY instance_id (instance_id,object_id,entry_time,internal_downtime_id)
) ENGINE=InnoDB COMMENT='Historical scheduled host and service downtime'; ) ENGINE=InnoDB COMMENT='Historical scheduled host and service downtime';
@ -975,7 +975,7 @@ CREATE TABLE IF NOT EXISTS icinga_scheduleddowntime (
actual_start_time_usec int default 0, actual_start_time_usec int default 0,
is_in_effect smallint default 0, is_in_effect smallint default 0,
trigger_time timestamp default '0000-00-00 00:00:00', trigger_time timestamp default '0000-00-00 00:00:00',
unique_id TEXT character set latin1 default NULL, name TEXT character set latin1 default NULL,
PRIMARY KEY (scheduleddowntime_id), PRIMARY KEY (scheduleddowntime_id),
UNIQUE KEY instance_id (instance_id,object_id,entry_time,internal_downtime_id) UNIQUE KEY instance_id (instance_id,object_id,entry_time,internal_downtime_id)
) ENGINE=InnoDB COMMENT='Current scheduled host and service downtime'; ) ENGINE=InnoDB COMMENT='Current scheduled host and service downtime';

View File

@ -59,14 +59,14 @@ CREATE INDEX cv_session_del_idx ON icinga_customvariables (session_token);
CREATE INDEX cvs_session_del_idx ON icinga_customvariablestatus (session_token); CREATE INDEX cvs_session_del_idx ON icinga_customvariablestatus (session_token);
-- ----------------------------------------- -- -----------------------------------------
-- #10431 comment/downtime unique id -- #10431 comment/downtime name
-- ----------------------------------------- -- -----------------------------------------
ALTER TABLE icinga_comments ADD COLUMN unique_id TEXT character set latin1 default NULL; ALTER TABLE icinga_comments ADD COLUMN name TEXT character set latin1 default NULL;
ALTER TABLE icinga_commenthistory ADD COLUMN unique_id TEXT character set latin1 default NULL; ALTER TABLE icinga_commenthistory ADD COLUMN name TEXT character set latin1 default NULL;
ALTER TABLE icinga_scheduleddowntime ADD COLUMN unique_id TEXT character set latin1 default NULL; ALTER TABLE icinga_scheduleddowntime ADD COLUMN name TEXT character set latin1 default NULL;
ALTER TABLE icinga_downtimehistory ADD COLUMN unique_id TEXT character set latin1 default NULL; ALTER TABLE icinga_downtimehistory ADD COLUMN name TEXT character set latin1 default NULL;
-- ----------------------------------------- -- -----------------------------------------
-- update dbversion -- update dbversion

View File

@ -108,7 +108,7 @@ CREATE TABLE icinga_commenthistory (
expiration_time timestamp with time zone default '1970-01-01 00:00:00+00', expiration_time timestamp with time zone default '1970-01-01 00:00:00+00',
deletion_time timestamp with time zone default '1970-01-01 00:00:00+00', deletion_time timestamp with time zone default '1970-01-01 00:00:00+00',
deletion_time_usec INTEGER default 0, deletion_time_usec INTEGER default 0,
unique_id TEXT default NULL, name TEXT default NULL,
CONSTRAINT PK_commenthistory_id PRIMARY KEY (commenthistory_id) , CONSTRAINT PK_commenthistory_id PRIMARY KEY (commenthistory_id) ,
CONSTRAINT UQ_commenthistory UNIQUE (instance_id,object_id,comment_time,internal_comment_id) CONSTRAINT UQ_commenthistory UNIQUE (instance_id,object_id,comment_time,internal_comment_id)
); );
@ -135,7 +135,7 @@ CREATE TABLE icinga_comments (
comment_source INTEGER default 0, comment_source INTEGER default 0,
expires INTEGER default 0, expires INTEGER default 0,
expiration_time timestamp with time zone default '1970-01-01 00:00:00+00', expiration_time timestamp with time zone default '1970-01-01 00:00:00+00',
unique_id TEXT default NULL, name TEXT default NULL,
CONSTRAINT PK_comment_id PRIMARY KEY (comment_id) , CONSTRAINT PK_comment_id PRIMARY KEY (comment_id) ,
CONSTRAINT UQ_comments UNIQUE (instance_id,object_id,comment_time,internal_comment_id) CONSTRAINT UQ_comments UNIQUE (instance_id,object_id,comment_time,internal_comment_id)
) ; ) ;
@ -440,7 +440,7 @@ CREATE TABLE icinga_downtimehistory (
was_cancelled INTEGER default 0, was_cancelled INTEGER default 0,
is_in_effect INTEGER default 0, is_in_effect INTEGER default 0,
trigger_time timestamp with time zone default '1970-01-01 00:00:00+00', trigger_time timestamp with time zone default '1970-01-01 00:00:00+00',
unique_id TEXT default NULL, name TEXT default NULL,
CONSTRAINT PK_downtimehistory_id PRIMARY KEY (downtimehistory_id) , CONSTRAINT PK_downtimehistory_id PRIMARY KEY (downtimehistory_id) ,
CONSTRAINT UQ_downtimehistory UNIQUE (instance_id,object_id,entry_time,internal_downtime_id) CONSTRAINT UQ_downtimehistory UNIQUE (instance_id,object_id,entry_time,internal_downtime_id)
) ; ) ;
@ -1002,7 +1002,7 @@ CREATE TABLE icinga_scheduleddowntime (
actual_start_time_usec INTEGER default 0, actual_start_time_usec INTEGER default 0,
is_in_effect INTEGER default 0, is_in_effect INTEGER default 0,
trigger_time timestamp with time zone default '1970-01-01 00:00:00+00', trigger_time timestamp with time zone default '1970-01-01 00:00:00+00',
unique_id TEXT default NULL, name TEXT default NULL,
CONSTRAINT PK_scheduleddowntime_id PRIMARY KEY (scheduleddowntime_id) , CONSTRAINT PK_scheduleddowntime_id PRIMARY KEY (scheduleddowntime_id) ,
CONSTRAINT UQ_scheduleddowntime UNIQUE (instance_id,object_id,entry_time,internal_downtime_id) CONSTRAINT UQ_scheduleddowntime UNIQUE (instance_id,object_id,entry_time,internal_downtime_id)
) ; ) ;

View File

@ -169,14 +169,14 @@ CREATE INDEX cv_session_del_idx ON icinga_customvariables (session_token);
CREATE INDEX cvs_session_del_idx ON icinga_customvariablestatus (session_token); CREATE INDEX cvs_session_del_idx ON icinga_customvariablestatus (session_token);
-- ----------------------------------------- -- -----------------------------------------
-- #10431 comment/downtime unique id -- #10431 comment/downtime name
-- ----------------------------------------- -- -----------------------------------------
ALTER TABLE icinga_comments ADD COLUMN unique_id TEXT default NULL; ALTER TABLE icinga_comments ADD COLUMN name TEXT default NULL;
ALTER TABLE icinga_commenthistory ADD COLUMN unique_id TEXT default NULL; ALTER TABLE icinga_commenthistory ADD COLUMN name TEXT default NULL;
ALTER TABLE icinga_scheduleddowntime ADD COLUMN unique_id TEXT default NULL; ALTER TABLE icinga_scheduleddowntime ADD COLUMN name TEXT default NULL;
ALTER TABLE icinga_downtimehistory ADD COLUMN unique_id TEXT default NULL; ALTER TABLE icinga_downtimehistory ADD COLUMN name TEXT default NULL;
-- ----------------------------------------- -- -----------------------------------------
-- update dbversion -- update dbversion

View File

@ -41,10 +41,10 @@ REGISTER_APIACTION(acknowledge_problem, "Service;Host", &ApiActions::Acknowledge
REGISTER_APIACTION(remove_acknowledgement, "Service;Host", &ApiActions::RemoveAcknowledgement); REGISTER_APIACTION(remove_acknowledgement, "Service;Host", &ApiActions::RemoveAcknowledgement);
REGISTER_APIACTION(add_comment, "Service;Host", &ApiActions::AddComment); REGISTER_APIACTION(add_comment, "Service;Host", &ApiActions::AddComment);
REGISTER_APIACTION(remove_all_comments, "Service;Host", &ApiActions::RemoveAllComments); REGISTER_APIACTION(remove_all_comments, "Service;Host", &ApiActions::RemoveAllComments);
REGISTER_APIACTION(remove_comment_by_id, "", &ApiActions::RemoveCommentByID); REGISTER_APIACTION(remove_comment, "", &ApiActions::RemoveComment);
REGISTER_APIACTION(schedule_downtime, "Service;Host", &ApiActions::ScheduleDowntime); REGISTER_APIACTION(schedule_downtime, "Service;Host", &ApiActions::ScheduleDowntime);
REGISTER_APIACTION(remove_all_downtimes, "Service;Host", &ApiActions::RemoveAllDowntimes); REGISTER_APIACTION(remove_all_downtimes, "Service;Host", &ApiActions::RemoveAllDowntimes);
REGISTER_APIACTION(remove_downtime_by_id, "", &ApiActions::RemoveDowntimeByID); REGISTER_APIACTION(remove_downtime, "", &ApiActions::RemoveDowntime);
REGISTER_APIACTION(shutdown_process, "", &ApiActions::ShutdownProcess); REGISTER_APIACTION(shutdown_process, "", &ApiActions::ShutdownProcess);
REGISTER_APIACTION(restart_process, "", &ApiActions::RestartProcess); REGISTER_APIACTION(restart_process, "", &ApiActions::RestartProcess);
@ -250,19 +250,19 @@ Dictionary::Ptr ApiActions::AddComment(const ConfigObject::Ptr& object,
if (!params->Contains("author") || !params->Contains("comment")) if (!params->Contains("author") || !params->Contains("comment"))
return ApiActions::CreateResult(403, "Comments require author and comment."); return ApiActions::CreateResult(403, "Comments require author and comment.");
String comment_id = Comment::AddComment(checkable, CommentUser, String comment_name = Comment::AddComment(checkable, CommentUser,
HttpUtility::GetLastParameter(params, "author"), HttpUtility::GetLastParameter(params, "author"),
HttpUtility::GetLastParameter(params, "comment"), 0); HttpUtility::GetLastParameter(params, "comment"), 0);
Comment::Ptr comment = Comment::GetByName(comment_id); Comment::Ptr comment = Comment::GetByName(comment_name);
int legacy_id = comment->GetLegacyId(); int legacy_id = comment->GetLegacyId();
Dictionary::Ptr additional = new Dictionary(); Dictionary::Ptr additional = new Dictionary();
additional->Set("comment_id", comment_id); additional->Set("name", comment_name);
additional->Set("legacy_id", legacy_id); additional->Set("legacy_id", legacy_id);
return ApiActions::CreateResult(200, "Successfully added comment with id '" return ApiActions::CreateResult(200, "Successfully added comment '"
+ comment_id + "' for object '" + checkable->GetName() + comment_name + "' for object '" + checkable->GetName()
+ "'.", additional); + "'.", additional);
} }
@ -279,22 +279,22 @@ Dictionary::Ptr ApiActions::RemoveAllComments(const ConfigObject::Ptr& object,
return ApiActions::CreateResult(200, "Successfully removed comments for object '" + checkable->GetName() + "'."); return ApiActions::CreateResult(200, "Successfully removed comments for object '" + checkable->GetName() + "'.");
} }
Dictionary::Ptr ApiActions::RemoveCommentByID(const ConfigObject::Ptr& object, Dictionary::Ptr ApiActions::RemoveComment(const ConfigObject::Ptr& object,
const Dictionary::Ptr& params) const Dictionary::Ptr& params)
{ {
if (!params->Contains("comment_id")) if (!params->Contains("name"))
return ApiActions::CreateResult(403, "Parameter 'comment_id' is required."); return ApiActions::CreateResult(403, "Parameter 'name' is required.");
String comment_id = HttpUtility::GetLastParameter(params, "comment_id"); String comment_name = HttpUtility::GetLastParameter(params, "name");
Comment::RemoveComment(comment_id); Comment::RemoveComment(comment_name);
Comment::Ptr comment = Comment::GetByName(comment_id); Comment::Ptr comment = Comment::GetByName(comment_name);
if (!comment) if (!comment)
return ApiActions::CreateResult(200, "Successfully removed comment '" + comment_id + "'."); return ApiActions::CreateResult(200, "Successfully removed comment '" + comment_name + "'.");
return ApiActions::CreateResult(403, "Could not remove comment '" + comment_id + "'."); return ApiActions::CreateResult(403, "Could not remove comment '" + comment_name + "'.");
} }
Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object, Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
@ -316,23 +316,23 @@ Dictionary::Ptr ApiActions::ScheduleDowntime(const ConfigObject::Ptr& object,
if (params->Contains("fixed")) if (params->Contains("fixed"))
fixed = HttpUtility::GetLastParameter(params, "fixed"); fixed = HttpUtility::GetLastParameter(params, "fixed");
String downtime_id = Downtime::AddDowntime(checkable, String downtime_name = Downtime::AddDowntime(checkable,
HttpUtility::GetLastParameter(params, "author"), HttpUtility::GetLastParameter(params, "author"),
HttpUtility::GetLastParameter(params, "comment"), HttpUtility::GetLastParameter(params, "comment"),
HttpUtility::GetLastParameter(params, "start_time"), HttpUtility::GetLastParameter(params, "start_time"),
HttpUtility::GetLastParameter(params, "end_time"), fixed, HttpUtility::GetLastParameter(params, "end_time"), fixed,
HttpUtility::GetLastParameter(params, "trigger_id"), HttpUtility::GetLastParameter(params, "trigger_name"),
HttpUtility::GetLastParameter(params, "duration")); HttpUtility::GetLastParameter(params, "duration"));
Downtime::Ptr downtime = Downtime::GetByName(downtime_id); Downtime::Ptr downtime = Downtime::GetByName(downtime_name);
int legacy_id = downtime->GetLegacyId(); int legacy_id = downtime->GetLegacyId();
Dictionary::Ptr additional = new Dictionary(); Dictionary::Ptr additional = new Dictionary();
additional->Set("downtime_id", downtime_id); additional->Set("name", downtime_name);
additional->Set("legacy_id", legacy_id); additional->Set("legacy_id", legacy_id);
return ApiActions::CreateResult(200, "Successfully scheduled downtime with id '" + return ApiActions::CreateResult(200, "Successfully scheduled downtime '" +
downtime_id + "' for object '" + checkable->GetName() + "'.", additional); downtime_name + "' for object '" + checkable->GetName() + "'.", additional);
} }
Dictionary::Ptr ApiActions::RemoveAllDowntimes(const ConfigObject::Ptr& object, Dictionary::Ptr ApiActions::RemoveAllDowntimes(const ConfigObject::Ptr& object,
@ -348,22 +348,22 @@ Dictionary::Ptr ApiActions::RemoveAllDowntimes(const ConfigObject::Ptr& object,
return ApiActions::CreateResult(200, "Successfully removed downtimes for object '" + checkable->GetName() + "'."); return ApiActions::CreateResult(200, "Successfully removed downtimes for object '" + checkable->GetName() + "'.");
} }
Dictionary::Ptr ApiActions::RemoveDowntimeByID(const ConfigObject::Ptr& object, Dictionary::Ptr ApiActions::RemoveDowntime(const ConfigObject::Ptr& object,
const Dictionary::Ptr& params) const Dictionary::Ptr& params)
{ {
if (!params->Contains("downtime_id")) if (!params->Contains("name"))
return ApiActions::CreateResult(403, "Parameter 'downtime_id' is required."); return ApiActions::CreateResult(403, "Parameter 'name' is required.");
String downtime_id = HttpUtility::GetLastParameter(params, "downtime_id"); String downtime_name = HttpUtility::GetLastParameter(params, "name");
Downtime::RemoveDowntime(downtime_id, true); Downtime::RemoveDowntime(downtime_name, true);
Downtime::Ptr downtime = Downtime::GetByName(downtime_id); Downtime::Ptr downtime = Downtime::GetByName(downtime_name);
if (!downtime) if (!downtime)
return ApiActions::CreateResult(200, "Successfully removed downtime '" + downtime_id + "'."); return ApiActions::CreateResult(200, "Successfully removed downtime '" + downtime_name + "'.");
return ApiActions::CreateResult(403, "Could not remove downtime '" + downtime_id + "'."); return ApiActions::CreateResult(403, "Could not remove downtime '" + downtime_name + "'.");
} }
Dictionary::Ptr ApiActions::ShutdownProcess(const ConfigObject::Ptr& object, Dictionary::Ptr ApiActions::ShutdownProcess(const ConfigObject::Ptr& object,

View File

@ -41,10 +41,10 @@ public:
static Dictionary::Ptr RemoveAcknowledgement(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 AddComment(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
static Dictionary::Ptr RemoveAllComments(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 RemoveComment(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
static Dictionary::Ptr ScheduleDowntime(const ConfigObject::Ptr& object, const Dictionary::Ptr& params); static Dictionary::Ptr ScheduleDowntime(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
static Dictionary::Ptr RemoveAllDowntimes(const ConfigObject::Ptr& object, const Dictionary::Ptr& params); static Dictionary::Ptr RemoveAllDowntimes(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
static Dictionary::Ptr RemoveDowntimeByID(const ConfigObject::Ptr& object, const Dictionary::Ptr& params); static Dictionary::Ptr RemoveDowntime(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 RestartProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);

View File

@ -319,8 +319,8 @@ void Downtime::TriggerDowntime(void)
{ {
ObjectLock olock(triggers); ObjectLock olock(triggers);
BOOST_FOREACH(const String& id, triggers) { BOOST_FOREACH(const String& triggerName, triggers) {
Downtime::GetByName(id)->TriggerDowntime(); Downtime::GetByName(triggerName)->TriggerDowntime();
} }
} }

View File

@ -85,7 +85,7 @@ bool ActionsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& reques
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
Dictionary::Ptr fail = new Dictionary(); Dictionary::Ptr fail = new Dictionary();
fail->Set("code", 500); fail->Set("code", 500);
fail->Set("status", "Action execution failed."); fail->Set("status", "Action execution failed: '" + DiagnosticInformation(ex, false) + "'.");
if (HttpUtility::GetLastParameter(params, "verboseErrors")) if (HttpUtility::GetLastParameter(params, "verboseErrors"))
fail->Set("diagnostic information", DiagnosticInformation(ex)); fail->Set("diagnostic information", DiagnosticInformation(ex));
results->Add(fail); results->Add(fail);