From 0b6423f9c99d9edf8c96fefd0f6c453859395aa1 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Mon, 30 Sep 2013 00:03:24 +0200 Subject: Import Nagios Plugins site Import the Nagios Plugins web site, Cronjobs, infrastructure scripts, and configuration files. --- web/attachments/103460-check_ups-NUT2.0.diff | 588 +++++++++++++++++++++++++++ 1 file changed, 588 insertions(+) create mode 100644 web/attachments/103460-check_ups-NUT2.0.diff (limited to 'web/attachments/103460-check_ups-NUT2.0.diff') diff --git a/web/attachments/103460-check_ups-NUT2.0.diff b/web/attachments/103460-check_ups-NUT2.0.diff new file mode 100644 index 0000000..e28c718 --- /dev/null +++ b/web/attachments/103460-check_ups-NUT2.0.diff @@ -0,0 +1,588 @@ +diff -ru nagiosplug/AUTHORS nagiosplug_AQ/AUTHORS +--- nagiosplug/AUTHORS 2004-08-23 23:59:37.000000000 +0200 ++++ nagiosplug_AQ/AUTHORS 2004-09-30 10:23:42.000000000 +0200 +@@ -119,3 +119,5 @@ + Sean Finney + Bill Kunkel + Paulo Afonso Graner Fessel ++Alain Richard ++Arnaud Quette +diff -ru nagiosplug/command.cfg.in nagiosplug_AQ/command.cfg.in +--- nagiosplug/command.cfg.in 2003-06-12 06:46:10.000000000 +0200 ++++ nagiosplug_AQ/command.cfg.in 2004-10-01 12:31:15.000000000 +0200 +@@ -91,6 +91,7 @@ + command[check_procs_zombie]=@libexecdir@/check_procs -w $ARG1$ -c $ARG2$ -s Z + command[check_procs_httpd]=@libexecdir@/check_procs -w 5:$ARG1$ -c 1:$ARG2$ -C httpd + command[check_procs_vsz]=@libexecdir@/check_procs -w 8096 -c 16182 -C httpd --metric VSZ ++command[check_ups]=@libexecdir@/check_ups -H $HOSTADDRESS$ -u $UPS$ + + # An example of using check_by_ssh as an active service check + command[ssh_disk]=@libexecdir@/check_by_ssh -H $HOSTADDRESS$ -C '@libexecdir@/check_disk -w 85% -c 95% -p $ARG1$' +diff -ru nagiosplug/plugins/check_ups.c nagiosplug_AQ/plugins/check_ups.c +--- nagiosplug/plugins/check_ups.c 2004-03-14 05:09:19.000000000 +0100 ++++ nagiosplug_AQ/plugins/check_ups.c 2004-10-01 11:35:19.000000000 +0200 +@@ -1,26 +1,35 @@ + /****************************************************************************** +- +- 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. +- +-******************************************************************************/ ++ * ++ * check_ups ++ * ++ * Program: Network UPS Tools plugin for Nagios ++ * License: GPL ++ * Copyright (c) 2000 Tom Shields ++ * 2004 Alain Richard ++ * 2004 Arnaud Quette ++ * ++ * 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 = "check_ups"; +-const char *revision = "$Revision: 1.14 $"; +-const char *copyright = "2000-2002"; ++const char *revision = "$Revision: 1.20 $"; ++const char *copyright = "2000-2004"; + const char *email = "nagiosplug-devel@lists.sourceforge.net"; + ++#include + #include "common.h" + #include "netutils.h" + #include "utils.h" +@@ -38,14 +47,22 @@ + #define UPS_TEMP 8 /* supports UPS temperature */ + #define UPS_LOADPCT 16 /* supports load percent */ + +-#define UPSSTATUS_NONE 0 +-#define UPSSTATUS_OFF 1 +-#define UPSSTATUS_OL 2 +-#define UPSSTATUS_OB 4 +-#define UPSSTATUS_LB 8 +-#define UPSSTATUS_CAL 16 +-#define UPSSTATUS_RB 32 /*Replace Battery */ +-#define UPSSTATUS_UNKOWN 64 ++#define UPSSTATUS_NONE 0 ++#define UPSSTATUS_OFF 1 ++#define UPSSTATUS_OL 2 ++#define UPSSTATUS_OB 4 ++#define UPSSTATUS_LB 8 ++#define UPSSTATUS_CAL 16 ++#define UPSSTATUS_RB 32 /*Replace Battery */ ++#define UPSSTATUS_BYPASS 64 ++#define UPSSTATUS_OVER 128 ++#define UPSSTATUS_TRIM 256 ++#define UPSSTATUS_BOOST 512 ++#define UPSSTATUS_CHRG 1024 ++#define UPSSTATUS_DISCHRG 2048 ++#define UPSSTATUS_UNKOWN 4096 ++ ++enum { NOSUCHVAR = ERROR-1 }; + + int server_port = PORT; + char *server_address; +@@ -63,9 +80,9 @@ + double ups_load_percent = 0.0; + double ups_temperature = 0.0; + char *ups_status; ++int temp_output_c = 0; + + int determine_status (void); +-int determine_supported_vars (void); + int get_ups_variable (const char *, char *, size_t); + + int process_arguments (int, char **); +@@ -73,7 +90,7 @@ + void print_help (void); + void print_usage (void); + +-int ++ int + main (int argc, char **argv) + { + int result = STATE_OK; +@@ -81,6 +98,7 @@ + char *data; + char temp_buffer[MAX_INPUT_BUFFER]; + double ups_utility_deviation = 0.0; ++ int res; + + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); +@@ -88,6 +106,7 @@ + + ups_status = strdup ("N/A"); + data = strdup (""); ++ message = strdup (""); + + if (process_arguments (argc, argv) != OK) + usage ("Invalid command arguments supplied\n"); +@@ -98,15 +117,11 @@ + /* set socket timeout */ + alarm (socket_timeout); + +- /* determine what variables the UPS supports */ +- if (determine_supported_vars () != OK) +- return STATE_CRITICAL; +- + /* get the ups status if possible */ ++ if (determine_status () != OK) ++ return STATE_CRITICAL; + if (supported_options & UPS_STATUS) { + +- if (determine_status () != OK) +- return STATE_CRITICAL; + ups_status = strdup (""); + result = STATE_OK; + +@@ -138,6 +153,24 @@ + asprintf (&ups_status, "%s%s", ups_status, ", Replace Battery"); + result = STATE_WARNING; + } ++ if (status & UPSSTATUS_BYPASS) { ++ asprintf (&ups_status, "%s%s", ups_status, ", On Bypass"); ++ } ++ if (status & UPSSTATUS_OVER) { ++ asprintf (&ups_status, "%s%s", ups_status, ", Overload"); ++ } ++ if (status & UPSSTATUS_TRIM) { ++ asprintf (&ups_status, "%s%s", ups_status, ", Trimming"); ++ } ++ if (status & UPSSTATUS_BOOST) { ++ asprintf (&ups_status, "%s%s", ups_status, ", Boosting"); ++ } ++ if (status & UPSSTATUS_CHRG) { ++ asprintf (&ups_status, "%s%s", ups_status, ", Charging"); ++ } ++ if (status & UPSSTATUS_DISCHRG) { ++ asprintf (&ups_status, "%s%s", ups_status, ", Discharging"); ++ } + if (status & UPSSTATUS_UNKOWN) { + asprintf (&ups_status, "%s%s", ups_status, ", Unknown"); + } +@@ -146,10 +179,12 @@ + } + + /* get the ups utility voltage if possible */ +- if (supported_options & UPS_UTILITY) { +- +- if (get_ups_variable ("UTILITY", temp_buffer, sizeof (temp_buffer)) != OK) +- return STATE_CRITICAL; ++ res=get_ups_variable ("input.voltage", temp_buffer, sizeof (temp_buffer)); ++ if (res == NOSUCHVAR) supported_options &= ~UPS_UTILITY; ++ else if (res != OK) ++ return STATE_CRITICAL; ++ else { ++ supported_options |= UPS_UTILITY; + + ups_utility_voltage = atof (temp_buffer); + asprintf (&message, "%sUtility=%3.1fV ", message, ups_utility_voltage); +@@ -167,23 +202,24 @@ + result = max_state (result, STATE_WARNING); + } + asprintf (&data, "%s", +- fperfdata ("voltage", ups_utility_voltage, "V", +- check_warn, warning_value, +- check_crit, critical_value, ++ perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", ++ check_warn, (long)(1000*warning_value), ++ check_crit, (long)(1000*critical_value), + TRUE, 0, FALSE, 0)); + } else { + asprintf (&data, "%s", +- fperfdata ("voltage", ups_utility_voltage, "V", ++ perfdata ("voltage", (long)(1000*ups_utility_voltage), "mV", + FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0)); + } + } + + /* get the ups battery percent if possible */ +- if (supported_options & UPS_BATTPCT) { +- +- if (get_ups_variable ("BATTPCT", temp_buffer, sizeof (temp_buffer)) != OK) +- return STATE_CRITICAL; +- ++ res=get_ups_variable ("battery.charge", temp_buffer, sizeof (temp_buffer)); ++ if (res == NOSUCHVAR) supported_options &= ~UPS_BATTPCT; ++ else if ( res != OK) ++ return STATE_CRITICAL; ++ else { ++ supported_options |= UPS_BATTPCT; + ups_battery_percent = atof (temp_buffer); + asprintf (&message, "%sBatt=%3.1f%% ", message, ups_battery_percent); + +@@ -207,11 +243,12 @@ + } + + /* get the ups load percent if possible */ +- if (supported_options & UPS_LOADPCT) { +- +- if (get_ups_variable ("LOADPCT", temp_buffer, sizeof (temp_buffer)) != OK) +- return STATE_CRITICAL; +- ++ res=get_ups_variable ("ups.load", temp_buffer, sizeof (temp_buffer)); ++ if ( res == NOSUCHVAR ) supported_options &= ~UPS_LOADPCT; ++ else if ( res != OK) ++ return STATE_CRITICAL; ++ else { ++ supported_options |= UPS_LOADPCT; + ups_load_percent = atof (temp_buffer); + asprintf (&message, "%sLoad=%3.1f%% ", message, ups_load_percent); + +@@ -235,13 +272,20 @@ + } + + /* get the ups temperature if possible */ +- if (supported_options & UPS_TEMP) { +- +- if (get_ups_variable ("UPSTEMP", temp_buffer, sizeof (temp_buffer)) != OK) +- return STATE_CRITICAL; +- +- ups_temperature = (atof (temp_buffer) * 1.8) + 32; +- asprintf (&message, "%sTemp=%3.1fF", message, ups_temperature); ++ res=get_ups_variable ("ups.temperature", temp_buffer, sizeof (temp_buffer)); ++ if ( res == NOSUCHVAR ) supported_options &= ~UPS_TEMP; ++ else if ( res != OK) ++ return STATE_CRITICAL; ++ else { ++ supported_options |= UPS_TEMP; ++ if (temp_output_c) { ++ ups_temperature = atof (temp_buffer); ++ asprintf (&message, "%sTemp=%3.1fC", message, ups_temperature); ++ } ++ else { ++ ups_temperature = (atof (temp_buffer) * 1.8) + 32; ++ asprintf (&message, "%sTemp=%3.1fF", message, ups_temperature); ++ } + + if (check_variable == UPS_TEMP) { + if (check_crit==TRUE && ups_temperature>=critical_value) { +@@ -284,15 +328,17 @@ + char recv_buffer[MAX_INPUT_BUFFER]; + char temp_buffer[MAX_INPUT_BUFFER]; + char *ptr; +- +- if (get_ups_variable ("STATUS", recv_buffer, sizeof (recv_buffer)) != +- STATE_OK) { ++ int res; ++ ++ res=get_ups_variable ("ups.status", recv_buffer, sizeof (recv_buffer)); ++ if (res == NOSUCHVAR) return OK; ++ if (res != STATE_OK) { + printf ("Invalid response received from hostn"); + return ERROR; + } +- +- recv_buffer[strlen (recv_buffer) - 1] = 0; +- ++ ++ supported_options |= UPS_STATUS; ++ + strcpy (temp_buffer, recv_buffer); + for (ptr = (char *) strtok (temp_buffer, " "); ptr != NULL; + ptr = (char *) strtok (NULL, " ")) { +@@ -308,6 +354,18 @@ + status |= UPSSTATUS_CAL; + else if (!strcmp (ptr, "RB")) + status |= UPSSTATUS_RB; ++ else if (!strcmp (ptr, "BYPASS")) ++ status |= UPSSTATUS_BYPASS; ++ else if (!strcmp (ptr, "OVER")) ++ status |= UPSSTATUS_OVER; ++ else if (!strcmp (ptr, "TRIM")) ++ status |= UPSSTATUS_TRIM; ++ else if (!strcmp (ptr, "BOOST")) ++ status |= UPSSTATUS_BOOST; ++ else if (!strcmp (ptr, "CHRG")) ++ status |= UPSSTATUS_CHRG; ++ else if (!strcmp (ptr, "DISCHRG")) ++ status |= UPSSTATUS_DISCHRG; + else + status |= UPSSTATUS_UNKOWN; + } +@@ -316,55 +374,6 @@ + } + + +-/* determines what options are supported by the UPS */ +-int +-determine_supported_vars (void) +-{ +- char send_buffer[MAX_INPUT_BUFFER]; +- char recv_buffer[MAX_INPUT_BUFFER]; +- char temp_buffer[MAX_INPUT_BUFFER]; +- char *ptr; +- +- +- /* get the list of variables that this UPS supports */ +- if (ups_name) +- sprintf (send_buffer, "LISTVARS %s\r\n", ups_name); +- else +- sprintf (send_buffer, "LISTVARS\r\n"); +- if (process_tcp_request +- (server_address, server_port, send_buffer, recv_buffer, +- sizeof (recv_buffer)) != STATE_OK) { +- printf ("Invalid response received from host\n"); +- return ERROR; +- } +- +- recv_buffer[strlen (recv_buffer) - 1] = 0; +- +- if (ups_name) +- ptr = recv_buffer + 5 + strlen (ups_name) + 2; +- else +- ptr = recv_buffer + 5; +- +- strcpy (temp_buffer, recv_buffer); +- +- for (ptr = (char *) strtok (temp_buffer, " "); ptr != NULL; +- ptr = (char *) strtok (NULL, " ")) { +- if (!strcmp (ptr, "UTILITY")) +- supported_options |= UPS_UTILITY; +- else if (!strcmp (ptr, "BATTPCT")) +- supported_options |= UPS_BATTPCT; +- else if (!strcmp (ptr, "LOADPCT")) +- supported_options |= UPS_LOADPCT; +- else if (!strcmp (ptr, "STATUS")) +- supported_options |= UPS_STATUS; +- else if (!strcmp (ptr, "UPSTEMP")) +- supported_options |= UPS_TEMP; +- } +- +- return OK; +-} +- +- + /* gets a variable value for a specific UPS */ + int + get_ups_variable (const char *varname, char *buf, size_t buflen) +@@ -373,12 +382,12 @@ + char temp_buffer[MAX_INPUT_BUFFER]; + char send_buffer[MAX_INPUT_BUFFER]; + char *ptr; ++ int len; + ++ *buf=0; ++ + /* create the command string to send to the UPS daemon */ +- if (ups_name) +- sprintf (send_buffer, "REQ %s@%s\n", varname, ups_name); +- else +- sprintf (send_buffer, "REQ %s\n", varname); ++ sprintf (send_buffer, "GET VAR %s %s\n", ups_name, varname); + + /* send the command to the daemon and get a response back */ + if (process_tcp_request +@@ -388,40 +397,43 @@ + return ERROR; + } + +- if (ups_name) +- ptr = temp_buffer + strlen (varname) + 5 + strlen (ups_name) + 1; +- else +- ptr = temp_buffer + strlen (varname) + 5; +- +- if (!strcmp (ptr, "NOT-SUPPORTED")) { +- printf ("Error: Variable '%s' is not supported\n", varname); ++ ptr = temp_buffer; ++ len = strlen(ptr); ++ if (len > 0 && ptr[len-1] == '\n') ptr[len-1]=0; ++ if (strcmp (ptr, "ERR UNKNOWN-UPS") == 0) { ++ printf ("Error: no such ups '%s' on that host\n", ups_name); + return ERROR; + } + +- if (!strcmp (ptr, "DATA-STALE")) { ++ if (strcmp (ptr, "ERR VAR-NOT-SUPPORTED") == 0) { ++ //printf ("Error: Variable '%s' is not supported\n", varname); ++ return NOSUCHVAR; ++ } ++ ++ if (strcmp (ptr, "ERR DATA-STALE") == 0) { + printf ("Error: UPS data is stale\n"); + return ERROR; + } + +- if (!strcmp (ptr, "UNKNOWN-UPS")) { +- if (ups_name) +- printf ("Error: UPS '%s' is unknown\n", ups_name); +- else +- printf ("Error: UPS is unknown\n"); ++ if (strncmp (ptr, "ERR", 3) == 0) { ++ printf ("Unkown error: %s\n", ptr); + return ERROR; + } + +- strncpy (buf, ptr, buflen - 1); +- buf[buflen - 1] = 0; ++ ptr = temp_buffer + strlen (varname) + strlen (ups_name) + 6; ++ len = strlen(ptr); ++ if (len < 2 || ptr[0] != '"' || ptr[len-1] != '"') { ++ printf ("Error: unable to parse variable\n"); ++ return ERROR; ++ } ++ strncpy (buf, ptr+1, len - 2); ++ buf[len - 2] = 0; + + return OK; + } + + +- +- +- +-/* Command line: CHECK_UPS [-u ups] [-p port] [-v variable] ++/* Command line: CHECK_UPS -H -u ups [-p port] [-v variable] + [-wv warn_value] [-cv crit_value] [-to to_sec] */ + + +@@ -439,6 +451,7 @@ + {"critical", required_argument, 0, 'c'}, + {"warning", required_argument, 0, 'w'}, + {"timeout", required_argument, 0, 't'}, ++ {"temperature", no_argument, 0, 'T'}, + {"variable", required_argument, 0, 'v'}, + {"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, +@@ -458,7 +471,7 @@ + } + + while (1) { +- c = getopt_long (argc, argv, "hVH:u:p:v:c:w:t:", longopts, ++ c = getopt_long (argc, argv, "hVTH:u:p:v:c:w:t:", longopts, + &option); + + if (c == -1 || c == EOF) +@@ -475,6 +488,9 @@ + usage2 ("Invalid host name", optarg); + } + break; ++ case 'T': /* FIXME: to be improved (ie "-T C" for Celsius or "-T F" for Farenheit) */ ++ temp_output_c = 1; ++ break; + case 'u': /* ups name */ + ups_name = optarg; + break; +@@ -525,7 +541,7 @@ + } + break; + case 'V': /* version */ +- print_revision (progname, "$Revision: 1.14 $"); ++ print_revision (progname, revision); + exit (STATE_OK); + case 'h': /* help */ + print_help (); +@@ -548,20 +564,17 @@ + } + + +- +- +- + int + validate_arguments (void) + { +- return OK; ++ if (! ups_name) { ++ printf ("Error : no ups indicated\n"); ++ return ERROR; ++ } ++ return OK; + } + + +- +- +- +- + void + print_help (void) + { +@@ -571,11 +584,13 @@ + print_revision (progname, revision); + + printf (_("Copyright (c) 2000 Tom Shields")); ++ printf (_("Copyright (c) 2004 Alain Richard \n")); ++ printf (_("Copyright (c) 2004 Arnaud Quette \n")); + printf (_(COPYRIGHT), copyright, email); + + printf (_("This plugin tests the UPS service on the specified host.\n\ +-Network UPS Tools from www.exploits.org must be running for this plugin to\n\ +-work.\n\n")); ++Network UPS Tools from www.networkupstools.org must be running for this \n\ ++plugin to work.\n\n")); + + print_usage (); + +@@ -587,6 +602,9 @@ + -u, --ups=STRING\n\ + Name of UPS\n")); + ++ printf (_("-T, --temperature\n\ ++ Output of temperatures in Celsius\n")); ++ + printf (_(UT_WARN_CRIT)); + + printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); +@@ -607,10 +625,10 @@ + will have to use the [ups] option to specify which UPS to check.\n\n")); + + printf (_("Notes:\n\n\ +-This plugin requires that the UPSD daemon distributed with Russel Kroll's\n\ +-Smart UPS Tools be installed on the remote host. If you do not have the\n\ ++This plugin requires that the UPSD daemon distributed with the NUT - Network\n\ ++UPS Tools to be installed on the remote host. If you do not have the\n\ + package installed on your system, you can download it from\n\ +-http://www.exploits.org/nut\n\n")); ++http://www.networkupstools.org\n\n")); + + printf (_(UT_SUPPORT)); + } +@@ -622,7 +640,7 @@ + print_usage (void) + { + printf (_("\ +-Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit]\n\ +- [-t timeout] [-v]\n"), progname); ++Usage: %s -H host -u ups [-p port] [-v variable] [-wv warn_value] [-cv crit_value] [-to to_sec] [-T]\n"), progname); + printf (_(UT_HLP_VRS), progname, progname); + } ++ +diff -ru nagiosplug/REQUIREMENTS nagiosplug_AQ/REQUIREMENTS +--- nagiosplug/REQUIREMENTS 2004-04-29 13:12:20.000000000 +0200 ++++ nagiosplug_AQ/REQUIREMENTS 2004-10-01 12:42:55.000000000 +0200 +@@ -65,6 +65,9 @@ + - Requires NSClient to run on the NT server to monitor + http://nsclient.ready2run.nl/ + ++check_ups: ++ - Requires Network UPS Tools (>= 1.4) to run on the server to monitor ++ http://www.networkupstools.org/ + + OS Specific Issues + ------------------ -- cgit v1.2.3-74-g34f1