|
1 /* |
|
2 * |
|
3 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|
4 * |
|
5 * U.S. Government Rights - Commercial software. Government users are |
|
6 * subject |
|
7 * to the Sun Microsystems, Inc. standard license agreement and applicable |
|
8 * provisions of the FAR and its supplements. |
|
9 * |
|
10 * |
|
11 * This distribution may include materials developed by third parties. Sun, |
|
12 * Sun Microsystems, the Sun logo and Solaris are trademarks or registered |
|
13 * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. |
|
14 * |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 /* |
|
20 * Note: this file originally auto-generated by mib2c using |
|
21 * : mib2c.scalar.conf,v 1.1.1.1 2003/03/26 18:12:30 pcarroll Exp $ |
|
22 */ |
|
23 |
|
24 #include <net-snmp/net-snmp-config.h> |
|
25 #include <net-snmp/net-snmp-includes.h> |
|
26 #include <net-snmp/agent/net-snmp-agent-includes.h> |
|
27 #include "demo_module_1.h" |
|
28 #include <sys/loadavg.h> |
|
29 |
|
30 char* getLoadAvg(int timeAverage){ |
|
31 double loadavg[3]; |
|
32 char *data = malloc(30 * sizeof(char)); |
|
33 int numOfSamples = getloadavg(loadavg, 3); |
|
34 if (numOfSamples == -1) |
|
35 sprintf(data, "%s", "Not valid"); |
|
36 else |
|
37 sprintf(data, "%e", loadavg[timeAverage]); |
|
38 return data; |
|
39 } |
|
40 |
|
41 /** Initializes the demo_module_1 module */ |
|
42 void |
|
43 init_demo_module_1(void) |
|
44 { |
|
45 static oid me1SystemLoadAvg5min_oid[] = { 1,3,6,1,4,1,42,2,2,4,4,1,1,2, 0 }; |
|
46 static oid me1SystemLoadAvg1min_oid[] = { 1,3,6,1,4,1,42,2,2,4,4,1,1,1, 0 }; |
|
47 static oid me1SystemLoadAvg15min_oid[] = { 1,3,6,1,4,1,42,2,2,4,4,1,1,3, 0 }; |
|
48 |
|
49 |
|
50 DEBUGMSGTL(("demo_module_1", "Initializing\n")); |
|
51 |
|
52 netsnmp_register_read_only_instance(netsnmp_create_handler_registration |
|
53 ("me1SystemLoadAvg15min", |
|
54 get_me1SystemLoadAvg15min, |
|
55 me1SystemLoadAvg15min_oid, |
|
56 OID_LENGTH(me1SystemLoadAvg15min_oid), |
|
57 HANDLER_CAN_RONLY)); |
|
58 netsnmp_register_read_only_instance(netsnmp_create_handler_registration |
|
59 ("me1SystemLoadAvg1min", |
|
60 get_me1SystemLoadAvg1min, |
|
61 me1SystemLoadAvg1min_oid, |
|
62 OID_LENGTH(me1SystemLoadAvg1min_oid), |
|
63 HANDLER_CAN_RONLY)); |
|
64 netsnmp_register_read_only_instance(netsnmp_create_handler_registration |
|
65 ("me1SystemLoadAvg5min", |
|
66 get_me1SystemLoadAvg5min, |
|
67 me1SystemLoadAvg5min_oid, |
|
68 OID_LENGTH(me1SystemLoadAvg5min_oid), |
|
69 HANDLER_CAN_RONLY)); |
|
70 } |
|
71 |
|
72 int |
|
73 get_me1SystemLoadAvg15min(netsnmp_mib_handler *handler, |
|
74 netsnmp_handler_registration *reginfo, |
|
75 netsnmp_agent_request_info *reqinfo, |
|
76 netsnmp_request_info *requests) |
|
77 { |
|
78 /* We are never called for a GETNEXT if it's registered as a |
|
79 "instance", as it's "magically" handled for us. */ |
|
80 |
|
81 /* a instance handler also only hands us one request at a time, so |
|
82 we don't need to loop over a list of requests; we'll only get one. */ |
|
83 char* data; |
|
84 switch(reqinfo->mode) { |
|
85 |
|
86 case MODE_GET: |
|
87 data = getLoadAvg(LOADAVG_15MIN); |
|
88 snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, (u_char *) data , strlen(data)); |
|
89 free(data); |
|
90 break; |
|
91 |
|
92 |
|
93 default: |
|
94 /* we should never get here, so this is a really bad error */ |
|
95 return SNMP_ERR_GENERR; |
|
96 } |
|
97 |
|
98 return SNMP_ERR_NOERROR; |
|
99 } |
|
100 int |
|
101 get_me1SystemLoadAvg1min(netsnmp_mib_handler *handler, |
|
102 netsnmp_handler_registration *reginfo, |
|
103 netsnmp_agent_request_info *reqinfo, |
|
104 netsnmp_request_info *requests) |
|
105 { |
|
106 /* We are never called for a GETNEXT if it's registered as a |
|
107 "instance", as it's "magically" handled for us. */ |
|
108 |
|
109 /* a instance handler also only hands us one request at a time, so |
|
110 we don't need to loop over a list of requests; we'll only get one. */ |
|
111 |
|
112 char* data; |
|
113 switch(reqinfo->mode) { |
|
114 |
|
115 case MODE_GET: |
|
116 data = getLoadAvg(LOADAVG_1MIN); |
|
117 snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, (u_char *) data , strlen(data)); |
|
118 free(data); |
|
119 break; |
|
120 |
|
121 |
|
122 default: |
|
123 /* we should never get here, so this is a really bad error */ |
|
124 return SNMP_ERR_GENERR; |
|
125 } |
|
126 |
|
127 return SNMP_ERR_NOERROR; |
|
128 } |
|
129 int |
|
130 get_me1SystemLoadAvg5min(netsnmp_mib_handler *handler, |
|
131 netsnmp_handler_registration *reginfo, |
|
132 netsnmp_agent_request_info *reqinfo, |
|
133 netsnmp_request_info *requests) |
|
134 { |
|
135 /* We are never called for a GETNEXT if it's registered as a |
|
136 "instance", as it's "magically" handled for us. */ |
|
137 |
|
138 /* a instance handler also only hands us one request at a time, so |
|
139 we don't need to loop over a list of requests; we'll only get one. */ |
|
140 |
|
141 char* data; |
|
142 switch(reqinfo->mode) { |
|
143 |
|
144 case MODE_GET: |
|
145 data = getLoadAvg(LOADAVG_5MIN); |
|
146 snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, (u_char *) data , strlen(data)); |
|
147 free(data); |
|
148 break; |
|
149 |
|
150 |
|
151 default: |
|
152 /* we should never get here, so this is a really bad error */ |
|
153 return SNMP_ERR_GENERR; |
|
154 } |
|
155 |
|
156 return SNMP_ERR_NOERROR; |
|
157 } |