diff options
Diffstat (limited to 'plugins/utils.c')
-rw-r--r-- | plugins/utils.c | 86 |
1 files changed, 56 insertions, 30 deletions
diff --git a/plugins/utils.c b/plugins/utils.c index a864e4aa..348ec022 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -36,9 +36,6 @@ extern const char *progname; | |||
36 | #define STRLEN 64 | 36 | #define STRLEN 64 |
37 | #define TXTBLK 128 | 37 | #define TXTBLK 128 |
38 | 38 | ||
39 | unsigned int timeout_state = STATE_CRITICAL; | ||
40 | unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; | ||
41 | |||
42 | time_t start_time, end_time; | 39 | time_t start_time, end_time; |
43 | 40 | ||
44 | /* ************************************************************************** | 41 | /* ************************************************************************** |
@@ -148,33 +145,6 @@ print_revision (const char *command_name, const char *revision) | |||
148 | command_name, revision, PACKAGE, VERSION); | 145 | command_name, revision, PACKAGE, VERSION); |
149 | } | 146 | } |
150 | 147 | ||
151 | const char * | ||
152 | state_text (int result) | ||
153 | { | ||
154 | switch (result) { | ||
155 | case STATE_OK: | ||
156 | return "OK"; | ||
157 | case STATE_WARNING: | ||
158 | return "WARNING"; | ||
159 | case STATE_CRITICAL: | ||
160 | return "CRITICAL"; | ||
161 | case STATE_DEPENDENT: | ||
162 | return "DEPENDENT"; | ||
163 | default: | ||
164 | return "UNKNOWN"; | ||
165 | } | ||
166 | } | ||
167 | |||
168 | void | ||
169 | timeout_alarm_handler (int signo) | ||
170 | { | ||
171 | if (signo == SIGALRM) { | ||
172 | printf (_("%s - Plugin timed out after %d seconds\n"), | ||
173 | state_text(timeout_state), timeout_interval); | ||
174 | exit (timeout_state); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | int | 148 | int |
179 | is_numeric (char *number) | 149 | is_numeric (char *number) |
180 | { | 150 | { |
@@ -668,3 +638,59 @@ char *sperfdata (const char *label, | |||
668 | 638 | ||
669 | return data; | 639 | return data; |
670 | } | 640 | } |
641 | |||
642 | char *sperfdata_int (const char *label, | ||
643 | int val, | ||
644 | const char *uom, | ||
645 | char *warn, | ||
646 | char *crit, | ||
647 | int minp, | ||
648 | int minv, | ||
649 | int maxp, | ||
650 | int maxv) | ||
651 | { | ||
652 | char *data = NULL; | ||
653 | if (strpbrk (label, "'= ")) | ||
654 | xasprintf (&data, "'%s'=", label); | ||
655 | else | ||
656 | xasprintf (&data, "%s=", label); | ||
657 | |||
658 | xasprintf (&data, "%s%d", data, val); | ||
659 | xasprintf (&data, "%s%s;", data, uom); | ||
660 | |||
661 | if (warn!=NULL) | ||
662 | xasprintf (&data, "%s%s", data, warn); | ||
663 | |||
664 | xasprintf (&data, "%s;", data); | ||
665 | |||
666 | if (crit!=NULL) | ||
667 | xasprintf (&data, "%s%s", data, crit); | ||
668 | |||
669 | xasprintf (&data, "%s;", data); | ||
670 | |||
671 | if (minp) | ||
672 | xasprintf (&data, "%s%d", data, minv); | ||
673 | |||
674 | if (maxp) { | ||
675 | xasprintf (&data, "%s;", data); | ||
676 | xasprintf (&data, "%s%d", data, maxv); | ||
677 | } | ||
678 | |||
679 | return data; | ||
680 | } | ||
681 | |||
682 | int | ||
683 | open_max (void) | ||
684 | { | ||
685 | errno = 0; | ||
686 | if (maxfd > 0) | ||
687 | return(maxfd); | ||
688 | |||
689 | if ((maxfd = sysconf (_SC_OPEN_MAX)) < 0) { | ||
690 | if (errno == 0) | ||
691 | maxfd = DEFAULT_MAXFD; /* it's indeterminate */ | ||
692 | else | ||
693 | die (STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n")); | ||
694 | } | ||
695 | return(maxfd); | ||
696 | } | ||