summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_swap.c132
-rw-r--r--plugins/check_swap.d/check_swap.h4
-rw-r--r--plugins/check_swap.d/swap.c2
-rw-r--r--plugins/common.h9
-rw-r--r--plugins/popen.c1
-rw-r--r--plugins/runcmd.c1
-rw-r--r--plugins/sslutils.c1
-rw-r--r--plugins/t/check_swap.t72
-rw-r--r--plugins/utils.c48
-rw-r--r--plugins/utils.h11
10 files changed, 172 insertions, 109 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index bc90a90b..1f2d0273 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -28,6 +28,9 @@
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30#include "common.h" 30#include "common.h"
31#include "output.h"
32#include "states.h"
33#include <limits.h>
31#ifdef HAVE_DECL_SWAPCTL 34#ifdef HAVE_DECL_SWAPCTL
32# ifdef HAVE_SYS_PARAM_H 35# ifdef HAVE_SYS_PARAM_H
33# include <sys/param.h> 36# include <sys/param.h>
@@ -69,8 +72,6 @@ int main(int argc, char **argv) {
69 bindtextdomain(PACKAGE, LOCALEDIR); 72 bindtextdomain(PACKAGE, LOCALEDIR);
70 textdomain(PACKAGE); 73 textdomain(PACKAGE);
71 74
72 char *status = strdup("");
73
74 /* Parse extra opts if any */ 75 /* Parse extra opts if any */
75 argv = np_extra_opts(&argc, argv, progname); 76 argv = np_extra_opts(&argc, argv, progname);
76 77
@@ -90,59 +91,101 @@ int main(int argc, char **argv) {
90 } 91 }
91 92
92 double percent_used; 93 double percent_used;
94 mp_check overall = mp_check_init();
95 if (config.output_format_is_set) {
96 overall.format = config.output_format;
97 }
98 mp_subcheck sc1 = mp_subcheck_init();
99 sc1 = mp_set_subcheck_default_state(sc1, STATE_OK);
100
93 /* if total_swap_mb == 0, let's not divide by 0 */ 101 /* if total_swap_mb == 0, let's not divide by 0 */
94 if (data.metrics.total != 0) { 102 if (data.metrics.total != 0) {
95 percent_used = HUNDRED_PERCENT * ((double)data.metrics.used) / ((double)data.metrics.total); 103 percent_used = HUNDRED_PERCENT * ((double)data.metrics.used) / ((double)data.metrics.total);
96 } else { 104 } else {
97 printf(_("SWAP %s - Swap is either disabled, not present, or of zero " 105 sc1 = mp_set_subcheck_state(sc1, config.no_swap_state);
98 "size."), 106 sc1.output = (char *)_("Swap is either disabled, not present, or of zero size.");
99 state_text(data.statusCode)); 107
100 exit(config.no_swap_state); 108 mp_add_subcheck_to_check(&overall, sc1);
109 mp_exit(overall);
101 } 110 }
102 111
103 if (verbose) { 112 if (verbose) {
104 printf("Computed usage percentage: %g\n", percent_used); 113 printf("Computed usage percentage: %g\n", percent_used);
105 } 114 }
106 115
107 uint64_t warn_print = config.warn.value; 116 mp_perfdata pd = perfdata_init();
108 if (config.warn.is_percentage) { 117 pd.label = "swap";
109 warn_print = config.warn.value * (data.metrics.total / HUNDRED_PERCENT); 118 pd = mp_set_pd_value(pd, data.metrics.free);
119 pd.uom = "B";
120
121 if (config.warn_is_set) {
122 uint64_t warn_print = config.warn.value;
123 if (config.warn.is_percentage) {
124 warn_print = config.warn.value * (data.metrics.total / HUNDRED_PERCENT);
125 }
126
127 mp_perfdata_value warn_pd = mp_create_pd_value(warn_print);
128
129 mp_range warn_range = mp_range_init();
130 warn_range.end_infinity = false;
131 warn_range.end = warn_pd;
132
133 pd.warn = warn_range;
134 pd.warn_present = true;
110 } 135 }
111 136
112 uint64_t crit_print = config.crit.value; 137 if (config.crit_is_set) {
113 if (config.crit.is_percentage) { 138 uint64_t crit_print = config.crit.value;
114 crit_print = config.crit.value * (data.metrics.total / HUNDRED_PERCENT); 139 if (config.crit.is_percentage) {
140 crit_print = config.crit.value * (data.metrics.total / HUNDRED_PERCENT);
141 }
142
143 mp_perfdata_value crit_pd = mp_create_pd_value(crit_print);
144
145 mp_range crit_range = mp_range_init();
146 crit_range.end_infinity = false;
147 crit_range.end = crit_pd;
148
149 pd.crit = crit_range;
150 pd.crit_present = true;
115 } 151 }
116 152
117 char *perfdata = perfdata_uint64("swap", data.metrics.free, "B", config.warn_is_set, warn_print, config.crit_is_set, crit_print, true, 153 mp_perfdata_value max = mp_create_pd_value(data.metrics.total);
118 0, true, data.metrics.total); 154 pd.max = max;
155 pd.max_present = true;
156
157 mp_perfdata_value min = mp_create_pd_value(0);
158 pd.min = min;
159 pd.min_present = true;
160
161 mp_add_perfdata_to_subcheck(&sc1, pd);
162 if (verbose > 1) {
163 printf("Warn threshold value: %" PRIu64 "\n", config.warn.value);
164 }
119 165
120 if (config.warn_is_set) { 166 if (config.warn_is_set) {
121 if (verbose > 1) { 167 if ((config.warn.is_percentage && (percent_used >= (100 - (double)config.warn.value))) || config.warn.value >= data.metrics.free) {
122 printf("Warn threshold value: %" PRIu64 "\n", config.warn.value); 168 sc1 = mp_set_subcheck_state(sc1, STATE_WARNING);
123 } 169 }
170 }
124 171
125 if ((config.warn.is_percentage && (percent_used >= (double)(HUNDRED_PERCENT - config.warn.value))) || 172 if (verbose > 1) {
126 config.warn.value >= data.metrics.free) { 173 printf("Crit threshold value: %" PRIu64 "\n", config.crit.value);
127 data.statusCode = max_state(data.statusCode, STATE_WARNING);
128 }
129 } 174 }
130 175
131 if (config.crit_is_set) { 176 if (config.crit_is_set) {
132 if (verbose > 1) { 177 if ((config.crit.is_percentage && (percent_used >= (100 - (double)config.crit.value))) || config.crit.value >= data.metrics.free) {
133 printf("Crit threshold value: %" PRIu64 "\n", config.crit.value); 178 sc1 = mp_set_subcheck_state(sc1, STATE_CRITICAL);
134 }
135
136 if ((config.crit.is_percentage && (percent_used >= (double)(HUNDRED_PERCENT - config.crit.value))) ||
137 config.crit.value >= data.metrics.free) {
138 data.statusCode = max_state(data.statusCode, STATE_CRITICAL);
139 } 179 }
140 } 180 }
141 181
142 printf(_("SWAP %s - %g%% free (%lluMiB out of %lluMiB) %s|%s\n"), state_text(data.statusCode), (HUNDRED_PERCENT - percent_used), 182 xasprintf(&sc1.output, _("%g%% free (%lluMiB out of %lluMiB)"), (100 - percent_used), data.metrics.free >> 20,
143 BYTES_TO_MiB(data.metrics.free), BYTES_TO_MiB(data.metrics.total), status, perfdata); 183 data.metrics.total >> 20);
184
185 overall.summary = "Swap";
186 mp_add_subcheck_to_check(&overall, sc1);
144 187
145 exit(data.statusCode); 188 mp_exit(overall);
146} 189}
147 190
148int check_swap(float free_swap_mb, float total_swap_mb, swap_config config) { 191int check_swap(float free_swap_mb, float total_swap_mb, swap_config config) {
@@ -172,15 +215,22 @@ int check_swap(float free_swap_mb, float total_swap_mb, swap_config config) {
172 return STATE_OK; 215 return STATE_OK;
173} 216}
174 217
218#define output_format_index CHAR_MAX + 1
219
175/* process command-line arguments */ 220/* process command-line arguments */
176swap_config_wrapper process_arguments(int argc, char **argv) { 221swap_config_wrapper process_arguments(int argc, char **argv) {
177 swap_config_wrapper conf_wrapper = {.errorcode = OK}; 222 swap_config_wrapper conf_wrapper = {.errorcode = OK};
178 conf_wrapper.config = swap_config_init(); 223 conf_wrapper.config = swap_config_init();
179 224
180 static struct option longopts[] = {{"warning", required_argument, 0, 'w'}, {"critical", required_argument, 0, 'c'}, 225 static struct option longopts[] = {{"warning", required_argument, 0, 'w'},
181 {"allswaps", no_argument, 0, 'a'}, {"no-swap", required_argument, 0, 'n'}, 226 {"critical", required_argument, 0, 'c'},
182 {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, 227 {"allswaps", no_argument, 0, 'a'},
183 {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; 228 {"no-swap", required_argument, 0, 'n'},
229 {"verbose", no_argument, 0, 'v'},
230 {"version", no_argument, 0, 'V'},
231 {"help", no_argument, 0, 'h'},
232 {"output-format", required_argument, 0, output_format_index},
233 {0, 0, 0, 0}};
184 234
185 while (true) { 235 while (true) {
186 int option = 0; 236 int option = 0;
@@ -263,6 +313,18 @@ swap_config_wrapper process_arguments(int argc, char **argv) {
263 case 'v': /* verbose */ 313 case 'v': /* verbose */
264 verbose++; 314 verbose++;
265 break; 315 break;
316 case output_format_index: {
317 parsed_output_format parser = mp_parse_output_format(optarg);
318 if (!parser.parsing_success) {
319 // TODO List all available formats here, maybe add anothoer usage function
320 printf("Invalid output format: %s\n", optarg);
321 exit(STATE_UNKNOWN);
322 }
323
324 conf_wrapper.config.output_format_is_set = true;
325 conf_wrapper.config.output_format = parser.output_format;
326 break;
327 }
266 case 'V': /* version */ 328 case 'V': /* version */
267 print_revision(progname, NP_VERSION); 329 print_revision(progname, NP_VERSION);
268 exit(STATE_UNKNOWN); 330 exit(STATE_UNKNOWN);
@@ -319,6 +381,8 @@ void print_help(swap_config config) {
319 _("Resulting state when there is no swap regardless of thresholds. " 381 _("Resulting state when there is no swap regardless of thresholds. "
320 "Default:"), 382 "Default:"),
321 state_text(config.no_swap_state)); 383 state_text(config.no_swap_state));
384 printf(" %s\n", "--output-format");
385 printf(" %s\n", _("Select output format. Valid values: \"one-line\", \"icingaweb2\", \"summary-only\", \"mp-test-json\""));
322 printf(UT_VERBOSE); 386 printf(UT_VERBOSE);
323 387
324 printf("\n"); 388 printf("\n");
diff --git a/plugins/check_swap.d/check_swap.h b/plugins/check_swap.d/check_swap.h
index 99039b21..1000fc9e 100644
--- a/plugins/check_swap.d/check_swap.h
+++ b/plugins/check_swap.d/check_swap.h
@@ -1,6 +1,7 @@
1#pragma once 1#pragma once
2 2
3#include "../common.h" 3#include "../common.h"
4#include "output.h"
4 5
5#ifndef SWAP_CONVERSION 6#ifndef SWAP_CONVERSION
6# define SWAP_CONVERSION 1 7# define SWAP_CONVERSION 1
@@ -32,6 +33,9 @@ typedef struct {
32 check_swap_threshold crit; 33 check_swap_threshold crit;
33 bool on_aix; 34 bool on_aix;
34 int conversion_factor; 35 int conversion_factor;
36
37 bool output_format_is_set;
38 mp_output_format output_format;
35} swap_config; 39} swap_config;
36 40
37swap_config swap_config_init(void); 41swap_config swap_config_init(void);
diff --git a/plugins/check_swap.d/swap.c b/plugins/check_swap.d/swap.c
index 2fe4544f..180d5037 100644
--- a/plugins/check_swap.d/swap.c
+++ b/plugins/check_swap.d/swap.c
@@ -14,6 +14,8 @@ swap_config swap_config_init(void) {
14 tmp.warn_is_set = false; 14 tmp.warn_is_set = false;
15 tmp.crit_is_set = false; 15 tmp.crit_is_set = false;
16 16
17 tmp.output_format_is_set = false;
18
17#ifdef _AIX 19#ifdef _AIX
18 tmp.on_aix = true; 20 tmp.on_aix = true;
19#else 21#else
diff --git a/plugins/common.h b/plugins/common.h
index b7a7d59b..603bae55 100644
--- a/plugins/common.h
+++ b/plugins/common.h
@@ -32,6 +32,7 @@
32#define _COMMON_H_ 32#define _COMMON_H_
33 33
34#include "config.h" 34#include "config.h"
35#include "../lib/monitoringplug.h"
35 36
36#ifdef HAVE_FEATURES_H 37#ifdef HAVE_FEATURES_H
37#include <features.h> 38#include <features.h>
@@ -179,14 +180,6 @@ enum {
179}; 180};
180 181
181enum { 182enum {
182 STATE_OK,
183 STATE_WARNING,
184 STATE_CRITICAL,
185 STATE_UNKNOWN,
186 STATE_DEPENDENT
187};
188
189enum {
190 DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */ 183 DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */
191 MAX_INPUT_BUFFER = 8192, /* max size of most buffers we use */ 184 MAX_INPUT_BUFFER = 8192, /* max size of most buffers we use */
192 MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */ 185 MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */
diff --git a/plugins/popen.c b/plugins/popen.c
index 2b9824bc..cfe930b6 100644
--- a/plugins/popen.c
+++ b/plugins/popen.c
@@ -40,7 +40,6 @@
40 40
41#include "./common.h" 41#include "./common.h"
42#include "./utils.h" 42#include "./utils.h"
43#include "../lib/maxfd.h"
44 43
45/* extern so plugin has pid to kill exec'd process on timeouts */ 44/* extern so plugin has pid to kill exec'd process on timeouts */
46extern pid_t *childpid; 45extern pid_t *childpid;
diff --git a/plugins/runcmd.c b/plugins/runcmd.c
index 74843149..4429ceb0 100644
--- a/plugins/runcmd.c
+++ b/plugins/runcmd.c
@@ -40,6 +40,7 @@
40 40
41/** includes **/ 41/** includes **/
42#include "runcmd.h" 42#include "runcmd.h"
43#include "../lib/monitoringplug.h"
43#ifdef HAVE_SYS_WAIT_H 44#ifdef HAVE_SYS_WAIT_H
44# include <sys/wait.h> 45# include <sys/wait.h>
45#endif 46#endif
diff --git a/plugins/sslutils.c b/plugins/sslutils.c
index 3c928413..719de575 100644
--- a/plugins/sslutils.c
+++ b/plugins/sslutils.c
@@ -29,6 +29,7 @@
29#define MAX_CN_LENGTH 256 29#define MAX_CN_LENGTH 256
30#include "common.h" 30#include "common.h"
31#include "netutils.h" 31#include "netutils.h"
32#include "../lib/monitoringplug.h"
32 33
33#ifdef HAVE_SSL 34#ifdef HAVE_SSL
34static SSL_CTX *ctx = NULL; 35static SSL_CTX *ctx = NULL;
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t
index eaa81083..93e481c3 100644
--- a/plugins/t/check_swap.t
+++ b/plugins/t/check_swap.t
@@ -5,39 +5,89 @@
5# 5#
6 6
7use strict; 7use strict;
8use Test::More tests => 14; 8use warnings;
9use Test::More tests => 35;
9use NPTest; 10use NPTest;
11use JSON;
10 12
11my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; 13my $successOutput = '/^OK.* - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
12my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; 14my $failureOutput = '/^CRITICAL: .*- [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
13my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/'; 15my $warnOutput = '/^WARNING: .*- [0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
14 16
17my $outputFormat = '--output-format one-line';
15my $result; 18my $result;
16 19
17$result = NPTest->testCmd( "./check_swap" ); # Always OK 20$result = NPTest->testCmd( "./check_swap $outputFormat" ); # Always OK
18cmp_ok( $result->return_code, "==", 0, "Always OK" ); 21cmp_ok( $result->return_code, "==", 0, "Always OK" );
19like( $result->output, $successOutput, "Right output" ); 22like( $result->output, $successOutput, "Right output" );
20 23
21$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free 24$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576 $outputFormat" ); # 1 MB free
22cmp_ok( $result->return_code, "==", 0, "At least 1MB free" ); 25cmp_ok( $result->return_code, "==", 0, "At least 1MB free" );
23like( $result->output, $successOutput, "Right output" ); 26like( $result->output, $successOutput, "Right output" );
24 27
25$result = NPTest->testCmd( "./check_swap -w 1% -c 1%" ); # 1% free 28$result = NPTest->testCmd( "./check_swap -w 1% -c 1% $outputFormat" ); # 1% free
26cmp_ok( $result->return_code, "==", 0, 'At least 1% free' ); 29cmp_ok( $result->return_code, "==", 0, 'At least 1% free' );
27like( $result->output, $successOutput, "Right output" ); 30like( $result->output, $successOutput, "Right output" );
28 31
29$result = NPTest->testCmd( "./check_swap -w 100% -c 100%" ); # 100% (always critical) 32$result = NPTest->testCmd( "./check_swap -w 100% -c 100% $outputFormat" ); # 100% (always critical)
30cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); 33cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' );
31like( $result->output, $failureOutput, "Right output" ); 34like( $result->output, $failureOutput, "Right output" );
32 35
33$result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn) 36$result = NPTest->testCmd( "./check_swap -w 100% -c 1% $outputFormat" ); # 100% (always warn)
34cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); 37cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' );
35like( $result->output, $warnOutput, "Right output" ); 38like( $result->output, $warnOutput, "Right output" );
36 39
37$result = NPTest->testCmd( "./check_swap -w 100%" ); # 100% (single threshold, always warn) 40$result = NPTest->testCmd( "./check_swap -w 100% $outputFormat" ); # 100% (single threshold, always warn)
38cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); 41cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' );
39like( $result->output, $warnOutput, "Right output" ); 42like( $result->output, $warnOutput, "Right output" );
40 43
41$result = NPTest->testCmd( "./check_swap -c 100%" ); # 100% (single threshold, always critical) 44$result = NPTest->testCmd( "./check_swap -c 100% $outputFormat" ); # 100% (single threshold, always critical)
42cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); 45cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' );
43like( $result->output, $failureOutput, "Right output" ); 46like( $result->output, $failureOutput, "Right output" );
47
48
49$outputFormat = '--output-format mp-test-json';
50my $output;
51my $message = '/^[0-9]+\% free \([0-9]+MiB out of [0-9]+MiB\)/';
52
53$result = NPTest->testCmd( "./check_swap $outputFormat" ); # Always OK
54cmp_ok( $result->return_code, "==", 0, "Always OK" );
55$output = decode_json($result->output);
56is($output->{'state'}, "OK", "State was correct");
57like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
58
59$result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576 $outputFormat" ); # 1 MB free
60cmp_ok( $result->return_code, "==", 0, "Always OK" );
61$output = decode_json($result->output);
62is($output->{'state'}, "OK", "State was correct");
63like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
64
65$result = NPTest->testCmd( "./check_swap -w 1% -c 1% $outputFormat" ); # 1% free
66cmp_ok( $result->return_code, "==", 0, "Always OK" );
67$output = decode_json($result->output);
68is($output->{'state'}, "OK", "State was correct");
69like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
70
71$result = NPTest->testCmd( "./check_swap -w 100% -c 100% $outputFormat" ); # 100% (always critical)
72cmp_ok( $result->return_code, "==", 0, "Always OK" );
73$output = decode_json($result->output);
74is($output->{'state'}, "CRITICAL", "State was correct");
75like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
76
77$result = NPTest->testCmd( "./check_swap -w 100% -c 1% $outputFormat" ); # 100% (always warn)
78cmp_ok( $result->return_code, "==", 0, "Always OK" );
79$output = decode_json($result->output);
80is($output->{'state'}, "WARNING", "State was correct");
81like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
82
83$result = NPTest->testCmd( "./check_swap -w 100% $outputFormat" ); # 100% (single threshold, always warn)
84cmp_ok( $result->return_code, "==", 0, "Always OK" );
85$output = decode_json($result->output);
86is($output->{'state'}, "WARNING", "State was correct");
87like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
88
89$result = NPTest->testCmd( "./check_swap -c 100% $outputFormat" ); # 100% (single threshold, always critical)
90cmp_ok( $result->return_code, "==", 0, "Always OK" );
91$output = decode_json($result->output);
92is($output->{'state'}, "CRITICAL", "State was correct");
93like($output->{'checks'}->[0]->{'output'}, $message, "Output was correct");
diff --git a/plugins/utils.c b/plugins/utils.c
index 6d366e3d..09649429 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -42,54 +42,6 @@ extern const char *progname;
42 42
43time_t start_time, end_time; 43time_t start_time, end_time;
44 44
45/* **************************************************************************
46 * max_state(STATE_x, STATE_y)
47 * compares STATE_x to STATE_y and returns result based on the following
48 * STATE_UNKNOWN < STATE_OK < STATE_WARNING < STATE_CRITICAL
49 *
50 * Note that numerically the above does not hold
51 ****************************************************************************/
52
53int max_state(int a, int b) {
54 if (a == STATE_CRITICAL || b == STATE_CRITICAL)
55 return STATE_CRITICAL;
56 else if (a == STATE_WARNING || b == STATE_WARNING)
57 return STATE_WARNING;
58 else if (a == STATE_OK || b == STATE_OK)
59 return STATE_OK;
60 else if (a == STATE_UNKNOWN || b == STATE_UNKNOWN)
61 return STATE_UNKNOWN;
62 else if (a == STATE_DEPENDENT || b == STATE_DEPENDENT)
63 return STATE_DEPENDENT;
64 else
65 return max(a, b);
66}
67
68/* **************************************************************************
69 * max_state_alt(STATE_x, STATE_y)
70 * compares STATE_x to STATE_y and returns result based on the following
71 * STATE_OK < STATE_DEPENDENT < STATE_UNKNOWN < STATE_WARNING < STATE_CRITICAL
72 *
73 * The main difference between max_state_alt and max_state it that it doesn't
74 * allow setting a default to UNKNOWN. It will instead prioritixe any valid
75 * non-OK state.
76 ****************************************************************************/
77
78int max_state_alt(int a, int b) {
79 if (a == STATE_CRITICAL || b == STATE_CRITICAL)
80 return STATE_CRITICAL;
81 else if (a == STATE_WARNING || b == STATE_WARNING)
82 return STATE_WARNING;
83 else if (a == STATE_UNKNOWN || b == STATE_UNKNOWN)
84 return STATE_UNKNOWN;
85 else if (a == STATE_DEPENDENT || b == STATE_DEPENDENT)
86 return STATE_DEPENDENT;
87 else if (a == STATE_OK || b == STATE_OK)
88 return STATE_OK;
89 else
90 return max(a, b);
91}
92
93void usage(const char *msg) { 45void usage(const char *msg) {
94 printf("%s\n", msg); 46 printf("%s\n", msg);
95 print_usage(); 47 print_usage();
diff --git a/plugins/utils.h b/plugins/utils.h
index f939e337..c7073990 100644
--- a/plugins/utils.h
+++ b/plugins/utils.h
@@ -13,11 +13,11 @@ in order to resist overflow attacks. In addition, a few functions are
13provided to standardize version and error reporting across the entire 13provided to standardize version and error reporting across the entire
14suite of plugins. */ 14suite of plugins. */
15 15
16/* now some functions etc are being defined in ../lib/utils_base.c */ 16#include "../config.h"
17#include "utils_base.h"
18
19#include <stdbool.h> 17#include <stdbool.h>
20 18#include <stdint.h>
19#include <stdio.h>
20#include <time.h>
21 21
22#ifdef NP_EXTRA_OPTS 22#ifdef NP_EXTRA_OPTS
23/* Include extra-opts functions if compiled in */ 23/* Include extra-opts functions if compiled in */
@@ -78,9 +78,6 @@ char *strpcat (char *, const char *, const char *);
78int xvasprintf (char **strp, const char *fmt, va_list ap); 78int xvasprintf (char **strp, const char *fmt, va_list ap);
79int xasprintf (char **strp, const char *fmt, ...); 79int xasprintf (char **strp, const char *fmt, ...);
80 80
81int max_state (int a, int b);
82int max_state_alt (int a, int b);
83
84void usage (const char *) __attribute__((noreturn)); 81void usage (const char *) __attribute__((noreturn));
85void usage2(const char *, const char *) __attribute__((noreturn)); 82void usage2(const char *, const char *) __attribute__((noreturn));
86void usage3(const char *, int) __attribute__((noreturn)); 83void usage3(const char *, int) __attribute__((noreturn));