Skip to content

Commit

Permalink
Issue NagiosEnterprises#685 - Add Ability To Set A Comment To Expire
Browse files Browse the repository at this point in the history
This commit sets up saving and expiration time for the ADD_[HOST/SERVICE]_COMMENT commands. It requires a new parameter, so doc will change. Also needs field added to GUI. Must figure out event handler to remove comment once expired.
  • Loading branch information
iwhite-nagios committed Feb 6, 2020
1 parent 2b6f0dc commit fa77664
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 15 deletions.
18 changes: 17 additions & 1 deletion base/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,7 @@ int cmd_add_comment(int cmd, time_t entry_time, char *args) {
char *user = NULL;
char *comment_data = NULL;
int persistent = 0;
time_t expire_time = 0;
int result = 0;

/* get the host name */
Expand Down Expand Up @@ -2038,6 +2039,10 @@ int cmd_add_comment(int cmd, time_t entry_time, char *args) {
else if(persistent < 0)
persistent = 0;

const char *exp_p;
if ((exp_p = my_strtok(NULL, ";")) == NULL)
return ERROR;
expire_time = atoi(exp_p);
/* get the name of the user who entered the comment */
if((user = my_strtok(NULL, ";")) == NULL)
return ERROR;
Expand All @@ -2047,7 +2052,18 @@ int cmd_add_comment(int cmd, time_t entry_time, char *args) {
return ERROR;

/* add the comment */
result = add_new_comment((cmd == CMD_ADD_HOST_COMMENT) ? HOST_COMMENT : SERVICE_COMMENT, USER_COMMENT, host_name, svc_description, entry_time, user, comment_data, persistent, COMMENTSOURCE_EXTERNAL, FALSE, (time_t)0, NULL);
result = add_new_comment((cmd == CMD_ADD_HOST_COMMENT) ? HOST_COMMENT : SERVICE_COMMENT,
USER_COMMENT,
host_name,
svc_description,
entry_time,
user,
comment_data,
persistent,
COMMENTSOURCE_EXTERNAL,
(expire_time > 0),
expire_time,
NULL);

if(result < 0)
return ERROR;
Expand Down
13 changes: 10 additions & 3 deletions base/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,16 @@ int init_event_queue(void)
}

/* schedule a new timed event */
timed_event *schedule_new_event(int event_type, int high_priority, time_t run_time,
int recurring, unsigned long event_interval, void *timing_func,
int compensate_for_time_change, void *event_data, void *event_args, int event_options)
timed_event *schedule_new_event(int event_type,
int high_priority,
time_t run_time,
int recurring,
unsigned long event_interval,
void *timing_func,
int compensate_for_time_change,
void *event_data,
void *event_args,
int event_options)
{
timed_event * new_event = NULL;
char run_time_string[MAX_DATETIME_LENGTH] = "";
Expand Down
121 changes: 111 additions & 10 deletions common/comments.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@ int initialize_comment_data(void) {


/* adds a new host or service comment */
int add_new_comment(int type, int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) {
int add_new_comment(int type,
int entry_type,
char *host_name,
char *svc_description,
time_t entry_time,
char *author_name,
char *comment_data,
int persistent,
int source,
int expires,
time_t expire_time,
unsigned long *comment_id) {
int result;
unsigned long new_comment_id = 0L;

Expand All @@ -84,11 +95,29 @@ int add_new_comment(int type, int entry_type, char *host_name, char *svc_descrip


/* adds a new host comment */
int add_new_host_comment(int entry_type, char *host_name, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) {
int add_new_host_comment(int entry_type,
char *host_name,
time_t entry_time,
char *author_name,
char *comment_data,
int persistent,
int source,
int expires,
time_t expire_time,
unsigned long *comment_id) {
int result;
unsigned long new_comment_id = 0L;

result = xcddefault_add_new_host_comment(entry_type, host_name, entry_time, author_name, comment_data, persistent, source, expires, expire_time, &new_comment_id);
result = xcddefault_add_new_host_comment(entry_type,
host_name,
entry_time,
author_name,
comment_data,
persistent,
source,
expires,
expire_time,
&new_comment_id);

/* save comment id */
if(comment_id != NULL)
Expand All @@ -104,11 +133,31 @@ int add_new_host_comment(int entry_type, char *host_name, time_t entry_time, cha


/* adds a new service comment */
int add_new_service_comment(int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) {
int add_new_service_comment(int entry_type,
char *host_name,
char *svc_description,
time_t entry_time,
char *author_name,
char *comment_data,
int persistent,
int source,
int expires,
time_t expire_time,
unsigned long *comment_id) {
int result;
unsigned long new_comment_id = 0L;

result = xcddefault_add_new_service_comment(entry_type, host_name, svc_description, entry_time, author_name, comment_data, persistent, source, expires, expire_time, &new_comment_id);
result = xcddefault_add_new_service_comment(entry_type,
host_name,
svc_description,
entry_time,
author_name,
comment_data,
persistent,
source,
expires,
expire_time,
&new_comment_id);

/* save comment id */
if(comment_id != NULL)
Expand Down Expand Up @@ -387,29 +436,81 @@ int add_comment_to_hashlist(nagios_comment *new_comment) {


/* adds a host comment to the list in memory */
int add_host_comment(int entry_type, char *host_name, time_t entry_time, char *author, char *comment_data, unsigned long comment_id, int persistent, int expires, time_t expire_time, int source) {
int add_host_comment(int entry_type,
char *host_name,
time_t entry_time,
char *author,
char *comment_data,
unsigned long comment_id,
int persistent,
int expires,
time_t expire_time,
int source) {
int result = OK;

result = add_comment(HOST_COMMENT, entry_type, host_name, NULL, entry_time, author, comment_data, comment_id, persistent, expires, expire_time, source);
result = add_comment(HOST_COMMENT,
entry_type,
host_name,
NULL,
entry_time,
author,
comment_data,
comment_id,
persistent,
expires,
expire_time,
source);

return result;
}



/* adds a service comment to the list in memory */
int add_service_comment(int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author, char *comment_data, unsigned long comment_id, int persistent, int expires, time_t expire_time, int source) {
int add_service_comment(int entry_type,
char *host_name,
char *svc_description,
time_t entry_time,
char *author,
char *comment_data,
unsigned long comment_id,
int persistent,
int expires,
time_t expire_time,
int source) {
int result = OK;

result = add_comment(SERVICE_COMMENT, entry_type, host_name, svc_description, entry_time, author, comment_data, comment_id, persistent, expires, expire_time, source);
result = add_comment(SERVICE_COMMENT,
entry_type,
host_name,
svc_description,
entry_time,
author,
comment_data,
comment_id,
persistent,
expires,
expire_time,
source);

return result;
}



/* adds a comment to the list in memory */
int add_comment(int comment_type, int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author, char *comment_data, unsigned long comment_id, int persistent, int expires, time_t expire_time, int source) {
int add_comment(int comment_type,
int entry_type,
char *host_name,
char *svc_description,
time_t entry_time,
char *author,
char *comment_data,
unsigned long comment_id,
int persistent,
int expires,
time_t expire_time,
int source) {
nagios_comment *new_comment = NULL;
nagios_comment *last_comment = NULL;
nagios_comment *temp_comment = NULL;
Expand Down
11 changes: 10 additions & 1 deletion xdata/xcddefault.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ int xcddefault_initialize_comment_data(void) {


/* adds a new host comment */
int xcddefault_add_new_host_comment(int entry_type, char *host_name, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) {
int xcddefault_add_new_host_comment(int entry_type,
char *host_name,
time_t entry_time,
char *author_name,
char *comment_data,
int persistent,
int source,
int expires,
time_t expire_time,
unsigned long *comment_id) {

/* find the next valid comment id */
while(find_host_comment(next_comment_id) != NULL)
Expand Down

0 comments on commit fa77664

Please sign in to comment.