summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cbf702f)
raw | patch | inline | side by side (parent: cbf702f)
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Sun, 10 Aug 2003 06:53:22 +0000 (06:53 +0000) | ||
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Sun, 10 Aug 2003 06:53:22 +0000 (06:53 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@676 f882894a-f735-0410-b71e-b25c423dba1c
34 files changed:
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 59e8ea0ca42e8491ff8fa224fa27b53800de3c08..b0aa1897821ebfcf1e5e706eed80b505b2a7297c 100644 (file)
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
int c;
char *p1, *p2;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
{"verbose", no_argument, 0, 'v'},
strcpy (argv[c], "-t");
while (1) {
- c = getopt_long (argc, argv, "Vvh1246ft:H:O:p:i:u:l:C:n:s:", long_options,
- &option_index);
+ c = getopt_long (argc, argv, "Vvh1246ft:H:O:p:i:u:l:C:n:s:", longopts,
+ &option);
if (c == -1 || c == EOF)
break;
diff --git a/plugins/check_dig.c b/plugins/check_dig.c
index ff16059158cdcf4dbd41766a0c820fefb07d9a10..f376e309268a0494629b96b43b9d7b20fa59889e 100644 (file)
--- a/plugins/check_dig.c
+++ b/plugins/check_dig.c
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"hostname", required_argument, 0, 'H'},
{"query_address", required_argument, 0, 'e'},
{"verbose", no_argument, 0, 'v'},
return ERROR;
while (1) {
- c = getopt_long (argc, argv, "hVvt:l:H:", long_options, &option_index);
+ c = getopt_long (argc, argv, "hVvt:l:H:", longopts, &option);
if (c == -1 || c == EOF)
break;
printf (_(UT_VERBOSE));
- support ();
+ printf (_(UT_SUPPORT));
}
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 7974d1415dd2e26ddb792315a3170f6ffaf12439..c8cfecd2a4a2cfa73ac46238c9f77b0a597d328c 100644 (file)
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
unsigned long l;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"timeout", required_argument, 0, 't'},
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
strcpy (argv[c], "-t");
while (1) {
- c = getopt_long (argc, argv, "+?VqhveCt:c:w:u:p:x:X:mklM", long_options, &option_index);
+ c = getopt_long (argc, argv, "+?VqhveCt:c:w:u:p:x:X:mklM", longopts, &option);
if (c == -1 || c == EOF)
break;
break;
case 'p': /* select path */
se = (struct name_list *) malloc (sizeof (struct name_list));
- se->name = strdup (optarg);
+ se->name = optarg;
se->name_next = NULL;
se->w_df = w_df;
se->c_df = c_df;
break;
case 'x': /* exclude path or partition */
se = (struct name_list *) malloc (sizeof (struct name_list));
- se->name = strdup (optarg);
+ se->name = optarg;
se->name_next = NULL;
*dptail = se;
dptail = &se->name_next;
break;
case 'X': /* exclude file system type */
se = (struct name_list *) malloc (sizeof (struct name_list));
- se->name = strdup (optarg);
+ se->name = optarg;
se->name_next = NULL;
*fstail = se;
fstail = &se->name_next;
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 8b3bb4f6addfd21b4edadba0432bd8d0ff084dfd..afc23a4f1b8fe3a74ee99cbc18506a06cc32a267 100644 (file)
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
const char *copyright = "2000-2003";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
-void
-print_usage (void)
-{
- printf (_("\
-Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n\
- %s --help\n\
- %s --version\n"),
- progname, progname, progname);
-}
-
-void
-print_help (void)
-{
- print_revision (progname, revision);
-
- printf (_(COPYRIGHT), copyright, email);
-
- print_usage ();
-
- printf (_(UT_HELP_VRSN));
-
- printf (_("\
--H, --hostname=HOST\n\
- The name or address you want to query\n\
--s, --server=HOST\n\
- Optional DNS server you want to use for the lookup\n\
--a, --expected-address=IP-ADDRESS\n\
- Optional IP address you expect the DNS server to return\n"));
-
- printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
-
- printf (_("\n\
-This plugin uses the nslookup program to obtain the IP address\n\
-for the given host/domain query. A optional DNS server to use may\n\
-be specified. If no DNS server is specified, the default server(s)\n\
-specified in /etc/resolv.conf will be used.\n"));
-}
-
int process_arguments (int, char **);
int validate_arguments (void);
int error_scan (char *);
+void print_help (void);
+void print_usage (void);
#define ADDRESS_LENGTH 256
char query_address[ADDRESS_LENGTH] = "";
else
return OK;
}
+
+
+
+
+
+\f
+void
+print_help (void)
+{
+ print_revision (progname, revision);
+
+ printf (_(COPYRIGHT), copyright, email);
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_("\
+-H, --hostname=HOST\n\
+ The name or address you want to query\n\
+-s, --server=HOST\n\
+ Optional DNS server you want to use for the lookup\n\
+-a, --expected-address=IP-ADDRESS\n\
+ Optional IP address you expect the DNS server to return\n"));
+
+ printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+
+ printf (_("\n\
+This plugin uses the nslookup program to obtain the IP address\n\
+for the given host/domain query. A optional DNS server to use may\n\
+be specified. If no DNS server is specified, the default server(s)\n\
+specified in /etc/resolv.conf will be used.\n"));
+
+ printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+ printf (_("\
+Usage: %s -H host [-s server] [-a expected-address] [-t timeout]\n\
+ %s --help\n\
+ %s --version\n"),
+ progname, progname, progname);
+}
diff --git a/plugins/check_fping.c b/plugins/check_fping.c
index 7e4049c8189c8d9e313fdec49598e83cebeaaf06..bb178305319e855dce9f46f67b2b888928454fff 100644 (file)
--- a/plugins/check_fping.c
+++ b/plugins/check_fping.c
#include "common.h"
#include "popen.h"
+#include "netutils.h"
#include "utils.h"
#define PACKET_COUNT 1
#define PL 0
#define RTA 1
-void
-print_usage (void)
-{
- printf (_("Usage: %s <host_address>\n"), progname);
-}
-
-void
-print_help (void)
-{
-
- print_revision (progname, "$Revision$");
-
- printf (_("\
-Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n\n\
-This plugin will use the /bin/fping command (from saint) to ping the\n\
-specified host for a fast check if the host is alive. Note that it is\n\
-necessary to set the suid flag on fping.\n\n"));
-
- print_usage ();
-
- printf (_(UT_HELP_VRSN));
-
- printf (_("\
- -H, --hostname=HOST\n\
- Name or IP Address of host to ping (IP Address bypasses name lookup,\n\
- reducing system load)\n\
- -w, --warning=THRESHOLD\n\
- warning threshold pair\n\
- -c, --critical=THRESHOLD\n\
- critical threshold pair\n\
- -b, --bytes=INTEGER\n\
- Size of ICMP packet (default: %d)\n\
- -n, --number=INTEGER\n\
- Number of ICMP packets to send (default: %d)\n"),
- PACKET_SIZE, PACKET_COUNT);
-
- printf (_(UT_VERBOSE));
-
- printf (_("\n\
-THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel\n\
-time (ms) which triggers a WARNING or CRITICAL state, and <pl> is the\n\
-percentage of packet loss to trigger an alarm state.\n"));
-
-}
-\f
int textscan (char *buf);
int process_arguments (int, char **);
int get_threshold (char *arg, char *rv[2]);
+void print_help (void);
+void print_usage (void);
char *server_name = NULL;
int cpl = UNKNOWN_PACKET_LOSS;
rta = strtod (rtastr, NULL);
if (cpl != UNKNOWN_PACKET_LOSS && loss > cpl)
status = STATE_CRITICAL;
- else if (crta != UNKNOWN_TRIP_TIME && rta > crta)
+ else if (crta <= 0 && rta > crta)
status = STATE_CRITICAL;
else if (wpl != UNKNOWN_PACKET_LOSS && loss > wpl)
status = STATE_WARNING;
- else if (wrta != UNKNOWN_TRIP_TIME && rta > wrta)
+ else if (wrta >= 0 && rta > wrta)
status = STATE_WARNING;
else
status = STATE_OK;
losstr = 1 + strstr (losstr, "/");
losstr = 1 + strstr (losstr, "/");
loss = strtod (losstr, NULL);
- if (loss == 100)
+ if (atoi(losstr) == 100)
status = STATE_CRITICAL;
else if (cpl != UNKNOWN_PACKET_LOSS && loss > cpl)
status = STATE_CRITICAL;
int c;
char *rv[2];
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"hostname", required_argument, 0, 'H'},
{"critical", required_argument, 0, 'c'},
{"warning", required_argument, 0, 'w'},
}
while (1) {
- c = getopt_long (argc, argv, "+hVvH:c:w:b:n:", long_options, &option_index);
+ c = getopt_long (argc, argv, "+hVvH:c:w:b:n:", longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
return OK;
}
+
+
+
+
+
+\f
+void
+print_help (void)
+{
+
+ print_revision (progname, "$Revision$");
+
+ printf (_("\
+Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n\n\
+This plugin will use the /bin/fping command (from saint) to ping the\n\
+specified host for a fast check if the host is alive. Note that it is\n\
+necessary to set the suid flag on fping.\n\n"));
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_("\
+ -H, --hostname=HOST\n\
+ Name or IP Address of host to ping (IP Address bypasses name lookup,\n\
+ reducing system load)\n\
+ -w, --warning=THRESHOLD\n\
+ warning threshold pair\n\
+ -c, --critical=THRESHOLD\n\
+ critical threshold pair\n\
+ -b, --bytes=INTEGER\n\
+ Size of ICMP packet (default: %d)\n\
+ -n, --number=INTEGER\n\
+ Number of ICMP packets to send (default: %d)\n"),
+ PACKET_SIZE, PACKET_COUNT);
+
+ printf (_(UT_VERBOSE));
+
+ printf (_("\n\
+THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel\n\
+time (ms) which triggers a WARNING or CRITICAL state, and <pl> is the\n\
+percentage of packet loss to trigger an alarm state.\n"));
+
+ printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+ printf (_("Usage: %s <host_address>\n"), progname);
+ printf (_(UT_HLP_VRS), progname, progname);
+}
diff --git a/plugins/check_game.c b/plugins/check_game.c
index 2b10991505794c7e88fe0cf94851c481547cb6bb..d5de13dbaa96828dc3dbc76b2737611ddbbed4d4 100644 (file)
--- a/plugins/check_game.c
+++ b/plugins/check_game.c
#include "popen.h"
#include "utils.h"
-void
-print_usage (void)
-{
- printf (_("\
-Usage: %s <game> <ip_address> [-p port] [-gf game_field] [-mf map_field]\n\
- [-pf ping_field]\n"), progname);
- printf (_(UT_HLP_VRS), progname, progname);
-}
-
-void
-print_help (void)
-{
- print_revision (progname, revision);
-
- printf (_(COPYRIGHT), copyright, email);
-
- printf (_("This plugin tests %s connections with the specified host."), progname);
-
- print_usage ();
-
- printf (_(UT_HELP_VRSN));
-
- printf (_("\
-<game> = Game type that is recognised by qstat (without the leading dash)\n\
-<ip_address> = The IP address of the device you wish to query\n\
- [port] = Optional port of which to connect\n\
- [game_field] = Field number in raw qstat output that contains game name\n\
- [map_field] = Field number in raw qstat output that contains map name\n\
- [ping_field] = Field number in raw qstat output that contains ping time\n"),
- DEFAULT_SOCKET_TIMEOUT);
-
- printf (_("\n\
-Notes:\n\
-- This plugin uses the 'qstat' command, the popular game server status query tool .\n\
- If you don't have the package installed, you will need to download it from\n\
- http://www.activesw.com/people/steve/qstat.html before you can use this plugin.\n"));
-
- printf (_(UT_SUPPORT));
-}
-\f
int process_arguments (int, char **);
int validate_arguments (void);
+void print_help (void);
+void print_usage (void);
#define QSTAT_DATA_DELIMITER ","
/* initialize the returned data buffer */
for (i = 0; i < QSTAT_MAX_RETURN_ARGS; i++)
- ret[i] = "";
+ ret[i] = strdup("");
i = 0;
p = (char *) strtok (input_buffer, QSTAT_DATA_DELIMITER);
case 'H': /* hostname */
if (strlen (optarg) >= MAX_HOST_ADDRESS_LENGTH)
die (STATE_UNKNOWN, _("Input buffer overflow\n"));
- server_ip = strdup (optarg);
+ server_ip = optarg;
break;
case 'P': /* port */
port = atoi (optarg);
case 'G': /* hostname */
if (strlen (optarg) >= MAX_INPUT_BUFFER)
die (STATE_UNKNOWN, _("Input buffer overflow\n"));
- game_type = strdup (optarg);
+ game_type = optarg;
break;
case 'p': /* index of ping field */
qstat_ping_field = atoi (optarg);
{
return OK;
}
+
+
+
+
+
+\f
+void
+print_help (void)
+{
+ print_revision (progname, revision);
+
+ printf (_(COPYRIGHT), copyright, email);
+
+ printf (_("This plugin tests %s connections with the specified host."), progname);
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_("\
+<game> = Game type that is recognised by qstat (without the leading dash)\n\
+<ip_address> = The IP address of the device you wish to query\n\
+ [port] = Optional port of which to connect\n\
+ [game_field] = Field number in raw qstat output that contains game name\n\
+ [map_field] = Field number in raw qstat output that contains map name\n\
+ [ping_field] = Field number in raw qstat output that contains ping time\n"));
+
+ printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+
+ printf (_("\n\
+Notes:\n\
+- This plugin uses the 'qstat' command, the popular game server status query tool .\n\
+ If you don't have the package installed, you will need to download it from\n\
+ http://www.activesw.com/people/steve/qstat.html before you can use this plugin.\n"));
+
+ printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+ printf (_("\
+Usage: %s <game> <ip_address> [-p port] [-gf game_field] [-mf map_field]\n\
+ [-pf ping_field]\n"), progname);
+ printf (_(UT_HLP_VRS), progname, progname);
+}
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c
index cb93a36e7eeff10daf13136fc44c82957c56d001..edde341e9e3dce5d4a9102a027a33034c359bda8 100644 (file)
--- a/plugins/check_hpjd.c
+++ b/plugins/check_hpjd.c
const char *email = "nagiosplug-devel@lists.sourceforge.net";
const char *option_summary = "-H host [-C community]\n";
-void
-print_usage (void)
-{
- printf (_("\
-Usage: %s -H host [-C community]\n"), progname);
- printf (_(UT_HLP_VRS), progname, progname);
-}
-void
-print_help (void)
-{
- print_revision (progname, revision);
-
- printf (_(COPYRIGHT), copyright, email);
-
- printf (_("\
-This plugin tests the STATUS of an HP printer with a JetDirect card.\n\
-Net-snmp must be installed on the computer running the plugin.\n\n"));
-
- print_usage ();
-
- printf (_(UT_HELP_VRSN));
-
- printf (_("\
- -C, --community=STRING\n\
- The SNMP community name (default=%s)\n"), DEFAULT_COMMUNITY);
-
- printf (_(UT_SUPPORT));
-}
-\f
#define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1"
#define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2"
#define HPJD_INTERVENTION_REQUIRED ".1.3.6.1.4.1.11.2.3.9.1.1.2.3"
int process_arguments (int, char **);
int validate_arguments (void);
+void print_help (void);
+void print_usage (void);
-char *community = DEFAULT_COMMUNITY;
+char *community = NULL;
char *address = NULL;
int
int line;
char input_buffer[MAX_INPUT_BUFFER];
char query_string[512];
- char error_message[MAX_INPUT_BUFFER];
+ char *errmsg;
char *temp_buffer;
int line_status = ONLINE;
int paper_status = 0;
int door_open = 0;
int paper_output = 0;
char display_message[MAX_INPUT_BUFFER];
- char *temp ;
+
+ errmsg = malloc(MAX_INPUT_BUFFER);
if (process_arguments (argc, argv) != OK)
usage (_("Invalid command arguments supplied\n"));
temp_buffer = strtok (input_buffer, "=");
temp_buffer = strtok (NULL, "=");
- switch (line) {
+ if (temp_buffer != NULL) {
- case 1: /* 1st line should contain the line status */
- if (temp_buffer != NULL)
- line_status = atoi (temp_buffer);
- else {
result = STATE_UNKNOWN;
- strcpy (error_message, input_buffer);
- }
- break;
+ strcpy (errmsg, input_buffer);
- case 2: /* 2nd line should contain the paper status */
- if (temp_buffer != NULL)
- paper_status = atoi (temp_buffer);
- else {
- result = STATE_UNKNOWN;
- strcpy (error_message, input_buffer);
- }
- break;
+ } else {
- case 3: /* 3rd line should be intervention required */
- if (temp_buffer != NULL)
- intervention_required = atoi (temp_buffer);
- else {
- result = STATE_UNKNOWN;
- strcpy (error_message, input_buffer);
- }
- break;
+ switch (line) {
- case 4: /* 4th line should be peripheral error */
- if (temp_buffer != NULL)
+ case 1: /* 1st line should contain the line status */
+ line_status = atoi (temp_buffer);
+ break;
+ case 2: /* 2nd line should contain the paper status */
+ paper_status = atoi (temp_buffer);
+ break;
+ case 3: /* 3rd line should be intervention required */
+ intervention_required = atoi (temp_buffer);
+ break;
+ case 4: /* 4th line should be peripheral error */
peripheral_error = atoi (temp_buffer);
- else {
- result = STATE_UNKNOWN;
- strcpy (error_message, input_buffer);
- }
- break;
-
- case 5: /* 5th line should contain the paper jam status */
- if (temp_buffer != NULL)
+ break;
+ case 5: /* 5th line should contain the paper jam status */
paper_jam = atoi (temp_buffer);
- else {
- result = STATE_UNKNOWN;
- strcpy (error_message, input_buffer);
- }
- break;
-
- case 6: /* 6th line should contain the paper out status */
- if (temp_buffer != NULL)
+ break;
+ case 6: /* 6th line should contain the paper out status */
paper_out = atoi (temp_buffer);
- else {
- result = STATE_UNKNOWN;
- strcpy (error_message, input_buffer);
- }
- break;
-
- case 7: /* 7th line should contain the toner low status */
- if (temp_buffer != NULL)
+ break;
+ case 7: /* 7th line should contain the toner low status */
toner_low = atoi (temp_buffer);
- else {
- result = STATE_UNKNOWN;
- strcpy (error_message, input_buffer);
- }
- break;
-
- case 8: /* did data come too slow for engine */
- if (temp_buffer != NULL)
+ break;
+ case 8: /* did data come too slow for engine */
page_punt = atoi (temp_buffer);
- else {
- result = STATE_UNKNOWN;
- strcpy (error_message, input_buffer);
- }
- break;
-
- case 9: /* did we run out of memory */
- if (temp_buffer != NULL)
+ break;
+ case 9: /* did we run out of memory */
memory_out = atoi (temp_buffer);
- else {
- result = STATE_UNKNOWN;
- strcpy (error_message, input_buffer);
- }
- break;
-
- case 10: /* is there a door open */
- if (temp_buffer != NULL)
+ break;
+ case 10: /* is there a door open */
door_open = atoi (temp_buffer);
- else {
- result = STATE_UNKNOWN;
- strcpy (error_message, input_buffer);
- }
- break;
-
- case 11: /* is output tray full */
- if (temp_buffer != NULL)
+ break;
+ case 11: /* is output tray full */
paper_output = atoi (temp_buffer);
- else {
- result = STATE_UNKNOWN;
- strcpy (error_message, input_buffer);
- }
- break;
-
- case 12: /* display panel message */
- if (temp_buffer != NULL)
+ break;
+ case 12: /* display panel message */
strcpy (display_message, temp_buffer + 1);
- else {
- result = STATE_UNKNOWN;
- strcpy (error_message, input_buffer);
+ break;
+ default:
+ break;
}
- break;
- default:
- break;
}
/* break out of the read loop if we encounter an error */
/* remove CRLF */
if (input_buffer[strlen (input_buffer) - 1] == '\n')
input_buffer[strlen (input_buffer) - 1] = 0;
- sprintf (error_message, "%s", input_buffer );
+ sprintf (errmsg, "%s", input_buffer );
}
/* might not be the problem, but most likely is. */
result = STATE_UNKNOWN ;
- asprintf (&temp, error_message);
- sprintf (error_message, "%s : Timeout from host %s\n", temp, address );
+ asprintf (&errmsg, "%s : Timeout from host %s\n", errmsg, address );
}
if (paper_jam) {
result = STATE_WARNING;
- strcpy (error_message, _("Paper Jam"));
+ strcpy (errmsg, _("Paper Jam"));
}
else if (paper_out) {
result = STATE_WARNING;
- strcpy (error_message, _("Out of Paper"));
+ strcpy (errmsg, _("Out of Paper"));
}
else if (line_status == OFFLINE) {
- if (strcmp (error_message, "POWERSAVE ON") != 0) {
+ if (strcmp (errmsg, "POWERSAVE ON") != 0) {
result = STATE_WARNING;
- strcpy (error_message, _("Printer Offline"));
+ strcpy (errmsg, _("Printer Offline"));
}
}
else if (peripheral_error) {
result = STATE_WARNING;
- strcpy (error_message, _("Peripheral Error"));
+ strcpy (errmsg, _("Peripheral Error"));
}
else if (intervention_required) {
result = STATE_WARNING;
- strcpy (error_message, _("Intervention Required"));
+ strcpy (errmsg, _("Intervention Required"));
}
else if (toner_low) {
result = STATE_WARNING;
- strcpy (error_message, _("Toner Low"));
+ strcpy (errmsg, _("Toner Low"));
}
else if (memory_out) {
result = STATE_WARNING;
- strcpy (error_message, _("Insufficient Memory"));
+ strcpy (errmsg, _("Insufficient Memory"));
}
else if (door_open) {
result = STATE_WARNING;
- strcpy (error_message, _("A Door is Open"));
+ strcpy (errmsg, _("A Door is Open"));
}
else if (paper_output) {
result = STATE_WARNING;
- strcpy (error_message, _("Output Tray is Full"));
+ strcpy (errmsg, _("Output Tray is Full"));
}
else if (page_punt) {
result = STATE_WARNING;
- strcpy (error_message, _("Data too Slow for Engine"));
+ strcpy (errmsg, _("Data too Slow for Engine"));
}
else if (paper_status) {
result = STATE_WARNING;
- strcpy (error_message, _("Unknown Paper Error"));
+ strcpy (errmsg, _("Unknown Paper Error"));
}
}
else if (result == STATE_UNKNOWN) {
- printf ("%s\n", error_message);
+ printf ("%s\n", errmsg);
/* if printer could not be reached, escalate to critical */
- if (strstr (error_message, "Timeout"))
+ if (strstr (errmsg, "Timeout"))
result = STATE_CRITICAL;
}
else if (result == STATE_WARNING)
- printf ("%s (%s)\n", error_message, display_message);
+ printf ("%s (%s)\n", errmsg, display_message);
return result;
}
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"hostname", required_argument, 0, 'H'},
{"community", required_argument, 0, 'C'},
/* {"critical", required_argument,0,'c'}, */
while (1) {
- c = getopt_long (argc, argv, "+hVH:C:", long_options, &option_index);
+ c = getopt_long (argc, argv, "+hVH:C:", longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
}
}
- if (argv[c] != NULL ) {
- community = argv[c];
+ if (community == NULL) {
+ if (argv[c] != NULL )
+ community = argv[c];
+ else
+ community = strdup (DEFAULT_COMMUNITY);
}
return validate_arguments ();
{
return OK;
}
+
+
+
+
+
+\f
+void
+print_help (void)
+{
+ print_revision (progname, revision);
+
+ printf (_(COPYRIGHT), copyright, email);
+
+ printf (_("\
+This plugin tests the STATUS of an HP printer with a JetDirect card.\n\
+Net-snmp must be installed on the computer running the plugin.\n\n"));
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_("\
+ -C, --community=STRING\n\
+ The SNMP community name (default=%s)\n"), DEFAULT_COMMUNITY);
+
+ printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+ printf (_("\
+Usage: %s -H host [-C community]\n"), progname);
+ printf (_(UT_HLP_VRS), progname, progname);
+}
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 3321d5ac88ff715a5704d4b4e3fea12007b8f4f1..27127d6af63e8bafd7097a9b146a39251555aa1b 100644 (file)
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
{
int c = 1;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
STD_LONG_OPTS,
{"file",required_argument,0,'F'},
{"link", no_argument, 0, 'L'},
}
while (1) {
- c = getopt_long (argc, argv, "Vvh46t:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nlLSm:", long_options, &option_index);
+ c = getopt_long (argc, argv, "Vvh46t:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nlLSm:", longopts, &option);
if (c == -1 || c == EOF)
break;
break;
/* Note: H, I, and u must be malloc'd or will fail on redirects */
case 'H': /* Host Name (virtual host) */
- host_name = strdup (optarg);
+ host_name = optarg;
break;
case 'I': /* Server IP-address */
- server_address = strdup(optarg);
+ server_address = optarg;
break;
case 'u': /* URL path */
asprintf (&server_url, "%s", optarg);
case 'P': /* HTTP POST data in URL encoded format */
if (http_method || http_post_data) break;
http_method = strdup("POST");
- http_post_data = strdup(optarg);
+ http_post_data = optarg;
break;
case 's': /* string or substring */
strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1);
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c
index 2064dd3b3f5bfde6216d5cb7443ffef8e6c51ec0..d2c6ae22b7662d1b3731fc0e7a7e9cd7de8572de 100644 (file)
--- a/plugins/check_ldap.c
+++ b/plugins/check_ldap.c
DEFAULT_PORT = 389
};
-void
-print_usage ()
-{
- printf (_("\
-Usage: %s -H <host> -b <base_dn> [-p <port>] [-a <attr>] [-D <binddn>]\n\
- [-P <password>] [-w <warn_time>] [-c <crit_time>] [-t timeout]%s\n\
-(Note: all times are in seconds.)\n"),
- progname, (HAVE_LDAP_SET_OPTION ? "[-2|-3] [-4|-6]" : ""));
- printf (_(UT_HLP_VRS), progname, progname);
-}
-
-void
-print_help ()
-{
- char *myport;
- asprintf (&myport, "%d", DEFAULT_PORT);
-
- print_revision (progname, revision);
-
- printf (_("Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n"));
- printf (_(COPYRIGHT), copyright, email);
-
- print_usage ();
-
- printf (_(UT_HELP_VRSN));
-
- printf (_(UT_HOST_PORT), 'p', myport);
-
- printf (_(UT_IPv46));
-
- printf (_("\
- -a [--attr]\n\
- ldap attribute to search (default: \"(objectclass=*)\"\n\
- -b [--base]\n\
- ldap base (eg. ou=my unit, o=my org, c=at)\n\
- -D [--bind]\n\
- ldap bind DN (if required)\n\
- -P [--pass]\n\
- ldap password (if required)\n"));
-
-#ifdef HAVE_LDAP_SET_OPTION
- printf (_("\
- -2 [--ver2]\n\
- use ldap protocol version 2\n\
- -3 [--ver3]\n\
- use ldap protocol version 3\n\
- (default protocol version: %d)\n"),
- DEFAULT_PROTOCOL);
-#endif
-
- printf (_(UT_WARN_CRIT));
-
- printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
-
- printf (_(UT_VERBOSE));
-
- printf (_(UT_SUPPORT));
-}
-\f
int process_arguments (int, char **);
int validate_arguments (void);
+void print_help (void);
+void print_usage (void);
char ld_defattr[] = "(objectclass=*)";
char *ld_attr = ld_defattr;
-char *ld_host = "";
-char *ld_base = "";
+char *ld_host = NULL;
+char *ld_base = NULL;
char *ld_passwd = NULL;
char *ld_binddn = NULL;
-unsigned int ld_port = DEFAULT_PORT;
+int ld_port = DEFAULT_PORT;
#ifdef HAVE_LDAP_SET_OPTION
int ld_protocol = DEFAULT_PROTOCOL;
#endif
{
int c;
- int option_index = 0;
+ int option = 0;
/* initialize the long option struct */
static struct option longopts[] = {
{"help", no_argument, 0, 'h'},
}
while (1) {
- c = getopt_long (argc, argv, "hV2346t:c:w:H:b:p:a:D:P:", longopts, &option_index);
+ c = getopt_long (argc, argv, "hV2346t:c:w:H:b:p:a:D:P:", longopts, &option);
if (c == -1 || c == EOF)
break;
case 't': /* timeout period */
if (!is_intnonneg (optarg))
usage2 (_("timeout interval must be a positive integer"), optarg);
- socket_timeout = atoi (optarg);
+ else
+ socket_timeout = atoi (optarg);
break;
case 'H':
ld_host = optarg;
}
c = optind;
- if (strlen(ld_host) == 0 && is_host(argv[c])) {
- asprintf (&ld_host, "%s", argv[c++]);
- }
- if (strlen(ld_base) == 0 && argv[c]) {
- asprintf (&ld_base, "%s", argv[c++]);
- }
+ if (ld_host == NULL && is_host(argv[c]))
+ ld_host = strdup (argv[c++]);
+
+ if (ld_base == NULL && argv[c])
+ ld_base = strdup (argv[c++]);
return validate_arguments ();
}
return OK;
}
+
+
+
+
+
+\f
+void
+print_help (void)
+{
+ char *myport;
+ asprintf (&myport, "%d", DEFAULT_PORT);
+
+ print_revision (progname, revision);
+
+ printf (_("Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n"));
+ printf (_(COPYRIGHT), copyright, email);
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_(UT_HOST_PORT), 'p', myport);
+
+ printf (_(UT_IPv46));
+
+ printf (_("\
+ -a [--attr]\n\
+ ldap attribute to search (default: \"(objectclass=*)\"\n\
+ -b [--base]\n\
+ ldap base (eg. ou=my unit, o=my org, c=at)\n\
+ -D [--bind]\n\
+ ldap bind DN (if required)\n\
+ -P [--pass]\n\
+ ldap password (if required)\n"));
+
+#ifdef HAVE_LDAP_SET_OPTION
+ printf (_("\
+ -2 [--ver2]\n\
+ use ldap protocol version 2\n\
+ -3 [--ver3]\n\
+ use ldap protocol version 3\n\
+ (default protocol version: %d)\n"),
+ DEFAULT_PROTOCOL);
+#endif
+
+ printf (_(UT_WARN_CRIT));
+
+ printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+
+ printf (_(UT_VERBOSE));
+
+ printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+ printf (_("\
+Usage: %s -H <host> -b <base_dn> [-p <port>] [-a <attr>] [-D <binddn>]\n\
+ [-P <password>] [-w <warn_time>] [-c <crit_time>] [-t timeout]%s\n\
+(Note: all times are in seconds.)\n"),
+ progname, (HAVE_LDAP_SET_OPTION ? "[-2|-3] [-4|-6]" : ""));
+ printf (_(UT_HLP_VRS), progname, progname);
+}
diff --git a/plugins/check_load.c b/plugins/check_load.c
index bdb1e55d18fae7cdf2af6f6f7fc0d39dab6010ae..c12cad37aa517754a159e5cd54d3e8cddb046dbc 100644 (file)
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
{
int c = 0;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
{"version", no_argument, 0, 'V'},
return ERROR;
while (1) {
- c = getopt_long (argc, argv, "Vhc:w:", long_options, &option_index);
+ c = getopt_long (argc, argv, "Vhc:w:", longopts, &option);
if (c == -1 || c == EOF)
break;
diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c
index 21efac2e901f32c22e64d49c96c3dd3eb3841a87..849e636fce964dd4c5e9e2c9c170176a1f88a195 100644 (file)
--- a/plugins/check_mrtg.c
+++ b/plugins/check_mrtg.c
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"logfile", required_argument, 0, 'F'},
{"expires", required_argument, 0, 'e'},
{"aggregation", required_argument, 0, 'a'},
}
while (1) {
- c = getopt_long (argc, argv, "hVF:e:a:v:c:w:l:u:", long_options,
- &option_index);
+ c = getopt_long (argc, argv, "hVF:e:a:v:c:w:l:u:", longopts,
+ &option);
if (c == -1 || c == EOF)
break;
index be2f562eab81dba4d679f312a893a1ce9e57eb9a..93b2c1d03fa569a9cb9fd6ed8257ae3a9dea74f3 100644 (file)
--- a/plugins/check_mrtgtraf.c
+++ b/plugins/check_mrtgtraf.c
{
int c;
- int option_index = 0;
+ int option = 0;
static struct option longopts[] = {
{"logfile", required_argument, 0, 'F'},
{"expires", required_argument, 0, 'e'},
}
while (1) {
- c = getopt_long (argc, argv, "hVF:e:a:c:w:", longopts, &option_index);
+ c = getopt_long (argc, argv, "hVF:e:a:c:w:", longopts, &option);
if (c == -1 || c == EOF)
break;
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 16a1f1335cf8f68f23575e21beebe5bbf679b357..a7afa52f12101809fc738463e936c258e03e211f 100644 (file)
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
#include <mysql/mysql.h>
#include <mysql/errmsg.h>
-void
-print_usage (void)
-{
- printf (_("\
-Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password]\n"),
- progname);
- printf (_(UT_HLP_VRS), progname, progname);
-}
-
-void
-print_help (void)
-{
- char *myport;
- asprintf (&myport, "%d", MYSQL_PORT);
-
- print_revision (progname, revision);
-
- printf (_(COPYRIGHT), copyright, email);
-
- printf (_("This program tests connections to a mysql server\n"));
-
- print_usage ();
-
- printf (_(UT_HELP_VRSN));
-
- printf (_(UT_HOST_PORT), 'P', myport);
-
- printf (_("\
- -d, --database=STRING\n\
- Check database with indicated name\n\
- -u, --username=STRING\n\
- Connect using the indicated username\n\
- -p, --password=STRING\n\
- Use the indicated password to authenticate the connection\n\
- ==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==\n\
- Your clear-text password will be visible as a process table entry\n"));
-
- printf (_("\n\
-There are no required arguments. By default, the local database with\n\
-a server listening on MySQL standard port %d will be checked\n"), MYSQL_PORT);
-
- printf (_(UT_SUPPORT));
-}
-\f
-char *db_user = "";
-char *db_host = "";
-char *db_pass = "";
-char *db = "";
+char *db_user = NULL;
+char *db_host = NULL;
+char *db_pass = NULL;
+char *db = NULL;
unsigned int db_port = MYSQL_PORT;
int process_arguments (int, char **);
int validate_arguments (void);
+void print_help (void);
+void print_usage (void);
int
main (int argc, char **argv)
{
MYSQL mysql;
- char result[1024];
+ char *result = NULL;
if (process_arguments (argc, argv) != OK)
usage (_("Invalid command arguments supplied\n"));
mysql_init (&mysql);
/* establish a connection to the server and error checking */
- if (!mysql_real_connect
- (&mysql, db_host, db_user, db_pass, db, db_port, NULL, 0)) {
-
- if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) {
- printf ("%s\n", mysql_error (&mysql));
- return STATE_WARNING;
-
- }
- else if (mysql_errno (&mysql) == CR_VERSION_ERROR) {
- printf ("%s\n", mysql_error (&mysql));
- return STATE_WARNING;
-
- }
- else if (mysql_errno (&mysql) == CR_OUT_OF_MEMORY) {
- printf ("%s\n", mysql_error (&mysql));
- return STATE_WARNING;
-
- }
- else if (mysql_errno (&mysql) == CR_IPSOCK_ERROR) {
- printf ("%s\n", mysql_error (&mysql));
- return STATE_WARNING;
-
- }
- else if (mysql_errno (&mysql) == CR_SOCKET_CREATE_ERROR) {
- printf ("%s\n", mysql_error (&mysql));
- return STATE_WARNING;
-
- }
- else {
- printf ("%s\n", mysql_error (&mysql));
- return STATE_CRITICAL;
- }
-
+ if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,NULL,0)) {
+ if (mysql_errno (&mysql) == CR_UNKNOWN_HOST)
+ die (STATE_WARNING, "%s\n", mysql_error (&mysql));
+ else if (mysql_errno (&mysql) == CR_VERSION_ERROR)
+ die (STATE_WARNING, "%s\n", mysql_error (&mysql));
+ else if (mysql_errno (&mysql) == CR_OUT_OF_MEMORY)
+ die (STATE_WARNING, "%s\n", mysql_error (&mysql));
+ else if (mysql_errno (&mysql) == CR_IPSOCK_ERROR)
+ die (STATE_WARNING, "%s\n", mysql_error (&mysql));
+ else if (mysql_errno (&mysql) == CR_SOCKET_CREATE_ERROR)
+ die (STATE_WARNING, "%s\n", mysql_error (&mysql));
+ else
+ die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
}
/* get the server stats */
- sprintf (result, mysql_stat (&mysql));
+ result = strdup (mysql_stat (&mysql));
/* error checking once more */
if (mysql_error (&mysql)) {
-
- if (mysql_errno (&mysql) == CR_SERVER_GONE_ERROR) {
- printf ("%s\n", mysql_error (&mysql));
- return STATE_CRITICAL;
-
- }
- else if (mysql_errno (&mysql) == CR_SERVER_LOST) {
- printf ("%s\n", mysql_error (&mysql));
- return STATE_CRITICAL;
-
- }
- else if (mysql_errno (&mysql) == CR_UNKNOWN_ERROR) {
- printf ("%s\n", mysql_error (&mysql));
- return STATE_UNKNOWN;
- }
-
+ if (mysql_errno (&mysql) == CR_SERVER_GONE_ERROR)
+ die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
+ else if (mysql_errno (&mysql) == CR_SERVER_LOST)
+ die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
+ else if (mysql_errno (&mysql) == CR_UNKNOWN_ERROR)
+ die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
}
/* close the connection */
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"hostname", required_argument, 0, 'H'},
{"database", required_argument, 0, 'd'},
{"username", required_argument, 0, 'u'},
return ERROR;
while (1) {
- c = getopt_long (argc, argv, "hVP:p:u:d:H:", long_options, &option_index);
+ c = getopt_long (argc, argv, "hVP:p:u:d:H:", longopts, &option);
if (c == -1 || c == EOF)
break;
int
validate_arguments (void)
{
+ if (db_user == NULL)
+ db_user = strdup("");
+
+ if (db_host == NULL)
+ db_host = strdup("");
+
+ if (db_pass == NULL)
+ db_pass == strdup("");
+
+ if (db == NULL)
+ db = strdup("");
+
return OK;
}
+
+
+
+
+
+\f
+void
+print_help (void)
+{
+ char *myport;
+ asprintf (&myport, "%d", MYSQL_PORT);
+
+ print_revision (progname, revision);
+
+ printf (_(COPYRIGHT), copyright, email);
+
+ printf (_("This program tests connections to a mysql server\n"));
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_(UT_HOST_PORT), 'P', myport);
+
+ printf (_("\
+ -d, --database=STRING\n\
+ Check database with indicated name\n\
+ -u, --username=STRING\n\
+ Connect using the indicated username\n\
+ -p, --password=STRING\n\
+ Use the indicated password to authenticate the connection\n\
+ ==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==\n\
+ Your clear-text password will be visible as a process table entry\n"));
+
+ printf (_("\n\
+There are no required arguments. By default, the local database with\n\
+a server listening on MySQL standard port %d will be checked\n"), MYSQL_PORT);
+
+ printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+ printf (_("\
+Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password]\n"),
+ progname);
+ printf (_(UT_HLP_VRS), progname, progname);
+}
diff --git a/plugins/check_nagios.c b/plugins/check_nagios.c
index a678e2a4e8f2d975e85cf7a70d8465c6aefe13b1..5b21ba1d93ce269042cf066cc4fd272de54ca95f 100644 (file)
--- a/plugins/check_nagios.c
+++ b/plugins/check_nagios.c
#include "popen.h"
#include "utils.h"
-void
-print_usage (void)
-{
- printf (_("\
-Usage: %s -F <status log file> -e <expire_minutes> -C <process_string>\n"),
- progname);
-}
-
-void
-print_help (void)
-{
- print_revision (progname, revision);
-
- printf (_(COPYRIGHT), copyright, email);
-
- printf (_("\
-This plugin attempts to check the status of the Nagios process on the local\n\
-machine. The plugin will check to make sure the Nagios status log is no older\n\
-than the number of minutes specified by the <expire_minutes> option. It also\n\
-uses the /bin/ps command to check for a process matching whatever you specify\n\
-by the <process_string> argument.\n"));
-
- print_usage ();
-
- printf (_(UT_HELP_VRSN));
-
- printf (_("\
--F, --filename=FILE\n\
- Name of the log file to check\n\
--e, --expires=INTEGER\n\
- Seconds aging afterwhich logfile is condsidered stale\n\
--C, --command=STRING\n\
- Command to search for in process table\n"));
-
- printf (_("\
-Example:\n\
- ./check_nagios -e 5 \\\
- -F /usr/local/nagios/var/status.log \\\
- -C /usr/local/nagios/bin/nagios\n"));
-}
-\f
int process_arguments (int, char **);
+void print_help (void);
+void print_usage (void);
char *status_log = NULL;
char *process_string = NULL;
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"filename", required_argument, 0, 'F'},
{"expires", required_argument, 0, 'e'},
{"command", required_argument, 0, 'C'},
}
while (1) {
- c = getopt_long (argc, argv, "+hVvF:C:e:", long_options, &option_index);
+ c = getopt_long (argc, argv, "+hVvF:C:e:", longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
expire_minutes = atoi (optarg);
else
die (STATE_UNKNOWN,
- _("Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n"),
- progname);
+ _("Expiration time must be an integer (seconds)\nType '%s -h' for additional help\n"),
+ progname);
break;
case 'v':
verbose++;
if (status_log == NULL)
die (STATE_UNKNOWN,
- _("You must provide the status_log\nType '%s -h' for additional help\n"),
- progname);
+ _("You must provide the status_log\nType '%s -h' for additional help\n"),
+ progname);
else if (process_string == NULL)
die (STATE_UNKNOWN,
_("You must provide a process string\nType '%s -h' for additional help\n"),
return OK;
}
+
+
+
+
+
+\f
+void
+print_help (void)
+{
+ print_revision (progname, revision);
+
+ printf (_(COPYRIGHT), copyright, email);
+
+ printf (_("\
+This plugin attempts to check the status of the Nagios process on the local\n\
+machine. The plugin will check to make sure the Nagios status log is no older\n\
+than the number of minutes specified by the <expire_minutes> option. It also\n\
+uses the /bin/ps command to check for a process matching whatever you specify\n\
+by the <process_string> argument.\n"));
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_("\
+-F, --filename=FILE\n\
+ Name of the log file to check\n\
+-e, --expires=INTEGER\n\
+ Seconds aging afterwhich logfile is condsidered stale\n\
+-C, --command=STRING\n\
+ Command to search for in process table\n"));
+
+ printf (_("\
+Example:\n\
+ ./check_nagios -e 5 \\\
+ -F /usr/local/nagios/var/status.log \\\
+ -C /usr/local/nagios/bin/nagios\n"));
+}
+
+
+
+
+void
+print_usage (void)
+{
+ printf (_("\
+Usage: %s -F <status log file> -e <expire_minutes> -C <process_string>\n"),
+ progname);
+}
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index b1314d4b66022fcd8a15d75d8a42eece1a827147..3b2bd5e1178db98725bfb8c29867db0b3733a60d 100644 (file)
--- a/plugins/check_nt.c
+++ b/plugins/check_nt.c
*
*****************************************************************************/
-#include "config.h"
#include "common.h"
#include "netutils.h"
#include "utils.h"
int process_arguments(int argc, char **argv){
int c;
- int option_index = 0;
- static struct option long_options[] =
+ int option = 0;
+ static struct option longopts[] =
{
{"port", required_argument,0,'p'},
{"timeout", required_argument,0,'t'},
}
while (1){
- c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:",long_options,&option_index);
+ c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:",longopts,&option);
if (c==-1||c==EOF||c==1)
break;
exit(STATE_OK);
case 'H': /* hostname */
if (server_address) free(server_address);
- server_address = strdup(optarg);
+ server_address = optarg;
break;
case 's': /* password */
- req_password = strdup (optarg);
+ req_password = optarg;
break;
case 'p': /* port */
if (is_intnonneg(optarg))
return ERROR;
break;
case 'l': /* value list */
- value_list = strdup (optarg);
+ value_list = optarg;
break;
case 'w': /* warning threshold */
warning_value=strtoul(optarg,NULL,10);
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c
index 4b2272699e3e2b26c3266106efc8801b8dc51520..92a1f117617c3cd7f0ae0c7e3d63eef30ba4f6c8 100644 (file)
--- a/plugins/check_nwstat.c
+++ b/plugins/check_nwstat.c
int process_arguments(int argc, char **argv) {
int c;
- int option_index = 0;
- static struct option long_options[] =
+ int option = 0;
+ static struct option longopts[] =
{
{"port", required_argument,0,'p'},
{"timeout", required_argument,0,'t'},
}
while (1) {
- c = getopt_long(argc,argv,"+hoVH:t:c:w:p:v:",long_options,&option_index);
+ c = getopt_long(argc,argv,"+hoVH:t:c:w:p:v:",longopts,&option);
if (c==-1||c==EOF||c==1)
break;
diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c
index 9958432e1c8edbc213b1f6877166a15d6bfc08ba..67fb5d1f7403a2348eefa410b6dd35ca841b09b5 100644 (file)
--- a/plugins/check_overcr.c
+++ b/plugins/check_overcr.c
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"port", required_argument, 0, 'p'},
{"timeout", required_argument, 0, 't'},
{"critical", required_argument, 0, 'c'},
}
while (1) {
- c = getopt_long (argc, argv, "+hVH:t:c:w:p:v:", long_options,
- &option_index);
+ c = getopt_long (argc, argv, "+hVH:t:c:w:p:v:", longopts,
+ &option);
if (c == -1 || c == EOF || c == 1)
break;
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c
index 2dce0b35d2ef533f254fec2f1f93ccc48b618a26..6cd217e09cc2a5e6931a62363db8656b962abf04 100644 (file)
--- a/plugins/check_pgsql.c
+++ b/plugins/check_pgsql.c
/******************************************************************************
- *
- * Program: PostgreSQL plugin for Nagios
- * License: GPL
- *
- * License Information:
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
- *
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
*****************************************************************************/
#define DEFAULT_DB "template1"
DEFAULT_CRIT = 8
};
-#include "config.h"
#include "common.h"
#include "utils.h"
+#include "netutils.h"
#include <libpq-fe.h>
int process_arguments (int, char **);
-void
-print_help (void)
-{
- char *myport;
-
- asprintf (&myport, "%d", DEFAULT_PORT);
-
- print_revision (progname, revision);
-
- printf (_(COPYRIGHT), copyright, email);
-
- printf (_("Test whether a PostgreSQL DBMS is accepting connections.\n\n"));
-
- print_usage ();
-
- printf (_(UT_HELP_VRSN));
-
- printf (_(UT_HOST_PORT), 'P', myport);
-
- printf (_(UT_IPv46));
-
- printf (S_("\
- -d, --database=STRING\n\
- Database to check (default: %s)\n\
- -l, --logname = STRING\n\
- Login name of user\n\
- -p, --password = STRING\n\
- Password (BIG SECURITY ISSUE)\n"), DEFAULT_DB);
-
- printf (_(UT_WARN_CRIT));
-
- printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
-
- printf (_(UT_VERBOSE));
-
- printf (S_("\nAll parameters are optional.\n\
-\n\
-This plugin tests a PostgreSQL DBMS to determine whether it is active and\n\
-accepting queries. In its current operation, it simply connects to the\n\
-specified database, and then disconnects. If no database is specified, it\n\
-connects to the template1 database, which is present in every functioning \n\
-PostgreSQL DBMS.\n"));
- printf (S_("\n\
-The plugin will connect to a local postmaster if no host is specified. To\n\
-connect to a remote host, be sure that the remote postmaster accepts TCP/IP\n\
-connections (start the postmaster with the -i option).\n"));
- printf (S_("\n\
-Typically, the nagios user (unless the --logname option is used) should be\n\
-able to connect to the database without a password. The plugin can also send\n\
-a password, but no effort is made to obsure or encrypt the password.\n"));
-
- support ();
-}
-
-void
-print_usage (void)
-{
- printf (S_("\
-Usage:\n %s [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]\n\
- [-t <timeout>]"), progname);
- printf (S_("[-d <database>] [-l <logname>] [-p <password>]\n"));
- printf (S_("\
- %s (-h | --help) for detailed help\n\
- %s (-V | --version) for version information\n"),
- progname, progname);
-}
int
main (int argc, char **argv)
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"timeout", required_argument, 0, 't'},
while (1) {
c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:",
- long_options, &option_index);
+ longopts, &option);
if (c == EOF)
break;
switch (c) {
case '?': /* usage */
usage3 (_("Unknown argument"), optopt);
+ break;
case 'h': /* help */
print_help ();
exit (STATE_OK);
case 't': /* timeout period */
if (!is_integer (optarg))
usage2 (_("Timeout Interval must be an integer"), optarg);
- timeout_interval = atoi (optarg);
+ else
+ timeout_interval = atoi (optarg);
break;
case 'c': /* critical time threshold */
if (!is_integer (optarg))
usage2 (_("Invalid critical threshold"), optarg);
- tcrit = atoi (optarg);
+ else
+ tcrit = atoi (optarg);
break;
case 'w': /* warning time threshold */
if (!is_integer (optarg))
usage2 (_("Invalid critical threshold"), optarg);
- twarn = atoi (optarg);
+ else
+ twarn = atoi (optarg);
break;
case 'H': /* host */
if (!is_host (optarg))
usage2 (_("You gave an invalid host name"), optarg);
- pghost = optarg;
+ else
+ pghost = optarg;
break;
case 'P': /* port */
if (!is_integer (optarg))
usage2 (_("Port must be an integer"), optarg);
- pgport = optarg;
+ else
+ pgport = optarg;
break;
case 'd': /* database name */
- if (!is_pg_dbname (optarg))
+ if (!is_pg_dbname (optarg)) /* checks length and valid chars */
usage2 (_("Database name is not valid"), optarg);
- strncpy (dbName, optarg, NAMEDATALEN - 1);
- dbName[NAMEDATALEN - 1] = 0;
+ else /* we know length, and know optarg is terminated, so us strcpy */
+ strcpy (dbName, optarg);
break;
case 'l': /* login name */
if (!is_pg_logname (optarg))
usage2 (_("user name is not valid"), optarg);
- pguser = optarg;
+ else
+ pguser = optarg;
break;
case 'p': /* authentication password */
case 'a':
</article>
-@@
******************************************************************************/
+\f
+
+
+
+
+void
+print_help (void)
+{
+ char *myport;
+
+ asprintf (&myport, "%d", DEFAULT_PORT);
+
+ print_revision (progname, revision);
+
+ printf (_(COPYRIGHT), copyright, email);
+
+ printf (_("Test whether a PostgreSQL DBMS is accepting connections.\n\n"));
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_(UT_HOST_PORT), 'P', myport);
+
+ printf (_(UT_IPv46));
+
+ printf (S_("\
+ -d, --database=STRING\n\
+ Database to check (default: %s)\n\
+ -l, --logname = STRING\n\
+ Login name of user\n\
+ -p, --password = STRING\n\
+ Password (BIG SECURITY ISSUE)\n"), DEFAULT_DB);
+
+ printf (_(UT_WARN_CRIT));
+
+ printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+
+ printf (_(UT_VERBOSE));
+
+ printf (S_("\nAll parameters are optional.\n\
+\n\
+This plugin tests a PostgreSQL DBMS to determine whether it is active and\n\
+accepting queries. In its current operation, it simply connects to the\n\
+specified database, and then disconnects. If no database is specified, it\n\
+connects to the template1 database, which is present in every functioning \n\
+PostgreSQL DBMS.\n"));
+ printf (S_("\n\
+The plugin will connect to a local postmaster if no host is specified. To\n\
+connect to a remote host, be sure that the remote postmaster accepts TCP/IP\n\
+connections (start the postmaster with the -i option).\n"));
+ printf (S_("\n\
+Typically, the nagios user (unless the --logname option is used) should be\n\
+able to connect to the database without a password. The plugin can also send\n\
+a password, but no effort is made to obsure or encrypt the password.\n"));
+
+ printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+ printf (S_("\
+Usage:\n %s [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]\n\
+ [-t <timeout>]"), progname);
+ printf (S_("[-d <database>] [-l <logname>] [-p <password>]\n"));
+ printf (S_("\
+ %s (-h | --help) for detailed help\n\
+ %s (-V | --version) for version information\n"),
+ progname, progname);
+}
+
diff --git a/plugins/check_ping.c b/plugins/check_ping.c
index fd73b8cef8eb8f55d7f2e9506825d6cf7291a16a..87f9db011d83bede362ff8fbe1efdd03d870d5d2 100644 (file)
--- a/plugins/check_ping.c
+++ b/plugins/check_ping.c
int c = 1;
char *ptr;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
STD_LONG_OPTS,
{"packets", required_argument, 0, 'p'},
{"nohtml", no_argument, 0, 'n'},
}
while (1) {
- c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:", long_options, &option_index);
+ c = getopt_long (argc, argv, "VvhnL46t:c:w:H:p:", longopts, &option);
if (c == -1 || c == EOF)
break;
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 1894b281595653ee0a6e37eedb8860a4893615e8..5313b977e0e0760759775aac59b916ad6e318c8d 100644 (file)
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
int c = 1;
char *user;
struct passwd *pw;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
{"metric", required_argument, 0, 'm'},
while (1) {
c = getopt_long (argc, argv, "Vvht:c:w:p:s:u:C:a:z:r:m:P:",
- long_options, &option_index);
+ longopts, &option);
if (c == -1 || c == EOF)
break;
if (statopts)
break;
else
- statopts = strdup(optarg);
+ statopts = optarg;
asprintf (&fmt, _("%s%sSTATE = %s"), fmt, (options ? ", " : ""), statopts);
options |= STAT;
break;
if (prog)
break;
else
- prog = strdup(optarg);
+ prog = optarg;
asprintf (&fmt, _("%s%scommand name '%s'"), fmt, (options ? ", " : ""),
prog);
options |= PROG;
if (args)
break;
else
- args = strdup(optarg);
+ args = optarg;
asprintf (&fmt, _("%s%sargs '%s'"), fmt, (options ? ", " : ""), args);
options |= ARGS;
break;
diff --git a/plugins/check_radius.c b/plugins/check_radius.c
index 714de58c83158c21740a558a7844612cf4017747..1e4fff7a855061ff5c7df113f58554bb44e2e8cf 100644 (file)
--- a/plugins/check_radius.c
+++ b/plugins/check_radius.c
const char *copyright = "2000-2003";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
-#include "config.h"
#include "common.h"
#include "utils.h"
+#include "netutils.h"
#include <radiusclient.h>
-void
-print_usage (void)
-{
- printf ("\
-Usage: %s -H host -F config_file -u username -p password [-P port]\n\
- [-t timeout] [-r retries] [-e expect]\n", progname);
- printf (_(UT_HLP_VRS), progname, progname);
-}
-
-void
-print_help (void)
-{
- char *myport;
- asprintf (&myport, "%d", PW_AUTH_UDP_PORT);
-
- print_revision (progname, revision);
-
- printf (_("Copyright (c) 1999 Robert August Vincent II\n"));
- printf (_(COPYRIGHT), copyright, email);
-
- printf(_("Tests to see if a radius server is accepting connections.\n\n"));
-
- print_usage ();
-
- printf (_(UT_HELP_VRSN));
-
- printf (_(UT_HOST_PORT), 'P', myport);
-
- printf (_("\
- -u, --username=STRING\n\
- The user to authenticate\n\
- -p, --password=STRING\n\
- Password for autentication (SECURITY RISK)\n\
- -F, --filename=STRING\n\
- Configuration file\n\
- -e, --expect=STRING\n\
- Response string to expect from the server\n\
- -r, --retries=INTEGER\n\
- Number of times to retry a failed connection\n"));
-
- printf (_(UT_TIMEOUT), timeout_interval);
-
- printf (_("\n\
-This plugin tests a radius server to see if it is accepting connections.\n\
-\n\
-The server to test must be specified in the invocation, as well as a user\n\
-name and password. A configuration file may also be present. The format of\n\
-the configuration file is described in the radiusclient library sources.\n\n"));
-
- printf (_("\
-The password option presents a substantial security issue because the\n\
-password can be determined by careful watching of the command line in\n\
-a process listing. This risk is exacerbated because nagios will\n\
-run the plugin at regular prdictable intervals. Please be sure that\n\
-the password used does not allow access to sensitive system resources,\n\
-otherwise compormise could occur.\n"));
-
- printf (_(UT_SUPPORT));
-}
-\f
int process_arguments (int, char **);
+void print_help (void);
+void print_usage (void);
char *server = NULL;
char *username = NULL;
char *password = NULL;
char *expect = NULL;
char *config_file = NULL;
-int port = PW_AUTH_UDP_PORT;
+unsigned short port = PW_AUTH_UDP_PORT;
int retries = 1;
int verbose = FALSE;
ENV *env = NULL;
SEND_DATA data;
int result;
UINT4 client_id;
+ char *str;
if (process_arguments (argc, argv) == ERROR)
usage (_("Could not parse arguments\n"));
+ str = strdup ("dictionary");
if ((config_file && rc_read_config (config_file)) ||
- rc_read_dictionary (rc_conf_str ("dictionary")))
+ rc_read_dictionary (rc_conf_str (str)))
die (STATE_UNKNOWN, _("Config file error"));
service = PW_AUTHENTICATE_ONLY;
if (rc_avpair_add (&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0) ==
NULL) return (ERROR_RC);
- rc_buildreq (&data, PW_ACCESS_REQUEST, server, port, timeout_interval,
- retries);
+ rc_buildreq (&data, PW_ACCESS_REQUEST, server, port, (int)timeout_interval,
+ retries);
result = rc_send_server (&data, msg);
rc_avpair_free (data.send_pairs);
if (result == BADRESP_RC)
die (STATE_WARNING, _("Auth Failed"));
if (expect && !strstr (msg, expect))
- die (STATE_WARNING, msg);
+ die (STATE_WARNING, "%s", msg);
if (result == OK_RC)
die (STATE_OK, _("Auth OK"));
return (0);
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"hostname", required_argument, 0, 'H'},
{"port", required_argument, 0, 'P'},
{"username", required_argument, 0, 'u'},
}
while (1) {
- c = getopt_long (argc, argv, "+hVvH:P:F:u:p:t:r:e:", long_options,
- &option_index);
+ c = getopt_long (argc, argv, "+hVvH:P:F:u:p:t:r:e:", longopts,
+ &option);
if (c == -1 || c == EOF || c == 1)
break;
}
return OK;
}
+
+
+
+
+
+\f
+void
+print_help (void)
+{
+ char *myport;
+ asprintf (&myport, "%d", PW_AUTH_UDP_PORT);
+
+ print_revision (progname, revision);
+
+ printf (_("Copyright (c) 1999 Robert August Vincent II\n"));
+ printf (_(COPYRIGHT), copyright, email);
+
+ printf(_("Tests to see if a radius server is accepting connections.\n\n"));
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_(UT_HOST_PORT), 'P', myport);
+
+ printf (_("\
+ -u, --username=STRING\n\
+ The user to authenticate\n\
+ -p, --password=STRING\n\
+ Password for autentication (SECURITY RISK)\n\
+ -F, --filename=STRING\n\
+ Configuration file\n\
+ -e, --expect=STRING\n\
+ Response string to expect from the server\n\
+ -r, --retries=INTEGER\n\
+ Number of times to retry a failed connection\n"));
+
+ printf (_(UT_TIMEOUT), timeout_interval);
+
+ printf (_("\n\
+This plugin tests a radius server to see if it is accepting connections.\n\
+\n\
+The server to test must be specified in the invocation, as well as a user\n\
+name and password. A configuration file may also be present. The format of\n\
+the configuration file is described in the radiusclient library sources.\n\n"));
+
+ printf (_("\
+The password option presents a substantial security issue because the\n\
+password can be determined by careful watching of the command line in\n\
+a process listing. This risk is exacerbated because nagios will\n\
+run the plugin at regular prdictable intervals. Please be sure that\n\
+the password used does not allow access to sensitive system resources,\n\
+otherwise compormise could occur.\n"));
+
+ printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+ printf ("\
+Usage: %s -H host -F config_file -u username -p password [-P port]\n\
+ [-t timeout] [-r retries] [-e expect]\n", progname);
+ printf (_(UT_HLP_VRS), progname, progname);
+}
diff --git a/plugins/check_real.c b/plugins/check_real.c
index 9c9c3e0b93cdd2797ca7ef9ff6a4834c19a7ec4c..3e8475a7f729535dd5fff5391241b3e2ca437223 100644 (file)
--- a/plugins/check_real.c
+++ b/plugins/check_real.c
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"hostname", required_argument, 0, 'H'},
{"IPaddress", required_argument, 0, 'I'},
{"expect", required_argument, 0, 'e'},
}
while (1) {
- c = getopt_long (argc, argv, "+hVI:H:e:u:p:w:c:t:", long_options,
- &option_index);
+ c = getopt_long (argc, argv, "+hVI:H:e:u:p:w:c:t:", longopts,
+ &option);
if (c == -1 || c == EOF)
break;
if (server_address)
break;
else if (is_host (optarg))
- server_address = strdup(optarg);
+ server_address = optarg;
else
usage (_("Invalid host name\n"));
break;
case 'e': /* string to expect in response header */
- server_expect = strdup(optarg);
+ server_expect = optarg;
break;
case 'u': /* server URL */
- server_url = strdup(optarg);
+ server_url = optarg;
break;
case 'p': /* port */
if (is_intpos (optarg)) {
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index c4e427a655652d56bd8d150198fbd778c1f18940..41ed5f38d0c1207a9c5a3795f55f92d847875e24 100644 (file)
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"hostname", required_argument, 0, 'H'},
{"expect", required_argument, 0, 'e'},
{"critical", required_argument, 0, 'c'},
while (1) {
c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:",
- long_options, &option_index);
+ longopts, &option);
if (c == -1 || c == EOF)
break;
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index e22d8a0b5eacf2ee864627c5f1ecdbaf35d83e65..af8f11983b10f9713df73861126579ce1a48bbf9 100644 (file)
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
#endif
char *server_address = NULL;
-char *community = DEFAULT_COMMUNITY;
+char *community = NULL;
char *authpriv = NULL;
char *proto = NULL;
char *seclevel = NULL;
char *authproto = NULL;
char *authpasswd = NULL;
char *privpasswd = NULL;
-char *oid = "";
-char *label = "SNMP";
-char *units = "";
-char *port = DEFAULT_PORT;
+char *oid;
+char *label;
+char *units;
+char *port;
char string_value[MAX_INPUT_BUFFER] = "";
char **labels = NULL;
char **unitv = NULL;
-int nlabels = 0;
-int labels_size = 8;
-int nunits = 0;
-int unitv_size = 8;
+size_t nlabels = 0;
+size_t labels_size = 8;
+size_t nunits = 0;
+size_t unitv_size = 8;
int verbose = FALSE;
unsigned long lower_warn_lim[MAX_OIDS];
unsigned long upper_warn_lim[MAX_OIDS];
int check_warning_value = FALSE;
int check_critical_value = FALSE;
int eval_method[MAX_OIDS];
-char *delimiter = DEFAULT_DELIMITER;
-char *output_delim = DEFAULT_OUTPUT_DELIMITER;
-char *miblist = DEFAULT_MIBLIST;
+char *delimiter;
+char *output_delim;
+char *miblist;
char input_buffer[MAX_INPUT_BUFFER];
char *command_line = NULL;
char *response = NULL;
- char *outbuff = "";
- char *output = "";
+ char *outbuff;
+ char *output;
char *ptr = NULL;
char *p2 = NULL;
char *show = NULL;
eval_method[i] = CHECK_UNDEF;
i = 0;
+ oid = strdup ("");
+ label = strdup ("SNMP");
+ units = strdup ("");
+ port = strdup (DEFAULT_PORT);
+ outbuff = strdup ("");
+ output = strdup ("");
+ delimiter = strdup (DEFAULT_DELIMITER);
+ output_delim = strdup (DEFAULT_OUTPUT_DELIMITER);
+ miblist = strdup (DEFAULT_MIBLIST);
+
if (process_arguments (argc, argv) == ERROR)
usage (_("Incorrect arguments supplied\n"));
result = max_state (result, iresult);
/* Prepend a label for this OID if there is one */
- if (nlabels > 1 && i < nlabels && labels[i] != NULL)
+ if (nlabels > (size_t)1 && (size_t)i < nlabels && labels[i] != NULL)
asprintf (&outbuff, "%s%s%s %s%s%s", outbuff,
(i == 0) ? " " : output_delim,
labels[i], mark (iresult), show, mark (iresult));
mark (iresult), show, mark (iresult));
/* Append a unit string for this OID if there is one */
- if (nunits > 0 && i < nunits && unitv[i] != NULL)
+ if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
i++;
int c = 1;
int j = 0, jj = 0, ii = 0;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
STD_LONG_OPTS,
{"community", required_argument, 0, 'C'},
{"oid", required_argument, 0, 'o'},
while (1) {
c = getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:P:L:U:a:A:X:",
- long_options, &option_index);
+ longopts, &option);
if (c == -1 || c == EOF)
break;
/* Connection info */
case 'C': /* group or community */
- community = strscpy (community, optarg);
+ community = optarg;
break;
case 'H': /* Host or server */
- server_address = strscpy (server_address, optarg);
+ server_address = optarg;
break;
case 'p': /* TCP port number */
- port = strscpy(port, optarg);
+ port = optarg;
break;
case 'm': /* List of MIBS */
- miblist = strscpy(miblist, optarg);
+ miblist = optarg;
break;
case 'P': /* SNMP protocol version */
- proto = strscpy(proto, optarg);
+ proto = optarg;
break;
case 'L': /* security level */
- seclevel = strscpy(seclevel,optarg);
+ seclevel = optarg;
break;
case 'U': /* security username */
- secname = strscpy(secname, optarg);
+ secname = optarg;
break;
case 'a': /* auth protocol */
- asprintf (&authproto, optarg);
+ authproto = optarg;
break;
case 'A': /* auth passwd */
- authpasswd = strscpy(authpasswd, optarg);
+ authpasswd = optarg;
break;
case 'X': /* priv passwd */
- privpasswd = strscpy(privpasswd, optarg);
+ privpasswd = optarg;
break;
case 't': /* timeout period */
if (!is_integer (optarg))
}
if (server_address == NULL)
- asprintf (&server_address, argv[optind]);
+ server_address = argv[optind];
+
+ if (community == NULL)
+ community = strdup (DEFAULT_COMMUNITY);
return validate_arguments ();
}
diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c
index fdded583b70ea06c1163f7227408f4619a3449e3..26709a7d91e4fd7a5cb7fc49fc7789885d0348ef 100644 (file)
--- a/plugins/check_ssh.c
+++ b/plugins/check_ssh.c
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"host", required_argument, 0, 'H'},
strcpy (argv[c], "-t");
while (1) {
- c = getopt_long (argc, argv, "+Vhv46t:H:p:", long_options, &option_index);
+ c = getopt_long (argc, argv, "+Vhv46t:H:p:", longopts, &option);
if (c == -1 || c == EOF)
break;
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index b92694d90ef923a87b59047a598d2736561d099f..a4e7e81420b8c66f72f74e63e85889d79bfeb9ac 100644 (file)
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
const char *copyright = "2000-2003";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
-int check_swap (int usp, int free_swap);
+int check_swap (int usp, long unsigned int free_swap);
int process_arguments (int argc, char **argv);
int validate_arguments (void);
void print_usage (void);
int sun = 0; /* defined by compiler if it is a sun solaris system */
#endif
-void
-print_usage (void)
-{
- printf (_("Usage:\n\
- %s [-a] -w <used_percentage>%% -c <used_percentage>%%\n\
- %s [-a] -w <bytes_free> -c <bytes_free>\n\
- %s (-h | --help) for detailed help\n\
- %s (-V | --version) for version information\n"),
- progname, progname, progname, progname);
-}
-
-
-
-
-
-void
-print_help (void)
-{
- print_revision (progname, revision);
-
- printf (_(COPYRIGHT), copyright, email);
-
- printf (_("Check swap space on local server.\n\n"));
-
- print_usage ();
-
- printf (_(UT_HELP_VRSN));
-
- printf (_("\n\
- -w, --warning=INTEGER\n\
- Exit with WARNING status if less than INTEGER bytes of swap space are free\n\
- -w, --warning=PERCENT%%\n\
- Exit with WARNING status if less than PERCENT of swap space has been used\n\
- -c, --critical=INTEGER\n\
- Exit with CRITICAL status if less than INTEGER bytes of swap space are free\n\
- -c, --critical=PERCENT%%\n\
- Exit with CRITCAL status if less than PERCENT of swap space has been used\n\
- -a, --allswaps\n\
- Conduct comparisons for all swap partitions, one by one\n"));
-
-#ifdef sun
- printf (_("\n\
-On Solaris, if -a specified, uses swap -l, otherwise uses swap -s.\n\
-Will be discrepencies because swap -s counts allocated swap and includes\n\
-real memory\n"));
-#endif
-
- support ();
-}
-\f
-
-
int
main (int argc, char **argv)
{
FILE *fp;
#endif
char str[32];
- char *status = "";
+ char *status;
+
+ status = strdup("");
if (process_arguments (argc, argv) != OK)
usage (_("Invalid command arguments supplied\n"));
\f
int
-check_swap (int usp, int free_swap)
+check_swap (int usp, long unsigned int free_swap)
{
int result = STATE_UNKNOWN;
if (usp >= 0 && usp >= (100.0 - crit_percent))
result = STATE_CRITICAL;
- else if (crit_size > 0 && (unsigned)free_swap <= crit_size)
+ else if (crit_size > 0 && free_swap <= crit_size)
result = STATE_CRITICAL;
else if (usp >= 0 && usp >= (100.0 - warn_percent))
result = STATE_WARNING;
- else if (warn_size > 0 && (unsigned)free_swap <= warn_size)
+ else if (warn_size > 0 && free_swap <= warn_size)
result = STATE_WARNING;
else if (usp >= 0.0)
result = STATE_OK;
int wc = 0; /* warning counter */
int cc = 0; /* critical counter */
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
{"allswaps", no_argument, 0, 'a'},
return ERROR;
while (1) {
- c = getopt_long (argc, argv, "+?Vvhac:w:", long_options, &option_index);
+ c = getopt_long (argc, argv, "+?Vvhac:w:", longopts, &option);
if (c == -1 || c == EOF)
break;
else {
usage (_("Warning threshold must be integer or percentage!\n"));
}
- wc++;
case 'c': /* critical time threshold */
if (is_intnonneg (optarg)) {
crit_size = atoi (optarg);
else {
usage (_("Critical threshold must be integer or percentage!\n"));
}
- cc++;
case 'a': /* all swap */
allswaps = TRUE;
break;
}
return OK;
}
+
+
+
+
+
+\f
+void
+print_help (void)
+{
+ print_revision (progname, revision);
+
+ printf (_(COPYRIGHT), copyright, email);
+
+ printf (_("Check swap space on local server.\n\n"));
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_("\n\
+ -w, --warning=INTEGER\n\
+ Exit with WARNING status if less than INTEGER bytes of swap space are free\n\
+ -w, --warning=PERCENT%%\n\
+ Exit with WARNING status if less than PERCENT of swap space has been used\n\
+ -c, --critical=INTEGER\n\
+ Exit with CRITICAL status if less than INTEGER bytes of swap space are free\n\
+ -c, --critical=PERCENT%%\n\
+ Exit with CRITCAL status if less than PERCENT of swap space has been used\n\
+ -a, --allswaps\n\
+ Conduct comparisons for all swap partitions, one by one\n"));
+
+#ifdef sun
+ printf (_("\n\
+On Solaris, if -a specified, uses swap -l, otherwise uses swap -s.\n\
+Will be discrepencies because swap -s counts allocated swap and includes\n\
+real memory\n"));
+#endif
+
+ printf (_(UT_SUPPORT));
+}
+
+
+
+
+void
+print_usage (void)
+{
+ printf (_("Usage:\n\
+ %s [-a] -w <used_percentage>%% -c <used_percentage>%%\n\
+ %s [-a] -w <bytes_free> -c <bytes_free>\n\
+ %s (-h | --help) for detailed help\n\
+ %s (-V | --version) for version information\n"),
+ progname, progname, progname, progname);
+}
diff --git a/plugins/check_tcp.c b/plugins/check_tcp.c
index fc0572cc3f19d11b752e5f80c284344577466369..bf8ed8caf6716df7bd99074820edbd76ebaa6439 100644 (file)
--- a/plugins/check_tcp.c
+++ b/plugins/check_tcp.c
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"hostname", required_argument, 0, 'H'},
{"critical-time", required_argument, 0, 'c'},
{"warning-time", required_argument, 0, 'w'},
while (1) {
c = getopt_long (argc, argv, "+hVv46H:s:e:q:m:c:w:t:p:C:W:d:Sr:",
- long_options, &option_index);
+ longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
diff --git a/plugins/check_time.c b/plugins/check_time.c
index 36b622fbfa3808de9170d3a4ee90a8dbad2da1cf..49e7c87daf4d7d2d2a7e041f8806eda67dfa210f 100644 (file)
--- a/plugins/check_time.c
+++ b/plugins/check_time.c
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"hostname", required_argument, 0, 'H'},
{"warning-variance", required_argument, 0, 'w'},
{"critical-variance", required_argument, 0, 'c'},
}
while (1) {
- c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:", long_options,
- &option_index);
+ c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:", longopts,
+ &option);
if (c == -1 || c == EOF)
break;
printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
- support ();
+ printf (_(UT_SUPPORT));
}
diff --git a/plugins/check_udp.c b/plugins/check_udp.c
index bd5de5864d7c97e4d0fa6a57adcb347de41a3ab5..5aaf3a7924240a26fcf4a390878837d68944194c 100644 (file)
--- a/plugins/check_udp.c
+++ b/plugins/check_udp.c
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"hostname", required_argument, 0, 'H'},
{"critical", required_argument, 0, 'c'},
{"warning", required_argument, 0, 'w'},
}
while (1) {
- c = getopt_long (argc, argv, "+hVvH:e:s:c:w:t:p:", long_options, &option_index);
+ c = getopt_long (argc, argv, "+hVvH:e:s:c:w:t:p:", longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index fcee747770ff00b30b9007a33cc8b600b0850225..7e7b36a4b01882e3b429d148618b2679fd19934c 100644 (file)
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"hostname", required_argument, 0, 'H'},
{"ups", required_argument, 0, 'u'},
{"port", required_argument, 0, 'p'},
}
while (1) {
- c = getopt_long (argc, argv, "hVH:u:p:v:c:w:t:", long_options,
- &option_index);
+ c = getopt_long (argc, argv, "hVH:u:p:v:c:w:t:", longopts,
+ &option);
if (c == -1 || c == EOF)
break;
diff --git a/plugins/check_users.c b/plugins/check_users.c
index 9e182015e21c6c07e4df41303d1b1cfe910bc8d3..9f308bc3f9b76fe038e59c5f0fa7355434dfd264 100644 (file)
--- a/plugins/check_users.c
+++ b/plugins/check_users.c
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"critical", required_argument, 0, 'c'},
{"warning", required_argument, 0, 'w'},
{"version", no_argument, 0, 'V'},
usage ("\n");
while (1) {
- c = getopt_long (argc, argv, "+hVvc:w:", long_options, &option_index);
+ c = getopt_long (argc, argv, "+hVvc:w:", longopts, &option);
if (c == -1 || c == EOF || c == 1)
break;
diff --git a/plugins/negate.c b/plugins/negate.c
index 3ef5ee769e4075220bafd48d9a7350ff365bc68a..c24658afce96e86451513b611434bb697c14c62c 100644 (file)
--- a/plugins/negate.c
+++ b/plugins/negate.c
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-******************************************************************************/
-
-const char *progname = "negate";
-const char *revision = "$Revision$";
-const char *copyright = "2002-2003";
-const char *email = "nagiosplug-devel@lists.sourceforge.net";
-
-#define DEFAULT_TIMEOUT 9
-
-#include "common.h"
-#include "utils.h"
-#include "popen.h"
-
-void
-print_usage (void)
-{
- printf (_("Usage: %s [-t timeout] <definition of wrapped plugin>\n"),
- progname);
- printf (_(UT_HLP_VRS), progname, progname);
-}
-
-void
-print_help (void)
-{
- print_revision (progname, revision);
-
- printf (_(COPYRIGHT), copyright, email);
-
- printf (_("\
-Negates the status of a plugin (returns OK for CRITICAL, and vice-versa).\n\
-\n"));
-
- print_usage ();
-
- printf (_(UT_HELP_VRSN));
-
- printf (_(UT_TIMEOUT), DEFAULT_TIMEOUT);
-
- printf (_("\
- [keep timeout than the plugin timeout to retain CRITICAL status]\n"));
-
- printf (_("\
- negate \"/usr/local/nagios/libexec/check_ping -H host\"\n\
- Run check_ping and invert result. Must use full path to plugin\n\
- negate \"/usr/local/nagios/libexec/check_procs -a 'vi negate.c'\"\n\
- Use single quotes if you need to retain spaces\n"));
-
- printf (_("\
-This plugin is a wrapper to take the output of another plugin and invert it.\n\
-If the wrapped plugin returns STATE_OK, the wrapper will return STATE_CRITICAL.\n\
-If the wrapped plugin returns STATE_CRITICAL, the wrapper will return STATE_OK.\n\
-Otherwise, the output state of the wrapped plugin is unchanged.\n"));
-
- printf (_(UT_SUPPORT));
-}
-\f
-char *command_line;
-
-int process_arguments (int, char **);
-int validate_arguments (void);
-/******************************************************************************
-
-The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@
-tags in the comments. With in the tags, the XML is assembled sequentially.
-You can define entities in tags. You also have all the #defines available as
-entities.
-
-Please note that all tags must be lowercase to use the DocBook XML DTD.
-
@@-<article>
<sect1>
<title>Quick Reference</title>
-<!-- The refentry forms a manpage -->
<refentry>
-<refmeta>
-<manvolnum>5<manvolnum>
-</refmeta>
+<refmeta><manvolnum>5<manvolnum></refmeta>
<refnamdiv>
<refname>&progname;</refname>
<refpurpose>&SUMMARY;</refpurpose>
<itemizedlist>
<listitem>Add option to do regex substitution in output text</listitem>
</itemizedlist>
-</sect2>
-
+</sect2>-@@
-<sect2>
-<title>Functions</title>
--@@
******************************************************************************/
+const char *progname = "negate";
+const char *revision = "$Revision$";
+const char *copyright = "2002-2003";
+const char *email = "nagiosplug-devel@lists.sourceforge.net";
+
+#define DEFAULT_TIMEOUT 9
+
+#include "common.h"
+#include "utils.h"
+#include "popen.h"
+
+char *command_line;
+
+int process_arguments (int, char **);
+int validate_arguments (void);
+void print_help (void);
+void print_usage (void);
+
int
main (int argc, char **argv)
{
int found = 0, result = STATE_UNKNOWN;
- char input_buffer[MAX_INPUT_BUFFER];
+ char *buf;
if (process_arguments (argc, argv) == ERROR)
usage (_("Could not parse arguments\n"));
printf (_("Could not open stderr for %s\n"), command_line);
}
- while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
+ buf = malloc(MAX_INPUT_BUFFER);
+ while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
found++;
- if (strchr (input_buffer, '\n')) {
- input_buffer[strcspn (input_buffer, "\n")] = 0;
- printf ("%s\n", input_buffer);
- }
- else {
- printf ("%s\n", input_buffer);
- }
+ printf ("%s", buf);
}
if (!found)
- die (STATE_UNKNOWN,\
- _("%s problem - No data recieved from host\nCMD: %s\n"),\
- argv[0], command_line);
+ die (STATE_UNKNOWN,
+ _("%s problem - No data recieved from host\nCMD: %s\n"),\
+ argv[0], command_line);
/* close the pipe */
result = spclose (child_process);
/* WARNING if output found on stderr */
- if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
+ if (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr))
result = max_state (result, STATE_WARNING);
/* close stderr */
/******************************************************************************
@@-
+<sect2>
+<title>Functions</title>
+
<sect3>
<title>process_arguments</title>
variables.</para>
<para>Aside from the standard 'help' and 'version' options, there
-is a only a 'timeout' option.No validation is currently done.</para>
+is a only a 'timeout' option.</para>
</sect3>
-@@
{
int c;
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"timeout", required_argument, 0, 't'},
while (1) {
c = getopt_long (argc, argv, "+hVt:",
- long_options, &option_index);
+ longopts, &option);
if (c == -1 || c == EOF)
break;
switch (c) {
case '?': /* help */
usage3 (_("Unknown argument"), optopt);
+ break;
case 'h': /* help */
print_help ();
exit (EXIT_SUCCESS);
+ break;
case 'V': /* version */
print_revision (progname, revision);
exit (EXIT_SUCCESS);
case 't': /* timeout period */
if (!is_integer (optarg))
usage2 (_("Timeout Interval must be an integer"), optarg);
- timeout_interval = atoi (optarg);
+ else
+ timeout_interval = atoi (optarg);
break;
}
}
return ERROR;
return STATE_OK;
}
-\f
/******************************************************************************
@@-
</article>
-@@
******************************************************************************/
+
+
+
+
+
+\f
+void
+print_help (void)
+{
+ print_revision (progname, revision);
+
+ printf (_(COPYRIGHT), copyright, email);
+
+ printf (_("\
+Negates the status of a plugin (returns OK for CRITICAL, and vice-versa).\n\
+\n"));
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_(UT_TIMEOUT), DEFAULT_TIMEOUT);
+
+ printf (_("\
+ [keep timeout than the plugin timeout to retain CRITICAL status]\n"));
+
+ printf (_("\
+ negate \"/usr/local/nagios/libexec/check_ping -H host\"\n\
+ Run check_ping and invert result. Must use full path to plugin\n\
+ negate \"/usr/local/nagios/libexec/check_procs -a 'vi negate.c'\"\n\
+ Use single quotes if you need to retain spaces\n"));
+
+ printf (_("\
+This plugin is a wrapper to take the output of another plugin and invert it.\n\
+If the wrapped plugin returns STATE_OK, the wrapper will return STATE_CRITICAL.\n\
+If the wrapped plugin returns STATE_CRITICAL, the wrapper will return STATE_OK.\n\
+Otherwise, the output state of the wrapped plugin is unchanged.\n"));
+
+ printf (_(UT_SUPPORT));
+}
+
+
+
+
+
+void
+print_usage (void)
+{
+ printf (_("Usage: %s [-t timeout] <definition of wrapped plugin>\n"),
+ progname);
+ printf (_(UT_HLP_VRS), progname, progname);
+}
diff --git a/plugins/popen.c b/plugins/popen.c
index 98ba085b79bb9e989643849b1297cee2cf02f361..05fd0ab9a0b32063bed8bddc633ca3a54d43fe27 100644 (file)
--- a/plugins/popen.c
+++ b/plugins/popen.c
*
******************************************************************************/
-#include <config.h>
-#include <common.h>
+#include "common.h"
/* extern so plugin has pid to kill exec'd process on timeouts */
extern int timeout_interval;
diff --git a/plugins/urlize.c b/plugins/urlize.c
index 12fb3ec9e09eff9e98e0dd28ac2e2ce01673b26d..f4bc67b39c1f9492261610fe314c0a28eb6e0a89 100644 (file)
--- a/plugins/urlize.c
+++ b/plugins/urlize.c
/******************************************************************************
- *
- * urlize.c
- *
- * Program: plugin wrapper for Nagios
- * License: GPL
- * Copyright (c) 2000 Karl DeBisschop (kdebiss@alum.mit.edu)
- *
- * Last Modified: $Date$
- * 2000-06-01 Karl DeBisschop <karl@debisschop.net>
- * Written based of concept in urlize.pl
- *
- * Usage: urlize <url> <plugin> <arg1> ... <argN>
- *
- * Description:
- *
- * This plugin wraps the text output of another command (plugin) in HTML
- * <A> tags, thus displaying the plugin output in as a clickable link in
- * the Nagios status screen. The return status is the same as the plugin
- * invoked by urlize
- *
- * License Information:
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *****************************************************************************/
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+******************************************************************************/
const char *progname = "urlize";
const char *revision = "$Revision$";
#include "utils.h"
#include "popen.h"
-void
-print_usage (void)
+void print_help (void);
+void print_usage (void);
+
+int
+main (int argc, char **argv)
{
- printf (_("Usage:\n %s <url> <plugin> <arg1> ... <argN>\n"), progname);
+ int found = 0, result = STATE_UNKNOWN;
+ char *url = NULL;
+ char *cmd;
+ char *buf;
+
+ int c;
+ int option = 0;
+ static struct option longopts[] = {
+ {"help", no_argument, 0, 'h'},
+ {"version", no_argument, 0, 'V'},
+ {"url", required_argument, 0, 'u'},
+ {0, 0, 0, 0}
+ };
+
+ while (1) {
+ c = getopt_long (argc, argv, "+hVu:", longopts, &option);
+
+ if (c == -1 || c == EOF)
+ break;
+
+ switch (c) {
+ case 'h': /* help */
+ print_help ();
+ exit (EXIT_SUCCESS);
+ break;
+ case 'V': /* version */
+ print_revision (progname, revision);
+ exit (EXIT_SUCCESS);
+ break;
+ case 'u':
+ url = strdup (argv[optind]);
+ break;
+ case '?':
+ default:
+ usage3 (_("Unknown argument"), optopt);
+ break;
+ }
+ }
+
+ if (url == NULL)
+ url = strdup (argv[optind++]);
+
+ cmd = strdup (argv[optind++]);
+ for (c = optind; c < argc; c++) {
+ asprintf (&cmd, "%s %s", cmd, argv[c]);
+ }
+
+ child_process = spopen (cmd);
+ if (child_process == NULL) {
+ printf (_("Could not open pipe: %s\n"), cmd);
+ exit (STATE_UNKNOWN);
+ }
+
+ child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
+ if (child_stderr == NULL) {
+ printf (_("Could not open stderr for %s\n"), cmd);
+ }
+
+ buf = malloc(MAX_INPUT_BUFFER);
+ printf ("<A href=\"%s\">", argv[1]);
+ while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
+ found++;
+ printf ("%s", buf);
+ }
+
+ if (!found)
+ die (STATE_UNKNOWN,
+ _("%s problem - No data recieved from host\nCMD: %s</A>\n"),
+ argv[0], cmd);
+
+ /* close the pipe */
+ result = spclose (child_process);
+
+ /* WARNING if output found on stderr */
+ if (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr))
+ result = max_state (result, STATE_WARNING);
+
+ /* close stderr */
+ (void) fclose (child_stderr);
+
+ printf ("</A>\n");
+ return result;
}
+
+
+
+
+\f
void
print_help (void)
{
You probably want:\n\
\n\
urlize http://example.com/ \"check_http -H example.com -r 'two words'\"\n"));
- exit (STATE_OK);
-}
-\f
-int
-main (int argc, char **argv)
-{
- int i = 0, found = 0, result = STATE_UNKNOWN;
- char *cmd = NULL;
- char input_buffer[MAX_INPUT_BUFFER];
-
- if (argc < 2) {
- print_usage ();
- exit (STATE_UNKNOWN);
- }
-
- if (!strcmp (argv[1], "-h") || !strcmp (argv[1], "--help")) {
- print_help ();
- exit (STATE_OK);
- }
-
- if (!strcmp (argv[1], "-V") || !strcmp (argv[1], "--version")) {
- print_revision (progname, revision);
- exit (STATE_OK);
- }
-
- if (argc < 2) {
- print_usage ();
- exit (STATE_UNKNOWN);
- }
-
- asprintf (&cmd, "%s", argv[2]);
- for (i = 3; i < argc; i++) {
- asprintf (&cmd, "%s %s", cmd, argv[i]);
- }
-
- child_process = spopen (cmd);
- if (child_process == NULL) {
- printf (_("Could not open pipe: %s\n"), cmd);
- exit (STATE_UNKNOWN);
- }
-
- child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
- if (child_stderr == NULL) {
- printf (_("Could not open stderr for %s\n"), cmd);
- }
-
- printf ("<A href=\"%s\">", argv[1]);
- while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
- found++;
- if (index (input_buffer, '\n')) {
- input_buffer[strcspn (input_buffer, "\n")] = 0;
- printf ("%s", input_buffer);
- }
- else {
- printf ("%s", input_buffer);
- }
- }
- if (!found) {
- printf (_("%s problem - No data recieved from host\nCMD: %s</A>\n"), argv[0],
- cmd);
- exit (STATE_UNKNOWN);
- }
+ printf (_(UT_SUPPORT));
+}
- /* close the pipe */
- result = spclose (child_process);
- /* WARNING if output found on stderr */
- if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
- result = max_state (result, STATE_WARNING);
- /* close stderr */
- (void) fclose (child_stderr);
- printf ("</A>\n");
- return result;
+void
+print_usage (void)
+{
+ printf (_("Usage:\n %s <url> <plugin> <arg1> ... <argN>\n"), progname);
}