check_ups.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*****************************************************************************
  2. *
  3. * Nagios check_ups plugin
  4. *
  5. * License: GPL
  6. * Copyright (c) 2000 Tom Shields
  7. * 2004 Alain Richard <alain.richard@equation.fr>
  8. * 2004 Arnaud Quette <arnaud.quette@mgeups.com>
  9. * Copyright (c) 2002-2014 Nagios Plugins Development Team
  10. *
  11. * Description:
  12. *
  13. * This file contains Network UPS Tools plugin for Nagios
  14. *
  15. * This plugin tests the UPS service on the specified host. Network UPS Tools
  16. * from www.networkupstools.org must be running for this plugin to work.
  17. *
  18. *
  19. * This program is free software: you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation, either version 3 of the License, or
  22. * (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. *
  32. *
  33. *****************************************************************************/
  34. const char *progname = "check_ups";
  35. const char *copyright = "2000-2014";
  36. const char *email = "devel@nagios-plugins.org";
  37. #include "common.h"
  38. #include "netutils.h"
  39. #include "utils.h"
  40. enum {
  41. PORT = 3493
  42. };
  43. #define CHECK_NONE 0
  44. #define UPS_NONE 0 /* no supported options */
  45. #define UPS_UTILITY 1 /* supports utility line voltage */
  46. #define UPS_BATTPCT 2 /* supports percent battery remaining */
  47. #define UPS_STATUS 4 /* supports UPS status */
  48. #define UPS_TEMP 8 /* supports UPS temperature */
  49. #define UPS_LOADPCT 16 /* supports load percent */
  50. #define UPSSTATUS_NONE 0
  51. #define UPSSTATUS_OFF 1
  52. #define UPSSTATUS_OL 2
  53. #define UPSSTATUS_OB 4
  54. #define UPSSTATUS_LB 8
  55. #define UPSSTATUS_CAL 16
  56. #define UPSSTATUS_RB 32 /*Replace Battery */
  57. #define UPSSTATUS_BYPASS 64
  58. #define UPSSTATUS_OVER 128
  59. #define UPSSTATUS_TRIM 256
  60. #define UPSSTATUS_BOOST 512
  61. #define UPSSTATUS_CHRG 1024
  62. #define UPSSTATUS_DISCHRG 2048
  63. #define UPSSTATUS_UNKNOWN 4096
  64. enum { NOSUCHVAR = ERROR-1 };
  65. int server_port = PORT;
  66. char *server_address;
  67. char *ups_name = NULL;
  68. double warning_value = 0.0;
  69. double critical_value = 0.0;
  70. int check_warn = FALSE;
  71. int check_crit = FALSE;
  72. int check_variable = UPS_NONE;
  73. int supported_options = UPS_NONE;
  74. int status = UPSSTATUS_NONE;
  75. static int extended_units = 0;
  76. double ups_utility_voltage = 0.0;
  77. double ups_battery_percent = 0.0;
  78. double ups_load_percent = 0.0;
  79. double ups_temperature = 0.0;
  80. char *ups_status;
  81. int temp_output_c = 0;
  82. int determine_status (void);
  83. int get_ups_variable (const char *, char *, size_t);
  84. int process_arguments (int, char **);
  85. int validate_arguments (void);
  86. void print_help (void);
  87. void print_usage (void);
  88. int
  89. main (int argc, char **argv)
  90. {
  91. int result = STATE_UNKNOWN;
  92. char *message;
  93. char *data;
  94. char *tunits;
  95. char temp_buffer[MAX_INPUT_BUFFER];
  96. double ups_utility_deviation = 0.0;
  97. int res;
  98. setlocale (LC_ALL, "");
  99. bindtextdomain (PACKAGE, LOCALEDIR);
  100. textdomain (PACKAGE);
  101. ups_status = strdup ("N/A");
  102. data = strdup ("");
  103. message = strdup ("");
  104. /* Parse extra opts if any */
  105. argv=np_extra_opts (&argc, argv, progname);
  106. if (process_arguments (argc, argv) == ERROR)
  107. usage4 (_("Could not parse arguments"));
  108. /* initialize alarm signal handling */
  109. signal (SIGALRM, socket_timeout_alarm_handler);
  110. /* set socket timeout */
  111. alarm (timeout_interval);
  112. /* get the ups status if possible */
  113. if (determine_status () != OK)
  114. return STATE_CRITICAL;
  115. if (supported_options & UPS_STATUS) {
  116. ups_status = strdup ("");
  117. result = STATE_OK;
  118. if (status & UPSSTATUS_OFF) {
  119. xasprintf (&ups_status, "Off");
  120. result = STATE_CRITICAL;
  121. }
  122. else if ((status & (UPSSTATUS_OB | UPSSTATUS_LB)) ==
  123. (UPSSTATUS_OB | UPSSTATUS_LB)) {
  124. xasprintf (&ups_status, _("On Battery, Low Battery"));
  125. result = STATE_CRITICAL;
  126. }
  127. else {
  128. if (status & UPSSTATUS_OL) {
  129. xasprintf (&ups_status, "%s%s", ups_status, _("Online"));
  130. }
  131. if (status & UPSSTATUS_OB) {
  132. xasprintf (&ups_status, "%s%s", ups_status, _("On Battery"));
  133. result = STATE_WARNING;
  134. }
  135. if (status & UPSSTATUS_LB) {
  136. xasprintf (&ups_status, "%s%s", ups_status, _(", Low Battery"));
  137. result = STATE_WARNING;
  138. }
  139. if (status & UPSSTATUS_CAL) {
  140. xasprintf (&ups_status, "%s%s", ups_status, _(", Calibrating"));
  141. }
  142. if (status & UPSSTATUS_RB) {
  143. xasprintf (&ups_status, "%s%s", ups_status, _(", Replace Battery"));
  144. result = STATE_WARNING;
  145. }
  146. if (status & UPSSTATUS_BYPASS) {
  147. xasprintf (&ups_status, "%s%s", ups_status, _(", On Bypass"));
  148. }
  149. if (status & UPSSTATUS_OVER) {
  150. xasprintf (&ups_status, "%s%s", ups_status, _(", Overload"));
  151. }
  152. if (status & UPSSTATUS_TRIM) {
  153. xasprintf (&ups_status, "%s%s", ups_status, _(", Trimming"));
  154. }
  155. if (status & UPSSTATUS_BOOST) {
  156. xasprintf (&ups_status, "%s%s", ups_status, _(", Boosting"));
  157. }
  158. if (status & UPSSTATUS_CHRG) {
  159. xasprintf (&ups_status, "%s%s", ups_status, _(", Charging"));
  160. }
  161. if (status & UPSSTATUS_DISCHRG) {
  162. xasprintf (&ups_status, "%s%s", ups_status, _(", Discharging"));
  163. }
  164. if (status & UPSSTATUS_UNKNOWN) {
  165. xasprintf (&ups_status, "%s%s", ups_status, _(", Unknown"));
  166. }
  167. }
  168. xasprintf (&message, "%sStatus=%s ", message, ups_status);
  169. }
  170. /* get the ups utility voltage if possible */
  171. res=get_ups_variable ("input.voltage", temp_buffer, sizeof (temp_buffer));
  172. if (res == NOSUCHVAR) supported_options &= ~UPS_UTILITY;
  173. else if (res != OK)
  174. return STATE_CRITICAL;
  175. else {
  176. supported_options |= UPS_UTILITY;
  177. ups_utility_voltage = atof (temp_buffer);
  178. xasprintf (&message, "%sUtility=%3.1fV ", message, ups_utility_voltage);
  179. if (ups_utility_voltage > 120.0)
  180. ups_utility_deviation = 120.0 - ups_utility_voltage;
  181. else
  182. ups_utility_deviation = ups_utility_voltage - 120.0;
  183. if (check_variable == UPS_UTILITY) {
  184. if (check_crit==TRUE && ups_utility_deviation>=critical_value) {
  185. result = STATE_CRITICAL;
  186. }
  187. else if (check_warn==TRUE && ups_utility_deviation>=warning_value) {
  188. result = max_state (result, STATE_WARNING);
  189. }
  190. xasprintf (&data, "%s",
  191. fperfdata ("voltage", ups_utility_voltage, (extended_units ? "V" : ""),
  192. check_warn, warning_value,
  193. check_crit, critical_value,
  194. TRUE, 0, FALSE, 0));
  195. } else {
  196. xasprintf (&data, "%s",
  197. fperfdata ("voltage", ups_utility_voltage, (extended_units ? "V" : ""),
  198. FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
  199. }
  200. }
  201. /* get the ups battery percent if possible */
  202. res=get_ups_variable ("battery.charge", temp_buffer, sizeof (temp_buffer));
  203. if (res == NOSUCHVAR) supported_options &= ~UPS_BATTPCT;
  204. else if ( res != OK)
  205. return STATE_CRITICAL;
  206. else {
  207. supported_options |= UPS_BATTPCT;
  208. ups_battery_percent = atof (temp_buffer);
  209. xasprintf (&message, "%sBatt=%3.1f%% ", message, ups_battery_percent);
  210. if (check_variable == UPS_BATTPCT) {
  211. if (check_crit==TRUE && ups_battery_percent <= critical_value) {
  212. result = STATE_CRITICAL;
  213. }
  214. else if (check_warn==TRUE && ups_battery_percent<=warning_value) {
  215. result = max_state (result, STATE_WARNING);
  216. }
  217. xasprintf (&data, "%s %s", data,
  218. fperfdata ("battery", ups_battery_percent, "%",
  219. check_warn, warning_value,
  220. check_crit, critical_value,
  221. TRUE, 0, TRUE, 100));
  222. } else {
  223. xasprintf (&data, "%s %s", data,
  224. fperfdata ("battery", ups_battery_percent, "%",
  225. FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100));
  226. }
  227. }
  228. /* get the ups load percent if possible */
  229. res=get_ups_variable ("ups.load", temp_buffer, sizeof (temp_buffer));
  230. if ( res == NOSUCHVAR ) supported_options &= ~UPS_LOADPCT;
  231. else if ( res != OK)
  232. return STATE_CRITICAL;
  233. else {
  234. supported_options |= UPS_LOADPCT;
  235. ups_load_percent = atof (temp_buffer);
  236. xasprintf (&message, "%sLoad=%3.1f%% ", message, ups_load_percent);
  237. if (check_variable == UPS_LOADPCT) {
  238. if (check_crit==TRUE && ups_load_percent>=critical_value) {
  239. result = STATE_CRITICAL;
  240. }
  241. else if (check_warn==TRUE && ups_load_percent>=warning_value) {
  242. result = max_state (result, STATE_WARNING);
  243. }
  244. xasprintf (&data, "%s %s", data,
  245. fperfdata ("load", ups_load_percent, "%",
  246. check_warn, warning_value,
  247. check_crit, critical_value,
  248. TRUE, 0, TRUE, 100));
  249. } else {
  250. xasprintf (&data, "%s %s", data,
  251. fperfdata ("load", ups_load_percent, "%",
  252. FALSE, 0, FALSE, 0, TRUE, 0, TRUE, 100));
  253. }
  254. }
  255. /* get the ups temperature if possible */
  256. res=get_ups_variable ("ups.temperature", temp_buffer, sizeof (temp_buffer));
  257. if ( res == NOSUCHVAR ) supported_options &= ~UPS_TEMP;
  258. else if ( res != OK)
  259. return STATE_CRITICAL;
  260. else {
  261. supported_options |= UPS_TEMP;
  262. if (temp_output_c) {
  263. tunits="degC";
  264. ups_temperature = atof (temp_buffer);
  265. xasprintf (&message, "%sTemp=%3.1fC", message, ups_temperature);
  266. }
  267. else {
  268. tunits="degF";
  269. ups_temperature = (atof (temp_buffer) * 1.8) + 32;
  270. xasprintf (&message, "%sTemp=%3.1fF", message, ups_temperature);
  271. }
  272. if (check_variable == UPS_TEMP) {
  273. if (check_crit==TRUE && ups_temperature>=critical_value) {
  274. result = STATE_CRITICAL;
  275. }
  276. else if (check_warn == TRUE && ups_temperature>=warning_value) {
  277. result = max_state (result, STATE_WARNING);
  278. }
  279. xasprintf (&data, "%s %s", data,
  280. fperfdata ("temp", ups_temperature, (extended_units ? tunits : ""),
  281. check_warn, warning_value,
  282. check_crit, critical_value,
  283. TRUE, 0, FALSE, 0));
  284. } else {
  285. xasprintf (&data, "%s %s", data,
  286. fperfdata ("temp", ups_temperature, (extended_units ? tunits : ""),
  287. FALSE, 0, FALSE, 0, TRUE, 0, FALSE, 0));
  288. }
  289. }
  290. /* if the UPS does not support any options we are looking for, report an error */
  291. if (supported_options == UPS_NONE) {
  292. result = STATE_CRITICAL;
  293. xasprintf (&message, _("UPS does not support any available options\n"));
  294. }
  295. /* reset timeout */
  296. alarm (0);
  297. printf ("UPS %s - %s|%s\n", state_text(result), message, data);
  298. return result;
  299. }
  300. /* determines what options are supported by the UPS */
  301. int
  302. determine_status (void)
  303. {
  304. char recv_buffer[MAX_INPUT_BUFFER];
  305. char temp_buffer[MAX_INPUT_BUFFER];
  306. char *ptr;
  307. int res;
  308. res=get_ups_variable ("ups.status", recv_buffer, sizeof (recv_buffer));
  309. if (res == NOSUCHVAR) return OK;
  310. if (res != STATE_OK) {
  311. printf ("%s\n", _("Invalid response received from host"));
  312. return ERROR;
  313. }
  314. supported_options |= UPS_STATUS;
  315. strcpy (temp_buffer, recv_buffer);
  316. for (ptr = (char *) strtok (temp_buffer, " "); ptr != NULL;
  317. ptr = (char *) strtok (NULL, " ")) {
  318. if (!strcmp (ptr, "OFF"))
  319. status |= UPSSTATUS_OFF;
  320. else if (!strcmp (ptr, "OL"))
  321. status |= UPSSTATUS_OL;
  322. else if (!strcmp (ptr, "OB"))
  323. status |= UPSSTATUS_OB;
  324. else if (!strcmp (ptr, "LB"))
  325. status |= UPSSTATUS_LB;
  326. else if (!strcmp (ptr, "CAL"))
  327. status |= UPSSTATUS_CAL;
  328. else if (!strcmp (ptr, "RB"))
  329. status |= UPSSTATUS_RB;
  330. else if (!strcmp (ptr, "BYPASS"))
  331. status |= UPSSTATUS_BYPASS;
  332. else if (!strcmp (ptr, "OVER"))
  333. status |= UPSSTATUS_OVER;
  334. else if (!strcmp (ptr, "TRIM"))
  335. status |= UPSSTATUS_TRIM;
  336. else if (!strcmp (ptr, "BOOST"))
  337. status |= UPSSTATUS_BOOST;
  338. else if (!strcmp (ptr, "CHRG"))
  339. status |= UPSSTATUS_CHRG;
  340. else if (!strcmp (ptr, "DISCHRG"))
  341. status |= UPSSTATUS_DISCHRG;
  342. else
  343. status |= UPSSTATUS_UNKNOWN;
  344. }
  345. return OK;
  346. }
  347. /* gets a variable value for a specific UPS */
  348. int
  349. get_ups_variable (const char *varname, char *buf, size_t buflen)
  350. {
  351. /* char command[MAX_INPUT_BUFFER]; */
  352. char temp_buffer[MAX_INPUT_BUFFER];
  353. char send_buffer[MAX_INPUT_BUFFER];
  354. char *ptr;
  355. char *logout = "OK Goodbye\n";
  356. int logout_len = strlen(logout);
  357. int len;
  358. *buf=0;
  359. /* create the command string to send to the UPS daemon */
  360. /* Add LOGOUT to avoid read failure logs */
  361. sprintf (send_buffer, "GET VAR %s %s\nLOGOUT\n", ups_name, varname);
  362. /* send the command to the daemon and get a response back */
  363. if (process_tcp_request
  364. (server_address, server_port, send_buffer, temp_buffer,
  365. sizeof (temp_buffer)) != STATE_OK) {
  366. printf ("%s\n", _("Invalid response received from host"));
  367. return ERROR;
  368. }
  369. ptr = temp_buffer;
  370. len = strlen(ptr);
  371. if (len > logout_len && strcmp (ptr + len - logout_len, logout) == 0) len -= logout_len;
  372. if (len > 0 && ptr[len-1] == '\n') ptr[len-1]=0;
  373. if (strcmp (ptr, "ERR UNKNOWN-UPS") == 0) {
  374. printf (_("CRITICAL - no such UPS '%s' on that host\n"), ups_name);
  375. return ERROR;
  376. }
  377. if (strcmp (ptr, "ERR VAR-NOT-SUPPORTED") == 0) {
  378. /*printf ("Error: Variable '%s' is not supported\n", varname);*/
  379. return NOSUCHVAR;
  380. }
  381. if (strcmp (ptr, "ERR DATA-STALE") == 0) {
  382. printf ("%s\n", _("CRITICAL - UPS data is stale"));
  383. return ERROR;
  384. }
  385. if (strncmp (ptr, "ERR", 3) == 0) {
  386. printf (_("Unknown error: %s\n"), ptr);
  387. return ERROR;
  388. }
  389. ptr = temp_buffer + strlen (varname) + strlen (ups_name) + 6;
  390. len = strlen(ptr);
  391. if (len < 2 || ptr[0] != '"' || ptr[len-1] != '"') {
  392. printf ("%s\n", _("Error: unable to parse variable"));
  393. return ERROR;
  394. }
  395. strncpy (buf, ptr+1, len - 2);
  396. buf[len - 2] = 0;
  397. return OK;
  398. }
  399. /* Command line: CHECK_UPS -H <host_address> -u ups [-p port] [-v variable]
  400. [-wv warn_value] [-cv crit_value] [-to to_sec] */
  401. /* process command-line arguments */
  402. int
  403. process_arguments (int argc, char **argv)
  404. {
  405. int c;
  406. int option = 0;
  407. static struct option longopts[] = {
  408. {"hostname", required_argument, 0, 'H'},
  409. {"ups", required_argument, 0, 'u'},
  410. {"port", required_argument, 0, 'p'},
  411. {"critical", required_argument, 0, 'c'},
  412. {"warning", required_argument, 0, 'w'},
  413. {"extended-units", no_argument, 0, 'e'},
  414. {"timeout", required_argument, 0, 't'},
  415. {"temperature", no_argument, 0, 'T'},
  416. {"variable", required_argument, 0, 'v'},
  417. {"version", no_argument, 0, 'V'},
  418. {"help", no_argument, 0, 'h'},
  419. {0, 0, 0, 0}
  420. };
  421. if (argc < 2)
  422. return ERROR;
  423. for (c = 1; c < argc; c++) {
  424. if (strcmp ("-to", argv[c]) == 0)
  425. strcpy (argv[c], "-t");
  426. else if (strcmp ("-wt", argv[c]) == 0)
  427. strcpy (argv[c], "-w");
  428. else if (strcmp ("-ct", argv[c]) == 0)
  429. strcpy (argv[c], "-c");
  430. }
  431. while (1) {
  432. c = getopt_long (argc, argv, "hVTH:u:p:v:c:w:t:", longopts,
  433. &option);
  434. if (c == -1 || c == EOF)
  435. break;
  436. switch (c) {
  437. case '?': /* help */
  438. usage5 ();
  439. case 'H': /* hostname */
  440. if (is_host (optarg)) {
  441. server_address = optarg;
  442. }
  443. else {
  444. usage2 (_("Invalid hostname/address"), optarg);
  445. }
  446. break;
  447. case 'T': /* FIXME: to be improved (ie "-T C" for Celsius or "-T F" for Farenheit) */
  448. temp_output_c = 1;
  449. break;
  450. case 'u': /* ups name */
  451. ups_name = optarg;
  452. break;
  453. case 'p': /* port */
  454. if (is_intpos (optarg)) {
  455. server_port = atoi (optarg);
  456. }
  457. else {
  458. usage2 (_("Port must be a positive integer"), optarg);
  459. }
  460. break;
  461. case 'c': /* critical time threshold */
  462. if (is_intnonneg (optarg)) {
  463. critical_value = atoi (optarg);
  464. check_crit = TRUE;
  465. }
  466. else {
  467. usage2 (_("Critical time must be a positive integer"), optarg);
  468. }
  469. break;
  470. case 'w': /* warning time threshold */
  471. if (is_intnonneg (optarg)) {
  472. warning_value = atoi (optarg);
  473. check_warn = TRUE;
  474. }
  475. else {
  476. usage2 (_("Warning time must be a positive integer"), optarg);
  477. }
  478. break;
  479. case 'e':
  480. extended_units = 1;
  481. break;
  482. case 'v': /* variable */
  483. if (!strcmp (optarg, "LINE"))
  484. check_variable = UPS_UTILITY;
  485. else if (!strcmp (optarg, "TEMP"))
  486. check_variable = UPS_TEMP;
  487. else if (!strcmp (optarg, "BATTPCT"))
  488. check_variable = UPS_BATTPCT;
  489. else if (!strcmp (optarg, "LOADPCT"))
  490. check_variable = UPS_LOADPCT;
  491. else
  492. usage2 (_("Unrecognized UPS variable"), optarg);
  493. break;
  494. case 't': /* timeout */
  495. timeout_interval = parse_timeout_string (optarg);
  496. break;
  497. case 'V': /* version */
  498. print_revision (progname, NP_VERSION);
  499. exit (STATE_OK);
  500. case 'h': /* help */
  501. print_help ();
  502. exit (STATE_OK);
  503. }
  504. }
  505. if (server_address == NULL && argc > optind) {
  506. if (is_host (argv[optind]))
  507. server_address = argv[optind++];
  508. else
  509. usage2 (_("Invalid hostname/address"), optarg);
  510. }
  511. if (server_address == NULL)
  512. server_address = strdup("127.0.0.1");
  513. return validate_arguments();
  514. }
  515. int
  516. validate_arguments (void)
  517. {
  518. if (! ups_name) {
  519. printf ("%s\n", _("Error : no UPS indicated"));
  520. return ERROR;
  521. }
  522. return OK;
  523. }
  524. void
  525. print_help (void)
  526. {
  527. char *myport;
  528. xasprintf (&myport, "%d", PORT);
  529. print_revision (progname, NP_VERSION);
  530. printf ("Copyright (c) 2000 Tom Shields\n");
  531. printf ("Copyright (c) 2004 Alain Richard <alain.richard@equation.fr>\n");
  532. printf ("Copyright (c) 2004 Arnaud Quette <arnaud.quette@mgeups.com>\n");
  533. printf (COPYRIGHT, copyright, email);
  534. printf ("%s\n", _("This plugin tests the UPS service on the specified host. Network UPS Tools"));
  535. printf ("%s\n", _("from www.networkupstools.org must be running for this plugin to work."));
  536. printf ("\n\n");
  537. print_usage ();
  538. printf (UT_HELP_VRSN);
  539. printf (UT_EXTRA_OPTS);
  540. printf (UT_HOST_PORT, 'p', myport);
  541. printf (" %s\n", "-u, --ups=STRING");
  542. printf (" %s\n", _("Name of UPS"));
  543. printf (" %s\n", "-T, --temperature");
  544. printf (" %s\n", _("Output of temperatures in Celsius"));
  545. printf (" %s\n", "-e, --extended-units");
  546. printf (" %s\n", _("Allow nonstandard units in performance data (used for voltage an temperatures)."));
  547. printf (" %s\n", "-v, --variable=STRING");
  548. printf (" %s %s\n", _("Valid values for STRING are"), "LINE, TEMP, BATTPCT or LOADPCT");
  549. printf (UT_WARN_CRIT);
  550. printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
  551. /* TODO: -v clashing with -v/-variable. Commenting out help text since verbose
  552. is unused up to now */
  553. /* printf (UT_VERBOSE); */
  554. printf ("\n");
  555. printf ("%s\n", _("This plugin attempts to determine the status of a UPS (Uninterruptible Power"));
  556. printf ("%s\n", _("Supply) on a local or remote host. If the UPS is online or calibrating, the"));
  557. printf ("%s\n", _("plugin will return an OK state. If the battery is on it will return a WARNING"));
  558. printf ("%s\n", _("state. If the UPS is off or has a low battery the plugin will return a CRITICAL"));
  559. printf ("%s\n", _("state."));
  560. printf ("\n");
  561. printf ("%s\n", _("Notes:"));
  562. printf (" %s\n", _("You may also specify a variable to check (such as temperature, utility voltage,"));
  563. printf (" %s\n", _("battery load, etc.) as well as warning and critical thresholds for the value"));
  564. printf (" %s\n", _("of that variable. If the remote host has multiple UPS that are being monitored"));
  565. printf (" %s\n", _("you will have to use the --ups option to specify which UPS to check."));
  566. printf ("\n");
  567. printf (" %s\n", _("This plugin requires that the UPSD daemon distributed with Russell Kroll's"));
  568. printf (" %s\n", _("Network UPS Tools be installed on the remote host. If you do not have the"));
  569. printf (" %s\n", _("package installed on your system, you can download it from"));
  570. printf (" %s\n", _("http://www.networkupstools.org"));
  571. printf (UT_SUPPORT);
  572. }
  573. void
  574. print_usage (void)
  575. {
  576. printf ("%s\n", _("Usage:"));
  577. printf ("%s -H host -u ups [-p port] [-v variable] [-w warn_value] [-c crit_value] [-e] [-to to_sec] [-T]\n", progname);
  578. }