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.c148
1 files changed, 81 insertions, 67 deletions
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index 499b9222..fcee7477 100644
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
@@ -29,68 +29,6 @@ enum {
29 PORT = 3493 29 PORT = 3493
30}; 30};
31 31
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));
67
68 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
69
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 32#define CHECK_NONE 0
95 33
96#define UPS_NONE 0 /* no supported options */ 34#define UPS_NONE 0 /* no supported options */
@@ -110,7 +48,7 @@ http://www.exploits.org/nut\n\n"));
110#define UPSSTATUS_UNKOWN 64 48#define UPSSTATUS_UNKOWN 64
111 49
112int server_port = PORT; 50int server_port = PORT;
113char *server_address = "127.0.0.1"; 51char *server_address;
114char *ups_name = NULL; 52char *ups_name = NULL;
115double warning_value = 0.0; 53double warning_value = 0.0;
116double critical_value = 0.0; 54double critical_value = 0.0;
@@ -124,14 +62,16 @@ double ups_utility_voltage = 0.0;
124double ups_battery_percent = 0.0; 62double ups_battery_percent = 0.0;
125double ups_load_percent = 0.0; 63double ups_load_percent = 0.0;
126double ups_temperature = 0.0; 64double ups_temperature = 0.0;
127char *ups_status = "N/A"; 65char *ups_status;
128 66
129int determine_status (void); 67int determine_status (void);
130int determine_supported_vars (void); 68int determine_supported_vars (void);
131int get_ups_variable (const char *, char *, int); 69int get_ups_variable (const char *, char *, size_t);
132 70
133int process_arguments (int, char **); 71int process_arguments (int, char **);
134int validate_arguments (void); 72int validate_arguments (void);
73void print_help (void);
74void print_usage (void);
135 75
136int 76int
137main (int argc, char **argv) 77main (int argc, char **argv)
@@ -141,6 +81,7 @@ main (int argc, char **argv)
141 char temp_buffer[MAX_INPUT_BUFFER]; 81 char temp_buffer[MAX_INPUT_BUFFER];
142 82
143 double ups_utility_deviation = 0.0; 83 double ups_utility_deviation = 0.0;
84 ups_status = strdup ("N/A");
144 85
145 if (process_arguments (argc, argv) != OK) 86 if (process_arguments (argc, argv) != OK)
146 usage ("Invalid command arguments supplied\n"); 87 usage ("Invalid command arguments supplied\n");
@@ -160,7 +101,7 @@ main (int argc, char **argv)
160 101
161 if (determine_status () != OK) 102 if (determine_status () != OK)
162 return STATE_CRITICAL; 103 return STATE_CRITICAL;
163 asprintf (&ups_status, ""); 104 ups_status = strdup ("");
164 result = STATE_OK; 105 result = STATE_OK;
165 106
166 if (status & UPSSTATUS_OFF) { 107 if (status & UPSSTATUS_OFF) {
@@ -395,7 +336,7 @@ determine_supported_vars (void)
395 336
396/* gets a variable value for a specific UPS */ 337/* gets a variable value for a specific UPS */
397int 338int
398get_ups_variable (const char *varname, char *buf, int buflen) 339get_ups_variable (const char *varname, char *buf, size_t buflen)
399{ 340{
400 /* char command[MAX_INPUT_BUFFER]; */ 341 /* char command[MAX_INPUT_BUFFER]; */
401 char temp_buffer[MAX_INPUT_BUFFER]; 342 char temp_buffer[MAX_INPUT_BUFFER];
@@ -569,6 +510,9 @@ process_arguments (int argc, char **argv)
569 usage ("Invalid host name"); 510 usage ("Invalid host name");
570 } 511 }
571 512
513 if (server_address == NULL)
514 server_address = strdup("127.0.0.1");
515
572 return validate_arguments(); 516 return validate_arguments();
573} 517}
574 518
@@ -581,3 +525,73 @@ validate_arguments (void)
581{ 525{
582 return OK; 526 return OK;
583} 527}
528
529
530
531
532
533
534void
535print_help (void)
536{
537 char *myport;
538 asprintf (&myport, "%d", PORT);
539
540 print_revision (progname, revision);
541
542 printf (_("Copyright (c) 2000 Tom Shields"));
543 printf (_(COPYRIGHT), copyright, email);
544
545 printf (_("This plugin tests the UPS service on the specified host.\n\
546Network UPS Tools from www.exploits.org must be running for this plugin to\n\
547work.\n\n"));
548
549 print_usage ();
550
551 printf (_(UT_HELP_VRSN));
552
553 printf (_(UT_HOST_PORT), 'p', myport);
554
555 printf (_("\
556 -u, --ups=STRING\n\
557 Name of UPS\n"));
558
559 printf (_(UT_WARN_CRIT));
560
561 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
562
563 printf (_(UT_VERBOSE));
564
565 printf (_("\
566This plugin attempts to determine the status of a UPS (Uninterruptible Power\n\
567Supply) on a local or remote host. If the UPS is online or calibrating, the\n\
568plugin will return an OK state. If the battery is on it will return a WARNING\n\
569state. If the UPS is off or has a low battery the plugin will return a CRITICAL\n\
570state.\n\n"));
571
572 printf (_("\
573You may also specify a variable to check [such as temperature, utility voltage,\n\
574battery load, etc.] as well as warning and critical thresholds for the value of\n\
575that variable. If the remote host has multiple UPS that are being monitored you\n\
576will have to use the [ups] option to specify which UPS to check.\n\n"));
577
578 printf (_("Notes:\n\n\
579This plugin requires that the UPSD daemon distributed with Russel Kroll's\n\
580Smart UPS Tools be installed on the remote host. If you do not have the\n\
581package installed on your system, you can download it from\n\
582http://www.exploits.org/nut\n\n"));
583
584 printf (_(UT_SUPPORT));
585}
586
587
588
589
590void
591print_usage (void)
592{
593 printf (_("\
594Usage: %s -H host [-e expect] [-p port] [-w warn] [-c crit]\n\
595 [-t timeout] [-v]\n"), progname);
596 printf (_(UT_HLP_VRS), progname, progname);
597}