summaryrefslogtreecommitdiffstats
path: root/plugins/check_swap.d
diff options
context:
space:
mode:
authorRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2024-01-04 02:11:48 +0100
committerRincewindsHat <12514511+RincewindsHat@users.noreply.github.com>2024-01-04 02:11:48 +0100
commit946d2f4b8fedfef30b8978d10823987cb6f88819 (patch)
tree3d4ccbd162a1fd8dd85f0c696baf5bc8713f4ff5 /plugins/check_swap.d
parent79d606abc137c9be288d2573984fc3cf7876cd79 (diff)
downloadmonitoring-plugins-946d2f4b8fedfef30b8978d10823987cb6f88819.tar.gz
Implement stub functionality for SRV4 swapctl stuff
Diffstat (limited to 'plugins/check_swap.d')
-rw-r--r--plugins/check_swap.d/swap.c65
1 files changed, 49 insertions, 16 deletions
diff --git a/plugins/check_swap.d/swap.c b/plugins/check_swap.d/swap.c
index 8dc7a4cc..50920fa3 100644
--- a/plugins/check_swap.d/swap.c
+++ b/plugins/check_swap.d/swap.c
@@ -233,7 +233,7 @@ swap_result getSwapFromSwapCommand(swap_config config, const char swap_command[]
233#define SWAP_NSWAP 0 233#define SWAP_NSWAP 0
234#define SWAP_STATS 1 234#define SWAP_STATS 1
235 235
236int swapctl(int cmd, const void *arg, int misc) { 236int bsd_swapctl(int cmd, const void *arg, int misc) {
237 (void) cmd; 237 (void) cmd;
238 (void) arg; 238 (void) arg;
239 (void) misc; 239 (void) misc;
@@ -249,17 +249,19 @@ struct swapent {
249 char se_path[PATH_MAX]; /* path to entry */ 249 char se_path[PATH_MAX]; /* path to entry */
250}; 250};
251 251
252#else
253#define bsd_swapctl swapctl
252#endif 254#endif
253 255
254swap_result getSwapFromSwapctl_BSD(swap_config config) { 256swap_result getSwapFromSwapctl_BSD(swap_config config) {
255 /* get the number of active swap devices */ 257 /* get the number of active swap devices */
256 int nswaps = swapctl(SWAP_NSWAP, NULL, 0); 258 int nswaps = bsd_swapctl(SWAP_NSWAP, NULL, 0);
257 259
258 /* initialize swap table + entries */ 260 /* initialize swap table + entries */
259 struct swapent *ent = (struct swapent *)malloc(sizeof(struct swapent) * nswaps); 261 struct swapent *ent = (struct swapent *)malloc(sizeof(struct swapent) * nswaps);
260 262
261 /* and now, tally 'em up */ 263 /* and now, tally 'em up */
262 int swapctl_res = swapctl(SWAP_STATS, ent, nswaps); 264 int swapctl_res = bsd_swapctl(SWAP_STATS, ent, nswaps);
263 if (swapctl_res < 0) { 265 if (swapctl_res < 0) {
264 perror(_("swapctl failed: ")); 266 perror(_("swapctl failed: "));
265 die(STATE_UNKNOWN, _("Error in swapctl call\n")); 267 die(STATE_UNKNOWN, _("Error in swapctl call\n"));
@@ -302,15 +304,46 @@ swap_result getSwapFromSwapctl_BSD(swap_config config) {
302 return result; 304 return result;
303} 305}
304 306
305#ifdef CHECK_SWAP_SWAPCTL_SVR4 307
308
309#ifndef CHECK_SWAP_SWAPCTL_SVR4
310int srv4_swapctl(int cmd, void *arg) {
311 (void) cmd;
312 (void) arg;
313 return 512;
314}
315
316typedef struct srv4_swapent {
317 char *ste_path; /* name of the swap file */
318 off_t ste_start; /* starting block for swapping */
319 off_t ste_length; /* length of swap area */
320 long ste_pages; /* number of pages for swapping */
321 long ste_free; /* number of ste_pages free */
322 long ste_flags; /* ST_INDEL bit set if swap file */
323 /* is now being deleted */
324} swapent_t;
325
326typedef struct swaptbl {
327 int swt_n; /* number of swapents following */
328 struct srv4_swapent swt_ent[]; /* array of swt_n swapents */
329} swaptbl_t;
330
331#define SC_LIST 2
332#define SC_GETNSWP 3
333
334#ifndef MAXPATHLEN
335#define MAXPATHLEN 2048
336#endif
337
338#else
339#define srv4_swapctl swapctl
340#endif
341
306swap_result getSwapFromSwap_SRV4(swap_config config) { 342swap_result getSwapFromSwap_SRV4(swap_config config) {
307 int i = 0, nswaps = 0, swapctl_res = 0; 343 int nswaps = 0;
308 //swaptbl_t *tbl = NULL; 344
309 void*tbl = NULL;
310 //swapent_t *ent = NULL;
311 void*ent = NULL;
312 /* get the number of active swap devices */ 345 /* get the number of active swap devices */
313 if ((nswaps = swapctl(SC_GETNSWP, NULL)) == -1) 346 if ((nswaps = srv4_swapctl(SC_GETNSWP, NULL)) == -1)
314 die(STATE_UNKNOWN, _("Error getting swap devices\n")); 347 die(STATE_UNKNOWN, _("Error getting swap devices\n"));
315 348
316 if (nswaps == 0) 349 if (nswaps == 0)
@@ -320,21 +353,22 @@ swap_result getSwapFromSwap_SRV4(swap_config config) {
320 printf("Found %d swap device(s)\n", nswaps); 353 printf("Found %d swap device(s)\n", nswaps);
321 354
322 /* initialize swap table + entries */ 355 /* initialize swap table + entries */
323 tbl = (swaptbl_t *)malloc(sizeof(swaptbl_t) + (sizeof(swapent_t) * nswaps)); 356 swaptbl_t *tbl = (swaptbl_t *)malloc(sizeof(swaptbl_t) + (sizeof(swapent_t) * nswaps));
324 357
325 if (tbl == NULL) 358 if (tbl == NULL)
326 die(STATE_UNKNOWN, _("malloc() failed!\n")); 359 die(STATE_UNKNOWN, _("malloc() failed!\n"));
327 360
328 memset(tbl, 0, sizeof(swaptbl_t) + (sizeof(swapent_t) * nswaps)); 361 memset(tbl, 0, sizeof(swaptbl_t) + (sizeof(swapent_t) * nswaps));
329 tbl->swt_n = nswaps; 362 tbl->swt_n = nswaps;
330 for (i = 0; i < nswaps; i++) { 363
364 for (int i = 0; i < nswaps; i++) {
331 if ((tbl->swt_ent[i].ste_path = 365 if ((tbl->swt_ent[i].ste_path =
332 (char *)malloc(sizeof(char) * MAXPATHLEN)) == NULL) 366 (char *)malloc(sizeof(char) * MAXPATHLEN)) == NULL)
333 die(STATE_UNKNOWN, _("malloc() failed!\n")); 367 die(STATE_UNKNOWN, _("malloc() failed!\n"));
334 } 368 }
335 369
336 /* and now, tally 'em up */ 370 /* and now, tally 'em up */
337 swapctl_res = swapctl(SC_LIST, tbl); 371 int swapctl_res = srv4_swapctl(SC_LIST, tbl);
338 if (swapctl_res < 0) { 372 if (swapctl_res < 0) {
339 perror(_("swapctl failed: ")); 373 perror(_("swapctl failed: "));
340 die(STATE_UNKNOWN, _("Error in swapctl call\n")); 374 die(STATE_UNKNOWN, _("Error in swapctl call\n"));
@@ -343,7 +377,7 @@ swap_result getSwapFromSwap_SRV4(swap_config config) {
343 double dsktotal_mb = 0.0, dskfree_mb = 0.0, dskused_mb = 0.0; 377 double dsktotal_mb = 0.0, dskfree_mb = 0.0, dskused_mb = 0.0;
344 unsigned long long total_swap_mb = 0, free_swap_mb = 0, used_swap_mb = 0; 378 unsigned long long total_swap_mb = 0, free_swap_mb = 0, used_swap_mb = 0;
345 379
346 for (i = 0; i < nswaps; i++) { 380 for (int i = 0; i < nswaps; i++) {
347 dsktotal_mb = (float)tbl->swt_ent[i].ste_pages / SWAP_CONVERSION; 381 dsktotal_mb = (float)tbl->swt_ent[i].ste_pages / SWAP_CONVERSION;
348 dskfree_mb = (float)tbl->swt_ent[i].ste_free / SWAP_CONVERSION; 382 dskfree_mb = (float)tbl->swt_ent[i].ste_free / SWAP_CONVERSION;
349 dskused_mb = (dsktotal_mb - dskfree_mb); 383 dskused_mb = (dsktotal_mb - dskfree_mb);
@@ -366,7 +400,7 @@ swap_result getSwapFromSwap_SRV4(swap_config config) {
366 } 400 }
367 401
368 /* and clean up after ourselves */ 402 /* and clean up after ourselves */
369 for (i = 0; i < nswaps; i++) { 403 for (int i = 0; i < nswaps; i++) {
370 free(tbl->swt_ent[i].ste_path); 404 free(tbl->swt_ent[i].ste_path);
371 } 405 }
372 free(tbl); 406 free(tbl);
@@ -379,4 +413,3 @@ swap_result getSwapFromSwap_SRV4(swap_config config) {
379 413
380 return result; 414 return result;
381} 415}
382#endif // CHECK_SWAP_SWAPCTL_SVR4