Skip to content

Commit 1462916

Browse files
author
J.M. Becker
committed
Check Ram Plugin
1 parent d555a8b commit 1462916

10 files changed

+347
-32
lines changed

.vscode/tasks.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
"type": "shell",
1717
"group": "test",
1818
"problemMatcher": []
19-
}
19+
},
20+
{
21+
"taskName": "check_snmp_ram",
22+
"command": "./build/bin/check_snmp_ram -v2c -c public localhost",
23+
"type": "shell",
24+
"group": "test",
25+
"problemMatcher": []
26+
}
2027
]
21-
}
28+
}

conf/check_snmp_extras.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,9 @@ object CheckCommand "snmp-extras-load" {
6262
command = [ PluginDir + "/check_snmp_load", "$snmp_address$" ]
6363

6464
}
65+
object CheckCommand "snmp-extras-ram" {
66+
import "snmp-extras-command"
67+
68+
command = [ PluginDir + "/check_snmp_ram", "$snmp_address$" ]
69+
70+
}

contrib/check_snmp_extras.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ popd
3131

3232
%attr(0755, -, -) %{_libdir}/nagios/plugins/check_snmp_disk
3333
%attr(0755, -, -) %{_libdir}/nagios/plugins/check_snmp_load
34+
%attr(0755, -, -) %{_libdir}/nagios/plugins/check_snmp_ram
3435

3536
%config %{_datadir}/icinga2/include/plugins-contrib.d/check_snmp_extras.conf

src/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11

2+
add_library(check_snmp_extras_lib STATIC check_snmp_extras_lib.c)
3+
24
add_executable(check_snmp_disk check_snmp_disk.c)
35
add_executable(check_snmp_load check_snmp_load.c)
6+
add_executable(check_snmp_ram check_snmp_ram.c)
47

5-
target_link_libraries(check_snmp_disk ${NETSNMP_LIBRARIES})
6-
target_link_libraries(check_snmp_load ${NETSNMP_LIBRARIES})
7-
8+
target_link_libraries(check_snmp_disk check_snmp_extras_lib ${NETSNMP_LIBRARIES})
9+
target_link_libraries(check_snmp_load check_snmp_extras_lib ${NETSNMP_LIBRARIES})
10+
target_link_libraries(check_snmp_ram check_snmp_extras_lib ${NETSNMP_LIBRARIES})
811

9-
install(TARGETS check_snmp_disk check_snmp_load
12+
install(TARGETS check_snmp_disk check_snmp_load check_snmp_ram
1013
ARCHIVE DESTINATION ${ARCHIVE_DIR}
1114
LIBRARY DESTINATION ${LIBRARY_DIR}
1215
RUNTIME DESTINATION ${RUNTIME_DIR}

src/check_snmp_disk.c

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,6 @@ optProc(int argc, char* const* argv, int opt)
5151
return;
5252
}
5353

54-
char*
55-
readable_fs(long unsigned bytes, char* buf)
56-
{
57-
int i = 0;
58-
const char* units[] = { "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
59-
while (bytes > 1024) {
60-
bytes /= 1024;
61-
i++;
62-
}
63-
sprintf(buf, "%lu%s", bytes, units[i]);
64-
return buf;
65-
}
66-
6754
struct hrentry_t*
6855
attachentry(struct hrentry_t* hentry)
6956
{
@@ -97,8 +84,8 @@ filterentry(struct hrentry_t* hentry)
9784
status = 1;
9885
} else if (netsnmp_oid_equals(hrfstype_iso_oid, index_len, hentry->hrfstype, hentry->hrfstype_len) == 0) {
9986
status = 1;
100-
}
101-
87+
}
88+
10289
else if (netsnmp_oid_equals(hrfstype_other_oid, index_len, hentry->hrfstype, hentry->hrfstype_len) == 0) {
10390
status = 1;
10491
}
@@ -149,7 +136,6 @@ querryentries(netsnmp_session* pss, struct hrentry_t* hentry)
149136
if (netsnmp_oid_equals(hrsttype_oid, index_len, vp->name, vp->name_length) == 0) {
150137
memcpy(hentry->hrsttype, vp->val.objid, vp->val_len);
151138
hentry->hrsttype_len = (vp->val_len / sizeof(oid));
152-
153139
}
154140
if (netsnmp_oid_equals(hrstdesc_oid, index_len, vp->name, vp->name_length) == 0) {
155141
memcpy(hentry->hrstdesc, vp->val.string, vp->val_len);
@@ -233,16 +219,15 @@ main(int argc, char** argv)
233219
}
234220

235221
/* Retrieve indexes */
236-
for (hrfsst_var = hrfsstindex_var; hrfsst_var; hrfsst_var = hrfsst_var->next_variable) {
237-
222+
for (hrfsst_var = hrfsstindex_var; hrfsst_var; hrfsst_var = hrfsst_var->next_variable) {
223+
238224
if (*hrfsst_var->val.integer != 0) {
239225
hentry = attachentry(hentry);
240226
hentry->hrstind = *hrfsst_var->val.integer;
241227
hentry->hrfsind = hrfsst_var->name[hrfsst_var->name_length - 1];
242228
}
243229
}
244230

245-
246231
snmp_free_var(hrfsstindex_var);
247232

248233
/* Query Entries */
@@ -272,7 +257,6 @@ main(int argc, char** argv)
272257

273258
readable_fs(hused[i], &bhused[i][0]);
274259
strcpy(&hrstdesc[i][0], hfree->hrstdesc);
275-
276260
}
277261

278262
for (hfree = hentry; hfree; hfree = hfree->prev) {
@@ -289,7 +273,6 @@ main(int argc, char** argv)
289273
}
290274
}
291275

292-
293276
char* wexit_msg = "DISK WARNING -";
294277
char* cexit_msg = "DISK CRITICAL -";
295278
char* oexit_msg = "DISK OK -";

src/check_snmp_extras.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/** @file check_snmp_extras.h
2+
* @brief Check SNMP Extras
3+
*
4+
* Check SNMP Extras
5+
*
6+
* @author J. M. Becker
7+
* @date 7/27/17
8+
*/
9+
10+
#ifndef CHECK_SNMP_EXTRAS_H
11+
#define CHECK_SNMP_EXTRAS_H
12+
13+
#include "check_snmp_extras_lib.h"
114

215
/* Exit Status */
316
#define STATUS_OK 0
@@ -9,3 +22,5 @@
922
#define MAX_OCTETSTRING_LEN 255
1023
#define MAX_OCTETSTRING_128_LEN 128
1124
#define MAX_OCTETSTRING_64_LEN 64
25+
26+
#endif /* CHECK_SNMP_EXTRAS_H */

src/check_snmp_extras_lib.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/** @file check_snmp_extras_lib.c
2+
* @brief Check SNMP Misc
3+
*
4+
* Check SNMP Misc
5+
*
6+
* @author J. M. Becker
7+
* @date 7/27/17
8+
*/
9+
10+
#include <stdio.h>
11+
12+
char*
13+
readable_fs(long unsigned bytes, char* buf)
14+
{
15+
int i = 0;
16+
const char* units[] = { "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
17+
while (bytes > 1024) {
18+
bytes /= 1024;
19+
i++;
20+
}
21+
sprintf(buf, "%lu%s", bytes, units[i]);
22+
return buf;
23+
}

src/check_snmp_extras_lib.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/** @file check_snmp_extras_lib.h
2+
* @brief Check SNMP Misc
3+
*
4+
* Check SNMP Misc
5+
*
6+
* @author J. M. Becker
7+
* @date 7/27/17
8+
*/
9+
10+
#ifndef CHECK_SNMP_EXTRAS_LIB_H
11+
#define CHECK_SNMP_EXTRAS_LIB_H
12+
13+
char*
14+
readable_fs(long unsigned bytes, char* buf);
15+
16+
#endif /* CHECK_SNMP_EXTRAS_LIB_H */

src/check_snmp_load.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct hrentry_t
2828
void
2929
usage(void)
3030
{
31-
fprintf(stderr, "USAGE: check_snmp_disk ");
31+
fprintf(stderr, "USAGE: check_snmp_load ");
3232
snmp_parse_args_usage(stderr);
3333
fprintf(stderr, " [OID]\n\n");
3434
snmp_parse_args_descriptions(stderr);
@@ -184,15 +184,14 @@ main(int argc, char** argv)
184184

185185
float hpload_avg = 0;
186186
long unsigned hpload_sum = 0;
187-
187+
188188
for (int n = 0; n <= i; ++n) {
189189
hpload_sum = hpload_sum + hpload[n];
190190
}
191191
if (i > 0 && hpload_sum > 0) {
192192
hpload_avg = hpload_sum / (i + 1);
193193
}
194194

195-
196195
for (int n = 0; n <= i; ++n) {
197196

198197
if (hpload_avg >= warning) {
@@ -231,8 +230,8 @@ main(int argc, char** argv)
231230
printf("|");
232231

233232
for (int n = 0; n <= i; ++n) {
234-
printf(" '%s_%d'=%lu%%", hdesc[n], n, hpload[n]);
235-
}
233+
printf(" '%s_%d'=%lu%%", hdesc[n], n, hpload[n]);
234+
}
236235

237236
return exit_status;
238237
}

0 commit comments

Comments
 (0)