summaryrefslogtreecommitdiffstats
path: root/plugins/check_ups.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_ups.c')
-rw-r--r--plugins/check_ups.c209
1 files changed, 92 insertions, 117 deletions
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index b077d31f..499b9222 100644
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
@@ -1,70 +1,97 @@
1/****************************************************************************** 1/******************************************************************************
2* 2
3* CHECK_UPS.C 3 This program is free software; you can redistribute it and/or modify
4* 4 it under the terms of the GNU General Public License as published by
5* Program: UPS monitor plugin for Nagios 5 the Free Software Foundation; either version 2 of the License, or (at
6* License: GPL 6 your option) any later version.
7* Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) 7
8* 8 This program is distributed in the hope that it will be useful, but
9* Last Modified: $Date$ 9 WITHOUT ANY WARRANTY; without even the implied warranty of
10* 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11* Command line: CHECK_UPS <host_address> [-u ups] [-p port] [-v variable] \ 11 General Public License for more details.
12* [-wv warn_value] [-cv crit_value] [-to to_sec] 12
13* 13 You should have received a copy of the GNU General Public License
14* Description: 14 along with this program; if not, write to the Free Software
15* 15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 16
17* This plugin attempts to determine the status of an UPS
18* (Uninterruptible Power Supply) on a remote host (or the local host)
19* that is being monitored with Russel Kroll's "Smarty UPS Tools"
20* package. If the UPS is online or calibrating, the plugin will
21* return an OK state. If the battery is on it will return a WARNING
22* state. If the UPS is off or has a low battery the plugin will
23* return a CRITICAL state. You may also specify a variable to check
24* (such as temperature, utility voltage, battery load, etc.) as well
25* as warning and critical thresholds for the value of that variable.
26* If the remote host has multiple UPS that are being monitored you
27* will have to use the [ups] option to specify which UPS to check.
28*
29* Notes:
30*
31* This plugin requires that the UPSD daemon distributed with Russel
32* Kroll's "Smart UPS Tools" be installed on the remote host. If you
33* don't have the package installed on your system, you can download
34* it from http://www.exploits.org/nut
35*
36* License Information:
37*
38* This program is free software; you can redistribute it and/or modify
39* it under the terms of the GNU General Public License as published by
40* the Free Software Foundation; either version 2 of the License, or
41* (at your option) any later version.
42*
43* This program is distributed in the hope that it will be useful,
44* but WITHOUT ANY WARRANTY; without even the implied warranty of
45* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46* GNU General Public License for more details.
47*
48* You should have received a copy of the GNU General Public License
49* along with this program; if not, write to the Free Software
50* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
51*
52******************************************************************************/ 17******************************************************************************/
53 18
54#include "config.h" 19const char *progname = "check_ups";
20const char *revision = "$Revision$";
21const char *copyright = "2000-2002";
22const char *email = "nagiosplug-devel@lists.sourceforge.net";
23
55#include "common.h" 24#include "common.h"
56#include "netutils.h" 25#include "netutils.h"
57#include "utils.h" 26#include "utils.h"
58 27
59const char *progname = "check_ups"; 28enum {
60#define REVISION "$Revision$" 29 PORT = 3493
61#define COPYRIGHT "1999-2002" 30};
62#define AUTHOR "Ethan Galstad" 31
63#define EMAIL "nagios@nagios.org" 32void
33print_usage (void)
34{
35 printf (_("\
36Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit]\n\
37 [-t timeout] [-v]\n"), progname);
38 printf (_(UT_HLP_VRS), progname, progname);
39}
40
41void
42print_help (void)
43{
44 char *myport;
45 asprintf (&myport, "%d", PORT);
46
47 print_revision (progname, revision);
48
49 printf (_("Copyright (c) 2000 Tom Shields"));
50 printf (_(COPYRIGHT), copyright, email);
51
52 printf (_("This plugin tests the UPS service on the specified host.\n\
53Network UPS Tools from www.exploits.org must be running for this plugin to\n\
54work.\n\n"));
55
56 print_usage ();
57
58 printf (_(UT_HELP_VRSN));
59
60 printf (_(UT_HOST_PORT), 'p', myport);
61
62 printf (_("\
63 -u, --ups=STRING\n\
64 Name of UPS\n"));
65
66 printf (_(UT_WARN_CRIT));
64 67
65#define CHECK_NONE 0 68 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
66 69
67#define PORT 3493 70 printf (_(UT_VERBOSE));
71
72 printf (_("\
73This plugin attempts to determine the status of a UPS (Uninterruptible Power\n\
74Supply) on a local or remote host. If the UPS is online or calibrating, the\n\
75plugin will return an OK state. If the battery is on it will return a WARNING\n\
76state. If the UPS is off or has a low battery the plugin will return a CRITICAL\n\
77state.\n\n"));
78
79 printf (_("\
80You may also specify a variable to check [such as temperature, utility voltage,\n\
81battery load, etc.] as well as warning and critical thresholds for the value of\n\
82that variable. If the remote host has multiple UPS that are being monitored you\n\
83will have to use the [ups] option to specify which UPS to check.\n\n"));
84
85 printf (_("Notes:\n\n\
86This plugin requires that the UPSD daemon distributed with Russel Kroll's\n\
87Smart UPS Tools be installed on the remote host. If you do not have the\n\
88package installed on your system, you can download it from\n\
89http://www.exploits.org/nut\n\n"));
90
91 printf (_(UT_SUPPORT));
92}
93
94#define CHECK_NONE 0
68 95
69#define UPS_NONE 0 /* no supported options */ 96#define UPS_NONE 0 /* no supported options */
70#define UPS_UTILITY 1 /* supports utility line voltage */ 97#define UPS_UTILITY 1 /* supports utility line voltage */
@@ -85,18 +112,18 @@ const char *progname = "check_ups";
85int server_port = PORT; 112int server_port = PORT;
86char *server_address = "127.0.0.1"; 113char *server_address = "127.0.0.1";
87char *ups_name = NULL; 114char *ups_name = NULL;
88double warning_value = 0.0L; 115double warning_value = 0.0;
89double critical_value = 0.0L; 116double critical_value = 0.0;
90int check_warning_value = FALSE; 117int check_warning_value = FALSE;
91int check_critical_value = FALSE; 118int check_critical_value = FALSE;
92int check_variable = UPS_NONE; 119int check_variable = UPS_NONE;
93int supported_options = UPS_NONE; 120int supported_options = UPS_NONE;
94int status = UPSSTATUS_NONE; 121int status = UPSSTATUS_NONE;
95 122
96double ups_utility_voltage = 0.0L; 123double ups_utility_voltage = 0.0;
97double ups_battery_percent = 0.0L; 124double ups_battery_percent = 0.0;
98double ups_load_percent = 0.0L; 125double ups_load_percent = 0.0;
99double ups_temperature = 0.0L; 126double ups_temperature = 0.0;
100char *ups_status = "N/A"; 127char *ups_status = "N/A";
101 128
102int determine_status (void); 129int determine_status (void);
@@ -105,8 +132,6 @@ int get_ups_variable (const char *, char *, int);
105 132
106int process_arguments (int, char **); 133int process_arguments (int, char **);
107int validate_arguments (void); 134int validate_arguments (void);
108void print_help (void);
109void print_usage (void);
110 135
111int 136int
112main (int argc, char **argv) 137main (int argc, char **argv)
@@ -115,7 +140,7 @@ main (int argc, char **argv)
115 char *message; 140 char *message;
116 char temp_buffer[MAX_INPUT_BUFFER]; 141 char temp_buffer[MAX_INPUT_BUFFER];
117 142
118 double ups_utility_deviation = 0.0L; 143 double ups_utility_deviation = 0.0;
119 144
120 if (process_arguments (argc, argv) != OK) 145 if (process_arguments (argc, argv) != OK)
121 usage ("Invalid command arguments supplied\n"); 146 usage ("Invalid command arguments supplied\n");
@@ -556,53 +581,3 @@ validate_arguments (void)
556{ 581{
557 return OK; 582 return OK;
558} 583}
559
560
561
562
563
564void
565print_help (void)
566{
567 print_revision (progname, "$Revision$");
568 printf
569 ("Copyright (c) 2000 Tom Shields/Karl DeBisschop\n\n"
570 "This plugin tests the UPS service on the specified host.\n"
571 "Newtork UPS Tools for www.exploits.org must be running for this plugin to work.\n\n");
572 print_usage ();
573 printf
574 ("\nOptions:\n"
575 " -H, --hostname=STRING or IPADDRESS\n"
576 " Check server on the indicated host\n"
577 " -p, --port=INTEGER\n"
578 " Make connection on the indicated port (default: %d)\n"
579 " -u, --ups=STRING\n"
580 " Name of UPS\n"
581 " -w, --warning=INTEGER\n"
582 " Seconds necessary to result in a warning status\n"
583 " -c, --critical=INTEGER\n"
584 " Seconds necessary to result in a critical status\n"
585 " -t, --timeout=INTEGER\n"
586 " Seconds before connection attempt times out (default: %d)\n"
587 " -v, --verbose\n"
588 " Print extra information (command-line use only)\n"
589 " -h, --help\n"
590 " Print detailed help screen\n"
591 " -V, --version\n"
592 " Print version information\n\n", PORT, DEFAULT_SOCKET_TIMEOUT);
593 support ();
594}
595
596
597
598
599
600void
601print_usage (void)
602{
603 printf
604 ("Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit]\n"
605 " [-t timeout] [-v]\n"
606 " %s --help\n"
607 " %s --version\n", progname, progname, progname);
608}