Skip to content

Commit 8533b53

Browse files
author
J. M. Becker
committed
Load initial
1 parent 3b51dd4 commit 8533b53

File tree

7 files changed

+379
-20
lines changed

7 files changed

+379
-20
lines changed

.vscode/tasks.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
"type": "shell",
1010
"group": "test",
1111
"problemMatcher": []
12+
},
13+
{
14+
"taskName": "check_snmp_load",
15+
"command": "./build/bin/check_snmp_load -v2c -c public localhost",
16+
"type": "shell",
17+
"group": "test",
18+
"problemMatcher": []
1219
}
1320
]
1421
}

conf/check_snmp_extras.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,9 @@ object CheckCommand "snmp-disk" {
5656
command = [ PluginDir + "/check_snmp_disk", "$snmp_address$" ]
5757

5858
}
59+
object CheckCommand "snmp-load" {
60+
import "snmp-extras-command"
61+
62+
command = [ PluginDir + "/check_snmp_load", "$snmp_address$" ]
5963

64+
}

contrib/check_snmp_extras.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ popd
3030
%defattr(0644, root, root, 0755)
3131

3232
%attr(0755, -, -) %{_libdir}/nagios/plugins/check_snmp_disk
33+
%attr(0755, -, -) %{_libdir}/nagios/plugins/check_snmp_load
3334

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

src/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11

22
add_executable(check_snmp_disk check_snmp_disk.c)
3+
add_executable(check_snmp_load check_snmp_load.c)
34

45
target_link_libraries(check_snmp_disk ${NETSNMP_LIBRARIES})
6+
target_link_libraries(check_snmp_load ${NETSNMP_LIBRARIES})
57

68

7-
install(TARGETS check_snmp_disk
9+
install(TARGETS check_snmp_disk check_snmp_load
810
ARCHIVE DESTINATION ${ARCHIVE_DIR}
911
LIBRARY DESTINATION ${LIBRARY_DIR}
1012
RUNTIME DESTINATION ${RUNTIME_DIR}

src/check_snmp_disk.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
#include <net-snmp/net-snmp-config.h>
1313
#include <net-snmp/net-snmp-includes.h>
1414

15+
int warning = 80;
16+
int critical = 90;
17+
1518
struct hrentry_t
1619
{
17-
int hrstind;
18-
int hrfsind;
20+
unsigned long hrstind;
21+
unsigned long hrfsind;
1922

20-
size_t hrstaunit;
23+
unsigned long hrstaunit;
2124
unsigned long hrstsize;
2225
unsigned long hrstused;
2326

@@ -149,13 +152,13 @@ querryentries(netsnmp_session* pss, struct hrentry_t* hentry)
149152
memcpy(hentry->hrstdesc, vp->val.string, vp->val_len);
150153
}
151154
if (netsnmp_oid_equals(hrstaunit_oid, index_len, vp->name, vp->name_length) == 0) {
152-
hentry->hrstaunit = (size_t)*vp->val.integer;
155+
hentry->hrstaunit = *vp->val.integer;
153156
}
154157
if (netsnmp_oid_equals(hrstsize_oid, index_len, vp->name, vp->name_length) == 0) {
155-
hentry->hrstsize = (unsigned long)*vp->val.integer;
158+
hentry->hrstsize = *vp->val.integer;
156159
}
157160
if (netsnmp_oid_equals(hrstused_oid, index_len, vp->name, vp->name_length) == 0) {
158-
hentry->hrstused = (unsigned long)*vp->val.integer;
161+
hentry->hrstused = *vp->val.integer;
159162
}
160163
if (netsnmp_oid_equals(hrfstype_oid, index_len, vp->name, vp->name_length) == 0) {
161164
memcpy(hentry->hrfstype, vp->val.objid, vp->val_len);
@@ -172,13 +175,12 @@ int
172175
main(int argc, char** argv)
173176
{
174177
int arg;
175-
176-
int hrst;
177-
int hrfsst;
178178
int query_status;
179-
180179
int exit_status = STATUS_OK;
181-
char oidbuf[MAX_OID_LEN];
180+
181+
unsigned long hrst;
182+
unsigned long hrfsst;
183+
182184
struct hrentry_t* hentry = NULL;
183185
struct hrentry_t* hfree = NULL;
184186

@@ -249,12 +251,12 @@ main(int argc, char** argv)
249251

250252
/* Correlate indexes */
251253
for (hrst_var = hrstindex_var; hrst_var; hrst_var = hrst_var->next_variable) {
252-
hrst = (int)*hrst_var->val.integer;
254+
hrst = *hrst_var->val.integer;
253255
hrfsst = 0;
254256

255257
for (hrfsst_var = hrfsstindex_var; hrfsst_var; hrfsst_var = hrfsst_var->next_variable) {
256-
if (hrst == (int)*hrfsst_var->val.integer) {
257-
hrfsst = (int)hrfsst_var->name[hrfsst_var->name_length - 1];
258+
if (hrst == *hrfsst_var->val.integer) {
259+
hrfsst = hrfsst_var->name[hrfsst_var->name_length - 1];
258260
break;
259261
}
260262
}
@@ -326,9 +328,10 @@ main(int argc, char** argv)
326328
exit_msg = oexit_msg;
327329
}
328330

329-
printf("%s", exit_msg);
331+
printf("%s used space:", exit_msg);
332+
330333
for (int n = 0; n < i; ++n) {
331-
printf(" used space: %s %s (%.1f%%);", hrstdesc[n], bhused[n], hpused[n]);
334+
printf(" %s %s (%.1f%%);", hrstdesc[n], bhused[n], hpused[n]);
332335
}
333336

334337
printf("|");

src/check_snmp_extras.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@
77

88
#define MAX_ENTRIES 50
99
#define MAX_DISPLAYSTRING_LEN 255
10-
11-
int warning = 80;
12-
int critical = 90;

0 commit comments

Comments
 (0)