check_dummy.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*****************************************************************************
  2. *
  3. * Nagios check_dummy plugin
  4. *
  5. * License: GPL
  6. * Copyright (c) 1999-2007 Nagios Plugins Development Team
  7. *
  8. * Description:
  9. *
  10. * This file contains the check_dummy plugin
  11. *
  12. * This plugin will simply return the state corresponding to the numeric value
  13. *
  14. *
  15. * This program is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation, either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. *
  28. *
  29. *****************************************************************************/
  30. const char *progname = "check_dummy";
  31. const char *copyright = "1999-2007";
  32. const char *email = "nagiosplug-devel@lists.sourceforge.net";
  33. #include "common.h"
  34. #include "utils.h"
  35. void print_help (void);
  36. void print_usage (void);
  37. int
  38. main (int argc, char **argv)
  39. {
  40. int result = STATE_UNKNOWN;
  41. setlocale (LC_ALL, "");
  42. bindtextdomain (PACKAGE, LOCALEDIR);
  43. textdomain (PACKAGE);
  44. if (argc < 2)
  45. usage4 (_("Could not parse arguments"));
  46. else if (strcmp (argv[1], "-V") == 0 || strcmp (argv[1], "--version") == 0) {
  47. print_revision (progname, NP_VERSION);
  48. exit (STATE_OK);
  49. }
  50. else if (strcmp (argv[1], "-h") == 0 || strcmp (argv[1], "--help") == 0) {
  51. print_help ();
  52. exit (STATE_OK);
  53. }
  54. else if (!is_integer (argv[1]))
  55. usage4 (_("Arguments to check_dummy must be an integer"));
  56. else
  57. result = atoi (argv[1]);
  58. switch (result) {
  59. case STATE_OK:
  60. printf (_("OK"));
  61. break;
  62. case STATE_WARNING:
  63. printf (_("WARNING"));
  64. break;
  65. case STATE_CRITICAL:
  66. printf (_("CRITICAL"));
  67. break;
  68. case STATE_UNKNOWN:
  69. printf (_("UNKNOWN"));
  70. break;
  71. default:
  72. printf (_("UNKNOWN"));
  73. printf (": ");
  74. printf (_("Status %d is not a supported error state\n"), result);
  75. return STATE_UNKNOWN;
  76. }
  77. if (argc >= 3)
  78. printf (": %s", argv[2]);
  79. printf("\n");
  80. return result;
  81. }
  82. void
  83. print_help (void)
  84. {
  85. print_revision (progname, NP_VERSION);
  86. printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
  87. printf (COPYRIGHT, copyright, email);
  88. printf ("%s\n", _("This plugin will simply return the state corresponding to the numeric value"));
  89. printf ("%s\n", _("of the <state> argument with optional text"));
  90. printf ("\n\n");
  91. print_usage ();
  92. printf (_(UT_HELP_VRSN));
  93. printf (_(UT_SUPPORT));
  94. }
  95. void
  96. print_usage (void)
  97. {
  98. printf (_("Usage:"));
  99. printf (" %s <integer state> [optional text]\n", progname);
  100. }