1 /*****************************************************************************
2 *
3 * XCDDEFAULT.C - Default external comment data routines for Nagios
4 *
5 * Copyright (c) 2000-2007 Ethan Galstad (egalstad@nagios.org)
6 * Last Modified: 09-04-2007
7 *
8 * License:
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 *****************************************************************************/
24
25
26 /*********** COMMON HEADER FILES ***********/
27
28 #include "../include/config.h"
29 #include "../include/common.h"
30 #include "../include/locations.h"
31 #include "../include/comments.h"
32 #include "../include/macros.h"
33
34 #ifdef NSCORE
35 #include "../include/objects.h"
36 #include "../include/nagios.h"
37 #endif
38
39 #ifdef NSCGI
40 #include "../include/cgiutils.h"
41 #endif
42
43
44 /**** IMPLEMENTATION SPECIFIC HEADER FILES ****/
45 #include "xcddefault.h"
46
47
48 #ifdef NSCORE
49 extern unsigned long next_comment_id;
50 extern comment *comment_list;
51 #endif
52
53
54
55 #ifdef NSCORE
56
57 /******************************************************************/
58 /************ COMMENT INITIALIZATION/CLEANUP FUNCTIONS ************/
59 /******************************************************************/
60
61
62 /* initialize comment data */
xcddefault_initialize_comment_data(char * main_config_file)63 int xcddefault_initialize_comment_data(char *main_config_file) {
64 comment *temp_comment = NULL;
65
66 /* find the new starting index for comment id if its missing*/
67 if(next_comment_id == 0L) {
68 for(temp_comment = comment_list; temp_comment != NULL; temp_comment = temp_comment->next) {
69 if(temp_comment->comment_id >= next_comment_id)
70 next_comment_id = temp_comment->comment_id + 1;
71 }
72 }
73
74 /* initialize next comment id if necessary */
75 if(next_comment_id == 0L)
76 next_comment_id = 1;
77
78 return OK;
79 }
80
81
82 /* removes invalid and old comments from the comment file */
xcddefault_cleanup_comment_data(char * main_config_file)83 int xcddefault_cleanup_comment_data(char *main_config_file) {
84
85 /* nothing to do anymore */
86
87 return OK;
88 }
89
90
91
92
93
94 /******************************************************************/
95 /***************** DEFAULT DATA OUTPUT FUNCTIONS ******************/
96 /******************************************************************/
97
98
99 /* adds a new host comment */
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)100 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) {
101
102 /* find the next valid comment id */
103 while(find_host_comment(next_comment_id) != NULL)
104 next_comment_id++;
105
106 /* add comment to list in memory */
107 add_host_comment(entry_type, host_name, entry_time, author_name, comment_data, next_comment_id, persistent, expires, expire_time, source);
108
109 /* update comment file */
110 xcddefault_save_comment_data();
111
112 /* return the id for the comment we are about to add (this happens in the main code) */
113 if(comment_id != NULL)
114 *comment_id = next_comment_id;
115
116 /* increment the comment id */
117 next_comment_id++;
118
119 return OK;
120 }
121
122
123 /* adds a new service comment */
xcddefault_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)124 int xcddefault_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) {
125
126 /* find the next valid comment id */
127 while(find_service_comment(next_comment_id) != NULL)
128 next_comment_id++;
129
130 /* add comment to list in memory */
131 add_service_comment(entry_type, host_name, svc_description, entry_time, author_name, comment_data, next_comment_id, persistent, expires, expire_time, source);
132
133 /* update comment file */
134 xcddefault_save_comment_data();
135
136 /* return the id for the comment we are about to add (this happens in the main code) */
137 if(comment_id != NULL)
138 *comment_id = next_comment_id;
139
140 /* increment the comment id */
141 next_comment_id++;
142
143 return OK;
144 }
145
146
147
148 /******************************************************************/
149 /**************** COMMENT DELETION FUNCTIONS **********************/
150 /******************************************************************/
151
152
153 /* deletes a host comment */
xcddefault_delete_host_comment(unsigned long comment_id)154 int xcddefault_delete_host_comment(unsigned long comment_id) {
155
156 /* update comment file */
157 xcddefault_save_comment_data();
158
159 return OK;
160 }
161
162
163 /* deletes a service comment */
xcddefault_delete_service_comment(unsigned long comment_id)164 int xcddefault_delete_service_comment(unsigned long comment_id) {
165
166 /* update comment file */
167 xcddefault_save_comment_data();
168
169 return OK;
170 }
171
172
173
174 /******************************************************************/
175 /****************** COMMENT OUTPUT FUNCTIONS **********************/
176 /******************************************************************/
177
178 /* writes comment data to file */
xcddefault_save_comment_data(void)179 int xcddefault_save_comment_data(void) {
180
181 /* don't update the status file now (too inefficent), let aggregated status updates do it */
182 return OK;
183 }
184
185 #endif
186
187