summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2003-09-30 13:54:26 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2003-09-30 13:54:26 (GMT)
commitbf1f9663de1abdec77556a6e35a90742d8abbdf5 (patch)
tree4945f4b1e27cd432c43896fa5a2a05b35495f7ef /plugins
parent3a942eb34d148947c382237efc7a919ffff1b7a5 (diff)
downloadmonitoring-plugins-bf1f9663de1abdec77556a6e35a90742d8abbdf5.tar.gz
Fixed logic problem if HAVE_SWAP, but not on AIX or Solaris. Removed
unnecessary ifdefs for help page. Better indentation for ifdefs git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@742 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_swap.c56
1 files changed, 33 insertions, 23 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 2b71fd2..367c720 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -99,23 +99,27 @@ main (int argc, char **argv)
99 fclose(fp); 99 fclose(fp);
100#else 100#else
101# ifdef HAVE_SWAP 101# ifdef HAVE_SWAP
102 asprintf(&swap_command, "%s", SWAP_COMMAND);
103 asprintf(&swap_format, "%s", SWAP_FORMAT);
104 conv_factor = SWAP_CONVERSION;
105
106/* These override the command used if a summary (and thus ! allswaps) is required */
107/* The summary flag returns more accurate information about swap usage on these OSes */
108# ifdef _AIX
102 if (!allswaps) { 109 if (!allswaps) {
103#ifdef _AIX
104 asprintf(&swap_command, "%s", "/usr/sbin/lsps -s"); 110 asprintf(&swap_command, "%s", "/usr/sbin/lsps -s");
105 asprintf(&swap_format, "%s", "%d%*s %d"); 111 asprintf(&swap_format, "%s", "%d%*s %d");
106 conv_factor = 1; 112 conv_factor = 1;
107#else 113 }
108# ifdef sun 114# else
115# ifdef sun
116 if (!allswaps) {
109 asprintf(&swap_command, "%s", "/usr/sbin/swap -s"); 117 asprintf(&swap_command, "%s", "/usr/sbin/swap -s");
110 asprintf(&swap_format, "%s", "%*s %*dk %*s %*s + %*dk %*s = %dk %*s %dk %*s"); 118 asprintf(&swap_format, "%s", "%*s %*dk %*s %*s + %*dk %*s = %dk %*s %dk %*s");
111 conv_factor = 2048; 119 conv_factor = 2048;
112# endif
113#endif
114 } else {
115 asprintf(&swap_command, "%s", SWAP_COMMAND);
116 asprintf(&swap_format, "%s", SWAP_FORMAT);
117 conv_factor = SWAP_CONVERSION;
118 } 120 }
121# endif
122# endif
119 123
120 if (verbose >= 2) 124 if (verbose >= 2)
121 printf (_("Command: %s\n"), swap_command); 125 printf (_("Command: %s\n"), swap_command);
@@ -148,33 +152,36 @@ main (int argc, char **argv)
148 } 152 }
149 } 153 }
150 154
155/* If different swap command is used for summary switch, need to read format differently */
156# ifdef _AIX
151 if (!allswaps) { 157 if (!allswaps) {
152#ifdef _AIX
153 fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_process); /* Ignore first line */ 158 fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_process); /* Ignore first line */
154 sscanf (input_buffer, swap_format, &total_swap, &used_swap); 159 sscanf (input_buffer, swap_format, &total_swap, &used_swap);
155 free_swap = total_swap * (100 - used_swap) /100; 160 free_swap = total_swap * (100 - used_swap) /100;
156 used_swap = total_swap - free_swap; 161 used_swap = total_swap - free_swap;
157 if (verbose >= 3) 162 if (verbose >= 3)
158 printf (_("total=%d, used=%d, free=%d\n"), total_swap, used_swap, free_swap); 163 printf (_("total=%d, used=%d, free=%d\n"), total_swap, used_swap, free_swap);
159#else 164 } else {
160# ifdef sun 165# else
166# ifdef sun
167 if (!allswaps) {
161 sscanf (input_buffer, swap_format, &used_swap, &free_swap); 168 sscanf (input_buffer, swap_format, &used_swap, &free_swap);
162 used_swap = used_swap / 1024; 169 used_swap = used_swap / 1024;
163 free_swap = free_swap / 1024; 170 free_swap = free_swap / 1024;
164 total_swap = used_swap + free_swap; 171 total_swap = used_swap + free_swap;
165# endif
166#endif
167 } else { 172 } else {
173# endif
174# endif
168 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { 175 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
169 sscanf (input_buffer, swap_format, &dsktotal, &dskfree); 176 sscanf (input_buffer, swap_format, &dsktotal, &dskfree);
170 177
171 dsktotal = dsktotal / conv_factor; 178 dsktotal = dsktotal / conv_factor;
172 /* AIX lists percent used, so this converts to dskfree in MBs */ 179 /* AIX lists percent used, so this converts to dskfree in MBs */
173#ifdef _AIX 180# ifdef _AIX
174 dskfree = dsktotal * (100 - dskfree) / 100; 181 dskfree = dsktotal * (100 - dskfree) / 100;
175#else 182# else
176 dskfree = dskfree / conv_factor; 183 dskfree = dskfree / conv_factor;
177#endif 184# endif
178 if (verbose >= 3) 185 if (verbose >= 3)
179 printf (_("total=%d, free=%d\n"), dsktotal, dskfree); 186 printf (_("total=%d, free=%d\n"), dsktotal, dskfree);
180 187
@@ -189,7 +196,14 @@ main (int argc, char **argv)
189 asprintf (&status, "%s [%lu (%d%%)]", status, dskfree, 100 - percent); 196 asprintf (&status, "%s [%lu (%d%%)]", status, dskfree, 100 - percent);
190 } 197 }
191 } 198 }
199# ifdef _AIX
200 }
201# else
202# ifdef sun
192 } 203 }
204# endif
205# endif
206
193 /* If we get anything on STDERR, at least set warning */ 207 /* If we get anything on STDERR, at least set warning */
194 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) 208 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
195 result = max_state (result, STATE_WARNING); 209 result = max_state (result, STATE_WARNING);
@@ -200,8 +214,8 @@ main (int argc, char **argv)
200 /* close the pipe */ 214 /* close the pipe */
201 if (spclose (child_process)) 215 if (spclose (child_process))
202 result = max_state (result, STATE_WARNING); 216 result = max_state (result, STATE_WARNING);
203# endif 217# endif /* HAVE_SWAP */
204#endif 218#endif /* HAVE_PROC_MEMINFO */
205 219
206 percent_used = 100 * ((double) used_swap) / ((double) total_swap); 220 percent_used = 100 * ((double) used_swap) / ((double) total_swap);
207 result = max_state (result, check_swap (percent_used, free_swap)); 221 result = max_state (result, check_swap (percent_used, free_swap));
@@ -387,16 +401,12 @@ print_help (void)
387 -a, --allswaps\n\ 401 -a, --allswaps\n\
388 Conduct comparisons for all swap partitions, one by one\n")); 402 Conduct comparisons for all swap partitions, one by one\n"));
389 403
390#ifdef sun
391 printf (_("\n\ 404 printf (_("\n\
392On Solaris, if -a specified, uses swap -l, otherwise uses swap -s.\n\ 405On Solaris, if -a specified, uses swap -l, otherwise uses swap -s.\n\
393Will be discrepencies because swap -s counts allocated swap and includes\n\ 406Will be discrepencies because swap -s counts allocated swap and includes\n\
394real memory\n")); 407real memory\n"));
395#endif
396#ifdef _AIX
397 printf (_("\n\ 408 printf (_("\n\
398On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.\n")); 409On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.\n"));
399#endif
400 410
401 printf (_(UT_SUPPORT)); 411 printf (_(UT_SUPPORT));
402} 412}