summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_apt.c70
-rw-r--r--plugins/check_by_ssh.c13
-rw-r--r--plugins/check_cluster.c27
-rw-r--r--plugins/check_dig.c25
-rw-r--r--plugins/check_disk.c49
-rw-r--r--plugins/check_dns.c13
-rw-r--r--plugins/check_fping.c53
-rw-r--r--plugins/check_game.c44
-rw-r--r--plugins/check_hpjd.c28
-rw-r--r--plugins/check_http.c173
10 files changed, 199 insertions, 296 deletions
diff --git a/plugins/check_apt.c b/plugins/check_apt.c
index f67ebf9..f72b9b5 100644
--- a/plugins/check_apt.c
+++ b/plugins/check_apt.c
@@ -43,6 +43,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
43#include "common.h" 43#include "common.h"
44#include "runcmd.h" 44#include "runcmd.h"
45#include "utils.h" 45#include "utils.h"
46#include "utils.h"
46#include "regex.h" 47#include "regex.h"
47 48
48/* some constants */ 49/* some constants */
@@ -74,7 +75,6 @@ int run_upgrade(int *pkgcount, int *secpkgcount);
74char* add_to_regexp(char *expr, const char *next); 75char* add_to_regexp(char *expr, const char *next);
75 76
76/* configuration variables */ 77/* configuration variables */
77static int verbose = 0; /* -v */
78static int do_update = 0; /* whether to call apt-get update */ 78static int do_update = 0; /* whether to call apt-get update */
79static upgrade_type upgrade = UPGRADE; /* which type of upgrade to do */ 79static upgrade_type upgrade = UPGRADE; /* which type of upgrade to do */
80static char *upgrade_opts = NULL; /* options to override defaults for upgrade */ 80static char *upgrade_opts = NULL; /* options to override defaults for upgrade */
@@ -90,6 +90,7 @@ static int exec_warning = 0; /* if a cmd exited non-zero */
90int main (int argc, char **argv) { 90int main (int argc, char **argv) {
91 int result=STATE_UNKNOWN, packages_available=0, sec_count=0; 91 int result=STATE_UNKNOWN, packages_available=0, sec_count=0;
92 92
93 np_set_mynames(argv[0], "APT");
93 if (process_arguments(argc, argv) == ERROR) 94 if (process_arguments(argc, argv) == ERROR)
94 usage_va(_("Could not parse arguments")); 95 usage_va(_("Could not parse arguments"));
95 96
@@ -115,8 +116,8 @@ int main (int argc, char **argv) {
115 result = max_state(result, STATE_OK); 116 result = max_state(result, STATE_OK);
116 } 117 }
117 118
118 printf(_("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s\n"), 119 np_die(result,
119 state_text(result), 120 _("%d packages available for %s (%d critical updates). %s%s%s%s"),
120 packages_available, 121 packages_available,
121 (upgrade==DIST_UPGRADE)?"dist-upgrade":"upgrade", 122 (upgrade==DIST_UPGRADE)?"dist-upgrade":"upgrade",
122 sec_count, 123 sec_count,
@@ -125,8 +126,6 @@ int main (int argc, char **argv) {
125 (exec_warning)?" errors detected":"", 126 (exec_warning)?" errors detected":"",
126 (stderr_warning||exec_warning)?". run with -v for information.":"" 127 (stderr_warning||exec_warning)?". run with -v for information.":""
127 ); 128 );
128
129 return result;
130} 129}
131 130
132/* process command-line arguments */ 131/* process command-line arguments */
@@ -161,7 +160,7 @@ int process_arguments (int argc, char **argv) {
161 print_revision(progname, revision); 160 print_revision(progname, revision);
162 exit(STATE_OK); 161 exit(STATE_OK);
163 case 'v': 162 case 'v':
164 verbose++; 163 np_increase_verbosity(1);
165 break; 164 break;
166 case 't': 165 case 't':
167 timeout_interval=atoi(optarg); 166 timeout_interval=atoi(optarg);
@@ -170,14 +169,14 @@ int process_arguments (int argc, char **argv) {
170 upgrade=DIST_UPGRADE; 169 upgrade=DIST_UPGRADE;
171 if(optarg!=NULL){ 170 if(optarg!=NULL){
172 upgrade_opts=strdup(optarg); 171 upgrade_opts=strdup(optarg);
173 if(upgrade_opts==NULL) die(STATE_UNKNOWN, "strdup failed"); 172 if(upgrade_opts==NULL) np_die(STATE_UNKNOWN, "strdup failed: %m");
174 } 173 }
175 break; 174 break;
176 case 'U': 175 case 'U':
177 upgrade=UPGRADE; 176 upgrade=UPGRADE;
178 if(optarg!=NULL){ 177 if(optarg!=NULL){
179 upgrade_opts=strdup(optarg); 178 upgrade_opts=strdup(optarg);
180 if(upgrade_opts==NULL) die(STATE_UNKNOWN, "strdup failed"); 179 if(upgrade_opts==NULL) np_die(STATE_UNKNOWN, "strdup failed: %m");
181 } 180 }
182 break; 181 break;
183 case 'n': 182 case 'n':
@@ -187,7 +186,7 @@ int process_arguments (int argc, char **argv) {
187 do_update=1; 186 do_update=1;
188 if(optarg!=NULL){ 187 if(optarg!=NULL){
189 update_opts=strdup(optarg); 188 update_opts=strdup(optarg);
190 if(update_opts==NULL) die(STATE_UNKNOWN, "strdup failed"); 189 if(update_opts==NULL) np_die(STATE_UNKNOWN, "strdup failed: %m");
191 } 190 }
192 break; 191 break;
193 case 'i': 192 case 'i':
@@ -228,22 +227,22 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
228 regres=regcomp(&ireg, include_ptr, REG_EXTENDED); 227 regres=regcomp(&ireg, include_ptr, REG_EXTENDED);
229 if(regres!=0) { 228 if(regres!=0) {
230 regerror(regres, &ireg, rerrbuf, 64); 229 regerror(regres, &ireg, rerrbuf, 64);
231 die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf); 230 np_die(STATE_UNKNOWN, _("Error compiling regexp: %s"), rerrbuf);
232 } 231 }
233 232
234 if(do_exclude!=NULL){ 233 if(do_exclude!=NULL){
235 regres=regcomp(&ereg, do_exclude, REG_EXTENDED); 234 regres=regcomp(&ereg, do_exclude, REG_EXTENDED);
236 if(regres!=0) { 235 if(regres!=0) {
237 regerror(regres, &ereg, rerrbuf, 64); 236 regerror(regres, &ereg, rerrbuf, 64);
238 die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), 237 np_die(STATE_UNKNOWN, _("Error compiling regexp: %s"),
239 progname, rerrbuf); 238 rerrbuf);
240 } 239 }
241 } 240 }
242 regres=regcomp(&sreg, crit_ptr, REG_EXTENDED); 241 regres=regcomp(&sreg, crit_ptr, REG_EXTENDED);
243 if(regres!=0) { 242 if(regres!=0) {
244 regerror(regres, &ereg, rerrbuf, 64); 243 regerror(regres, &ereg, rerrbuf, 64);
245 die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), 244 np_die(STATE_UNKNOWN, _("Error compiling regexp: %s"),
246 progname, rerrbuf); 245 rerrbuf);
247 } 246 }
248 247
249 cmdline=construct_cmdline(upgrade, upgrade_opts); 248 cmdline=construct_cmdline(upgrade, upgrade_opts);
@@ -255,8 +254,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
255 if(result != 0){ 254 if(result != 0){
256 exec_warning=1; 255 exec_warning=1;
257 result = STATE_UNKNOWN; 256 result = STATE_UNKNOWN;
258 fprintf(stderr, _("'%s' exited with non-zero status.\n"), 257 np_verbose(_("'%s' exited with non-zero status."), cmdline);
259 cmdline);
260 } 258 }
261 259
262 /* parse the output, which should only consist of lines like 260 /* parse the output, which should only consist of lines like
@@ -269,9 +267,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
269 * in which case the logic here will slightly change. 267 * in which case the logic here will slightly change.
270 */ 268 */
271 for(i = 0; i < chld_out.lines; i++) { 269 for(i = 0; i < chld_out.lines; i++) {
272 if(verbose){ 270 np_verbatim(chld_out.line[i]);
273 printf("%s\n", chld_out.line[i]);
274 }
275 /* if it is a package we care about */ 271 /* if it is a package we care about */
276 if(regexec(&ireg, chld_out.line[i], 0, NULL, 0)==0){ 272 if(regexec(&ireg, chld_out.line[i], 0, NULL, 0)==0){
277 /* if we're not excluding, or it's not in the 273 /* if we're not excluding, or it's not in the
@@ -281,11 +277,9 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
281 pc++; 277 pc++;
282 if(regexec(&sreg, chld_out.line[i], 0, NULL, 0)==0){ 278 if(regexec(&sreg, chld_out.line[i], 0, NULL, 0)==0){
283 spc++; 279 spc++;
284 if(verbose) printf("*"); 280 np_debug(1, "*");
285 }
286 if(verbose){
287 printf("*%s\n", chld_out.line[i]);
288 } 281 }
282 np_verbose("*%s", chld_out.line[i]);
289 } 283 }
290 } 284 }
291 } 285 }
@@ -296,11 +290,8 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
296 if(chld_err.buflen){ 290 if(chld_err.buflen){
297 stderr_warning=1; 291 stderr_warning=1;
298 result = max_state(result, STATE_WARNING); 292 result = max_state(result, STATE_WARNING);
299 if(verbose){ 293 for(i = 0; i < chld_err.lines; i++)
300 for(i = 0; i < chld_err.lines; i++) { 294 np_verbatim(chld_err.line[i]);
301 fprintf(stderr, "%s\n", chld_err.line[i]);
302 }
303 }
304 } 295 }
305 regfree(&ireg); 296 regfree(&ireg);
306 regfree(&sreg); 297 regfree(&sreg);
@@ -324,25 +315,18 @@ int run_update(void){
324 if(result != 0){ 315 if(result != 0){
325 exec_warning=1; 316 exec_warning=1;
326 result = STATE_CRITICAL; 317 result = STATE_CRITICAL;
327 fprintf(stderr, _("'%s' exited with non-zero status.\n"), 318 np_verbose(_("'%s' exited with non-zero status."), cmdline);
328 cmdline);
329 } 319 }
330 320
331 if(verbose){ 321 for(i = 0; i < chld_out.lines; i++)
332 for(i = 0; i < chld_out.lines; i++) { 322 np_verbatim(chld_out.line[i]);
333 printf("%s\n", chld_out.line[i]);
334 }
335 }
336 323
337 /* If we get anything on stderr, at least set warning */ 324 /* If we get anything on stderr, at least set warning */
338 if(chld_err.buflen){ 325 if(chld_err.buflen){
339 stderr_warning=1; 326 stderr_warning=1;
340 result = max_state(result, STATE_WARNING); 327 result = max_state(result, STATE_WARNING);
341 if(verbose){ 328 for(i = 0; i < chld_err.lines; i++)
342 for(i = 0; i < chld_err.lines; i++) { 329 np_verbatim(chld_err.line[i]);
343 fprintf(stderr, "%s\n", chld_err.line[i]);
344 }
345 }
346 } 330 }
347 free(cmdline); 331 free(cmdline);
348 return result; 332 return result;
@@ -353,12 +337,12 @@ char* add_to_regexp(char *expr, const char *next){
353 337
354 if(expr==NULL){ 338 if(expr==NULL){
355 re=malloc(sizeof(char)*(strlen("^Inst () ")+strlen(next)+1)); 339 re=malloc(sizeof(char)*(strlen("^Inst () ")+strlen(next)+1));
356 if(!re) die(STATE_UNKNOWN, "malloc failed!\n"); 340 if(!re) np_die(STATE_UNKNOWN, "malloc failed: %m");
357 sprintf(re, "^Inst (%s) ", next); 341 sprintf(re, "^Inst (%s) ", next);
358 } else { 342 } else {
359 /* resize it, adding an extra char for the new '|' separator */ 343 /* resize it, adding an extra char for the new '|' separator */
360 re=realloc(expr, sizeof(char)*strlen(expr)+1+strlen(next)+1); 344 re=realloc(expr, sizeof(char)*strlen(expr)+1+strlen(next)+1);
361 if(!re) die(STATE_UNKNOWN, "realloc failed!\n"); 345 if(!re) np_die(STATE_UNKNOWN, "realloc failed: %m");
362 /* append it starting at ')' in the old re */ 346 /* append it starting at ')' in the old re */
363 sprintf((char*)(re+strlen(re)-2), "|%s) ", next); 347 sprintf((char*)(re+strlen(re)-2), "|%s) ", next);
364 } 348 }
@@ -394,7 +378,7 @@ char* construct_cmdline(upgrade_type u, const char *opts){
394 len+=strlen(aptcmd)+1; /* "upgrade\0" */ 378 len+=strlen(aptcmd)+1; /* "upgrade\0" */
395 379
396 cmd=(char*)malloc(sizeof(char)*len); 380 cmd=(char*)malloc(sizeof(char)*len);
397 if(cmd==NULL) die(STATE_UNKNOWN, "malloc failed"); 381 if(cmd==NULL) np_die(STATE_UNKNOWN, "malloc failed: %m");
398 sprintf(cmd, "%s %s %s", PATH_TO_APTGET, opts_ptr, aptcmd); 382 sprintf(cmd, "%s %s %s", PATH_TO_APTGET, opts_ptr, aptcmd);
399 return cmd; 383 return cmd;
400} 384}
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 46d1297..5594087 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -57,7 +57,6 @@ char *outputfile = NULL;
57char *host_shortname = NULL; 57char *host_shortname = NULL;
58char **service; 58char **service;
59int passive = FALSE; 59int passive = FALSE;
60int verbose = FALSE;
61 60
62int 61int
63main (int argc, char **argv) 62main (int argc, char **argv)
@@ -71,6 +70,7 @@ main (int argc, char **argv)
71 FILE *fp = NULL; 70 FILE *fp = NULL;
72 struct output chld_out, chld_err; 71 struct output chld_out, chld_err;
73 72
73 np_set_mynames(argv[0], "BY-SSH");
74 remotecmd = ""; 74 remotecmd = "";
75 comm = strdup (SSH_COMMAND); 75 comm = strdup (SSH_COMMAND);
76 76
@@ -89,8 +89,7 @@ main (int argc, char **argv)
89 alarm (timeout_interval); 89 alarm (timeout_interval);
90 90
91 /* run the command */ 91 /* run the command */
92 if (verbose) 92 np_verbatim(comm);
93 printf ("%s\n", comm);
94 93
95 result = np_runcmd(comm, &chld_out, &chld_err, 0); 94 result = np_runcmd(comm, &chld_out, &chld_err, 0);
96 95
@@ -206,7 +205,7 @@ process_arguments (int argc, char **argv)
206 print_help (); 205 print_help ();
207 exit (STATE_OK); 206 exit (STATE_OK);
208 case 'v': /* help */ 207 case 'v': /* help */
209 verbose = TRUE; 208 np_increase_verbosity(1);
210 break; 209 break;
211 case 't': /* timeout period */ 210 case 't': /* timeout period */
212 if (!is_integer (optarg)) 211 if (!is_integer (optarg))
@@ -292,7 +291,7 @@ process_arguments (int argc, char **argv)
292 c = optind; 291 c = optind;
293 if (hostname == NULL) { 292 if (hostname == NULL) {
294 if (c <= argc) { 293 if (c <= argc) {
295 die (STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname); 294 np_die(STATE_UNKNOWN, _("You must provide a host name"));
296 } 295 }
297 host_or_die(argv[c]); 296 host_or_die(argv[c]);
298 hostname = argv[c++]; 297 hostname = argv[c++];
@@ -326,10 +325,10 @@ validate_arguments (void)
326 return ERROR; 325 return ERROR;
327 326
328 if (passive && commands != services) 327 if (passive && commands != services)
329 die (STATE_UNKNOWN, _("%s: In passive mode, you must provide a service name for each command.\n"), progname); 328 np_die(STATE_UNKNOWN, _("In passive mode, you must provide a service name for each command."));
330 329
331 if (passive && host_shortname == NULL) 330 if (passive && host_shortname == NULL)
332 die (STATE_UNKNOWN, _("%s: In passive mode, you must provide the host short name from the nagios configs.\n"), progname); 331 np_die(STATE_UNKNOWN, _("In passive mode, you must provide the host short name from the nagios configs."));
333 332
334 return OK; 333 return OK;
335} 334}
diff --git a/plugins/check_cluster.c b/plugins/check_cluster.c
index 703fff9..031f833 100644
--- a/plugins/check_cluster.c
+++ b/plugins/check_cluster.c
@@ -59,8 +59,6 @@ int check_type=CHECK_SERVICES;
59char *data_vals=NULL; 59char *data_vals=NULL;
60char *label=NULL; 60char *label=NULL;
61 61
62int verbose=0;
63
64int process_arguments(int,char **); 62int process_arguments(int,char **);
65 63
66 64
@@ -71,12 +69,13 @@ int main(int argc, char **argv){
71 int return_code=STATE_OK; 69 int return_code=STATE_OK;
72 thresholds *thresholds = NULL; 70 thresholds *thresholds = NULL;
73 71
72 np_set_mynames(argv[0], "CLUSTER");
74 if(process_arguments(argc,argv)==ERROR) 73 if(process_arguments(argc,argv)==ERROR)
75 usage(_("Could not parse arguments")); 74 usage(_("Could not parse arguments"));
76 75
77 /* Initialize the thresholds */ 76 /* Initialize the thresholds */
78 set_thresholds(&thresholds, warn_threshold, crit_threshold); 77 set_thresholds(&thresholds, warn_threshold, crit_threshold);
79 if(verbose) 78 if(np_get_verbosity()>0)
80 print_thresholds("check_cluster", thresholds); 79 print_thresholds("check_cluster", thresholds);
81 80
82 /* check the data values */ 81 /* check the data values */
@@ -121,21 +120,17 @@ int main(int argc, char **argv){
121 120
122 121
123 /* return the status of the cluster */ 122 /* return the status of the cluster */
124 if(check_type==CHECK_SERVICES){ 123 if(check_type==CHECK_SERVICES)
125 return_code=get_status(total_services_warning+total_services_unknown+total_services_critical, thresholds); 124 np_die(get_status(total_services_warning+total_services_unknown+total_services_critical, thresholds),
126 printf("CLUSTER %s: %s: %d ok, %d warning, %d unknown, %d critical\n", 125 "%s: %d ok, %d warning, %d unknown, %d critical\n",
127 state_text(return_code), (label==NULL)?"Service cluster":label, 126 (label==NULL)?"Service cluster":label,
128 total_services_ok,total_services_warning, 127 total_services_ok,total_services_warning,
129 total_services_unknown,total_services_critical); 128 total_services_unknown,total_services_critical);
130 } 129 else
131 else{ 130 np_die(get_status(total_services_warning+total_services_unknown+total_services_critical, thresholds),
132 return_code=get_status(total_hosts_down+total_hosts_unreachable, thresholds); 131 "%s: %d up, %d down, %d unreachable\n",
133 printf("CLUSTER %s: %s: %d up, %d down, %d unreachable\n", 132 (label==NULL)?"Host cluster":label,
134 state_text(return_code), (label==NULL)?"Host cluster":label,
135 total_hosts_up,total_hosts_down,total_hosts_unreachable); 133 total_hosts_up,total_hosts_down,total_hosts_unreachable);
136 }
137
138 return return_code;
139} 134}
140 135
141 136
@@ -198,7 +193,7 @@ int process_arguments(int argc, char **argv){
198 break; 193 break;
199 194
200 case 'v': /* verbose */ 195 case 'v': /* verbose */
201 verbose++; 196 np_increase_verbosity(1);
202 break; 197 break;
203 198
204 case 'V': /* version */ 199 case 'V': /* version */
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index e850337..77bc9b7 100644
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
@@ -59,7 +59,6 @@ char *query_address = NULL;
59char *record_type = "A"; 59char *record_type = "A";
60char *expected_address = NULL; 60char *expected_address = NULL;
61char *dns_server = NULL; 61char *dns_server = NULL;
62int verbose = FALSE;
63int server_port = DEFAULT_PORT; 62int server_port = DEFAULT_PORT;
64double warning_interval = UNDEFINED; 63double warning_interval = UNDEFINED;
65double critical_interval = UNDEFINED; 64double critical_interval = UNDEFINED;
@@ -77,6 +76,7 @@ main (int argc, char **argv)
77 double elapsed_time; 76 double elapsed_time;
78 int result = STATE_UNKNOWN; 77 int result = STATE_UNKNOWN;
79 78
79 np_set_mynames(argv[0], "DNS");
80 setlocale (LC_ALL, ""); 80 setlocale (LC_ALL, "");
81 bindtextdomain (PACKAGE, LOCALEDIR); 81 bindtextdomain (PACKAGE, LOCALEDIR);
82 textdomain (PACKAGE); 82 textdomain (PACKAGE);
@@ -95,13 +95,11 @@ main (int argc, char **argv)
95 alarm (timeout_interval); 95 alarm (timeout_interval);
96 gettimeofday (&tv, NULL); 96 gettimeofday (&tv, NULL);
97 97
98 if (verbose) { 98 np_verbatim(command_line);
99 printf ("%s\n", command_line); 99 if(expected_address != NULL) {
100 if(expected_address != NULL) { 100 np_verbose(_("Looking for: '%s'"), expected_address);
101 printf (_("Looking for: '%s'\n"), expected_address); 101 } else {
102 } else { 102 np_verbose(_("Looking for: '%s'"), query_address);
103 printf (_("Looking for: '%s'\n"), query_address);
104 }
105 } 103 }
106 104
107 /* run the command */ 105 /* run the command */
@@ -117,8 +115,7 @@ main (int argc, char **argv)
117 /* loop through the whole 'ANSWER SECTION' */ 115 /* loop through the whole 'ANSWER SECTION' */
118 for(; i < chld_out.lines; i++) { 116 for(; i < chld_out.lines; i++) {
119 /* get the host address */ 117 /* get the host address */
120 if (verbose) 118 np_verbatim(chld_out.line[i]);
121 printf ("%s\n", chld_out.line[i]);
122 119
123 if (strstr (chld_out.line[i], (expected_address == NULL ? query_address : expected_address)) != NULL) { 120 if (strstr (chld_out.line[i], (expected_address == NULL ? query_address : expected_address)) != NULL) {
124 msg = chld_out.line[i]; 121 msg = chld_out.line[i];
@@ -165,8 +162,9 @@ main (int argc, char **argv)
165 else if (warning_interval > UNDEFINED && elapsed_time > warning_interval) 162 else if (warning_interval > UNDEFINED && elapsed_time > warning_interval)
166 result = STATE_WARNING; 163 result = STATE_WARNING;
167 164
168 printf ("DNS %s - %.3f seconds response time (%s)|%s\n", 165 np_die(result,
169 state_text (result), elapsed_time, 166 "%.3f seconds response time (%s)|%s\n",
167 elapsed_time,
170 msg ? msg : _("Probably a non-existent host/domain"), 168 msg ? msg : _("Probably a non-existent host/domain"),
171 fperfdata("time", elapsed_time, "s", 169 fperfdata("time", elapsed_time, "s",
172 (warning_interval>UNDEFINED?TRUE:FALSE), 170 (warning_interval>UNDEFINED?TRUE:FALSE),
@@ -174,7 +172,6 @@ main (int argc, char **argv)
174 (critical_interval>UNDEFINED?TRUE:FALSE), 172 (critical_interval>UNDEFINED?TRUE:FALSE),
175 critical_interval, 173 critical_interval,
176 TRUE, 0, FALSE, 0)); 174 TRUE, 0, FALSE, 0));
177 return result;
178} 175}
179 176
180 177
@@ -257,7 +254,7 @@ process_arguments (int argc, char **argv)
257 } 254 }
258 break; 255 break;
259 case 'v': /* verbose */ 256 case 'v': /* verbose */
260 verbose = TRUE; 257 np_increase_verbosity(1);
261 break; 258 break;
262 case 'T': 259 case 'T':
263 record_type = optarg; 260 record_type = optarg;
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 03f0949..91cc097 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -134,7 +134,6 @@ char *path;
134char *exclude_device; 134char *exclude_device;
135char *units; 135char *units;
136uintmax_t mult = 1024 * 1024; 136uintmax_t mult = 1024 * 1024;
137int verbose = 0;
138int erronly = FALSE; 137int erronly = FALSE;
139int display_mntp = FALSE; 138int display_mntp = FALSE;
140int exact_match = FALSE; 139int exact_match = FALSE;
@@ -178,7 +177,8 @@ main (int argc, char **argv)
178 struct name_list *seen = NULL; 177 struct name_list *seen = NULL;
179 struct stat *stat_buf; 178 struct stat *stat_buf;
180 179
181 preamble = strdup (" - free space:"); 180 np_set_mynames(argv[0], "DISK");
181 preamble = strdup (" free space:");
182 output = strdup (""); 182 output = strdup ("");
183 details = strdup (""); 183 details = strdup ("");
184 perf = strdup (""); 184 perf = strdup ("");
@@ -228,12 +228,12 @@ main (int argc, char **argv)
228 /* Process for every path in list */ 228 /* Process for every path in list */
229 for (path = path_select_list; path; path=path->name_next) { 229 for (path = path_select_list; path; path=path->name_next) {
230 230
231 if (verbose > 3 && path->freespace_percent->warning != NULL && path->freespace_percent->critical != NULL) 231 if (path->freespace_percent->warning != NULL && path->freespace_percent->critical != NULL)
232 printf("Thresholds(pct) for %s warn: %f crit %f\n",path->name, path->freespace_percent->warning->end, 232 np_debug(4, "Thresholds(pct) for %s warn: %f crit %f\n",path->name, path->freespace_percent->warning->end,
233 path->freespace_percent->critical->end); 233 path->freespace_percent->critical->end);
234 234
235 if (verbose > 3 && path->group != NULL) 235 if (path->group != NULL)
236 printf("Group of %s: %s\n",path->name,path->group); 236 np_debug(4, "Group of %s: %s\n",path->name,path->group);
237 237
238 /* reset disk result */ 238 /* reset disk result */
239 disk_result = STATE_UNKNOWN; 239 disk_result = STATE_UNKNOWN;
@@ -270,8 +270,7 @@ main (int argc, char **argv)
270 fsp.fsu_files += tmpfsp.fsu_files; /* Total file nodes. */ 270 fsp.fsu_files += tmpfsp.fsu_files; /* Total file nodes. */
271 fsp.fsu_ffree += tmpfsp.fsu_ffree; /* Free file nodes. */ 271 fsp.fsu_ffree += tmpfsp.fsu_ffree; /* Free file nodes. */
272 272
273 if (verbose > 3) 273 np_debug(4, "Group %s: add %llu blocks (%s) \n", path->group, tmpfsp.fsu_bavail, temp_list->name);
274 printf("Group %s: add %llu blocks (%s) \n", path->group, tmpfsp.fsu_bavail, temp_list->name);
275 /* printf("Group %s: add %u blocks (%s)\n", temp_list->name); // path->group, tmpfsp.fsu_bavail, temp_list->name); */ 274 /* printf("Group %s: add %u blocks (%s)\n", temp_list->name); // path->group, tmpfsp.fsu_bavail, temp_list->name); */
276 275
277 np_add_name(&seen, temp_list->best_match->me_mountdir); 276 np_add_name(&seen, temp_list->best_match->me_mountdir);
@@ -318,35 +317,33 @@ main (int argc, char **argv)
318 dused_inodes_percent = calculate_percent(fsp.fsu_files - fsp.fsu_ffree, fsp.fsu_files); 317 dused_inodes_percent = calculate_percent(fsp.fsu_files - fsp.fsu_ffree, fsp.fsu_files);
319 dfree_inodes_percent = 100 - dused_inodes_percent; 318 dfree_inodes_percent = 100 - dused_inodes_percent;
320 319
321 if (verbose >= 3) { 320 np_debug(3, "For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g\n",
322 printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g\n",
323 me->me_mountdir, dused_pct, dfree_pct, dused_units, dfree_units, dtotal_units, dused_inodes_percent, dfree_inodes_percent); 321 me->me_mountdir, dused_pct, dfree_pct, dused_units, dfree_units, dtotal_units, dused_inodes_percent, dfree_inodes_percent);
324 }
325 322
326 /* Threshold comparisons */ 323 /* Threshold comparisons */
327 324
328 temp_result = get_status(dfree_units, path->freespace_units); 325 temp_result = get_status(dfree_units, path->freespace_units);
329 if (verbose >=3) printf("Freespace_units result=%d\n", temp_result); 326 np_debug(3, "Freespace_units result=%d\n", temp_result);
330 disk_result = max_state( disk_result, temp_result ); 327 disk_result = max_state( disk_result, temp_result );
331 328
332 temp_result = get_status(dfree_pct, path->freespace_percent); 329 temp_result = get_status(dfree_pct, path->freespace_percent);
333 if (verbose >=3) printf("Freespace%% result=%d\n", temp_result); 330 np_debug(3, "Freespace%% result=%d\n", temp_result);
334 disk_result = max_state( disk_result, temp_result ); 331 disk_result = max_state( disk_result, temp_result );
335 332
336 temp_result = get_status(dused_units, path->usedspace_units); 333 temp_result = get_status(dused_units, path->usedspace_units);
337 if (verbose >=3) printf("Usedspace_units result=%d\n", temp_result); 334 np_debug(3, "Usedspace_units result=%d\n", temp_result);
338 disk_result = max_state( disk_result, temp_result ); 335 disk_result = max_state( disk_result, temp_result );
339 336
340 temp_result = get_status(dused_pct, path->usedspace_percent); 337 temp_result = get_status(dused_pct, path->usedspace_percent);
341 if (verbose >=3) printf("Usedspace_percent result=%d\n", temp_result); 338 np_debug(3, "Usedspace_percent result=%d\n", temp_result);
342 disk_result = max_state( disk_result, temp_result ); 339 disk_result = max_state( disk_result, temp_result );
343 340
344 temp_result = get_status(dused_inodes_percent, path->usedinodes_percent); 341 temp_result = get_status(dused_inodes_percent, path->usedinodes_percent);
345 if (verbose >=3) printf("Usedinodes_percent result=%d\n", temp_result); 342 np_debug(3, "Usedinodes_percent result=%d\n", temp_result);
346 disk_result = max_state( disk_result, temp_result ); 343 disk_result = max_state( disk_result, temp_result );
347 344
348 temp_result = get_status(dfree_inodes_percent, path->freeinodes_percent); 345 temp_result = get_status(dfree_inodes_percent, path->freeinodes_percent);
349 if (verbose >=3) printf("Freeinodes_percent result=%d\n", temp_result); 346 np_debug(3, "Freeinodes_percent result=%d\n", temp_result);
350 disk_result = max_state( disk_result, temp_result ); 347 disk_result = max_state( disk_result, temp_result );
351 348
352 result = max_state(result, disk_result); 349 result = max_state(result, disk_result);
@@ -381,10 +378,10 @@ main (int argc, char **argv)
381 TRUE, 0, 378 TRUE, 0,
382 TRUE, dtotal_units)); 379 TRUE, dtotal_units));
383 380
384 if (disk_result==STATE_OK && erronly && !verbose) 381 if (disk_result==STATE_OK && erronly && np_get_verbosity()<=0)
385 continue; 382 continue;
386 383
387 if (disk_result!=STATE_OK || verbose>=0) { 384 if (disk_result!=STATE_OK || np_get_verbosity()>=0) {
388 asprintf (&output, "%s %s %.0f %s (%.0f%%", 385 asprintf (&output, "%s %s %.0f %s (%.0f%%",
389 output, 386 output,
390 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, 387 (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
@@ -410,12 +407,11 @@ main (int argc, char **argv)
410 407
411 } 408 }
412 409
413 if (verbose > 2) 410 if (np_get_verbosity()>=3)
414 asprintf (&output, "%s%s", output, details); 411 asprintf (&output, "%s%s", output, details);
415 412
416 413
417 printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf); 414 np_die(result, "%s%s|%s", (erronly && result==STATE_OK) ? "" : preamble, output, perf);
418 return result;
419} 415}
420 416
421 417
@@ -635,10 +631,10 @@ process_arguments (int argc, char **argv)
635 np_add_name(&fs_exclude_list, optarg); 631 np_add_name(&fs_exclude_list, optarg);
636 break; 632 break;
637 case 'v': /* verbose */ 633 case 'v': /* verbose */
638 verbose++; 634 np_increase_verbosity(1);
639 break; 635 break;
640 case 'q': /* verbose */ 636 case 'q': /* verbose */
641 verbose--; 637 np_decrease_verbosity(1);
642 break; 638 break;
643 case 'e': 639 case 'e':
644 erronly = TRUE; 640 erronly = TRUE;
@@ -670,8 +666,7 @@ process_arguments (int argc, char **argv)
670 for (me = mount_list; me; me = me->me_next) { 666 for (me = mount_list; me; me = me->me_next) {
671 if (np_regex_match_mount_entry(me, &re)) { 667 if (np_regex_match_mount_entry(me, &re)) {
672 fnd = true; 668 fnd = true;
673 if (verbose > 3) 669 np_debug(4, "%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);
674 printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);
675 670
676 /* add parameter if not found. overwrite thresholds if path has already been added */ 671 /* add parameter if not found. overwrite thresholds if path has already been added */
677 if (! (se = np_find_parameter(path_select_list, me->me_mountdir))) { 672 if (! (se = np_find_parameter(path_select_list, me->me_mountdir))) {
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 454f813..d81536a 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -56,7 +56,6 @@ void print_usage (void);
56char query_address[ADDRESS_LENGTH] = ""; 56char query_address[ADDRESS_LENGTH] = "";
57char dns_server[ADDRESS_LENGTH] = ""; 57char dns_server[ADDRESS_LENGTH] = "";
58char ptr_server[ADDRESS_LENGTH] = ""; 58char ptr_server[ADDRESS_LENGTH] = "";
59int verbose = FALSE;
60char expected_address[ADDRESS_LENGTH] = ""; 59char expected_address[ADDRESS_LENGTH] = "";
61int match_expected_address = FALSE; 60int match_expected_address = FALSE;
62int expect_authority = FALSE; 61int expect_authority = FALSE;
@@ -80,6 +79,7 @@ main (int argc, char **argv)
80 output chld_out, chld_err; 79 output chld_out, chld_err;
81 size_t i; 80 size_t i;
82 81
82 np_set_mynames(argv[0], "DNS");
83 setlocale (LC_ALL, ""); 83 setlocale (LC_ALL, "");
84 bindtextdomain (PACKAGE, LOCALEDIR); 84 bindtextdomain (PACKAGE, LOCALEDIR);
85 textdomain (PACKAGE); 85 textdomain (PACKAGE);
@@ -99,8 +99,7 @@ main (int argc, char **argv)
99 alarm (timeout_interval); 99 alarm (timeout_interval);
100 gettimeofday (&tv, NULL); 100 gettimeofday (&tv, NULL);
101 101
102 if (verbose) 102 np_verbatim(command_line);
103 printf ("%s\n", command_line);
104 103
105 /* run the command */ 104 /* run the command */
106 if((np_runcmd(command_line, &chld_out, &chld_err, 0)) != 0) { 105 if((np_runcmd(command_line, &chld_out, &chld_err, 0)) != 0) {
@@ -110,8 +109,7 @@ main (int argc, char **argv)
110 109
111 /* scan stdout */ 110 /* scan stdout */
112 for(i = 0; i < chld_out.lines; i++) { 111 for(i = 0; i < chld_out.lines; i++) {
113 if (verbose) 112 np_verbatim(chld_out.line[i]);
114 puts(chld_out.line[i]);
115 113
116 if (strstr (chld_out.line[i], ".in-addr.arpa")) { 114 if (strstr (chld_out.line[i], ".in-addr.arpa")) {
117 if ((temp_buffer = strstr (chld_out.line[i], "name = "))) 115 if ((temp_buffer = strstr (chld_out.line[i], "name = ")))
@@ -161,8 +159,7 @@ main (int argc, char **argv)
161 159
162 /* scan stderr */ 160 /* scan stderr */
163 for(i = 0; i < chld_err.lines; i++) { 161 for(i = 0; i < chld_err.lines; i++) {
164 if (verbose) 162 np_verbatim(chld_err.line[i]);
165 puts(chld_err.line[i]);
166 163
167 if (error_scan (chld_err.line[i]) != STATE_OK) { 164 if (error_scan (chld_err.line[i]) != STATE_OK) {
168 result = max_state (result, error_scan (chld_err.line[i])); 165 result = max_state (result, error_scan (chld_err.line[i]));
@@ -329,7 +326,7 @@ process_arguments (int argc, char **argv)
329 print_revision (progname, revision); 326 print_revision (progname, revision);
330 exit (STATE_OK); 327 exit (STATE_OK);
331 case 'v': /* version */ 328 case 'v': /* version */
332 verbose = TRUE; 329 np_increase_verbosity(1);
333 break; 330 break;
334 case 't': /* timeout period */ 331 case 't': /* timeout period */
335 timeout_interval = atoi (optarg); 332 timeout_interval = atoi (optarg);
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index 4dc48b7..8114b36 100644
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
@@ -60,7 +60,6 @@ void print_usage (void);
60char *server_name = NULL; 60char *server_name = NULL;
61int packet_size = PACKET_SIZE; 61int packet_size = PACKET_SIZE;
62int packet_count = PACKET_COUNT; 62int packet_count = PACKET_COUNT;
63int verbose = FALSE;
64int cpl; 63int cpl;
65int wpl; 64int wpl;
66double crta; 65double crta;
@@ -81,6 +80,7 @@ main (int argc, char **argv)
81 char *input_buffer = NULL; 80 char *input_buffer = NULL;
82 input_buffer = malloc (MAX_INPUT_BUFFER); 81 input_buffer = malloc (MAX_INPUT_BUFFER);
83 82
83 np_set_mynames(argv[0], "FPING");
84 setlocale (LC_ALL, ""); 84 setlocale (LC_ALL, "");
85 bindtextdomain (PACKAGE, LOCALEDIR); 85 bindtextdomain (PACKAGE, LOCALEDIR);
86 textdomain (PACKAGE); 86 textdomain (PACKAGE);
@@ -94,32 +94,26 @@ main (int argc, char **argv)
94 asprintf (&command_line, "%s -b %d -c %d %s", PATH_TO_FPING, 94 asprintf (&command_line, "%s -b %d -c %d %s", PATH_TO_FPING,
95 packet_size, packet_count, server); 95 packet_size, packet_count, server);
96 96
97 if (verbose) 97 np_verbatim(command_line);
98 printf ("%s\n", command_line);
99 98
100 /* run the command */ 99 /* run the command */
101 child_process = spopen (command_line); 100 child_process = spopen (command_line);
102 if (child_process == NULL) { 101 if (child_process == NULL)
103 printf (_("Could not open pipe: %s\n"), command_line); 102 np_die(STATE_UNKNOWN, _("Could not open pipe: %s"), command_line);
104 return STATE_UNKNOWN;
105 }
106 103
107 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); 104 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
108 if (child_stderr == NULL) { 105 if (child_stderr == NULL)
109 printf (_("Could not open stderr for %s\n"), command_line); 106 printf (_("Could not open stderr for %s\n"), command_line);
110 }
111 107
112 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { 108 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
113 if (verbose) 109 np_verbatim(input_buffer);
114 printf ("%s", input_buffer);
115 status = max_state (status, textscan (input_buffer)); 110 status = max_state (status, textscan (input_buffer));
116 } 111 }
117 112
118 /* If we get anything on STDERR, at least set warning */ 113 /* If we get anything on STDERR, at least set warning */
119 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { 114 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
120 status = max_state (status, STATE_WARNING); 115 status = max_state (status, STATE_WARNING);
121 if (verbose) 116 np_verbatim(input_buffer);
122 printf ("%s", input_buffer);
123 status = max_state (status, textscan (input_buffer)); 117 status = max_state (status, textscan (input_buffer));
124 } 118 }
125 (void) fclose (child_stderr); 119 (void) fclose (child_stderr);
@@ -129,9 +123,7 @@ main (int argc, char **argv)
129 /* need to use max_state not max */ 123 /* need to use max_state not max */
130 status = max_state (status, STATE_WARNING); 124 status = max_state (status, STATE_WARNING);
131 125
132 printf ("FPING %s - %s\n", state_text (status), server_name); 126 np_die("%s", server_name);
133
134 return status;
135} 127}
136 128
137 129
@@ -146,16 +138,15 @@ textscan (char *buf)
146 int status = STATE_UNKNOWN; 138 int status = STATE_UNKNOWN;
147 139
148 if (strstr (buf, "not found")) { 140 if (strstr (buf, "not found")) {
149 die (STATE_CRITICAL, _("FPING UNKNOW - %s not found\n"), server_name); 141 np_die(STATE_UNKNOWN, _("%s not found"), server_name);
150 142
151 } 143 }
152 else if (strstr (buf, "is unreachable") || strstr (buf, "Unreachable")) { 144 else if (strstr (buf, "is unreachable") || strstr (buf, "Unreachable")) {
153 die (STATE_CRITICAL, _("FPING CRITICAL - %s is unreachable\n"), 145 np_die(STATE_CRITICAL, _("%s is unreachable"), "host");
154 "host");
155 146
156 } 147 }
157 else if (strstr (buf, "is down")) { 148 else if (strstr (buf, "is down")) {
158 die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name); 149 np_die(STATE_CRITICAL, _("%s is down"), server_name);
159 150
160 } 151 }
161 else if (strstr (buf, "is alive")) { 152 else if (strstr (buf, "is alive")) {
@@ -181,9 +172,9 @@ textscan (char *buf)
181 status = STATE_WARNING; 172 status = STATE_WARNING;
182 else 173 else
183 status = STATE_OK; 174 status = STATE_OK;
184 die (status, 175 np_die(status,
185 _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"), 176 _("- %s (loss=%.0f%%, rta=%f ms)|%s %s\n"),
186 state_text (status), server_name, loss, rta, 177 server_name, loss, rta,
187 perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100), 178 perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100),
188 fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0)); 179 fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0));
189 180
@@ -203,8 +194,8 @@ textscan (char *buf)
203 else 194 else
204 status = STATE_OK; 195 status = STATE_OK;
205 /* loss=%.0f%%;%d;%d;0;100 */ 196 /* loss=%.0f%%;%d;%d;0;100 */
206 die (status, _("FPING %s - %s (loss=%.0f%% )|%s\n"), 197 np_die(status, _("%s (loss=%.0f%% )|%s"),
207 state_text (status), server_name, loss , 198 server_name, loss,
208 perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100)); 199 perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100));
209 200
210 } 201 }
@@ -266,7 +257,7 @@ process_arguments (int argc, char **argv)
266 print_revision (progname, revision); 257 print_revision (progname, revision);
267 exit (STATE_OK); 258 exit (STATE_OK);
268 case 'v': /* verbose mode */ 259 case 'v': /* verbose mode */
269 verbose = TRUE; 260 np_increase_verbosity(1);
270 break; 261 break;
271 case 'H': /* hostname */ 262 case 'H': /* hostname */
272 if (is_host (optarg) == FALSE) { 263 if (is_host (optarg) == FALSE) {
@@ -335,13 +326,11 @@ get_threshold (char *arg, char *rv[2])
335 if (arg2) { 326 if (arg2) {
336 arg1[strcspn (arg1, ",:")] = 0; 327 arg1[strcspn (arg1, ",:")] = 0;
337 if (strstr (arg1, "%") && strstr (arg2, "%")) 328 if (strstr (arg1, "%") && strstr (arg2, "%"))
338 die (STATE_UNKNOWN, 329 np_die(STATE_UNKNOWN,
339 _("%s: Only one threshold may be packet loss (%s)\n"), progname, 330 _("Only one threshold may be packet loss (%s)\n"), arg);
340 arg);
341 if (!strstr (arg1, "%") && !strstr (arg2, "%")) 331 if (!strstr (arg1, "%") && !strstr (arg2, "%"))
342 die (STATE_UNKNOWN, 332 np_die(STATE_UNKNOWN,
343 _("%s: Only one threshold must be packet loss (%s)\n"), 333 _("Only one threshold must be packet loss (%s)\n"), arg);
344 progname, arg);
345 } 334 }
346 335
347 if (arg2 && strstr (arg2, "%")) { 336 if (arg2 && strstr (arg2, "%")) {
diff --git a/plugins/check_game.c b/plugins/check_game.c
index 79abec3..f53e7a3 100644
--- a/plugins/check_game.c
+++ b/plugins/check_game.c
@@ -58,8 +58,6 @@ char *server_ip;
58char *game_type; 58char *game_type;
59int port = 0; 59int port = 0;
60 60
61int verbose;
62
63int qstat_game_players_max = -1; 61int qstat_game_players_max = -1;
64int qstat_game_players = -1; 62int qstat_game_players = -1;
65int qstat_game_field = -1; 63int qstat_game_field = -1;
@@ -76,6 +74,7 @@ main (int argc, char **argv)
76 size_t i = 0; 74 size_t i = 0;
77 output chld_out; 75 output chld_out;
78 76
77 np_set_mymanes(argv[0], "GAME");
79 setlocale (LC_ALL, ""); 78 setlocale (LC_ALL, "");
80 bindtextdomain (PACKAGE, LOCALEDIR); 79 bindtextdomain (PACKAGE, LOCALEDIR);
81 textdomain (PACKAGE); 80 textdomain (PACKAGE);
@@ -92,8 +91,7 @@ main (int argc, char **argv)
92 if (port) 91 if (port)
93 asprintf (&command_line, "%s:%-d", command_line, port); 92 asprintf (&command_line, "%s:%-d", command_line, port);
94 93
95 if (verbose > 0) 94 np_verbatim(command_line);
96 printf ("%s\n", command_line);
97 95
98 /* run the command. historically, this plugin ignores output on stderr, 96 /* run the command. historically, this plugin ignores output on stderr,
99 * as well as return status of the qstat program */ 97 * as well as return status of the qstat program */
@@ -109,11 +107,8 @@ main (int argc, char **argv)
109 In the end, I figured I'd simply let an error occur & then trap it 107 In the end, I figured I'd simply let an error occur & then trap it
110 */ 108 */
111 109
112 if (!strncmp (chld_out.line[0], "unknown option", 14)) { 110 if (!strncmp (chld_out.line[0], "unknown option", 14))
113 printf (_("CRITICAL - Host type parameter incorrect!\n")); 111 np_die(STATE_CRITICAL, _("CRITICAL - Host type parameter incorrect!"));
114 result = STATE_CRITICAL;
115 return result;
116 }
117 112
118 p = (char *) strtok (chld_out.line[0], QSTAT_DATA_DELIMITER); 113 p = (char *) strtok (chld_out.line[0], QSTAT_DATA_DELIMITER);
119 while (p != NULL) { 114 while (p != NULL) {
@@ -124,20 +119,14 @@ main (int argc, char **argv)
124 break; 119 break;
125 } 120 }
126 121
127 if (strstr (ret[2], QSTAT_HOST_ERROR)) { 122 if (strstr (ret[2], QSTAT_HOST_ERROR))
128 printf (_("CRITICAL - Host not found\n")); 123 np_die(STATE_CRITICAL, _("CRITICAL - Host not found"));
129 result = STATE_CRITICAL; 124 else if (strstr (ret[2], QSTAT_HOST_DOWN))
130 } 125 np_die(STATE_CRITICAL, _("CRITICAL - Game server down or unavailable"));
131 else if (strstr (ret[2], QSTAT_HOST_DOWN)) { 126 else if (strstr (ret[2], QSTAT_HOST_TIMEOUT))
132 printf (_("CRITICAL - Game server down or unavailable\n")); 127 np_die(STATE_CRITICAL, _("CRITICAL - Game server timeout\n"));
133 result = STATE_CRITICAL; 128 else
134 } 129 np_die(STATE_OK, "%s/%s %s (%s), Ping: %s ms|%s %s\n",
135 else if (strstr (ret[2], QSTAT_HOST_TIMEOUT)) {
136 printf (_("CRITICAL - Game server timeout\n"));
137 result = STATE_CRITICAL;
138 }
139 else {
140 printf ("OK: %s/%s %s (%s), Ping: %s ms|%s %s\n",
141 ret[qstat_game_players], 130 ret[qstat_game_players],
142 ret[qstat_game_players_max], 131 ret[qstat_game_players_max],
143 ret[qstat_game_field], 132 ret[qstat_game_field],
@@ -149,9 +138,6 @@ main (int argc, char **argv)
149 fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "", 138 fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "",
150 FALSE, 0, FALSE, 0, 139 FALSE, 0, FALSE, 0,
151 TRUE, 0, FALSE, 0)); 140 TRUE, 0, FALSE, 0));
152 }
153
154 return result;
155} 141}
156 142
157 143
@@ -203,14 +189,14 @@ process_arguments (int argc, char **argv)
203 print_revision (progname, revision); 189 print_revision (progname, revision);
204 exit (STATE_OK); 190 exit (STATE_OK);
205 case 'v': /* version */ 191 case 'v': /* version */
206 verbose = TRUE; 192 np_increase_verbosity(1);
207 break; 193 break;
208 case 't': /* timeout period */ 194 case 't': /* timeout period */
209 timeout_interval = atoi (optarg); 195 timeout_interval = atoi (optarg);
210 break; 196 break;
211 case 'H': /* hostname */ 197 case 'H': /* hostname */
212 if (strlen (optarg) >= MAX_HOST_ADDRESS_LENGTH) 198 if (strlen (optarg) >= MAX_HOST_ADDRESS_LENGTH)
213 die (STATE_UNKNOWN, _("Input buffer overflow\n")); 199 np_die(STATE_UNKNOWN, _("Input buffer overflow"));
214 server_ip = optarg; 200 server_ip = optarg;
215 break; 201 break;
216 case 'P': /* port */ 202 case 'P': /* port */
@@ -218,7 +204,7 @@ process_arguments (int argc, char **argv)
218 break; 204 break;
219 case 'G': /* hostname */ 205 case 'G': /* hostname */
220 if (strlen (optarg) >= MAX_INPUT_BUFFER) 206 if (strlen (optarg) >= MAX_INPUT_BUFFER)
221 die (STATE_UNKNOWN, _("Input buffer overflow\n")); 207 np_die(STATE_UNKNOWN, _("Input buffer overflow"));
222 game_type = optarg; 208 game_type = optarg;
223 break; 209 break;
224 case 'p': /* index of ping field */ 210 case 'p': /* index of ping field */
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c
index 8a60ce8..f37b2ba 100644
--- a/plugins/check_hpjd.c
+++ b/plugins/check_hpjd.c
@@ -98,6 +98,7 @@ main (int argc, char **argv)
98 98
99 errmsg = malloc(MAX_INPUT_BUFFER); 99 errmsg = malloc(MAX_INPUT_BUFFER);
100 100
101 np_set_mynames(argv[0], "HPJD");
101 setlocale (LC_ALL, ""); 102 setlocale (LC_ALL, "");
102 bindtextdomain (PACKAGE, LOCALEDIR); 103 bindtextdomain (PACKAGE, LOCALEDIR);
103 textdomain (PACKAGE); 104 textdomain (PACKAGE);
@@ -127,15 +128,12 @@ main (int argc, char **argv)
127 128
128 /* run the command */ 129 /* run the command */
129 child_process = spopen (command_line); 130 child_process = spopen (command_line);
130 if (child_process == NULL) { 131 if (child_process == NULL)
131 printf (_("Could not open pipe: %s\n"), command_line); 132 np_die(STATE_UNKNOWN, _("Could not open pipe: %s"), command_line);
132 return STATE_UNKNOWN;
133 }
134 133
135 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); 134 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
136 if (child_stderr == NULL) { 135 if (child_stderr == NULL)
137 printf (_("Could not open stderr for %s\n"), command_line); 136 printf (_("Could not open stderr for %s\n"), command_line);
138 }
139 137
140 result = STATE_OK; 138 result = STATE_OK;
141 139
@@ -286,21 +284,13 @@ main (int argc, char **argv)
286 } 284 }
287 285
288 if (result == STATE_OK) 286 if (result == STATE_OK)
289 printf (_("Printer ok - (%s)\n"), display_message); 287 np_die(STATE_OK, _("Printer ok - (%s)"), display_message);
290
291 else if (result == STATE_UNKNOWN) {
292
293 printf ("%s\n", errmsg);
294
295 /* if printer could not be reached, escalate to critical */
296 if (strstr (errmsg, "Timeout"))
297 result = STATE_CRITICAL;
298 }
299
300 else if (result == STATE_WARNING) 288 else if (result == STATE_WARNING)
301 printf ("%s (%s)\n", errmsg, display_message); 289 np_die(STATE_WARNING, "%s (%s)\n", errmsg, display_message);
302 290
303 return result; 291 /* if printer could not be reached, escalate to critical */
292 np_die(strstr(errmsg, "Timeout") ? STATE_CRITICAL : STATE_UNKNOWN,
293 "%s", errmsg);
304} 294}
305 295
306 296
diff --git a/plugins/check_http.c b/plugins/check_http.c
index b371cd6..3b93795 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -113,7 +113,6 @@ char **http_opt_headers;
113int http_opt_headers_count = 0; 113int http_opt_headers_count = 0;
114int onredirect = STATE_OK; 114int onredirect = STATE_OK;
115int use_ssl = FALSE; 115int use_ssl = FALSE;
116int verbose = FALSE;
117int sd; 116int sd;
118int min_page_len = 0; 117int min_page_len = 0;
119int max_page_len = 0; 118int max_page_len = 0;
@@ -140,6 +139,8 @@ main (int argc, char **argv)
140{ 139{
141 int result = STATE_UNKNOWN; 140 int result = STATE_UNKNOWN;
142 141
142 np_set_mynames(argv[0], "HTTP");
143
143 /* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */ 144 /* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */
144 server_url = strdup(HTTP_URL); 145 server_url = strdup(HTTP_URL);
145 server_url_length = strlen(server_url); 146 server_url_length = strlen(server_url);
@@ -307,8 +308,7 @@ process_arguments (int argc, char **argv)
307 onredirect = STATE_WARNING; 308 onredirect = STATE_WARNING;
308 if (!strcmp (optarg, "critical")) 309 if (!strcmp (optarg, "critical"))
309 onredirect = STATE_CRITICAL; 310 onredirect = STATE_CRITICAL;
310 if (verbose) 311 np_verbose (_("option f:%d"), onredirect);
311 printf(_("option f:%d \n"), onredirect);
312 break; 312 break;
313 /* Note: H, I, and u must be malloc'd or will fail on redirects */ 313 /* Note: H, I, and u must be malloc'd or will fail on redirects */
314 case 'H': /* Host Name (virtual host) */ 314 case 'H': /* Host Name (virtual host) */
@@ -381,7 +381,7 @@ process_arguments (int argc, char **argv)
381#endif 381#endif
382 break; 382 break;
383 case 'v': /* verbose */ 383 case 'v': /* verbose */
384 verbose = TRUE; 384 np_increase_verbosity(1);
385 break; 385 break;
386 case 'm': /* min_page_length */ 386 case 'm': /* min_page_length */
387 { 387 {
@@ -389,17 +389,15 @@ process_arguments (int argc, char **argv)
389 if (strchr(optarg, ':') != (char *)NULL) { 389 if (strchr(optarg, ':') != (char *)NULL) {
390 /* range, so get two values, min:max */ 390 /* range, so get two values, min:max */
391 tmp = strtok(optarg, ":"); 391 tmp = strtok(optarg, ":");
392 if (tmp == NULL) { 392 if (tmp == NULL)
393 printf("Bad format: try \"-m min:max\"\n"); 393 np_die (STATE_UNKNOWN, "Bad format: try \"-m min:max\"");
394 exit (STATE_WARNING); 394 else
395 } else
396 min_page_len = atoi(tmp); 395 min_page_len = atoi(tmp);
397 396
398 tmp = strtok(NULL, ":"); 397 tmp = strtok(NULL, ":");
399 if (tmp == NULL) { 398 if (tmp == NULL)
400 printf("Bad format: try \"-m min:max\"\n"); 399 np_die (STATE_UNKNOWN, "Bad format: try \"-m min:max\"");
401 exit (STATE_WARNING); 400 else
402 } else
403 max_page_len = atoi(tmp); 401 max_page_len = atoi(tmp);
404 } else 402 } else
405 min_page_len = atoi (optarg); 403 min_page_len = atoi (optarg);
@@ -420,10 +418,8 @@ process_arguments (int argc, char **argv)
420 else if (L && (optarg[L-1] == 's' || 418 else if (L && (optarg[L-1] == 's' ||
421 isdigit (optarg[L-1]))) 419 isdigit (optarg[L-1])))
422 maximum_age = atoi (optarg); 420 maximum_age = atoi (optarg);
423 else { 421 else
424 fprintf (stderr, "unparsable max-age: %s\n", optarg); 422 np_die (STATE_UNKNOWN, _("Unparsable max-age: %s"), optarg);
425 exit (STATE_WARNING);
426 }
427 } 423 }
428 break; 424 break;
429 } 425 }
@@ -593,7 +589,7 @@ parse_time_string (const char *string)
593 t = mktime (&tm); 589 t = mktime (&tm);
594 if (t == (time_t) -1) t = 0; 590 if (t == (time_t) -1) t = 0;
595 591
596 if (verbose) { 592 if (np_get_verbosity() > 0) {
597 const char *s = string; 593 const char *s = string;
598 while (*s && *s != '\r' && *s != '\n') 594 while (*s && *s != '\r' && *s != '\n')
599 fputc (*s++, stdout); 595 fputc (*s++, stdout);
@@ -665,28 +661,27 @@ check_document_dates (const char *headers)
665 661
666 /* Done parsing the body. Now check the dates we (hopefully) parsed. */ 662 /* Done parsing the body. Now check the dates we (hopefully) parsed. */
667 if (!server_date || !*server_date) { 663 if (!server_date || !*server_date) {
668 die (STATE_UNKNOWN, _("HTTP UNKNOWN - Server date unknown\n")); 664 np_die (STATE_UNKNOWN, _("Server date unknown"));
669 } else if (!document_date || !*document_date) { 665 } else if (!document_date || !*document_date) {
670 die (STATE_CRITICAL, _("HTTP CRITICAL - Document modification date unknown\n")); 666 np_die (STATE_CRITICAL, _("Document modification date unknown"));
671 } else { 667 } else {
672 time_t srv_data = parse_time_string (server_date); 668 time_t srv_data = parse_time_string (server_date);
673 time_t doc_data = parse_time_string (document_date); 669 time_t doc_data = parse_time_string (document_date);
674 670
675 if (srv_data <= 0) { 671 if (srv_data <= 0) {
676 die (STATE_CRITICAL, _("HTTP CRITICAL - Server date \"%100s\" unparsable"), server_date); 672 np_die (STATE_CRITICAL, _("Server date \"%100s\" unparsable"), server_date);
677 } else if (doc_data <= 0) { 673 } else if (doc_data <= 0) {
678 die (STATE_CRITICAL, _("HTTP CRITICAL - Document date \"%100s\" unparsable"), document_date); 674 np_die (STATE_CRITICAL, _("Document date \"%100s\" unparsable"), document_date);
679 } else if (doc_data > srv_data + 30) { 675 } else if (doc_data > srv_data + 30) {
680 die (STATE_CRITICAL, _("HTTP CRITICAL - Document is %d seconds in the future\n"), (int)doc_data - (int)srv_data); 676 np_die (STATE_CRITICAL, _("Document is %d seconds in the future"),
677 (int)doc_data - (int)srv_data);
681 } else if (doc_data < srv_data - maximum_age) { 678 } else if (doc_data < srv_data - maximum_age) {
682 int n = (srv_data - doc_data); 679 int n = (srv_data - doc_data);
683 if (n > (60 * 60 * 24 * 2)) 680 if (n > (60 * 60 * 24 * 2))
684 die (STATE_CRITICAL, 681 np_die (STATE_CRITICAL, _("Last modified %.1f days ago"),
685 _("HTTP CRITICAL - Last modified %.1f days ago\n"),
686 ((float) n) / (60 * 60 * 24)); 682 ((float) n) / (60 * 60 * 24));
687 else 683 else
688 die (STATE_CRITICAL, 684 np_die (STATE_CRITICAL, _("Last modified %d:%02d:%02d ago"),
689 _("HTTP CRITICAL - Last modified %d:%02d:%02d ago\n"),
690 n / (60 * 60), (n / 60) % 60, n % 60); 685 n / (60 * 60), (n / 60) % 60, n % 60);
691 } 686 }
692 687
@@ -767,7 +762,7 @@ check_http (void)
767 762
768 /* try to connect to the host at the given port number */ 763 /* try to connect to the host at the given port number */
769 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) 764 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK)
770 die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n")); 765 np_die (STATE_CRITICAL, _("Unable to open TCP socket"));
771#ifdef HAVE_SSL 766#ifdef HAVE_SSL
772 if (use_ssl == TRUE) { 767 if (use_ssl == TRUE) {
773 np_net_ssl_init(sd); 768 np_net_ssl_init(sd);
@@ -820,7 +815,7 @@ check_http (void)
820 asprintf (&buf, "%s%s", buf, CRLF); 815 asprintf (&buf, "%s%s", buf, CRLF);
821 } 816 }
822 817
823 if (verbose) printf ("%s\n", buf); 818 np_verbatim (buf);
824 my_send (buf, strlen (buf)); 819 my_send (buf, strlen (buf));
825 820
826 /* fetch the page */ 821 /* fetch the page */
@@ -842,15 +837,15 @@ check_http (void)
842 if (use_ssl) { 837 if (use_ssl) {
843 sslerr=SSL_get_error(ssl, i); 838 sslerr=SSL_get_error(ssl, i);
844 if ( sslerr == SSL_ERROR_SSL ) { 839 if ( sslerr == SSL_ERROR_SSL ) {
845 die (STATE_WARNING, _("HTTP WARNING - Client Certificate Required\n")); 840 np_die (STATE_WARNING, _("Client Certificate Required"));
846 } else { 841 } else {
847 die (STATE_CRITICAL, _("HTTP CRITICAL - Error on receive\n")); 842 np_die (STATE_CRITICAL, _("Error on receive"));
848 } 843 }
849 } 844 }
850 else { 845 else {
851 */ 846 */
852#endif 847#endif
853 die (STATE_CRITICAL, _("HTTP CRITICAL - Error on receive\n")); 848 np_die (STATE_CRITICAL, _("HTTP CRITICAL - Error on receive"));
854#ifdef HAVE_SSL 849#ifdef HAVE_SSL
855 /* XXX 850 /* XXX
856 } 851 }
@@ -860,7 +855,7 @@ check_http (void)
860 855
861 /* return a CRITICAL status if we couldn't read any data */ 856 /* return a CRITICAL status if we couldn't read any data */
862 if (pagesize == (size_t) 0) 857 if (pagesize == (size_t) 0)
863 die (STATE_CRITICAL, _("HTTP CRITICAL - No data received from host\n")); 858 np_die (STATE_CRITICAL, _("HTTP CRITICAL - No data received from host"));
864 859
865 /* close the connection */ 860 /* close the connection */
866#ifdef HAVE_SSL 861#ifdef HAVE_SSL
@@ -874,8 +869,7 @@ check_http (void)
874 /* leave full_page untouched so we can free it later */ 869 /* leave full_page untouched so we can free it later */
875 page = full_page; 870 page = full_page;
876 871
877 if (verbose) 872 np_verbose ("%s://%s:%d%s is %d characters",
878 printf ("%s://%s:%d%s is %d characters\n",
879 use_ssl ? "https" : "http", server_address, 873 use_ssl ? "https" : "http", server_address,
880 server_port, server_url, (int)pagesize); 874 server_port, server_url, (int)pagesize);
881 875
@@ -886,8 +880,7 @@ check_http (void)
886 page += (size_t) strspn (page, "\r\n"); 880 page += (size_t) strspn (page, "\r\n");
887 status_line[strcspn(status_line, "\r\n")] = 0; 881 status_line[strcspn(status_line, "\r\n")] = 0;
888 strip (status_line); 882 strip (status_line);
889 if (verbose) 883 np_verbose ("STATUS: %s", status_line);
890 printf ("STATUS: %s\n", status_line);
891 884
892 /* find header info and null-terminate it */ 885 /* find header info and null-terminate it */
893 header = page; 886 header = page;
@@ -902,29 +895,27 @@ check_http (void)
902 } 895 }
903 page += (size_t) strspn (page, "\r\n"); 896 page += (size_t) strspn (page, "\r\n");
904 header[pos - header] = 0; 897 header[pos - header] = 0;
905 if (verbose) 898 np_verbose ("**** HEADER ****\n%s\n**** CONTENT ****\n%s", header,
906 printf ("**** HEADER ****\n%s\n**** CONTENT ****\n%s\n", header,
907 (no_body ? " [[ skipped ]]" : page)); 899 (no_body ? " [[ skipped ]]" : page));
908 900
909 /* make sure the status line matches the response we are looking for */ 901 /* make sure the status line matches the response we are looking for */
910 if (!strstr (status_line, server_expect)) { 902 if (!strstr (status_line, server_expect)) {
911 if (server_port == HTTP_PORT) 903 if (server_port == HTTP_PORT)
912 asprintf (&msg, 904 asprintf (&msg,
913 _("Invalid HTTP response received from host\n")); 905 _("Invalid HTTP response received from host"));
914 else 906 else
915 asprintf (&msg, 907 asprintf (&msg,
916 _("Invalid HTTP response received from host on port %d\n"), 908 _("Invalid HTTP response received from host on port %d"),
917 server_port); 909 server_port);
918 die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); 910 np_die (STATE_CRITICAL, "%s", msg);
919 } 911 }
920 912
921 /* Exit here if server_expect was set by user and not default */ 913 /* Exit here if server_expect was set by user and not default */
922 if ( server_expect_yn ) { 914 if ( server_expect_yn ) {
923 asprintf (&msg, 915 asprintf (&msg,
924 _("HTTP OK: Status line output matched \"%s\"\n"), 916 _("Status line output matched \"%s\""),
925 server_expect); 917 server_expect);
926 if (verbose) 918 np_verbatim (msg);
927 printf ("%s\n",msg);
928 } 919 }
929 else { 920 else {
930 /* Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF */ 921 /* Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF */
@@ -933,40 +924,32 @@ check_http (void)
933 924
934 status_code = strchr (status_line, ' ') + sizeof (char); 925 status_code = strchr (status_line, ' ') + sizeof (char);
935 if (strspn (status_code, "1234567890") != 3) 926 if (strspn (status_code, "1234567890") != 3)
936 die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status Line (%s)\n"), status_line); 927 np_die (STATE_CRITICAL, _("Invalid Status Line (%s)"), status_line);
937 928
938 http_status = atoi (status_code); 929 http_status = atoi (status_code);
939 930
940 /* check the return code */ 931 /* check the return code */
941 932
942 if (http_status >= 600 || http_status < 100) 933 if (http_status >= 600 || http_status < 100)
943 die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status (%s)\n"), status_line); 934 np_die (STATE_CRITICAL, _("Invalid Status (%s)"), status_line);
944 935
945 /* server errors result in a critical state */ 936 /* server errors result in a critical state */
946 else if (http_status >= 500) 937 else if (http_status >= 500)
947 die (STATE_CRITICAL, _("HTTP CRITICAL: %s\n"), status_line); 938 np_die (STATE_CRITICAL, _("%s"), status_line);
948 939
949 /* client errors result in a warning state */ 940 /* client errors result in a warning state */
950 else if (http_status >= 400) 941 else if (http_status >= 400)
951 die (STATE_WARNING, _("HTTP WARNING: %s\n"), status_line); 942 np_die (STATE_WARNING, _("%s"), status_line);
952 943
953 /* check redirected page if specified */ 944 /* check redirected page if specified */
954 else if (http_status >= 300) { 945 else if (http_status >= 300) {
955 946
956 if (onredirect == STATE_DEPENDENT) 947 if (onredirect == STATE_DEPENDENT)
957 redir (header, status_line); 948 redir (header, status_line);
958 else if (onredirect == STATE_UNKNOWN)
959 printf (_("HTTP UNKNOWN"));
960 else if (onredirect == STATE_OK)
961 printf (_("HTTP OK"));
962 else if (onredirect == STATE_WARNING)
963 printf (_("HTTP WARNING"));
964 else if (onredirect == STATE_CRITICAL)
965 printf (_("HTTP CRITICAL"));
966 microsec = deltime (tv); 949 microsec = deltime (tv);
967 elapsed_time = (double)microsec / 1.0e6; 950 elapsed_time = (double)microsec / 1.0e6;
968 die (onredirect, 951 np_die (onredirect,
969 _(" - %s - %.3f second response time %s|%s %s\n"), 952 _("%s - %.3f second response time %s|%s %s"),
970 status_line, elapsed_time, 953 status_line, elapsed_time,
971 (display_html ? "</A>" : ""), 954 (display_html ? "</A>" : ""),
972 perfd_time (elapsed_time), perfd_size (pagesize)); 955 perfd_time (elapsed_time), perfd_size (pagesize));
@@ -982,59 +965,50 @@ check_http (void)
982 microsec = deltime (tv); 965 microsec = deltime (tv);
983 elapsed_time = (double)microsec / 1.0e6; 966 elapsed_time = (double)microsec / 1.0e6;
984 asprintf (&msg, 967 asprintf (&msg,
985 _("HTTP WARNING: %s - %.3f second response time %s|%s %s\n"), 968 _("%s - %.3f second response time %s|%s %s"),
986 status_line, elapsed_time, 969 status_line, elapsed_time,
987 (display_html ? "</A>" : ""), 970 (display_html ? "</A>" : ""),
988 perfd_time (elapsed_time), perfd_size (pagesize)); 971 perfd_time (elapsed_time), perfd_size (pagesize));
989 if (check_critical_time == TRUE && elapsed_time > critical_time) 972 if (check_critical_time == TRUE && elapsed_time > critical_time)
990 die (STATE_CRITICAL, "%s", msg); 973 np_die (STATE_CRITICAL, "%s", msg);
991 if (check_warning_time == TRUE && elapsed_time > warning_time) 974 if (check_warning_time == TRUE && elapsed_time > warning_time)
992 die (STATE_WARNING, "%s", msg); 975 np_die (STATE_WARNING, "%s", msg);
993 976
994 /* Page and Header content checks go here */ 977 /* Page and Header content checks go here */
995 /* these checks should be last */ 978 /* these checks should be last */
996 979
997 if (strlen (string_expect)) { 980 if (strlen (string_expect)) {
998 if (strstr (page, string_expect)) { 981 if (strstr (page, string_expect))
999 printf (_("HTTP OK %s - %.3f second response time %s|%s %s\n"), 982 np_die (STATE_OK, _("%s - %.3f second response time %s|%s %s"),
1000 status_line, elapsed_time, 983 status_line, elapsed_time,
1001 (display_html ? "</A>" : ""), 984 (display_html ? "</A>" : ""),
1002 perfd_time (elapsed_time), perfd_size (pagesize)); 985 perfd_time (elapsed_time), perfd_size (pagesize));
1003 exit (STATE_OK); 986 else
1004 } 987 np_die (STATE_CRITICAL, _("string not found%s|%s %s"),
1005 else {
1006 printf (_("HTTP CRITICAL - string not found%s|%s %s\n"),
1007 (display_html ? "</A>" : ""), 988 (display_html ? "</A>" : ""),
1008 perfd_time (elapsed_time), perfd_size (pagesize)); 989 perfd_time (elapsed_time), perfd_size (pagesize));
1009 exit (STATE_CRITICAL);
1010 }
1011 } 990 }
1012 991
1013 if (strlen (regexp)) { 992 if (strlen (regexp)) {
1014 errcode = regexec (&preg, page, REGS, pmatch, 0); 993 errcode = regexec (&preg, page, REGS, pmatch, 0);
1015 if ((errcode == 0 && invert_regex == 0) || (errcode == REG_NOMATCH && invert_regex == 1)) { 994 if ((errcode == 0 && invert_regex == 0) || (errcode == REG_NOMATCH && invert_regex == 1))
1016 printf (_("HTTP OK %s - %.3f second response time %s|%s %s\n"), 995 np_die (STATE_OK, _("%s - %.3f second response time %s|%s %s"),
1017 status_line, elapsed_time, 996 status_line, elapsed_time,
1018 (display_html ? "</A>" : ""), 997 (display_html ? "</A>" : ""),
1019 perfd_time (elapsed_time), perfd_size (pagesize)); 998 perfd_time (elapsed_time), perfd_size (pagesize));
1020 exit (STATE_OK);
1021 }
1022 else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) { 999 else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) {
1023 if (invert_regex == 0) 1000 if (invert_regex == 0)
1024 msg = strdup(_("pattern not found")); 1001 msg = strdup(_("pattern not found"));
1025 else 1002 else
1026 msg = strdup(_("pattern found")); 1003 msg = strdup(_("pattern found"));
1027 printf (("%s - %s%s|%s %s\n"), 1004 np_die (STATE_CRITICAL, "%s%s|%s %s",
1028 _("HTTP CRITICAL"),
1029 msg, 1005 msg,
1030 (display_html ? "</A>" : ""), 1006 (display_html ? "</A>" : ""),
1031 perfd_time (elapsed_time), perfd_size (pagesize)); 1007 perfd_time (elapsed_time), perfd_size (pagesize));
1032 exit (STATE_CRITICAL);
1033 } 1008 }
1034 else { 1009 else {
1035 regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); 1010 regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
1036 printf (_("HTTP CRITICAL - Execute Error: %s\n"), errbuf); 1011 np_die (STATE_CRITICAL, _("Execute Error: %s"), errbuf);
1037 exit (STATE_CRITICAL);
1038 } 1012 }
1039 } 1013 }
1040 1014
@@ -1042,20 +1016,18 @@ check_http (void)
1042 /* page_len = get_content_length(header); */ 1016 /* page_len = get_content_length(header); */
1043 page_len = pagesize; 1017 page_len = pagesize;
1044 if ((max_page_len > 0) && (page_len > max_page_len)) { 1018 if ((max_page_len > 0) && (page_len > max_page_len)) {
1045 printf (_("HTTP WARNING: page size %d too large%s|%s\n"), 1019 np_die (STATE_WARNING, _("page size %d too large%s|%s"),
1046 page_len, (display_html ? "</A>" : ""), perfd_size (page_len) ); 1020 page_len, (display_html ? "</A>" : ""), perfd_size (page_len) );
1047 exit (STATE_WARNING);
1048 } else if ((min_page_len > 0) && (page_len < min_page_len)) { 1021 } else if ((min_page_len > 0) && (page_len < min_page_len)) {
1049 printf (_("HTTP WARNING: page size %d too small%s|%s\n"), 1022 np_die (STATE_WARNING, _("page size %d too small%s|%s"),
1050 page_len, (display_html ? "</A>" : ""), perfd_size (page_len) ); 1023 page_len, (display_html ? "</A>" : ""), perfd_size (page_len) );
1051 exit (STATE_WARNING);
1052 } 1024 }
1053 /* We only get here if all tests have been passed */ 1025 /* We only get here if all tests have been passed */
1054 asprintf (&msg, _("HTTP OK %s - %d bytes in %.3f seconds %s|%s %s\n"), 1026 asprintf (&msg, _("%s - %d bytes in %.3f seconds %s|%s %s"),
1055 status_line, page_len, elapsed_time, 1027 status_line, page_len, elapsed_time,
1056 (display_html ? "</A>" : ""), 1028 (display_html ? "</A>" : ""),
1057 perfd_time (elapsed_time), perfd_size (page_len)); 1029 perfd_time (elapsed_time), perfd_size (page_len));
1058 die (STATE_OK, "%s", msg); 1030 np_die (STATE_OK, "%s", msg);
1059 return STATE_UNKNOWN; 1031 return STATE_UNKNOWN;
1060} 1032}
1061 1033
@@ -1085,11 +1057,11 @@ redir (char *pos, char *status_line)
1085 1057
1086 addr = malloc (MAX_IPV4_HOSTLENGTH + 1); 1058 addr = malloc (MAX_IPV4_HOSTLENGTH + 1);
1087 if (addr == NULL) 1059 if (addr == NULL)
1088 die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate addr\n")); 1060 np_die (STATE_UNKNOWN, _("Could not allocate addr"));
1089 1061
1090 url = malloc (strcspn (pos, "\r\n")); 1062 url = malloc (strcspn (pos, "\r\n"));
1091 if (url == NULL) 1063 if (url == NULL)
1092 die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate url\n")); 1064 np_die (STATE_UNKNOWN, _("Could not allocate url"));
1093 1065
1094 while (pos) { 1066 while (pos) {
1095 sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i); 1067 sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i);
@@ -1097,8 +1069,8 @@ redir (char *pos, char *status_line)
1097 pos += (size_t) strcspn (pos, "\r\n"); 1069 pos += (size_t) strcspn (pos, "\r\n");
1098 pos += (size_t) strspn (pos, "\r\n"); 1070 pos += (size_t) strspn (pos, "\r\n");
1099 if (strlen(pos) == 0) 1071 if (strlen(pos) == 0)
1100 die (STATE_UNKNOWN, 1072 np_die (STATE_UNKNOWN,
1101 _("HTTP UNKNOWN - Could not find redirect location - %s%s\n"), 1073 _("Could not find redirect location - %s%s"),
1102 status_line, (display_html ? "</A>" : "")); 1074 status_line, (display_html ? "</A>" : ""));
1103 continue; 1075 continue;
1104 } 1076 }
@@ -1113,14 +1085,14 @@ redir (char *pos, char *status_line)
1113 for (; (i = strspn (pos, "\r\n")); pos += i) { 1085 for (; (i = strspn (pos, "\r\n")); pos += i) {
1114 pos += i; 1086 pos += i;
1115 if (!(i = strspn (pos, " \t"))) { 1087 if (!(i = strspn (pos, " \t"))) {
1116 die (STATE_UNKNOWN, _("HTTP UNKNOWN - Empty redirect location%s\n"), 1088 np_die (STATE_UNKNOWN, _("Empty redirect location%s"),
1117 display_html ? "</A>" : ""); 1089 display_html ? "</A>" : "");
1118 } 1090 }
1119 } 1091 }
1120 1092
1121 url = realloc (url, strcspn (pos, "\r\n") + 1); 1093 url = realloc (url, strcspn (pos, "\r\n") + 1);
1122 if (url == NULL) 1094 if (url == NULL)
1123 die (STATE_UNKNOWN, _("HTTP UNKNOWN - could not allocate url\n")); 1095 np_die (STATE_UNKNOWN, _("could not allocate url"));
1124 1096
1125 /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */ 1097 /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */
1126 if (sscanf (pos, HD1, type, addr, &i, url) == 4) 1098 if (sscanf (pos, HD1, type, addr, &i, url) == 4)
@@ -1159,8 +1131,8 @@ redir (char *pos, char *status_line)
1159 } 1131 }
1160 1132
1161 else { 1133 else {
1162 die (STATE_UNKNOWN, 1134 np_die (STATE_UNKNOWN,
1163 _("HTTP UNKNOWN - Could not parse redirect location - %s%s\n"), 1135 _("Could not parse redirect location - %s%s"),
1164 pos, (display_html ? "</A>" : "")); 1136 pos, (display_html ? "</A>" : ""));
1165 } 1137 }
1166 1138
@@ -1169,16 +1141,16 @@ redir (char *pos, char *status_line)
1169 } /* end while (pos) */ 1141 } /* end while (pos) */
1170 1142
1171 if (++redir_depth > max_depth) 1143 if (++redir_depth > max_depth)
1172 die (STATE_WARNING, 1144 np_die (STATE_WARNING,
1173 _("HTTP WARNING - maximum redirection depth %d exceeded - %s://%s:%d%s%s\n"), 1145 _("maximum redirection depth %d exceeded - %s://%s:%d%s%s"),
1174 max_depth, type, addr, i, url, (display_html ? "</A>" : "")); 1146 max_depth, type, addr, i, url, (display_html ? "</A>" : ""));
1175 1147
1176 if (server_port==i && 1148 if (server_port==i &&
1177 !strcmp(server_address, addr) && 1149 !strcmp(server_address, addr) &&
1178 (host_name && !strcmp(host_name, addr)) && 1150 (host_name && !strcmp(host_name, addr)) &&
1179 !strcmp(server_url, url)) 1151 !strcmp(server_url, url))
1180 die (STATE_WARNING, 1152 np_die (STATE_WARNING,
1181 _("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"), 1153 _("redirection creates an infinite loop - %s://%s:%d%s%s"),
1182 type, addr, i, url, (display_html ? "</A>" : "")); 1154 type, addr, i, url, (display_html ? "</A>" : ""));
1183 1155
1184 strcpy (server_type, type); 1156 strcpy (server_type, type);
@@ -1193,18 +1165,17 @@ redir (char *pos, char *status_line)
1193 if ((url[0] == '/')) 1165 if ((url[0] == '/'))
1194 server_url = strdup (url); 1166 server_url = strdup (url);
1195 else if (asprintf(&server_url, "/%s", url) == -1) 1167 else if (asprintf(&server_url, "/%s", url) == -1)
1196 die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate server_url%s\n"), 1168 np_die (STATE_UNKNOWN, _("Could not allocate server_url%s"),
1197 display_html ? "</A>" : ""); 1169 display_html ? "</A>" : "");
1198 free(url); 1170 free(url);
1199 1171
1200 if ((server_port = i) > MAX_PORT) 1172 if ((server_port = i) > MAX_PORT)
1201 die (STATE_UNKNOWN, 1173 np_die (STATE_UNKNOWN,
1202 _("HTTP UNKNOWN - Redirection to port above %d - %s://%s:%d%s%s\n"), 1174 _("Redirection to port above %d - %s://%s:%d%s%s"),
1203 MAX_PORT, server_type, server_address, server_port, server_url, 1175 MAX_PORT, server_type, server_address, server_port, server_url,
1204 display_html ? "</A>" : ""); 1176 display_html ? "</A>" : "");
1205 1177
1206 if (verbose) 1178 np_verbose (_("Redirection to %s://%s:%d%s"), server_type, server_address,
1207 printf (_("Redirection to %s://%s:%d%s\n"), server_type, server_address,
1208 server_port, server_url); 1179 server_port, server_url);
1209 1180
1210 check_http (); 1181 check_http ();