diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/utils.c | 27 | ||||
-rw-r--r-- | plugins/utils.h | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/plugins/utils.c b/plugins/utils.c index 0e79fbd..88b4411 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -53,6 +53,33 @@ max_state (int a, int b) | |||
53 | return max (a, b); | 53 | return max (a, b); |
54 | } | 54 | } |
55 | 55 | ||
56 | /* ************************************************************************** | ||
57 | * max_state_alt(STATE_x, STATE_y) | ||
58 | * compares STATE_x to STATE_y and returns result based on the following | ||
59 | * STATE_OK < STATE_DEPENDENT < STATE_UNKNOWN < STATE_WARNING < STATE_CRITICAL | ||
60 | * | ||
61 | * The main difference between max_state_alt and max_state it that it doesn't | ||
62 | * allow setting a default to UNKNOWN. It will instead prioritixe any valid | ||
63 | * non-OK state. | ||
64 | ****************************************************************************/ | ||
65 | |||
66 | int | ||
67 | max_state_alt (int a, int b) | ||
68 | { | ||
69 | if (a == STATE_CRITICAL || b == STATE_CRITICAL) | ||
70 | return STATE_CRITICAL; | ||
71 | else if (a == STATE_WARNING || b == STATE_WARNING) | ||
72 | return STATE_WARNING; | ||
73 | else if (a == STATE_UNKNOWN || b == STATE_UNKNOWN) | ||
74 | return STATE_UNKNOWN; | ||
75 | else if (a == STATE_DEPENDENT || b == STATE_DEPENDENT) | ||
76 | return STATE_DEPENDENT; | ||
77 | else if (a == STATE_OK || b == STATE_OK) | ||
78 | return STATE_OK; | ||
79 | else | ||
80 | return max (a, b); | ||
81 | } | ||
82 | |||
56 | void usage (const char *msg) | 83 | void usage (const char *msg) |
57 | { | 84 | { |
58 | printf ("%s\n", msg); | 85 | printf ("%s\n", msg); |
diff --git a/plugins/utils.h b/plugins/utils.h index f15a7b1..bb99ee1 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
@@ -76,6 +76,7 @@ char *strpcpy (char *, const char *, const char *); | |||
76 | char *strpcat (char *, const char *, const char *); | 76 | char *strpcat (char *, const char *, const char *); |
77 | 77 | ||
78 | int max_state (int a, int b); | 78 | int max_state (int a, int b); |
79 | int max_state_alt (int a, int b); | ||
79 | 80 | ||
80 | void usage (const char *) __attribute__((noreturn)); | 81 | void usage (const char *) __attribute__((noreturn)); |
81 | void usage2(const char *, const char *) __attribute__((noreturn)); | 82 | void usage2(const char *, const char *) __attribute__((noreturn)); |