mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-05-28 04:35:40 -04:00
Convert plugins to use the new output functions
*** THIS COMMIT WILL BE MODIFIED IN THE FUTURE! **** Convert some of the C plugins to use the new "configurable output functions".
This commit is contained in:
parent
92bb86c484
commit
ff8b447e14
10 changed files with 199 additions and 296 deletions
|
|
@ -43,6 +43,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
|
|||
#include "common.h"
|
||||
#include "runcmd.h"
|
||||
#include "utils.h"
|
||||
#include "utils.h"
|
||||
#include "regex.h"
|
||||
|
||||
/* some constants */
|
||||
|
|
@ -74,7 +75,6 @@ int run_upgrade(int *pkgcount, int *secpkgcount);
|
|||
char* add_to_regexp(char *expr, const char *next);
|
||||
|
||||
/* configuration variables */
|
||||
static int verbose = 0; /* -v */
|
||||
static int do_update = 0; /* whether to call apt-get update */
|
||||
static upgrade_type upgrade = UPGRADE; /* which type of upgrade to do */
|
||||
static 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 */
|
|||
int main (int argc, char **argv) {
|
||||
int result=STATE_UNKNOWN, packages_available=0, sec_count=0;
|
||||
|
||||
np_set_mynames(argv[0], "APT");
|
||||
if (process_arguments(argc, argv) == ERROR)
|
||||
usage_va(_("Could not parse arguments"));
|
||||
|
||||
|
|
@ -115,8 +116,8 @@ int main (int argc, char **argv) {
|
|||
result = max_state(result, STATE_OK);
|
||||
}
|
||||
|
||||
printf(_("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s\n"),
|
||||
state_text(result),
|
||||
np_die(result,
|
||||
_("%d packages available for %s (%d critical updates). %s%s%s%s"),
|
||||
packages_available,
|
||||
(upgrade==DIST_UPGRADE)?"dist-upgrade":"upgrade",
|
||||
sec_count,
|
||||
|
|
@ -125,8 +126,6 @@ int main (int argc, char **argv) {
|
|||
(exec_warning)?" errors detected":"",
|
||||
(stderr_warning||exec_warning)?". run with -v for information.":""
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* process command-line arguments */
|
||||
|
|
@ -161,7 +160,7 @@ int process_arguments (int argc, char **argv) {
|
|||
print_revision(progname, revision);
|
||||
exit(STATE_OK);
|
||||
case 'v':
|
||||
verbose++;
|
||||
np_increase_verbosity(1);
|
||||
break;
|
||||
case 't':
|
||||
timeout_interval=atoi(optarg);
|
||||
|
|
@ -170,14 +169,14 @@ int process_arguments (int argc, char **argv) {
|
|||
upgrade=DIST_UPGRADE;
|
||||
if(optarg!=NULL){
|
||||
upgrade_opts=strdup(optarg);
|
||||
if(upgrade_opts==NULL) die(STATE_UNKNOWN, "strdup failed");
|
||||
if(upgrade_opts==NULL) np_die(STATE_UNKNOWN, "strdup failed: %m");
|
||||
}
|
||||
break;
|
||||
case 'U':
|
||||
upgrade=UPGRADE;
|
||||
if(optarg!=NULL){
|
||||
upgrade_opts=strdup(optarg);
|
||||
if(upgrade_opts==NULL) die(STATE_UNKNOWN, "strdup failed");
|
||||
if(upgrade_opts==NULL) np_die(STATE_UNKNOWN, "strdup failed: %m");
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
|
|
@ -187,7 +186,7 @@ int process_arguments (int argc, char **argv) {
|
|||
do_update=1;
|
||||
if(optarg!=NULL){
|
||||
update_opts=strdup(optarg);
|
||||
if(update_opts==NULL) die(STATE_UNKNOWN, "strdup failed");
|
||||
if(update_opts==NULL) np_die(STATE_UNKNOWN, "strdup failed: %m");
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
|
|
@ -228,22 +227,22 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
|
|||
regres=regcomp(&ireg, include_ptr, REG_EXTENDED);
|
||||
if(regres!=0) {
|
||||
regerror(regres, &ireg, rerrbuf, 64);
|
||||
die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"), progname, rerrbuf);
|
||||
np_die(STATE_UNKNOWN, _("Error compiling regexp: %s"), rerrbuf);
|
||||
}
|
||||
|
||||
if(do_exclude!=NULL){
|
||||
regres=regcomp(&ereg, do_exclude, REG_EXTENDED);
|
||||
if(regres!=0) {
|
||||
regerror(regres, &ereg, rerrbuf, 64);
|
||||
die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"),
|
||||
progname, rerrbuf);
|
||||
np_die(STATE_UNKNOWN, _("Error compiling regexp: %s"),
|
||||
rerrbuf);
|
||||
}
|
||||
}
|
||||
regres=regcomp(&sreg, crit_ptr, REG_EXTENDED);
|
||||
if(regres!=0) {
|
||||
regerror(regres, &ereg, rerrbuf, 64);
|
||||
die(STATE_UNKNOWN, _("%s: Error compiling regexp: %s"),
|
||||
progname, rerrbuf);
|
||||
np_die(STATE_UNKNOWN, _("Error compiling regexp: %s"),
|
||||
rerrbuf);
|
||||
}
|
||||
|
||||
cmdline=construct_cmdline(upgrade, upgrade_opts);
|
||||
|
|
@ -255,8 +254,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
|
|||
if(result != 0){
|
||||
exec_warning=1;
|
||||
result = STATE_UNKNOWN;
|
||||
fprintf(stderr, _("'%s' exited with non-zero status.\n"),
|
||||
cmdline);
|
||||
np_verbose(_("'%s' exited with non-zero status."), cmdline);
|
||||
}
|
||||
|
||||
/* parse the output, which should only consist of lines like
|
||||
|
|
@ -269,9 +267,7 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
|
|||
* in which case the logic here will slightly change.
|
||||
*/
|
||||
for(i = 0; i < chld_out.lines; i++) {
|
||||
if(verbose){
|
||||
printf("%s\n", chld_out.line[i]);
|
||||
}
|
||||
np_verbatim(chld_out.line[i]);
|
||||
/* if it is a package we care about */
|
||||
if(regexec(&ireg, chld_out.line[i], 0, NULL, 0)==0){
|
||||
/* if we're not excluding, or it's not in the
|
||||
|
|
@ -281,11 +277,9 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
|
|||
pc++;
|
||||
if(regexec(&sreg, chld_out.line[i], 0, NULL, 0)==0){
|
||||
spc++;
|
||||
if(verbose) printf("*");
|
||||
}
|
||||
if(verbose){
|
||||
printf("*%s\n", chld_out.line[i]);
|
||||
np_debug(1, "*");
|
||||
}
|
||||
np_verbose("*%s", chld_out.line[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -296,11 +290,8 @@ int run_upgrade(int *pkgcount, int *secpkgcount){
|
|||
if(chld_err.buflen){
|
||||
stderr_warning=1;
|
||||
result = max_state(result, STATE_WARNING);
|
||||
if(verbose){
|
||||
for(i = 0; i < chld_err.lines; i++) {
|
||||
fprintf(stderr, "%s\n", chld_err.line[i]);
|
||||
}
|
||||
}
|
||||
for(i = 0; i < chld_err.lines; i++)
|
||||
np_verbatim(chld_err.line[i]);
|
||||
}
|
||||
regfree(&ireg);
|
||||
regfree(&sreg);
|
||||
|
|
@ -324,25 +315,18 @@ int run_update(void){
|
|||
if(result != 0){
|
||||
exec_warning=1;
|
||||
result = STATE_CRITICAL;
|
||||
fprintf(stderr, _("'%s' exited with non-zero status.\n"),
|
||||
cmdline);
|
||||
np_verbose(_("'%s' exited with non-zero status."), cmdline);
|
||||
}
|
||||
|
||||
if(verbose){
|
||||
for(i = 0; i < chld_out.lines; i++) {
|
||||
printf("%s\n", chld_out.line[i]);
|
||||
}
|
||||
}
|
||||
for(i = 0; i < chld_out.lines; i++)
|
||||
np_verbatim(chld_out.line[i]);
|
||||
|
||||
/* If we get anything on stderr, at least set warning */
|
||||
if(chld_err.buflen){
|
||||
stderr_warning=1;
|
||||
result = max_state(result, STATE_WARNING);
|
||||
if(verbose){
|
||||
for(i = 0; i < chld_err.lines; i++) {
|
||||
fprintf(stderr, "%s\n", chld_err.line[i]);
|
||||
}
|
||||
}
|
||||
for(i = 0; i < chld_err.lines; i++)
|
||||
np_verbatim(chld_err.line[i]);
|
||||
}
|
||||
free(cmdline);
|
||||
return result;
|
||||
|
|
@ -353,12 +337,12 @@ char* add_to_regexp(char *expr, const char *next){
|
|||
|
||||
if(expr==NULL){
|
||||
re=malloc(sizeof(char)*(strlen("^Inst () ")+strlen(next)+1));
|
||||
if(!re) die(STATE_UNKNOWN, "malloc failed!\n");
|
||||
if(!re) np_die(STATE_UNKNOWN, "malloc failed: %m");
|
||||
sprintf(re, "^Inst (%s) ", next);
|
||||
} else {
|
||||
/* resize it, adding an extra char for the new '|' separator */
|
||||
re=realloc(expr, sizeof(char)*strlen(expr)+1+strlen(next)+1);
|
||||
if(!re) die(STATE_UNKNOWN, "realloc failed!\n");
|
||||
if(!re) np_die(STATE_UNKNOWN, "realloc failed: %m");
|
||||
/* append it starting at ')' in the old re */
|
||||
sprintf((char*)(re+strlen(re)-2), "|%s) ", next);
|
||||
}
|
||||
|
|
@ -394,7 +378,7 @@ char* construct_cmdline(upgrade_type u, const char *opts){
|
|||
len+=strlen(aptcmd)+1; /* "upgrade\0" */
|
||||
|
||||
cmd=(char*)malloc(sizeof(char)*len);
|
||||
if(cmd==NULL) die(STATE_UNKNOWN, "malloc failed");
|
||||
if(cmd==NULL) np_die(STATE_UNKNOWN, "malloc failed: %m");
|
||||
sprintf(cmd, "%s %s %s", PATH_TO_APTGET, opts_ptr, aptcmd);
|
||||
return cmd;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ char *outputfile = NULL;
|
|||
char *host_shortname = NULL;
|
||||
char **service;
|
||||
int passive = FALSE;
|
||||
int verbose = FALSE;
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
|
|
@ -71,6 +70,7 @@ main (int argc, char **argv)
|
|||
FILE *fp = NULL;
|
||||
struct output chld_out, chld_err;
|
||||
|
||||
np_set_mynames(argv[0], "BY-SSH");
|
||||
remotecmd = "";
|
||||
comm = strdup (SSH_COMMAND);
|
||||
|
||||
|
|
@ -89,8 +89,7 @@ main (int argc, char **argv)
|
|||
alarm (timeout_interval);
|
||||
|
||||
/* run the command */
|
||||
if (verbose)
|
||||
printf ("%s\n", comm);
|
||||
np_verbatim(comm);
|
||||
|
||||
result = np_runcmd(comm, &chld_out, &chld_err, 0);
|
||||
|
||||
|
|
@ -206,7 +205,7 @@ process_arguments (int argc, char **argv)
|
|||
print_help ();
|
||||
exit (STATE_OK);
|
||||
case 'v': /* help */
|
||||
verbose = TRUE;
|
||||
np_increase_verbosity(1);
|
||||
break;
|
||||
case 't': /* timeout period */
|
||||
if (!is_integer (optarg))
|
||||
|
|
@ -292,7 +291,7 @@ process_arguments (int argc, char **argv)
|
|||
c = optind;
|
||||
if (hostname == NULL) {
|
||||
if (c <= argc) {
|
||||
die (STATE_UNKNOWN, _("%s: You must provide a host name\n"), progname);
|
||||
np_die(STATE_UNKNOWN, _("You must provide a host name"));
|
||||
}
|
||||
host_or_die(argv[c]);
|
||||
hostname = argv[c++];
|
||||
|
|
@ -326,10 +325,10 @@ validate_arguments (void)
|
|||
return ERROR;
|
||||
|
||||
if (passive && commands != services)
|
||||
die (STATE_UNKNOWN, _("%s: In passive mode, you must provide a service name for each command.\n"), progname);
|
||||
np_die(STATE_UNKNOWN, _("In passive mode, you must provide a service name for each command."));
|
||||
|
||||
if (passive && host_shortname == NULL)
|
||||
die (STATE_UNKNOWN, _("%s: In passive mode, you must provide the host short name from the nagios configs.\n"), progname);
|
||||
np_die(STATE_UNKNOWN, _("In passive mode, you must provide the host short name from the nagios configs."));
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,8 +59,6 @@ int check_type=CHECK_SERVICES;
|
|||
char *data_vals=NULL;
|
||||
char *label=NULL;
|
||||
|
||||
int verbose=0;
|
||||
|
||||
int process_arguments(int,char **);
|
||||
|
||||
|
||||
|
|
@ -71,12 +69,13 @@ int main(int argc, char **argv){
|
|||
int return_code=STATE_OK;
|
||||
thresholds *thresholds = NULL;
|
||||
|
||||
np_set_mynames(argv[0], "CLUSTER");
|
||||
if(process_arguments(argc,argv)==ERROR)
|
||||
usage(_("Could not parse arguments"));
|
||||
|
||||
/* Initialize the thresholds */
|
||||
set_thresholds(&thresholds, warn_threshold, crit_threshold);
|
||||
if(verbose)
|
||||
if(np_get_verbosity()>0)
|
||||
print_thresholds("check_cluster", thresholds);
|
||||
|
||||
/* check the data values */
|
||||
|
|
@ -121,21 +120,17 @@ int main(int argc, char **argv){
|
|||
|
||||
|
||||
/* return the status of the cluster */
|
||||
if(check_type==CHECK_SERVICES){
|
||||
return_code=get_status(total_services_warning+total_services_unknown+total_services_critical, thresholds);
|
||||
printf("CLUSTER %s: %s: %d ok, %d warning, %d unknown, %d critical\n",
|
||||
state_text(return_code), (label==NULL)?"Service cluster":label,
|
||||
if(check_type==CHECK_SERVICES)
|
||||
np_die(get_status(total_services_warning+total_services_unknown+total_services_critical, thresholds),
|
||||
"%s: %d ok, %d warning, %d unknown, %d critical\n",
|
||||
(label==NULL)?"Service cluster":label,
|
||||
total_services_ok,total_services_warning,
|
||||
total_services_unknown,total_services_critical);
|
||||
}
|
||||
else{
|
||||
return_code=get_status(total_hosts_down+total_hosts_unreachable, thresholds);
|
||||
printf("CLUSTER %s: %s: %d up, %d down, %d unreachable\n",
|
||||
state_text(return_code), (label==NULL)?"Host cluster":label,
|
||||
else
|
||||
np_die(get_status(total_services_warning+total_services_unknown+total_services_critical, thresholds),
|
||||
"%s: %d up, %d down, %d unreachable\n",
|
||||
(label==NULL)?"Host cluster":label,
|
||||
total_hosts_up,total_hosts_down,total_hosts_unreachable);
|
||||
}
|
||||
|
||||
return return_code;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -198,7 +193,7 @@ int process_arguments(int argc, char **argv){
|
|||
break;
|
||||
|
||||
case 'v': /* verbose */
|
||||
verbose++;
|
||||
np_increase_verbosity(1);
|
||||
break;
|
||||
|
||||
case 'V': /* version */
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ char *query_address = NULL;
|
|||
char *record_type = "A";
|
||||
char *expected_address = NULL;
|
||||
char *dns_server = NULL;
|
||||
int verbose = FALSE;
|
||||
int server_port = DEFAULT_PORT;
|
||||
double warning_interval = UNDEFINED;
|
||||
double critical_interval = UNDEFINED;
|
||||
|
|
@ -77,6 +76,7 @@ main (int argc, char **argv)
|
|||
double elapsed_time;
|
||||
int result = STATE_UNKNOWN;
|
||||
|
||||
np_set_mynames(argv[0], "DNS");
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
|
@ -95,13 +95,11 @@ main (int argc, char **argv)
|
|||
alarm (timeout_interval);
|
||||
gettimeofday (&tv, NULL);
|
||||
|
||||
if (verbose) {
|
||||
printf ("%s\n", command_line);
|
||||
if(expected_address != NULL) {
|
||||
printf (_("Looking for: '%s'\n"), expected_address);
|
||||
} else {
|
||||
printf (_("Looking for: '%s'\n"), query_address);
|
||||
}
|
||||
np_verbatim(command_line);
|
||||
if(expected_address != NULL) {
|
||||
np_verbose(_("Looking for: '%s'"), expected_address);
|
||||
} else {
|
||||
np_verbose(_("Looking for: '%s'"), query_address);
|
||||
}
|
||||
|
||||
/* run the command */
|
||||
|
|
@ -117,8 +115,7 @@ main (int argc, char **argv)
|
|||
/* loop through the whole 'ANSWER SECTION' */
|
||||
for(; i < chld_out.lines; i++) {
|
||||
/* get the host address */
|
||||
if (verbose)
|
||||
printf ("%s\n", chld_out.line[i]);
|
||||
np_verbatim(chld_out.line[i]);
|
||||
|
||||
if (strstr (chld_out.line[i], (expected_address == NULL ? query_address : expected_address)) != NULL) {
|
||||
msg = chld_out.line[i];
|
||||
|
|
@ -165,8 +162,9 @@ main (int argc, char **argv)
|
|||
else if (warning_interval > UNDEFINED && elapsed_time > warning_interval)
|
||||
result = STATE_WARNING;
|
||||
|
||||
printf ("DNS %s - %.3f seconds response time (%s)|%s\n",
|
||||
state_text (result), elapsed_time,
|
||||
np_die(result,
|
||||
"%.3f seconds response time (%s)|%s\n",
|
||||
elapsed_time,
|
||||
msg ? msg : _("Probably a non-existent host/domain"),
|
||||
fperfdata("time", elapsed_time, "s",
|
||||
(warning_interval>UNDEFINED?TRUE:FALSE),
|
||||
|
|
@ -174,7 +172,6 @@ main (int argc, char **argv)
|
|||
(critical_interval>UNDEFINED?TRUE:FALSE),
|
||||
critical_interval,
|
||||
TRUE, 0, FALSE, 0));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -257,7 +254,7 @@ process_arguments (int argc, char **argv)
|
|||
}
|
||||
break;
|
||||
case 'v': /* verbose */
|
||||
verbose = TRUE;
|
||||
np_increase_verbosity(1);
|
||||
break;
|
||||
case 'T':
|
||||
record_type = optarg;
|
||||
|
|
|
|||
|
|
@ -134,7 +134,6 @@ char *path;
|
|||
char *exclude_device;
|
||||
char *units;
|
||||
uintmax_t mult = 1024 * 1024;
|
||||
int verbose = 0;
|
||||
int erronly = FALSE;
|
||||
int display_mntp = FALSE;
|
||||
int exact_match = FALSE;
|
||||
|
|
@ -178,7 +177,8 @@ main (int argc, char **argv)
|
|||
struct name_list *seen = NULL;
|
||||
struct stat *stat_buf;
|
||||
|
||||
preamble = strdup (" - free space:");
|
||||
np_set_mynames(argv[0], "DISK");
|
||||
preamble = strdup (" free space:");
|
||||
output = strdup ("");
|
||||
details = strdup ("");
|
||||
perf = strdup ("");
|
||||
|
|
@ -228,12 +228,12 @@ main (int argc, char **argv)
|
|||
/* Process for every path in list */
|
||||
for (path = path_select_list; path; path=path->name_next) {
|
||||
|
||||
if (verbose > 3 && path->freespace_percent->warning != NULL && path->freespace_percent->critical != NULL)
|
||||
printf("Thresholds(pct) for %s warn: %f crit %f\n",path->name, path->freespace_percent->warning->end,
|
||||
path->freespace_percent->critical->end);
|
||||
if (path->freespace_percent->warning != NULL && path->freespace_percent->critical != NULL)
|
||||
np_debug(4, "Thresholds(pct) for %s warn: %f crit %f\n",path->name, path->freespace_percent->warning->end,
|
||||
path->freespace_percent->critical->end);
|
||||
|
||||
if (verbose > 3 && path->group != NULL)
|
||||
printf("Group of %s: %s\n",path->name,path->group);
|
||||
if (path->group != NULL)
|
||||
np_debug(4, "Group of %s: %s\n",path->name,path->group);
|
||||
|
||||
/* reset disk result */
|
||||
disk_result = STATE_UNKNOWN;
|
||||
|
|
@ -270,8 +270,7 @@ main (int argc, char **argv)
|
|||
fsp.fsu_files += tmpfsp.fsu_files; /* Total file nodes. */
|
||||
fsp.fsu_ffree += tmpfsp.fsu_ffree; /* Free file nodes. */
|
||||
|
||||
if (verbose > 3)
|
||||
printf("Group %s: add %llu blocks (%s) \n", path->group, tmpfsp.fsu_bavail, temp_list->name);
|
||||
np_debug(4, "Group %s: add %llu blocks (%s) \n", path->group, tmpfsp.fsu_bavail, temp_list->name);
|
||||
/* printf("Group %s: add %u blocks (%s)\n", temp_list->name); // path->group, tmpfsp.fsu_bavail, temp_list->name); */
|
||||
|
||||
np_add_name(&seen, temp_list->best_match->me_mountdir);
|
||||
|
|
@ -318,35 +317,33 @@ main (int argc, char **argv)
|
|||
dused_inodes_percent = calculate_percent(fsp.fsu_files - fsp.fsu_ffree, fsp.fsu_files);
|
||||
dfree_inodes_percent = 100 - dused_inodes_percent;
|
||||
|
||||
if (verbose >= 3) {
|
||||
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",
|
||||
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",
|
||||
me->me_mountdir, dused_pct, dfree_pct, dused_units, dfree_units, dtotal_units, dused_inodes_percent, dfree_inodes_percent);
|
||||
}
|
||||
|
||||
/* Threshold comparisons */
|
||||
|
||||
temp_result = get_status(dfree_units, path->freespace_units);
|
||||
if (verbose >=3) printf("Freespace_units result=%d\n", temp_result);
|
||||
np_debug(3, "Freespace_units result=%d\n", temp_result);
|
||||
disk_result = max_state( disk_result, temp_result );
|
||||
|
||||
temp_result = get_status(dfree_pct, path->freespace_percent);
|
||||
if (verbose >=3) printf("Freespace%% result=%d\n", temp_result);
|
||||
np_debug(3, "Freespace%% result=%d\n", temp_result);
|
||||
disk_result = max_state( disk_result, temp_result );
|
||||
|
||||
temp_result = get_status(dused_units, path->usedspace_units);
|
||||
if (verbose >=3) printf("Usedspace_units result=%d\n", temp_result);
|
||||
np_debug(3, "Usedspace_units result=%d\n", temp_result);
|
||||
disk_result = max_state( disk_result, temp_result );
|
||||
|
||||
temp_result = get_status(dused_pct, path->usedspace_percent);
|
||||
if (verbose >=3) printf("Usedspace_percent result=%d\n", temp_result);
|
||||
np_debug(3, "Usedspace_percent result=%d\n", temp_result);
|
||||
disk_result = max_state( disk_result, temp_result );
|
||||
|
||||
temp_result = get_status(dused_inodes_percent, path->usedinodes_percent);
|
||||
if (verbose >=3) printf("Usedinodes_percent result=%d\n", temp_result);
|
||||
np_debug(3, "Usedinodes_percent result=%d\n", temp_result);
|
||||
disk_result = max_state( disk_result, temp_result );
|
||||
|
||||
temp_result = get_status(dfree_inodes_percent, path->freeinodes_percent);
|
||||
if (verbose >=3) printf("Freeinodes_percent result=%d\n", temp_result);
|
||||
np_debug(3, "Freeinodes_percent result=%d\n", temp_result);
|
||||
disk_result = max_state( disk_result, temp_result );
|
||||
|
||||
result = max_state(result, disk_result);
|
||||
|
|
@ -381,10 +378,10 @@ main (int argc, char **argv)
|
|||
TRUE, 0,
|
||||
TRUE, dtotal_units));
|
||||
|
||||
if (disk_result==STATE_OK && erronly && !verbose)
|
||||
if (disk_result==STATE_OK && erronly && np_get_verbosity()<=0)
|
||||
continue;
|
||||
|
||||
if (disk_result!=STATE_OK || verbose>=0) {
|
||||
if (disk_result!=STATE_OK || np_get_verbosity()>=0) {
|
||||
asprintf (&output, "%s %s %.0f %s (%.0f%%",
|
||||
output,
|
||||
(!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
|
||||
|
|
@ -410,12 +407,11 @@ main (int argc, char **argv)
|
|||
|
||||
}
|
||||
|
||||
if (verbose > 2)
|
||||
if (np_get_verbosity()>=3)
|
||||
asprintf (&output, "%s%s", output, details);
|
||||
|
||||
|
||||
printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf);
|
||||
return result;
|
||||
np_die(result, "%s%s|%s", (erronly && result==STATE_OK) ? "" : preamble, output, perf);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -635,10 +631,10 @@ process_arguments (int argc, char **argv)
|
|||
np_add_name(&fs_exclude_list, optarg);
|
||||
break;
|
||||
case 'v': /* verbose */
|
||||
verbose++;
|
||||
np_increase_verbosity(1);
|
||||
break;
|
||||
case 'q': /* verbose */
|
||||
verbose--;
|
||||
np_decrease_verbosity(1);
|
||||
break;
|
||||
case 'e':
|
||||
erronly = TRUE;
|
||||
|
|
@ -670,8 +666,7 @@ process_arguments (int argc, char **argv)
|
|||
for (me = mount_list; me; me = me->me_next) {
|
||||
if (np_regex_match_mount_entry(me, &re)) {
|
||||
fnd = true;
|
||||
if (verbose > 3)
|
||||
printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);
|
||||
np_debug(4, "%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);
|
||||
|
||||
/* add parameter if not found. overwrite thresholds if path has already been added */
|
||||
if (! (se = np_find_parameter(path_select_list, me->me_mountdir))) {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ void print_usage (void);
|
|||
char query_address[ADDRESS_LENGTH] = "";
|
||||
char dns_server[ADDRESS_LENGTH] = "";
|
||||
char ptr_server[ADDRESS_LENGTH] = "";
|
||||
int verbose = FALSE;
|
||||
char expected_address[ADDRESS_LENGTH] = "";
|
||||
int match_expected_address = FALSE;
|
||||
int expect_authority = FALSE;
|
||||
|
|
@ -80,6 +79,7 @@ main (int argc, char **argv)
|
|||
output chld_out, chld_err;
|
||||
size_t i;
|
||||
|
||||
np_set_mynames(argv[0], "DNS");
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
|
@ -99,8 +99,7 @@ main (int argc, char **argv)
|
|||
alarm (timeout_interval);
|
||||
gettimeofday (&tv, NULL);
|
||||
|
||||
if (verbose)
|
||||
printf ("%s\n", command_line);
|
||||
np_verbatim(command_line);
|
||||
|
||||
/* run the command */
|
||||
if((np_runcmd(command_line, &chld_out, &chld_err, 0)) != 0) {
|
||||
|
|
@ -110,8 +109,7 @@ main (int argc, char **argv)
|
|||
|
||||
/* scan stdout */
|
||||
for(i = 0; i < chld_out.lines; i++) {
|
||||
if (verbose)
|
||||
puts(chld_out.line[i]);
|
||||
np_verbatim(chld_out.line[i]);
|
||||
|
||||
if (strstr (chld_out.line[i], ".in-addr.arpa")) {
|
||||
if ((temp_buffer = strstr (chld_out.line[i], "name = ")))
|
||||
|
|
@ -161,8 +159,7 @@ main (int argc, char **argv)
|
|||
|
||||
/* scan stderr */
|
||||
for(i = 0; i < chld_err.lines; i++) {
|
||||
if (verbose)
|
||||
puts(chld_err.line[i]);
|
||||
np_verbatim(chld_err.line[i]);
|
||||
|
||||
if (error_scan (chld_err.line[i]) != STATE_OK) {
|
||||
result = max_state (result, error_scan (chld_err.line[i]));
|
||||
|
|
@ -329,7 +326,7 @@ process_arguments (int argc, char **argv)
|
|||
print_revision (progname, revision);
|
||||
exit (STATE_OK);
|
||||
case 'v': /* version */
|
||||
verbose = TRUE;
|
||||
np_increase_verbosity(1);
|
||||
break;
|
||||
case 't': /* timeout period */
|
||||
timeout_interval = atoi (optarg);
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ void print_usage (void);
|
|||
char *server_name = NULL;
|
||||
int packet_size = PACKET_SIZE;
|
||||
int packet_count = PACKET_COUNT;
|
||||
int verbose = FALSE;
|
||||
int cpl;
|
||||
int wpl;
|
||||
double crta;
|
||||
|
|
@ -81,6 +80,7 @@ main (int argc, char **argv)
|
|||
char *input_buffer = NULL;
|
||||
input_buffer = malloc (MAX_INPUT_BUFFER);
|
||||
|
||||
np_set_mynames(argv[0], "FPING");
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
|
@ -94,32 +94,26 @@ main (int argc, char **argv)
|
|||
asprintf (&command_line, "%s -b %d -c %d %s", PATH_TO_FPING,
|
||||
packet_size, packet_count, server);
|
||||
|
||||
if (verbose)
|
||||
printf ("%s\n", command_line);
|
||||
np_verbatim(command_line);
|
||||
|
||||
/* run the command */
|
||||
child_process = spopen (command_line);
|
||||
if (child_process == NULL) {
|
||||
printf (_("Could not open pipe: %s\n"), command_line);
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
if (child_process == NULL)
|
||||
np_die(STATE_UNKNOWN, _("Could not open pipe: %s"), command_line);
|
||||
|
||||
child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
|
||||
if (child_stderr == NULL) {
|
||||
if (child_stderr == NULL)
|
||||
printf (_("Could not open stderr for %s\n"), command_line);
|
||||
}
|
||||
|
||||
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
|
||||
if (verbose)
|
||||
printf ("%s", input_buffer);
|
||||
np_verbatim(input_buffer);
|
||||
status = max_state (status, textscan (input_buffer));
|
||||
}
|
||||
|
||||
/* If we get anything on STDERR, at least set warning */
|
||||
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
|
||||
status = max_state (status, STATE_WARNING);
|
||||
if (verbose)
|
||||
printf ("%s", input_buffer);
|
||||
np_verbatim(input_buffer);
|
||||
status = max_state (status, textscan (input_buffer));
|
||||
}
|
||||
(void) fclose (child_stderr);
|
||||
|
|
@ -129,9 +123,7 @@ main (int argc, char **argv)
|
|||
/* need to use max_state not max */
|
||||
status = max_state (status, STATE_WARNING);
|
||||
|
||||
printf ("FPING %s - %s\n", state_text (status), server_name);
|
||||
|
||||
return status;
|
||||
np_die("%s", server_name);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -146,16 +138,15 @@ textscan (char *buf)
|
|||
int status = STATE_UNKNOWN;
|
||||
|
||||
if (strstr (buf, "not found")) {
|
||||
die (STATE_CRITICAL, _("FPING UNKNOW - %s not found\n"), server_name);
|
||||
np_die(STATE_UNKNOWN, _("%s not found"), server_name);
|
||||
|
||||
}
|
||||
else if (strstr (buf, "is unreachable") || strstr (buf, "Unreachable")) {
|
||||
die (STATE_CRITICAL, _("FPING CRITICAL - %s is unreachable\n"),
|
||||
"host");
|
||||
np_die(STATE_CRITICAL, _("%s is unreachable"), "host");
|
||||
|
||||
}
|
||||
else if (strstr (buf, "is down")) {
|
||||
die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name);
|
||||
np_die(STATE_CRITICAL, _("%s is down"), server_name);
|
||||
|
||||
}
|
||||
else if (strstr (buf, "is alive")) {
|
||||
|
|
@ -181,9 +172,9 @@ textscan (char *buf)
|
|||
status = STATE_WARNING;
|
||||
else
|
||||
status = STATE_OK;
|
||||
die (status,
|
||||
_("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"),
|
||||
state_text (status), server_name, loss, rta,
|
||||
np_die(status,
|
||||
_("- %s (loss=%.0f%%, rta=%f ms)|%s %s\n"),
|
||||
server_name, loss, rta,
|
||||
perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100),
|
||||
fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0));
|
||||
|
||||
|
|
@ -203,8 +194,8 @@ textscan (char *buf)
|
|||
else
|
||||
status = STATE_OK;
|
||||
/* loss=%.0f%%;%d;%d;0;100 */
|
||||
die (status, _("FPING %s - %s (loss=%.0f%% )|%s\n"),
|
||||
state_text (status), server_name, loss ,
|
||||
np_die(status, _("%s (loss=%.0f%% )|%s"),
|
||||
server_name, loss,
|
||||
perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100));
|
||||
|
||||
}
|
||||
|
|
@ -266,7 +257,7 @@ process_arguments (int argc, char **argv)
|
|||
print_revision (progname, revision);
|
||||
exit (STATE_OK);
|
||||
case 'v': /* verbose mode */
|
||||
verbose = TRUE;
|
||||
np_increase_verbosity(1);
|
||||
break;
|
||||
case 'H': /* hostname */
|
||||
if (is_host (optarg) == FALSE) {
|
||||
|
|
@ -335,13 +326,11 @@ get_threshold (char *arg, char *rv[2])
|
|||
if (arg2) {
|
||||
arg1[strcspn (arg1, ",:")] = 0;
|
||||
if (strstr (arg1, "%") && strstr (arg2, "%"))
|
||||
die (STATE_UNKNOWN,
|
||||
_("%s: Only one threshold may be packet loss (%s)\n"), progname,
|
||||
arg);
|
||||
np_die(STATE_UNKNOWN,
|
||||
_("Only one threshold may be packet loss (%s)\n"), arg);
|
||||
if (!strstr (arg1, "%") && !strstr (arg2, "%"))
|
||||
die (STATE_UNKNOWN,
|
||||
_("%s: Only one threshold must be packet loss (%s)\n"),
|
||||
progname, arg);
|
||||
np_die(STATE_UNKNOWN,
|
||||
_("Only one threshold must be packet loss (%s)\n"), arg);
|
||||
}
|
||||
|
||||
if (arg2 && strstr (arg2, "%")) {
|
||||
|
|
|
|||
|
|
@ -58,8 +58,6 @@ char *server_ip;
|
|||
char *game_type;
|
||||
int port = 0;
|
||||
|
||||
int verbose;
|
||||
|
||||
int qstat_game_players_max = -1;
|
||||
int qstat_game_players = -1;
|
||||
int qstat_game_field = -1;
|
||||
|
|
@ -76,6 +74,7 @@ main (int argc, char **argv)
|
|||
size_t i = 0;
|
||||
output chld_out;
|
||||
|
||||
np_set_mymanes(argv[0], "GAME");
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
|
@ -92,8 +91,7 @@ main (int argc, char **argv)
|
|||
if (port)
|
||||
asprintf (&command_line, "%s:%-d", command_line, port);
|
||||
|
||||
if (verbose > 0)
|
||||
printf ("%s\n", command_line);
|
||||
np_verbatim(command_line);
|
||||
|
||||
/* run the command. historically, this plugin ignores output on stderr,
|
||||
* as well as return status of the qstat program */
|
||||
|
|
@ -109,11 +107,8 @@ main (int argc, char **argv)
|
|||
In the end, I figured I'd simply let an error occur & then trap it
|
||||
*/
|
||||
|
||||
if (!strncmp (chld_out.line[0], "unknown option", 14)) {
|
||||
printf (_("CRITICAL - Host type parameter incorrect!\n"));
|
||||
result = STATE_CRITICAL;
|
||||
return result;
|
||||
}
|
||||
if (!strncmp (chld_out.line[0], "unknown option", 14))
|
||||
np_die(STATE_CRITICAL, _("CRITICAL - Host type parameter incorrect!"));
|
||||
|
||||
p = (char *) strtok (chld_out.line[0], QSTAT_DATA_DELIMITER);
|
||||
while (p != NULL) {
|
||||
|
|
@ -124,20 +119,14 @@ main (int argc, char **argv)
|
|||
break;
|
||||
}
|
||||
|
||||
if (strstr (ret[2], QSTAT_HOST_ERROR)) {
|
||||
printf (_("CRITICAL - Host not found\n"));
|
||||
result = STATE_CRITICAL;
|
||||
}
|
||||
else if (strstr (ret[2], QSTAT_HOST_DOWN)) {
|
||||
printf (_("CRITICAL - Game server down or unavailable\n"));
|
||||
result = STATE_CRITICAL;
|
||||
}
|
||||
else if (strstr (ret[2], QSTAT_HOST_TIMEOUT)) {
|
||||
printf (_("CRITICAL - Game server timeout\n"));
|
||||
result = STATE_CRITICAL;
|
||||
}
|
||||
else {
|
||||
printf ("OK: %s/%s %s (%s), Ping: %s ms|%s %s\n",
|
||||
if (strstr (ret[2], QSTAT_HOST_ERROR))
|
||||
np_die(STATE_CRITICAL, _("CRITICAL - Host not found"));
|
||||
else if (strstr (ret[2], QSTAT_HOST_DOWN))
|
||||
np_die(STATE_CRITICAL, _("CRITICAL - Game server down or unavailable"));
|
||||
else if (strstr (ret[2], QSTAT_HOST_TIMEOUT))
|
||||
np_die(STATE_CRITICAL, _("CRITICAL - Game server timeout\n"));
|
||||
else
|
||||
np_die(STATE_OK, "%s/%s %s (%s), Ping: %s ms|%s %s\n",
|
||||
ret[qstat_game_players],
|
||||
ret[qstat_game_players_max],
|
||||
ret[qstat_game_field],
|
||||
|
|
@ -149,9 +138,6 @@ main (int argc, char **argv)
|
|||
fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "",
|
||||
FALSE, 0, FALSE, 0,
|
||||
TRUE, 0, FALSE, 0));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -203,14 +189,14 @@ process_arguments (int argc, char **argv)
|
|||
print_revision (progname, revision);
|
||||
exit (STATE_OK);
|
||||
case 'v': /* version */
|
||||
verbose = TRUE;
|
||||
np_increase_verbosity(1);
|
||||
break;
|
||||
case 't': /* timeout period */
|
||||
timeout_interval = atoi (optarg);
|
||||
break;
|
||||
case 'H': /* hostname */
|
||||
if (strlen (optarg) >= MAX_HOST_ADDRESS_LENGTH)
|
||||
die (STATE_UNKNOWN, _("Input buffer overflow\n"));
|
||||
np_die(STATE_UNKNOWN, _("Input buffer overflow"));
|
||||
server_ip = optarg;
|
||||
break;
|
||||
case 'P': /* port */
|
||||
|
|
@ -218,7 +204,7 @@ process_arguments (int argc, char **argv)
|
|||
break;
|
||||
case 'G': /* hostname */
|
||||
if (strlen (optarg) >= MAX_INPUT_BUFFER)
|
||||
die (STATE_UNKNOWN, _("Input buffer overflow\n"));
|
||||
np_die(STATE_UNKNOWN, _("Input buffer overflow"));
|
||||
game_type = optarg;
|
||||
break;
|
||||
case 'p': /* index of ping field */
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ main (int argc, char **argv)
|
|||
|
||||
errmsg = malloc(MAX_INPUT_BUFFER);
|
||||
|
||||
np_set_mynames(argv[0], "HPJD");
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
|
@ -127,15 +128,12 @@ main (int argc, char **argv)
|
|||
|
||||
/* run the command */
|
||||
child_process = spopen (command_line);
|
||||
if (child_process == NULL) {
|
||||
printf (_("Could not open pipe: %s\n"), command_line);
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
if (child_process == NULL)
|
||||
np_die(STATE_UNKNOWN, _("Could not open pipe: %s"), command_line);
|
||||
|
||||
child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
|
||||
if (child_stderr == NULL) {
|
||||
if (child_stderr == NULL)
|
||||
printf (_("Could not open stderr for %s\n"), command_line);
|
||||
}
|
||||
|
||||
result = STATE_OK;
|
||||
|
||||
|
|
@ -286,21 +284,13 @@ main (int argc, char **argv)
|
|||
}
|
||||
|
||||
if (result == STATE_OK)
|
||||
printf (_("Printer ok - (%s)\n"), display_message);
|
||||
|
||||
else if (result == STATE_UNKNOWN) {
|
||||
|
||||
printf ("%s\n", errmsg);
|
||||
|
||||
/* if printer could not be reached, escalate to critical */
|
||||
if (strstr (errmsg, "Timeout"))
|
||||
result = STATE_CRITICAL;
|
||||
}
|
||||
|
||||
np_die(STATE_OK, _("Printer ok - (%s)"), display_message);
|
||||
else if (result == STATE_WARNING)
|
||||
printf ("%s (%s)\n", errmsg, display_message);
|
||||
np_die(STATE_WARNING, "%s (%s)\n", errmsg, display_message);
|
||||
|
||||
return result;
|
||||
/* if printer could not be reached, escalate to critical */
|
||||
np_die(strstr(errmsg, "Timeout") ? STATE_CRITICAL : STATE_UNKNOWN,
|
||||
"%s", errmsg);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -113,7 +113,6 @@ char **http_opt_headers;
|
|||
int http_opt_headers_count = 0;
|
||||
int onredirect = STATE_OK;
|
||||
int use_ssl = FALSE;
|
||||
int verbose = FALSE;
|
||||
int sd;
|
||||
int min_page_len = 0;
|
||||
int max_page_len = 0;
|
||||
|
|
@ -140,6 +139,8 @@ main (int argc, char **argv)
|
|||
{
|
||||
int result = STATE_UNKNOWN;
|
||||
|
||||
np_set_mynames(argv[0], "HTTP");
|
||||
|
||||
/* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */
|
||||
server_url = strdup(HTTP_URL);
|
||||
server_url_length = strlen(server_url);
|
||||
|
|
@ -307,8 +308,7 @@ process_arguments (int argc, char **argv)
|
|||
onredirect = STATE_WARNING;
|
||||
if (!strcmp (optarg, "critical"))
|
||||
onredirect = STATE_CRITICAL;
|
||||
if (verbose)
|
||||
printf(_("option f:%d \n"), onredirect);
|
||||
np_verbose (_("option f:%d"), onredirect);
|
||||
break;
|
||||
/* Note: H, I, and u must be malloc'd or will fail on redirects */
|
||||
case 'H': /* Host Name (virtual host) */
|
||||
|
|
@ -381,7 +381,7 @@ process_arguments (int argc, char **argv)
|
|||
#endif
|
||||
break;
|
||||
case 'v': /* verbose */
|
||||
verbose = TRUE;
|
||||
np_increase_verbosity(1);
|
||||
break;
|
||||
case 'm': /* min_page_length */
|
||||
{
|
||||
|
|
@ -389,17 +389,15 @@ process_arguments (int argc, char **argv)
|
|||
if (strchr(optarg, ':') != (char *)NULL) {
|
||||
/* range, so get two values, min:max */
|
||||
tmp = strtok(optarg, ":");
|
||||
if (tmp == NULL) {
|
||||
printf("Bad format: try \"-m min:max\"\n");
|
||||
exit (STATE_WARNING);
|
||||
} else
|
||||
if (tmp == NULL)
|
||||
np_die (STATE_UNKNOWN, "Bad format: try \"-m min:max\"");
|
||||
else
|
||||
min_page_len = atoi(tmp);
|
||||
|
||||
tmp = strtok(NULL, ":");
|
||||
if (tmp == NULL) {
|
||||
printf("Bad format: try \"-m min:max\"\n");
|
||||
exit (STATE_WARNING);
|
||||
} else
|
||||
if (tmp == NULL)
|
||||
np_die (STATE_UNKNOWN, "Bad format: try \"-m min:max\"");
|
||||
else
|
||||
max_page_len = atoi(tmp);
|
||||
} else
|
||||
min_page_len = atoi (optarg);
|
||||
|
|
@ -420,10 +418,8 @@ process_arguments (int argc, char **argv)
|
|||
else if (L && (optarg[L-1] == 's' ||
|
||||
isdigit (optarg[L-1])))
|
||||
maximum_age = atoi (optarg);
|
||||
else {
|
||||
fprintf (stderr, "unparsable max-age: %s\n", optarg);
|
||||
exit (STATE_WARNING);
|
||||
}
|
||||
else
|
||||
np_die (STATE_UNKNOWN, _("Unparsable max-age: %s"), optarg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -593,7 +589,7 @@ parse_time_string (const char *string)
|
|||
t = mktime (&tm);
|
||||
if (t == (time_t) -1) t = 0;
|
||||
|
||||
if (verbose) {
|
||||
if (np_get_verbosity() > 0) {
|
||||
const char *s = string;
|
||||
while (*s && *s != '\r' && *s != '\n')
|
||||
fputc (*s++, stdout);
|
||||
|
|
@ -665,28 +661,27 @@ check_document_dates (const char *headers)
|
|||
|
||||
/* Done parsing the body. Now check the dates we (hopefully) parsed. */
|
||||
if (!server_date || !*server_date) {
|
||||
die (STATE_UNKNOWN, _("HTTP UNKNOWN - Server date unknown\n"));
|
||||
np_die (STATE_UNKNOWN, _("Server date unknown"));
|
||||
} else if (!document_date || !*document_date) {
|
||||
die (STATE_CRITICAL, _("HTTP CRITICAL - Document modification date unknown\n"));
|
||||
np_die (STATE_CRITICAL, _("Document modification date unknown"));
|
||||
} else {
|
||||
time_t srv_data = parse_time_string (server_date);
|
||||
time_t doc_data = parse_time_string (document_date);
|
||||
|
||||
if (srv_data <= 0) {
|
||||
die (STATE_CRITICAL, _("HTTP CRITICAL - Server date \"%100s\" unparsable"), server_date);
|
||||
np_die (STATE_CRITICAL, _("Server date \"%100s\" unparsable"), server_date);
|
||||
} else if (doc_data <= 0) {
|
||||
die (STATE_CRITICAL, _("HTTP CRITICAL - Document date \"%100s\" unparsable"), document_date);
|
||||
np_die (STATE_CRITICAL, _("Document date \"%100s\" unparsable"), document_date);
|
||||
} else if (doc_data > srv_data + 30) {
|
||||
die (STATE_CRITICAL, _("HTTP CRITICAL - Document is %d seconds in the future\n"), (int)doc_data - (int)srv_data);
|
||||
np_die (STATE_CRITICAL, _("Document is %d seconds in the future"),
|
||||
(int)doc_data - (int)srv_data);
|
||||
} else if (doc_data < srv_data - maximum_age) {
|
||||
int n = (srv_data - doc_data);
|
||||
if (n > (60 * 60 * 24 * 2))
|
||||
die (STATE_CRITICAL,
|
||||
_("HTTP CRITICAL - Last modified %.1f days ago\n"),
|
||||
np_die (STATE_CRITICAL, _("Last modified %.1f days ago"),
|
||||
((float) n) / (60 * 60 * 24));
|
||||
else
|
||||
die (STATE_CRITICAL,
|
||||
_("HTTP CRITICAL - Last modified %d:%02d:%02d ago\n"),
|
||||
np_die (STATE_CRITICAL, _("Last modified %d:%02d:%02d ago"),
|
||||
n / (60 * 60), (n / 60) % 60, n % 60);
|
||||
}
|
||||
|
||||
|
|
@ -767,7 +762,7 @@ check_http (void)
|
|||
|
||||
/* try to connect to the host at the given port number */
|
||||
if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK)
|
||||
die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n"));
|
||||
np_die (STATE_CRITICAL, _("Unable to open TCP socket"));
|
||||
#ifdef HAVE_SSL
|
||||
if (use_ssl == TRUE) {
|
||||
np_net_ssl_init(sd);
|
||||
|
|
@ -820,7 +815,7 @@ check_http (void)
|
|||
asprintf (&buf, "%s%s", buf, CRLF);
|
||||
}
|
||||
|
||||
if (verbose) printf ("%s\n", buf);
|
||||
np_verbatim (buf);
|
||||
my_send (buf, strlen (buf));
|
||||
|
||||
/* fetch the page */
|
||||
|
|
@ -842,15 +837,15 @@ check_http (void)
|
|||
if (use_ssl) {
|
||||
sslerr=SSL_get_error(ssl, i);
|
||||
if ( sslerr == SSL_ERROR_SSL ) {
|
||||
die (STATE_WARNING, _("HTTP WARNING - Client Certificate Required\n"));
|
||||
np_die (STATE_WARNING, _("Client Certificate Required"));
|
||||
} else {
|
||||
die (STATE_CRITICAL, _("HTTP CRITICAL - Error on receive\n"));
|
||||
np_die (STATE_CRITICAL, _("Error on receive"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
*/
|
||||
#endif
|
||||
die (STATE_CRITICAL, _("HTTP CRITICAL - Error on receive\n"));
|
||||
np_die (STATE_CRITICAL, _("HTTP CRITICAL - Error on receive"));
|
||||
#ifdef HAVE_SSL
|
||||
/* XXX
|
||||
}
|
||||
|
|
@ -860,7 +855,7 @@ check_http (void)
|
|||
|
||||
/* return a CRITICAL status if we couldn't read any data */
|
||||
if (pagesize == (size_t) 0)
|
||||
die (STATE_CRITICAL, _("HTTP CRITICAL - No data received from host\n"));
|
||||
np_die (STATE_CRITICAL, _("HTTP CRITICAL - No data received from host"));
|
||||
|
||||
/* close the connection */
|
||||
#ifdef HAVE_SSL
|
||||
|
|
@ -874,8 +869,7 @@ check_http (void)
|
|||
/* leave full_page untouched so we can free it later */
|
||||
page = full_page;
|
||||
|
||||
if (verbose)
|
||||
printf ("%s://%s:%d%s is %d characters\n",
|
||||
np_verbose ("%s://%s:%d%s is %d characters",
|
||||
use_ssl ? "https" : "http", server_address,
|
||||
server_port, server_url, (int)pagesize);
|
||||
|
||||
|
|
@ -886,8 +880,7 @@ check_http (void)
|
|||
page += (size_t) strspn (page, "\r\n");
|
||||
status_line[strcspn(status_line, "\r\n")] = 0;
|
||||
strip (status_line);
|
||||
if (verbose)
|
||||
printf ("STATUS: %s\n", status_line);
|
||||
np_verbose ("STATUS: %s", status_line);
|
||||
|
||||
/* find header info and null-terminate it */
|
||||
header = page;
|
||||
|
|
@ -902,29 +895,27 @@ check_http (void)
|
|||
}
|
||||
page += (size_t) strspn (page, "\r\n");
|
||||
header[pos - header] = 0;
|
||||
if (verbose)
|
||||
printf ("**** HEADER ****\n%s\n**** CONTENT ****\n%s\n", header,
|
||||
np_verbose ("**** HEADER ****\n%s\n**** CONTENT ****\n%s", header,
|
||||
(no_body ? " [[ skipped ]]" : page));
|
||||
|
||||
/* make sure the status line matches the response we are looking for */
|
||||
if (!strstr (status_line, server_expect)) {
|
||||
if (server_port == HTTP_PORT)
|
||||
asprintf (&msg,
|
||||
_("Invalid HTTP response received from host\n"));
|
||||
_("Invalid HTTP response received from host"));
|
||||
else
|
||||
asprintf (&msg,
|
||||
_("Invalid HTTP response received from host on port %d\n"),
|
||||
_("Invalid HTTP response received from host on port %d"),
|
||||
server_port);
|
||||
die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg);
|
||||
np_die (STATE_CRITICAL, "%s", msg);
|
||||
}
|
||||
|
||||
/* Exit here if server_expect was set by user and not default */
|
||||
if ( server_expect_yn ) {
|
||||
asprintf (&msg,
|
||||
_("HTTP OK: Status line output matched \"%s\"\n"),
|
||||
_("Status line output matched \"%s\""),
|
||||
server_expect);
|
||||
if (verbose)
|
||||
printf ("%s\n",msg);
|
||||
np_verbatim (msg);
|
||||
}
|
||||
else {
|
||||
/* Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF */
|
||||
|
|
@ -933,40 +924,32 @@ check_http (void)
|
|||
|
||||
status_code = strchr (status_line, ' ') + sizeof (char);
|
||||
if (strspn (status_code, "1234567890") != 3)
|
||||
die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status Line (%s)\n"), status_line);
|
||||
np_die (STATE_CRITICAL, _("Invalid Status Line (%s)"), status_line);
|
||||
|
||||
http_status = atoi (status_code);
|
||||
|
||||
/* check the return code */
|
||||
|
||||
if (http_status >= 600 || http_status < 100)
|
||||
die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status (%s)\n"), status_line);
|
||||
np_die (STATE_CRITICAL, _("Invalid Status (%s)"), status_line);
|
||||
|
||||
/* server errors result in a critical state */
|
||||
else if (http_status >= 500)
|
||||
die (STATE_CRITICAL, _("HTTP CRITICAL: %s\n"), status_line);
|
||||
np_die (STATE_CRITICAL, _("%s"), status_line);
|
||||
|
||||
/* client errors result in a warning state */
|
||||
else if (http_status >= 400)
|
||||
die (STATE_WARNING, _("HTTP WARNING: %s\n"), status_line);
|
||||
np_die (STATE_WARNING, _("%s"), status_line);
|
||||
|
||||
/* check redirected page if specified */
|
||||
else if (http_status >= 300) {
|
||||
|
||||
if (onredirect == STATE_DEPENDENT)
|
||||
redir (header, status_line);
|
||||
else if (onredirect == STATE_UNKNOWN)
|
||||
printf (_("HTTP UNKNOWN"));
|
||||
else if (onredirect == STATE_OK)
|
||||
printf (_("HTTP OK"));
|
||||
else if (onredirect == STATE_WARNING)
|
||||
printf (_("HTTP WARNING"));
|
||||
else if (onredirect == STATE_CRITICAL)
|
||||
printf (_("HTTP CRITICAL"));
|
||||
microsec = deltime (tv);
|
||||
elapsed_time = (double)microsec / 1.0e6;
|
||||
die (onredirect,
|
||||
_(" - %s - %.3f second response time %s|%s %s\n"),
|
||||
np_die (onredirect,
|
||||
_("%s - %.3f second response time %s|%s %s"),
|
||||
status_line, elapsed_time,
|
||||
(display_html ? "</A>" : ""),
|
||||
perfd_time (elapsed_time), perfd_size (pagesize));
|
||||
|
|
@ -982,59 +965,50 @@ check_http (void)
|
|||
microsec = deltime (tv);
|
||||
elapsed_time = (double)microsec / 1.0e6;
|
||||
asprintf (&msg,
|
||||
_("HTTP WARNING: %s - %.3f second response time %s|%s %s\n"),
|
||||
_("%s - %.3f second response time %s|%s %s"),
|
||||
status_line, elapsed_time,
|
||||
(display_html ? "</A>" : ""),
|
||||
perfd_time (elapsed_time), perfd_size (pagesize));
|
||||
if (check_critical_time == TRUE && elapsed_time > critical_time)
|
||||
die (STATE_CRITICAL, "%s", msg);
|
||||
np_die (STATE_CRITICAL, "%s", msg);
|
||||
if (check_warning_time == TRUE && elapsed_time > warning_time)
|
||||
die (STATE_WARNING, "%s", msg);
|
||||
np_die (STATE_WARNING, "%s", msg);
|
||||
|
||||
/* Page and Header content checks go here */
|
||||
/* these checks should be last */
|
||||
|
||||
if (strlen (string_expect)) {
|
||||
if (strstr (page, string_expect)) {
|
||||
printf (_("HTTP OK %s - %.3f second response time %s|%s %s\n"),
|
||||
if (strstr (page, string_expect))
|
||||
np_die (STATE_OK, _("%s - %.3f second response time %s|%s %s"),
|
||||
status_line, elapsed_time,
|
||||
(display_html ? "</A>" : ""),
|
||||
perfd_time (elapsed_time), perfd_size (pagesize));
|
||||
exit (STATE_OK);
|
||||
}
|
||||
else {
|
||||
printf (_("HTTP CRITICAL - string not found%s|%s %s\n"),
|
||||
else
|
||||
np_die (STATE_CRITICAL, _("string not found%s|%s %s"),
|
||||
(display_html ? "</A>" : ""),
|
||||
perfd_time (elapsed_time), perfd_size (pagesize));
|
||||
exit (STATE_CRITICAL);
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen (regexp)) {
|
||||
errcode = regexec (&preg, page, REGS, pmatch, 0);
|
||||
if ((errcode == 0 && invert_regex == 0) || (errcode == REG_NOMATCH && invert_regex == 1)) {
|
||||
printf (_("HTTP OK %s - %.3f second response time %s|%s %s\n"),
|
||||
if ((errcode == 0 && invert_regex == 0) || (errcode == REG_NOMATCH && invert_regex == 1))
|
||||
np_die (STATE_OK, _("%s - %.3f second response time %s|%s %s"),
|
||||
status_line, elapsed_time,
|
||||
(display_html ? "</A>" : ""),
|
||||
perfd_time (elapsed_time), perfd_size (pagesize));
|
||||
exit (STATE_OK);
|
||||
}
|
||||
else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) {
|
||||
if (invert_regex == 0)
|
||||
msg = strdup(_("pattern not found"));
|
||||
else
|
||||
msg = strdup(_("pattern found"));
|
||||
printf (("%s - %s%s|%s %s\n"),
|
||||
_("HTTP CRITICAL"),
|
||||
np_die (STATE_CRITICAL, "%s%s|%s %s",
|
||||
msg,
|
||||
(display_html ? "</A>" : ""),
|
||||
perfd_time (elapsed_time), perfd_size (pagesize));
|
||||
exit (STATE_CRITICAL);
|
||||
}
|
||||
else {
|
||||
regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
|
||||
printf (_("HTTP CRITICAL - Execute Error: %s\n"), errbuf);
|
||||
exit (STATE_CRITICAL);
|
||||
np_die (STATE_CRITICAL, _("Execute Error: %s"), errbuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1042,20 +1016,18 @@ check_http (void)
|
|||
/* page_len = get_content_length(header); */
|
||||
page_len = pagesize;
|
||||
if ((max_page_len > 0) && (page_len > max_page_len)) {
|
||||
printf (_("HTTP WARNING: page size %d too large%s|%s\n"),
|
||||
np_die (STATE_WARNING, _("page size %d too large%s|%s"),
|
||||
page_len, (display_html ? "</A>" : ""), perfd_size (page_len) );
|
||||
exit (STATE_WARNING);
|
||||
} else if ((min_page_len > 0) && (page_len < min_page_len)) {
|
||||
printf (_("HTTP WARNING: page size %d too small%s|%s\n"),
|
||||
np_die (STATE_WARNING, _("page size %d too small%s|%s"),
|
||||
page_len, (display_html ? "</A>" : ""), perfd_size (page_len) );
|
||||
exit (STATE_WARNING);
|
||||
}
|
||||
/* We only get here if all tests have been passed */
|
||||
asprintf (&msg, _("HTTP OK %s - %d bytes in %.3f seconds %s|%s %s\n"),
|
||||
asprintf (&msg, _("%s - %d bytes in %.3f seconds %s|%s %s"),
|
||||
status_line, page_len, elapsed_time,
|
||||
(display_html ? "</A>" : ""),
|
||||
perfd_time (elapsed_time), perfd_size (page_len));
|
||||
die (STATE_OK, "%s", msg);
|
||||
np_die (STATE_OK, "%s", msg);
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
|
|
@ -1085,11 +1057,11 @@ redir (char *pos, char *status_line)
|
|||
|
||||
addr = malloc (MAX_IPV4_HOSTLENGTH + 1);
|
||||
if (addr == NULL)
|
||||
die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate addr\n"));
|
||||
np_die (STATE_UNKNOWN, _("Could not allocate addr"));
|
||||
|
||||
url = malloc (strcspn (pos, "\r\n"));
|
||||
if (url == NULL)
|
||||
die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate url\n"));
|
||||
np_die (STATE_UNKNOWN, _("Could not allocate url"));
|
||||
|
||||
while (pos) {
|
||||
sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i);
|
||||
|
|
@ -1097,8 +1069,8 @@ redir (char *pos, char *status_line)
|
|||
pos += (size_t) strcspn (pos, "\r\n");
|
||||
pos += (size_t) strspn (pos, "\r\n");
|
||||
if (strlen(pos) == 0)
|
||||
die (STATE_UNKNOWN,
|
||||
_("HTTP UNKNOWN - Could not find redirect location - %s%s\n"),
|
||||
np_die (STATE_UNKNOWN,
|
||||
_("Could not find redirect location - %s%s"),
|
||||
status_line, (display_html ? "</A>" : ""));
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1113,14 +1085,14 @@ redir (char *pos, char *status_line)
|
|||
for (; (i = strspn (pos, "\r\n")); pos += i) {
|
||||
pos += i;
|
||||
if (!(i = strspn (pos, " \t"))) {
|
||||
die (STATE_UNKNOWN, _("HTTP UNKNOWN - Empty redirect location%s\n"),
|
||||
np_die (STATE_UNKNOWN, _("Empty redirect location%s"),
|
||||
display_html ? "</A>" : "");
|
||||
}
|
||||
}
|
||||
|
||||
url = realloc (url, strcspn (pos, "\r\n") + 1);
|
||||
if (url == NULL)
|
||||
die (STATE_UNKNOWN, _("HTTP UNKNOWN - could not allocate url\n"));
|
||||
np_die (STATE_UNKNOWN, _("could not allocate url"));
|
||||
|
||||
/* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */
|
||||
if (sscanf (pos, HD1, type, addr, &i, url) == 4)
|
||||
|
|
@ -1159,8 +1131,8 @@ redir (char *pos, char *status_line)
|
|||
}
|
||||
|
||||
else {
|
||||
die (STATE_UNKNOWN,
|
||||
_("HTTP UNKNOWN - Could not parse redirect location - %s%s\n"),
|
||||
np_die (STATE_UNKNOWN,
|
||||
_("Could not parse redirect location - %s%s"),
|
||||
pos, (display_html ? "</A>" : ""));
|
||||
}
|
||||
|
||||
|
|
@ -1169,16 +1141,16 @@ redir (char *pos, char *status_line)
|
|||
} /* end while (pos) */
|
||||
|
||||
if (++redir_depth > max_depth)
|
||||
die (STATE_WARNING,
|
||||
_("HTTP WARNING - maximum redirection depth %d exceeded - %s://%s:%d%s%s\n"),
|
||||
np_die (STATE_WARNING,
|
||||
_("maximum redirection depth %d exceeded - %s://%s:%d%s%s"),
|
||||
max_depth, type, addr, i, url, (display_html ? "</A>" : ""));
|
||||
|
||||
if (server_port==i &&
|
||||
!strcmp(server_address, addr) &&
|
||||
(host_name && !strcmp(host_name, addr)) &&
|
||||
!strcmp(server_url, url))
|
||||
die (STATE_WARNING,
|
||||
_("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"),
|
||||
np_die (STATE_WARNING,
|
||||
_("redirection creates an infinite loop - %s://%s:%d%s%s"),
|
||||
type, addr, i, url, (display_html ? "</A>" : ""));
|
||||
|
||||
strcpy (server_type, type);
|
||||
|
|
@ -1193,18 +1165,17 @@ redir (char *pos, char *status_line)
|
|||
if ((url[0] == '/'))
|
||||
server_url = strdup (url);
|
||||
else if (asprintf(&server_url, "/%s", url) == -1)
|
||||
die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate server_url%s\n"),
|
||||
np_die (STATE_UNKNOWN, _("Could not allocate server_url%s"),
|
||||
display_html ? "</A>" : "");
|
||||
free(url);
|
||||
|
||||
if ((server_port = i) > MAX_PORT)
|
||||
die (STATE_UNKNOWN,
|
||||
_("HTTP UNKNOWN - Redirection to port above %d - %s://%s:%d%s%s\n"),
|
||||
np_die (STATE_UNKNOWN,
|
||||
_("Redirection to port above %d - %s://%s:%d%s%s"),
|
||||
MAX_PORT, server_type, server_address, server_port, server_url,
|
||||
display_html ? "</A>" : "");
|
||||
|
||||
if (verbose)
|
||||
printf (_("Redirection to %s://%s:%d%s\n"), server_type, server_address,
|
||||
np_verbose (_("Redirection to %s://%s:%d%s"), server_type, server_address,
|
||||
server_port, server_url);
|
||||
|
||||
check_http ();
|
||||
|
|
|
|||
Loading…
Reference in a new issue