ffmpeg-6: fix COMPONENT_REVISION
[oi-userland.git] / components / sysutils / net-snmp / sun / sdk / demo / demo_module_8 / me1LoadGroup.c
blob10ba5d0857adf9095ee78e18f2a696f5173da2dc
1 /*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3 */
5 #include <net-snmp/net-snmp-config.h>
6 #include <net-snmp/net-snmp-includes.h>
7 #include <net-snmp/agent/net-snmp-agent-includes.h>
8 #include "me1LoadGroup.h"
9 #include <sys/loadavg.h>
11 char *
12 getLoadAvg(int timeAverage)
14 double loadavg[3];
15 char *data = malloc(30 * sizeof (char));
16 int numOfSamples = getloadavg(loadavg, 3);
17 sprintf(data, "%e", loadavg[timeAverage]);
18 return (data);
21 /* Initializes the me1LoadGroup module */
22 void
23 init_me1LoadGroup(void)
25 static oid me1SystemLoadAvg15min_oid[] =
26 { 1, 3, 6, 1, 4, 1, 42, 2, 2, 4, 4, 1, 1, 3, 0 };
27 static oid me1SystemLoadAvg1min_oid[] =
28 {1, 3, 6, 1, 4, 1, 42, 2, 2, 4, 4, 1, 1, 1, 0 };
29 static oid me1SystemLoadAvg5min_oid[] =
30 {1, 3, 6, 1, 4, 1, 42, 2, 2, 4, 4, 1, 1, 2, 0 };
32 DEBUGMSGTL(("me1LoadGroup", "Initializing\n"));
34 netsnmp_register_read_only_instance(netsnmp_create_handler_registration
35 ("me1SystemLoadAvg15min",
36 get_me1SystemLoadAvg15min,
37 me1SystemLoadAvg15min_oid,
38 OID_LENGTH(me1SystemLoadAvg15min_oid),
39 HANDLER_CAN_RONLY));
40 netsnmp_register_read_only_instance(netsnmp_create_handler_registration
41 ("me1SystemLoadAvg1min",
42 get_me1SystemLoadAvg1min,
43 me1SystemLoadAvg1min_oid,
44 OID_LENGTH(me1SystemLoadAvg1min_oid),
45 HANDLER_CAN_RONLY));
46 netsnmp_register_read_only_instance(netsnmp_create_handler_registration
47 ("me1SystemLoadAvg5min",
48 get_me1SystemLoadAvg5min,
49 me1SystemLoadAvg5min_oid,
50 OID_LENGTH(me1SystemLoadAvg5min_oid),
51 HANDLER_CAN_RONLY));
54 int
55 get_me1SystemLoadAvg15min(netsnmp_mib_handler * handler,
56 netsnmp_handler_registration * reginfo,
57 netsnmp_agent_request_info * reqinfo,
58 netsnmp_request_info * requests)
61 * We are never called for a GETNEXT if it's registered as a
62 * "instance", as it's "magically" handled for us.
66 * a instance handler also only hands us one request at a time, so we
67 * don't need to loop over a list of requests; we'll only get one.
69 char *data = getLoadAvg(LOADAVG_15MIN);
70 switch (reqinfo->mode) {
72 case MODE_GET:
74 * Get data from data collection routine, Hardcoded here for
75 * testing purpose
77 snmp_set_var_typed_value(requests->requestvb,
78 ASN_OCTET_STR, (u_char *) data, strlen(data));
79 free(data);
80 break;
83 default:
84 /* we should never get here, so this is a really bad error */
85 return (SNMP_ERR_GENERR);
88 return (SNMP_ERR_NOERROR);
90 int
91 get_me1SystemLoadAvg1min(netsnmp_mib_handler * handler,
92 netsnmp_handler_registration * reginfo,
93 netsnmp_agent_request_info * reqinfo,
94 netsnmp_request_info * requests)
97 * We are never called for a GETNEXT if it's registered as a
98 * "instance", as it's "magically" handled for us.
102 * a instance handler also only hands us one request at a time, so we
103 * don't need to loop over a list of requests; we'll only get one.
106 char *data = getLoadAvg(LOADAVG_1MIN);
107 switch (reqinfo->mode) {
109 case MODE_GET:
110 snmp_set_var_typed_value(requests->requestvb,
111 ASN_OCTET_STR, (u_char *) data, strlen(data));
112 free(data);
113 break;
116 default:
117 /* we should never get here, so this is a really bad error */
118 return (SNMP_ERR_GENERR);
121 return (SNMP_ERR_NOERROR);
124 get_me1SystemLoadAvg5min(netsnmp_mib_handler * handler,
125 netsnmp_handler_registration * reginfo,
126 netsnmp_agent_request_info * reqinfo,
127 netsnmp_request_info * requests)
130 * We are never called for a GETNEXT if it's registered as a
131 * "instance", as it's "magically" handled for us.
135 * a instance handler also only hands us one request at a time, so we
136 * don't need to loop over a list of requests; we'll only get one.
139 char *data = getLoadAvg(LOADAVG_5MIN);
140 switch (reqinfo->mode) {
141 case MODE_GET:
142 snmp_set_var_typed_value(requests->requestvb,
143 ASN_OCTET_STR, (u_char *) data, strlen(data));
144 free(data);
145 break;
148 default:
149 /* we should never get here, so this is a really bad error */
150 return (SNMP_ERR_GENERR);
153 return (SNMP_ERR_NOERROR);