summaryrefslogtreecommitdiffstats
path: root/lib/utils_base.c
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2008-03-19 14:42:12 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2008-03-19 14:42:12 (GMT)
commitb17b2421987bb8a7606948333e75f990b35852b8 (patch)
tree5d220f355728f1448f9dbd6f796631bbfef0733c /lib/utils_base.c
parentcab9440a671390e279228cd31ad56b055d611a21 (diff)
downloadmonitoring-plugins-b17b2421987bb8a7606948333e75f990b35852b8.tar.gz
1st pass at check_procs with multiple threshold checks
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/branches/new_threshold_syntax@1958 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/utils_base.c')
-rw-r--r--lib/utils_base.c135
1 files changed, 133 insertions, 2 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c
index d1453c6..1320b71 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -98,6 +98,138 @@ range
98 return NULL; 98 return NULL;
99} 99}
100 100
101/* New range string parsing routines, for the v2 thresholds syntax */
102/* Returns range if OK, otherwise errors. Sets utils_errno if error */
103int utils_errno;
104range *
105_parse_range_string_v2 (char *str) {
106 range *temp_range;
107 double start;
108 double end;
109 char *end_str;
110
111 temp_range = (range *) malloc(sizeof(range));
112
113 /* Initialise */
114 temp_range->start = 0;
115 temp_range->start_infinity = FALSE;
116 temp_range->end = 0;
117 temp_range->end_infinity = FALSE;
118 temp_range->alert_on = INSIDE;
119
120 if (str[0] == '^') {
121 temp_range->alert_on = OUTSIDE;
122 str++;
123 }
124
125 end_str = index(str, ':');
126 if (end_str == NULL) {
127 utils_errno = NP_RANGE_MISSING_COLON;
128 free(temp_range);
129 temp_range = NULL;
130 return NULL;
131 }
132 end_str++;
133 if (str[0] == ':') {
134 temp_range->start_infinity = TRUE;
135 } else {
136 start = strtod(str, NULL); /* Will stop at ':' */
137 set_range_start(temp_range, start);
138 }
139 if (strcmp(end_str, "") != 0) {
140 end = strtod(end_str, NULL);
141 set_range_end(temp_range, end);
142 } else {
143 temp_range->end_infinity = TRUE;
144 }
145
146 if (temp_range->start_infinity == TRUE ||
147 temp_range->end_infinity == TRUE ||
148 temp_range->start <= temp_range->end) {
149 return temp_range;
150 }
151 free(temp_range);
152 temp_range = NULL;
153 utils_errno = NP_RANGE_UNPARSEABLE;
154 return NULL;
155}
156
157void
158_die_on_parse_error(int errorcode) {
159 switch (errorcode) {
160 case NP_RANGE_UNPARSEABLE:
161 die(STATE_UNKNOWN, _("Range format incorrect\n"));
162 case NP_WARN_WITHIN_CRIT:
163 die(STATE_UNKNOWN, _("Warning level is a subset of critical and will not be alerted\n"));
164 case NP_RANGE_MISSING_COLON:
165 die(STATE_UNKNOWN, _("Range is missing a colon\n"));
166 case NP_MEMORY_ERROR:
167 die(STATE_UNKNOWN, _("Memory error\n"));
168 }
169}
170
171thresholds
172*_parse_thresholds_string(char *string) {
173 thresholds *temp_thresholds = NULL;
174 char *separator = NULL;
175 char *temp_string = NULL;
176 range *temp_range = NULL;
177 int rc;
178
179 temp_thresholds = malloc(sizeof(temp_thresholds));
180 if (temp_thresholds == NULL) {
181 utils_errno = NP_MEMORY_ERROR;
182 return NULL;
183 }
184
185 temp_thresholds->warning = NULL;
186 temp_thresholds->critical = NULL;
187
188 if (string == NULL || strcmp(string, "") == 0)
189 return temp_thresholds;
190
191 if((temp_string = strdup(string)) == NULL) {
192 free(temp_thresholds);
193 utils_errno = NP_MEMORY_ERROR;
194 return NULL;
195 }
196
197 /* Find critical part and parse the range */
198 separator = index(temp_string, '/');
199 if (separator) {
200 *separator = '\0';
201 separator++;
202 }
203 if ((strcmp(temp_string, "") != 0) && (temp_range = _parse_range_string_v2( temp_string )) == NULL) {
204 free(temp_thresholds);
205 free(temp_string);
206 /* utils_errno already set */
207 return NULL;
208 }
209 temp_thresholds->critical = temp_range;
210
211 if (separator == NULL || strcmp(separator, "") == 0) {
212 return temp_thresholds;
213 }
214 /* UOM not processed yet */
215 if(( temp_range = _parse_range_string_v2( separator )) == NULL) {
216 free(temp_thresholds);
217 free(temp_string);
218 return NULL;
219 }
220 temp_thresholds->warning = temp_range;
221 return temp_thresholds;
222}
223
224thresholds
225*parse_thresholds_string(char *string)
226{
227 thresholds *my_threshold;
228 if ((my_threshold = _parse_thresholds_string(string)) == NULL)
229 _die_on_parse_error(utils_errno);
230 return my_threshold;
231}
232
101/* returns 0 if okay, otherwise 1 */ 233/* returns 0 if okay, otherwise 1 */
102int 234int
103_set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string) 235_set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string)
@@ -139,8 +271,7 @@ set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_str
139 } 271 }
140} 272}
141 273
142void print_thresholds(const char *threshold_name, thresholds *my_threshold) { 274void print_thresholds(thresholds *my_threshold) {
143 printf("%s - ", threshold_name);
144 if (! my_threshold) { 275 if (! my_threshold) {
145 printf("Threshold not set"); 276 printf("Threshold not set");
146 } else { 277 } else {